<?php

namespace App\Livewire\Merchant;

use App\Models\Order;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Component;

#[Layout('layouts.merchant')]
#[Title('طلباتي - تاجر بلس')]
class MyOrdersPage extends Component
{
    public string $statusFilter = '';

    public function render()
    {
        $orders = Order::where('user_id', auth()->id())
            ->when($this->statusFilter, fn ($q) => $q->where('status', $this->statusFilter))
            ->withCount('items')
            ->latest()
            ->get();

        $statusLabels = Order::getStatusLabels();

        return view('livewire.merchant.my-orders-page', compact('orders', 'statusLabels'));
    }
}
