|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Livewire; |
| 4 | + |
| 5 | +use Illuminate\View\View; |
| 6 | +use Livewire\Component; |
| 7 | + |
| 8 | +class FoundationPreview extends Component |
| 9 | +{ |
| 10 | + public int $surfaceIndex = 0; |
| 11 | + |
| 12 | + /** |
| 13 | + * @var array<int, array{label: string, title: string, detail: string}> |
| 14 | + */ |
| 15 | + protected array $surfaces = [ |
| 16 | + [ |
| 17 | + 'label' => 'Desktop', |
| 18 | + 'title' => 'Desktop-first shell', |
| 19 | + 'detail' => 'NativePHP remains the first-class local shell for Katra while Laravel stays at the core.', |
| 20 | + ], |
| 21 | + [ |
| 22 | + 'label' => 'Server', |
| 23 | + 'title' => 'Server deployment', |
| 24 | + 'detail' => 'The same Laravel foundation is intended to run as a traditional shared or dedicated server deployment.', |
| 25 | + ], |
| 26 | + [ |
| 27 | + 'label' => 'Container', |
| 28 | + 'title' => 'Container runtime', |
| 29 | + 'detail' => 'Docker and Kubernetes targets stay in view so the product model is not trapped in a desktop-only shape.', |
| 30 | + ], |
| 31 | + ]; |
| 32 | + |
| 33 | + public function cycleSurface(): void |
| 34 | + { |
| 35 | + $this->surfaceIndex = ($this->surfaceIndex + 1) % count($this->surfaces); |
| 36 | + } |
| 37 | + |
| 38 | + public function updatingSurfaceIndex(mixed $value): void |
| 39 | + { |
| 40 | + $this->surfaceIndex = $this->normalizeSurfaceIndex((int) $value); |
| 41 | + } |
| 42 | + |
| 43 | + public function hydrate(): void |
| 44 | + { |
| 45 | + $this->surfaceIndex = $this->normalizeSurfaceIndex($this->surfaceIndex); |
| 46 | + } |
| 47 | + |
| 48 | + public function render(): View |
| 49 | + { |
| 50 | + $this->surfaceIndex = $this->normalizeSurfaceIndex($this->surfaceIndex); |
| 51 | + |
| 52 | + return view('livewire.foundation-preview', [ |
| 53 | + 'surfaces' => $this->surfaces, |
| 54 | + 'activeSurface' => $this->surfaces[$this->surfaceIndex], |
| 55 | + ]); |
| 56 | + } |
| 57 | + |
| 58 | + protected function normalizeSurfaceIndex(int $index): int |
| 59 | + { |
| 60 | + $maxIndex = count($this->surfaces) - 1; |
| 61 | + |
| 62 | + if ($maxIndex < 0 || $index < 0) { |
| 63 | + return 0; |
| 64 | + } |
| 65 | + |
| 66 | + if ($index > $maxIndex) { |
| 67 | + return $maxIndex; |
| 68 | + } |
| 69 | + |
| 70 | + return $index; |
| 71 | + } |
| 72 | +} |
0 commit comments