{% import 'elementor/macros' as m %}
{% macro color(mode, value, network) %}{% if mode == 'custom' and value matches '/^#([0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$|^(rgb|rgba|hsl|hsla)\\([0-9.,%+ \t\\/-]+\\)$/i' %}{{ value }}{% elseif mode == 'brand' %}var(--coresocial-color-brand-{{ network }}){% elseif mode == 'transparent' %}transparent{% else %}inherit{% endif %}{% endmacro %}
{% import _self as cs %}
{% set profiles = coresocial_data.profiles %}
{% if (settings.show ?? 'all') == 'all' %}
    {% set selection = profiles|keys %}
{% elseif (settings.profiles ?? '[]') matches '/^\\[\\s*("[0-9]+"\\s*(,\\s*"[0-9]+"\\s*)*)?\\]$/' %}
    {% set selection = (settings.profiles ?? '[]')|replace({'[':'', ']':'', '"':'', ' ':''})|split(',') %}
{% else %}
    {% set selection = [] %}
{% endif %}
{% set layout = (settings.layout ?? 'icons') == 'icons' ? 'icon' : settings.layout %}
{% set label = settings.label ?? 'name' %}
{% set align = settings.align ?? 'center' %}
{% set uid = coresocial_uid|default(id) %}
{% set target = settings.target ?? '_blank' %}
{% set rel = [] %}
{% for part in (settings.rel ?? 'noopener')|lower|split(' ') %}{% if part in ['noopener','noreferrer','nofollow','external','me'] %}{% set rel = rel|merge([part]) %}{% endif %}{% endfor %}
<div class="{{ settings.classes|default([])|join(' ')|e('html_attr') }}" data-interaction-id="{{ interaction_id|e('html_attr') }}"{{ m.render_custom_attributes(settings) }}>
    <div class="coresocial-block-wrapper coresocial-block-profiles coresocial-elementor-profiles {{ settings.class|default('')|e('html_attr') }}"{% if coresocial_editor|default(false) %} inert{% endif %}>
        <ul class="coresocial-profiles-list coresocial-list-align-{{ align|e('html_attr') }} coresocial-layout-{{ layout|e('html_attr') }} coresocial-label-{{ label|e('html_attr') }} coresocial-style-{{ (settings.style ?? 'plain')|e('html_attr') }}{% if align == 'justify' and (settings.columns ?? 0) > 0 and (settings.columns ?? 0) <= 4 %} coresocial-columns-{{ settings.columns|number_format(0, '.', '') }}{% endif %}" style="--coresocial-profile-rounded:{{ (settings.icon_border_radius ?? 0)|number_format(0, '.', '') }}px;--coresocial-profile-font-size:{{ (settings.font_size ?? 16)|number_format(0, '.', '') }}px;--coresocial-profile-icon-size:{{ (settings.icon_size ?? 20)|number_format(0, '.', '') }}px">
            {% set seen = [] %}
            {% for key in selection %}
                {% if key in profiles|keys and key not in seen %}
                    {% set seen = seen|merge([key]) %}{% set profile = profiles[key] %}
                    {% set item_class = 'coresocial-profile-' ~ profile.network ~ '-' ~ profile.id %}
                    <li class="{{ item_class|e('html_attr') }} coresocial-profile-align-{{ (settings.item_align ?? 'center')|e('html_attr') }}">
                        <a{% if not coresocial_editor|default(false) %} href="{{ profile.url|e('html_attr') }}"{% endif %} title="{{ profile.name|e('html_attr') }}{% if profile.count > 0 %} ({{ profile.count }} {{ profile.followers_label|e('html_attr') }}){% endif %}"{% if target in ['_blank','_self','_parent','_top'] %} target="{{ target }}"{% endif %}{% if rel is not empty %} rel="{{ rel|join(' ')|e('html_attr') }}"{% endif %} style="--cs-profile-text:{{ cs.color(settings.icon_text ?? 'inherit', settings.icon_text_custom ?? '#000', profile.network) }};--cs-profile-background:{{ cs.color(settings.icon_background ?? 'transparent', settings.icon_background_custom ?? '#fff', profile.network) }};--cs-profile-hover-text:{{ cs.color(settings.icon_hover_text ?? 'brand', settings.icon_hover_text_custom ?? '#000', profile.network) }};--cs-profile-hover-background:{{ cs.color(settings.icon_hover_background ?? 'transparent', settings.icon_hover_background_custom ?? '#fff', profile.network) }}">
                            {% if layout != 'label' %}<i class="coresocial-icon coresocial-icon-{{ profile.network|e('html_attr') }}"></i>{% endif %}
                            {% if layout != 'icon' %}<span>{% if label != 'followers' or profile.count == 0 %}
                                <span class="__name">{{ profile.name|e }}</span>{% endif %}{% if profile.count > 0 and label != 'name' %}{% if label == 'name-followers' %}
                                <br>{% endif %}<span class="__followers"><strong>{{ profile.count }}</strong> {{ profile.followers_label|e }}</span>{% endif %}</span>{% endif %}
                        </a>
                    </li>
                {% endif %}
            {% endfor %}
        </ul>
    </div>
</div>
