{{--
    The shared section header: eyebrow, heading, accent rule, subtitle.

    Every block that introduces itself with a title renders it through here, so
    the heading treatment is one decision for the whole site rather than a
    different set of utility classes in each block partial.

    The heading passes through website_highlight(), so an author can emphasise
    part of a title by bracing it: "Welcome to {OC-Sport}".

    @param string $headerAlign   overrides the block's own header_align
    @param string $headingSize   type scale for the heading
    @param string $headerClass   extra classes on the <header>
--}}
@php
    $align = $headerAlign ?? $block->get('header_align') ?? 'center';
    $alignClass = [
        'start' => 'text-start',
        'center' => 'text-center mx-auto',
        'end' => 'text-end ms-auto',
    ][$align] ?? 'text-center mx-auto';

    $ruleClass = $block->get('heading_rule') === 'accent_bar'
        ? 'ec-heading-rule '.($align === 'center' ? 'ec-heading-rule--center' : 'ec-heading-rule--start')
        : '';

    $eyebrow = $block->get('eyebrow');
    $headerTitle = $block->get('title');
    $subtitle = $block->get('subtitle');
    $headingSize = $headingSize ?? 'text-3xl sm:text-4xl';

    // A page needs exactly one h1. Which section carries it is an authoring
    // decision, so it is a field rather than a guess about block order.
    $headingTag = $block->get('heading_level') === 'h1' ? 'h1' : 'h2';
@endphp

@if (filled($eyebrow) || filled($headerTitle) || filled($subtitle))
    <header class="max-w-3xl mb-10 {{ $alignClass }} {{ $headerClass ?? '' }}">
        @if (filled($eyebrow))
            <p class="ec-eyebrow mb-3">{{ $eyebrow }}</p>
        @endif

        @if (filled($headerTitle))
            <{{ $headingTag }} class="ec-heading {{ $headingSize }} font-black leading-tight {{ $ruleClass }}">
                {!! website_highlight($headerTitle) !!}
            </{{ $headingTag }}>
        @endif

        @if (filled($subtitle))
            <p class="ec-muted mt-4 text-lg leading-relaxed">{{ $subtitle }}</p>
        @endif
    </header>
@endif
