{% use "bootstrap_3_horizontal_layout.html.twig" %}
{%- block form_start -%}
    {%- if action == '' -%}
    {%- set action = app.request.requestUri -%}
    {%- endif -%}
    {{ parent() }}
{%- endblock form_start -%}
{%- block form_label -%}
    {% if label is not same as(false) -%}
        {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-sm-2 control-label')|trim}) -%}
        {% if not compound -%}
            {% set label_attr = label_attr|merge({'for': id}) %}
        {%- endif -%}
        {% if required -%}
            {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
        {%- endif -%}
        {% if label is empty -%}
            {%- if label_format is not empty -%}
                {% set label = label_format|replace({
                '%name%': name,
                '%id%': id,
                }) %}
            {%- else -%}
                {% set label = name|humanize %}
            {%- endif -%}
        {%- endif -%}
        <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
        {{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}
        {{- block('label_help_block') -}}
        </label>
    {%- endif -%}
{%- endblock form_label -%}


{%- block label_help_block -%}
    {%- if label_help|default(false) != false -%}
        <span class="help-block">
            <a href="#" data-toggle="tooltip" title="{{ translation_domain is same as(false) ? label_help : label_help|trans({}, translation_domain) }}"><span class="badge"><i class="fa fa-info"></i></span></a>
        </span>
    {%- endif -%}
{%- endblock label_help_block -%}

{%- block help_block -%}
    {%- if help|default(false) != false -%}
        <p class="help-block">{{ translation_domain is same as(false) ? help : help|trans({}, translation_domain) }}</p>
    {%- endif -%}
{%- endblock help_block -%}

{%- block form_widget_simple -%}
    {{- parent() -}}
    {{- block('help_block') -}}
{%- endblock form_widget_simple -%}

{%- block form_collection_panel -%}
    <div class="panel panel-default ibox" data-collection-item>
        <div class="panel-heading">
            <h5></h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
                <a class="close-link">
                    <i class="fa fa-times"></i>
                </a>
            </div>
        </div>
        <div class="panel-body ibox-content">
            {%- if field is defined -%}
            {{- form_widget(field) -}}
            {{- form_errors(field) -}}
            {%- endif -%}
        </div>
    </div>
{%- endblock form_collection_panel -%}

{%- block form_prototype -%}
    <div data-collection-widget class="form-group"{% for key, value in attr %} {{ key }}="{{ value }}"{% endfor %}>
        {{- form_label(form) -}}
        <div class="col-sm-10" data-collection-container>
            {%- for field in form -%}
                {{ block("form_collection_panel") }}
            {%- endfor -%}
            <div class="form-group">
                <button class="btn btn-white" data-prototype-element-count="{{ form|length }}" data-prototype-panel="{{ block("form_collection_panel")|e }}" data-prototype-widget="{{ form_widget(form.vars.prototype)|e }}" ><i class="fa fa-plus"></i> {{ 'form.button.add_new_item'|trans({}, translation_domain) }}</button>
            </div>
        </div>
    </div>
{%- endblock form_prototype -%}

{%- block form_row -%}
    {%- if attr['data-subform']|default(false) -%}
        {%- if attr['data-subform'] == 'embaded' -%}
            {{- form_widget(form) -}}
            {{- form_errors(form) -}}
            <div class="hr-line-dashed"></div>
        {%- elseif attr['data-subform'] == 'panel' -%}
            <div class="panel panel-default ibox">
                <div class="panel-heading">
                    <h5>{{ form.vars.label|default(form.vars.name)|trans({}, 'forms') }}</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="panel-body ibox-content">
                    {{- form_widget(form) -}}
                    {{- form_errors(form) -}}
                </div>
            </div>
            <div class="hr-line-dashed"></div>
        {%- elseif attr['data-subform'] == 'tab' -%}
            <div data-tab-errors="{{ form|count_children_error }}" data-tab="{{ form.vars.id }}" class="tab-pane" data-tab-label="{{ form.vars.label|default(form.vars.name)|trans({}, 'forms') }}">
                <div class="panel-body">
                {{- form_widget(form) -}}
                {{- form_errors(form) -}}
                </div>
            </div>
        {%- endif -%}
    {%- else -%}
        {%- if form.vars.prototype is defined -%}
            {{ block("form_prototype") }}
        {%- else -%}
            {{- parent() -}}
        {%- endif -%}
        <div class="hr-line-dashed"></div>
    {%- endif -%}
{%- endblock form_row -%}

{%- block form_widget_compound -%}
    {%- if form.parent is empty -%}
        {{ form_errors(form) }}
    {%- endif -%}
    {{- block('form_rows') -}}
    {{- form_rest(form) -}}
{%- endblock form_widget_compound -%}

{%- block origin_radio_widget -%}
    <input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
    <i></i>
{%- endblock origin_radio_widget -%}

{%- block radio_widget -%}
    {%- set parent_label_class = parent_label_class|default('') -%}
    {% if 'radio-inline' in parent_label_class %}
        {{- form_label(form, null, { widget: parent() }) -}}
    {% else -%}
        <div class="i-checks">
        {{- form_label(form, null, { widget: block("origin_radio_widget") }) -}}
        </div>
    {%- endif %}
{%- endblock radio_widget -%}

{%- block origin_checkbox_widget -%}
    <input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
    <i></i>
{%- endblock origin_checkbox_widget -%}

{% block checkbox_widget -%}
    {% set parent_label_class = parent_label_class|default('') -%}
    {% if 'checkbox-inline' in parent_label_class %}
        {{- form_label(form, null, { widget: parent() }) -}}
    {% else -%}
        <div class="i-checks">
            {{- form_label(form, null, { widget: block("origin_checkbox_widget") }) -}}
        </div>
    {%- endif %}
{%- endblock checkbox_widget %}

{%- block choice_widget_expanded -%}
    {% set trans_hint = form.vars.attr['trans-hint']|default %}
    {%- for group_label, group in choices -%}
         {%- if group is iterable -%}
             <div{% if trans_hint %} class="col-md-12 col-lg-6"{% endif %}>
                <table class="table table-bordered">
                 <thead>
                     <tr>
                         <td{% if trans_hint %} colspan="2"{% endif %}>{{ (group_label ~ '.type')|trans({}, translation_domain) }}</td>
                     </tr>
                 </thead>
                 <tbody>
             {%- for key, choice in group -%}
                 <tr>
                     <td{% if trans_hint %} class="col-xs-5 col-lg-4"{% endif %}>
                         {{- form_widget(form[key]) -}}
                         {{- form_label(form[key], null, {translation_domain: choice_translation_domain}) -}}
                     </td>
                     {%- if trans_hint -%}
                         <td>{{ (choice.label ~ '.hint')|trans({}, choice_translation_domain) }}</td>
                     {%- endif -%}
                 </tr>
             {%- endfor -%}
                 </tbody>
             </table>
             </div>
         {%- else -%}
             {{- form_widget(form[group_label]) -}}
             {{- form_label(form[group_label], null, {translation_domain: choice_translation_domain}) -}}
         {%- endif -%}
    {% endfor -%}
    {{- block('help_block') -}}
{%- endblock choice_widget_expanded -%}

{%- block submit_back_widget -%}
    {%- set attr = attr|merge({class: (attr.class|default('btn-primary') ~ ' btn')|trim}) -%}
    {%- set label = label|default('form.button.submit') -%}
    {{- block('submit_widget') -}}
    {%- if with_save_back -%}
        &nbsp;<button type="submit" id="{{ form.vars.id }}_save_back" class="btn btn-primary">{{ "form.button.submit_back"|trans({}, translation_domain) }}</button>
        <input type="hidden" name="return_url" value="{{ path(back_route, {slug: app.session.get('Site').slug}|merge(app.request.attributes.get('_route_params'))) }}" />
    {%- endif -%}
    {%- if with_back -%}
        &nbsp;<a class="btn btn-white" href="{{ path(back_route, {slug: app.session.get('Site').slug}|merge(app.request.attributes.get('_route_params'))) }}">{{ "form.button.cancel"|trans({}, translation_domain) }}</a>
    {%- endif -%}
    {%- if with_reset -%}
        &nbsp;<button type="reset" class="btn btn-white">{{ "form.button.reset"|trans({}, translation_domain) }}</button>
    {%- endif -%}
{%- endblock submit_back_widget -%}

{%- block choice_widget_collapsed -%}
    {%- if multiple -%}
    {%- set attr = attr|merge({"data-placeholder":" ", "data-widget": (attr["data-widget"]|default('chosen'))|trim}) -%}
    {%- endif -%}
    {{- parent() -}}
    {{- block('help_block') -}}
{%- endblock choice_widget_collapsed -%}

{%- block date_widget -%}
    <div class="input-group date" {% if widget == 'single_text' %}data-widget-datepicker{% endif %} >
        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
        {{- parent() -}}
    </div>
{%- endblock date_widget -%}

{%- block time_widget -%}
    <div class="input-group" data-placement="top" {% if widget == 'single_text' %}data-widget-timepicker{% endif %} data-autoclose="true"{% if with_seconds %} data-with-seconds{% endif %}>
        {{- parent() -}}
    </div>
{%- endblock time_widget -%}

{%- block display_widget -%}
    {%- if template is not null -%}
    {% include template with {data: form.vars.data, parentData: form.parent.vars.data} %}
    {%- endif -%}
{%- endblock -%}