<?php
/**
 * @author      Magetop Developer (Hau)
 * @package     Magento Multi Vendor Marketplace
 * @copyright   Copyright (c) Magetop (https://www.magetop.com)
 * @terms       https://www.magetop.com/terms
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 **/
?>

<div data-bind="scope: '<?= /* @escapeNotVerified */  $block->getComponentName()?>'" data-role="bulk-step">
    <h2 class="steps-wizard-title"><?= /* @escapeNotVerified */  __('Step 3: Bulk Images, Price, and Quantity') ?></h2>
    <div class="steps-wizard-info">
        <?= /* @escapeNotVerified */  __('Based on your selections <span class="new-products-count" data-bind="text:countVariations"></span>
        new products will be created. Use this step to customize images and price for your new products.') ?>
    </div>

    <div data-bind="with: sections().images" class="steps-wizard-section">
        <div data-role="section">
        <div class="steps-wizard-section-title">
            <span><?= /* @escapeNotVerified */  __('Images') ?></span>
        </div>

        <ul class="steps-wizard-section-list">
            <li>
                <div class="magetop__field magetop__field-option">
                    <input type="radio"
                           id="apply-single-set-radio"
                           class="magetop__control-radio"
                           value="single"
                           data-bind="checked:type">
                    <label for="apply-single-set-radio" class="magetop__field-label">
                        <span><?= /* @escapeNotVerified */  __('Apply single set of images to all SKUs') ?></span>
                    </label>
                </div>
            </li>
            <li>
                <div class="magetop__field magetop__field-option">
                    <input type="radio"
                           id="apply-unique-images-radio"
                           class="magetop__control-radio"
                           value="each"
                           data-bind="checked:type">
                    <label for="apply-unique-images-radio" class="magetop__field-label">
                        <span><?= /* @escapeNotVerified */  __('Apply unique images by attribute to each SKU') ?></span>
                    </label>
                </div>
            </li>
            <li>
                <div class="magetop__field magetop__field-option">
                    <input type="radio"
                           id="skip-images-uploading-radio"
                           class="magetop__control-radio"
                           value="none"
                           checked
                           data-bind="checked:type">
                    <label for="skip-images-uploading-radio" class="magetop__field-label">
                        <span><?= /* @escapeNotVerified */  __('Skip image uploading at this time') ?></span>
                    </label>
                </div>
            </li>
        </ul>

        <div data-role="step-gallery-single" class="attribute-image-selector" data-bind="visible: type() == 'single'">
            <div data-role="gallery"
                 class="gallery"
                 data-images="[]"
                 data-types="<?php /* @noEscape */ echo $block->escapeHtml(
                     $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getProConfigImageTypes())
                 ) ?>"
                >
                <div class="image image-placeholder">
                    <div data-role="uploader" class="uploader">
                        <div class="image-browse">
                            <span><?= /* @escapeNotVerified */  __('Browse Files...') ?></span>
                            <input type="file"
                                   id=""
                                   name="image"
                                   class="magetop__control-file"
                                   multiple="multiple"
                                   data-url="<?= /* @escapeNotVerified */ $block->getUrl('marketplace/product_gallery/upload') ?>" />
                        </div>
                    </div>
                    <p class="image-placeholder-text"><?= /* @escapeNotVerified */  __('Browse to find or drag image here') ?></p>
                </div>

                <script data-template="uploader" type="text/x-magento-template">
                    <div id="<%- data.id %>" class="file-row">
                        <span class="file-info"><%- data.name %> (<%- data.size %>)</span>
                        <div class="progressbar-container">
                            <div class="progressbar upload-progress" style="width: 0%;"></div>
                        </div>
                        <div class="spinner">
                            <span></span><span></span><span></span><span></span>
                            <span></span><span></span><span></span><span></span>
                        </div>
                    </div>
                </script>

                <script data-template="gallery-content" type="text/x-magento-template">
                    <div class="image item <% if (data.disabled == 1) { %>hidden-for-front<% } %>"
                         data-role="image">
                        <input type="hidden"
                               name="product[media_gallery][images][<%- data.file_id %>][position]"
                               value="<%- data.position %>"/>
                        <input type="hidden"
                               name="product[media_gallery][images][<%- data.file_id %>][file]"
                               value="<%- data.file %>"/>
                        <input type="hidden"
                               name="product[media_gallery][images][<%- data.file_id %>][value_id]"
                               value="<%- data.value_id %>"/>
                        <input type="hidden"
                               name="product[media_gallery][images][<%- data.file_id %>][label]"
                               value="<%- data.label %>"/>
                        <input type="hidden"
                               name="product[media_gallery][images][<%- data.file_id %>][disabled]"
                               value="<%- data.disabled %>"/>
                        <input type="hidden"
                               name="product[media_gallery][images][<%- data.file_id %>][removed]"/>
                        <img class="product-image" src="<%- data.url %>" alt="<%- data.label %>"/>
                        <button type="button"
                                class="action-remove"
                                data-role="delete-button"
                                title="<?= $block->escapeHtml(__('Remove image')) ?>">
                            <span><?= /* @escapeNotVerified */  __('Remove image') ?></span>
                        </button>
                        <div class="draggable-handle"></div>
                        <div class="image-label" title="<?= $block->escapeHtml(__('Edit role')) ?>"></div>
                        <div class="image-fade"><span><?= /* @escapeNotVerified */  __('Hidden') ?></span></div>
                    </div>
                </script>

                <script data-template="image" type="text/x-magento-template">
                    <div class="image">
                        <img
                            class="product-image"
                            src="<%- data.url %>"
                            data-position="<%- data.position %>"
                            alt="<%- data.label %>" />
                        <button type="button"
                                class="action-remove"
                                data-role="delete-button"
                                title="<?= $block->escapeHtml(__('Remove image')) ?>">
                            <span><?= /* @escapeNotVerified */  __('Remove image') ?></span>
                        </button>
                        <div class="draggable-handle"></div>
                        <div class="image-label" title="<?= $block->escapeHtml(__('Edit role')) ?>"></div>
                        <div class="image-fade"><span><?= /* @escapeNotVerified */  __('Hidden') ?></span></div>
                    </div>
                </script>

                <script class="dialog-template" type="text/x-magento-template" data-title="Image Options">
                    <div class="image-panel magetop__scope-old" data-role="dialog">
                        <div class="image-panel-preview">
                            <img src="<%- data.url %>" alt="<%- data.label %>" />
                        </div>
                        <div class="image-panel-controls">
                            <strong class="image-name"><%- data.label %></strong>

                            <fieldset class="magetop__fieldset fieldset-image-panel">
                                <div class="field field-image-description">
                                    <label class="field field-image-description">
                                        <span><?= /* @escapeNotVerified */  __('Alt Text') ?></span>
                                    </label>
                                    <div class="control">
                                        <textarea id="image-description"
                                                  class="magetop__control-textarea"
                                                  rows="3"
                                                  name="product[media_gallery][images][<%- data.file_id %>][label]"
                                            ><%- data.label %></textarea>
                                    </div>
                                </div>

                                <div class="field field-image-role">
                                    <label class="label">
                                        <span><?= /* @escapeNotVerified */  __('Role') ?></span>
                                    </label>
                                    <div class="control">
                                        <ul class="multiselect-alt">
                                            <?php
                                            foreach ($block->getProConfigMediaAttributes() as $attribute) : ?>
                                                <li class="item">
                                                    <label>
                                                        <input class="image-type"
                                                               data-role="type-selector"
                                                               type="checkbox"
                                                               value="<?php /* @noEscape */ echo $block->escapeHtml(
                                                                   $attribute->getAttributeCode()
                                                               ) ?>"
                                                            />
                                                        <?php /* @noEscape */ echo $block->escapeHtml(
                                                            $attribute->getFrontendLabel()
                                                        ) ?>
                                                    </label>
                                                </li>
                                                <?php
                                            endforeach;
                                            ?>
                                        </ul>
                                    </div>
                                </div>

                                <div class="field field-image-hide">
                                    <label class="label">
                                        <input type="checkbox"
                                               data-role="visibility-trigger"
                                               value="1"
                                               name="product[media_gallery][images][<%- data.file_id %>][disabled]"
                                        <% if (data.disabled == 1) { %>checked="checked"<% } %> />
                                        <span><?= /* @escapeNotVerified */  __('Hide from Product Page') ?></span>
                                    </label>
                                </div>
                            </fieldset>
                        </div>
                    </div>
                </script>

            </div>
        </div>
        <div data-role="step-gallery-each" class="attribute-image-selector" data-bind="visible: type() == 'each'">
            <fieldset class="magetop__fieldset bulk-attribute-values">
                <div class="magetop__field _required">
                    <label class="magetop__field-label" for="apply-images-attributes">
                        <span><?= /* @escapeNotVerified */  __('Select attribute')?></span>
                    </label>
                    <div class="magetop__field-control">
                        <select
                            id="apply-images-attributes"
                            class="magetop__control-select"
                            data-bind="
                                options: $parent.attributes,
                                optionsText: 'label',
                                value: attribute,
                                optionsCaption: '<?= /* @escapeNotVerified */  __("Select")?>'
                                ">
                        </select>
                    </div>
                </div>
            </fieldset>

            <ul class="items attributes-selector-list" data-bind="if:attribute, visible: attribute">
                <!-- ko foreach: {data: attribute().chosen, afterRender: $parent.bindGalleries} -->
                <li class="item" data-bind="attr:{'data-role':'step-gallery-option-' + id}">
                    <label class="attribute-label">
                        <span data-bind="text:label"></span>
                    </label>

                    <div data-role="gallery"
                         class="gallery"
                         data-images="[]"
                         data-types="<?php /* @noEscape */ echo $block->escapeHtml(
                             $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getProConfigImageTypes())
                         ) ?>"
                        >
                        <div class="image image-placeholder">
                            <div data-role="uploader" class="uploader">
                                <div class="image-browse">
                                    <span><?= /* @escapeNotVerified */  __('Browse Files...') ?></span>
                                    <input type="file" name="image" multiple="multiple"
                                           data-url="<?= /* @escapeNotVerified */ $block->getUrl('marketplace/product_gallery/upload') ?>" />
                                </div>
                            </div>
                            <p class="image-placeholder-text"><?= /* @escapeNotVerified */  __('Browse to find or drag image here') ?></p>
                            <div class="spinner">
                               <span></span><span></span><span></span><span></span>
                               <span></span><span></span><span></span><span></span>
                            </div>
                        </div>
                        <script data-template="uploader" type="text/x-magento-template">
                            <div id="<%- data.id %>" class="file-row">
                                <span class="file-info"><%- data.name %> (<%- data.size %>)</span>
                                <div class="progressbar-container">
                                    <div class="progressbar upload-progress" style="width: 0%;"></div>
                                </div>
                                <div class="spinner">
                                    <span></span><span></span><span></span><span></span>
                                    <span></span><span></span><span></span><span></span>
                                </div>
                            </div>
                        </script>

                        <script data-template="gallery-content" type="text/x-magento-template">
                            <div class="image item <% if (data.disabled == 1) { %>hidden-for-front<% } %>"
                                 data-role="image">
                                <input type="hidden"
                                       name="product[media_gallery][images][<%- data.file_id %>][position]"
                                       value="<%- data.position %>" class="position"/>
                                <input type="hidden"
                                       name="product[media_gallery][images][<%- data.file_id %>][file]"
                                       value="<%- data.file %>"/>
                                <input type="hidden"
                                       name="product[media_gallery][images][<%- data.file_id %>][value_id]"
                                       value="<%- data.value_id %>"/>
                                <input type="hidden"
                                       name="product[media_gallery][images][<%- data.file_id %>][label]"
                                       value="<%- data.label %>"/>
                                <input type="hidden"
                                       name="product[media_gallery][images][<%- data.file_id %>][disabled]"
                                       value="<%- data.disabled %>"/>
                                <input type="hidden"
                                       name="product[media_gallery][images][<%- data.file_id %>][removed]"
                                       value=""
                                       class="is-removed"/>
                                <img class="product-image" src="<%- data.url %>" alt="<%- data.label %>"/>

                                <button type="button"
                                        class="action-remove"
                                        data-role="delete-button"
                                        title="<?= $block->escapeHtml(__('Remove image')) ?>">
                                    <span><?= /* @escapeNotVerified */  __('Remove image') ?></span>
                                </button>
                                <div class="draggable-handle"></div>
                                <div class="image-label" title="<?= $block->escapeHtml(__('Edit role')) ?>"></div>
                                <div class="image-fade"><span><?= /* @escapeNotVerified */  __('Hidden') ?></span></div>
                            </div>
                        </script>

                        <script data-template="image" type="text/x-magento-template">
                            <div class="image">
                                <img
                                    class="product-image"
                                    src="<%- data.url %>"
                                    data-position="<%- data.position %>"
                                    alt="<%- data.label %>" />

                                <button type="button"
                                        class="action-remove"
                                        data-role="delete-button"
                                        title="<?= $block->escapeHtml(__('Remove image')) ?>">
                                    <span><?= /* @escapeNotVerified */  __('Remove image') ?></span>
                                </button>
                                <div class="draggable-handle"></div>
                                <div class="image-label" title="<?= $block->escapeHtml(__('Edit role')) ?>"></div>
                                <div class="image-fade"><span><?= /* @escapeNotVerified */  __('Hidden') ?></span></div>
                            </div>
                        </script>

                        <script class="dialog-template" type="text/x-magento-template" data-title="Image Options">
                            <div class="image-panel magetop__scope-old" data-role="dialog">
                                <div class="image-panel-preview">
                                    <img src="<%- data.url %>" alt="<%- data.label %>" />
                                </div>
                                <div class="image-panel-controls">
                                    <strong class="image-name"><%- data.label %></strong>

                                    <fieldset class="magetop__fieldset fieldset-image-panel">
                                        <div class="field field-image-description">
                                            <label class="label" for="image-description">
                                                <span><?= /* @escapeNotVerified */  __('Alt Text') ?></span>
                                            </label>
                                            <div class="control">
                                                <textarea
                                                    id="image-description"
                                                    rows="3"
                                                    name="product[media_gallery][images][<%- data.file_id %>][label]"><%- data.label %></textarea>
                                            </div>
                                        </div>

                                        <div class="field field-image-role">
                                            <label class="label">
                                                <span><?= /* @escapeNotVerified */  __('Role') ?></span>
                                            </label>
                                            <div class="control">
                                                <ul class="multiselect-alt">
                                                    <?php
                                                    foreach ($block->getProConfigMediaAttributes() as $attribute) :
                                                        ?>
                                                        <li class="item">
                                                            <label>
                                                                <input class="image-type"
                                                                       data-role="type-selector"
                                                                       type="checkbox"
                                                                       value="<?php /* @noEscape */ echo $block->escapeHtml(
                                                                           $attribute->getAttributeCode()
                                                                       ) ?>"
                                                                    />
                                                                <?php /* @noEscape */ echo $block->escapeHtml(
                                                                    $attribute->getFrontendLabel()
                                                                ) ?>
                                                            </label>
                                                        </li>
                                                        <?php
                                                    endforeach;
                                                    ?>
                                                </ul>
                                            </div>
                                        </div>

                                        <div class="field field-image-hide">
                                            <label class="label">
                                                <input type="checkbox"
                                                       data-role="visibility-trigger"
                                                       value="1"
                                                       name="product[media_gallery][images][<%- data.file_id %>][disabled]"
                                                       <% if (data.disabled == 1) { %>checked="checked"<% } %> />
                                                <span><?= /* @escapeNotVerified */  __('Hide from Product Page') ?></span>
                                            </label>
                                        </div>
                                    </fieldset>
                                </div>
                            </div>
                        </script>

                    </div>
                </li>
                <!-- /ko -->
            </ul>
        </div>
    </div>
