<?php
/**
 * Copyright 2016 Adobe
 * All Rights Reserved.
 */

/** @var $block \Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Variations\Config\Matrix */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
/** @var \Magento\Framework\Escaper $escaper */
?>
<?php
/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
$jsonHelper = $block->getData('jsonHelper');
$currencySymbol = $block->getCurrencySymbol();
?>
<div class="<?= /* @noEscape */ $block->getData('config/dataScope') ?>"
     data-role="step-wizard-dialog"
     data-bind="scope: '<?= /* @noEscape */ $block->getForm() ?>.<?= /* @noEscape */ $block->getModal() ?>'">
    <!-- ko template: getTemplate() --><!-- /ko -->
</div>
<div class="<?= /* @noEscape */ $block->getData('config/dataScope') ?>"
     id="product-variations-matrix" data-role="product-variations-matrix">
    <div data-bind="scope: 'configurableVariations'"></div>
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "<?= /* @noEscape */ $block->getData('config/form') ?>.<?= /* @noEscape */ $block->getModal() ?>": {
                        "component": "Magento_ConfigurableProduct/js/components/modal-configurable",
                        "options": {"type": "slide",
                         "title": "<?= $escaper->escapeHtml(__('Create Product Configurations')) ?>"},
                        "formName": "<?= /* @noEscape */ $block->getForm() ?>",
                        "isTemplate": false,
                        "stepWizard": "<?= /* @noEscape */ $block->getData('config/nameStepWizard') ?>",
                        "children": {
                            "wizard": {
                                "url": "<?= /* @noEscape */ $block->getUrl(
                                    $block->getData('config/urlWizard'),
                                    ['id' => $block->getProduct()->getId()]
                                ) ?>",
                                "component": "Magento_Ui/js/form/components/html"
                            }
                        }
                    },
                    "<?= /* @noEscape */ $block->getData('config/form') ?>.configurableVariations": {
                        "component": "Magento_ConfigurableProduct/js/variations/variations",
                        "provider": "<?= /* @noEscape */ $block->getProvider() ?>",
                        "dataScopeVariations": "variations",
                        "dataScopeAttributes": "data.attributes",
                        "dataScopeAttributeCodes": "data.attribute_codes",
                        "dataScopeAttributesData": "data.product.configurable_attributes_data",
                        "formName": "<?= /* @noEscape */ $block->getForm() ?>",
                        "attributeSetHandler": "<?= /* @noEscape */ $block->getForm()
                        ?>.configurable_attribute_set_handler_modal",
                        "wizardModalButtonName": "<?= /* @noEscape */ $block->getForm()
                        ?>.configurable.configurable_products_button_set.create_configurable_products_button",
                        "wizardModalButtonTitle": "<?= $escaper->escapeHtml(__('Edit Configurations')) ?>",
                        "productAttributes":<?=/* @noEscape */ $jsonHelper->jsonEncode(
                            $block->getProductAttributes()
                        )?>,
                        "productUrl": "<?= /* @noEscape */ $block->getUrl('catalog/product/edit', ['id' => '%id%']) ?>",
                        "variations": <?= /* @noEscape */ $jsonHelper->jsonEncode($block->getProductMatrix()) ?>,
                        "currencySymbol": "<?= /* @noEscape */ $currencySymbol ?>",
                        "attributeSetCreationUrl": "<?= /* @noEscape */ $block->getUrl('*/product_set/save') ?>"
                    }
                }
            }
        }
    }
</script>
<?php $dataScope = /* @noEscape */ $block->getData('config/dataScope');
$scriptString = <<<script
    require(['jquery', 'mage/apply/main'], function ($, main) {
        main.apply();
        $('.{$dataScope}[data-role=step-wizard-dialog]').applyBindings();
        $('.{$dataScope}[data-role=product-variations-matrix]').applyBindings();
    })
script;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
