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

@model PantheonRA.WebApi.Contracts.PaWoExItem

@{
    Model.ProdType = ViewBag.ProdType;
}

@Html.HiddenFor(model => model.WoExDecPlacesMate)

@using (Html.BeginForm(null, null, FormMethod.Post, new { @id = "workOrderEditMat", enctype = "multipart/form-data" }))
{
    <div class="wrapper wrapper-content">
        <div class="tabs-container">
            @Html.Partial("_ProcessingTabNavigation")

            <div class="tab-content">
                @Html.HiddenFor(model => model.AcKey)
                @Html.HiddenFor(model => model.AnNo)
                @Html.HiddenFor(model => model.Ident)
                @Html.HiddenFor(model => model.ProdType)
                @Html.HiddenFor(model => model.WoEx.DocType)

                <div class="divided-content">
                    <div class="divided-content-main divided-content-full">

                        <div class="row document-head d-head-m-b-10">

                            <div class="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-xs-4 document-head-disabled-input">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.AnNo, Loc.Position, new { @class = "control-label m-t-xs" })
                                    <input class="form-control" id="anNo" disabled="disabled" type="text" value=" @Model.AnNo">
                                </div>
                            </div>
                            <div class="col-xs-4 document-head-disabled-input">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Ident, Loc.MaterialEnum, new { @class = "control-label m-t-xs" })
                                    <input class="form-control" id="acIdent" disabled="disabled" type="text" value=" @Model.Ident">
                                </div>
                            </div>

                        </div>

                        <div class="project-list">
                            <div class="row">

                                <div class="form-horizontal form-md">

                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg">
                                            <div class="card-header">
                                                <h3 class="card-title"><i class="fas fa-thumbs-up text-primary fa-lg m-r-sm"></i>  @Loc.Quantity</h3>
                                            </div>

                                            <div class="card-body">

                                                <div class="input-group input-group-lg">
                                                    <span class="input-group-btn">
                                                        <button id="b_dQty" type="button" class="btn btn-plus-minus"><i class="fa fa-minus fa-lg text-primary"></i></button>
                                                    </span>
                                                    <input type="number" id="qty" name="Qty" required class="form-control col-md-8 text-center input-lg" autocomplete="off" min="0" />
                                                    <span class="input-group-btn">
                                                        <button id="b_iQty" type="button" class="btn btn-plus-minus"><i class="fa fa-plus fa-lg text-primary"></i></button>
                                                    </span>
                                                </div>
                                                <div class="text-center m-t-sm">
                                                    <span>/@String.Format("{0:0.##}", Model.RestQtyCalc) @Model.UM</span>
                                                </div>

                                            </div>

                                        </div>

                                    </div>

                                    <div class="col-xs-12 card-work-reg-card @((ViewBag.ProdType == ProductionType.MF)?String.Empty:"hidden")">
                                        <div class="card card-work-reg">
                                            <div class="card-header">

                                                <h3 class="card-title"><i class="fas fa-wrench  text-primary fa-lg m-r-sm"></i>@Loc.WOScrap</h3>
                                            </div>

                                            <div class="card-body">

                                                <div class="input-group input-group-lg">
                                                    <span class="input-group-btn">
                                                        <button id="b_dScrapQty" type="button" class="btn btn-plus-minus"><i class="fa fa-minus fa-lg  text-primary"></i></button>
                                                    </span>
                                                    <input type="number" id="scrapQty" name="ScrapQty" required class="form-control col-md-8 text-center input-lg" autocomplete="off" min="0" />
                                                    <span class="input-group-btn">
                                                        <button id="b_iScrapQty" type="button" class="btn btn-plus-minus"><i class="fa fa-plus fa-lg text-primary"></i></button>
                                                    </span>
                                                </div>

                                                <div class="text-center m-t-sm">
                                                    <span>/@String.Format("{0:0.##}", Model.RestScrapQtyCalc) @Model.UM</span>
                                                </div>

                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg">
                                            <div class="card-header">

                                                <h3 class="card-title"><i class="fas fa-times text-primary fa-lg m-r-sm"></i> @((ViewBag.ProdType == ProductionType.MF)?Loc.WOWaste:Loc.Shrinkage)</h3>
                                            </div>

                                            <div class="card-body">

                                                <div class="input-group input-group-lg">
                                                    <span class="input-group-btn">
                                                        <button id="b_dWasteQty" type="button" class="btn btn-plus-minus"><i class="fa fa-minus fa-lg  text-primary"></i></button>
                                                    </span>
                                                    <input type="number" id="wasteQty" name="WasteQty" required class="form-control col-md-8 text-center input-lg" autocomplete="off" min="0" />
                                                    <span class="input-group-btn">
                                                        <button id="b_iWasteQty" type="button" class="btn btn-plus-minus"><i class="fa fa-plus fa-lg text-primary"></i></button>
                                                    </span>
                                                </div>
                                                <div class="text-center m-t-sm">
                                                    <span>/@String.Format("{0:0.##}", Model.RestWasteQtyCalc) @Model.UM</span>
                                                </div>

                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg ">
                                            <div class="card-header">

                                                <h3 class="card-title"><i class="far fa-calendar-alt text-primary fa-lg m-r-sm"></i>  @Loc.Date</h3>
                                            </div>

                                            <div class="card-body">
                                                <input id="date" type="date" name="Date" class="input-lg text-center col-xs-12" value="@DateTime.Now.Date.ToString("yyyy-MM-dd")">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-12 card-work-reg-card">
                                        <div class="card card-work-reg ">
                                            <div class="card-body text-center">

                                                @Html.Image(ImageHelper.GetImageThumbnail(Model.Picture, 200), "", new { id = "image" })
                                                <i id="noImage" class='fal fa-image fa-3x text-muted hidden' style='opacity:0.5'></i>

                                            </div>
                                        </div>

                                    </div>
                                </div>

                            </div>

                        </div>

                    </div>

                    <div class="divided-content-side">
                        <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="#home" class="local-tab">@Loc.Note</a></li>
                            </ul>
                        </div>
                        <div class="tab-content" id="sideNavBar">
                            <div id="home" class="tab-pane">
                                <div class="form-horizontal additonal-options">
                                    <div class="form-horizontal m-t-lg">
                                        <textarea id="note" name="Note" class="form-control col-xs-10 input-lg" rows="6"></textarea>
                                    </div>
                                </div>
                            </div>

                            <button id="back1" type="button" class="btn btn-rounded btn-back">
                                <i class="fas fa-chevron-left"></i>
                            </button>

                        </div>
                    </div>

                </div>
            </div>

            <a href="@Url.Action("WorkOrderMaterials", "Manufacturing", new { key = Model.AcKey })" id="back" class="btn btn-light btn-rounded text-primary btn-back">
                <i class="fas fa-chevron-left"></i>
            </a>
            <div class="cont-right m-r-n-sm @(Model.IssueFinished == "Y" ? "hidden" : String.Empty) ">
                <button id="confirmButton" type="button" class="btn btn-primary pull-right btn-rounded m-l-sm" onclick="saveMaterial(true);">
                    <i class="fa fa-check"></i> <span>@Loc.Confirm</span>
                </button>

                <button id="comment" type="button" class="btn pull-right btn-rounded hidden">
                    <i class="fas fa-comment"></i>
                </button>
            </div>
        </div>
    </div>
}

