@php
    use App\Support\NumberToWords as N;
    $cal = $this->calendar;
    $weekDays = ['شنبه', 'یک‌شنبه', 'دوشنبه', 'سه‌شنبه', 'چهارشنبه', 'پنج‌شنبه', 'جمعه'];
    $priorityColor = ['low' => '#94a3b8', 'medium' => '#d97706', 'high' => '#dc2626'];
@endphp
<x-filament-panels::page>
    <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:12px;">
        <x-filament::button wire:click="prevMonth" icon="heroicon-o-chevron-right" color="gray">ماه قبل</x-filament::button>
        <div style="font-size:18px; font-weight:bold;">{{ $cal['monthName'] }} {{ N::digits($this->year) }}</div>
        <x-filament::button wire:click="nextMonth" icon="heroicon-o-chevron-left" color="gray">ماه بعد</x-filament::button>
    </div>

    <div style="display:grid; grid-template-columns:repeat(7,1fr); gap:6px;">
        @foreach($weekDays as $wd)
            <div style="text-align:center; font-weight:bold; font-size:12px; color:#475569; padding:6px;">{{ $wd }}</div>
        @endforeach

        @for($i = 0; $i < $cal['leading']; $i++)
            <div></div>
        @endfor

        @for($day = 1; $day <= $cal['daysInMonth']; $day++)
            @php $dayTasks = $cal['tasks'][$day] ?? collect(); @endphp
            <div style="min-height:90px; border:1px solid #e2e8f0; border-radius:8px; padding:5px; background:#fff;">
                <div style="font-size:12px; font-weight:bold; color:#334155;">{{ N::digits($day) }}</div>
                @foreach($dayTasks as $t)
                    <a href="{{ \App\Filament\Resources\TaskResource::getUrl('edit', ['record' => $t]) }}"
                       title="{{ $t->title }}"
                       style="display:block; margin-top:3px; font-size:10px; color:#fff; background:{{ $priorityColor[$t->priority] ?? '#64748b' }}; border-radius:4px; padding:2px 5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
                        {{ $t->title }}
                    </a>
                @endforeach
            </div>
        @endfor
    </div>
</x-filament-panels::page>
