{#
/**
 * @file
 * CivicTheme Label component.
 *
 * Props:
 * - theme: [string] Theme variation (light or dark).
 * - tag: [string] HTML tag to use (label, legend).
 * - content: [string] The label's content.
 * - size: [string] Label size (extra-large, large, regular, small, extra-small).
 * - is_required: [boolean] Whether the label is required.
 * - required_text: [string] Text to display within label element when required.
 * - for: [string] Form element ID this label belongs to.
 * - allow_html: [boolean] Whether to allow HTML in text.
 * - attributes: [string] Additional HTML attributes.
 * - modifier_class: [string] Additional CSS classes.
 */
#}

{% set tag = tag in ['label', 'legend'] ? tag : 'label' %}
{% set size = size in ['extra-large', 'large', 'regular', 'small', 'extra-small'] ? size : 'regular' %}
{% set size_class = 'ct-label--%s'|format(size) %}
{% set required_class = is_required ? 'ct-label--required' : '' %}
{% set required_text = required_text|default('(required)') %}
{% set theme_class = 'ct-theme-%s'|format(theme|default('light')) %}
{% set modifier_class = '%s %s %s %s'|format(theme_class, size_class, required_class, modifier_class|default('')) %}

{% if content is not empty -%}
  <{{ tag }}
  class="ct-label {{ modifier_class -}}"
  {% if for is not empty %} for="{{ for }}" {% endif %}
  {% if attributes is not empty %}{{- attributes|raw -}}{% endif %}
  >
  {% if allow_html is defined ? allow_html : false %}
    {{- content|raw -}}
  {% else %}
    {{- content -}}{%- if is_required %} <span class="ct-label__required">{{ required_text }}</span>{%- endif -%}
  {% endif %}
  </{{ tag }}>
{%- endif %}
