{#
This file is part of "Total Order Discount" project and subject to the terms
and conditions defined in file "LICENSE.txt", which is part of this source
code package and also available on the project page: https://git.io/JvumR
#}

{% set links = {
  'Opencart Marketplace':  'https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=33296',
  'Homepage': 'https://underr.space/en/notes/projects/project-0001.html',
  'Github': 'https://git.io/JvumR',
  'LICENSE': 'https://git.io/Jvuma'
} %}

{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-total" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary">
          <i class="fa fa-save"></i>
        </button>
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default">
          <i class="fa fa-reply"></i>
        </a>
      </div>
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {%- for breadcrumb in breadcrumbs -%}

        <li>
          <a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a>
        </li>

        {%- endfor -%}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    {%- if error_permission -%}

    <div class="alert alert-danger alert-dismissible">
      <i class="fa fa-exclamation-circle"></i>
      {{ error_permission }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>

    {%- endif -%}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title">
          <i class="fa fa-pencil"></i>
          {{ text_edit }}
        </h3>
      </div>
      <div class="panel-body">
        <form
          action="{{ action }}"
          method="post"
          enctype="multipart/form-data"
          id="form-total"
          class="form-horizontal">

          <div class="form-group">
            <div
              class="btn-group btn-group-toggle col-sm-12 text-left"
              data-toggle="buttons"
              id="input-status">
              <label class="btn btn-default{% if status %} active btn-success{% endif %}">
                <input
                  autocomplete="off"
                  name="total_order_discount_status"
                  type="radio"
                  value="1"
                  {% if status %}checked{% endif %}/>
                  {{ text_enabled }}
              </label>
              <label class="btn btn-default{% if not status %} active btn-success{% endif %}">
                <input
                  autocomplete="off"
                  name="total_order_discount_status"
                  type="radio"
                  value="0"
                  {% if not status %}checked{% endif %}>
                  {{ text_disabled }}
              </label>
            </div>
          </div>

          <ul class="nav nav-tabs" id="tabs">
              <li class="active">
                  <a data-toggle="tab" href="#tab-parameters">
                      {{ entry_tab_parameters }}
                  </a>
              </li>
              <li {% if error_discount_title %}style="border: 1px solid red;"{% endif %}>
                  <a data-toggle="tab" href="#tab-text">
                      {{ entry_tab_text }}
                  </a>
              </li>
          </ul>

          <div class="tab-content">
            <div class="tab-pane active" id="tab-parameters">
              <div class="form-group">
                <label class="col-sm-2 control-label" for="select-condition">{{ entry_condition }}</label>
                <div class="col-sm-6">
                  <select name="total_order_discount[condition]" id="select-condition" class="form-control">
                    {%- if (discount.condition == 'quantity') -%}

                    <option value="price">{{ text_price }}</option>
                    <option value="quantity" selected="selected">{{ text_quantity }}</option>

                    {%- else -%}

                    <option value="price" selected="selected">{{ text_price }}</option>
                    <option value="quantity">{{ text_quantity }}</option>

                    {%- endif -%}
                  </select>
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-2 control-label" for="select-type">{{ entry_type }}</label>
                <div class="col-sm-6">
                  <select name="total_order_discount[type]" id="select-type" class="form-control">
                    {% if (discount.type == 'fixed') %}
                    <option value="percentage">{{ text_percentage }}</option>
                    <option value="fixed" selected="selected">{{ text_fixed }}</option>
                    {% else %}
                    <option value="percentage" selected="selected">{{ text_percentage }}</option>
                    <option value="fixed">{{ text_fixed }}</option>
                    {% endif %}
                  </select>
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-2 control-label" for="input-key">{{ entry_key }}</label>
                <div class="col-sm-2">
                  <input
                    class="form-control"
                    id="input-key"
                    min="0"
                    name="total_order_discount[key]"
                    placeholder="{{ entry_key }}"
                    type="number"
                    step="any"
                    value="{% if discount.key %}{{ discount.key }}{% else %}0{% endif %}"/>
                </div>

                <label class="col-sm-2 control-label" for="input-value">
                  {{ entry_value }}
                  <span data-toggle="tooltip" title="" data-original-title="{{ help_discount_value }}"></span>
                </label>
                <div class="col-sm-2">
                  <input
                    class="form-control"
                    id="input-value"
                    name="total_order_discount[value]"
                    placeholder="{{ entry_value }}"
                    type="number"
                    value="{% if discount.value %}{{ discount.value }}{% else %}0{% endif %}"
                    step="any"/>
                </div>
              </div>

              <div class="form-group">
                <label
                  class="col-sm-2 control-label"
                  for="input-sort-order">
                  {{ entry_sort_order }}
                </label>
                <div class="col-sm-6">
                  <input
                    class="form-control"
                    id="input-sort-order"
                    min="0"
                    name="total_order_discount[sort_order]"
                    placeholder="{{ entry_sort_order }}"
                    step="1"
                    type="number"
                    value="{{ discount.sort_order }}"/>
                </div>
              </div>
            </div>

            <div class="tab-pane" id="tab-text">

              <table class="table table-striped table-bordered table-hover">
                {%- if error_discount_title -%}

                <div class="alert alert-danger alert-dismissible">
                  <i class="fa fa-exclamation-circle"></i>
                  {{ error_discount_title }}
                  <button type="button" class="close" data-dismiss="alert">&times;</button>
                </div>

                {%- endif -%}

                {%- for language in languages -%}

                <tr>
                  <td>
                    <div>
                      <label class="control-label">
                        {{ _context['entry_title'] }}
                      </label>
                     <div class="input-group">
                        <span class="input-group-addon">
                          <img
                            src="language/{{ language.code }}/{{ language.code }}.png"
                            title="{{ language.name }}"/>
                        </span>
                        <input
                          class="form-control"
                          name="total_order_discount[title][{{ language.language_id }}]"
                          placeholder="{{ _context['text_title'] }}"
                          type="text"
                          value="{{ discount.title[language.language_id] }}"/>
                      </div>
                    </div>
                  </td>
                </tr>

                {%- endfor -%}
              </table>
            </div>

            <div class="tab-pane" id="tab-info">
              <div class="col-sm-12 text-center">{{ text_about }}</div>
              <div class="text-center">
                {%- for name, url in links -%}

                <a href="{{ url }}" target="_blank">{{ name }}</a>
                {% if not loop.last %} | {% endif %}

                {%- endfor -%}
              </div>
              <hr/>
              <div class="text-center">{{ copyright }}, {{ email }}</div>
            </div>
          </div>

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

<script type="text/javascript"><!--

    function setValueRange(type) {
        if (type == 'percentage') {
            $('#input-value').attr({'max': '100'}).attr({'min': '-100'});
        } else if (type == "fixed") {
            $('#input-value').removeAttr('min').removeAttr('max');
        }
    }

    $('#select-type').on('change', function() {
        setValueRange($(this).val());
    });

    setValueRange($('#select-type').val());

    $('#input-status .btn.btn-default').click(function () {
        if (!$(this).hasClass('active')) {
            $('#input-status .btn.btn-default').removeClass('btn-success');

            $(this).addClass('btn-success');
        }
    });

--></script>
{{ footer }}
