{#
  Variables
    - form
#}
{{ form_start(form) }}
<ul class="nav nav-tabs nav-tabs-contained">
    <li class="active"><a data-toggle="tab" href="#channels">{{ 'mautic.lead.contact.channels'|trans }}</a></li>
    <li><a data-toggle="tab" href="#categories">{{ 'mautic.lead.preferred.categories'|trans }}</a></li>
    <li><a data-toggle="tab" href="#segments">{{ 'mautic.lead.preferred.segments'|trans }}</a></li>
</ul>
<div class="tab-content">
    <div id="channels" class="tab-pane fade in active">
        <table class="table" width="100%">
            <thead>
            <tr>
                <th>
                    <input type="checkbox" id="lead_contact_frequency_rules_subscribed_channels_0" name="check_all" onclick="Mautic.togglePreferredChannel('all');" value="all">
                </th>
                <th>{{ 'mautic.lead.contact.channels'|trans }}</th>
                <th>{{ 'mautic.lead.preferred.frequency'|trans }}</th>
                <th>{{ 'mautic.lead.preferred.channels'|trans }}</th>
            </tr>
            </thead>
            <tbody >

            {% for channel in form.lead_channels.subscribed_channels.vars.choices %}
                {% set isContactable = leadChannels[channel.value] is not defined %}
                {% set isHidden = leadChannels[channel.value] is not defined %}
                {% set isChecked = leadChannels[channel.value] is defined %}
                {% set isDisabled = leadChannels[channel.value] is not defined %}
                <tr>
                    <th style="vertical-align: top" class="col-md-1">
                        <input type="checkbox"
                               id="{{ channel.value }}"
                               name="lead_contact_frequency_rules[lead_channels][subscribed_channels][]"
                               class="control-label"
                               onclick="Mautic.togglePreferredChannel(this.value);"
                               value="{{ channel.value|e }}"
                               {% if isChecked %}checked{% endif %}>
                    </th>
                    <td class="col-md-1" style="vertical-align: top">
                        <div id="is-contactable-{{ channel.value }}" class="{% if not isContactable %}text-muted{% endif %} fw-sb">
                            {{ getChannelLabel(channel.value) }}
                        </div>
                    </td>
                    <td class="col-md-9" style="vertical-align: top">
                            <div>
                                <div class="pull-left">
                                    {% set attr = form.lead_channels['frequency_number_' ~ channel.value].vars.attr %}
                                    {% set attr = attr|merge({'class': attr.class ~ ' pull-left'}) %}
                                    {{ form_widget(form.lead_channels['frequency_number_' ~ channel.value], {'attr': attr}) }}
                                    {{ form_label(form.lead_channels['frequency_time_' ~ channel.value]) }}
                                    <div class="frequency-select">{{ form_widget(form.lead_channels['frequency_time_' ~ channel.value]) }}</div>
                                </div>
                            </div>
                    </td>
                <td class="col-md-1" style="vertical-align: top;" align="center">
                        <input type="radio"
                               id="preferred_{{ channel.value }}"
                               name="lead_contact_frequency_rules[lead_channels][preferred_channel]"
                               class="contact"
                               value="{{ channel.value|e }}"
                               {% if form['lead_channels']['preferred_channel'].vars['value'] == channel.value %}checked{% endif %}
                               {% if isDisabled %}disabled{% endif %}>
                </td>
                </tr>
                <tr style="border-top:none"><th style="border-top:none"></th>
                    <td  style="border-top:none"></td>
                    <td colspan="2" style="border-top:none">
                        <div id="frequency_{{ channel.value }}"
                             class="{% if isHidden %}hide{% endif %}">
                            <div>
                                <label class="text-muted fw-n">{{ 'mautic.lead.frequency.dates.label'|trans }}</label>
                            </div>
                            <div>
                                {{ form_widget(form['lead_channels']['contact_pause_start_date_' ~ channel.value]) }}
                                <div style="float:left;">
                                    {{ form_label(form['lead_channels']['contact_pause_end_date_' ~ channel.value]) }}
                                </div>
                                {{ form_widget(form['lead_channels']['contact_pause_end_date_' ~ channel.value]) }}
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </td>
                </tr>
                {% do form.lead_channels.setRendered() %}
            {% endfor %}
            </tbody>
        </table>
    </div>
    <div id="categories" class="tab-pane fade">
        <table class="table" width="100%">
            <thead>
            <tr>
                <th>{{ form_row(form.global_categories) }}</th>
            </tr>
            </thead>
        </table>
    </div>
    <div id="segments" class="tab-pane fade">
        <table class="table" width="100%">
            <thead>
              <tr>
                  <th>{{ form_row(form.lead_lists) }}</th>
              </tr>
            </thead>
        </table>
    </div>
</div>
{{ form_end(form, render_rest = false) }}