</div>

    <div data-bind="with: sections().price" class="steps-wizard-section">
        <div data-role="section">
            <div class="steps-wizard-section-title">
                <span><?= /* @escapeNotVerified */  __('Price') ?></span>
            </div>
            <ul class="steps-wizard-section-list">
                <li>
                    <div class="magetop__field magetop__field-option">
                        <input type="radio"
                               id="apply-single-price-radio"
                               class="magetop__control-radio"
                               value="single"
                               data-bind="checked:type" />
                        <label for="apply-single-price-radio"
                               class="magetop__field-label">
                            <span><?= /* @escapeNotVerified */  __('Apply single price to all SKUs') ?></span>
                        </label>
                    </div>
                </li>
                <li>
                    <div class="magetop__field magetop__field-option">
                        <input type="radio"
                               id="apply-unique-prices-radio"
                               class="magetop__control-radio"
                               value="each"
                               data-bind="checked:type" />
                        <label for="apply-unique-prices-radio"
                               class="magetop__field-label">
                            <span><?= /* @escapeNotVerified */  __('Apply unique prices by attribute to each SKU') ?></span>
                        </label>
                    </div>
                </li>
                <li>
                    <div class="magetop__field magetop__field-option">
                        <input type="radio"
                               id="skip-pricing-radio"
                               class="magetop__control-radio"
                               value="none"
                               checked
                               data-bind="checked:type" />
                        <label for="skip-pricing-radio" class="magetop__field-label">
                            <span><?= /* @escapeNotVerified */  __('Skip price at this time') ?></span>
                        </label>
                    </div>
                </li>
            </ul>
            <form data-role="attributes-values-form">
            <fieldset class="magetop__fieldset bulk-attribute-values" data-bind="visible: type() == 'single'">
                <div class="magetop__field _required">
                    <label for="apply-single-price-input" class="magetop__field-label">
                        <span><?= /* @escapeNotVerified */  __('Price') ?></span>
                    </label>
                    <div class="magetop__field-control">
                        <div class="currency-addon">
                            <input class="magetop__control-text required-entry validate-zero-or-greater" type="text"
                                   data-bind="value:value, uniqueName: true" id="apply-single-price-input"/>
                            <span class="currency-symbol" data-bind="text:currencySymbol"></span>
                        </div>
                    </div>
                </div>
            </fieldset>
            </form>

            <div data-bind="visible: type() == 'each'">
                <fieldset class="magetop__fieldset bulk-attribute-values">
                    <div class="magetop__field _required">
                        <label for="select-each-price" class="magetop__field-label">
                            <span><?= /* @escapeNotVerified */  __('Select attribute') ?></span>
                        </label>
                        <div class="magetop__field-control">
                            <select id="select-each-price" class="magetop__control-select" data-bind="
                                    options: $parent.attributes,
                                    optionsText: 'label',
                                    value: attribute,
                                    optionsCaption: 'Select'"></select>
                        </div>
                    </div>
                </fieldset>

                <form data-role="attributes-values-form">
                    <fieldset class="magetop__fieldset bulk-attribute-values" data-bind="if:attribute">
                        <!-- ko foreach: attribute().chosen -->
                        <div class="magetop__field _required">
                            <label data-bind="attr: {for: 'apply-single-price-input-' + $index()}" class="magetop__field-label">
                                <span data-bind="text:label"></span>
                            </label>
                            <div class="magetop__field-control">
                                <div class="currency-addon">
                                    <input class="magetop__control-text required-entry validate-zero-or-greater"
                                           type="text"
                                           data-bind="value:sections()[$parent.label], uniqueName: true,
                                           attr: {id: 'apply-single-price-input-' + $index()}"/>
                                    <span class="currency-symbol" data-bind="text:$parent.currencySymbol"></span>
                                </div>
                            </div>
                        </div>
                        <!-- /ko -->
                    </fieldset>
                </form>
            </div>
        </div>
    </div>

    <div data-bind="with: sections().quantity" class="steps-wizard-section">
        <div data-role="section">
            <div class="steps-wizard-section-title">
                <span><?= /* @escapeNotVerified */  __('Quantity') ?></span>
            </div>
            <ul class="steps-wizard-section-list">
                <li>
                    <div class="magetop__field magetop__field-option">
                        <input type="radio"
                               id="apply-single-inventory-radio"
                               class="magetop__control-radio"
                               value="single"
                               data-bind="checked: type" />
                        <label for="apply-single-inventory-radio" class="magetop__field-label">
                            <span><?= /* @escapeNotVerified */  __('Apply single quantity to each SKUs') ?></span>
                        </label>
                    </div>
                </li>
                <li>
                    <div class="magetop__field magetop__field-option">
                        <input type="radio"
                               id="apply-unique-inventory-radio"
                               class="magetop__control-radio"
                               value="each"
                               data-bind="checked: type" />
                        <label for="apply-unique-inventory-radio" class="magetop__field-label">
                            <span><?= /* @escapeNotVerified */  __('Apply unique quantity by attribute to each SKU') ?></span>
                        </label>
                    </div>
                </li>
                <li>
                    <div class="magetop__field magetop__field-option">
                        <input type="radio"
                               id="skip-inventory-radio"
                               class="magetop__control-radio"
                               value="none"
                               checked
                               data-bind="checked: type" />
                        <label for="skip-inventory-radio" class="magetop__field-label">
                            <span><?= /* @escapeNotVerified */  __('Skip quantity at this time') ?></span>
                        </label>
                    </div>
                </li>
            </ul>

            <form data-role="attributes-values-form">
            <fieldset class="magetop__fieldset bulk-attribute-values" data-bind="visible: type() == 'single'">
                <div class="magetop__field _required">
                    <label for="apply-single-inventory-input" class="magetop__field-label">
                        <span><?= /* @escapeNotVerified */  __('Quantity') ?></span>
                    </label>
                    <div class="magetop__field-control">
                        <input type="text"
                               id="apply-single-inventory-input"
                               class="magetop__control-text required-entry validate-zero-or-greater"
                               data-bind="value: value, uniqueName: true" />
                    </div>
                </div>
            </fieldset>
            </form>

            <div data-bind="visible: type() == 'each'">
                <fieldset class="magetop__fieldset bulk-attribute-values">
                    <div class="magetop__field _required">
                        <label for="apply-single-price-input-qty" class="magetop__field-label">
                            <span><?= /* @escapeNotVerified */  __('Select attribute') ?></span>
                        </label>
                        <div class="magetop__field-control">
                            <select id="apply-single-price-input-qty" class="magetop__control-select" data-bind="
                                options: $parent.attributes,
                                optionsText: 'label',
                                value: attribute,
                                optionsCaption: 'Select'"></select>
                        </div>
                    </div>
                </fieldset>
                <form data-role="attributes-values-form">
                <fieldset class="magetop__fieldset bulk-attribute-values" data-bind="if:attribute">
                    <!-- ko foreach: attribute().chosen -->
                    <div class="magetop__field _required">
                        <label data-bind="attr: {for: 'apply-qty-input-' + $index()}" class="magetop__field-label">
                            <span data-bind="text:label"></span>
                        </label>
                        <div class="magetop__field-control">
                            <input id="apply-single-price-input-value"
                                   class="magetop__control-text required-entry validate-zero-or-greater" type="text"
                                   data-bind="value:sections()[$parent.label], uniqueName: true,
                                   attr: {id: 'apply-qty-input-' + $index()}"/>
                        </div>
                    </div>
                    <!-- /ko -->
                </fieldset>
                </form>
            </div>
        </div>
    </div>
</form>
</div>

<script type="text/x-magento-init">
{
    "*": {
        "Magento_Ui/js/core/app": {
            "components": {
                "<?= /* @escapeNotVerified */  $block->getComponentName()?>": {
                    "component": "Magetop_Marketplace/js/variations/steps/bulk",
                    "appendTo": "<?= /* @noEscape */  $block->getParentComponentName()?>",
                    "noImage": "<?= /* @noEscape */  $block->getProItemNoImageUrl() ?>",
                    "variationsComponent": "configurableVariations"
                }
            }
        }
    }
}
</script>
