{% use 'form_div_layout.html.twig' %}
{# Macro to render a static (read-only) field value with consistent formatting #}
{% macro render_static_field(label, value) %}
{{ value ?: '-' }}
{% endmacro %}
{# Macro to render info icon tooltip for descriptions #}
{% macro info_tooltip(description) %}
{{ description|raw }}
{% endmacro %}
{%- block form_row -%}
{%- set row_attr = row_attr|merge({ 'class': (row_attr.class|default('') ~ ' mb-4')|trim }) -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
{%- if form.vars.expanded is defined and form.vars.expanded -%}
{%- else -%}
{%- endblock multiselect_widget -%}
{%- block birthday_widget -%}
{%- set placeholders = {
'day': 'Tag',
'month': 'Monat',
'year': 'Jahr'
} -%}
{%- set field_order = ['day', 'month', 'year'] -%}
{# Check if HTMX attributes are present - if so, use birthday controller for deferred triggering #}
{%- set has_htmx = attr['hx-trigger'] is defined -%}
{%- set htmx_attrs = {} -%}
{%- if has_htmx -%}
{# Extract HTMX attributes and replace trigger with custom event #}
{%- set htmx_attrs = {
'hx-trigger': 'birthday:complete',
'hx-post': attr['hx-post']|default(''),
'hx-target': attr['hx-target']|default('#main-content'),
'hx-swap': attr['hx-swap']|default('innerHTML')
} -%}
{# Remove HTMX attrs from main attr to avoid duplication #}
{%- set attr = attr|filter((v, k) => k not in ['hx-trigger', 'hx-post', 'hx-target', 'hx-swap']) -%}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' flex items-center space-x-2')|trim}) -%}
{%- for field_name in field_order -%}
{%- set child = form[field_name] -%}
{%- set child_attr = child.vars.attr|default({}) -%}
{%- set child_attr = child_attr|merge({
'placeholder': placeholders[field_name],
'class': (child_attr.class|default('') ~ ' form-field')|trim
}) -%}
{%- if has_htmx -%}
{%- set child_attr = child_attr|merge({
'data-birthday-target': field_name,
'data-action': 'change->birthday#check'
}) -%}
{%- endif -%}
{{- form_widget(child, {'attr': child_attr}) -}}
{% if not loop.last %}
.
{% endif %}
{%- endfor -%}
{%- endblock birthday_widget -%}
{% block insurance_choice_widget %}
{%- if expanded -%}
{%- for child in form %}
{%- set child_attr = {} -%}
{%- if attr['hx-trigger'] is defined -%}
{%- set child_attr = child_attr|merge({
'hx-trigger': attr['hx-trigger'],
'hx-post': attr['hx-post'],
'hx-swap': attr['hx-swap']
}) -%}
{%- endif -%}
{%- if child.vars.attr is defined -%}
{%- set child_attr = child_attr|merge(child.vars.attr) -%}
{%- endif -%}
{%- set insurance = insurances[child.vars.value] ?? null -%}
{%- set urlsProductInfo = insurance is not null ? insurance.getAllUrlsProductInfo() : [] -%}
{{- form_row(child, { 'attr': child_attr }) -}}
{%- if urlsProductInfo is not empty -%}