{% extends 'base_widget.html.twig' %}

{% block title %}WidgetForm index{% endblock %}

{% block js %}
    <script src="https://smartcaptcha.yandexcloud.net/captcha.js"></script>
{% endblock %}

{% block body %}
    {% if renderForm %}
        <form id="wf_cabinet_{{ widget_form.id }}" action="{{ path('widget_form_show', {'id': widget_form.id}) }}" method="POST">
            {% set query = app.request.query.all %}
            {% for key, queryParam in query %}
                {% if key == 'fields' %}
                    {% for field, val in queryParam %}
                        <input type="hidden" name="fields[{{ field }}]" value="{{ val }}">
                    {% endfor %}
                {% endif %}
                {% if key != 'hidden' and key != 'fields' %} 
                    <input type="hidden" name="{{ key }}" value="{{ queryParam }}">
                {% endif %}
            {% endfor %}    

                <input id="wf_title" type="hidden" name="fields[TITLE]" value="{{ widget_form.name }}">
                <input id="wf_currency_id" type="hidden" name="fields[CURRENCY_ID]" value="RUB">
            {% for input in widget_form.widgetFormInputs %}
                {% set  hiddenVal = false %}
                {% if query.hidden is defined and query.hidden[input.bitrix24Id] is defined %}
                    {% set  hiddenVal = query.hidden[input.bitrix24Id] %}
                {% endif %}
                <div class="form-group">
                    {% if input.type == 'text' %}
                        {% if hiddenVal == false %}
                            {# <label for="wf_{{ input.bitrix24Id }}">{{ input.text }}</label>   #}
                            <input class="form-control" type="text" name="fields[{{ input.bitrix24Id }}]" id="wf_{{ input.bitrix24Id }}" placeholder="{{ input.text }}" required>
                        {% else %}
                            <input class="form-control" type="hidden" name="fields[{{ input.bitrix24Id }}]" id="wf_{{ input.bitrix24Id }}" value="{{ hiddenVal }}">
                        {% endif %}
                    {% elseif input.type == 'phone' %}
                        {# <label for="wf_{{ input.bitrix24Id }}">{{ input.text }}</label>   #}
                        <input class="form-control" type="text" name="fields[{{ input.bitrix24Id }}][][VALUE]" data-controller="inputMask" id="wf_{{ input.bitrix24Id }}" placeholder="{{ input.text }}" required>
                        <input type="hidden" name="fields[{{ input.bitrix24Id }}][][VALUE_TYPE]" value="MOBILE" required>
                    {% elseif input.type == 'date' %}
                        <label class="d-block" for="wf_{{ input.bitrix24Id }}">{{ input.text }}</label>
                        <input class="form-control" type="text" name="fields[{{ input.bitrix24Id }}]" data-controller="datePicker" id=" wf_{{ input.bitrix24Id }}" placeholder="{{ input.text }}" required>
                    {% elseif input.type == 'textarea' %}
                        {% if hiddenVal == false %}
                            {# <label for="wf_{{ input.bitrix24Id }}">{{ input.text }}</label>   #}
                            <textarea class="form-control" id="wf_{{ input.bitrix24Id }}" name="fields[{{ input.bitrix24Id }}]" placeholder="{{ input.text }}" required></textarea>
                        {% else %}
                            <textarea class="form-control" id="wf_{{ input.bitrix24Id }}" name="fields[{{ input.bitrix24Id }}]">{{ hiddenVal }}</textarea>
                        {% endif %}
                    {% endif %}
                </div>
            {% endfor %}
                
            <div class="form-group mb-0">
                <a class="staff-info__review license-link" href="{{ getPoliticaLink(regionId) }}" target="_blank">Отправляя данные, вы подтверждаете согласие на обработку персональных данных и принимаете условия политики их обработки</a>
            </div>
            <div id="smart-captcha"></div>
            <div class="form-group">
                <button disabled type="submit" class="btn btn-primary form-control mt-3" data-controller="smartCaptcha" data-form-id="wf_cabinet_{{ widget_form.id }}" data-action="click->smartCaptcha#setYm">Отправить</button>
            </div>
        </form>    
    {% else %}
        <div class="text-center">
            <img src="/images/checkmark.png" width="150" alt="ok">
            <p>Ваша заявка отправлена! <br>  Мы свяжемся с Вами в ближайшее время.</p>
        </div>
    {% endif %}
    
{% endblock %}
