<%@ 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();

    //@Override this is suggested by Microsoft, overriding the initialize culture function (that is
    //automatically called by the aspx.
    //Checks if the cookie exists and sets the language correctly, otherwise will fall-back to the default language
    //(English).
    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>

<%  
    //this prevents the browser from caching templates. (on IE the templates where cached with the old language
    //too, so the change language was not working, this is a workaround for that).

    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("~/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("~/app/pages/vtd/" + Path.GetFileNameWithoutExtension(this.Request.PhysicalPath) + "/" + Path.GetFileNameWithoutExtension(this.Request.PhysicalPath) + ".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;
        border-left: 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-cell.ag-cell-first-right-pinned:not(.ag-cell-range-left):not(.ag-cell-range-single-cell) {
        border-left: none !important;
    }
    .ag-pinned-left-header {
        border-right: none !important;
    }
    .ag-pinned-right-header {
        border-left: 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;
    }
    .processes-grid-container.ag-theme-alpine {
        height: 75vh;
        border: 1px solid #ccc;
    }
    .ag-root-wrapper.ag-layout-normal.ag-ltr {
        height: 75vh;
    }
    .date-picker {
        border: none !important;
        margin-bottom: 0 !important;
        -webkit-box-shadow: none !important;
        box-shadow: none !important;
        background-color: #fff;
    }
    .bg-white.shadow-md.rounded-lg select {
        background-color: #fff;
        color: #111827;
        height: 37.78px;
        padding: 0 0.5rem;
        box-sizing: border-box;
    }
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    .spinner {
        animation: spin 1s linear infinite;
        transform-origin: center;
    }
</style>

<h2 class="professional-title">VTD Production</h2>

<div class="bg-white shadow-md rounded-lg p-2 mb-4">
    <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">
                <div class="flex flex-wrap items-center space-x-1">
                    <div class="flex items-center">
                        <label for="dateStartTbx" class="ml-2 mr-2 text-sm font-medium text-gray-700"><asp:localize runat="server" meta:resourcekey="date_start_tbx_label" /></label>
                        <div class="flex items-center border border-gray-300 rounded-md">
                            <input type="text" id="dateStartTbx" class="input-date date-picker pl-10 pr-3 py-2 border-0 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500" style="z-index:1000; width:120px;" data-bind="value: momentFormat(start$, 'YYYY-MM-DD', '<asp:Localize runat=server meta:resourcekey=mmddyyyy_format />')">
                            <button type="button" id="calendarStartBtn" class="px-2 py-2 border-l border-gray-300 hover:bg-gray-100 rounded-r">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-gray-600" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd" /></svg>
                            </button>
                        </div>
                    </div>
                    <div class="flex items-center">
                        <label for="dateEndTbx" class="ml-2 mr-2 text-sm font-medium text-gray-700"><asp:localize runat="server" meta:resourcekey="date_end_tbx_label" /></label>
                        <div class="flex items-center border border-gray-300 rounded-md">
                            <input type="text" id="dateEndTbx" class="input-date date-picker pl-10 pr-3 py-2 border-0 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500" style="z-index:1000; width:120px;" data-bind="value: momentFormat(end$, 'YYYY-MM-DD', '<asp:Localize runat=server meta:resourcekey=mmddyyyy_format />')">
                            <button type="button" id="calendarEndBtn" class="px-2 py-2 border-l border-gray-300 hover:bg-gray-100 rounded-r">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-gray-600" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd" /></svg>
                            </button>
                        </div>
                    </div>
                </div>
                <div class="flex flex-wrap items-center space-x-1">
                    <div class="flex items-center">
                        <label class="ml-2 mr-2 text-sm font-medium text-gray-700"><asp:Localize runat="server" meta:resourcekey="tank_label" /></label>
                        <select disabled data-bind="value: tankCode, options: tanks, optionsDefault: { label: '<asp:Localize runat=server meta:resourcekey=select_crew_label />', value: null }" class="block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md" style="width:80px;">
                        </select>
                    </div>
                    <div class="flex items-center">
                        <label class="ml-2 mr-2 text-sm font-medium text-gray-700"><asp:Localize runat="server" meta:resourcekey="crew_label" /></label>
                        <select data-bind="value: crewId, options: crews, optionsDefault: { label: '<asp:Localize runat=server meta:resourcekey=select_crew_label />', value: null }" class="block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md" style="width:80px;">
                        </select>
                    </div>
                    <div class="flex items-center">
                        <label class="ml-2 mr-2 text-sm font-medium text-gray-700"><asp:Localize runat="server" meta:resourcekey="shift_label" /></label>
                        <select data-bind="value: shiftId, options: shifts, optionsDefault: { label: '<asp:Localize runat=server meta:resourcekey=select_shift_label />', value: null }" class="block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md" style="width:80px;">
                        </select>
                    </div>
                    <div class="flex items-center ml-4">
                        <label class="ml-2 mr-2 text-sm font-medium text-gray-700">Hand Additions</label>
                        <label class="switch">
                            <input class="handAddToggle" data-bind="value: hideShowHandAdditionToggle" type="checkbox" />
                            <span class="slider round"></span>
                        </label>
                    </div>
                </div>
            </div>
            <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;">
                    <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>
    <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="vtd-production-grid"></div>
        </div>
    </div>
</div>

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

<!-- Hand Additions Modal -->
<div class="modal fade" id="handAdditions" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title span9" id="handAdditionsLabel">Hand Additions</h5>
                <button type="button" id="addHandAdditionBtn" class="span2 btn-primary">
                    Add
                </button>
                <button type="button" id="closeHandAdditionModal" class="close span1" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="hand-additions-items-grid-container items-grid-container"></div>
            </div>
        </div>
    </div>
</div>


<script id="assign_heats_modal" type="text/x-handlebars-template">
    <div class="modal-header" >    
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4>
            <span data-bind="text: title" style="font-weight:bold;"></span>
        </h4>    
    </div>
    <div class="modal-body">
        <div style="padding-bottom:0;" class="modal-body">
            <div class="row-fluid">                 
                
                <div class="pull-left" style="width:100%;margin-left:0;">  
                        <div class="no-data-poster row-fluid text-center animated fadeIn" data-bind="classes: { hide: any(hasData, isLoading), }" style="height:350px;">
                            <div class="row-fluid" style="position:relative;top:100px;">
                                <i class="fw-icon-circle-blank fw-icon-4x" style="font-size:115px;"></i>
                            </div>
                            <div class="row-fluid" style="position:relative;top:115px;">
                                <h3 style="font-size:50px;">
                                    <asp:localize runat="server" meta:resourcekey="no_data_available" />
                                </h3>
                            </div>
                        </div>
                        <div class="no-data-poster row-fluid text-center animated fadeIn" data-bind="classes: { hide: not(isLoading), }" style="height:350px;">
                            <div class="row-fluid" style="position:relative;top:100px;">
                                <i class="fa fa-cog fw-icon-4x fa-spin" style="font-size:115px;"></i>
                            </div>
                            <div class="row-fluid" style="position:relative;top:115px;">
                                <h3 style="font-size:50px;">
                                    <asp:localize runat="server" meta:resourcekey="loading_data" />
                                </h3>
                            </div>
                        </div>
                </div>
               
                <div class="last-heats-grid-container row-fluid infinite-container" data-bind="classes: { hide: any(not(hasData), isLoading), }"></div>   

            </div>
        </div>
    </div>
    <div class="modal-footer">
        <div class="modal-status-msg-container pull-left">
            <div class="modal-status-msg hide" data-bind="toggle: notEquals(errorMsg, ''),">
                <span data-bind="text: errorMsg, attr: { title: errorMsg, }," style="color:#ff0000;font-size:16px;"></span>
            </div>
            <div class="modal-status-msg hide" data-bind="toggle: processing,">
                <asp:Localize runat='server' meta:resourcekey='processing_msg' />
                <i class="fa fa-cog fa-spin"></i>
            </div>
        </div>
        <button id="acceptBtn" class="btn btn-primary" data-bind="enabled: all(not(processing), selectedHeatId),">
            <asp:Localize runat='server' meta:resourcekey='accept_btn_label' />
        </button>
        
        <button id="cancelBtn" class="btn" data-dismiss="modal" data-bind="enabled: not(processing),">
            <asp:Localize runat='server' meta:resourcekey='cancel_btn_label' />
        </button>


    </div>
</script>
