{%- block aa_file_widget -%}
    {{ form_errors(form) }}
    {% set mediaUrl = null %}
    {% if form.vars.data is not null %}
        {% set mediaUrl = media_url(form.vars.data) %}
    {% endif %}
    {% set svgLinkIcon %}
        {% include '@AutoAdminMedia/Form/icon/link_icon.svg' %}
    {% endset %}
    <div class="aa-file">
        <div class="row">
            <div class="col-4">
                <div class="preview">
                    <label for="">&nbsp;</label>
                    {% if mediaUrl is defined and mediaUrl is not empty %}
                        <a href="{{ mediaUrl }}" target="_blank">{{ svgLinkIcon }} {{ mediaUrl }}</a>
                    {% endif %}
                </div>
                <div class="file-input">
                    <div class="form-group">
                        {% set subAttr = form.file.vars.attr|default({})|merge({
                            placeholder:
                            (form.vars.data.fileName|default(form.file.vars.attr.placeholder|default('-'))),
                        }) %}

                        {% if form.file.vars.errors|length %}
                            {% set subAttr = subAttr|merge({'autofocus': null}) %}
                        {% endif %}

                        {{ form_widget(form.file, {attr: subAttr}) }}
                        <small>{{ 'media.max_upload_size_label'|trans({'max_upload_size': max_upload_size}, 'aa_admin')|raw }}</small>
                        {{ form_errors(form.file) }}
                    </div>
                </div>
            </div>
            <div class="col">
                <div class="form-group">
                    {{- form_row(form.title) -}}
                </div>
            </div>
        </div>
        {% if form.delete_media is defined %}
            <div class="delete-wrap">
                {#            {{- form_row(form.delete_media, {attr: {class: 'my-class'}}) -}}#}
                {{- form_widget(form.delete_media) -}}
                {{- form_label(form.delete_media) -}}
            </div>
        {% endif %}
    </div>
{%- endblock -%}

{%- block aa_image_widget -%}
    {% set mediaUrl = null %}
    {% if form.vars.data is not null %}
        {% set mediaUrl = media_url(form.vars.data) %}
    {% endif %}
  {% set svgLinkIcon %}
      {% include '@AutoAdminMedia/Form/icon/link_icon.svg' %}
  {% endset %}
  {% set svgMissingMediaIcon %}
      {% include '@AutoAdminMedia/Form/icon/missing_image.svg' %}
  {% endset %}
    <div class="aa-image">
        <div class="row">
            <div class="col-4">
                <div class="preview {% if mediaUrl|default('') is empty %} missing-media{% endif %}">
                    <div href="{{ mediaUrl|default('') }}"
                         target="_blank"
                         class="preview-wrap"
                    >
                        <img
                            src="{{ mediaUrl|default()|webp()}}"
                            title="{{ form.vars.data.title|default() }}"
                            alt="{{ form.vars.data.alt|default() }}"
                            loading="lazy"
                        />
                        <div class="no-media-icon">{{ svgMissingMediaIcon }}</div>
                    </div>
                    <a href="{{ mediaUrl }}" target="_blank" class="media-link">{{ svgLinkIcon|raw }} {{ mediaUrl }}</a>
                </div>

            </div>
            <div class="col">
                <div class="file-input">
                    <div class="form-group">
                        {% set subAttr = form.file.vars.attr|default({})|merge({
                            placeholder:
                            (form.vars.data.fileName|default(form.file.vars.attr.placeholder|default('-')))
                        }) %}

                        {% if form.file.vars.errors|length %}
                            {% set subAttr = subAttr|merge({'autofocus': null}) %}
                        {% endif %}

                        {{ form_widget(form.file, {attr: subAttr}) }}
                        <small>{{ 'media.max_upload_size_label'|trans({'max_upload_size': max_upload_size}, 'aa_admin')|raw }}</small>
                        {{ form_errors(form.file) }}
                    </div>
                </div>
                <div class="form-group">
                    {{ form_row(form.title) }}
                </div>
                <div class="form-group">
                    {{ form_row(form.alt) }}
                </div>
                {% if form.id is defined %}
                    {{ form_row(form.id) }}
                {% endif %}

            </div>
        </div>
        {% if form.delete_media is defined %}
            <div class="delete-wrap">
                {#            {{- form_row(form.delete_media, {attr: {class: 'my-class'}}) -}}#}
                {{- form_widget(form.delete_media) -}}
                {{- form_label(form.delete_media) -}}
            </div>
        {% endif %}
    </div>
{%- endblock -%}

{#{%- block aa_file_label -%}#}
{#    {%- set label = label|trans|default(label) -%}#}
{#    {{- block('form_label') -}}#}
{#{%- endblock -%}#}


{#{%- block aa_media_collection_row -%}#}
{#    {% set row_attr = form.vars.row_attr %}#}
{#    {% set row_attr = row_attr|merge({class: row_attr.class|default('') ~ ' aa-media-collection-wrap'}) %}#}
{#    {{- block('form_row') -}}#}
{#{%- endblock -%}#}

{#{%- block aa_media_collection_widget -%}#}
{#    {% set subAttr = {#}
{#        'data-form-allow-add': form.vars.allow_add,#}
{#        'data-form-allow-add': form.vars.allow_delete,#}
{#        'data-form-required': form.vars.required,#}
{#    } %}#}

{#    {% set attr = form.vars.attr %}#}
{#    {% set attr = attr|merge({class: attr.class|default('') ~ ' aa-media-collection'}) %}#}

{#    {{ form_widget(form, {attr: attr|merge(subAttr)})}}#}
{#    {{ dump(form.vars) }}#}
{#    {% if form.vars.allow_add %}#}
{#        <button class="btn btn-secondary aa-media-collection-add">+ {{ 'aa_media.add_image'|trans }}</button>#}
{#    {% endif %}#}
{#{%- endblock -%}#}