@using BTCPayServer.Services.PaymentRequests
@model BTCPayServer.Models.PaymentRequestViewModels.UpdatePaymentRequestViewModel
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers

<section>
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h2 class="section-heading">@(string.IsNullOrEmpty(Model.Id) ? "Create" : "Edit") Payment Request</h2>
                <hr class="primary">
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 text-center">
                <partial name="_StatusMessage" for="StatusMessage"/>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <form method="post" action="@Url.Action("EditPaymentRequest", "PaymentRequest", new { id = Model.Id}, Context.Request.Scheme)">
                    <input type="hidden" name="Id" value="@Model.Id"/>
                    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                    <div class="form-group">
                        <label asp-for="Title" class="control-label"></label>*
                        <input asp-for="Title" class="form-control"/>
                        <span asp-validation-for="Title" class="text-danger"></span>
                    </div>

                    <div class="form-group">
                        <label asp-for="Amount" class="control-label"></label>*
                        <input type="number" step="any" asp-for="Amount" class="form-control"/>
                        <span asp-validation-for="Amount" class="text-danger"></span>
                    </div>

                    <div class="form-group">
                        <label asp-for="Currency" class="control-label"></label>*
                        <input  asp-for="Currency" class="form-control"/>
                        <span asp-validation-for="Currency" class="text-danger"></span>
                    </div>
                    <div class="form-group">
                        <label asp-for="AllowCustomPaymentAmounts"></label>
                        <input asp-for="AllowCustomPaymentAmounts" type="checkbox" class="form-check"/>
                        <span asp-validation-for="AllowCustomPaymentAmounts" class="text-danger"></span>
                    </div>
                    <div class="form-group">

                        <label asp-for="StoreId" class="control-label"></label>
                        @if (string.IsNullOrEmpty(Model.Id))
                        {
                            <select asp-for="StoreId" asp-items="Model.Stores" class="form-control"></select>
                        }
                        else
                        {
                            <input type="hidden" asp-for="StoreId" value="@Model.StoreId"/>
                            <input type="text" class="form-control" value="@Model.Stores.Single(item => item.Value == Model.StoreId).Text" readonly/>
                        }

                        <span asp-validation-for="StoreId" class="text-danger"></span>

                    </div>
                    <div class="form-group">
                        <label asp-for="Email" class="control-label"></label>
                        <input type="email" asp-for="Email" class="form-control"></input>
                        <span asp-validation-for="Email" class="text-danger"></span>
                    </div>
                    <div class="form-group">
                        <label asp-for="ExpiryDate" class="control-label"></label>
                        <div class="input-group ">
                            <input asp-for="ExpiryDate" class="form-control datetime" min="today" placeholder="No expiry date has been set for this payment request"/>
                            <div class="input-group-append">

                                <button class="btn btn-secondary input-group-clear" type="button" title="Clear">
                                    <span class=" fa fa-times"></span>
                                </button>
                            </div>
                        </div>
                        <span asp-validation-for="ExpiryDate" class="text-danger"></span>
                    </div>
                    <div class="form-group">
                        <label asp-for="Description" class="control-label"></label>
                        <textarea asp-for="Description" class="form-control richtext"></textarea>
                        <span asp-validation-for="Description" class="text-danger"></span>
                    </div>
                    <div class="form-group">
                        <label asp-for="CustomCSSLink" class="control-label"></label>
                        <a href="https://docs.btcpayserver.org/development/theme#bootstrap-themes" target="_blank">
                            <span class="fa fa-question-circle-o" title="More information..."></span>
                        </a>
                        <input asp-for="CustomCSSLink" class="form-control"/>
                        <span asp-validation-for="CustomCSSLink" class="text-danger"></span>
                    </div>
                    <div class="form-group">
                        <label asp-for="EmbeddedCSS" class="control-label"></label>
                        <textarea asp-for="EmbeddedCSS" rows="10" cols="40" class="form-control"></textarea>
                        <span asp-validation-for="EmbeddedCSS" class="text-danger"></span>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-primary">Save</button>
                        @if (!string.IsNullOrEmpty(Model.Id))
                        {
                            <a class="btn btn-secondary" target="_blank" asp-action="ViewPaymentRequest" id="@Model.Id">View</a>
                            <a class="btn btn-secondary" 
                               target="_blank"
                               asp-action="ListInvoices"
                               asp-controller="Invoice" 
                               asp-route-searchterm="@($"orderid:{PaymentRequestRepository.GetOrderIdForPaymentRequest(Model.Id)}")">Invoices</a>
                            <a class="btn btn-secondary" asp-action="ClonePaymentRequest" id="@Model.Id">Clone</a>                                                                              
                        }
                        <a class="btn btn-secondary" target="_blank" asp-action="GetPaymentRequests">Back to list</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>

@section Scripts {

    <bundle name="wwwroot/bundles/payment-request-admin-bundle.min.js"></bundle>
    <bundle name="wwwroot/bundles/payment-request-admin-bundle.min.css"></bundle>
}
