b2in/app/Livewire/Cabinet/QuickStatus.php
2026-04-10 17:18:17 +02:00

109 lines
3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Livewire\Cabinet;
use App\Models\CabinetTabletSetting;
use Livewire\Component;
class QuickStatus extends Component
{
public bool $authorized = false;
public string $storeStatus = 'auto';
public string $noticeHeadline = '';
public string $noticeSubtext = '';
public bool $saved = false;
/** @var array<string, array{label: string, color: string, icon: string, description: string}> */
public array $statusOptions = [
'auto' => [
'label' => 'Automatisch',
'color' => 'green',
'icon' => '✓',
'description' => 'Status aus Öffnungszeiten',
],
'closed' => [
'label' => 'Geschlossen',
'color' => 'yellow',
'icon' => '',
'description' => 'Manuell geschlossen',
],
'notice' => [
'label' => 'Hinweis',
'color' => 'orange',
'icon' => '!',
'description' => 'Info-Nachricht anzeigen',
],
'warning' => [
'label' => 'Warnung',
'color' => 'red',
'icon' => '!',
'description' => 'Dringende Warnung',
],
];
public function mount(): void
{
$validKey = config('domains.cabinet_status_key');
$key = request()->get('key');
if (! $validKey || $key !== $validKey) {
$this->authorized = false;
return;
}
$this->authorized = true;
$settings = CabinetTabletSetting::current();
$this->storeStatus = $settings->store_status ?? 'auto';
$this->noticeHeadline = $settings->notice_headline ?? '';
$this->noticeSubtext = $settings->notice_subtext ?? '';
}
public function selectStatus(string $status): void
{
if (! $this->authorized) {
return;
}
if (! array_key_exists($status, $this->statusOptions)) {
return;
}
$this->storeStatus = $status;
$this->saved = false;
}
public function save(): void
{
if (! $this->authorized) {
return;
}
$this->validate([
'storeStatus' => 'required|in:auto,notice,warning,closed',
'noticeHeadline' => 'nullable|string|max:40',
'noticeSubtext' => 'nullable|string|max:80',
], [
'storeStatus.in' => 'Ungültiger Status.',
'noticeHeadline.max' => 'Headline max. 40 Zeichen.',
'noticeSubtext.max' => 'Subtext max. 80 Zeichen.',
]);
CabinetTabletSetting::current()->update([
'store_status' => $this->storeStatus,
'notice_headline' => $this->noticeHeadline ?: null,
'notice_subtext' => $this->noticeSubtext ?: null,
]);
$this->saved = true;
}
public function render(): \Illuminate\View\View
{
return view('livewire.cabinet.quick-status')
->layout('layouts.cabinet-quick');
}
}