<?php
namespace Solwin\Verticalmenu\Block\Adminhtml\Menu\Edit;

/**
 * @method Tabs setTitle(\string $title)
 */
class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
    /**
     * Tabs template
     * 
     * @var string
     */
    protected $_template = 'Magento_Backend::widget/tabshoriz.phtml';

    /**
     * Registry
     * 
     * @var \Magento\Framework\Registry
     */
    protected $coreRegistry;

    /**
     * constructor
     * 
     * @param \Magento\Framework\Registry $coreRegistry
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
     * @param \Magento\Backend\Model\Auth\Session $authSession
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\Registry $coreRegistry,
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Json\EncoderInterface $jsonEncoder,
        \Magento\Backend\Model\Auth\Session $authSession,
        array $data = []
    )
    {
        $this->coreRegistry = $coreRegistry;
        parent::__construct($context, $jsonEncoder, $authSession, $data);
    }


    /**
     * Initialize Tabs
     *
     * @return void
     */
    protected function _construct()
    {
        parent::_construct();
        $this->setId('menu_info_tabs');
        $this->setDestElementId('menu_tab_content');
        $this->setTitle(__('Menu Data'));
    }

    /**
     * Retrieve Menu object
     *
     * @return \Solwin\Verticalmenu\Model\Menu
     */
    public function getMenu()
    {
        return $this->coreRegistry->registry('solwin_verticalmenu_menu');
    }


    /**
     * Prepare Layout Content
     *
     * @return $this
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     */
    protected function _prepareLayout()
    {
        $this->addTab(
            'menu',
            [
                'label' => __('Menu information'),
                'content' => $this->getLayout()->createBlock(
                    'Solwin\Verticalmenu\Block\Adminhtml\Menu\Edit\Tab\Menu',
                    'solwin_verticalmenu_menu_edit_tab_menu'
                )->toHtml()
            ]
        );
        // dispatch event add custom tabs
        $this->_eventManager->dispatch('adminhtml_solwin_verticalmenu_menu_tabs', ['tabs' => $this]);
        return parent::_prepareLayout();
    }
}
