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

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

{% set active_menu = 'system' %}

{% block meta_title %}{{ 'Payment gateways'|trans }}{% endblock %}

{% block content %}
    <ul class="nav nav-tabs" role="tablist">
        <li class="nav-item" role="presentation">
            <a class="nav-link active" href="#tab-index" data-bs-toggle="tab">{{ 'Payment gateways'|trans }}</a>
        </li>
        <li class="nav-item" role="presentation">
            <a class="nav-link" href="#tab-new" data-bs-toggle="tab">
                <svg class="icon me-2">
                    <use xlink:href="#plus" />
                </svg>
                {{ 'New payment gateway'|trans }}
            </a>
        </li>
        <li class="nav-item" role="presentation">
            <a class="nav-link" href="#tab-extension-directory" data-bs-toggle="tab">
                <svg class="icon me-2">
                    <use xlink:href="#plus" />
                </svg>
                {{ 'Install from the Extension Directory'|trans }}
            </a>
        </li>
    </ul>

<div class="card">
    <div class="tab-content">
        <div class="tab-pane fade show active" id="tab-index" role="tabpanel">
            {% include 'partial_search.html.twig' %}
            <table class="table card-table table-vcenter table-striped text-nowrap sortable">
                <thead>
                    <tr>
                        <th>{{ 'Title'|trans }}</th>
                        <th>{{ 'Code'|trans }}</th>
                        <th>{{ 'Enabled'|trans }}</th>
                        <th>{{ 'Allow one time payments'|trans }}</th>
                        <th>{{ 'Allow subscriptions'|trans }}</th>
                        <th class="w-1"></th>
                    </tr>
                </thead>
                <tbody>
                {% for gateway in admin.invoice_gateway_get_list({ 'per_page': 100 }|merge(request)).list %}
                <tr>
                    <td>
                        <a href="{{ '/invoice/gateway'|alink }}/{{ gateway.id }}">{{ gateway.title }}</a>
                    </td>
                    <td>{{ gateway.code }}</td>
                    <td>{{ mf.q(gateway.enabled) }}</td>
                    <td>{{ mf.q(gateway.allow_single) }}</td>
                    <td>{{ mf.q(gateway.allow_recurrent) }}</td>
                    <td>
                        <a class="btn btn-icon api-link"
                            href="{{ 'api/admin/invoice/gateway_copy'|link({ 'id': gateway.id, 'CSRFToken': CSRFToken }) }}"
                            title="{{ 'Copy'|trans }}"
                            data-api-redirect="{{ 'invoice/gateways'|alink }}">
                            <svg class="icon">
                                <use xlink:href="#copy" />
                            </svg>
                        </a>
                        <a class="btn btn-icon" href="{{ '/invoice/gateway'|alink }}/{{ gateway.id }}">
                            <svg class="icon">
                                <use xlink:href="#edit" />
                            </svg>
                        </a>
                        <a class="btn btn-icon api-link"
                            href="{{ 'api/admin/invoice/gateway_delete'|link({ 'id': gateway.id, 'CSRFToken': CSRFToken }) }}"
                            data-api-confirm="{{ 'Are you sure?'|trans }}"
                            data-api-redirect="{{ 'invoice/gateways'|alink }}">
                            <svg class="icon">
                                <use xlink:href="#delete" />
                            </svg>
                        </a>
                    </td>
                </tr>
                </tbody>
                {% else %}
                <tbody>
                    <tr>
                        <td class="text-muted" colspan="5">{{ 'The list is empty'|trans }}</td>
                    </tr>
                </tbody>
                {% endfor %}
            </table>
        </div>

        <div class="tab-pane fade" id="tab-new" role="tabpanel">
            <div class="card-body">
                <h1>{{ 'Adding new payment gateway'|trans }}</h1>
                <p class="text-muted">{{ 'Although FOSSBilling ships with most popular payment gateways, you can install other gateways.'|trans }}</p>
                <p>{{ 'Follow these instructions to install new payment gateway.'|trans }}</p>
                <ul>
                    <li>{{ 'Check for payment gateway at'|trans }} <a href="http://extensions.fossbilling.org/" target="_blank">FOSSBilling extensions site</a> {{ 'for more payment gateways'|trans }}</li>
                    <li>{{ 'Download payment gateway extension file and place it to'|trans }}<strong>{{ constant('PATH_LIBRARY') }}/Payment/Adapter</strong></li>
                    <li>{{ 'After file is uploaded in place, reload this page.'|trans }}</li>
                    <li>{{ 'Select uploaded file name and click on install.'|trans }}</li>
                    <li>{{ 'Payment gateway will be installed in FOSSBilling and can be configured in \"Payment gateways\" tab.'|trans }}</li>
                    <li>{{ 'For developers. Read'|trans }} <a href="https://fossbilling.org/docs" target="_blank">FOSSBilling documentation</a> {{ 'to learn how to create your own payment gateway and share it with community'|trans }}</li>
                </ul>
            </div>

            {% if admin.invoice_gateway_get_available|length > 0 %}
            <table class="table card-table table-vcenter table-striped text-nowrap">
                <thead>
                    <tr>
                        <th>{{ 'Code'|trans }}</th>
                        <th class="w-1">{{ 'Install'|trans }}</th>
                    </tr>
                </thead>
                <tbody>
                {% for gtw in admin.invoice_gateway_get_available %}
                <tr>
                    <td>{{ gtw }}</td>
                    <td>
                        <a class="btn btn-icon api-link"
                            href="{{ 'api/admin/invoice/gateway_install'|link({ 'code': gtw, 'CSRFToken': CSRFToken }) }}"
                             title="{{ 'Install'|trans }}"
                            data-api-redirect="{{ 'invoice/gateways'|alink }}">
                            <svg class="icon">
                                <use xlink:href="#cog" />
                            </svg>
                        </a>
                    </td>
                </tr>
                </tbody>
                {% else %}
                <tbody>
                    <tr>
                        <td class="text-muted" colspan="5">{{ 'All payment gateways installed'|trans }}</td>
                    </tr>
                </tbody>
                {% endfor %}
            </table>
            {% endif %}
        </div>

        <div class="tab-pane fade" id="tab-extension-directory" role="tabpanel">
            {% include "partial_extensions.html.twig" with {'type': 'payment-gateway', 'header':"List of payment gateways on the Extension Directory"} only %}
        </div>
    </div>
</div>
{% endblock %}