<?php

namespace App\Livewire\Admin\Users;

use App\Models\Event;
use App\Models\User;
use Livewire\Component;

class Calendar extends Component
{
    public User $user;

    public bool $sidebarOpen = false;
    public ?string $selectedEventId = null;

    public function mount(User $user)
    {
        $this->user = $user;
    }

    public function openEvent(string $eventId)
    {
        $this->selectedEventId = $eventId;
        $this->sidebarOpen = true;
    }

    public function closeSidebar()
    {
        $this->sidebarOpen = false;
        $this->selectedEventId = null;
    }

    public function render()
    {
        $events = $this->user->events()
            ->orderBy('starts_at', 'desc')
            ->get();

        $selectedEvent = $this->selectedEventId
            ? Event::find($this->selectedEventId)
            : null;

        return view('livewire.admin.users.calendar', compact('events', 'selectedEvent'))
            ->layout('layouts.app');
    }
}
