<?php

namespace App\Livewire\Studio\Catalog\Product;

use App\Models\Product;
use App\Traits\Authorization\WithAuthorization;
use App\Traits\Components\WithConfirmation;
use App\Traits\Components\WithToast;
use App\Traits\Notification\WithSubscribeNotification;
use App\Traits\Utilities\WithRequestNotification;
use Flux\Flux;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Title;
use Livewire\Component;

#[Title('Produk')]
class Index extends Component
{
    use WithAuthorization, WithConfirmation, WithRequestNotification, WithSubscribeNotification, WithToast;

    public function delete(Product $product): void
    {
        $this->canOrAbort('delete product');

        $product->delete();

        $this->dispatch('refreshDatatable');

        $this->toast('Produk berhasil dihapus.');

        Flux::modals()->close();
    }

    public function render(): View
    {
        return view('livewire.studio.catalog.product.index', [
            'pageTitle' => 'Produk',
        ]);
    }
}
