{#
 # This file is part of SolidInvoice package.
 #
 # (c) Pierre du Plessis <open-source@solidworx.co>
 #
 # This source file is subject to the MIT license that is bundled
 # with this source code in the file LICENSE.
 #}

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

{% block widget_attributes -%}
    id="{{ id }}" name="{{ full_name }}"{% if disabled %} disabled="disabled"{% endif %}{% if required %} data-required="required"{% endif %}
    {% for attrname, attrvalue in attr %}{% if attrname in ['placeholder', 'title'] %}{{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}" {% else %}{{ attrname }}="{{ attrvalue }}" {% endif %}{% endfor %}
{%- endblock widget_attributes %}

{% block form_help -%}
    {%- if help is not empty -%}
        <div class="alert alert-info mt-2">
            {{ parent()|replace({'text-muted': ''})|raw }}
        </div>
    {%- endif -%}
{%- endblock form_help %}

{% block notification_widget -%}
    <strong>{{ label|default(name)|humanize|title }}</strong>
    {% if help is defined and help is not empty %}
        <span class="help-{{ help_type }}"><small>{{ help|trans|nl2br }}</small></span>
    {% endif %}

    <div class="row">
        <div class="col-md-2">
            {{ form_row(form.email) }}
        </div>
        <div class="col-md-2">
            {{ form_row(form.sms) }}
        </div>
    </div>

    {{ form_errors(form) }}
{%- endblock notification_widget %}

{% block form_label -%}
    {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' control-label')|trim}) %}
    {% if label is empty %}
        {% set label = name|humanize %}
    {% endif %}

    {% if not compound %}
        {% if required %}
            {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
        {% endif %}

        {{- parent() -}}
    {% elseif 'choice' in block_prefixes %}
        {% if required %}
            {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
        {% endif %}
        {% set compound = false %}
        {{- parent() -}}
    {% endif %}
{%- endblock form_label %}

{% block contact_detail_widget %}
    {% include "@SolidInvoiceClient/Form/contact_details.html.twig" %}
{% endblock contact_detail_widget %}

{% block contact_widget %}
    {% include "@SolidInvoiceClient/Form/contacts.html.twig" %}
{% endblock contact_widget %}

{% block tax_number_widget -%}
    <div class="input-group" {{ stimulus_controller('vat-validator', {'url': path('_tax_number_validate')}) }}>
        {{ form_widget(form, { attr: stimulus_target('vat-validator', 'input').toArray() }) }}

        <span class="input-group-btn">
            <a href="#" class="btn btn-secondary vat-validator" rel="tooltip" title="{{ 'EU Countries Only'|trans }}"
                {{ stimulus_action('vat-validator', 'validate', 'click') }}
                {{ stimulus_target('vat-validator', 'button') }}
            >
                {{ 'tax.form.input.validate'|trans }}
            </a>
        </span>
    </div>
{%- endblock tax_number_widget %}

{% block tax_choice_widget_options -%}
    {% for group_label, choice in options %}
        {% if choice is iterable %}
            <optgroup label="{{ group_label|trans({}, translation_domain) }}">
                {% set options = choice %}
                {{ block('choice_widget_options') }}
            </optgroup>
        {% else %}
            {% set attrs -%}
                data-type="{{ choice.data.type }}" data-rate="{{ choice.data.rate }}" data-id="{{ choice.data.id }}"
            {%- endset %}
            <option value="{{ choice.value }}" {{ attrs }} {% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice_translation_domain is same as(false) ? choice.label : choice.label|trans({}, choice_translation_domain) }}</option>
        {% endif %}
    {% endfor %}
{%- endblock tax_choice_widget_options %}

{% block address_widget %}
    {% set id = random() %}
    <div class="widget">

        <div class="row">
            <div class="col-md-6">
                {{ form_row(form.street1) }}
            </div>
            <div class="col-md-6">
                {{ form_row(form.street2) }}
            </div>
        </div>

        <div class="row">
            <div class="col-md-6">
                {{ form_row(form.city) }}
            </div>
            <div class="col-md-6">
                {{ form_row(form.state) }}
            </div>
        </div>

        <div class="row">
            <div class="col-md-6">
                {{ form_row(form.zip) }}
            </div>
            <div class="col-md-6">
                {{ form_row(form.country) }}
            </div>
        </div>

        {% if form.vars.button_delete is defined %}
            {{ form_widget(form.vars.button_delete, {label_html: true, label: icon('trash-o') ~ ' ' ~ 'client.address.delete'|trans, attr: {class: 'btn btn-danger btn-flat float-right'}}) }}
            <br class="clear" />
        {% endif %}

        <br class="clear"/>
    </div>
{% endblock address_widget %}

{% block settings_address_widget %}
    <legend>
        <h4>
            {{ 'Address'|trans }}
        </h4>
    </legend>

    {{ block('address_widget') }}
{% endblock settings_address_widget %}

{% block cron_widget %}
    {% set type = 'hidden' %}
    {% set attr = attr|merge({"class": "cron-expr"}) %}
    {{ block('form_widget') }}
{% endblock cron_widget %}

{% block discount_row %}
    <label for="{{ form.value.vars.id }}">{{ label }}</label>
    <div class="form-group multiple-form-group input-group">
        {{ form_widget(form.value) }}
        {{ form_widget(form.type) }}
    </div>
{% endblock discount_row %}

{% block image_upload_widget %}
    {%- if compound is defined and compound -%}
        {%- set element = 'fieldset' -%}
    {%- endif -%}
    {%- set widget_attr = {} -%}
    {%- if help is not empty -%}
        {%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
    {%- endif -%}
    <{{ element|default('div') }}{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %} {{ stimulus_controller('logo_upload') }}>
    {{ app_logo(width=100, showDefault=false) }}
    {{- form_widget(form, widget_attr) -}}
    {{- form_help(form) -}}
    </{{ element|default('div') }}>
{% endblock image_upload_widget %}
