{% 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 -%}
{%- endif -%}
{%- endblock form_row -%}
{%- block form_label -%}
{% set class = 'font-semibold' %}
{% if errors|length %}
{% set class = class ~ ' text-red-500' %}
{% endif %}
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' ' ~ class)|trim}) %}
{{ parent() }}
{%- endblock form_label -%}
{%- block form_errors -%}
{%- if errors|length > 0 -%}
{%- for error in errors -%}
{{ error.message }}
{%- endfor -%}
{%- endif -%}
{%- endblock form_errors -%}
{%- block form_widget_simple -%}
{%- set type = type|default('text') -%}
{%- set tooltip = null -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
{%- if type != 'hidden' -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-field')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-field--has-error' }) -%}
{%- endif -%}
{%- if disabled is defined and disabled == true -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' cursor-not-allowed' }) -%}
{%- endif -%}
{%- endif -%}
{{ parent() }}
{%- if disabled is defined and disabled == true -%}
{%- endif -%}
{%- endblock form_widget_simple -%}
{%- block textarea_widget -%}
{%- set tooltip = null -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-field')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-field--has-error' }) -%}
{%- endif -%}
{%- if disabled is defined and disabled == true -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' cursor-not-allowed' }) -%}
{%- endif -%}
{{ parent() }}
{%- if disabled is defined and disabled == true -%}
{%- endif -%}
{%- endblock textarea_widget -%}
{%- block checkbox_widget -%}
{%- set tooltip = null -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-checkbox')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-checkbox--has-error' }) -%}
{%- endif -%}
{%- endblock checkbox_widget -%}
{%- block radio_widget -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-radio')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-radio--has-error' }) -%}
{%- endif -%}
{%- set tooltip = null -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
{%- endblock radio_widget -%}
{% block checkbox_row %}
{%- import _self as forms -%}
{%- set tooltip = null -%}
{%- if form.vars.attr['data-tooltip'] is defined -%}
{%- set tooltip = form.vars.attr['data-tooltip'] -%}
{%- endif -%}
{%- set description = form.vars.attr['data-description'] ?? null -%}
{%- if description is not null -%}
{{ forms.info_tooltip(description) }}
{%- endif -%}
{% endblock %}
{% block radio_row %}
{%- import _self as forms -%}
{%- set tooltip = null -%}
{%- if form.vars.attr['data-tooltip'] is defined -%}
{%- set tooltip = form.vars.attr['data-tooltip'] -%}
{%- endif -%}
{%- set description = form.vars.attr['data-description'] ?? null -%}
{%- if description is not null -%}
{{ forms.info_tooltip(description) }}
{%- endif -%}
{% endblock %}
{%- block choice_widget_collapsed -%}
{%- set tooltip = null -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-field')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-field--has-error' }) -%}
{%- endif -%}
{%- if disabled is defined and disabled == true -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' cursor-not-allowed' }) -%}
{%- endif -%}
{%- if attr.readonly is defined %}
{{ parent() }}
{% else %}
{{ parent() }}
{% endif %}
{%- endblock choice_widget_collapsed -%}
{%- block choice_widget_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 attr.readonly is defined and child.vars.attr.readonly is not defined -%}
{%- set child_attr = child_attr|merge({'readonly': true}) -%}
{%- endif -%}
{%- if child.vars.attr['data-tooltip'] is defined -%}
{%- set child_attr = child_attr|merge({'data-tooltip': child.vars.attr['data-tooltip']}) -%}
{%- endif -%}
{{- form_row(child, { 'attr': child_attr }) -}}
{% endfor -%}
{%- endblock choice_widget_expanded -%}
{%- block multiselect_widget -%}
{%- 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 -%}