{% extends request.ajax ? 'layout_blank.html.twig' : 'layout_default.html.twig' %}

{% import 'macro_functions.html.twig' as mf %}

{% block meta_title %}{{ 'Gateway'|trans }} {{ gateway.title }}{% endblock %}

{% set active_menu = 'system' %}

{% block breadcrumbs %}
    <ul class="breadcrumb">
        <li class="breadcrumb-item">
            <a href="{{ '/'|alink }}">
                <svg class="icon">
                    <use xlink:href="#home" />
                </svg>
            </a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ 'invoice/gateways'|alink }}">{{ 'Payment gateways'|trans }}</a>
        </li>
        <li class="breadcrumb-item active" aria-current="page">{{ gateway.title }}</li>
    </ul>
{% endblock %}

{% block content %}
<div class="card">
    <div class="card-body">
        <h3>{{ 'Payment gateway configuration'|trans }} {{ gateway.title }}</h3>
        <h5>{{ gateway.title }}</h5>
        {{ gateway.description|raw }}

        <form method="post" action="{{ 'api/admin/invoice/gateway_update'|link }}" class="api-form" data-api-msg="{{ 'Gateway updated'|trans }}">
            <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Payment gateway title'|trans }}:</label>
                <div class="col">
                    <input class="form-control" type="text" name="title" value="{{ gateway.title }}">
                </div>
            </div>

            {# Build form elements from registrar configuration array #}
            {{ mf.build_form(gateway.form, gateway.config) }}

            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Select which currencies can accept this payment gateway (Select none to allow all currencies)'|trans }}</label>
                <div class="col">
                    {% set currencies = guest.currency_get_pairs %}
                    <select class="form-select" name="accepted_currencies[]" multiple="multiple" size="{{ currencies|length }}">
                        {% for id, currency in currencies %}
                        <option value="{{ id }}"{% if id in gateway.accepted_currencies %} selected{% endif %}>{{ currency }}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Enabled'|trans }}:</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioEnabledYes" type="radio" name="enabled" value="1"{% if gateway.enabled %} checked{% endif %}>
                        <label class="form-check-label" for="radioEnabledYes">{{ 'Yes'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioEnabledNo" type="radio" name="enabled" value="0"{% if not gateway.enabled %} checked{% endif %}>
                        <label class="form-check-label" for="radioEnabledNo">{{ 'No'|trans }}</label>
                    </div>
                </div>
            </div>

            {% if gateway.supports_one_time_payments %}
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Allow one time payments'|trans }}:</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioAllowSingleYes" type="radio" name="allow_single" value="1"{% if gateway.allow_single %} checked{% endif %}>
                        <label class="form-check-label" for="radioAllowSingleYes">{{ 'Yes'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioAllowSingleNo" type="radio" name="allow_single" value="0"{% if not gateway.allow_single %} checked{% endif %}>
                        <label class="form-check-label" for="radioAllowSingleNo">{{ 'No'|trans }}</label>
                    </div>
                </div>
            </div>
            {% else %}
            <input type="hidden" name="allow_single" value="0">
            {% endif %}

            {% if gateway.supports_subscriptions %}
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Allow subscription payments'|trans }}:</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioAllowRecurrentYes" type="radio" name="allow_recurrent" value="1"{% if gateway.allow_recurrent %} checked{% endif %}>
                        <label class="form-check-label" for="radioAllowRecurrentYes">{{ 'Yes'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioAllowRecurrentNo" type="radio" name="allow_recurrent" value="0"{% if not gateway.allow_recurrent %} checked{% endif %}>
                        <label class="form-check-label" for="radioAllowRecurrentNo">{{ 'No'|trans }}</label>
                    </div>
                </div>
            </div>
            {% else %}
            <input type="hidden" name="allow_recurrent" value="0">
            {% endif %}

            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Enable test mode'|trans }}:</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioTestModeYes" type="radio" name="test_mode" value="1"{% if gateway.test_mode %} checked{% endif %}>
                        <label class="form-check-label" for="radioTestModeYes">{{ 'Yes'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioTestModeNo" type="radio" name="test_mode" value="0"{% if not gateway.test_mode %} checked{% endif %}>
                        <label class="form-check-label" for="radioTestModeNo">{{ 'No'|trans }}</label>
                    </div>
                </div>
            </div>

            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'IPN Callback URL'|trans }}:</label>
                <div class="col">
                    <input class="form-control" type="text" value="{{ gateway.callback }}" readonly="readonly">
                </div>
            </div>

            <input type="hidden" name="id" value="{{ gateway.id }}">
            <input type="submit" value="{{ 'Update'|trans }}" class="btn btn-primary w-100">
        </form>
    </div>
</div>
{% endblock %}
