<?php

namespace KupShop\ElninoBundle\Admin\Tabs;

use KupShop\AdminBundle\Admin\WindowTab;

class ElninoSeo extends WindowTab
{
    protected $title = 'flapElninoSectionSeo';

    protected $template = 'window/sections.elnino.seo.tpl';

    public static function getTypes()
    {
        return [
            'sections' => -1,
        ];
    }

    public function getVars($smarty_tpl_vars)
    {
        $vars = parent::getVars($smarty_tpl_vars);

        return $vars;
    }

    public function handleUpdate()
    {
        $data = $this->getData();
        $data = array_merge($this->getSectionData(), $data);

        $this->updateSQL('sections', ['data' => json_encode($data)], ['id' => $this->getID()]);
    }

    public function getSectionData()
    {
        $data = $this->selectSQL('sections', ['id' => $this->getID()], ['data'])->fetchColumn();

        return json_decode($data, true) ?? [];
    }
}
