<?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 Advancepreview extends AbstractModifier
{
    const PREVIEW_TAB = 'prvview_tab';
    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['opd_fieldset_name'] = [
            'arguments' => [
                'data' => [
                    'config' => [
                        'label' => __('3D Preview Data'),
                        'sortOrder' => 9,
                        '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\Form')->setTemplate('Magetop_Advancepreview::product/form.phtml')->toHtml(),
                                'sortOrder' => 10,
                            ],
                        ],
                    ],
                    'children' => [],
                ],
            ],
        ];

        return $meta;
    }

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