<?php

namespace App\Livewire\Plans;

use App\Models\Plan;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;

class Index extends Component
{
    public $plans;
    public $allFeatures;
    public $subscription;
    public $currentPlanKey;
    public $billing = 'monthly'; // monthly | yearly

    public function mount()
    {
        $this->plans = Plan::public()->with(['features.group'])
            ->where('active', true)
            ->orderBy('sort')
            ->get();

        $this->allFeatures = \App\Models\Feature::with('group')
            ->where('active', true)
            ->orderBy('sort')
            ->get();

        $user = Auth::user();

        if ($user?->subscription) {
            $this->subscription = $user->subscription;
            $this->currentPlanKey = $user->subscription->plan?->plan_key;
        }
    }

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