<?php

namespace App\Livewire\Merchant;

use App\Services\CartService;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Component;

#[Layout('layouts.merchant')]
#[Title('السلة - تاجر بلس')]
class CartPage extends Component
{
    public function updateQuantity(int $variantId, int $qty): void
    {
        app(CartService::class)->updateQuantity($variantId, $qty);
    }

    public function removeItem(int $variantId): void
    {
        app(CartService::class)->removeItem($variantId);
    }

    public function clearCart(): void
    {
        app(CartService::class)->clear();
    }

    public function render()
    {
        $cartService = app(CartService::class);
        $summary = $cartService->recalculate();

        return view('livewire.merchant.cart-page', compact('summary'));
    }
}
