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

/** @var $block \Magento\Catalog\Block\Adminhtml\Product\Grid */
?>
<div id="<?= /* @noEscape */ $block->getHtmlId() ?>" class="admin__grid-massaction">
    <?php if ($block->getHideFormElement() !== true) :?>
    <form action="" id="<?= /* @noEscape */ $block->getHtmlId() ?>-form" method="post">
    <?php endif ?>
        <div class="admin__grid-massaction-form">
            <?= $block->getBlockHtml('formkey') ?>
            <select
                id="<?= /* @noEscape */ $block->getHtmlId() ?>-select"
                class="local-validation admin__control-select">
                <option class="admin__control-select-placeholder" value="" selected><?= $block->escapeHtml(__('Actions')) ?></option>
                <?php foreach ($block->getItems() as $_item) :?>
                    <option value="<?= $block->escapeHtmlAttr($_item->getId()) ?>"<?= ($_item->getSelected() ? ' selected="selected"' : '') ?>><?= $block->escapeHtml($_item->getLabel()) ?></option>
                <?php endforeach; ?>
            </select>
            <span class="outer-span" id="<?= /* @noEscape */ $block->getHtmlId() ?>-form-hiddens"></span>
            <span class="outer-span" id="<?= /* @noEscape */ $block->getHtmlId() ?>-form-additional"></span>
            <?= $block->getApplyButtonHtml() ?>
        </div>
    <?php if ($block->getHideFormElement() !== true) :?>
    </form>
    <?php endif ?>
    <div class="no-display">
    <?php foreach ($block->getItems() as $_item) :?>
        <div id="<?= /* @noEscape */ $block->getHtmlId() ?>-item-<?= $block->escapeHtmlAttr($_item->getId()) ?>-block">
            <?= $_item->getAdditionalActionBlockHtml() ?>
        </div>
    <?php endforeach; ?>
    </div>

    <div class="mass-select-wrap">
        <select id="<?= /* @noEscape */ $block->getHtmlId() ?>-mass-select" data-menu="grid-mass-select">
            <optgroup label="<?= $block->escapeHtmlAttr(__('Mass Actions')) ?>">
                <option disabled selected></option>
                <?php if ($block->getUseSelectAll()) :?>
                    <option value="selectAll">
                        <?= $block->escapeHtml(__('Select All')) ?>
                    </option>
                    <option value="unselectAll">
                        <?= $block->escapeHtml(__('Unselect All')) ?>
                    </option>
                <?php endif; ?>
                <option value="selectVisible">
                    <?= $block->escapeHtml(__('Select Visible')) ?>
                </option>
                <option value="unselectVisible">
                    <?= $block->escapeHtml(__('Unselect Visible')) ?>
                </option>
            </optgroup>
        </select>
        <label for="<?= /* @noEscape */ $block->getHtmlId() ?>-mass-select"></label>
    </div>

<script>
    require(['jquery'], function($){
        'use strict';
        $('#<?= /* @noEscape */ $block->getHtmlId() ?>-mass-select').change(function () {
            var massAction = $('option:selected', this).val();
            switch (massAction) {
                <?php if ($block->getUseSelectAll()) :?>
                case 'selectAll':
                    return <?= $block->escapeJs($block->getJsObjectName()) ?>.selectAll();
                    break
                case 'unselectAll':
                    return <?= $block->escapeJs($block->getJsObjectName()) ?>.unselectAll();
                    break
                <?php endif; ?>
                case 'selectVisible':
                    return <?= $block->escapeJs($block->getJsObjectName()) ?>.selectVisible();
                    break
                case 'unselectVisible':
                    return <?= $block->escapeJs($block->getJsObjectName()) ?>.unselectVisible();
                    break
            }
            this.blur();
        });

    });

    <?php if (!$block->getParentBlock()->canDisplayContainer()) :?>
        <?= $block->escapeJs($block->getJsObjectName())  ?>.setGridIds('<?= /* @noEscape */ $block->getGridIdsJson() ?>');
    <?php endif; ?>
</script>
</div>
