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

@{
    var dailyAllowNum = (int)ViewBag.Enumerator;
    var dailyAllowAnNo = (int)ViewBag.DistanceAnNo;
    bool isDomestic = (bool)ViewBag.IsDomestic;
    var hideOnDomestic = isDomestic ? "hidden" : string.Empty;

    bool isLocalizationBA = Loc.CurrentLocalization == Localization.Code.BA;
    bool isLocalizationMK = Loc.CurrentLocalization == Localization.Code.MK;
    bool isLocalizationSL = Loc.CurrentLocalization == Localization.Code.SI;
    bool isLocalizationME = Loc.CurrentLocalization == Localization.Code.ME;
    bool isLocalizationHR = Loc.CurrentLocalization == Localization.Code.HR;

    var hideOnLocalizationBA = isLocalizationBA ? "hidden" : string.Empty;
    var hideOnLocalizationMK = isLocalizationMK ? "hidden" : string.Empty;
    var hideOnLocalizationME = isLocalizationME ? "hidden" : string.Empty;
    var hideOnLocalizationHR = isLocalizationHR ? "hidden" : string.Empty;

    var workerLegislation = (string)ViewBag.Legislation;
    var hideOnLegislationBA = workerLegislation == Legislation.BA ? "hidden" : string.Empty;

    var hideOnDomesticMK = isDomestic && isLocalizationMK ? "hidden" : string.Empty;
    var hideOnDomesticNotBANotHR = isDomestic && !isLocalizationBA && !isLocalizationHR ? "hidden" : string.Empty;

    bool isSLInternationalC = !isDomestic && isLocalizationSL ? true : false;

    var currencyId = string.Format("{0}-{1}", "Currency", dailyAllowNum);
    var fxRateId = string.Format("{0}-{1}", "anFxRate", dailyAllowNum);
    var dailyAllowNoId = string.Format("{0}-{1}", "anDailyAllowNo", dailyAllowNum);
    var priceDailyAllowId = string.Format("{0}-{1}", "anPriceDailyAllow", dailyAllowNum);
    var valueId = string.Format("{0}-{1}", "Value", dailyAllowNum);
    var defaultFxRate = DailyAllowTypes.DefaultFxRate;
    var defaultFactor = DailyAllowTypes.DefaultFactor;
}

@Html.Hidden("isSLInternationalC", isSLInternationalC)

