<?php

namespace App\Livewire\Studio\Master\Outlet;

use App\Enums\Day;
use App\Livewire\Forms\Studio\Master\OutletForm;
use App\Models\Outlet;
use App\Traits\Authorization\WithAuthorization;
use App\Traits\Components\WithToast;
use App\Traits\Outlet\WithFacilityHandler;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Title;
use Livewire\Component;

#[Title('Ubah Outlet')]
class Edit extends Component
{
    use WithAuthorization, WithFacilityHandler, WithToast;

    public OutletForm $form;

    public array $days = [];

    public function mount(Outlet $outlet): void
    {
        $this->form->setOutlet($outlet);
        $this->days = Day::cases();
    }

    public function save(): void
    {
        $this->canOrAbort('update outlet');

        $this->form->update();

        $this->redirectRoute('studio.master.outlet.index', [
            'notification' => 'Outlet berhasil diperbarui.',
        ], navigate: true);
    }

    public function render(): View
    {
        return view('livewire.studio.master.outlet.form', [
            'pageTitle' => 'Ubah Outlet',
        ]);
    }
}
