@using PantheonRA.BackOffice.Models
@using PantheonRA.WebApi.Contracts
@using PantheonRA.WebApi.Contracts.Enums

@model PaWoEx
@{
    var _isMobile = Request.Browser.IsMobileDevice;
}

<div class="tabs-container">
    @Html.Partial("_ProcessingTabNavigation")
    <div class="row buttons-tabbed @(_isMobile?"hidden":"")">
        @Html.Partial("_FormButtons", new FormButtonsViewModel
            {
                BackUrl = Url.Action("Index", "Manufacturing")
            })

        @if (PantheonRA.BackOffice.CurrentUser.CanAccess(Permissions.PRODUCTION))
        {
            <a href="@Url.Action("Receive", "Manufacturing", new { @id = Model.AcKey})"
               id="receiveButton"
               class="btn btn-success  pull-right"
               title="@Loc.Receive">
                <i class="fa fa-dolly"></i><span class="hidden-xs m-l-xs">@Loc.Receive</span>
            </a>
        }
    </div>
    <div class="tab-content">
        <input id="localStorageFiltersFor" value="workOrderList" hidden />
        @Html.HiddenFor(model => model.AcKey)
        @Html.HiddenFor(model => model.ParentWO)
        @Html.HiddenFor(model => model.WoExDecPlacesProd)

        <div class="row document-head @(_isMobile?"d-head-m-b-0":"")" style="margin-bottom:5px !important">
            <div class="col-lg-2 col-md-3 col-xs-4 document-head-disabled-input">
                <div class="form-group">
                    @Html.LabelFor(model => model.AcKey, Loc.Key, new { @class = "control-label m-t-xs" })
                    <input class="form-control" id="acKeyDisplay" disabled="disabled" type="text" value=" @Model.KeyView">
                </div>
            </div>
            <div class="col-lg-2 document-head-disabled-input @(ViewBag.ItemType == "S"?"col-xs-4":"col-xs-8")">
                <div class="form-group typeahead-ident-filter">
                    @Html.Label(Loc.Product, new { @class = "control-label" })
                    <input type="text" disabled="disabled" class="form-control" id="ident" value="@(Model.Ident + " - " + Model.Name )" />
                </div>
            </div>

            <div class="col-lg-2 col-md-3 col-xs-4 @(_isMobile ? "hidden" : "") @(ViewBag.ProdType == ProductionType.MF && @ViewBag.ItemType == "S" ? String.Empty : "hidden" )">
                <div class="form-group">
                    <label class="control-label">@Loc.WOResource</label>
                    <select id="ResursID" class="form-control selectpicker localStorageFilter" data-live-search="true" multiple="multiple" title="@Loc.All">
                        @foreach (var item in ViewBag.SetResursLookup)
                        {
                            if (!String.IsNullOrEmpty(item.Value))
                            {
                                <option value="@item.Value">
                                    @(item.Value + " - " + item.Text)
                                </option>
                            }
                        }
                    </select>
                </div>
            </div>

            <div class="col-xs-4 document-head-disabled-input selectResurs @(!_isMobile ? "hidden" : "") @(ViewBag.ItemType == "S"?String.Empty:"hidden")">
                <div class="form-group">
                    @Html.Label(Loc.WOResource, new { @class = "control-label" })
                    <input type="text" readonly="readonly" class="form-control" id="mResursID" value="@Loc.All" />
                </div>
            </div>


        </div>

        <div class="divided-content">

            <div class="divided-content-main @((_isMobile || String.IsNullOrEmpty(ViewBag.ItemType)) ? "divided-content-full no-padding" : "")">

                <div class="document-list-no-footer">
                    <table id="mainGridProcessing" data-grid-id="work-order-items" data-url="@ViewBag.DataTableURL" class="card">
                        <thead style="display:none">
                        </thead>
                    </table>
                </div>

            </div>

            <div class="divided-content-side m-t-n-xs">
                <div class="tabs-container">
                    <ul class="nav nav-tabs horizontal-menu" id="tabNav">
                        <li class="active divided-tab-1" id="homeTab">
                            <a id="tabCaption" data-toggle="tab" href="#item-options" class="local-tab">
                                <span>@(_isMobile?Loc.AdditionalSettings:Loc.WorkHistory)</span>
                                <i class="far fa-times pull-right fa-lg text-muted btn-close-side-panel"></i>
                            </a>

                        </li>
                    </ul>
                </div>
                <div class="tab-content" id="sideNavBar">
                    <div id="item-options" class="tab-pane">
                        <div class="form-horizontal additonal-options">

                            <div class="row border-bottom p-l-10" id="work-history">
                                <a data-toggle="tab" href="#work-reg-history">
                                    <h3 class="text-default"><i class="fas fa-history text-primary p-r-sm"></i>@Loc.WorkHistory</h3>
                                </a>
                            </div>

                        </div>
                    </div>

                    <div id="work-reg-history" class="tab-pane m-l-n-sm m-r-n-sm  fade in active">
                        <table id="woExOperWork" data-grid-id="WoExOperWork" data-url="@Url.Action("WoExOperWork", "Manufacturing")" class="list-table">
                            <thead>
                                <tr>
                                    <th>@Loc.Worker</th>
                                    <th>@Loc.Key</th>
                                    <th>@Loc.Product/@Loc.Operation</th>
                                    <th>@Loc.Planned</th>
                                    <th>@Loc.Status</th>
                                </tr>
                            </thead>
                        </table>
                    </div>

                    @if (_isMobile)
                    {
                        <div id="resurs" class="tab-pane additonal-options m-l-n-sm m-r-n-sm" style="padding-bottom:100px" data-control="#ResursID">
                            @foreach (var item in ViewBag.SetResursLookup)
                            {
                                if (!String.IsNullOrEmpty(item.Value))
                                {
                                    <div class="border-bottom p-l-10 filter-list-item" data-value="@item.Value" data-display="@item.Value">
                                        <a data-toggle="tab">
                                            <h3 class="text-default" data-toggle="tab">
                                                @item.Value - @item.Text
                                                <i class="fa text-primary p-r-sm pull-right"></i>
                                            </h3>
                                        </a>
                                    </div>
                                }
                            }
                        </div>

                        <button type="button" class="btn btn-rounded btn-back btn-close-side-panel">
                            <i class="fas fa-chevron-left"></i>
                        </button>
                        <button type="button" class="btn btn-rounded btn-back btn-back-to-menu hidden">
                            <i class="fas fa-chevron-left"></i>
                        </button>
                    }

                </div>
            </div>

        </div>
    </div>

    <a href="@Url.Action("Index", "Manufacturing")" id="back" class="btn btn-light btn-rounded btn-back @(!_isMobile?"hidden":"") ">
        <i class="fas fa-chevron-left"></i>
    </a>

    <div class="cont-right @(!_isMobile?"hidden":"")" style="right:0px;">
        @if (PantheonRA.BackOffice.CurrentUser.CanAccess(Permissions.PRODUCTION))
        {
            <a href="@Url.Action("Receive", "Manufacturing", new { @id = Model.AcKey})"
                id="receiving" role="button"
                class="btn pull-right btn-primary btn-rounded m-l-sm">
                <i class="fa fa-dolly"></i><span class="m-l-xs">@Loc.Receive</span>
            </a>
        }

        <button id="options" type="button" class="btn pull-right btn-rounded @(ViewBag.ItemType == "S"?String.Empty:"hidden")">
            <i class="fas fa-ellipsis-h"></i>
        </button>
    </div>

</div>

<div id="operPopover">
    <table id="popoverTable" class="table">
    </table>
</div>

@section pageScripts{
    @Scripts.Render("~/bundles/manufacturing")
    <script>
    $(document).ready(function () {

        initializeWorkOrderProcessing({
            itemType: '@ViewBag.ItemType',
            prodType: '@ViewBag.ProdType'

        }, {
            operationCaption: '@Loc.Operation',
            materialCaption: '@Loc.MaterialEnum',
            operationStart: '@Loc.OperationStart',
            operationPause: '@Loc.OperationPause',
            operationContinue: '@Loc.OperationContinue',
            operationEnd: '@Loc.OperationEnd',
            workRegistration: '@Loc.WorkRegistration',
            materialsForOperation: '@Loc.MaterialsForOperation'
        }, {
            operMatURL: '@Url.Action("MaterialsForOperationList", "Manufacturing")',
            operRegURL: '@Url.Action("GetActiveWoExRegOper", "Manufacturing")'

        }, {
            canInputCompletedWork: '@PantheonRA.BackOffice.CurrentUser.CanAccess(Permissions.PRODUCTION)'
        });

    });
    </script>

}
