@model FooterModel

@using Nop.Core
@using Nop.Core.Domain.Tax
@using Nop.Core.Domain.Topics
@using Nop.Services.Configuration;
@using Nop.Services.Localization
@using Nop.Services.Media;

@inject IWorkContext workContext
@inject ILocalizationService localizationService
@inject IPictureService pictureService
@inject IStoreContext storeContext
@inject ISettingService settingService
@inject IThemeContext themeContext

@{
    var themeName = await themeContext.GetWorkingThemeNameAsync();
    var language = await workContext.GetWorkingLanguageAsync();
    var store = await storeContext.GetCurrentStoreAsync();
    var storeName = await localizationService.GetLocalizedAsync(store, s => s.Name);

    var columns = 1;
    var hideDesignedByNopStation = await settingService.GetSettingByKeyAsync<bool>(
        "CarHavenSettings.HideDesignedByNopStationAtFooter", storeId: store.Id,loadSharedValueIfNotFound: true);

    var showSupportedCards = await settingService.GetSettingByKeyAsync<bool>(
        "CarHavenSettings.ShowSupportedCardsAtFooter", storeId: store.Id, loadSharedValueIfNotFound: true);

    var supportedCardsImageUrl = "";
    var pictureId = 0;

    if (hideDesignedByNopStation)
    {
        columns++;
    }

    if (showSupportedCards)
    {
        columns++;

        pictureId = await settingService.GetSettingByKeyAsync<int>("CarHavenSettings.FooterSupportedCardsPictureId",
            storeId: store.Id,
            loadSharedValueIfNotFound: true
        );

        supportedCardsImageUrl = await pictureService.GetPictureUrlAsync(pictureId);
    }

    if (!Model.HidePoweredByNopCommerce)
        columns++;
}

