{# LIBRARIES #}
{{ attach_library('ui_patterns/tm_bits_badge.tm_bits_badge_lib') }}

{# VARIABLES #}
{% if badge_text or badge_text_large %}
  {% set badge_img_url = FALSE %}
{% endif %}

{% set badge_attributes = badge_attributes|default(create_attribute()) %}
{% set badge_class = [
  'card-badge',
  badge_class ?? '',
  floating ? 'floating',
  badge_color ? 'tcb-' ~ badge_color,
  badge_img_url ? 'badge-image'
] %}

{# TEMPLATE #}
{% if badge_text or badge_text_large or badge_img_url %}

  <div {{ badge_attributes.addClass(badge_class) }}>

    {# Text overrides image #}
    {% if badge_text or badge_text_large %}

      <div class="badge-text">
        {% if badge_text %}<span>{{ badge_text|raw }}</span>{% endif %}
        {% if badge_text_large %}<span class="large">{{ badge_text_large }}</span>{% endif %}
      </div>

    {% elseif badge_img_url %}

      {% include "@atoms/html5/image/image.twig" with {
        'alt': badge_img_alt,
        'url': badge_img_url,
        'img_attributes': badge_img_attrs|default(create_attribute()),
        'img_class': 'offer-badge w-100',
      } only %}

    {% endif %}

  </div>

{% endif %}
