LocalGovIMS_localgov-ims/src/Admin/Views/Transaction/_Refund.cshtml
@model Admin.Models.Transaction.RefundViewModel

@if (User.IsInRole(Role.TransactionRefund))
{
    <div class="modal fade modal-lg" id="refundModal" tabindex="-1" aria-labelledby="refundModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h1 class="modal-title fs-5" id="refundModalLabel">Create refund</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>

                <div class="modal-body">

                    <div class="alert alert-info mb-3">
                        <div class="fw-bold pb-1">
                            Remember
                        </div>
                        <p class="mb-0">You can only have one refund in progress per transaction, additional refunds to this transaction will be blocked until this one completes</p>
                    </div>

                    @using (Html.BeginForm("Refund", "Transaction", new { }, FormMethod.Post, new { id = "refund-form" }))
                    {

                        <div class="table-responsive">
                            <table class="table table-striped table-bordered mt-2">
                                <thead>
                                    <tr>
                                        <th scope="col">Type</th>
                                        <th scope="col">Account</th>
                                        <th scope="col">Narrative</th>
                                        <th scope="col">Original amount (£)</th>
                                        <th scope="col">Remaining amount (£)</th>
                                        <th scope="col" id="RefundAmountLabel">Refund amount (£)</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @for (int i = 0; i < Model.RefundItems.Count; i++)
                                    {
                                        <tr>
                                            <td>@Model.RefundItems[i].Transaction.Fund.FundName</td>
                                            <td>@Model.RefundItems[i].Transaction.AccountReference</td>
                                            <td>@Model.RefundItems[i].Transaction.Narrative</td>
                                            <td class="text-end">@Html.ToCurrency(Model.RefundItems[i].Transaction.Amount)</td>
                                            <td class="text-end">@Html.ToCurrency(Model.RefundItems[i].RemainingAmount)</td>
                                            <td class="text-end">
                                                @Html.HiddenFor(m => Model.RefundItems[i].Transaction.TransactionReference)
                                                @if (Model.RefundItems[i].RemainingAmount > 0)
                                                { 
                                                    if (User.IsInRole(Role.TransactionPartialRefund)) // todo: add role check for partial refund - make sure to check this in controller too.
                                                    {
                                                        @Html.TextBoxFor(x => x.RefundItems[i].RefundAmount, new { @class = "form-control monetary-amount", @aria_labelledby = "RefundAmountLabel" })
                                                    }
                                                    else
                                                    {
                                                        <input type="checkbox" name="@Html.NameFor(x => x.RefundItems[i].RefundAmount)" value="@Model.RefundItems[i].RemainingAmount" aria-labelledby="RefundAmountLabel" />
                                                    }
                                                }
                                                else
                                                {
                                                    <span>Unavailable</span>
                                                }
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>

                        @Html.HiddenFor(x => x.Reference)

                        <div class="row mb-3">
                            <div class="col">
                                @Html.LabelFor(m => m.RefundReason, new { @class = "form-label" })
                                @Html.TextAreaFor(m => m.RefundReason, new { @class = "form-control", rows = "3", cols = "60" })
                                <div class="form__element--error">
                                    @Html.ValidationMessageFor(m => m.RefundReason)
                                </div>
                            </div>
                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                            <button type="button" class="btn btn-primary send-email one-click-submit-button" id="refund-submit">Submit refund</button>
                        </div>
                    }
                </div>

            </div>
        </div>
    </div>
}