<%@ Page Language="C#" AutoEventWireup="true" UICulture="auto" Culture="auto" meta:resourcekey="PageResource1" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Globalization" %>

<script runat="server">
    String version = WebAppVersion.GetWebAppVersion();

    protected override void InitializeCulture()
    {
        HttpCookie lang = Request.Cookies["siteLanguage"];

        String selectedLanguage = (lang != null) ? lang.Value : "en";
        UICulture = selectedLanguage;
        Culture = selectedLanguage;

        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
        base.InitializeCulture();
    }
</script>

<%
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.Now.AddMinutes(-30)); %>

<%--view template starts here (will be appended inside a row-fluid)--%>

<link href="<%= ResolveUrl("~/app/pages/mes/" + Path.GetFileNameWithoutExtension(this.Request.PhysicalPath) + "/" + Path.GetFileNameWithoutExtension(this.Request.PhysicalPath) + ".css")%>" rel="stylesheet" />
<link href="<%= ResolveUrl("~/assets/ag-grid/ag-grid.css") %>" rel="stylesheet" />
<link href="<%= ResolveUrl("~/assets/ag-grid/ag-theme-alpine.css") %>" rel="stylesheet" />
<link href="<%= ResolveUrl("~/app/components/ag-grid/ag-grid-styles.css") %>" rel="stylesheet" />
<link href="<%= ResolveUrl("~/assets/fonts/reboto-font.css") %>" rel="stylesheet" />
<link href="<%= ResolveUrl("~/assets/tailwind/tailwind.min.css") %>" rel="stylesheet" />
<link href="<%= ResolveUrl("~/assets/libs/js/multiselect/virtual-select.min.css") %>" rel="stylesheet" />

<style>
    .content-container { padding-top: 0px !important; }
    #subnavbar-inner { display: none !important; }

    .professional-title {
        font-size: 22px;
        font-weight: 400;
        color: #202124;
        padding-bottom: 1px;
        border-bottom: 1px solid #dadce0;
        margin-bottom: 2px;
        font-family: 'Roboto', Arial, sans-serif;
    }

    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    .spinner {
        animation: spin 1s linear infinite;
        transform-origin: center;
    }
</style>

<h2 class="professional-title"><asp:Localize runat="server" meta:resourcekey="screen_title" /></h2>

