<?php
namespace Leadlion\StockUpdates\Block\System\Config;


use Magento\Config\Block\System\Config\Form\Field;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\Element\AbstractElement;

class Button extends Field
{
    protected $_template = 'Leadlion_StockUpdates::system/config/button.phtml';
    public function __construct(Context $context, array $data = [])
    {
        parent::__construct($context, $data);
    }

    public function render(AbstractElement $element)
    {
        $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
        return parent::render($element);
    }
    protected function _getElementHtml(AbstractElement $element)
    {
        return $this->_toHtml();
    }
    public function getUmButtonUrl()
    {
        return $this->getUrl('leadlionupdatestocks/index/index',['um' => 1]);
    }
    public function getButtonUrl()
    {
        return $this->getUrl('leadlionupdatestocks/index/index',[]);
    }
    public function getButtonHtml()
    {
        $button = $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')->setData(
            [
                'id' => 'leadlionstocks',
                'label' => __('Update stocks from SmartBill'),
                'on_click' => sprintf("location.href = '%s';", $this->getButtonUrl())
            ]);
        return $button->toHtml();
    }
    public function getUmButtonHtml()
    {
        $button = $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')->setData(
            [
                'id' => 'leadlionsum',
                'label' => __('Update measuringUnit from SmartBill'),
                'on_click' => sprintf("location.href = '%s';", $this->getUmButtonUrl())
            ]);
        return $button->toHtml();
    }
}
