@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@using Dynamicweb.Frontend
@using Dynamicweb.Frontend.Navigation
@{
	var currency = Dynamicweb.Ecommerce.Services.Currencies.GetCurrency(Pageview?.Area?.EcomCurrencyId ?? string.Empty) ?? null;

	string? toggleIcon = null;
	if (!(Model.Item?.GetBoolean("HideLanguageFlag") ?? false)) 
	{
		toggleIcon = $"/Files/Images/Icons/Flags/{Pageview?.Area?.CultureInfo?.Name}.svg";
	}
	if ((Model.Item?.TryGetString("Icon", out var icon) ?? false) && (Model.Item?.GetBoolean("HideLanguageFlag") ?? false))
	{
		toggleIcon = icon;
	}
}

<div class="nav-wrapper">
	<button type="button" class="nav-link hstack p-2 gap-2 text-nowrap text-decoration-underline-hover"
		hx-get
		hx-vals='{"LayoutTemplate": "/Designs/Swift-v2/Paragraph/Swift-v2_LanguageSelector/Modals/LanguageModal.cshtml"}'
		hx-target="main"
		hx-swap="beforeend">
		@if (!string.IsNullOrEmpty(toggleIcon) && toggleIcon.EndsWith(".svg", StringComparison.OrdinalIgnoreCase))
		{
			<span class="icon-3 pe-none">@ReadFile(toggleIcon)</span>
		}
		@if (Model.Item?.GetBoolean("ShowLanguageName") ?? false) 
		{
			if (Model.Item?.TryGetString("LanguageNameFormat", out var languageNameFormat) ?? false)
			{
				if (languageNameFormat == "short")
				{
					<span>@(Pageview?.Area?.CultureInfo?.TwoLetterISOLanguageName)</span>
				}
				else
				{
					<span>@(Pageview?.Area?.CultureInfo?.NativeName)</span>
				}
			}
		}
		@if ((Model.Item?.TryGetString("Label", out var label) ?? false) && !(Model.Item?.GetBoolean("ShowLanguageName") ?? false))
		{
			<span>@(label)</span>
		}
		
		@if (Model.Item?.GetBoolean("ShowLanguageCurrency") ?? false) 
		{
			<span class="vr"></span>
			<span class="text-uppercase text-muted">@(currency?.Symbol)</span>
		}
	</button>
</div>