<div class="space-y-4">

    <x-portal.tabs :tabs="[
        'news' => __('الأخبار'),
        'events' => __('الفعاليات'),
        'programs' => __('البرامج'),
        'branches' => __('الفروع'),
    ]" :active="$tab" />

    @if($tab === 'news')
        @forelse($news as $item)
            <article class="portal-card px-4 py-3">
                <p class="text-sm font-bold">{{ $item->title }}</p>
                <p class="mt-0.5 text-[11px]" style="color: var(--portal-muted);">
                    {{ $item->published_at?->translatedFormat('j M Y') }}
                    @if($item->category) · {{ $item->category }} @endif
                </p>
                @if($item->excerpt)
                    <p class="mt-2 text-xs leading-relaxed" style="color: var(--portal-muted);">{{ $item->excerpt }}</p>
                @endif
            </article>
        @empty
            <x-portal.card><x-portal.empty :title="__('لا توجد أخبار منشورة')" /></x-portal.card>
        @endforelse

    @elseif($tab === 'events')
        @forelse($events as $event)
            @php $registration = $myRegistrations[$event->id] ?? null; @endphp
            <article class="portal-card px-4 py-3">
                <div class="flex items-start justify-between gap-2">
                    <p class="min-w-0 text-sm font-bold">{{ $event->title }}</p>
                    @if($registration)
                        {{-- Answerable only since event_registrations gained a
                             participant_id: it linked a person, so "which of my
                             children is registered" had no answer. --}}
                        <span class="shrink-0 rounded-full px-2 py-0.5 text-[10px] font-bold"
                              style="background: color-mix(in oklab, var(--brand-success) 14%, var(--portal-surface)); color: var(--brand-success);">
                            {{ __('مسجَّل') }}
                        </span>
                    @endif
                </div>
                <p class="num mt-0.5 text-[11px]" style="color: var(--portal-muted);">
                    {{ $event->starts_at?->translatedFormat('j M Y — H:i') }}
                    @if($event->location_name) · {{ $event->location_name }} @endif
                </p>
                @if($event->description)
                    <p class="mt-2 line-clamp-3 text-xs leading-relaxed" style="color: var(--portal-muted);">{{ strip_tags($event->description) }}</p>
                @endif
            </article>
        @empty
            <x-portal.card><x-portal.empty :title="__('لا توجد فعاليات قادمة')" /></x-portal.card>
        @endforelse

    @elseif($tab === 'programs')
        @forelse($programs as $program)
            <article class="portal-card px-4 py-3">
                <p class="text-sm font-bold">{{ $program->name_ar ?? $program->name }}</p>
                @if($program->activity)
                    <p class="mt-0.5 text-[11px]" style="color: var(--portal-muted);">
                        {{ $program->activity->name_ar ?? $program->activity->name }}
                    </p>
                @endif
                {{-- No price is shown here on purpose. Every price is computed at
                     sale time by PricingService, and there is no active base
                     price to fall back on — showing a guess would be worse than
                     showing none. --}}
            </article>
        @empty
            <x-portal.card><x-portal.empty :title="__('لا توجد برامج متاحة')" /></x-portal.card>
        @endforelse

    @else
        @forelse($branches as $branch)
            <article class="portal-card px-4 py-3">
                <p class="text-sm font-bold">{{ $branch->name_ar ?? $branch->name }}</p>
                @if($branch->address)
                    <p class="mt-0.5 text-xs" style="color: var(--portal-muted);">{{ $branch->address }}</p>
                @endif
                <div class="mt-2 flex flex-wrap gap-2">
                    @if($branch->phone)
                        <a href="tel:{{ $branch->phone }}"
                           class="num rounded-lg px-3 py-1.5 text-xs font-semibold"
                           style="background: var(--brand-50); color: var(--brand-700);">
                            {{ $branch->phone }}
                        </a>
                    @endif
                    @if($branch->latitude && $branch->longitude)
                        <a href="https://www.google.com/maps/search/?api=1&query={{ $branch->latitude }},{{ $branch->longitude }}"
                           target="_blank" rel="noopener noreferrer"
                           class="rounded-lg px-3 py-1.5 text-xs font-semibold"
                           style="background: var(--brand-50); color: var(--brand-700);">
                            {{ __('الاتجاهات') }}
                        </a>
                    @endif
                </div>
            </article>
        @empty
            <x-portal.card><x-portal.empty :title="__('لا توجد فروع')" /></x-portal.card>
        @endforelse
    @endif
</div>
