{#
  Variables
    - form
    - fields
    - first
#}
{% block _leadlist_filters_entry_widget %}
  {% set isPrototype = ('__name__' == form.vars.name) %}
  {% set filterType = form.field.vars.value %}
  {% set inGroup = form.vars.data is defined and form.vars.data.glue is defined and 'and' == form.vars.data.glue and false == first %}
  {% set isBehavior = fields.behaviors[filterType].label is defined %}

  {% if isBehavior %}
      {% set object = 'behaviors' %}
  {% else %}
      {% set object = form.vars.data.object|default('') %}
  {% endif %}
  {% set objectIconClass = 'company' == object ? 'ri-building-2-line' : 'ri-user-6-fill' %}
  {% set filterTypeIconClass = fields[object][filterType]['iconClass']|default('') %}

  {% if isPrototype or fields[object][filterType].label is defined %}

      <div class="filter--row segment-filter d-flex fw-nowrap ai-center gap-sm {% if inGroup %}in-group{% endif %}" id="{{ id }}">
            <span class="filter--condition-when fw-sb{% if '0' != form.vars.name %} hide{% endif %}">{{ 'mautic.lead.list.form.glue.when'|trans }}</span>
            <div class="filter--condition panel-glue d-flex ai-center gap-xs pl-0{% if '0' == form.vars.name %} hide{% endif %}">
                <i class="ri-draggable ri-1x text-primary"></i>
                {{ form_widget(form.glue) }}
            </div>

            <div class="filter--panel panel">
                <div class="d-flex fw-nowrap">
                    <div class="filter--field-name d-flex ai-center pr-lg pl-lg" size="lg">
                        {% set objectLabel = translatorHasId('mautic.lead_list.filter.' ~ object) ? ('mautic.lead_list.filter.' ~ object)|trans : object|trans  %}
                        <i class="object-icon {{ filterTypeIconClass }}" aria-hidden="true"></i>
                        <span> {% if isPrototype %}__label__{% else %}{{ 'mautic.lead_list.filter.field.label'|trans({'%object%': objectLabel, '%field%': fields[object][filterType]['label'] })|raw}}{% endif %}</span>
                    </div>

                    <div class="filter--field-operator fs-0">
                        {{ form_widget(form.operator) }}
                    </div>

                    {% set hasErrors = (form.properties.vars.errors|length > 0) %}
                    <div class="filter--field-properties fg-1 {% if hasErrors %}has-error{% endif %}">
                        <div class="properties-form">
                            {{ form_widget(form.properties) }}
                        </div>
                        {{ form_errors(form.properties) }}
                    </div>
                    {{ form_widget(form.field) }}
                    {{ form_widget(form.type) }}
                    {{ form_widget(form.object) }}
                </div>
            </div>
            <div class="pr-0 pull-right">
                <div class="segment-button btn-group d-flex jc-end pull-right" role="group">
                    {% include '@MauticCore/Helper/button.html.twig' with {
                        buttons: [
                            {
                                label: 'mautic.lead_list.filter.label.clonefilter',
                                variant: 'ghost',
                                icon_only: true,
                                size: 'sm',
                                icon: 'ri-file-copy-line',
                                href: 'javascript: void(0);',
                                attributes: {
                                'class': 'copy-filter-group',
                            },
                            },
                            {
                                label: 'mautic.lead_list.filter.label.removefilter',
                                variant: 'ghost',
                                icon_only: true,
                                size: 'sm',
                                danger: 'true',
                                icon: 'ri-delete-bin-line',
                                href: 'javascript: void(0);',
                                attributes: {
                                'class': 'remove-selected',
                            },
                            }
                        ]
                    } %}
                </div>
            </div>
    </div>

  {% endif %}
{% endblock %}
