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

// @codingStandardsIgnoreFile

?>
<?php
/**
 * @see \Magento\Backend\Block\Store\Switcher
 */

/**
 * @var $block \Magento\Backend\Block\Store\Switcher
 */
?>

<?php if ($block->isShow()): ?>
<div class="field field-store-switcher">
    <label class="label" for="store_switcher"><?php /* @escapeNotVerified */ echo __('Show Report For:') ?></label>
    <div class="control">
        <select 
            id="store_switcher"
            class="admin__control-select"
            name="store_switcher"
            onchange="return switchStore(this);">
            <option value=""><?php /* @escapeNotVerified */ echo __('All Websites') ?></option>
            <?php foreach ($block->getWebsiteCollection() as $_website): ?>
                <?php $showWebsite = false; ?>
                <?php foreach ($block->getGroupCollection($_website) as $_group): ?>
                    <?php $showGroup = false; ?>
                    <?php foreach ($block->getStoreCollection($_group) as $_store): ?>
                        <?php if ($showWebsite == false): ?>
                            <?php $showWebsite = true; ?>
                            <option website="true" value="<?php /* @escapeNotVerified */ echo implode(',', $_website->getStoreIds()) ?>"<?php if ($block->getRequest()->getParam('store_ids') == implode(',', $_website->getStoreIds())): ?> selected<?php endif; ?>><?php echo $block->escapeHtml($_website->getName()) ?></option>
                        <?php endif; ?>
                        <?php if ($showGroup == false): ?>
                            <?php $showGroup = true; ?>
                            <option group="true" value="<?php /* @escapeNotVerified */ echo implode(',', $_group->getStoreIds()) ?>"<?php if ($block->getRequest()->getParam('store_ids') == implode(',', $_group->getStoreIds())): ?> selected<?php endif; ?>>&nbsp;&nbsp;&nbsp;<?php echo $block->escapeHtml($_group->getName()) ?></option>
                        <?php endif; ?>
                        <option value="<?php /* @escapeNotVerified */ echo $_store->getId() ?>"<?php if ($block->getStoreId() == $_store->getId()): ?> selected<?php endif; ?>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $block->escapeHtml($_store->getName()) ?></option>
                    <?php endforeach; ?>
                    <?php if ($showGroup): ?>
                        </optgroup>
                    <?php endif; ?>
                <?php endforeach; ?>
            <?php endforeach; ?>
        </select>
    </div>
    <?php echo $block->getHintHtml() ?>
</div>
<script>
require(['prototype'], function(){

    switchStore = function(obj){
        var storeParam = obj.value ? 'store_ids/' + obj.value + '/' : '';
        if(obj.switchParams){
            storeParam+= obj.switchParams;
        }
        setLocation('<?php /* @escapeNotVerified */ echo $block->getSwitchUrl() ?>'+storeParam);
    }

});
</script>
<?php endif; ?>
