{#
  Parameters:
  - id (string) (default: '')
  - label (string) (default: '')
  - required (boolean) (default: false)
  - disabled (boolean) (default: false)
  - readonly (boolean) (default: false)
  - invalid (boolean) (default: false)
  - valid (boolean) (default: false)
  - invalid_feedback (string) (default: '')
  - valid_feedback (string) (default: '')
  - helper_text (string) (default: '')
  - helper_text_id (string) (default: '')
  - hidden_label (boolean) (default: false)
  - text (string) (default: '')
  - rows (int) (default: 4)
  - floating (boolean) (default: false)
  - horizontal (boolean) (default: false)
  - horizontal_class (string) (default: col-sm-10)
  - horizontal_label_class (string) (default: col-sm-2)
  - attributes (drupal attrs)
#}

{%- set _id = id|default('') %}
{% set _label = label|default('') %}
{% set _required = required ?? false %}
{% set _disabled = disabled ?? false %}
{% set _readonly = readonly ?? false %}
{% set _invalid = invalid ?? false %}
{% set _valid = valid ?? false %}
{% set _invalid_feedback = invalid_feedback|default('') %}
{% set _valid_feedback = valid_feedback|default('') %}
{% set _helper_text = helper_text|default('') %}
{% set _helper_text_id = helper_text_id|default('') %}
{% set _hidden_label = hidden_label ?? false %}
{% set _text = text|default('') %}
{% set _rows = rows|default('4') %}
{% set _floating = floating ?? false %}
{% set _horizontal = horizontal ?? false %}
{% set _horizontal_class = horizontal_class|default('col-sm-10') %}
{% set _horizontal_label_class = horizontal_label_class|default('col-sm-2') %}

{%- set _label_block = false %}
{% set _label_class = 'form-label' %}
{% set _classes = ['form-control'] %}

{%- if _invalid is not empty %}
  {%- set _classes = _classes|merge(['is-invalid']) %}
{% endif %}
{% if _valid is not empty %}
  {%- set _classes = _classes|merge(['is-valid']) %}
{% endif %}
{% set _placeholder = placeholder|default('') %}
{% if _horizontal %}
  {%- set _label_class = 'col-form-label ' ~ _horizontal_label_class %}
{% endif %}
{% if _hidden_label %}
  {%- set _label_class = _label_class ~ ' visually-hidden' %}
{% endif %}

{%- if attributes is empty %}
  {%- set attributes = create_attribute() %}
{% endif %}

{%- set attributes = attributes.addClass(_classes).setAttribute('rows', _rows) %}

{%- if _id %}
  {%- set attributes = attributes.setAttribute('id', _id) %}
{% endif %}

{%- if _required %}
  {%- set attributes = attributes.setAttribute('required', true) %}
{% endif %}

{%- if _disabled %}
  {%- set attributes = attributes.setAttribute('disabled', true) %}
{% endif %}

{%- if _readonly %}
  {%- set attributes = attributes.setAttribute('readonly', true) %}
{% endif %}

{%- if _placeholder is not empty %}
  {%- set attributes = attributes.setAttribute('placeholder', _placeholder) %}
{% endif %}

{%- if _helper_text_id is not empty %}
  {%- set attributes = attributes.setAttribute('aria-describedby', _helper_text_id) %}
{% endif %}

{%- if _floating or _horizontal %}
{% set _wrapper_class = _floating ? 'form-floating' : 'row' -%}
<div class="{{ _wrapper_class }}">
{%- endif %}
{% if _label is not empty %}
  {%- set _label_block -%}
    <label
    {% if _id %}
      for="{{ _id|e('html_attr') }}"
    {% endif %}
      class="{{ _label_class }}"
    >
      {{- label -}}
    </label>
  {%- endset %}
{% endif %}

{%- if _label_block and _floating == false %}
  {{- _label_block|raw }}
{%- endif %}
{% if _horizontal and floating == false -%}
<div class="{{ _horizontal_class }}">
{%- endif -%}
  <textarea
    {{ attributes }}
  >
  {{- _text -}}
  </textarea>
{%- if _horizontal and floating == false -%}
</div>
{%- endif %}
{% if _label_block and _floating %}
  {{- _label_block|raw }}
{%- endif %}
{% if _invalid_feedback is not empty -%}
  <div class="invalid-feedback">
    {{- _invalid_feedback -}}
  </div>
{%- endif %}
{% if _valid_feedback is not empty -%}
  <div class="valid-feedback">
    {{- _valid_feedback -}}
  </div>
{%- endif %}
{% if _helper_text is not empty -%}
  <div
    class="form-text"
  {%- if _helper_text_id is not empty -%}
    id="{{ _helper_text_id }}"
  {%- endif -%}>
    {{- _helper_text -}}
  </div>
{%- endif %}
{% if _floating or _horizontal -%}
</div>
{%- endif -%}
