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

@{
    DateTime currentDate = DateTime.Now;
    var startMonthDate = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day);
    var endMonthDate = startMonthDate;
    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", "TimeAttendance", null,
    new AjaxOptions
    {
        UpdateTargetId = "AttendanceRecordsID",
        OnBegin = "startLoading('AttendanceRecordsID')",
        OnSuccess = "showTooltip();hideColumns();enableFilters();"
    },
    new { id = "attendance-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" style="margin-bottom:unset">
        <div class="col-md-2 col-sm-6 @(PantheonRA.BackOffice.CurrentUser.HasGranule(PantheonRA.WebApi.Contracts.Enums.Granules.WorkRosterGranule) ? "hidden" : string.Empty)">
            <div class="form-group selectpicker-dropdown">
                @Html.LabelFor(model => model.FilterRequest.Workers, Loc.Worker, new { @class = "control-label " })

                @Html.DropDownList(
                    "Workers",
                    new SelectList(Model.TimeRecordsFilterData.PermissionEmployees.Where(x => x.Active == ActiveStatus.Active), "WorkerCode", "WorkerName", PantheonRA.BackOffice.CurrentUser.EmployeeId),
                    Loc.All,
                    HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                        "Workers", false, Loc.Worker, true,
                        new { @multiple = "multiple", data_live_search = "true", @title = Loc.Worker }))
            </div>
        </div>
        <div class="col-md-2 col-sm-6 @(PantheonRA.BackOffice.CurrentUser.HasGranule(PantheonRA.WebApi.Contracts.Enums.Granules.WorkRosterGranule) ? "hidden" : string.Empty)">
            <div class="form-group selectpicker-dropdown">
                @Html.LabelFor(model => model.FilterRequest.Departments, Loc.Department, new { @class = "control-label" })
                @Html.DropDownList(
                    "Departments",
                    new SelectList(Model.TimeRecordsFilterData.Departments, "Name", "Name"), 
                    Loc.All,
                    HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                        "Departments", false, Loc.Department, true,
                        new { @multiple = "multiple", data_live_search = "true", @title = Loc.Department }))
            </div>
        </div>
        <div class="col-md-2 col-sm-6">
            <div class="form-group selectpicker-dropdown">
                @Html.LabelFor(model => model.FilterRequest.WorkObligations, Loc.CurrentStatus, new { @class = "control-label" })
                @Html.DropDownList("WorkObligations",
                    new SelectList(Model.TimeRecordsFilterData.WorkObligations, "Code", "Name"), 
                    Loc.All,
                    HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                        "WorkObligations", false, Loc.CurrentStatus, true,
                        new { @multiple = "multiple", data_live_search = "true", @title = Loc.CurrentStatus }))
            </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 select2"
                        data-search-width="200"
                        onchange="hideColumns()">
                    <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();hideColumns();", @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();hideColumns();", @autocomplete = "off" })
                </div>
            </div>
        </div>
        <div class="col-md-2 col-sm-6 @(PantheonRA.BackOffice.CurrentUser.HasGranule(PantheonRA.WebApi.Contracts.Enums.Granules.WorkRosterGranule) ? "hidden" : string.Empty)">
            <div class="form-group selectpicker-dropdown">
                @Html.LabelFor(model => model.FilterRequest.EmploymentStatuses, Loc.EmploymentStatus, new { @class = "control-label" })
                @Html.DropDownList("EmploymentStatuses",
                    new SelectList(Model.TimeRecordsFilterData.EmploymentStatueses, "Name", "Name"), 
                    Loc.All,
                    HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                        "EmploymentStatuses", false, Loc.EmploymentStatus, true,
                        new { @multiple = "multiple", data_live_search = "true", @title = Loc.EmploymentStatus }))
            </div>
        </div>
        <div class="col-md-1 col-sm-6 @(PantheonRA.BackOffice.CurrentUser.HasGranule(PantheonRA.WebApi.Contracts.Enums.Granules.WorkRosterGranule) ? "hidden" : string.Empty)">
            <div class="form-group multi-no-border selectpicker-dropdown">
                <label class="control-label">@Loc.Status</label>
                <select class="form-control selectpicker"
                        name="WorkingStatuses"
                        id="WorkingStatuses"
                        title="@Loc.Status"
                        data-search-width="100"
                        multiple>
                    <option value="@ActiveStatus.Active" selected="selected">@Loc.Active</option>
                    <option value="@ActiveStatus.Inactive">@Loc.Inactive</option>
                </select>
            </div>
        </div>
    </div>
}

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