<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var $block \Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Variations\Config\Matrix */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<?php
/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
$jsonHelper = $block->getData('jsonHelper');
$productMatrix = $block->getProductMatrix();
$attributes = $block->getProductAttributes();
$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": "<?= $block->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": "<?= $block->escapeHtml(__('Edit Configurations')) ?>",
                        "productAttributes":<?=/* @noEscape */ $jsonHelper->jsonEncode($attributes)?>,
                        "productUrl": "<?= /* @noEscape */ $block->getUrl('catalog/product/edit', ['id' => '%id%']) ?>",
                        "variations": <?= /* @noEscape */ $jsonHelper->jsonEncode($productMatrix) ?>,
                        "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) ?>
