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

// @codingStandardsIgnoreFile

?>
<div id="<?php echo $block->getHtmlId() ?>" class="admin__grid-massaction">

    <?php if ($block->getHideFormElement() !== true):?>
    <form action="" id="<?php echo $block->getHtmlId() ?>-form" method="post">
    <?php endif ?>
        <div class="admin__grid-massaction-form">
        <?php echo $block->getBlockHtml('formkey')?>
            <select
                id="<?php echo $block->getHtmlId() ?>-select"
                class="required-entry local-validation admin__control-select">
                <option class="admin__control-select-placeholder" value="" selected><?php /* @escapeNotVerified */ echo __('Actions') ?></option>
                <?php foreach ($block->getItems() as $_item): ?>
                    <option value="<?php /* @escapeNotVerified */ echo $_item->getId() ?>"<?php echo($_item->getSelected() ? ' selected="selected"' : '')?>><?php /* @escapeNotVerified */ echo $_item->getLabel() ?></option>
                <?php endforeach; ?>
            </select>
            <span class="outer-span" id="<?php echo $block->getHtmlId() ?>-form-hiddens"></span>
            <span class="outer-span" id="<?php echo $block->getHtmlId() ?>-form-additional"></span>
            <?php echo $block->getApplyButtonHtml() ?>
        </div>
    <?php if ($block->getHideFormElement() !== true):?>
    </form>
    <?php endif ?>
    <div class="no-display">
        <?php foreach ($block->getItems() as $_item): ?>
            <div id="<?php echo $block->getHtmlId() ?>-item-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-block">
                <?php echo $_item->getAdditionalActionBlockHtml() ?>
            </div>
        <?php endforeach; ?>
    </div>
    <div class="mass-select-wrap">
        <select
            id="<?php echo $block->getHtmlId() ?>-mass-select"
            class="action-select-multiselect"
            data-menu="grid-mass-select">
            <optgroup label="<?php /* @escapeNotVerified */ echo __('Mass Actions')?>">
                <option disabled selected></option>
            <?php if ($block->getUseSelectAll()):?>
                <option value="selectAll">
                    <?php /* @escapeNotVerified */ echo __('Select All') ?>
                </option>
                <option value="unselectAll">
                    <?php /* @escapeNotVerified */ echo __('Unselect All') ?>
                </option>
            <?php endif; ?>
                <option value="selectVisible">
                    <?php /* @escapeNotVerified */ echo __('Select Visible') ?>
                </option>
                <option value="unselectVisible">
                    <?php /* @escapeNotVerified */ echo __('Unselect Visible') ?>
                </option>
            </optgroup>
        </select>
        <label for="<?php echo $block->getHtmlId() ?>-mass-select"></label>
    </div>
<script>
    require(['jquery'], function($){
        'use strict';
        $('#<?php echo $block->getHtmlId() ?>-mass-select').change(function () {
            var massAction = $('option:selected', this).val();
            switch (massAction) {
                <?php if ($block->getUseSelectAll()):?>
                case 'selectAll':
                    return <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.selectAll();
                    break;
                case 'unselectAll':
                    return <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.unselectAll();
                    break;
                <?php endif; ?>
                case 'selectVisible':
                    return <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.selectVisible();
                    break;
                case 'unselectVisible':
                    return <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.unselectVisible();
                    break;
            }
            this.blur();
        });
    });

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