<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_Marketplace
 * @author    Webkul
 * @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
?>
<?php
/** @var $block \Webkul\Marketplace\Block\Product\Edit\Tab\Variations\Config */
$productType = $this->getRequest()->getParam('type');
if ($block->getSellerProduct()->getId()) {
    $productType = $block->getSellerProduct()->getTypeId();
}
$type = 'configurable';
$isConfigurableProduct = $block->getSellerProduct()->getTypeId() === $type || $this->getRequest()->has('attributes');
$allowedtypes=explode(',', $this->helper(\Webkul\Marketplace\Helper\Data::class)->getAllowedProductType());
if (in_array($type, $allowedtypes) && ($productType == 'simple' || $productType == 'virtual' || $productType == 'configurable')) { ?>
    <script>
        var BASE_URL = '';
        var FORM_KEY = "";
    </script>
    <div class="entry-edit form-inline" id="super_config" data-panel="product-variations">
        <div data-bind="scope: 'variation-steps-wizard'" class="product-create-configuration">
            <div class="product-create-configuration-info">
                <div class="note" data-role="product-create-configuration-info">
                    <?= $block->escapeHtml(__('Configurable products allow customers to choose options (Ex: shirt color).
                You need to create a simple product for each configuration (Ex: a product for each color).'));?>
                </div>
            </div>
            <div class="product-create-configuration-actions" data-action="product-create-configuration-buttons">
                <div class="product-create-configuration-action">
                    <button type="button" data-action="open-steps-wizard" title="Create Product Configurations" class="action-secondary" data-bind="click: open">
                    <span data-role="button-label" data-edit-label="<?=  /* @noEscape */ __('Edit Configurations') ?>">
                        <?= /* @escapeNotVerified */ $block->getSellerProduct()->getId() && $isConfigurableProduct
                            ? $block->escapeHtml(__('Edit Configurations'))
                            : $block->escapeHtml(__('Create Configurations'))
                        ?>
                    </span>
                    </button>
                </div>
            </div>
        </div>
        <div class="fieldset">
            <?= $block->getChildHtml('sellermatrix'); ?>

            <!-- Select Associated Product popup -->
            <div data-grid-id="associated-products-container">
                <div class="admin__data-grid-outer-wrap" data-bind="scope: 'configurable_associated_product_listing.configurable_associated_product_listing'">
                    <div data-role="spinner" data-component="configurable_associated_product_listing.configurable_associated_product_listing.product_columns" class="admin__data-grid-loading-mask">
                        <div class="spinner">
                            <span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span>
                        </div>
                    </div>
                    <!-- ko template: getTemplate() --><!-- /ko -->

                </div>
            </div>

            <input type="hidden" name="affect_configurable_product_attributes" value="1" />
        </div>
    </div>
    <script type="text/x-magento-init">
        {
            "*": {
                "Magento_Ui/js/core/app": {
                    "components": {
                        "configurableProductGrid": {
                            "component": "Webkul_Marketplace/js/variations/product-grid",
                            "productsFilter": "configurable_associated_product_listing.configurable_associated_product_listing.listing_top.listing_filters",
                            "productsProvider": "configurable_associated_product_listing.data_source",
                            "productsMassAction": "configurable_associated_product_listing.configurable_associated_product_listing.product_columns.ids",
                            "productsColumns": "configurable_associated_product_listing.configurable_associated_product_listing.product_columns",
                            "productsGridUrl": "<?= $block->escapeUrl($block->getUrl('marketplace/product/associated_grid', ['componentJson' => true,'_secure' => $this->getRequest()->isSecure()]))?>",
                            "configurableVariations": "configurableVariations"
                        }
                    }
                },
                "Webkul_Marketplace/js/configurable-type-handler": {
                    "blockId": "#super_config",
                    "tabId": "super_config",
                    "hasVariations": "<?= $isConfigurableProduct ? 'true' : 'false' ?>"
                }
            }
        }
    </script>
    <?php
} ?>
