<?php

namespace App\Livewire;

use App\Models\Carrera;
use App\Models\Nivel;
use App\Models\Plan;
use Livewire\Component;

class Carreras extends Component
{
    public $niveles;
    public $selectedNivel = null;
    public $carreras = [];
    public $selectedCarrera = null;
    public Plan $plan;

    public function mount(Plan $plan)
    {
    $this->plan = $plan;

    $this->niveles = Nivel::all();

    $this->selectedNivel = (int) $plan->nivel;
    $this->selectedCarrera = (int) $plan->carrera;

    $this->carreras = Carrera::where('nivel', $this->selectedNivel)->get();
    }


    // Este método se ejecuta cuando $selectedCountry cambia
    public function updatedSelectedNivel($nivel)
    {
        $this->carreras = Carrera::where('nivel','=', $nivel)->get();
        $this->selectedCarrera = null; // Reiniciar ciudad al cambiar país
    }

    public function render()
    {
        return view('livewire.carreras');
    }
}
