<?php

namespace App\Livewire;

use App\Models\Climbing;
use Livewire\Component;
use Livewire\Attributes\On; // WAJIB ADA untuk mendengarkan event di Livewire 3

class ClimbingDetail extends Component
{
    public $climbing;
    public $show = false;

    /**
     * Fungsi untuk memuat data pendaki berdasarkan ID.
     * Atribut #[On] akan mendengarkan dispatch 'load-climbing' dari file Blade dashboard.
     */
    #[On('load-climbing')] // WAJIB ADA (Ini kupingnya Livewire)
    public function loadClimbing($id)
    {
        // Mengambil data pendaki beserta relasi tiket dan guidenya
        $this->climbing = Climbing::with(['ticket', 'group.guide', 'guide'])->find($id);
        
        if ($this->climbing) {
            $this->show = true;
        }
    }

    /**
     * Fungsi untuk menutup modal
     */
    public function close()
    {
        $this->show = false;
        $this->climbing = null;
    }

    public function render()
    {
        return view('livewire.climbing-detail');
    }
}