<?php

namespace FiloBlu\ExtBlackbirdMenuManager\Block\Adminhtml\NodeType;

use Blackbird\MenuManager\Api\NodeTypeInterfaceAdmin;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Button;

/**
 *
 */
class Subcategory extends Template implements NodeTypeInterfaceAdmin
{
    /**
     * @var string
     */
    protected $_template = 'menu/nodetype/subcategory.phtml';

    /**
     * Subcategory constructor.
     * @param Context $context
     * @param array $data
     */
    public function __construct(
        Context $context,
        $data = []
    ) {
        parent::__construct($context, $data);
    }

    /**
     * @return string
     */
    public function getUrlSource()
    {
        return $this->getUrl('menumanager/subcategory_widget/chooser/form/subcategory_id_chooser');
    }

    /**
     * get the button to open the subcategory chooser
     *
     * @return string
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function getOpenChooserButtonHtml()
    {
        return $this->getLayout()->createBlock(
            Button::class, 'open_chooser_subcategory', [
                'data' => [
                    'id'    => 'open_chooser',
                    'label' => __('Open Chooser'),
                    'title' => __('Open Chooser'),
                    'class' => 'button-open-chooser',
                ]
            ]
        )->toHtml();
    }

    /**
     * get the button to apply the chooser
     *
     * @return string
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function getApplyButtonHtml()
    {
        return $this->getLayout()->createBlock(
            Button::class, 'apply_chooser_subcategory', [
                'data' => [
                    'id'    => 'apply',
                    'label' => __('Apply'),
                    'title' => __('Apply'),
                    'class' => 'button-apply-chooser'
                ]
            ]
        )->toHtml();
    }
}
