<?php
/**
 * Copyright © 2018 EaDesign by Eco Active S.R.L. All rights reserved.
 * See LICENSE for license details.
 */

namespace Eadesigndev\Awb\Block\Adminhtml\Xtea;

use Eadesigndev\Awb\Block\Adminhtml\Xtea\Edit\Buttons\DuplicateButton;
use Eadesigndev\Awb\Block\Adminhtml\Xtea\Edit\Buttons\AprobaAwb;
use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;

/**
 * Class EditAwb
 * @package Eadesigndev\Awb\Block\Adminhtml\Xtea
 */
#[\AllowDynamicProperties]
class EditAwb extends Container
{
    private $duplicateButton;

    private $aprobaAwb;

    /**
     * Core registry
     * @var Registry
     * @var DuplicateButton
     * @var AprobaAwb
     */

    private $coreRegistry = null;

    public function __construct(
        Context $context,
        Registry $registry,
        DuplicateButton $duplicateButton,
        AprobaAwb $aprobaAwb,
        array $data = []
    ) {

        $this->coreRegistry = $registry;
        $this->duplicateButton = $duplicateButton;
        $this->aprobaAwb = $aprobaAwb;
        parent::__construct(
            $context,
            $data
        );
    }

    /**
     *
     * @return void
     */
    public function _construct()
    {
        $this->_objectId = 'entity_id';
        $this->_blockGroup = 'Eadesigndev_Awb';
        $this->_controller = 'adminhtml_xtea';

        parent::_construct();

        $this->buttonList->remove('save');
        $this->buttonList->remove('reset');

        $this->getToolbar()->addChild(
            'save-split-button',
            'Magento\Backend\Block\Widget\Button\SplitButton',
            [
                'id'           => 'save-split-button',
                'label'        => __('Save & finish AWB'),
                'class_name'   => 'Magento\Backend\Block\Widget\Button\SplitButton',
                'button_class' => 'widget-button-update',
                'options'      => [
                    [
                        'id'             => 'save-button',
                        'label'          => __('Save & finish AWB'),
                        'default'        => true,
                        'data_attribute' => [
                            'mage-init' => [
                                'button' => [
                                    'event'  => 'save',
                                    'target' => '#edit_form'
                                ]
                            ]
                        ]
                    ],
                    [
                        'id'             => 'save-continue-button',
                        'label'          => __('Save AWB'),
                        'data_attribute' => [
                            'mage-init' => [
                                'button' => [
                                    'event'  => 'saveAndContinueEdit',
                                    'target' => '#edit_form'
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        );

        $this->buttonList->add(
            'print',
            [
                'label' => __('Print'),
                'class' => 'action-secondary',
                'data_attribute' => [
                    'mage-init' => [
                        'button' => [
                            'event' => 'printDocument',
                            'target' => '#edit_form'
                        ],
                    ],
                ]
            ],
            5
        );

        $this->buttonList->update(
            'delete',
            'label',
            __('Delete Awb')
        );
    }
}
