@model AddressAttributeModel

@if (Model.Id > 0)
{
    <div class="card-body">
        @await Html.PartialAsync("Table", new DataTablesModel
        {
            Name = "addressattributevalues-grid",
            UrlRead = new DataUrl("ValueList", "AddressAttribute", new RouteValueDictionary { [nameof(AddressAttributeValueSearchModel.AddressAttributeId)] = Model.Id }),
            UrlDelete = new DataUrl("ValueDelete", "AddressAttribute", null),
            Length = Model.AddressAttributeValueSearchModel.PageSize,
            LengthMenu = Model.AddressAttributeValueSearchModel.AvailablePageSizes,
            ColumnCollection = new List<ColumnProperty>
            {
                new ColumnProperty(nameof(AddressAttributeValueModel.Name))
                {
                    Title = T("Admin.Address.AddressAttributes.Values.Fields.Name").Text
                },
                new ColumnProperty(nameof(AddressAttributeValueModel.IsPreSelected))
                {
                    Title = T("Admin.Address.AddressAttributes.Values.Fields.IsPreSelected").Text,
                    Width = "10",
                    ClassName = NopColumnClassDefaults.CenterAll,
                    Render = new RenderBoolean()
                },
                new ColumnProperty(nameof(AddressAttributeValueModel.DisplayOrder))
                {
                    Title = T("Admin.Address.AddressAttributes.Values.Fields.DisplayOrder").Text,
                    Width = "100",
                    ClassName =  NopColumnClassDefaults.CenterAll
                },
                new ColumnProperty(nameof(AddressAttributeValueModel.Id))
                {
                    Title = T("Admin.Common.Edit").Text,
                    ClassName = NopColumnClassDefaults.Button,
                    Width = "100",
                    Render = new RenderCustom("renderColumnEdit")
                },
                new ColumnProperty(nameof(AddressAttributeValueModel.Id))
                {
                    Title = T("Admin.Common.Delete").Text,
                    ClassName = NopColumnClassDefaults.Button,
                    Render = new RenderButtonRemove(T("Admin.Common.Delete").Text),
                    Width = "100"
                }
            }
        })
    </div>
    <div class="card-footer">
        <button type="submit" id="btnAddNewValue" onclick="javascript:OpenWindow('@(Url.Action("ValueCreatePopup", "AddressAttribute", new { addressAttributeId = Model.Id, btnId = "btnRefresh", formId = "addressattribute-form" }))', 800, 400, true); return false;" class="btn btn-primary">
            @T("Admin.Address.AddressAttributes.Values.AddNew")
        </button>
        <button type="submit" id="btnRefresh" style="display: none"></button>
        <script>
                function renderColumnEdit(data, type, row, meta) {
                    return '<button onclick=\"javascript:OpenWindow(\'@Url.Content("~/Admin/AddressAttribute/ValueEditPopup/")' + data + '?btnId=btnRefresh&formId=addressattribute-form\', 800, 800, true); return false;\" class="btn btn-default"><i class="fas fa-pencil"></i>@T("Admin.Common.Edit").Text</button>';
                }

                $(function() {
                    $('#btnRefresh').click(function () {
                        //refresh grid
                        updateTable('#addressattributevalues-grid');

                        //return false to don't reload a page
                        return false;
                    });
                });
        </script>
    </div>
}
else
{
    <div class="card-body">
        @T("Admin.Address.AddressAttributes.Values.SaveBeforeEdit")
    </div>
}