{% extends 'ZenstruckFormBundle:Twitter:form_bootstrap3_layout.html.twig' %}

{% block form_row %}
    {% spaceless %}
        <div class="form-group row{% if errors|length > 0 %} has-error{% endif %}">
            {{ form_label(form, label|default(null)) }}
            {% set ctrl_width =  'col-md-12' %}
        </div>
        <div class="form-group row">
            <div class="{{ ctrl_width }}">
                {{ form_widget(form) }}
                {{ form_errors(form) }}
                {% if help is defined and help %}
                    <div class="help-block">{{ help }}</div>
                {% endif %}
            </div>
        </div>
    {% endspaceless %}
{% endblock form_row %}

{% block form_label %}
    {% spaceless %}
        {% set is_multichoice_widget = (checked is defined) and ('choice' in form.parent.vars.block_prefixes) %}

        {% if is_multichoice_widget %}
            {% set label_attr = label_attr|merge({'class': 'radio' in block_prefixes ? 'radio' : 'checkbox'}) %}
        {% else %}
            {% set lbl_width =  'col-md-12' %}
            {% set label_attr = label_attr|merge({'class': 'control-label ' ~ lbl_width}) %}
        {% endif %}
        {% 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 %}
            {% set label = id|trans({}, translation_domain) %}
        {% endif %}
        <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
            {{ label|trans({}, translation_domain) }}
            {% if is_multichoice_widget %}
                {{ form_widget(form) }}
            {% endif %}
        </label>
    {% endspaceless %}
{% endblock form_label %}

{% block checkbox_widget %}
    {% if 'choice' not in form.parent.vars.block_prefixes %}
        {% set attr = attr|merge({'class': (attr.class|default('') ~ ' control-standalone')|trim}) %}
    {% endif %}
    {{ parent() | replace({'form-control': ''}) | raw }}
{% endblock checkbox_widget %}
