@php
    $contextService = trim((string) ($serviceTitle ?? ($service->title ?? '')));
    $contextIntent = trim((string) ($intent ?? 'pricing'));
    $contextPackage = trim((string) ($package ?? ''));
    $compact = (bool) ($compact ?? false);
    $headline = $headline ?? null;
    $showSupport = $showSupport ?? true;

    $query = array_filter([
        'intent' => $contextIntent ?: null,
        'service' => $contextService ?: null,
        'package' => $contextPackage ?: null,
    ]);

    $auditUrl = route('contact', array_merge($query, ['intent' => 'free-audit']));
    $pricingUrl = route('contact', array_merge($query, ['intent' => 'pricing']));
    $emailSubject = $contextService
        ? "Tracking help for {$contextService}"
        : 'Tracking help request';
    $emailBody = $contextService
        ? "Hi Saleem,%0D%0A%0D%0AI need help with {$contextService}.%0D%0A%0D%0APlease share next steps.%0D%0A"
        : "Hi Saleem,%0D%0A%0D%0AI need help with tracking and reporting.%0D%0A";
    $whatsAppUrl = filled($settings?->whatsapp_url)
        ? $settings->whatsapp_url . '?text=' . urlencode(
            $contextService
                ? "Hi Saleem, I need help with {$contextService}."
                : 'Hi Saleem, I need help with tracking and reporting.'
        )
        : null;
@endphp

<div class="ssa-contact-actions {{ $compact ? 'ssa-contact-actions--compact' : '' }}">
    @if($headline)
        <h3>{{ $headline }}</h3>
    @endif

    <div class="ssa-contact-actions__grid">
        <a href="{{ $auditUrl }}" class="ssa-contact-action ssa-contact-action--primary">
            <span class="ssa-contact-action__label">Request Free Audit</span>
            <span class="ssa-contact-action__meta">Share your current setup and get the first fixes identified.</span>
        </a>

        <a href="{{ $pricingUrl }}" class="ssa-contact-action">
            <span class="ssa-contact-action__label">Contact Form</span>
            <span class="ssa-contact-action__meta">Ask about scope, timelines, and package recommendations.</span>
        </a>

        @if(filled($settings?->contact_email))
            <a href="mailto:{{ $settings->contact_email }}?subject={{ rawurlencode($emailSubject) }}&body={{ $emailBody }}" class="ssa-contact-action">
                <span class="ssa-contact-action__label">Email</span>
                <span class="ssa-contact-action__meta">{{ $settings->contact_email }}</span>
            </a>
        @endif

        @if($whatsAppUrl)
            <a href="{{ $whatsAppUrl }}" class="ssa-contact-action" target="_blank" rel="noopener">
                <span class="ssa-contact-action__label">WhatsApp Chat</span>
                <span class="ssa-contact-action__meta">Start a direct conversation on mobile or desktop.</span>
            </a>
        @endif

        @if($showSupport)
            <button type="button" class="ssa-contact-action ssa-contact-action--button" data-open-support-chat>
                <span class="ssa-contact-action__label">Support Chat</span>
                <span class="ssa-contact-action__meta">Open the on-page chat form for a quick support request.</span>
            </button>
        @endif
    </div>
</div>