<tr id="DailyAllowsCreate-@dailyAllowNum" class="to-dailyallow-create">

    <td class="hidden">
        @Html.Hidden("Deleted", "", new { @name = "Deleted", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowDeleted") })
        @Html.Hidden("AddManual", true, new { @name = "AddManual", @id = string.Format("{0}-{1}", dailyAllowNum, "AddManual") })
        @Html.Hidden("AnNo", dailyAllowAnNo, new { @name = "AnNo", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowAnNo"), @resetValue = "false" })
        @Html.Hidden("Country", "", new { @name = "Country", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowCountry") })
        @Html.Hidden("CZakonodaja", "SI", new { @name = "CZakonodaja", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowCZakonodaja") })
        @Html.Hidden("DailyAllowOrdinalNumber", "", new { @name = "DailyAllowOrdinalNumber", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowDailyAllowOrdinalNumber") })
        @Html.Hidden("IsDomestic", "", new { @name = "IsDomestic", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowIsDomestic") })
        @Html.Hidden("IsFromSixToEight", "", new { @name = "IsFromSixToEight", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowIsFromSixToEight") })
        @Html.Hidden("lIsInstallGE", "F", new { @name = "lIsInstallGE", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowlIsInstallGE") })
        @Html.Hidden("PriceFullDailyAllow", "", new { @name = "PriceFullDailyAllow", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowPriceFullDailyAllow") })
        @Html.Hidden("PriceHalfDailyAllow", "", new { @name = "PriceHalfDailyAllow", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowPriceHalfDailyAllow") })
        @Html.Hidden("PriceReducedDailyAllow", "", new { @name = "PriceReducedDailyAllow", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowPriceReducedDailyAllow") })
        @Html.Hidden("QId", "", new { @name = "QId", @id = string.Format("{0}-{1}", dailyAllowNum, "DailyAllowQId") })
    </td>
    <td label="@Loc.DailyAllow">
        <div style="width: 100%" onclick="expandTravelOrderRow('DailyAllowsTable-@dailyAllowNum', '-1', true);">
            <select id="@string.Format("{0}-{1}","DailyAllow",dailyAllowNum)"
                    name="DailyAllow"
                    required
                    class="form-control select2withAPI"
                    allow-clear="true"
                    data-placeholder="@Loc.DailyAllow"
                    data-column-names="@Loc.DailyAllow,@Loc.Country"
                    data-bootstrap-columns="col-md-6,col-md-6"
                    data-search-width="400"
                    data-dropdown-height="300"
                    data-selector-separator=", "
                    onchange="setDailyAllows('@dailyAllowNum');
                              SetDailyAllowFxRate('@dailyAllowNum', '@currencyId', '@fxRateId', '@dailyAllowNoId', '@priceDailyAllowId', '@valueId')"
                    data-url=@Url.Action("GetDailyAllowTypes", "TravelOrdersDailyAllows")></select>
        </div>
    </td>

    <td label="@Loc.DailyAllowNo">
        <input type="text"
               id="@string.Format("{0}-{1}","anDailyAllowNo",dailyAllowNum)"
               name="anDailyAllowNo"
               required
               class="form-control thousands-with-decimals"
               placeholder="@Loc.DailyAllowNo"
               onchange="SetDailyAllowFxRate('@dailyAllowNum', '@currencyId', '@fxRateId', '@dailyAllowNoId', '@priceDailyAllowId', '@valueId')"
               value="" />
    </td>

    <td label="@Loc.DailyAllowAmount">
        <input type="text"
               id="@string.Format("{0}-{1}","anPriceDailyAllow",dailyAllowNum)"
               name="anPriceDailyAllow"
               required
               class="form-control thousands-with-decimals"
               placeholder="@Loc.DailyAllowAmount"
               onchange="SetDailyAllowFxRate('@dailyAllowNum', '@currencyId', '@fxRateId', '@dailyAllowNoId', '@priceDailyAllowId', '@valueId')"
               value="" />
    </td>

    <td label="@Loc.Breakfast" class="text-center @hideOnLocalizationME @hideOnDomesticMK @hideOnLocalizationHR da-breakfast">
        <input type="checkbox"
               class="travelorders-checkbox custom-checkbox"
               id="@string.Format("{0}-{1}","IsBreakfastIncluded", dailyAllowNum)"
               name="IsBreakfastIncluded"
               value=""
               onchange="setCheckedValue(this.id,
                            '@string.Format("{0}-{1}", "IsLunchIncluded", dailyAllowNum)',
                            '@string.Format("{0}-{1}", "IsDinnerIncluded", dailyAllowNum)',
                            '@string.Format("{0}-{1}","anDailyAllowNo",dailyAllowNum)');
                         setPercentageOnCreate(@dailyAllowNum);" />
    </td>

    <td label="@Loc.Lunch" class="text-center @hideOnLocalizationME @hideOnDomesticMK @hideOnDomesticNotBANotHR da-lunch">
        <input type="checkbox"
               class="travelorders-checkbox custom-checkbox"
               id="@string.Format("{0}-{1}", "IsLunchIncluded", dailyAllowNum)"
               name="IsLunchIncluded"
               value=""
               onchange="setCheckedValue(this.id,
                            '@string.Format("{0}-{1}", "IsBreakfastIncluded", dailyAllowNum)',
                            '@string.Format("{0}-{1}", "IsDinnerIncluded", dailyAllowNum)',
                            '@string.Format("{0}-{1}","anDailyAllowNo",dailyAllowNum)');
                         setPercentageOnCreate(@dailyAllowNum);" />
    </td>

    <td label="@Loc.Dinner" class="text-center legislationRSBD @hideOnLocalizationME @hideOnDomesticMK @hideOnDomesticNotBANotHR @hideOnLegislationBA da-dinner">
        <input type="checkbox"
               class="travelorders-checkbox custom-checkbox"
               id="@string.Format("{0}-{1}", "IsDinnerIncluded", dailyAllowNum)"
               name="IsDinnerIncluded"
               value=""
               onchange="setCheckedValue(this.id,
                            '@string.Format("{0}-{1}", "IsBreakfastIncluded", dailyAllowNum)',
                            '@string.Format("{0}-{1}", "IsLunchIncluded", dailyAllowNum)',
                            '@string.Format("{0}-{1}","anDailyAllowNo",dailyAllowNum)');
                         setPercentageOnCreate(@dailyAllowNum);" />
    </td>

    <td label="@Loc.Factor" class="@hideOnLocalizationME @hideOnDomesticMK">
        <input type="text"
               id="@string.Format("{0}-{1}","CalcFactor", dailyAllowNum)"
               name="CalcFactor"
               class="form-control"
               placeholder="@Loc.Factor"
               value="@defaultFactor"
               readonly />
    </td>


    <td label="@Loc.DailyAllowBonus" class="@hideOnLocalizationME @hideOnLocalizationMK @hideOnLocalizationBA">
        <input type="text"
               id="@string.Format("{0}-{1}","anPriceFieldBonus", dailyAllowNum)"
               name="anPriceFieldBonus"
               class="form-control thousands-with-decimals"
               placeholder="@Loc.DailyAllowBonus"
               value="" />
    </td>

    <td label="@Loc.Value">
        <input type="text"
               id="@string.Format("{0}-{1}","Value", dailyAllowNum)"
               name="Value"
               class="form-control"
               placeholder="@Loc.Value"
               value="" />
    </td>

    <td label="@Loc.Currency">
        <select id="@string.Format("{0}-{1}","Currency", dailyAllowNum)"
                name="Currency"
                required
                class="form-control select2withAPI default-currency"
                data-placeholder="@Loc.Currency"
                onchange="SetDailyAllowFxRate('@dailyAllowNum', '@currencyId', '@fxRateId', '@dailyAllowNoId', '@priceDailyAllowId', '@valueId')"
                data-url=@Url.Action("GetDropDownValues", "GlobalHelper", new { apiPath = "/v1/travel-orders/expenses/currencies-lookupitems" })></select>
    </td>

    <td label="@Loc.FxRate">
        <input type="text"
               id="@string.Format("{0}-{1}","anFxRate", dailyAllowNum)"
               name="anFxRate"
               class="form-control"
               placeholder="@Loc.FxRate"
               value="@defaultFxRate" />
    </td>

    <td>
        <button id="addDailyAllow"
                type="button"
                onclick="AddNewRow('#DailyAllowsCreate-@dailyAllowNum', '#DailyAllowsPrefix-@dailyAllowNum', '#DailyAllowsTable-@dailyAllowNum');
           setDefaultCurrency('@currencyId')"
                class="btn btn-success add-del-allow-expense">
            <i class="fa fa-plus"></i>
        </button>
    </td>

</tr>