@model PantheonRA.BackOffice.Models.PoaFileMetadataViewModel

@{
    var isReadonly = Model.IsReadonly;
}

@if (Model != null && Model.Metadata != null && Model.Metadata.Any())
{
    for (var i = 0; i < Model.Metadata.Count; i++)
    {
        @MetadataInput(Model.Metadata[i], Html.NameFor(model => Model.Metadata[i]), isReadonly)
    }
}


@helper MetadataInput(PantheonRA.WebApi.Contracts.PaTaskMetadata metadata, MvcHtmlString componentName, bool isReadonly)
{
    var inputClass = "";
    if (metadata.Obligatory)
    {
        inputClass += "obligatory-input ";
    }
    if (metadata.Type == PantheonRA.BackOffice.Enums.MetadataType.Date)
    {
        inputClass += "datepicker ";
    }
    if (metadata.Type == PantheonRA.BackOffice.Enums.MetadataType.Decimal)
    {
        inputClass += "numberInput ";
    }

    var dataUrl = "";
    var dataColumnNames = "";
    var dataBootstrapColumns = "";

    if(metadata.Setter == "ltSubj" || metadata.Setter == "ltDobavitelj" || metadata.Setter == "ltKupec")
    {
        dataUrl = Url.Action("GetSubjectsLookupItems", "PoaClassification");
        dataColumnNames = string.Format("{0},{1},{2},{3}", Loc.Company,Loc.Name,Loc.Address,Loc.Post);
        dataBootstrapColumns = "col-md-4,col-md-4,col-md-3,col-md-1";
    }
    else if (metadata.Setter == "ltMNClassification")
    {
        dataUrl = Url.Action("GetClassificationsLookupItems", "PoaClassification");
        dataColumnNames = string.Format("{0},{1}", Loc.Description,Loc.Code);
        dataBootstrapColumns = "col-md-6,col-md-6";
    }
    else if (metadata.Setter == "ltPoslDog")
    {
        dataUrl = Url.Action("GetDocumentTypeLookupItems", "PoaClassification");
        dataColumnNames = string.Format("{0},{1}", Loc.DocType,Loc.Name);
        dataBootstrapColumns = "col-md-6,col-md-6";
    }
        else if (metadata.Setter == "ltOddelekAct")
    {
        dataUrl = Url.Action("GetDepartmentsLookupItems", "PoaClassification");
        dataColumnNames = string.Format("{0},{1},{2}", Loc.Department,Loc.Name + " 2", Loc.Name + " 3");
        dataBootstrapColumns = "col-md-6,col-md-3,col-md-3";
    }
        else if 
        (
            metadata.Setter == "ltSTRNO" 
            || metadata.Setter == "ltSTRN"
        )
    {
        dataUrl = Url.Action("GetCasesLookupItems", "PoaClassification");
        dataColumnNames = string.Format("{0}, {1}", Loc.CaseNumber, Loc.Subject);
        dataBootstrapColumns = "col-md-6,col-md-6";
    }

    <div class="form-group poa-metadata-item">
        <label class="control-label" for="@Html.NameFor(model => metadata.Value)" title="@metadata.OutputName">@metadata.OutputName</label>
        <div>
            @if (string.IsNullOrEmpty(metadata.Setter))
            {
                <input autocomplete="off" class="form-control @inputClass" name="@(componentName + "." + Html.DisplayNameFor(model => metadata.Value))"
                       placeholder="@metadata.OutputName" type="text" value="@metadata.Value" @(isReadonly ? "disabled" : "")>
            }
            else
            {
                    <select id="poa-metadata-dropdown-@metadata.MetadataId"
                            name="@(componentName + "." + Html.DisplayNameFor(model => metadata.Value))"
                            data-placeholder="@metadata.OutputName"
                            class="form-control select2withAPI @inputClass"
                            data-url="@dataUrl"
                            data-column-names="@dataColumnNames"
                            data-bootstrap-columns=@dataBootstrapColumns
                            data-splitter=","
                            data-allow-clear="true"
                            data-search-width="800">
                        <option value="@metadata.Value" selected>@(string.IsNullOrEmpty(metadata.Display) ? metadata.Value : metadata.Display)</option>
                    </select>
                }
            <span class="poa-validation" style="color:#BB5534" hidden></span>
        </div>
        <input type="hidden" value="@metadata.MetadataId" name="@(componentName + "." + Html.DisplayNameFor(model => metadata.MetadataId))" />
        <input type="hidden" value="@metadata.Setter" name="@(componentName + "." + Html.DisplayNameFor(model => metadata.Setter))" />
        <input type="hidden" value="@metadata.Type" name="@(componentName + "." + Html.DisplayNameFor(model => metadata.Type))" />
        <input type="hidden" value="@metadata.OutputName" name="@(componentName + "." + Html.DisplayNameFor(model => metadata.OutputName))" />
        <input type="hidden" value="@metadata.Message" name="@(componentName + "." + Html.DisplayNameFor(model => metadata.Message))" />
        <input type="hidden" value="@metadata.Obligatory.ToString()" name="@(componentName + "." + Html.DisplayNameFor(model => metadata.Obligatory))" />
    </div>
}