<?php

namespace LaraBB\Post\UI\Web\Handlers;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use LaraBB\Post\Actions\CreateAction;
use LaraBB\Post\UI\Web\Requests\Create;

/**
 * Class CreateHandler
 * @package LaraBB\Post\UI\Web\Handlers
 */
class CreateHandler extends Controller
{
    /**
     * CreateHandler constructor.
     * @param CreateAction $createAction
     * @param Factory $view
     */
    public function __construct(
        private readonly CreateAction $createAction,
        private readonly Factory $view
    ) {

    }


    /**
     * @param Create $request
     * @return View
     */
    public function __invoke(Create $request): View
    {
        return $this->view->make('post::create-edit', array_merge(
            ['edit' => false],
            $this->createAction->run($request)
        ));
    }
}
