<?php

namespace App\Livewire\Admin;

use Livewire\Component;
use App\Models\CampBooking;

class BookingManagement extends Component
{
    public $bookings;
    public $statusOptions = ['pending', 'confirmed', 'rejected'];

    public function mount()
    {
        $this->bookings = CampBooking::with('camp_package')->latest()->get();
    }

    public function updateStatus($id, $status)
    {
        $booking = CampBooking::find($id);
        $booking->update(['status' => $status]);

        // Dispatch the alert event
        $this->dispatch('statusUpdated', [
            'message' => "Booking #{$booking->payment_reference} updated to {$status}."
        ]);

        session()->flash('success', 'Status updated successfully!');
    }

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