<?php

namespace App\Livewire\Studio\Master\User;

use App\Livewire\Forms\Studio\Master\UserForm;
use App\Models\Outlet;
use App\Traits\WithAuthorization;
use App\Traits\WithOutletSelector;
use App\Traits\WithToast;
use App\Traits\WithUpdatedData;
use Livewire\Attributes\Title;
use Livewire\Component;

#[Title('Tambah Pegawai')]
class Create extends Component
{
    use WithAuthorization, WithOutletSelector, WithToast, WithUpdatedData;

    public UserForm $form;

    public array $outlets = [];

    public function mount()
    {
        $this->outlets = Outlet::pluck('name', 'id')->toArray();
    }

    public function save()
    {
        $this->canOrAbort('create user');

        $this->form->store();

        $this->toast('Pegawai berhasil ditambahkan.');

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

    public function render()
    {
        return view('livewire.studio.master.user.form', [
            'pageTitle' => 'Tambah Pegawai',
        ]);
    }
}
