{% extends app['twig_theme'] ~ '/' ~ 'layout.twig' %}

{% set active_alias = 'company-list' %}
{% set title = 'Advertising'|trans ~ ': ' ~ 'Campaign'|trans %}

{% block head %}

    {{ parent() }}
    <style type="text/css">
        {% include (app.twig_theme ~ "/ExternalAdvertising/company_add/company_add.css") %}
    </style>

{% endblock %}

{% block footer_js %}
    
        {{ parent() }}
        {% include app.twig_theme ~ "/basic_templates/scripts-select2.twig" %}

{% endblock footer_js %}

{% block footer %}
    {{ parent() }}

    <script type="text/javascript" defer>
       
        {% include (app.twig_theme ~ "/ExternalAdvertising/company_add/company_add.js.twig") %}

    </script>
{% endblock %}


{% block content %}

    <div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="box">
                    <div class="box-content">
                        <div class="row">
                            <div class="col-sm-12">
                                <h4><strong>{{ 'Set the audience for advertising'|trans }}</strong></h4>
                                <hr style="margin-top: 0;">
                            </div>
                            <div class="col-sm-5">
                                <p>
                                    {{ 'Select the Source ID, used devices and display advertising format.'|trans }}
                                    {{ 'Do not forget to save your changes when you\'re done.'|trans }}
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {{ form_start(app['form'], {'method': 'POST', 'action': (app.request_context.baseUrl ~ '/' ~ app.controller_alias  ~ '/' ~ app.action_alias) | trans, 'attr': {'class': 'form-horizontal', 'role': 'form', 'id': 'form_'}}) }}
        <div class="bg-danger">
            <div class="bg-danger">
                {{ form_errors(app['form']) }}
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="box">
                    <div class="box-content">
                        <div class="form-group">
                            <label class="col-sm-2 control-label ">{{ 'Title'|trans }}<span class="icon-required">*</span></label>
                            <div class="col-xs-10 col-sm-8">
                                <div class=" col-xs-10 col-sm-5">
                                    {{ form_widget(app['form'].id, {'attr': {}}) }}
                                    {{ form_widget(app['form'].name, {'attr': {'data-validation' : 'required', "data-validation-error-msg-container" : "#name_error"}}) }}
                                    <div class="bg-danger" id="name_error">
                                        {{ form_errors(app['form'].name) }}
                                    </div>
                                </div>
                                <span class="help-inline col-xs-12 col-sm-12">
                                    <span class="small txt-default">{{ 'Name the audience of the ad campaign.'|trans }}</span>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label ">{{ 'Source ID'|trans }}<span class="icon-required">*</span></label>
                            <div class="col-xs-10 col-sm-8">
                                <div class=" col-xs-10 col-sm-5">
                                    {{ form_widget(app['form'].source, {'attr': {'class': 'form-control', 'data-validation': 'required', "data-validation-error-msg-container" : "#source_error"}}) }}
                                    <div class="bg-danger" id="source_error">
                                        {{ form_errors(app['form'].source) }}
                                    </div>
                                </div>
                                <span class="help-inline col-xs-12 col-sm-12">
                                    <span class="small txt-default">
                                        {{ 'Select Source ID.'|trans }}
                                        {{ 'It identifies your subscribers in the system and allows you to count impressions advertising.'|trans }}
                                        <br>
                                        {{ 'You can have multiple Source ID.'|trans }}
                                        {{ 'This allows you to track your income for different audiences.'|trans }}
                                        <br>
                                        {{ 'To get an additional Source ID, write to'|trans }}:
                                        <a href="mailto:adexchange@adtelligent.com">adexchange@adtelligent.com</a>
                                    </span>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label ">{{ 'Platform'|trans }}<span class="icon-required">*</span></label>
                            <div class="col-xs-10 col-sm-8">
                                <div class=" col-xs-10 col-sm-5">
                                    {{ form_widget(app['form'].platform, {'attr': {'class': 'form-control', 'data-validation': 'required', "data-validation-error-msg-container" : "#platform_error"}}) }}
                                    <div class="bg-danger" id="platform_error">
                                        {{ form_errors(app['form'].platform) }}
                                    </div>
                                </div>
                                <span class="help-inline col-xs-12 col-sm-12">
                                    <span class="small txt-default">
                                        {{ 'Select the platform for advertising clips.'|trans }}
                                    </span>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">{{ 'Settings'|trans }}<span class="icon-required">*</span></label>
                            <div class="col-xs-10 col-sm-8" style="margin-top: 8px;">
                                <table class="table ext_ad_table table-striped table-bordered table-hover table-heading">
                                    <thead>
                                        <tr role="row">
                                            <th width="13%"><strong>{{ 'System'|trans }}</strong></th>
                                            <th width="9%"><strong>{{ 'Enable'|trans }}</strong></th>
                                            <th width="50%"><div class="col-sm-12"><strong>{{ 'Ad position'|trans }}</strong></div></th>
                                            <th width="10%"><strong>{{ 'Ad blocks'|trans }}</strong></th>
                                            <th width="18%"><strong>{{ '"Skip" button (after 7 sec)'|trans }}</strong></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    {% set prefix = '' %}
                                    {% for platform_part, label_part in app['platform_list'] %}
                                        {% for code, label_part_part in label_part %}
                                            
                                            {% set prefix = label_part_part.prefix %}
                                            
                                            {% for key, addPositionField in app['form'][platform_part] if ((key ~ '')|slice(0, 1) == prefix and not(key in ['205', '203', '103'])) %}
                                            <tr id="{{ platform_part }}_part_{{ key }}" class="{% if loop.first %}border-top{% endif %} no-border-row {{ platform_part }}_part_{{ code }}" {% if platform_part != app['form'].platform.vars.value %}style="display: none;"{% endif %}>
                                                {% if loop.first %}
                                                <td rowspan="{{ label_part[code].count }}">
                                                    <div class="col-sm-12">
                                                        <strong>{{ label_part[code].label }}</strong>
                                                    </div>
                                                </td>
                                                {% endif %}
                                                <td>
                                                    <div class="col-sm-12">
                                                        <div class="checkbox">
                                                            <label>
                                                                <input data-code="{{ key }}" type="checkbox" {% if addPositionField.vars.value %}checked="checked"{% endif %} >
                                                                <i class="fa fa-square-o small"></i>
                                                            </label>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12"></div>
                                                </td>
                                                <td>
                                                    <div class="col-sm-12">
                                                        {{ form_label(addPositionField, addPositionField.vars.label[key], {'label_attr': {'data-codereff': key}}) }}
                                                    </div>
                                                    <div class="col-sm-12">
                                                        {% if key == '205' %}
                                                        <label class='txt-danger' id="warning_label" {% if not(addPositionField.vars.value) %}style="visibility: hidden;" {% endif %} >{{ 'Attention! advertising block will be played instead of the content.' | trans }}</label>
                                                        {% endif %}
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="col-sm-12">
                                                        {{ form_widget(addPositionField, {'attr': {'class': 'populate placeholder', 'data-codereff': key } }) }}
                                                    </div>
                                                    <div class="col-sm-12"></div>
                                                </td>
                                                <td>
                                                    {% set  platform_part_skip = (platform_part ~ '_skip') | trans %}
                                                    <div class="col-sm-12">
                                                        <div class="checkbox">
                                                            <label>
                                                                {{ form_widget(app['form'][platform_part_skip][key], { 'attr': {'data-codereff': key, 'value': 7 } }) }}
                                                                <i class="fa fa-square-o small"></i>
                                                            </label>
                                                        </div>
                                                    </div>
                                                </td>
                                            </tr>
                                            {% endfor %}

                                        {% endfor %}
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="form-group form-group-checkbox">
                            <label class="col-sm-2 control-label">{{ 'Activate the campaign'|trans }}</label>
                            <div class="col-xs-10 col-sm-8">
                                <div class=" col-xs-10 col-sm-5">
                                    <span class="col-xs-12 col-sm-12 no-padding">
                                        <div class="mswitch">
                                            {{ form_widget(app['form'].status, {'attr': {}}) }}
                                            {{ form_label(app['form'].status) }}
                                        </div>
                                    </span>
                                </div>
                                <div>
                                    <div class="bg-danger">
                                        {{ form_errors(app['form'].status) }}
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-10 col-sm-9">
                                <div class=" col-xs-10 col-sm-8 col-offset-control-label">
                                    {{ form_widget(app['form'].save, { 'label': 'Save'|trans , attr: {'class': 'btn btn-success green'}}) }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div style="display: none;">
            {{ form_rest(app['form']) }}
        </div>
        {{ form_end(app['form']) }}  
    </div>

{% endblock %}
