<?php

namespace App\Traits\Purchase;

use App\Models\PurchaseItem;

trait WithDeleteItem
{
    public function deleteItem(PurchaseItem $item): void
    {
        $this->purchaseItems = $this->purchaseItems->reject(fn ($i) => $i->id === $item->id);

        $item->delete();

        $this->form->total = formatCurrencyNumber($this->purchaseItems->sum('total_price'), '');

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