@model PantheonRA.WebApi.Contracts.TravelOrderAllData
@using PantheonRA.BackOffice;
@using PantheonRA.BackOffice.Models;
@using PantheonRA.BackOffice.Enums;
@using PantheonRA.WebApi.Contracts.Enums;
@using PAW.Contracts.Enums;

<input type="hidden" id="AjpesUrl" value="@Url.Action("AjpesSearch", "Subjects")" />
<input type="hidden" id="CreateSubjectUrl" value="@Url.Action("CreateFromPartial", "Subjects")" />
<input type="hidden" id="PartnerId" />
<input type="hidden" id="SubjectRewriteDataLoc" value="@Loc.RewriteSubjectData" />
@Html.Hidden("searchSubjectsUrl", @Url.Action("GetSubjectById", "TravelOrdersDistances"))

@{
    string action = (Model == null || Model.Header == null || string.IsNullOrEmpty(Model.Header.AcKey)) ? "Create" : "Edit";
    var currentLoc = Loc.CurrentLocalization;
    var locBA = Localization.Code.BA;
    var locMK = Localization.Code.MK;
    var locSI = Localization.Code.SI;
    var languageCode = CurrentUser.Localizationi18n;
    var legislationBA = Legislation.BA;
    var legislationRS = Legislation.RS;
    var legislationBD = Legislation.BD;
    var currentLegislation = Model.Header.WorkerLegislation;
    var TODate = Model.Header.Date.Date.ToString("dd.MM.yyyy");
    ViewBag.IsPrintOpt = Model.Header.IsPrintOpt;
}

@Html.Hidden("currentLoc", currentLoc)
@Html.Hidden("locMK", locMK)
@Html.Hidden("locBA", locBA)
@Html.Hidden("locSL", locSI)
@Html.Hidden("startLocationAddress", Model.StartLocationAddress)
@Html.Hidden("endLocationAddress", Model.EndLocationAddress)
@Html.Hidden("DistancesCount", Model.DistanceViewModels.Count())
@Html.Hidden("LegislationBA", legislationBA)
@Html.Hidden("LegislationRS", legislationRS)
@Html.Hidden("LegislationBD", legislationBD)
@Html.Hidden("CurrentLegislation", currentLegislation)
@Html.Hidden("TODate", TODate)
@Html.Hidden("AcKeyIRIS", Model.AcKeyInUse)
@Html.Hidden("CostDrvError", Loc.CostDrvIsRequired)
@Html.Hidden("IsObligDept", Model.Header.IsObligDept)
@Html.Hidden("IsObligCostDrv", Model.Header.IsObligCostDrv)
@Html.Hidden("DocType", Model.Header.DocumentType)
@Html.Hidden("Archive", Model.Header.DocTypeDMS)
@Html.Hidden("Classification", Model.Header.ClassificationId)
@Html.Hidden("GoogleApiKey", Model.Header.GoogleApiKey)
@Html.Hidden("OpenDocumentUrl", Url.Action("Edit", "DocumentType", new { id = Model.Header.DocumentType }))
@Html.Hidden("CompanyPageUrl", Url.Action("Index", "Company", new { enterGoogleApiKey = true }))
@Html.Hidden("SaveTravelOrderUrl", Url.Action("Edit", "TravelOrderAllData"))

@section pageCss{
<link href="~/Content/plugins/icomoon/style.css" rel="stylesheet" />
}
<script type="text/javascript"
        src="@Url.Content(string.Format("https://maps.googleapis.com/maps/api/js?language={0}&libraries=places&key={1}",
        languageCode, Model.Header.GoogleApiKey))">
</script>

@Scripts.Render("~/bundles/travelorders")

<script>
    $(document).ready(function () {
        dropifyUpload();
        getDefaultCurrency();
        setDynamicTables();
        disableChangeAcKey();
    });
</script>

@Html.Partial("_HelperValues")

<div class="wrapper wrapper-content">
    <div class="tabs-container">

        @Html.Partial("~/Views/TravelOrderAllData/_TravelOrdersTabNavigation.cshtml")
        <div class="tab-content">
            @using (Html.BeginForm(action, "TravelOrderAllData", FormMethod.Post, new { @enctype = "multipart/form-data", @id = "pn-form", @novalidate = "novalidate" }))
            {
                @Html.Hidden("Print", Model.Print, new { Id = "isPrint" })

                @Html.Partial("~/Views/TravelOrderAllData/_TravelOrdersButtons.cshtml", Model.Header)

                <div class="divided-content">
                    <div class="divided-content-main travel-order-content modul-bg" id="mobile-wrapper-scrollable">

                        @if (string.IsNullOrWhiteSpace(Model.Header.AcKey))
                        {
                            <div class="placeholder placeholder-global-destination hidden-xs"><span class="placeholder-text">@Loc.TravelOrderPlaceholder</span></div>
                        }

                        @Html.Partial("_Header", Model.Header)
                        <br />

                        <div class="divided-content-scrollable-not-mobile">
                            @Html.Partial("_DistanceViewModel", Model.DistanceViewModels)
                        </div>

                        <div id="travel-orders-footer">
                            @Html.Partial("_Footer", Model.Totals)
                        </div>

                    </div>

                    <div class="divided-content-side z-index-4">
                        @Html.Partial("~/Views/TravelOrderAllData/_TravelOrdersTabs.cshtml", Model)
                    </div>
                </div>
            }
        </div>
    </div>
</div>

<div class="modal inmodal fade" id="subjectModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-xxl" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <a class="btn-transparent m-r-xs pull-right" href="@SiteHelpAttributeHelper.GetHelpUrl(HelpIds.ExampleSubjectsNewInModal)" target="_blank"><i class="fas fa-book-reader"></i></a>
                <h3 class="text-left container">@Loc.CreateNewSubject</h3>
            </div>
            <div class="modal-body">
                @{Html.RenderPartial("~/Views/Subjects/_CreateSubjectFormPartial.cshtml",
                new SubjectCreateViewModel()
                {
                SubjectEditData = new SubjectEditData() { SelectedCountryId = ViewBag.CountryName },
                Countries = ViewBag.Countries,
                ForCountry = PantheonRA.BackOffice.CurrentUser.Localization.ToString(),
                IsTravelOrder = true
                });}
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="saveSubjectInDistances()"><i class="fa fa-check m-r-xs"></i>@Loc.Add</button>
                <button type="button" data-dismiss="modal" class="btn btn-link"><i class="fa fa-times m-r-xs text-primary"></i>@Loc.Cancel</button>
            </div>
        </div>
    </div>
</div>

@Html.Partial("_NoteModal")
@Html.Partial("_IRIS", Model)
@Html.Partial("_GoogleAPIKeyIRIS", Model)
@Html.Partial("_GoogleAPIKeyExpiredIRIS", Model)
@Html.Partial("~/Views/Shared/Components/_CreateDocumentModals.cshtml")

@section pageScripts{
<script>
        $(document).ready(function () {
            initializeSubjectsEdit(true);
            initializeNewDistanceInput($('#NewNode'), { noResults: '@Loc.NoResults', company: '@Loc.Company', name: '@Loc.Name', address: '@Loc.Address', gridzipcode: '@Loc.GridZipCode' });
            if ($("#GoogleApiKey").val()) {
                initializePlacesSearch('street-search');
            }
        });
        showDistanceDateTimePicker();
        showExpenseDateTimePicker();
</script>
}