{#
/**
 * @file
 * Template for a Bootstrap 5 Link component.
 *
 * Available variables:
 * - attributes: HTML attributes for the anchor element.
 * - url: The href destination. Required.
 * - text: The visible link text. Required.
 * - aria_label: Optional aria-label attribute for accessibility.
 * - target: Link target (same = _self, new = _blank).
 * - stretched_link: (boolean) Apply stretched-link to cover nearest positioned container.
 * - as_button: (boolean) Render with Bootstrap button classes.
 * - button_variant: Bootstrap variant for button style (primary, secondary, etc.).
 * - width_class: Bootstrap width utility class.
 * - link_classes: Extra classes for plain link rendering.
 * - button_classes: Extra classes when rendering as a button.
 * - custom_class: Additional CSS classes.
 *
 * @ingroup themeable
 */
#}

{% set attributes = attributes|default(create_attribute()) %}
{% set label = text|default('Link') %}
{% set aria_label = aria_label|default('') %}
{% set target = target|default('same') %}
{% set as_button = as_button|default(false) %}
{% set stretched_link = stretched_link|default(false) %}
{% set button_variant = button_variant|default('primary') %}
{% set width_class = width_class|default('none') %}

{% set base_button_class = as_button ? ('btn btn-' ~ button_variant) : '' %}
{% set extra_classes = as_button ? button_classes|default('') : link_classes|default('') %}

{% set classes = [
  base_button_class,
  extra_classes,
  width_class and width_class != 'none' ? width_class : '',
  stretched_link ? 'stretched-link' : '',
  custom_class|default(''),
]|filter(v => v) %}

{% set target_attr = target == 'new' ? '_blank' : '_self' %}

<a
  href="{{ url }}"
  {{ attributes.addClass(classes) }}
  target="{{ target_attr }}"
  {% if target == 'new' %}rel="noopener noreferrer"{% endif %}
  {% if aria_label %}aria-label="{{ aria_label }}"{% endif %}
>
  {{ label }}
</a>
