<?php

namespace App\Domains\Event\Controllers;

use App\Providers\InertiaProvider;
use App\Scopes\CommonController;
use Illuminate\Http\Request;
use Inertia\Response;

class AvailableEventsController extends CommonController
{
    public function __invoke(Request $request) : Response {
        $events = [];
        foreach ($this->events->getAvailable(false) as $event) {
            $events[] = $event->toResource()->toArray($request);
        };


        $inertiaProvider = new InertiaProvider('Event/ListAvailable', ['events' => $events]);
        return $inertiaProvider->render();
    }
}
