@model ConfigurationModel

@using Nop.Services
@using Nop.Plugin.Payments.Square
@using Nop.Plugin.Payments.Square.Domain
@using Nop.Plugin.Payments.Square.Models
@inject Nop.Core.IWebHelper webHelper

@{
    Layout = "_ConfigurePlugin";
}

<script>
    $(document).ready(function () {
        $('#@Html.IdFor(model => model.UseSandbox)').click(toggleUseSandbox);
        toggleUseSandbox();
    });

    function toggleUseSandbox() {
        if ($('#@Html.IdFor(model => model.UseSandbox)').is(':checked')) {
            $('#groupApplicationSecret').hide();
            $('#liveAccessToken').hide();
            $('#sandboxAccessToken').show();
            $('#liveApplicationId').hide();
            $('#sandboxApplicationId').show();
        } else {
            $('#groupApplicationSecret').show();
            $('#liveAccessToken').show();
            $('#sandboxAccessToken').hide();
            $('#liveApplicationId').show();
            $('#sandboxApplicationId').hide();
        }
    }
</script>

<form asp-controller="PaymentSquare" asp-action="Configure" method="post">
    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                @Html.Raw(string.Format(T("Plugins.Payments.Square.Instructions").Text, Url.RouteUrl(SquarePaymentDefaults.AccessTokenRoute, null, webHelper.CurrentRequestProtocol)))
                <div class="form-group">
                    <div class="col-md-3">
                        <nop-label asp-for="UseSandbox" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="UseSandbox" />
                        <span asp-validation-for="UseSandbox"></span>
                    </div>
                </div>
                <div class="form-group" id="sandboxApplicationId">
                    <div class="col-md-3">
                        <nop-label asp-for="SandboxApplicationId" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="SandboxApplicationId" asp-required="true" />
                        <span asp-validation-for="SandboxApplicationId"></span>
                    </div>
                </div>
                <div class="form-group" id="liveApplicationId">
                    <div class="col-md-3">
                        <nop-label asp-for="ApplicationId" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="ApplicationId" asp-required="true" />
                        <span asp-validation-for="ApplicationId"></span>
                    </div>
                </div>
                <div class="form-group" id="groupApplicationSecret">
                    <div class="col-md-3">
                        <nop-label asp-for="ApplicationSecret" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="ApplicationSecret" asp-required="true" asp-value="@Model.ApplicationSecret" />
                        <span asp-validation-for="ApplicationSecret"></span>
                    </div>
                </div>
                <div class="form-group" id="sandboxAccessToken">
                    <div class="col-md-3">
                        <nop-label asp-for="SandboxAccessToken" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="SandboxAccessToken" asp-required="true" asp-value="@Model.SandboxAccessToken" />
                        <span asp-validation-for="SandboxAccessToken"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        <nop-label asp-for="LocationId" />
                    </div>
                    <div class="col-md-9">
                        <nop-select asp-for="LocationId" asp-items="Model.Locations" asp-required="true" />
                        <span asp-validation-for="LocationId"></span>
                    </div>
                </div>
                <div class="form-group" id="liveAccessToken">
                    <div class="col-md-3">
                        <nop-label asp-for="AccessToken" />
                    </div>
                    <div class="col-md-9">
                        <div class="input-group input-group-required">
                            <nop-editor asp-for="AccessToken" asp-value="@Model.AccessToken" asp-disabled="true" />
                            <div class="input-group-btn">
                                <button type="submit" name="obtainAccessToken" class="btn btn-info">
                                    @T("Plugins.Payments.Square.ObtainAccessToken")
                                </button>
                                <nop-required />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        <nop-label asp-for="TransactionModeId" />
                    </div>
                    <div class="col-md-9">
                        <nop-select asp-for="TransactionModeId" asp-items="@(TransactionMode.Authorize.ToSelectList(false))" />
                        <span asp-validation-for="TransactionModeId"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        <nop-label asp-for="AdditionalFee" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="AdditionalFee" />
                        <span asp-validation-for="AdditionalFee"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        <nop-label asp-for="AdditionalFeePercentage" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="AdditionalFeePercentage" />
                        <span asp-validation-for="AdditionalFeePercentage"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-9 col-md-offset-3">
                        <div class="input-group input-group-short">
                            <div class="input-group-text">
                                <input type="submit" name="save" class="btn btn-primary" value="@T("Admin.Common.Save")" />
                            </div>
                            @if (!Model.UseSandbox &&
                                !string.IsNullOrEmpty(Model.ApplicationId) &&
                                !string.IsNullOrEmpty(Model.ApplicationSecret) &&
                                !string.IsNullOrEmpty(Model.AccessToken))
                            {
                                <div class="input-group-btn">
                                    <button type="submit" name="revokeAccessTokens" class="btn bg-red">
                                        @T("Plugins.Payments.Square.RevokeAccessTokens")
                                    </button>
                                </div>
                            }
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>