<div class="modal inmodal fade" id="imageModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body text-center">
                @Html.Image(ImageHelper.GetImageThumbnail(Model.Picture, 400), "alt=''", new { id = "image"})
                <i id="noImage" class='fal fa-image fa-3x text-muted hidden' style='opacity:0.5'></i>
            </div>
            <div class="modal-footer" style="text-align:center !important;">
                <button type="button" class="btn btn-primary btn-rounded" data-dismiss="modal">@Loc.Close</button>
            </div>
        </div>
    </div>
</div>


<input type="hidden" id="receiveURL" value="@Url.Action("ConfirmMat", "Manufacturing")" />
<input type="hidden" id="buttonText" value="@Loc.OK" />
<input type="hidden" id="succesText" value="@Loc.SuccessIssueMsg" />
<input type="hidden" id="requiedQty" value="@Loc.RequiredInput @Loc.Quantity" />
<input type="hidden" id="productionTypeMF" value="@ProductionType.MF" />
<input type="hidden" id="productionTypeSE" value="@ProductionType.SE" />
<input type="hidden" id="manufacturingExampleMF" value="@SiteHelpAttributeHelper.GetHelpUrl(HelpIds.ManufacturingExampleMF)" />
<input type="hidden" id="manufacturingExampleSE" value="@SiteHelpAttributeHelper.GetHelpUrl(HelpIds.ManufacturingExampleSE)" />

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

        $(document).ready(function () {

            var decPlaces = $("#WoExDecPlacesMate").val();
            $('.card-work-reg').find('input[type=number]').val(round(0, decPlaces));

            $('.card-work-reg').find('input[type=number]').blur(function () {
                $(this).val(round(Number($(this).val()), decPlaces) );
            });

            $('.btn-plus-minus').click(function () {
                var control = $(this).parents("div").children(".form-control");

                if ($(this).children().hasClass("fa-plus")) {
                    control.val(roundToPercision(decPlaces, Number(control.val()) + 1));
                };

                if ($(this).children().hasClass("fa-minus")) {
                    if (Number(control.val()) > 0)
                        control.val(roundToPercision(decPlaces, Number(control.val()) - 1));
                };

            });


            $('#comment').on("click", function () {
                $('#sideNavBar>#home').addClass("fade").addClass("in").addClass("active");
                $(".divided-content").addClass("divided-content-side-opened").removeClass("divided-content-side-closed");
            });

            $('#apply').on("click", function () {
                $(".divided-content").addClass("divided-content-side-closed").removeClass("divided-content-side-opened");
            });

            $('#back1').on("click", function () {
                $(".divided-content").addClass("divided-content-side-closed").removeClass("divided-content-side-opened");
            });

            $('#image').on("click", function () {
                $("#imageModal").modal('show');
            });


        });
    </script>

}

