<?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\Outlet\WithFacilityHandler;
use App\Traits\WithAuthorization;
use App\Traits\WithToast;
use App\Traits\WithUpdatedData;
use Livewire\Attributes\Title;
use Livewire\Component;

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

    public OutletForm $form;

    public array $days = [];

    public function mount(Outlet $outlet)
    {
        $this->form->setOutlet($outlet);

        $this->days = Day::cases();
    }

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

        $this->form->update();

        $this->toast('Outlet berhasil diperbarui.');

        $this->redirectRoute('studio.master.outlet.index', navigate: true);
    }

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