<?php
/**
 * @package   Essentials YOOtheme Pro 2.2.16 build 0813.1608
 * @author    ZOOlanders https://www.zoolanders.com
 * @copyright Copyright (C) Joolanders, SL
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
 */

namespace ZOOlanders\YOOessentials\Form\Listener;

use YOOtheme\Http\Request;
use ZOOlanders\YOOessentials\Form\Controller\FormAdminController;
use ZOOlanders\YOOessentials\Form\Source\FormQueryType;
use ZOOlanders\YOOessentials\Form\Source\FormType;

class AddFormSource
{
    public Request $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function handle($source): void
    {
        if ($this->request->getParam('p') !== FormAdminController::FIELDS_URL) {
            return;
        }

        $source->objectType(FormType::TYPE_NAME, FormType::config($this->request->getParam('controls', [])));
        $source->queryType(FormQueryType::config());
    }
}
