<?php

namespace App\Http\Controllers\PublicSite;

use App\Http\Controllers\Controller;
use App\Models\Event;
use Illuminate\Contracts\View\View;

class EventController extends Controller
{
    public function index(): View
    {
        return view('public.events.index', [
            'upcoming' => Event::published()->upcoming()->paginate(9),
            'past' => Event::published()->past()->take(4)->get(),
        ]);
    }

    public function show(Event $event): View
    {
        abort_unless($event->status->value === 'published', 404);

        return view('public.events.show', [
            'event' => $event,
            'upcoming' => Event::published()->upcoming()->whereKeyNot($event->id)->take(3)->get(),
        ]);
    }
}
