<?php

use App\Models\Order;
use Livewire\Attributes\Computed;
use Livewire\Component;
use Livewire\Attributes\Defer; 

return new class extends Component
{
    public $showModal = false;
    public $selectedOrder;
    public $newStatus;

    public function mount()
    {

    }

    #[Computed] // 👈 Mark as computed
    public function orders()
    {
        return Order::with(['items.product', 'user', 'address'])->get();
    }
    public function viewOrder($id)
    {
        $this->selectedOrder = Order::with(['user'])->find($id);
        $this->newStatus = $this->selectedOrder->status;
        $this->showModal = true;
    }

    public function updateStatus()
    {
        $this->selectedOrder->update(['status' => $this->newStatus]);
        $this->showModal = false;
        session()->flash('message', 'Order status updated to ' . $this->newStatus);
    }

    protected function view($data = [])
    {
        return app('view')->file('C:\laragon\www\ecommerce\storage\framework/views/livewire/views/30807c4d.blade.php', $data);
    }
};
