{% extends "layout.html" %}

{% block content_header %}
  {{ build_breadcrumb(_('Transports'), '', 'asterisk', [_('List')]) }}
{% endblock %}

{% block content %}
  {% call build_section_row() %}

    {% call build_form_tabs_box() %}
      {% call build_tabs_navigation() %}
        {{ add_tab_navigation_header(_('Transport'), form.name.data, 'asterisk') }}
        {{ add_tab_navigation_item('transport', _('Transport'), active=True) }}
        {{ add_tab_navigation_item('options', _('Options')) }}
      {% endcall %}

      {% call build_form(action=url_for('.TransportView:post')) %}
        {% call build_tabs_content() %}

          {% call build_tab_content_item('transport', active=True) %}
            {% call add_default_fields(form=form, submit_value=_('Add')) %}
              {{ render_field(form.name) }}
            {% endcall %}
          {% endcall %}

          {% call build_tab_content_item('options') %}
            {% call add_default_fields(form=form, submit_value=_('Add')) %}
              {{ build_add_row_entry_header() }}
              {% call build_table() %}

                {% call build_table_headers() %}
                  <th>{{ _('Option Key') }}</th>
                  <th>{{ _('Option Value') }}</th>
                  <th style="width: 21px;"></th>
                {% endcall %}

                {% call build_table_body(class_='dynamic-table') %}
                  {% do form.options.append_entry() %}
                  {{ _build_option_entry(form.options.pop_entry(), template=True) }}

                  {% for option in form.options %}
                    {{ _build_option_entry(option) }}
                  {% endfor %}
                {% endcall %}

              {% endcall %}

              {{ build_add_row_entry_header() }}
            {% endcall %}
          {% endcall %}

        {% endcall %}
      {% endcall %}

    {% endcall %}

  {% endcall %}
{% endblock %}

{% macro _build_option_entry(option, template=False) %}
  {% if template %}
    {% set tr_class = "row-template hidden" %}
  {% else %}
    {% set tr_class = "row-line" %}
  {% endif %}
  <tr class="{{ tr_class }}">
    <td>{{ render_field(
      option.option_key,
      with_label=False,
      inputclass='ui-helper-clearfix',
      data_listing_href=url_for(listing_urls['pjsip_doc'], section='transport'),
    ) }}</td>
    <td>{{ render_field(option.option_value, with_label=False) }}</td>
    <td>{{ add_delete_entry_button() }}</td>
  </tr>
{% endmacro %}
