<?php

namespace KupShop\SaveFormsBundle\Admin;

class Forms extends \Window
{
    protected $tableName = 'save_forms';
    protected $nameField = 'id';

    public function getTemplate()
    {
        $object = $this->getObject();
        $type = $object['type'] ?? 'default';
        $template = "fallback:window/forms/{$type}.tpl:window/forms.tpl";

        return $this->template = $template;
    }

    public function getData()
    {
        $data = parent::getData();
        if (getVal('Submit')) {
            $formData = array_replace($this->getCustomData(), $data['data'] ?? []);
            $data['data'] = $formData;
            $this->serializeCustomData($data);
        }

        return $data;
    }
}

return Forms::class;
