{#
/**
 * @file
 * CivicTheme Link component.
 *
 * Props:
 * - theme: [string] Theme variation (light or dark).
 * - text: [string] Link text.
 * - url: [string] Link URL.
 * - title: [string] Title attribute for the link.
 * - is_new_window: [boolean] Open link in a new window.
 * - is_external: [boolean] Indicates if the link is external.
 * - is_active: [boolean] Indicates if the link is active
 * - is_disabled: [boolean] Indicates if the link is disabled.
 * - icon: [string] Icon name.
 * - icon_placement: [string] Icon position (before or after).
 * - icon_group_disabled: [boolean] Disable icon and last word grouping.
 * - icon_single_only: [boolean] Only show 1 icon (if both icon and is_external are present, external takes preference).
 * - attributes: [string] Additional HTML attributes.
 * - modifier_class: [string] Additional CSS classes.
 */
#}

{%- set text = text|default('') -%}
{%- set only_icon_class = icon is not empty and text is empty ? 'ct-link--only-icon' : '' -%}
{%- set icon_placement = icon_placement in ['before', 'after'] ? icon_placement : 'after' -%}
{%- set is_external_class = is_external ? 'ct-link--external' : '' -%}
{%- set is_active_class = is_active ? 'ct-link--active' : '' -%}
{%- set is_disabled_class = is_disabled ? 'ct-link--disabled' : '' -%}
{%- set theme_class = 'ct-theme-%s'|format(theme|default('light')) -%}
{%- set modifier_class = '%s %s %s %s %s %s'|format(theme_class, is_external_class, is_active_class, is_disabled_class, only_icon_class, modifier_class|default(''))|trim -%}
{%- set attributes = is_disabled ? attributes ~ ' disabled' : attributes -%}

{%- if text is not empty or icon is not empty -%}
  {%- set link_content -%}
    {%- include 'civictheme:text-icon' with {
      text: text,
      is_new_window: is_new_window,
      is_external: is_external,
      icon: icon,
      icon_placement: icon_placement,
      icon_class: 'ct-link__icon',
      icon_group_disabled: icon_group_disabled is defined ? icon_group_disabled : false,
      icon_single_only: icon_single_only is defined ? icon_single_only : false,
    } only -%}
  {%- endset -%}

  <a
    class="ct-link {{ modifier_class -}}"
    {% if url is not empty %}href="{{ url }}"{% endif %}
    {% if title is not empty %}title="{{ title }}"{% endif %}
    {% if is_new_window %}target="_blank"{% endif %}
    {% if is_disabled %}disabled{% endif %}
    {% if attributes is not empty %}{{- attributes|raw -}}{% endif %}
  >
    {{- link_content -}}
  </a>
{%- endif -%}
