<?php

namespace App\Livewire\Studio\Manage\Order;

use App\Models\Order;
use App\Traits\Order\WithUpdateStock;
use App\Traits\WithCloseModal;
use App\Traits\WithConfirmation;
use App\Traits\WithToast;
use Flux\Flux;
use Livewire\Attributes\Title;
use Livewire\Component;

#[Title('Order')]
class Index extends Component
{
    use WithCloseModal, WithConfirmation, WithToast, WithUpdateStock;

    public function delete(Order $order)
    {
        foreach ($order->items as $item) {
            $this->increaseOutletStock($order->outlet, $item);
        }

        $order->delete();

        $this->dispatch('refreshDatatable');

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

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

    public function render()
    {
        return view('livewire.studio.manage.order.index', [
            'pageTitle' => 'Order',
        ]);
    }
}
