<?php

namespace ThurData\Servers\KerioEmail\Core\UI\Widget\Others;

use ThurData\Servers\KerioEmail\Core\Traits\Lang;
use ThurData\Servers\KerioEmail\Core\UI\Builder\BaseContainer;
use ThurData\Servers\KerioEmail\Core\UI\Interfaces\AjaxElementInterface;
use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\RawDataJsonResponse;

/**
 * Class DetailsWidget
 *
 * @autor ThurData <info@thurdata.ch>
 */

class DetailsWidget extends BaseContainer implements AjaxElementInterface
{
    use Lang;

    protected $id    = 'detailsWidget';
    protected $name  = 'detailsWidget';
    protected $title = 'detailsWidget';

    protected $vueComponent            = true;
    protected $defaultVueComponentName = 'mg-details-widget';

    public function initContent()
    {

    }

    public function prepareAjaxData()
    {

    }

    public function getParsedTitle()
    {
        if($this->getRawTitle())
        {
            return $this->getRawTitle();
        }

        if($this->getTitle())
        {
            $this->loadLang();

            return $this->lang->controlerContextTranslate($this->getId() ,$this->getTitle());
        }

        return '';
    }

    public function returnAjaxData()
    {
        $this->prepareAjaxData();

        return (new RawDataJsonResponse([
            'title' => $this->getParsedTitle(),
            'data' => $this->data
        ]));
    }
}
