<?php

namespace App\Livewire\Admin\Plans;

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

class Index extends Component
{
    public $plans;

    protected $listeners = ['planUpdated' => 'loadPlans'];

    public function mount()
    {
        $this->loadPlans();
    }

    public function loadPlans()
    {
        $this->plans = Plan::orderBy('price')->get();
    }

    public function delete($id)
    {
        Plan::find($id)?->delete();
        $this->loadPlans();
    }

    public function render()
    {
        return view('livewire.admin.plans.index')
            ->layout('layouts.app');
    }
}
