{#
	Reusable Twig macros. Keep this lean — add per project.
	Usage:  {% import 'macros.twig' as macros %}
#}

{# Link button. target/rel are sanitized via the PHP safe_* helpers. #}
{% macro btn(href, title, target = false, classes = '') %}
	{% set safe_target = safe_target(target) %}
	<a href="{{ safe_url(href) }}" class="btn {{ classes }}"
		{% if safe_target %} target="{{ safe_target }}"{% if safe_rel(safe_target) %} rel="{{ safe_rel(safe_target) }}"{% endif %}{% endif %}>
		<span>{{ title }}</span>
	</a>
{% endmacro %}

{# Responsive <picture>. Pass a Timber image (or an ACF image id/array). #}
{% macro picture(image, alt = '', classes = '', eager = false) %}
	{% set img = image ? get_image(image) : null %}
	{% if img %}
		<picture>
			<img src="{{ img.src }}" alt="{{ alt ?: img.alt }}"
				loading="{{ eager ? 'eager' : 'lazy' }}"
				decoding="{{ eager ? 'sync' : 'async' }}"
				class="{{ classes }}">
		</picture>
	{% endif %}
{% endmacro %}

{#
	Section wrapper classes from the shared ACF "setting_section" group
	(padding top/bottom + background modifier). Used by every block.
#}
{% macro section_classes(settings) %}
	{% set s = settings.setting_section ?? settings %}
	{{ s.padding_top }} {{ s.padding_bottom }}
	{%- if s.background_color == 'dark' %} is-dark{% elseif s.background_color == 'gray' %} is-gray{% endif -%}
{% endmacro %}

{# Osmo Check Section Theme: dark = nav claire, light = nav noire. #}
{% macro section_theme(settings, force = null) %}
	{%- if force -%}
		{{- force -}}
	{%- else -%}
		{%- set s = settings.setting_section ?? settings -%}
		{{- s.background_color == 'dark' ? 'dark' : 'light' -}}
	{%- endif -%}
{% endmacro %}

{# Native <video>. autoplay = muted loop (no controls). Otherwise native controls. #}
{% macro video_mp4(video_url, classes = '', autoplay = false) %}
	<video
		class="c-media__asset {{ classes }}"
		{% if autoplay %}muted loop{% else %}controls{% endif %}
		playsinline
		webkit-playsinline="webkit-playsinline"
		preload="metadata"
		src="{{ safe_url(video_url) }}"
	></video>
{% endmacro %}

{# Osmo Play/Pause Video on Scroll. [data-video="playpause"] must not be renamed. #}
{% macro video_mp4_playpause(video_url, classes = '') %}
	<div data-video="playpause" class="c-media__fill">
		{{ _self.video_mp4(video_url, classes, true) }}
	</div>
{% endmacro %}

{#
	Button 043 — pill CTA (hover wipe + optional leading icon).
	------------------------------------------------------------------
	label       Text label
	href        Link URL (default #)
	options     Hash:
	  classes     Extra classes (e.g. font-mono text-xxs)
	  icon        null | 'apple' | 'android' | 'svg/….svg' path
	  aria_label  Accessible name (optional)
	  attrs       Raw extra attributes string
	  target      Link target (_blank, …)
	  reveal      Scroll rise (opacity + y). Default true; false for fixed header CTA.

	Examples:
	  {{ macros.button_043(__('La draft', 'genesis'), '#', {
	    classes: 'underlay-nav__cta-header font-mono text-xxs',
	    reveal: false,
	    attrs: 'data-modal-target="discovery" data-modal-status="not-active"'
	  }) }}
	  {{ macros.button_043('iOS', '#', {
	    classes: 'font-mono text-xxs',
	    icon: 'apple',
	    aria_label: __('Télécharger sur iOS', 'genesis')
	  }) }}
#}
{% macro button_043(label, href = '#', options = {}) %}
	{% set classes = options.classes|default('') %}
	{% set icon = options.icon|default(null) %}
	{% set aria_label = options.aria_label|default(null) %}
	{% set attrs = options.attrs|default('') %}
	{% set target = options.target|default(false) %}
	{% set reveal = options.reveal is defined ? options.reveal : true %}
	{% set safe_target = safe_target(target) %}
	{% set has_icon = icon ? true : false %}
	{% set icon_file = icon == 'apple' ? 'svg/apple.svg' : (icon == 'android' ? 'svg/android.svg' : icon) %}

	<a
		href="{{ safe_url(href) }}"
		data-button-043=""
		class="button-043{{ has_icon ? ' button-043--icon' : '' }} {{ classes }}"
		{% if reveal %} js-reveal="rise"{% endif %}
		{% if aria_label %} aria-label="{{ aria_label }}"{% endif %}
		{% if safe_target %} target="{{ safe_target }}"{% if safe_rel(safe_target) %} rel="{{ safe_rel(safe_target) }}"{% endif %}{% endif %}
		{% if attrs %} {{ attrs|raw }}{% endif %}
	>
		<span class="button-043__bg">
			<span class="button-043__bg-hover"></span>
		</span>
		<span class="button-043__inner">
			<span class="button-043__mask">
				{% if has_icon %}
					<span class="button-043__text">
						<span class="button-043__row">
							<span class="button-043__leading-icon" aria-hidden="true">{% include icon_file %}</span>
							<span>{{ label }}</span>
						</span>
						<span class="button-043__row" aria-hidden="true">
							<span class="button-043__leading-icon">{% include icon_file %}</span>
							<span>{{ label }}</span>
						</span>
					</span>
				{% else %}
					<span class="button-043__text">{{ label }}</span>
				{% endif %}
			</span>
		</span>
	</a>
{% endmacro %}
