diff --git a/app/Livewire/ProgramEditor.php b/app/Livewire/ProgramEditor.php index 76559d8..0690d91 100644 --- a/app/Livewire/ProgramEditor.php +++ b/app/Livewire/ProgramEditor.php @@ -217,7 +217,11 @@ public function formattedDuration(): string public function totalDuration(): int { - return array_reduce( + if (empty($this->phases)) { + return 0; + } + + $total = array_reduce( $this->phases, static function (int $carry, array $p): int { $repTime = $p['duration'] * $p['repetitions']; @@ -226,6 +230,9 @@ static function (int $carry, array $p): int { }, 0, ); + + // The last phase's cooldown is never executed (timer goes straight to COMPLETED). + return $total - (int) ($this->phases[array_key_last($this->phases)]['cooldown'] ?? 0); } /** diff --git a/app/Livewire/TimerScreen.php b/app/Livewire/TimerScreen.php index abb7958..3ee5e5f 100644 --- a/app/Livewire/TimerScreen.php +++ b/app/Livewire/TimerScreen.php @@ -126,6 +126,10 @@ public function start(): void $runner = app(TimerRunner::class); $program = Program::with('phases')->findOrFail($this->programId); + if ($program->phases->isEmpty()) { + return; + } + $this->programTotalDuration = $program->totalDuration(); $runner->load($program); $runner->start(); diff --git a/resources/views/livewire/timer-screen.blade.php b/resources/views/livewire/timer-screen.blade.php index b405b1f..87cb252 100644 --- a/resources/views/livewire/timer-screen.blade.php +++ b/resources/views/livewire/timer-screen.blade.php @@ -259,13 +259,20 @@ class="text-gray-800 text-xs mt-2 select-none" {{-- Primary action --}} @if($state === StateMachine::idle) - + @if(count($phases) === 0) +