{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}
{% import "macro_functions.phtml" as mf %}
{% block meta_title %}{{ 'Gateway'|trans }} {{ gateway.title }}{% endblock %}
{% set active_menu = 'system' %}

{% block breadcrumbs %}
<ul>
    <li class="firstB"><a href="{{ '/'|alink }}">{{ 'Home'|trans }}</a></li>
    <li><a href="{{ 'invoice/gateways'|alink }}">{{ 'Payment gateways'|trans }}</a></li>
    <li class="lastB">{{ gateway.title }}</li>
</ul>
{% endblock %}

{% block content %}

<div class="widget">
    <div class="head">
        <h5>{{ 'Payment gateway configuration'|trans }} {{ gateway.title }}</h5>
    </div>

    <div class="help">
        <h5>{{ gateway.title }}</h5>
        {{ gateway.description|raw }}
    </div>

    <form method="post" action="{{ 'api/admin/invoice/gateway_update'|link }}" class="mainForm save api-form" data-api-msg="Gateway updated">
    <fieldset>
        <div class="rowElem noborder">
            <label class="topLabel">{{ 'Payment gateway title'|trans }}:</label>
            <div class="formBottom">
                <input type="text" name="title" value="{{ gateway.title }}" />
            </div>
            <div class="fix"></div>
        </div>

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

        <div class="rowElem">
            <label class="topLabel">{{ 'Select which currencies can accept this payment gateway (Select none to allow all currencies)'|trans }}</label>
            <div class="formBottom">
                {% set currencies = guest.currency_get_pairs %}
                <select name="accepted_currencies[]" multiple="multiple" class="multiple" size="{{currencies|length}}">
                    {% for id,currency in currencies %}
                    <option value="{{id}}" {% if id in gateway.accepted_currencies %}selected="selected"{% endif %}>{{ currency }}</option>
                    {% endfor %}
                </select>
            </div>
            <div class="fix"></div>
        </div>

        <div class="rowElem">
            <label>{{ 'Enabled'|trans }}:</label>
            <div class="formRight">
                <input type="radio" name="enabled" value="1"{% if gateway.enabled %} checked="checked"{% endif %}/><label>{{ 'Yes'|trans }}</label>
                <input type="radio" name="enabled" value="0"{% if not gateway.enabled %} checked="checked"{% endif %} /><label>{{ 'No'|trans }}</label>
            </div>
            <div class="fix"></div>
        </div>

        {% if gateway.supports_one_time_payments %}
        <div class="rowElem">
            <label>{{ 'Allow one time payments'|trans }}:</label>
            <div class="formRight">
                <input type="radio" name="allow_single" value="1"{% if gateway.allow_single %} checked="checked"{% endif %}/><label>{{ 'Yes'|trans }}</label>
                <input type="radio" name="allow_single" value="0"{% if not gateway.allow_single %} checked="checked"{% endif %} /><label>{{ 'No'|trans }}</label>
            </div>
            <div class="fix"></div>
        </div>
        {% else %}
        <input type="hidden" name="allow_single" value="0" />
        {% endif %}
        
        {% if gateway.supports_subscriptions %}
        <div class="rowElem">
            <label>{{ 'Allow subscription payments'|trans }}:</label>
            <div class="formRight">
                <input type="radio" name="allow_recurrent" value="1"{% if gateway.allow_recurrent %} checked="checked"{% endif %}/><label>{{ 'Yes'|trans }}</label>
                <input type="radio" name="allow_recurrent" value="0"{% if not gateway.allow_recurrent %} checked="checked"{% endif %} /><label>{{ 'No'|trans }}</label>
            </div>
            <div class="fix"></div>
        </div>
        {% else %}
        <input type="hidden" name="allow_recurrent" value="0" />
        {% endif %}

        <div class="rowElem">
            <label>{{ 'Enable test mode'|trans }}:</label>
            <div class="formRight">
                <input type="radio" name="test_mode" value="1"{% if gateway.test_mode %} checked="checked"{% endif %}/><label>{{ 'Yes'|trans }}</label>
                <input type="radio" name="test_mode" value="0"{% if not gateway.test_mode %} checked="checked"{% endif %} /><label>{{ 'No'|trans }}</label>
            </div>
            <div class="fix"></div>
        </div>

        <div class="rowElem">
            <label>{{ 'IPN Callback URL'|trans }}:</label>
            <div class="formRight">
                <input type="text" value="{{ gateway.callback }}" readonly="readonly"/>
            </div>
            <div class="fix"></div>
        </div>

        <input type="submit" value="{{ 'Update'|trans }}" class="greyishBtn submitForm" />
        <input type="hidden" name="id" value="{{ gateway.id }}" />
    </fieldset>
    </form>
</div>
{% endblock %}
