@model RecurringPaymentModel

<div class="card-body">
    @if (Model.LastPaymentFailed)
    {
        <div class="form-group row">
            <div class="col-md-12">
                @T("Admin.RecurringPayments.History.LastPaymentFailed")
            </div>
        </div>
    }
    @if (!string.IsNullOrEmpty(Model.NextPaymentDate))
    {
        <div class="form-group row">
            <div class="col-md-12">
                @T("Admin.RecurringPayments.History.NextPaymentDate")
                <text>:</text>
                @Model.NextPaymentDate
            </div>
        </div>
    }
    @if (!string.IsNullOrEmpty(Model.NextPaymentDate) || Model.CanCancelRecurringPayment)
    {
        <div class="form-group row">
            <div class="col-md-12">
                @if (!string.IsNullOrEmpty(Model.NextPaymentDate))
                {
                    <button type="submit" name="processnextpayment" class="btn btn-success">
                        @T("Admin.RecurringPayments.History.ProcessNextPayment")
                    </button>
                }
                @if (Model.CanCancelRecurringPayment)
                {
                    <button type="submit" name="cancelpayment" class="btn btn-secondary">
                        @T("Admin.RecurringPayments.History.CancelPayment")
                    </button>
                }
            </div>
        </div>
    }

    @await Html.PartialAsync("Table", new DataTablesModel
    {
        Name = "history-grid",
        UrlRead = new DataUrl("HistoryList", "RecurringPayment", new RouteValueDictionary { [nameof(Model.RecurringPaymentHistorySearchModel.RecurringPaymentId)] = Model.RecurringPaymentHistorySearchModel.RecurringPaymentId }),
        Length = Model.RecurringPaymentHistorySearchModel.PageSize,
        LengthMenu = Model.RecurringPaymentHistorySearchModel.AvailablePageSizes,
        ColumnCollection = new List<ColumnProperty>
        {
            new ColumnProperty(nameof(RecurringPaymentHistoryModel.CustomOrderNumber))
            {
                Title = T("Admin.RecurringPayments.History.CustomOrderNumber").Text,
                ClassName =  NopColumnClassDefaults.Button,
                Width = "200",
                Render = new RenderCustom("renderColumnOrderInfo")
            },
            new ColumnProperty(nameof(RecurringPaymentHistoryModel.OrderStatus))
            {
                Title = T("Admin.RecurringPayments.History.OrderStatus").Text,
                Width = "200"
            },
            new ColumnProperty(nameof(RecurringPaymentHistoryModel.PaymentStatus))
            {
                Title = T("Admin.RecurringPayments.History.PaymentStatus").Text,
                Width = "200"
            },
            new ColumnProperty(nameof(RecurringPaymentHistoryModel.ShippingStatus))
            {
                Title = T("Admin.RecurringPayments.History.ShippingStatus").Text,
                Width = "200"
            },
            new ColumnProperty(nameof(RecurringPaymentHistoryModel.CreatedOn))
            {
                Title = T("Admin.RecurringPayments.History.CreatedOn").Text,
                Width = "100",
                Render = new RenderDate()
            }
        }
    })
    <script asp-location="Footer">
        function renderColumnOrderInfo(data, type, row, meta) {
            if (row.OrderId > 0) {
                var textRenderer = $.fn.dataTable.render.text().display;
                return '<a class="btn btn-default" href="@Url.Content("~/Admin/Order/Edit/")' + row.OrderId + '"><i class="far fa-eye"></i>' + textRenderer(row.CustomOrderNumber) + ' - @T("Admin.Common.View").Text</a>';
            } else {
                return 'order item is deleted';
            }
        }
    </script>
</div>