<?php

namespace App\Livewire\Admin;

use App\Enums\OrderStatus;
use App\Enums\PaymentStatus;
use App\Models\Order;
use App\Models\Payment;
use Livewire\Attributes\On;
use Livewire\Component;

/**
 * Badge sidebar Admin yang refresh via Livewire event.
 * Dipanggil: $this->dispatch('refresh-admin-badges') dari Pesanan/Show dan Pembayaran/Show.
 */
class AdminBadges extends Component
{
    public int $pendingOrders   = 0;
    public int $pendingPayments = 0;

    public function mount(): void
    {
        $this->refresh();
    }

    #[On('refresh-admin-badges')]
    public function refresh(): void
    {
        $this->pendingOrders   = Order::where('status', OrderStatus::Pending)->count();
        $this->pendingPayments = Payment::where('status', PaymentStatus::Pending)->count();
    }

    public function render()
    {
        return view('livewire.admin.admin-badges');
    }
}
