{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}
{% import "macro_functions.phtml" as mf %}
{% set active_menu = 'system' %}
{% block meta_title %}{% trans 'Currency management' %}{% endblock %}
{% block content %}

<div class="widget simpleTabs nomargin">

    <ul class="tabs">
        <li><a href="#tab-currencies">{% trans 'Currencies' %}</a></li>
        <li><a href="#tab-new-currency">{% trans 'Add new currency' %}</a></li>
    </ul>

    <div class="tabs_container">
        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-currencies">

            <div class="help">
                <h3>{% trans 'Manage currencies' %}</h3>
                <p>{% trans 'Default currency is the one you manage all your prices in admin area. If your client in client area chooses other than default currency, prices will be recalculated according to conversion rate. You can have only one default currency. You can not add same currency once again. Changing default currency is not recommended when active orders are available. Nothing is recalculated on default currency change. Your income is calculated in default currency. Changing default currency after you have paid invoices will distort income statistics. Currency rates are taken from Google.' %}</p>
            </div>

            <table class="tableStatic wide">
                <thead>
                    <tr>
                        <th>{% trans 'ISO code' %}</th>
                        <th>{% trans 'Title' %}</th>
                        <th>{% trans 'Conversion rate' %}</th>
                        <th>{% trans 'Example price' %}</th>
                        <th style="width:17%">&nbsp;</th>
                    </tr>
                </thead>

                <tbody>
                {% for currency in admin.currency_get_list.list %}
                  <tr>
                      <td>{% if currency.default %}<strong>{{ currency.code }}</strong>{% else %}{{ currency.code }}{% endif %}</td>
                      <td>{{ currency.title }}</td>
                      <td>{{ currency.conversion_rate }}</td>
                      <td>{{ mf.currency_format(1) }} = {{ mf.currency(1, currency.code) }}</td>
                      <td class="actions">
                          <a class="bb-button btn14" href="{{ '/currency/manage'|alink }}/{{currency.code}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                          <a class="bb-button btn14 bb-rm-tr api-link" data-api-redirect="currency" data-api-confirm="Are you sure?" href="admin/currency/delete?code={{currency.code}}"><img src="images/icons/dark/trash.png" alt=""></a>
                          {% if not currency.default %}
                          <a class="bb-button btn14 api-link" data-api-redirect="currency" href="admin/currency/set_default?code={{currency.code}}" title="Set as default" class="rightDir"><img src="images/icons/dark/star.png" alt=""></a>
                          {% endif %}
                      </td>
                  </tr>
                {% else %}
                  <tr>
                      <td colspan="5">
                          {% trans 'The list is empty' %}
                      </td>
                  </tr>
                {% endfor %}
                </tbody>

                <tfoot>
                    <tr>
                        <td colspan="5">
                            <div class="aligncenter">
                                <a href="admin/currency/update_rates" data-api-redirect="currency" class="btn55 mr10 api-link"><img src="images/icons/middlenav/refresh4.png" alt=""><span>{% trans 'Update Rates' %}</span></a>
                            </div>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </div>

        <div class="tab_content nopadding" id="tab-new-currency">

            <form method="post" action="admin/currency/create" class="mainForm save api-form" data-api-redirect="{{ 'currency/index' }}">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Code' %}:</label>
                        <div class="formRight">
                            {{ mf.selectbox('code', admin.currency_get_pairs, 'USD', 1) }}
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Title' %}:</label>
                        <div class="formRight">
                            <input type="text" name="title" value="" required="required">
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Conversion rate' %}:</label>
                        <div class="formRight">
                            <input type="text" name="conversion_rate" value="1" required="required">
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Format' %}:</label>
                        <div class="formRight">
                            <input type="text" name="format" value="{{price}} $" required="required">
                        </div>
                        <div class="fix"></div>
                    </div>

                    <input type="submit" value="{% trans 'Add' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>


        </div>
    </div>
</div>

{% endblock %}