<div class="bg-white shadow-md rounded-lg p-2 mb-4">

    <%-- ============ ACTION BAR ============ --%>
    <div class="bg-white shadow-md rounded-lg mb-2">
        <div class="flex items-center justify-between flex-wrap">

            <%-- Heat navigation: prev / picker / next --%>
            <div class="flex items-center space-x-2 mb-2">
                <button id="backNavBtn" type="button"
                        class="heat-nav-btn bg-blue-600 hover:bg-blue-700 text-white py-2 px-3 rounded flex items-center justify-center"
                        style="height: 36.5px; font-size: 14px;"
                        title="<asp:Localize runat=server meta:resourcekey=back_item_btn_title />">
                    <i class="fa fa-chevron-left"></i>
                </button>

                <div class="flex items-center">
                    <label class="ml-2 mr-2 text-sm font-medium text-gray-700">
                        <asp:Localize runat="server" meta:resourcekey="heat_label" />
                    </label>
                    <div id="heat-picker-multi-select" class="heat-picker" style="width: 180px;"></div>
                </div>

                <button id="forwardNavBtn" type="button"
                        class="heat-nav-btn bg-blue-600 hover:bg-blue-700 text-white py-2 px-3 rounded flex items-center justify-center"
                        style="height: 36.5px; font-size: 14px;"
                        title="<asp:Localize runat=server meta:resourcekey=forward_item_btn_title />">
                    <i class="fa fa-chevron-right"></i>
                </button>

                <%-- Nearby heats badges (from GetThermalProfile Table2) --%>
                <div class="navigation-buttons ml-2" data-bind="classes: { hide: any(not(hasData), isLoading) }"></div>
            </div>

            <%-- Export + manual refresh --%>
            <div class="flex space-x-2 mb-2">
                <button type="button" class="btn-export-to-excel bg-gray-100 hover:bg-gray-200 text-gray-800 py-2 px-4 rounded flex items-center justify-center"
                        style="height: 36.5px; font-size: 14px;"
                        data-bind="attr: { disabled: not(hasData) }">
                    <span class="excel-export-state fa fa-file-excel-o mr-2"></span>
                    <img class="loading-state hide" style="width:20px;height:20px;" src="<%= ResolveUrl("~/assets/img/spinner20.gif") %>" />
                    <span>Excel</span>
                </button>
                <button id="refreshBtn" class="bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded flex items-center justify-center"
                        style="width: 120px; height: 36.5px; font-size: 14px;"
                        title="<asp:localize runat=server meta:resourcekey=refresh_btn_title />">
                    <div data-bind="classes: { hide: isLoading }">
                        <i class="fa fa-refresh mr-2"></i>
                        <span>Refresh</span>
                    </div>
                    <div data-bind="classes: { hide: not(isLoading) }">
                        <div class="flex items-center">
                            <svg class="h-5 w-5 mr-2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                                <g class="spinner">
                                    <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none"/>
                                    <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"/>
                                </g>
                            </svg>
                            <span>Loading...</span>
                        </div>
                    </div>
                </button>
            </div>
        </div>
    </div>

    <%-- ============ HEAT / LADLE HEADLINE ============ --%>
    <div class="headline-card bg-white shadow-md rounded-lg p-3 mb-3 flex items-center justify-between">
        <div class="flex items-center">
            <div class="headline-icon mr-3">
                <i class="fa fa-thermometer-half fa-2x text-red-500"></i>
            </div>
            <div>
                <div class="headline-label text-xs text-gray-500 uppercase tracking-wide">
                    <asp:Localize runat="server" meta:resourcekey="ladle_label" />
                </div>
                <div class="headline-value text-3xl font-semibold text-gray-800" data-bind="text: ladleText">-</div>
            </div>
        </div>
        <div class="flex items-center">
            <div class="text-right mr-6">
                <div class="headline-label text-xs text-gray-500 uppercase tracking-wide">
                    <asp:Localize runat="server" meta:resourcekey="heat_label" />
                </div>
                <div class="headline-value text-2xl font-semibold text-gray-800" data-bind="text: heatNameText">-</div>
            </div>
            <div class="text-right">
                <div class="headline-label text-xs text-gray-500 uppercase tracking-wide">
                    <asp:Localize runat="server" meta:resourcekey="liquidus_label" />
                </div>
                <div class="headline-value text-2xl font-semibold text-red-600" data-bind="text: liquidusText">-</div>
            </div>
        </div>
    </div>

    <%-- ============ KPI ROW: Time Since + Since Reline ============ --%>
    <div class="grid grid-cols-1 md:grid-cols-5 gap-3 mb-3">
        <div class="kpi-card kpi-time bg-white shadow-md rounded-lg p-3">
            <div class="kpi-label text-xs text-gray-500 uppercase tracking-wide">
                <asp:Localize runat="server" meta:resourcekey="ladle_close_label" />
            </div>
            <div class="kpi-value text-2xl font-semibold text-gray-800" data-bind="text: ladleCloseText">-</div>
            <div class="kpi-sublabel text-xs text-gray-400 mt-1">
                <asp:Localize runat="server" meta:resourcekey="time_since_sublabel" />
            </div>
        </div>
        <div class="kpi-card kpi-time bg-white shadow-md rounded-lg p-3">
            <div class="kpi-label text-xs text-gray-500 uppercase tracking-wide">
                <asp:Localize runat="server" meta:resourcekey="start_tap_label" />
            </div>
            <div class="kpi-value text-2xl font-semibold text-gray-800" data-bind="text: startTapText">-</div>
            <div class="kpi-sublabel text-xs text-gray-400 mt-1">
                <asp:Localize runat="server" meta:resourcekey="time_since_sublabel" />
            </div>
        </div>
        <div class="kpi-card kpi-reline bg-white shadow-md rounded-lg p-3">
            <div class="kpi-label text-xs text-gray-500 uppercase tracking-wide">
                <asp:Localize runat="server" meta:resourcekey="heats_label" />
            </div>
            <div class="kpi-value text-2xl font-semibold text-gray-800" data-bind="text: heatsText">-</div>
            <div class="kpi-sublabel text-xs text-gray-400 mt-1">
                <asp:Localize runat="server" meta:resourcekey="since_reline_sublabel" />
            </div>
        </div>
        <div class="kpi-card kpi-reline bg-white shadow-md rounded-lg p-3">
            <div class="kpi-label text-xs text-gray-500 uppercase tracking-wide">
                <asp:Localize runat="server" meta:resourcekey="contact_hours_label" />
            </div>
            <div class="kpi-value text-2xl font-semibold text-gray-800" data-bind="text: contactText">-</div>
            <div class="kpi-sublabel text-xs text-gray-400 mt-1">
                <asp:Localize runat="server" meta:resourcekey="since_reline_sublabel" />
            </div>
        </div>
        <div class="kpi-card kpi-reline bg-white shadow-md rounded-lg p-3">
            <div class="kpi-label text-xs text-gray-500 uppercase tracking-wide">
                <asp:Localize runat="server" meta:resourcekey="mwh_label" />
            </div>
            <div class="kpi-value text-2xl font-semibold text-gray-800" data-bind="text: mwhText">-</div>
            <div class="kpi-sublabel text-xs text-gray-400 mt-1">
                <asp:Localize runat="server" meta:resourcekey="since_reline_sublabel" />
            </div>
        </div>
    </div>

    <%-- ============ READINGS GRID ============ --%>
    <div class="bg-white shadow-md rounded-lg p-2" style="border: 4px solid #ccc;">
        <div class="flex items-center justify-between mb-2 px-1">
            <h3 class="text-sm font-semibold text-gray-700 m-0">
                <asp:Localize runat="server" meta:resourcekey="readings_title" />
            </h3>
            <span class="text-xs text-gray-500" data-bind="text: readingsCountText">0</span>
        </div>
        <div id="thermal-grid" class="processes-grid-container ag-theme-alpine w-full"></div>
    </div>
</div>

<div class="row-fluid screen-content" id="main-div"></div>