<div class="footer">
    <div class="footer-upper">

        <div class="footer-links">
            <div class="footer-block information">
                <div class="title">
                    <strong>@T("Footer.Information")</strong>
                </div>
                <ul class="list">
                    @if (Model.SitemapEnabled && Model.DisplaySitemapFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("Sitemap")">@T("Sitemap")</a></li>
                    }
                    @foreach (var topic in Model.Topics.Where(x => x.IncludeInFooterColumn1).ToList())
                    {
                        <li><a href="@(Url.RouteUrl<Topic>(new { SeName = topic.SeName }))">@topic.Name</a></li>
                    }
                    @if (Model.DisplayContactUsFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("ContactUs")">@T("ContactUs")</a></li>
                    }
                </ul>
            </div>
            <div class="footer-block customer-service">
                <div class="title">
                    <strong>@T("Footer.CustomerService")</strong>
                </div>
                <ul class="list">
                    @if (Model.SearchEnabled && Model.DisplayProductSearchFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("ProductSearch")">@T("Search")</a> </li>
                    }
                    @if (Model.NewsEnabled && Model.DisplayNewsFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("NewsArchive")">@T("News")</a></li>
                    }
                    @if (Model.BlogEnabled && Model.DisplayBlogFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("Blog")">@T("Blog")</a></li>
                    }
                    @if (Model.ForumEnabled && Model.DisplayForumsFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("Boards")">@T("Forum.Forums")</a></li>
                    }
                    @if (Model.RecentlyViewedProductsEnabled && Model.DisplayRecentlyViewedProductsFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("RecentlyViewedProducts")">@T("Products.RecentlyViewedProducts")</a></li>
                    }
                    @if (Model.CompareProductsEnabled && Model.DisplayCompareProductsFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("CompareProducts")">@T("Products.Compare.List")</a></li>
                    }
                    @if (Model.NewProductsEnabled && Model.DisplayNewProductsFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("NewProducts")">@T("Products.NewProducts")</a></li>
                    }
                    @foreach (var topic in Model.Topics.Where(x => x.IncludeInFooterColumn2).ToList())
                    {
                        <li><a href="@(Url.RouteUrl<Topic>(new { SeName = topic.SeName }))">@topic.Name</a></li>
                    }
                    @if (Model.AllowCustomersToCheckGiftCardBalance)
                    {
                        <li><a href="@Url.RouteUrl("CheckGiftCardBalance")">@T("CheckGiftCardBalance")</a></li>
                    }
                </ul>
            </div>
            <div class="footer-block my-account">
                <div class="title">
                    <strong>@T("Footer.MyAccount")</strong>
                </div>
                <ul class="list">
                    @if (Model.DisplayCustomerInfoFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("CustomerInfo")">@T("Account.MyAccount")</a></li>
                    }
                    @if (Model.DisplayCustomerOrdersFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("CustomerOrders")">@T("Account.CustomerOrders")</a></li>
                    }
                    @if (Model.DisplayCustomerAddressesFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("CustomerAddresses")">@T("Account.CustomerAddresses")</a></li>
                    }
                    @if (Model.ShoppingCartEnabled && Model.DisplayShoppingCartFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("ShoppingCart")">@T("ShoppingCart")</a></li>
                    }
                    @if (Model.WishlistEnabled && Model.DisplayWishlistFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("Wishlist")">@T("Wishlist")</a></li>
                    }
                    @if (Model.AllowCustomersToApplyForVendorAccount && Model.DisplayApplyVendorAccountFooterItem)
                    {
                        <li><a href="@Url.RouteUrl("ApplyVendorAccount")">@T("Vendors.ApplyAccount")</a></li>
                    }
                    @foreach (var topic in Model.Topics.Where(x => x.IncludeInFooterColumn3).ToList())
                    {
                        <li><a href="@(Url.RouteUrl<Topic>(new { SeName = topic.SeName }))">@topic.Name</a></li>
                    }
                </ul>
            </div>
        </div>

        <div class="follow-us">

                @await Component.InvokeAsync(typeof(NewsletterBoxViewComponent))
                <div class="social">
                    <div class="title">
                        <strong>@T("Footer.FollowUs")</strong>
                    </div>
                    @await Component.InvokeAsync(typeof(SocialButtonsViewComponent))
            </div>

            <div class="payment-method">
                @if (showSupportedCards == true)
                {
                    <div class="title">
                        <strong>@T("NopStation.Theme.CarHaven.FooterSupportedCards.Title")</strong>
                    </div>

                    <div class="payment-methods">
                        <img class="payment-method-image" src="@supportedCardsImageUrl" alt="Payment methods" title="Payment methods" />

                    </div>
                    }
            </div>
        </div>
    </div>
    <div class="footer-lower">
        @if (!Model.HidePoweredByNopCommerce)
        {
            <div class="footer-powered-by">
                @*Would you like to remove the "Powered by nopCommerce" link in the bottom of the footer?
                    Please find more info at https://www.nopcommerce.com/nopcommerce-copyright-removal-key*@
                Powered by <a href="@(OfficialSite.Main)" target="_blank" @(Model.IsHomePage ? string.Empty : "rel=nofollow")>nopCommerce</a>
            </div>
        }

        @if (!hideDesignedByNopStation)
        { 
            <div class="footer-powered-by">
                Designed By <img class="nopstation-logo" alt="Designed by nopStation" title="Designed by nopStation" src="/Themes/CarHaven/Content/images/designed-by-nopstation.png" width="98" height="22">
            </div>
        }

        <div class="footer-info">
            <span class="footer-disclaimer">@T("Content.CopyrightNotice", DateTime.Now.Year, Model.StoreName)</span>
            @if (Model.DisplayTaxShippingInfoFooter)
            {
                var inclTax = await workContext.GetTaxDisplayTypeAsync() == TaxDisplayType.IncludingTax;
                <span class="footer-tax-shipping">
                    @T(inclTax ? "Footer.TaxShipping.InclTax" : "Footer.TaxShipping.ExclTax", Url.RouteTopicUrl("shippinginfo"))
                </span>
            }
        </div>
        @await Component.InvokeAsync(typeof(StoreThemeSelectorViewComponent))
    </div>
    @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.Footer, additionalData = Model })
</div>
<script asp-location="Footer">
    $(function() {
        $('.footer-block .title').on('click', function () {
            var e = window, a = 'inner';
            if (!('innerWidth' in window)) {
                a = 'client';
                e = document.documentElement || document.body;
            }
            var result = { width: e[a + 'Width'], height: e[a + 'Height'] };
            if (result.width < 769) {
                $(this).siblings('.list').slideToggle('slow');
            }
        });
    });
</script>
<script asp-location="Footer">
    $(function() {
        $('.block .title').on('click', function () {
            var e = window, a = 'inner';
            if (!('innerWidth' in window)) {
                a = 'client';
                e = document.documentElement || document.body;
            }
            var result = { width: e[a + 'Width'], height: e[a + 'Height'] };
            if (result.width < 1001) {
                $(this).siblings('.listbox').slideToggle('slow');
            }
        });
    });
</script>