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

// @codingStandardsIgnoreFile

/** @var Switcher $block */

use Magento\Store\Block\Switcher;

if ( count($block->getStores()) > 1):
	$id = $block->getIdModifier() ? '-' . $block->getIdModifier() : '';
	$_current = null;
	foreach ($block->getStores() as $_lang) {
		if ($_lang->getId() == $block->getCurrentStoreId()) {
			$_current = $_lang;
			break;
		}
	}
?>
<div class="switcher language switcher-language switcher-hover ox-move-item ox-move-item-store.settings tiny-arrow tiny-drop" data-ui-id="language-switcher" id="switcher-language<?= $block->escapeHtmlAttr($id) ?>">
    <strong class="label switcher-label"><span><?= $block->escapeHtml(__('Language')) ?></span></strong>
    <div class="actions dropdown options switcher-options">
        <div class="action toggle switcher-trigger"
             id="switcher-language-trigger<?= $block->escapeHtmlAttr($id) ?>"
             data-mage-init='{"dropdown":{"autoclose":"false"}}'
             data-toggle="dropdown"
             data-trigger-keypress-button="true">
             <strong class="view-<?= $block->escapeHtml($block->getCurrentStoreCode()) ?>">
                <img class="flag-image" src="<?= $block->escapeUrl($block->getViewFileUrl('images/flags/' . $_current->getCode() . '.png')) ?>" width="16px" height="12px" alt="<?= $block->escapeHtmlAttr($_current->getName()) ?>" />
                <span class="flag-name"><?= $block->escapeHtml($_current->getName()) ?></span>
            </strong>
        </div>
        <ul class="dropdown switcher-dropdown"
            data-target="dropdown">
            <?php foreach ($block->getStores() as $_lang): ?>
                <?php if ($_lang->getId() != $block->getCurrentStoreId()): ?>
                    <li class="view-<?= $block->escapeHtml($_lang->getCode()) ?> switcher-option">
                        <a href="<?= $block->escapeUrl($block->getViewModel()->getTargetStoreRedirectUrl($_lang)) ?>">
                            <img class="flag-image" src="<?= $block->escapeUrl($block->getViewFileUrl('images/flags/' . $_lang->getCode() . '.png')) ?>" width="16px" height="12px" alt="<?= $block->escapeHtmlAttr($_lang->getName()) ?>" />
                            <span class="flag-name"><?= $block->escapeHtml($_lang->getName()) ?></span>
                        </a>
                    </li>
                <?php endif; ?>
            <?php endforeach; ?>
        </ul>
    </div>
</div>
<?php endif; ?>
