<%@ 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" />

<style>
    .processes-grid-container .ag-pinned-right-cols-container,
    .processes-grid-container .ag-pinned-left-cols-container {
        border-right: none !important;
    }
    .ag-cell.ag-cell-last-left-pinned:not(.ag-cell-range-right):not(.ag-cell-range-single-cell) {
        border-right: none !important;
    }
    .ag-pinned-left-header {
        border-right: none !important;
    }
    .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="page_title" /></h2>

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

    <%-- ============ TOP BAR (Add + Refresh) ============ --%>
    <div class="bg-white shadow-md rounded-lg mb-2">
        <div class="flex items-center justify-between flex-wrap">
            <div class="flex items-center space-x-2 mb-2 px-2">
                <span class="text-sm text-gray-500" data-bind="text: rowCountLabel"></span>
            </div>
            <div class="flex space-x-2 mb-2">
                <button id="exportExcelBtn" 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;" title="<asp:localize runat=server meta:resourcekey=excel_btn_title />">
                    <span class="fa fa-file-excel-o mr-2"></span>
                    <span><asp:Localize runat="server" meta:resourcekey="excel_btn_label" /></span>
                </button>
                <button id="addYearBtn" type="button" class="bg-emerald-600 hover:bg-emerald-700 text-white py-2 px-4 rounded flex items-center justify-center" style="height: 36.5px; font-size: 14px; background-color: #059669;" data-bind="classes: { hide: readOnlyPermission }" title="<asp:localize runat=server meta:resourcekey=add_item_btn_title />">
                    <i class="fa fa-plus mr-2"></i>
                    <span><asp:Localize runat="server" meta:resourcekey="add_item_btn_label" /></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><asp:Localize runat="server" meta:resourcekey="refresh_btn_label" /></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><asp:Localize runat="server" meta:resourcekey="loading_data_short" /></span>
                        </div>
                    </div>
                </button>
            </div>
        </div>
    </div>

    <%-- ============ GRID ============ --%>
    <div class="mx-auto">
        <div class="bg-white shadow-md rounded-lg p-2 mb-4" style="border: 4px solid #ccc;">
            <div class="processes-grid-container ag-theme-alpine w-full" id="prepurchased-energy-grid" style="height: 65vh; border: 1px solid #ccc;"></div>
        </div>
    </div>
</div>

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


<%-- ============ ADD YEAR MODAL ============ --%>
<script id="add_year_modal_template" type="text/x-handlebars-template">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4>
            <asp:Localize runat="server" meta:resourcekey="add_modal_title" />
        </h4>
    </div>
    <div class="modal-body">
        <div class="row-field">
            <label class="row-field-label" for="newYearInput">
                <asp:Localize runat="server" meta:resourcekey="year_label" />
            </label>
            <input type="number" id="newYearInput" class="row-field-input" placeholder="2026" min="1900" max="2999" />
        </div>
        <div class="row-field">
            <label class="row-field-label" for="newMWHLimitInput">
                <asp:Localize runat="server" meta:resourcekey="mwh_limit_label" />
            </label>
            <input type="number" id="newMWHLimitInput" class="row-field-input" placeholder="0.00" step="0.01" min="0" />
        </div>
        <div class="row-field">
            <label class="row-field-label" for="newPriceInput">
                <asp:Localize runat="server" meta:resourcekey="price_label" />
            </label>
            <input type="number" id="newPriceInput" class="row-field-input" placeholder="0.00" step="0.01" min="0" />
        </div>
        <div id="addYearError" class="hide"></div>
    </div>
    <div class="modal-footer">
        <button type="button" id="cancelAddYearBtn" class="btn" data-dismiss="modal">
            <asp:Localize runat="server" meta:resourcekey="cancel_btn_label" />
        </button>
        <button type="button" id="acceptAddYearBtn" class="btn btn-primary">
            <asp:Localize runat="server" meta:resourcekey="save_btn_label" />
        </button>
    </div>
</script>
