@php
    use App\Domain\Training\Support\GroupColor;
@endphp

<x-print.sheet
    :title="$facility->name_ar"
    :subtitle="__('الجدول الأسبوعي')"
    size="A3 landscape"
    :meta="[
        __('الفرع') => $facility->branch?->name_ar ?? '—',
        __('الأسبوع') => $weekStart->format('Y-m-d') . ' → ' . $weekEnd->format('Y-m-d'),
        __('الحجوزات') => $totalBookings,
    ]">

    <x-slot:legend>
        @foreach($legendGroups as $g)
            <span class="item">
                <span class="dot" style="background: {{ GroupColor::for($g['id']) }}"></span>
                {{ $g['name'] }}
            </span>
        @endforeach
        @if(empty($legendGroups))
            <span style="color:#6B7280">{{ __('لا توجد حجوزات هذا الأسبوع') }}</span>
        @endif
    </x-slot:legend>

    @push('styles')
    <style>
        .week td { height: 26px; padding: 2px; }
        .day-head { font-size: 11px; }
        .day-head span { display: block; font-weight: 400; opacity: .7; font-size: 9.5px; }
        .bk {
            padding: 3px 5px;
            border-radius: 3px;
            font-size: 10px;
            line-height: 1.3;
            margin-bottom: 2px;
        }
        .bk:last-child { margin-bottom: 0; }
        .bk b { display: block; font-weight: 700; }
        .bk .where { font-size: 9px; opacity: .8; }
    </style>
    @endpush

    <table class="week">
        <thead>
            <tr>
                <th class="time-col">{{ __('الوقت') }}</th>
                @foreach($days as $day)
                    <th class="day-head">
                        {{ $day['name'] }}
                        <span class="num">{{ $day['date']->format('m-d') }}</span>
                    </th>
                @endforeach
            </tr>
        </thead>
        <tbody>
            @foreach($slots as $slot)
                <tr>
                    <td class="time-col">{{ $slot['label'] }}</td>
                    @foreach($days as $day)
                        <td>
                            @foreach($grid[$day['key']][$slot['key']] ?? [] as $booking)
                                <div class="bk" style="background: {{ GroupColor::for($booking['group_id']) }}26;
                                          border: 1px solid {{ GroupColor::for($booking['group_id']) }}66;
                                          color: {{ GroupColor::for($booking['group_id']) }};">
                                    <b>{{ $booking['title'] }}</b>
                                    <span class="where num">
                                        {{ $booking['start'] }}–{{ $booking['end'] }}
                                        @if($booking['segments']) · {{ $booking['segments'] }} @endif
                                    </span>
                                </div>
                            @endforeach
                        </td>
                    @endforeach
                </tr>
            @endforeach
        </tbody>
    </table>
</x-print.sheet>
