@php
    $buttons = collect($block->get('buttons') ?: []);
    $align = $block->get('align', 'center');
    $alignClass = ['start' => 'text-start items-start', 'center' => 'text-center items-center', 'end' => 'text-end items-end'][$align] ?? 'text-center items-center';
    $shell = match ($variant) {
        'card', 'boxed' => 'ec-surface rounded-3xl p-10 sm:p-14 shadow-sm',
        'gradient'      => 'ec-gradient rounded-3xl p-10 sm:p-14',
        'image_bg'      => 'relative rounded-3xl p-10 sm:p-14 overflow-hidden',
        default         => '',
    };
@endphp
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
    <div class="{{ $shell }}">
        @if ($variant === 'image_bg' && $block->get('image'))
            <img src="{{ $block->get('image') }}" alt="" class="absolute inset-0 -z-10 h-full w-full object-cover" aria-hidden="true">
            <div class="absolute inset-0 -z-10 bg-black/55" aria-hidden="true"></div>
        @endif

        <div class="{{ $variant === 'split' ? 'grid md:grid-cols-[1fr_auto] gap-8 items-center' : 'flex flex-col gap-5 ' . $alignClass }}">
            <div class="flex flex-col gap-3 {{ $variant === 'split' ? 'text-start' : '' }}">
                <h2 class="ec-heading text-2xl sm:text-4xl font-bold">{{ $block->get('title') }}</h2>
                @if ($block->get('description'))
                    <p class="ec-muted text-lg max-w-2xl">{{ $block->get('description') }}</p>
                @endif
            </div>

            @if ($buttons->isNotEmpty())
                <div class="flex flex-wrap gap-3 {{ $align === 'center' && $variant !== 'split' ? 'justify-center' : '' }}">
                    @foreach ($buttons as $i => $btn)
                        @php $btnHref = safe_url(data_get($btn, 'url')); @endphp
                        @continue (! $btnHref)
                        <a href="{{ $btnHref }}"
                           class="ec-btn ec-btn--{{ data_get($btn, 'style', 'primary') }} inline-flex items-center gap-2 rounded-full px-8 py-3.5 font-semibold transition">
                            @if (data_get($btn, 'icon'))
                                <x-website.icon :name="data_get($btn, 'icon')" class="w-5 h-5" />
                            @endif
                            {{ $block->get("buttons.{$i}.label") ?: data_get($btn, 'label') }}
                        </a>
                    @endforeach
                </div>
            @endif
        </div>
    </div>
</div>
