{#
  Variables
    - lead
    - events
#}
{% extends '@MauticCore/Default/content.html.twig' %}

{% block mauticContent %}lead{% endblock %}

{% set isAnonymous = lead.isAnonymous %}
{% set leadName = lead.isAnonymous ? lead.primaryIdentifier|trans : lead.primaryIdentifier %}
{% set avatar %}
  {% if not isAnonymous %}
    <span class="pull-left img-wrapper img-rounded mr-10" style="width:33px"><img src="{{ leadGetAvatar(lead) }}" alt="" /></span>
  {% endif %}
{% endset %}

{% set flag = fields.core.country is defined and fields.core.country.value is not empty ? assetGetCountryFlag(fields.core.country.value) : '' %}
{% set groups = fields|keys %}

{% block headerTitle %}
    {{ avatar }}<div class="pull-left mt-5"><span class="span-block">{{ leadName|purify }}</span><span class="span-block small ml-sm">
    {{ lead.secondaryIdentifier|purify }}</span></div>
    {{ customContent('lead.name.after', _context) }}
{% endblock %}

{% block preHeader %}
{{- include('@MauticCore/Helper/page_actions.html.twig',
    {
        'item'            : lead,
        'routeBase'       : 'contact',
        'langVar'         : 'lead.lead',
        'customButtons'   : [],
        'templateButtons' : {
            'close' : securityHasEntityAccess(
                permissions['lead:leads:viewown'],
                permissions['lead:leads:viewother'],
                lead.permissionUser
            ),
        },
        'targetLabel'     : 'mautic.lead.leads'|trans
    }
) -}}
{% endblock %}

{% block actions %}
    {% set canEdit = securityHasEntityAccess(permissions['lead:leads:editown'], permissions['lead:leads:editother'], lead.permissionUser) %}
    {% set buttons = [] %}

    {% if fields.core.email is defined %}
        {% set emailAdress = fields.core.email.value %}
        {% set sendButton = {
            'attr': {
                'id': 'sendEmailButton',
                'data-toggle': 'ajaxmodal',
                'data-target': '#MauticSharedModal',
                'data-header': 'mautic.lead.email.send_email.header'|trans({'%email%': emailAdress}),
                'href': path('mautic_contact_action', {'objectId': lead.id, 'objectAction': 'email'}),
            },
            'btnText': 'mautic.lead.email.send_email'|trans,
            'iconClass': 'ri-mail-send-line',
            'primary': true,
        } %}
        {% if emailAdress is empty %}
            {% set sendButton = sendButton|merge({'tooltip' : 'mautic.lead.email.send_email.disabled'}) %}
            {% set sendButton = sendButton|merge({'attr' : {'disabled' : true}}) %}
        {% endif %}
        {% set buttons = buttons|merge([sendButton]) %}
    {% endif %}

    {% if canEdit %}
        {% set buttons = buttons|merge([{
            'attr': {
                'data-toggle': 'ajaxmodal',
                'data-target': '#MauticSharedModal',
                'data-header': 'mautic.lead.lead.header.contact.frequency'|trans({'%name%': lead.primaryIdentifier|e}),
                'href': path('mautic_contact_action', {'objectId': lead.id, 'objectAction': 'contactFrequency'}),
            },
            'btnText': 'mautic.lead.contact.frequency'|trans,
            'iconClass': 'ri-settings-5-line',
        }]) %}

        {% if pointGroups is not empty %}
            {% set buttons = buttons|merge([{
                'attr': {
                    'data-toggle': 'ajaxmodal',
                    'data-target': '#MauticSharedModal',
                    'data-header': 'mautic.lead.groups.panel.title'|trans,
                    'href': path('mautic_contact_action', {'objectId': lead.id, 'objectAction': 'contactGroupPoints'}),
                },
                'btnText': 'mautic.lead.groups.panel.title'|trans,
                'iconClass': 'ri-coins-line',
            }]) %}
        {% endif %}
    {% endif %}

    {% if securityIsGranted('campaign:campaigns:edit') %}
        {% set buttons = buttons|merge([{
            'attr': {
                'data-toggle': 'ajaxmodal',
                'data-target': '#MauticSharedModal',
                'data-header': 'mautic.lead.lead.header.campaigns'|trans({'%name%': lead.primaryIdentifier|e}),
                'data-footer': 'false',
                'href': path('mautic_contact_action', {'objectId': lead.id, 'objectAction': 'campaign'}),
            },
            'btnText': 'mautic.campaign.campaigns'|trans,
            'iconClass': 'ri-megaphone-line',
        }]) %}
    {% endif %}

    {% if securityHasEntityAccess(permissions['lead:leads:deleteown'], permissions['lead:leads:deleteother'], lead.permissionUser) and canEdit %}
        {% set buttons = buttons|merge([{
            'attr': {
                'data-toggle': 'ajaxmodal',
                'data-target': '#MauticSharedModal',
                'data-header': 'mautic.lead.lead.header.merge'|trans({'%name%': lead.primaryIdentifier|e}),
                'href': path('mautic_contact_action', {'objectId': lead.id, 'objectAction': 'merge'}),
            },
            'btnText': 'mautic.lead.merge'|trans,
            'iconClass': 'ri-exchange-2-line',
        }]) %}
    {% endif %}

    {% if securityHasEntityAccess(permissions['lead:leads:viewown'], permissions['lead:leads:viewother'], lead.permissionUser) and enableExportPermission is not empty %}
        {% set buttons = buttons|merge([{
            'attr': {
                'data-toggle': 'download',
                'href': path('mautic_contact_export_action', {'contactId': lead.id}),
            },
            'btnText': 'mautic.core.export'|trans,
            'iconClass': 'ri-export-line',
        }]) %}
    {% endif %}

    {{ include('@MauticCore/Helper/page_actions.html.twig', {
            'item': lead,
            'routeBase': 'contact',
            'langVar': 'lead.lead',
            'customButtons': buttons,
            'templateButtons': {
                'edit': canEdit,
                'delete': securityHasEntityAccess(
                    permissions['lead:leads:deleteown'],
                    permissions['lead:leads:deleteother'],
                    lead.permissionUser
                ),
            },
    }) }}
{% endblock %}

{% block content %}
<!-- start: box layout -->
<div class="box-layout">
    <!-- left section -->
    <div class="col-md-9 height-auto">
        <div>
            <!--/ lead detail header -->

            <!-- lead detail collapseable -->
            <div class="collapse pr-md pl-md" id="lead-details">
                <ul class="pt-md nav nav-tabs nav-tabs-contained" role="tablist">
                    {% for g in groups %}
                        {% if fields[g] is not empty %}
                            <li class="{% if loop.first %}active{% endif %}">
                                <a href="#{{ g }}" class="group" data-toggle="tab">
                                    {{ ('mautic.lead.field.group.'~g)|trans }}
                                </a>
                            </li>
                        {% endif %}
                    {% endfor %}
                        <li>
                            <a href="#devices" class="group" data-toggle="tab">{{ 'mautic.lead.devices'|trans }}</a>
                        </li>
                    <li>
                        <a href="#lead-stats" class="group" data-toggle="tab">{{ 'mautic.lead.stats'|trans }}</a>
                    </li>
                </ul>

                <!-- start: tab-content -->
                <div class="tab-content pa-md">
                    {% for group in groups %}
                        <div class="tab-pane fade {% if loop.first %}in active{% endif %} bdr-w-0" id="{{ group }}">
                            <div class="pr-md pl-md pb-md">
                                <div class="panel shd-none mb-0">
                                    <table class="table table-hover mb-0">
                                        <tbody>
                                        {% if 'core' == group %}
                                          {{ include('@MauticCore/Helper/details.html.twig', {'entity': lead}) }}
                                        {% endif %}
                                        {% set no_result = true %}
                                        {% for field in fields[group] %}
                                            {% if field.value is not empty %}
                                                {%  set no_result = false %}
                                                <tr>
                                                    <td width="20%"><span class="fw-b textTitle">{{ field.label|purify }}</span></td>
                                                    <td>
                                                        {% if 'core' == group and 'country' == field.alias and flag is not empty %}
                                                            <img class="mr-sm" src="{{ flag }}" alt="" style="max-height: 24px;"/>
                                                            <span class="mt-1">{{ field.value|purify }}</span>
                                                        {% else %}
                                                            {% if 'multiselect' == field.type %}
                                                                {% if field.value is iterable %}
                                                                    {{ field.value|join(', ') }}
                                                                {% else %}
                                                                    {{ field.normalizedValue|purify|replace({'|': ', '}) }}
                                                                {% endif %}
                                                            {% elseif 'url' == field.type %}
                                                                <a href="{{ field.value|purify }}" target="_blank">{{ field.value }}</a>
                                                            {% elseif 'html' == field.type %}
                                                                <div style="resize: vertical; overflow: auto">{{ field.value|raw }}</div>
                                                            {% elseif 'datetime' == field.type %}
                                                                {{ dateToFullConcat(field.value, 'UTC') }}
                                                            {% else %}
                                                                {{ field.normalizedValue|purify }}
                                                            {% endif %}
                                                        {% endif %}
                                                    </td>
                                                </tr>
                                            {% endif %}
                                        {% endfor %}

                                        {% if no_result %}
                                            <tr><td colspan="2">{{ 'mautic.lead.field.group.no_data'|trans }}</td></tr>
                                        {% endif %}

                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                        <div class="tab-pane fade bdr-w-0" id="devices">
                            {% if devices %}
                                {{ include('@MauticLead/Lead/_devices.html.twig', {'devices': devices}) }}
                            {% else %}
                                {{ include('@MauticCore/Helper/no_information.html.twig', {'tip': 'mautic.contact.noinformation.devices'}) }}
                            {% endif %}
                        </div>
                    <div class="tab-pane fade bdr-w-0" id="lead-stats" data-target-url="{{ path('mautic_contact_stats', {'objectId': lead.id}) }}">
                        <div class="spinner"><i class="ri-loader-3-line ri-spin"></i></div>
                    </div>
                </div>
            </div>
            <!--/ lead detail collapseable -->
        </div>

        <div>
            <!-- lead detail collapseable toggler -->
            <div class="hr-expand nm">
                <span data-toggle="tooltip" title="{{ 'mautic.core.details'|trans }}">
                    <a href="javascript:void(0)" class="arrow text-secondary collapsed" data-toggle="collapse" data-target="#lead-details">
                       <span class="caret"></span>
                       {{ 'mautic.core.details'|trans }}
                    </a>
                </span>
            </div>
            <!--/ lead detail collapseable toggler -->

            {% if not isAnonymous %}
                <div class="pa-md">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="panel">
                                <div class="panel-body box-layout">
                                    <div class="col-xs-8 va-m">
                                        <h5 class="text-white dark-md fw-sb mb-xs">{{ 'mautic.lead.field.header.engagements'|trans }}</h5>
                                    </div>
                                    <div class="col-xs-4 va-t text-right">
                                        <h3 class="text-white dark-sm"><span class="ri-eye-line"></span></h3>
                                    </div>
                                </div>
                                <div class="d-flex fd-column pt-0 pl-15 pb-15 pr-15 min-h-256">
                                    {{ include('@MauticCore/Helper/chart.html.twig', {'chartData': engagementData, 'chartType': 'line', 'chartHeight': 250}) }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            {% endif %}
        </div>

        <div class="pa-md">
            <!-- tabs controls -->
            <ul class="nav nav-tabs nav-tabs-contained mt-10">
                <li class="active">
                    <a href="#timeline-container" role="tab" data-toggle="tab">
                        <span size="sm" class="label label-primary mr-sm" id="TimelineCount">
                            {{ events.total }}
                        </span>
                        {{ 'mautic.lead.lead.tab.history'|trans }}
                    </a>
                </li>
                <li class="">
                    <a href="#notes-container" role="tab" data-toggle="tab">
                        <span size="sm" class="label label-primary mr-sm" id="NoteCount">
                            {{ noteCount }}
                        </span>
                        {{ 'mautic.lead.lead.tab.notes'|trans }}
                    </a>
                </li>
                {% if not isAnonymous %}
                    <li class="">
                        <a href="#social-container" role="tab" data-toggle="tab">
                        <span size="sm" class="label label-primary mr-sm" id="SocialCount">
                            {{ socialProfiles|length }}
                        </span>
                            {{ 'mautic.lead.lead.tab.social'|trans }}
                        </a>
                    </li>
                {% endif %}
                <li class="">
                    <a href="#integration-container" role="tab" data-toggle="tab">
                    <span size="sm" class="label label-primary mr-sm" id="IntegrationCount">
                        {{ integrations|length }}
                    </span>
                        {{ 'mautic.lead.lead.tab.integration'|trans }}
                    </a>
                </li>
                <li class="">
                    <a href="#auditlog-container" role="tab" data-toggle="tab">
                    <span size="sm" class="label label-primary mr-sm" id="AuditLogCount">
                        {{ auditlog.total }}
                    </span>
                        {{ 'mautic.lead.lead.tab.auditlog'|trans }}
                    </a>
                </li>
                    <li class="">
                        <a href="#place-container" role="tab" data-toggle="tab" id="load-lead-map">
                        <span size="sm" class="label label-primary mr-sm" id="PlaceCount">
                            {{ places|length }}
                        </span>
                            {{ 'mautic.lead.lead.tab.places'|trans }}
                        </a>
                    </li>
                {{ customContent('tabs', _context) }}
            </ul>
            <!--/ tabs controls -->

            <!-- start: tab-content -->
            <div class="tab-content pa-md">
                <!-- #history-container -->
                <div class="tab-pane fade in active bdr-w-0" id="timeline-container">
                    {{ include('@MauticLead/Timeline/list.html.twig', {'events': events, 'lead': lead}) }}
                </div>
                <!--/ #history-container -->

                <!-- #notes-container -->
                <div class="tab-pane fade bdr-w-0" id="notes-container">
                    {{ render(controller('Mautic\\LeadBundle\\Controller\\NoteController::indexAction', {'leadId': lead.id, 'ignoreAjax': 1})) }}
                </div>
                <!--/ #notes-container -->

                <!-- #social-container -->
                {% if not isAnonymous %}
                    <div class="tab-pane fade bdr-w-0" id="social-container">
                        {{ include('@MauticLead/Social/index.html.twig', {
                            'lead': lead,
                            'socialProfiles': socialProfiles,
                            'socialProfileUrls': socialProfileUrls,
                        }) }}
                    </div>
                {% endif %}
                <!--/ #social-container -->

                <!-- #integration-container -->
                <div class="tab-pane fade bdr-w-0" id="integration-container">
                    {{ include('@MauticLead/Integration/index.html.twig', {
                        'lead': lead,
                        'integrations': integrations,
                    }) }}
                </div>
                <!--/ #integration-container -->

                <!-- #auditlog-container -->
                <div class="tab-pane fade bdr-w-0" id="auditlog-container">
                    {{ include('@MauticLead/Auditlog/_list.html.twig', {
                        'lead': lead,
                        'events': auditlog,
                    }) }}
                </div>
                <!--/ #auditlog-container -->

                <!-- custom content -->
                {{ customContent('tabs.content', _context) }}
                <!-- end: custom content -->

                <!-- #place-container -->
                    <div class="tab-pane fade bdr-w-0" id="place-container">
                        {% if not places and not configGetParameter('ip_lookup_auth') %}
                            {{ include('@MauticCore/Helper/no_information.html.twig', {
                                'tip': 'mautic.contact.noinformation.places'
                            }) }}
                        {% endif %}
                        {{ include('@MauticLead/Lead/_map.html.twig', {'places': places}) }}
                    </div>
                <!--/ #place-container -->
            </div>
            <!--/ end: tab-content -->
        </div>

    </div>
    <!--/ left section -->

    <!-- right section -->
    <div class="col-md-3 bdr-l height-auto">
        <!-- form HTML -->
        <div class="panel shd-none bdr-rds-0 bdr-w-0 mb-0">
            {% if not lead.isAnonymous %}
                <div class="lead-avatar-panel">
                    <div class="avatar-collapser hr-expand nm">
                        <a href="javascript:void(0)"
                            class="arrow text-secondary text-center {% if 'expanded' != avatarPanelState %}collapsed{% endif %}"
                            data-toggle="collapse"
                            data-target="#lead-avatar-block">
                            <span class="caret"></span>
                        </a>
                    </div>
                    <div class="collapse {% if 'expanded' == avatarPanelState %}in{% endif %}" id="lead-avatar-block">
                        <img class="img-responsive" src="{{ leadGetAvatar(lead) }}" alt="{{ leadName|e }}"/>
                    </div>
                </div>
            {% endif %}
            <div class="mt-sm points-panel text-center">
                <h1 style="{% if lead.color is not empty %}font-color:{{ lead.color }} !important;{% endif %}">
                    {{ 'mautic.lead.points.count'|trans({'%count%': lead.points}) }}
                </h1>
                <hr/>
                {% if lead.stage %}
                    {{ lead.stage.name|purify }}<hr>
                {% endif %}
            </div>

            {% if lead.groupScores is not empty %}
                <div class="panel-heading">
                    <div class="panel-title">
                        {{ 'mautic.lead.groups.panel.title'|trans }}
                    </div>
                </div>

                <div class="panel-body pt-sm group-points-panel">
                    {% for groupScore in lead.groupScores %}
                        <div class="row">
                            <h6 class="fw-sb col-md-6">
                                {{ groupScore.group.name }}
                            </h6>
                            <p class="text-secondary col-md-6">
                                {{ 'mautic.lead.points.count'|trans({'%count%': groupScore.score}) }}
                            </p>
                        </div>
                    {% endfor %}
                </div>
            {% endif %}

            {% if doNotContact %}
                {{ include('@MauticLead/Lead/_dnc_large.html.twig', {'doNotContact': doNotContact}) }}
            {% endif %}
            {% if doNotContactSms %}
                {{ include('@MauticLead/Lead/_dnc_large.html.twig', {'doNotContact': doNotContactSms}) }}
            {% endif %}
            <div class="panel-heading">
                <div class="panel-title">
                    {{ 'mautic.lead.field.header.contact'|trans }}
                </div>
            </div>
            <div class="panel-body pt-sm">
            {% if lead.owner %}
                <h6 class="fw-sb">{{ 'mautic.lead.lead.field.owner'|trans }}</h6>
                <p class="text-secondary">{{ lead.owner.name|purify }}</p>
            {% endif %}

                <h6 class="fw-sb">
                    {{ 'mautic.lead.field.address'|trans }}
                </h6>
                <address class="text-secondary">
                    {% if fields.core.address1 is defined %}{{ fields.core.address1.value|purify }}<br>{% endif %}
                    {% if fields.core.address2 is defined %}{{ fields.core.address2.value|purify }}<br>{% endif %}
                    {{ lead.location|purify }}
                    {% if fields.core.zipcode is defined %}{{ fields.core.zipcode.value|purify }}{% endif %}
                    <br>
                </address>

                <h6 class="fw-sb">{{ 'mautic.core.type.email'|trans }}</h6>
                <p class="text-secondary">{{ fields.core.email.value|purify }}</p>

                {% if fields.core.phone is defined %}
                    <h6 class="fw-sb">{{ 'mautic.lead.field.type.tel.home'|trans }}</h6>
                    <p class="text-secondary">{{ fields.core.phone.value|purify }}</p>
                {% endif %}

                {% if fields.core.mobile is defined %}
                    <h6 class="fw-sb">{{ 'mautic.lead.field.type.tel.mobile'|trans }}</h6>
                    <p class="text-secondary mb-0">{{ fields.core.mobile.value|purify }}</p>
                {% endif %}
            </div>
        </div>
        <!--/ form HTML -->

            <hr class="hr-w-2" style="width:50%">

            <div class="panel shd-none bdr-rds-0 bdr-w-0">
                <div class="panel-heading">
                    <div class="panel-title">{{ 'mautic.lead.lead.upcoming.events'|trans }}</div>
                </div>
                {% if not upcomingEvents %}
                    {{ include('@MauticCore/Helper/no_information.html.twig', {'tip': 'mautic.contact.noinformation.upcoming'}) }}
                {% endif %}
                <div class="panel-body pt-sm">
                    <ul class="media-list media-list-feed">
                        {% for event in upcomingEvents %}
                            {% set metadata = serializerDecode(event.metadata) %}
                            {% set errors = false %}
                            {% if metadata.errors is defined and metadata.errors is not empty %}
                                {% set errors = metadata.errors is iterable ? metadata.errors|join('<br/>') : metadata.errors %}
                            {% endif %}
                            <li class="media">
                                <div class="media-object pull-left mt-xs">
                                    <span class="figure"></span>
                                </div>
                                <div class="media-body">
                                    {{ 'mautic.lead.lead.upcoming.event.triggered.at'|trans({
                                          '%event%': event.event_name,
                                          '%link%': '<a href="'~path('mautic_campaign_action', {'objectAction': 'view', 'objectId': event.campaign_id})~'" data-toggle="ajax">'~event.campaign_name~'</a>',
                                    })|purify }}
                                    {% if errors is not empty %}
                                      <i class="ri-alert-line text-danger" data-toggle="tooltip" title="{{ errors|purify }}"></i>
                                    {% endif %}
                                    <p class="fs-12 dark-sm timeline-campaign-event-date-{{ event.event_id }}">
                                      {{ dateToFull(event.trigger_date, 'utc') }}
                                    </p>
                                </div>
                            </li>
                        {% endfor %}
                    </ul>
                </div>
            </div>

        <div class="pa-sm">
            {% if lead.tags|length <= 8 %}
                {# Use tile--base for 8 or fewer tags #}
                {% set tagContent %}
                <div class="d-flex jc-space-between">
                    <span class="fw-b ellipsis mb-md">{{ 'mautic.lead.tags'|trans }}</span>
                    <i class="ri-hashtag" aria-hidden="true"></i>
                </div>
                <div class="d-flex fw-wrap gap-xs mt-xs">
                    {% if lead.tags|length > 0 %}
                        {% for tag in lead.tags %}
                            <div id="tagLabel{{ tag.id }}">
                                {% include '@MauticCore/Helper/_tag.html.twig' with {'tags': [{
                                    'label': tag.tag|purify,
                                    'attributes': {
                                        'href': path('mautic_tagmanager_action', {'objectAction': 'view', 'objectId': tag.id}),
                                        'data-toggle': 'ajax',
                                    },
                                    'color': 'blue',
                                    'type': 'dismissible',
                                    'dismissible_onclick': 'Mautic.removeTagFromLead(this, ' ~ lead.id ~ ', ' ~ tag.id ~ ', event);'
                                }]} %}
                            </div>
                        {% endfor %}
                    {% else %}
                        <p class="text-helper">{{ 'mautic.lead.tags.no_results'|trans }}</p>
                    {% endif %}
                    </div>
                {% endset %}
                
                {% include '@MauticCore/Components/tile.html.twig' with {
                    'type': 'base',
                    'content': tagContent
                } %}
            {% else %}
                {# Use tile--expandable-interactive for more than 8 tags #}
                {% set firstEightTags = lead.tags|slice(0, 8) %}
                {% set remainingTags = lead.tags|slice(8) %}
                
                {% set aboveContent %}
                <div class="d-flex jc-space-between">
                    <span class="fw-b ellipsis mb-md">{{ 'mautic.lead.tags'|trans }}</span>
                    <i class="ri-hashtag" aria-hidden="true"></i>
                </div>
                    <div class="d-flex fw-wrap gap-xs">
                    {% for tag in firstEightTags %}
                        <div id="tagLabel{{ tag.id }}">
                            {% include '@MauticCore/Helper/_tag.html.twig' with {'tags': [{
                                'label': tag.tag|purify,
                                'attributes': {
                                    'href': path('mautic_tagmanager_action', {'objectAction': 'view', 'objectId': tag.id}),
                                    'data-toggle': 'ajax',
                                },
                                'color': 'blue',
                                'type': 'dismissible',
                                'dismissible_onclick': 'Mautic.removeTagFromLead(this, ' ~ lead.id ~ ', ' ~ tag.id ~ ', event);'
                            }]} %}
                        </div>
                    {% endfor %}
                    </div>
                {% endset %}
                
                {% set belowContent %}
                <div class="d-flex fw-wrap gap-xs mt-xs">
                    {% for tag in remainingTags %}
                        <div id="tagLabel{{ tag.id }}">
                            {% include '@MauticCore/Helper/_tag.html.twig' with {'tags': [{
                                'label': tag.tag|purify,
                                'attributes': {
                                    'href': path('mautic_tagmanager_action', {'objectAction': 'view', 'objectId': tag.id}),
                                    'data-toggle': 'ajax',
                                },
                                'color': 'blue',
                                'type': 'dismissible',
                                'dismissible_onclick': 'Mautic.removeTagFromLead(this, ' ~ lead.id ~ ', ' ~ tag.id ~ ', event);'
                            }]} %}
                        </div>
                    {% endfor %}
                    </div>
                {% endset %}
                
                {% include '@MauticCore/Components/tile.html.twig' with {
                    'type': 'expandable-interactive',
                    'aboveFoldContent': aboveContent,
                    'belowFoldContent': belowContent
                } %}
            {% endif %}
        </div>
        <div class="pa-sm panel-companies layout--size-0">
            {% if companies is defined and companies|length > 0 %}
                {% set companiesList = [] %}
                {% for key, company in companies %}
                    {% set companiesList = companiesList|merge([{
                        'label': company.companyname|purify,
                        'link': path('mautic_company_action', {'objectAction': 'view', 'objectId': company.id}),
                        'icon': (company.is_primary == 1 ? 'ri-user-star-fill' : ''),
                        'button': {
                            'onclick': 'Mautic.setAsPrimaryCompany(' ~ company.id ~ ', ' ~ lead.id ~ ');',
                            'icon': 'ri-check-line',
                            'size': 'lg',
                            'label': 'mautic.lead.company.set.primary'|trans
                        }
                    }]) %}
                {% endfor %}

                {% set tileContent %}
                <div class="ma-neg-local">
                    {{ include('@MauticCore/Components/contained-list.html.twig', {
                        'title': 'mautic.lead.lead.companies'|trans,
                        'items': companiesList,
                        'variant': 'interactive-actions'
                    }) }}
                </div>
                {% endset %}

                {{ include('@MauticCore/Components/tile.html.twig', {
                    'type': 'base',
                    'content': tileContent
                }) }}
            {% else %}
                {% set content %}
                <div class="d-flex jc-space-between">
                    <span class="fw-b ellipsis mb-md">{{ 'mautic.lead.lead.companies'|trans }}</span>
                    <i class="ri-building-line" aria-hidden="true"></i>
                </div>
                <p class="text-helper">{{ 'mautic.lead.lead.companies.no_results'|trans }}</p>
                <div class="clearfix"></div>
                {% endset %}
                
                {% include '@MauticCore/Components/tile.html.twig' with {'type': 'base', 'content': content} %}
            {% endif %}
        </div>
        <div class="pa-sm">
            {% if lists[lead.id] is defined and lists[lead.id]|length > 0 %}
                {% set segments = lists[lead.id] %}
                {% set classes = ['gray', 'red', 'magenta', 'purple', 'blue', 'cyan', 'teal', 'green'] %}
                
                {% if segments|length <= 8 %}
                    {% set content %}
                        <div class="d-flex jc-space-between">
                            <span class="fw-b ellipsis mb-md">{{ 'mautic.lead.lead.lists'|trans }}</span>
                            <i class="ri-pie-chart-line" aria-hidden="true"></i>
                        </div>
                        <div class="d-flex fw-wrap gap-xs">
                            {% for key, list in segments %}
                                {% set tag = {
                                    'label': list.name|purify,
                                    'attributes': {
                                        'href': path('mautic_segment_action', {'objectAction': 'view', 'objectId': list.id}),
                                        'data-toggle': 'ajax'
                                    },
                                    'color': cycle(classes, key)
                                } %}
                                {% include '@MauticCore/Helper/_tag.html.twig' with {'tags': [tag]} %}
                            {% endfor %}
                        </div>
                    {% endset %}
                    
                    {% include '@MauticCore/Components/tile.html.twig' with {'type': 'base', 'content': content} %}
                {% else %}
                    {% set aboveContent %}
                        <div class="d-flex jc-space-between">
                            <span class="fw-b ellipsis mb-md">{{ 'mautic.lead.lead.lists'|trans }}</span>
                            <i class="ri-pie-chart-line" aria-hidden="true"></i>
                        </div>
                        <div class="d-flex fw-wrap gap-xs">
                            {% for key, list in segments|slice(0, 8) %}
                                {% set tag = {
                                    'label': list.name|purify,
                                    'attributes': {
                                        'href': path('mautic_segment_action', {'objectAction': 'view', 'objectId': list.id}),
                                    'data-toggle': 'ajax'
                                },
                                'color': cycle(classes, key)
                            } %}
                            {% include '@MauticCore/Helper/_tag.html.twig' with {'tags': [tag]} %}
                        {% endfor %}
                        </div>
                    {% endset %}
                    
                    {% set belowContent %}
                        <div class="d-flex fw-wrap gap-xs mt-xs">
                        {% for key, list in segments|slice(8) %}
                            {% set tag = {
                                'label': list.name|purify,
                                'attributes': {
                                    'href': path('mautic_segment_action', {'objectAction': 'view', 'objectId': list.id}),
                                    'data-toggle': 'ajax'
                                },
                                'color': cycle(classes, key + 8)
                            } %}
                            {% include '@MauticCore/Helper/_tag.html.twig' with {'tags': [tag]} %}
                        {% endfor %}
                        </div>
                    {% endset %}
                    
                    {% include '@MauticCore/Components/tile.html.twig' with {
                        'type': 'expandable-interactive',
                        'aboveFoldContent': aboveContent,
                        'belowFoldContent': belowContent
                    } %}
                {% endif %}
            {% else %}
                {% set content %}
                <div class="d-flex jc-space-between">
                    <span class="fw-b ellipsis mb-md">{{ 'mautic.lead.lead.lists'|trans }}</span>
                    <i class="ri-pie-chart-line" aria-hidden="true"></i>
                </div>
                <p class="text-helper">{{ 'mautic.lead.lead.lists.no_results'|trans }}</p>
                <div class="clearfix"></div>
                {% endset %}
                
                {% include '@MauticCore/Components/tile.html.twig' with {'type': 'base', 'content': content} %}
            {% endif %}
        </div>

          <div class="clearfix"></div>
        </div>
    </div>
    <!--/ right section -->
</div>
<!--/ end: box layout -->
{% endblock %}
