@model PantheonRA.BackOffice.Models.TimeRecordViewModel
@using PantheonRA.BackOffice.Enums

@{
    DateTime currentDate = DateTime.Now;
    var startMonthDate = new DateTime(currentDate.Year, currentDate.Month, 1);
    var endMonthDate = DateTime.Now;
    var lastTen = currentDate.AddDays(-10).ToString(Loc.DateFormat);
    var lastMonth = currentDate.AddMonths(-1).ToString(Loc.DateFormat);
    var lastQuarter = currentDate.AddMonths(-3).ToString(Loc.DateFormat);
}

@using (Ajax.BeginForm(
    "Records", "TimeRecords", null,
    new AjaxOptions
    {
        UpdateTargetId = "RecordsID",
        OnSuccess = "hoverRow();hoverSaldoAndTotal();showTooltip();",
        OnComplete = "select2withAPI();formatEmployeeString();select2OnClick();"
    },
    new { id = "filter-form" }))
{
    @Html.Hidden("currentDate", currentDate.ToString(Loc.DateFormat))
    @Html.Hidden("startMonthDate", startMonthDate.ToString(Loc.DateFormat))
    @Html.Hidden("endMonthDate", endMonthDate.ToString(Loc.DateFormat))
    @Html.Hidden("lastTen", lastTen)
    @Html.Hidden("lastMonth", lastMonth)
    @Html.Hidden("lastQuarter", lastQuarter)
    <button type="submit" id="submit-filter-form" value="submit" hidden></button>

    <div class="row document-head filter-row hidden" style="margin-bottom:unset">
        <div class="col-md-2 col-sm-6">
            <div class="form-group">
                <label class="control-label">@Loc.Search</label>
                <input autocomplete="off"
                       class="form-control search-input"
                       id="Keywords"
                       name="Keywords"
                       placeholder="@Loc.Search"
                       type="text"
                       onkeyup="submitFilterForm('@string.Empty', true);" />
            </div>
        </div>
        <div class="col-md-2 col-sm-6 @(PantheonRA.BackOffice.CurrentUser.HasGranule(PantheonRA.WebApi.Contracts.Enums.Granules.WorkRosterGranule) ? "document-head-disabled-input" : string.Empty)">
            <div class="form-group timerecord-focus-bottom-border">
                <label>@Loc.Worker</label>
                <select name="Workers[0]"
                        id="Worker"
                        data-placeholder="@Loc.Worker"
                        class="form-control select2withAPI"
                        data-column-names="@Loc.Code,@Loc.LastName,@Loc.FirstName,@Loc.Job,@Loc.Department"
                        data-bootstrap-columns="col-md-3,col-md-2,col-md-2,col-md-2,col-md-3"
                        data-search-width="600"
                        onchange="submitFilterForm('@string.Empty', true); formatEmployeeString();"
                        data-url=@Url.Action("GetDropDownValues", "GlobalHelper", new {
                                        apiPath = "/v1/employees/personal-map-employees-lookupitems"}) >
                    <option value="@Model.TimeRecordModalViewModel.Worker" selected>@Model.TimeRecordModalViewModel.FullName</option>
                </select>
            </div>
        </div>
        <div class="col-md-2 col-sm-6">
            <div class="form-group selectpicker-dropdown">
                @Html.Label("WorkObligations", Loc.WorkObligation, new { @class = "control-label" })
                @Html.DropDownList("WorkObligations",
                    new SelectList(Model.TimeRecordModalViewModel.TimeRecordsFilterData.WorkObligations, "Code", "Name"), Loc.All,
                    HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                        "WorkObligations", false, Loc.WorkObligation, true,
                        new { @multiple = "multiple", data_live_search = "true", @title = Loc.WorkObligation }))
            </div>
        </div>
        <div class="col-md-2 col-sm-6">
            <div class="form-group selectpicker-dropdown">
                @Html.Label("Departments", Loc.Department, new { @class = "control-label" })
                @Html.DropDownList("Departments",
                    new SelectList(Model.TimeRecordModalViewModel.TimeRecordsFilterData.Departments, "Name", "Name"), Loc.All,
                    HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                        "Department", false, Loc.Department, true,
                        new { @multiple = "multiple", data_live_search = "true", @title = Loc.Department }))
            </div>
        </div>
        <div class="col-md-1 col-sm-6">
            <div class="form-group selectpicker-dropdown">
                @Html.Label("CostDrivers", Loc.CostCarrier, new { @class = "control-label" })
                @Html.DropDownList("CostDrivers",
                    new SelectList(Model.TimeRecordModalViewModel.TimeRecordsFilterData.CostDrivers, "Name", "Name"), Loc.All,
                    HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                        "CostCarrier", false, Loc.Department, true,
                        new { @multiple = "multiple", data_live_search = "true", @title = Loc.CostCarrier }))
            </div>
        </div>
        <div class="col-md-1 col-sm-6">
            <div class="form-group">
                <label>@Loc.DisplayType</label>
                <select id="WholesaleFilter"
                        name="Period"
                        class="form-control custom-select">
                    <option value="@ItemsDisplayFilterType.LastTen">@Loc.LastTen</option>
                    <option value="@ItemsDisplayFilterType.LastMonth">@Loc.LastMonth</option>
                    <option value="@ItemsDisplayFilterType.LastQuarter">@Loc.LastQuarter</option>
                    <option value="@ItemsDisplayFilterType.CustomDate" selected="selected">@Loc.CustomDate</option>
                </select>
            </div>
        </div>
        <div class="col-md-1 col-sm-6">
            <div class="form-group">
                <label class="control-label">@Loc.From</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="far fa-calendar alt"></i></span>
                    @Html.TextBox("DateStart", startMonthDate,
                        new { @id = "Filter_DateFrom", @class = "form-control custom-datepicker", @onchange = "submitFilterForm('Filter_DateFrom', true);", @autocomplete = "off" })
                </div>
            </div>
        </div>
        <div class="col-md-1 col-sm-6">
            <div class="form-group">
                <label class="control-label">@Loc.To</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="far fa-calendar alt"></i></span>
                    @Html.TextBox("DateEnd", endMonthDate,
                        new { @id = "Filter_DateTo", @class = "form-control custom-datepicker", @onchange = "submitFilterForm('Filter_DateTo', true);", @autocomplete = "off" })
                </div>
            </div>
        </div>
    </div>
}

<form class="hidden" action="@Url.Action("PrintPDF", "TimeRecords")" method="post" id="report-form" target="_blank">
    <input name="Workers[0]" id="pdf-worker" value="@Model.TimeRecordModalViewModel.Worker" />
    <input name="DateStart" id="pdf-datestart" value="@startMonthDate" />
    <input name="DateEnd" id="pdf-dateend" value="@endMonthDate" />
    <input name="IsAttendanceReport" class="attendance-report-input" value="false" />
</form>