<?php

namespace App\Traits\Purchase;

use App\Models\PurchaseItem;

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

        $item->delete();

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

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