<?php


namespace Magetop\Advancepreview\Ui\Product\Form;

use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\UrlInterface;
use Magento\Ui\Component\Container;
class PreviewDiscount extends AbstractModifier
{
    const PREVIEW_TAB = 'custom_preview_discount';
    const OPD_TAB_CONTENT = 'content';

    /**
     * @var \Magento\Catalog\Model\Locator\LocatorInterface
     */
    protected $locator;

    /**
     * @var ArrayManager
     */
    protected $arrayManager;

    /**
     * @var UrlInterface
     */
    protected $urlBuilder;

    /**
     * @var array
     */
    protected $meta = [];
    protected $_backendTemplate;
    /**
     * @param LocatorInterface $locator
     * @param ArrayManager $arrayManager
     * @param UrlInterface $urlBuilder
     */
    public function __construct(
        LocatorInterface $locator,
        ArrayManager $arrayManager,
        UrlInterface $urlBuilder,
        \Magento\Backend\Block\Template $backendTemplate
    ) {
        $this->locator = $locator;
        $this->arrayManager = $arrayManager;
        $this->urlBuilder = $urlBuilder;
        $this->_backendTemplate = $backendTemplate;
    }

    public function modifyMeta(array $meta)
    {
        $blockTemplate = $this->_backendTemplate;
        $meta['custom_discount_fieldset_name'] = [
            'arguments' => [
                'data' => [
                    'config' => [
                        'label' => __('Standard Design Service'),
                        'sortOrder' => 10,
                        'collapsible' => true,
                        'componentType' => 'fieldset'
                    ]
                ]
            ],
            'children' => [
                static::PREVIEW_TAB => [
                    'arguments' => [
                        'data' => [
                            'config' => [
                                'label' => null,
                                'formElement' => Container::NAME,
                                'componentType' => Container::NAME,
                                'template' => 'ui/form/components/complex',
                                'content' => $blockTemplate->getLayout()->createBlock('Magetop\Advancepreview\Block\Adminhtml\Product\Edit\PreviewDiscount')->setTemplate('Magetop_Advancepreview::product/discount/form.phtml')->toHtml(),
                                'sortOrder' => 10,
                            ],
                        ],
                    ],
                    'children' => [],
                ],
            ],
        ];

        return $meta;
    }

    /**
     * {@inheritdoc}
     */
    public function modifyData(array $data)
    {
        return $data;
    }
}
