@php
use App\Domain\Attendance\EventType;
$stateKey = $today['state']->langKey();
$order = [EventType::TravelCheckIn, EventType::StartWork, EventType::StartBreak, EventType::EndBreak, EventType::ReturnDeparture, EventType::FinalCheckOut];
$primary = in_array($today['state']->value, ['working']) ? ($today['dualJourney'] ? EventType::ReturnDeparture : EventType::FinalCheckOut) : ($today['allowed'][0] ?? null);
@endphp
$dashboard, 'mx-auto flex max-w-2xl flex-col gap-4' => ! $dashboard])>
@if($employeeDashboard)
@include('livewire._employee-dashboard')
@else
@include('livewire._worksite-selection')
@if ($dashboard)
{{-- Worker home: four summary cards (status now, planned shift, recorded work time, GPS), same data as the record below. --}}
@php
$tones = ['working' => 'bg-success-soft text-success', 'finished' => 'bg-success-soft text-success', 'traveling' => 'bg-info-soft text-primary', 'on_break' => 'bg-warning-soft text-warning', 'private_leave' => 'bg-warning-soft text-warning'];
$tone = $tones[$today['state']->value] ?? 'bg-muted text-muted-foreground';
@endphp
@foreach ([['user-round-check', __('attendance.summary.status')], ['calendar-clock', __('attendance.summary.schedule')], ['clock-3', __('attendance.summary.duration')], ['map-pin', __('attendance.summary.gps')]] as $i => [$icon, $label])
@if ($i === 0)
{{ __('workStatus.'.$stateKey) }}
@elseif ($i === 1)
{{ $planned ? $planned['startTime'].'–'.$planned['endTime'] : __('attendance.summary.noSchedule') }}
{{ $planned ? __('attendance.summary.scheduleNote', ['timezone' => $tz]) : __('attendance.summary.noScheduleNote') }}
@elseif ($i === 2)
{{ $workMinutes >= 60 ? intdiv($workMinutes, 60).'h '.str_pad((string) ($workMinutes % 60), 2, '0', STR_PAD_LEFT).'m' : $workMinutes.'m' }}
{{ __('attendance.summary.durationNote') }}
@else
{{ __('attendance.summary.gpsStates.prompt') }}
{{ __('attendance.summary.gpsNote') }}
@endif
@endforeach
@endif
@if($actionsReady)
$dashboard]) aria-labelledby="att-title">
{{ __('attendance.title') }}
{{ __($attendanceMode === 'manual' ? 'scanning.manualSubtitle' : 'attendance.subtitle') }}
in_array($today['state']->value, ['working']), 'bg-info-soft text-accent-foreground' => in_array($today['state']->value, ['traveling', 'on_break', 'private_leave']), 'bg-muted text-muted-foreground' => in_array($today['state']->value, ['not_started', 'finished'])])>{{ __('workStatus.'.$stateKey) }}
$dashboard])>
{{ __('attendance.summary.schedule') }}
{{ $planned ? $planned['startTime'].'–'.$planned['endTime'] : __('attendance.summary.noSchedule') }}
{{ $planned ? __('attendance.summary.scheduleNote', ['timezone' => $tz]) : __('attendance.summary.noScheduleNote') }}
{{ __('attendance.summary.gps') }}
{{ __('attendance.summary.gpsStates.prompt') }}
{{ __('attendance.summary.gpsNote') }}
@if ($pending)
{{ __('attendance.lateBanner.title', ['minutes' => $pending->minutes_late]) }}
{{ __('attendance.lateBanner.action') }}
@endif
@if(!$today['closed'])
@foreach(['automatic','manual'] as $mode)
{{ __('scanning.'.$mode) }}
@endforeach
@if($attendanceMode === 'manual')
{{ __('scanning.manual') }}
{{ __('scanning.manualTime') }} ({{ $tz }})
{{ __('scanning.manualReason') }}
{{ __('scanning.manualHint') }}
@endif
@endif
@include('livewire._journey-clocks')
@if ($today['closed'])
! $dashboard, 'bg-success-soft text-success' => $dashboard && $today['closed'] === 'finished', 'bg-warning-soft text-warning' => $dashboard && $today['closed'] !== 'finished'])>{{ __('attendance.closed.'.$today['closed']) }}
@endif
{{-- Stepper: six primary actions. Done = check + time, available = the action, otherwise "not now". The server still decides what is valid. --}}
@foreach ($order as $n => $step)
@php
$last = $events->where('type', $step)->last();
$available = in_array($step, $today['allowed'], true) && ! $today['closed'];
$done = (bool) $last;
$journeyActive = $today['dualJourney'] && (($step === EventType::TravelCheckIn && $today['state']->value === 'traveling') || ($step === EventType::ReturnDeparture && $today['state']->value === 'return_travel'));
@endphp
@unless ($loop->last) @endunless
@if ($available)
@php $isPrimary = $primary === $step; @endphp
value }}', {{ $step->requiresLocation($today['sixStep']) ? 'true' : 'false' }})" :disabled="busy || !$wire.allowedActions.includes('{{ $step->value }}')"
@class(['flex min-h-14 flex-1 items-center justify-between gap-3 rounded-2xl px-4 text-left outline-none transition focus-visible:ring-4 focus-visible:ring-ring/30 disabled:cursor-wait disabled:opacity-70', 'brand-gradient text-white shadow-soft hover:brightness-110' => $isPrimary, 'border border-border bg-white text-foreground hover:bg-muted' => ! $isPrimary])>
{{ $n + 1 }}. {{ $step->label('buttons',$today['dualJourney'],$today['sixStep']) }} $isPrimary, 'text-muted-foreground' => ! $isPrimary])>{{ $done ? __('attendance.lastRegisteredAt', ['time' => $last->recorded_at->setTimezone($tz)->format('H:i')]) : (!$today['dualJourney'] && config('worksites.enabled') && $attendanceMode !== 'manual' && $step === EventType::TravelCheckIn ? __('scanning.checkInHint') : $step->label('hints',$today['dualJourney'],$today['sixStep'])) }}
@if ($step->requiresLocation($today['sixStep'])) @endif
@else
$done, 'border-border/60 bg-muted/30 text-muted-foreground' => ! $done])>
{{ $n + 1 }}. {{ $step->label('buttons',$today['dualJourney'],$today['sixStep']) }} {{ $done ? __('attendance.lastRegisteredAt', ['time' => $last->recorded_at->setTimezone($tz)->format('H:i')]) : (!$today['dualJourney'] && config('worksites.enabled') && $attendanceMode !== 'manual' && $step === EventType::TravelCheckIn ? __('scanning.checkInHint') : $step->label('hints',$today['dualJourney'],$today['sixStep'])) }}
@if ($done) {{ $last->recorded_at->setTimezone($tz)->format('H:i') }}@if(isset($last->metadata['manual'])){{ __('scanning.manual') }} @endif @else{{ __('attendance.states.unavailable') }} @endif
@endif
@endforeach
{{ __('attendance.gpsModal.locating') }}
{{ __('attendance.gpsModal.notSaved') }}
{{ __($today['sixStep'] ? 'sixStep.gpsFootnote' : ($today['dualJourney'] ? 'journeys.gpsFootnote' : 'attendance.gpsFootnote')) }}
@include('livewire._attendance-secondary')
@if ($error)
{{ Lang::has('scanning.errors.'.$error) ? __('scanning.errors.'.$error) : (str_starts_with($error, 'WORKSITE_') ? __('worksites.errors.'.$error) : __('attendance.errors.'.$error)) }}
@elseif ($notice)
@if ($notice === 'explanationSaved'){{ __('attendance.toast.explanationSaved') }}. {{ __('attendance.toast.explanationSavedBody') }}
@else{{ __('attendance.toast.saved', ['action' => __($today['sixStep'] && Lang::has('sixStep.actions.'.$notice) ? 'sixStep.actions.'.$notice : 'attendance.actions.'.$notice)]) }}@endif
@endif
@endif
$dashboard]) aria-labelledby="rec-title">
{{ __('attendance.record.title') }}
{{ __('attendance.record.subtitle', ['timezone' => $tz]) }}
@if ($events->isEmpty())
{{ __('attendance.record.empty') }}
{{ __('attendance.record.emptyHint') }}
@elseif ($dashboard)
{{-- Timeline (worker home): one ring per saved event, the time in blue, the state the event led to, and the GPS accuracy when a fix was saved. --}}
@php
$after = ['worksite_arrival'=>['onSite','bg-info-soft text-primary'],'return_departure'=>['returnTravel','bg-info-soft text-primary'],'travel_check_in' => ['traveling', 'bg-info-soft text-primary'], 'start_work' => ['working', 'bg-primary text-white'], 'start_break' => ['onBreak', 'bg-warning-soft text-warning'], 'end_break' => ['working', 'bg-primary text-white'], 'start_private_leave' => ['privateLeave', 'bg-warning-soft text-warning'], 'end_private_leave' => ['working', 'bg-primary text-white'], 'final_check_out' => ['finished', 'bg-success-soft text-success']];
@endphp
@foreach ($events as $e)
@unless ($loop->last) @endunless
{{ __('attendance.actions.'.$e->type->langKey()) }}
{{ $e->recorded_at->setTimezone($tz)->format('H:i') }}
@include('livewire._manual-event-details', ['event' => $e])
@if (isset($after[$e->type->value])) {{ __('workStatus.'.$after[$e->type->value][0]) }} @endif
@if ($e->location) {{ __('attendance.record.gps', ['meters' => round($e->location->accuracy_meters)]) }} @endif
@endforeach
@else
@foreach ($events as $e)
{{ __('attendance.actions.'.$e->type->langKey()) }}@include('livewire._manual-event-details', ['event' => $e])
@if ($e->location){{ __('attendance.record.gps', ['meters' => round($e->location->accuracy_meters)]) }} @endif
{{ $e->recorded_at->setTimezone($tz)->format('H:i:s') }}
@endforeach
@endif
@endif
@if ($explaining && $pending)
{{ __('attendance.lateModal.title', ['minutes' => $threshold]) }}
{{ __('attendance.lateModal.description') }}
{{ __('attendance.lateModal.scheduled') }} {{ $pending->scheduled_start_at->setTimezone($tz)->format('H:i') }}
{{ __('attendance.lateModal.actual') }} {{ $pending->actual_start_at->setTimezone($tz)->format('H:i') }}
{{ __('attendance.lateModal.minutesLate') }} {{ $pending->minutes_late }} min
{{ __('attendance.lateModal.timeKept') }}
@endif