@props([
'calendarMonth',
'appointmentsByDate',
'visiblePerDay' => 5,
'useMeetingWithLabel' => false,
])
@php
$calendarMonth = $calendarMonth instanceof \App\Support\CalendarMonth
? $calendarMonth
: \App\Support\CalendarMonth::fromRequest(request());
$grid = $calendarMonth->grid();
$calendarCells = $grid['cells'];
$todayDay = $calendarMonth->todayDay();
$weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
$appointmentsByDate = $appointmentsByDate ?? collect();
$useMeetingWithLabel = (bool) $useMeetingWithLabel;
$salesmanInitials = \App\Models\Appointment::salesmanInitials(...);
$calendarViewerId = auth()->id() !== null ? (int) auth()->id() : null;
$appointmentTooltip = static fn (\App\Models\Appointment $appointment): string => \App\Support\AppointmentsMonthCalendarPresenter::appointmentTooltip(
$appointment,
$calendarViewerId,
);
$chipPersonLabel = static fn (\App\Models\Appointment $appointment): string => \App\Support\AppointmentsMonthCalendarPresenter::chipPersonLabel(
$appointment,
$useMeetingWithLabel,
$calendarViewerId,
);
$salesmanColorPalette = [
'text-blue-700',
'text-violet-700',
'text-teal-700',
'text-amber-700',
'text-rose-700',
'text-indigo-700',
'text-cyan-700',
'text-fuchsia-700',
'text-lime-700',
'text-orange-700',
];
$salesmanColorClass = static function (?\App\Models\User $user) use ($salesmanColorPalette): string {
if ($user === null) {
return 'text-gray-600';
}
return $salesmanColorPalette[(int) $user->id % count($salesmanColorPalette)];
};
@endphp
@foreach ($weekdays as $dayLabel)
{{ $dayLabel }}
@endforeach
@foreach ($calendarCells as $day)
@if ($day === null)
@else
@php
$dateKey = $calendarMonth->date->copy()->day($day)->format('Y-m-d');
$dayAppointments = $appointmentsByDate->get($dateKey, collect());
$isToday = $todayDay !== null && $day === $todayDay;
$visibleAppointments = $dayAppointments->take($visiblePerDay);
$moreCount = max(0, $dayAppointments->count() - $visiblePerDay);
$cellClasses = $isToday
? 'ring-2 ring-[var(--dealer-accent-color)] bg-red-50 border-[var(--dealer-accent-color)]'
: 'border-gray-200 bg-gray-50';
$dayNumberClasses = $isToday
? 'text-[var(--dealer-accent-color)] font-bold'
: 'text-gray-700 font-semibold';
@endphp
{{ $day }}
@if ($dayAppointments->isNotEmpty())
@foreach ($visibleAppointments as $appointment)
@php
$chipSalesman = $appointment->user;
$chipInitials = $chipSalesman ? $salesmanInitials($chipSalesman) : '?';
$chipSalesmanColor = $chipSalesman ? $salesmanColorClass($chipSalesman) : 'text-gray-600';
$chipTime = $appointment->appointment_datetime?->format('H:i') ?? '';
$chipLead = $chipPersonLabel($appointment);
@endphp
@if ($appointment->isCompleted())
✓
@elseif ($appointment->isMissed())
✕
@elseif ($appointment->isNoShow())
?
@endif
{{ $chipTime }} · {{ $chipInitials }}
@if ($appointment->isProspectingVisit())
· Prospecting
@elseif ($appointment->displaySubtext())
· {{ $appointment->displaySubtext() }}
@endif
@if ($chipLead !== '')
· {{ $chipLead }}
@endif
@endforeach
@endif
@endif
@endforeach