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

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Language switcher template
 */
?>
<?php 
	$themeSettingConfig = $this->helper('MGS\ThemeSettings\Helper\Config');
	$imgLanguage = $themeSettingConfig->getStoreConfig('themesettings/header/img_language');		
?>
<?php if (count($block->getStores())>1): ?>
<?php $id = $block->getIdModifier() ? '-' . $block->getIdModifier() : ''?>
<div class="switcher language switcher-language <?php if($imgLanguage):?> img_language <?php endif;?>" data-ui-id="language-switcher" id="switcher-language<?php /* @escapeNotVerified */ echo $id?>">
    <strong class="label switcher-label"><span><?php /* @escapeNotVerified */ echo __('Language') ?></span></strong>
    <div class="actions dropdown options switcher-options">
        <div class="action toggle switcher-trigger" id="switcher-language-trigger<?php /* @escapeNotVerified */ echo $id?>">
			
            <strong class="view-<?= $block->escapeHtml($block->getCurrentStoreCode()) ?>">
            <?php $path = 'Magento_Store::images/flags/' . $block->getCurrentStoreCode() .  '.png' ?>
				<?php if($imgLanguage):?>
					<img class="img-flag" src="<?php echo $this->getViewFileUrl($path); ?>"/>
				<?php endif ?>
                <span><?= $block->escapeHtml($block->getStoreName()) ?></span>
            </strong>
        </div>
        <ul class="dropdown switcher-dropdown"
            data-mage-init='{"dropdownDialog":{
                "appendTo":"#switcher-language<?php /* @escapeNotVerified */ echo $id ?> > .options",
                "triggerTarget":"#switcher-language-trigger<?php /* @escapeNotVerified */ echo $id ?>",
                "closeOnMouseLeave": false,
                "triggerClass":"active",
                "parentClass":"active",
                "buttons":null}}'>
            <?php foreach ($block->getStores() as $_lang): ?>
                <?php if ($_lang->getId() != $block->getCurrentStoreId()): ?>
                    <li class="view-<?= $block->escapeHtml($_lang->getCode()); ?> switcher-option">
                        <?php $path = 'Magento_Store::images/flags/' . $block->escapeHtml($_lang->getCode()) .  '.png' ?>
                        <a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getTargetStorePostData($_lang); ?>'>
                            <?php if($imgLanguage):?>
								<img class="img-flag" src="<?php echo $this->getViewFileUrl($path); ?>"/>
							<?php endif ?>
                            <?= $block->escapeHtml($_lang->getName()) ?></a>
                    </li>
                <?php endif; ?>
            <?php endforeach; ?>
        </ul>
    </div>
</div>
<?php endif; ?>
