@inject INopFileProvider fileProvider;
@inject IWebHelper webHelper
@inject LocalizationSettings localizationSettings
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment WebHostEnvironment
@using Nop.Core.Domain.Localization

@{
    var supportRtl = (await workContext.GetWorkingLanguageAsync()).Rtl && !localizationSettings.IgnoreRtlPropertyForAdminArea;

    var culture = CultureInfo.CurrentCulture;
    var uiCulture = CultureInfo.CurrentUICulture;

    //Code to get check if current cultures scripts are exists. If not, select parent cultures scripts
    string GetDefaultCulture()
    {
        var localePattern = NopCommonDefaults.LocalePatternPath;

        var cultureToUse = NopCommonDefaults.DefaultLocalePattern; //Default regionalisation to use

        if (fileProvider.DirectoryExists(fileProvider.Combine(WebHostEnvironment.WebRootPath, string.Format(localePattern, culture.Name))))
            cultureToUse = culture.Name;
        else if (fileProvider.DirectoryExists(fileProvider.Combine(WebHostEnvironment.WebRootPath, string.Format(localePattern, culture.TwoLetterISOLanguageName))))
            cultureToUse = culture.TwoLetterISOLanguageName;

        return cultureToUse;
    }
}

@*Google Font*@
<!link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic" />

@* CSS resources *@
<link rel="stylesheet" href="~/lib_npm/jquery-ui-dist/jquery-ui.min.css"/>
<link rel="stylesheet" href="~/lib_npm/bootstrap-touchspin/jquery.bootstrap-touchspin.min.css"/>
<link rel="stylesheet" href="~/lib_npm/@("@fortawesome")/fontawesome-free/css/all.min.css"/>
<link rel="stylesheet" href="~/lib_npm/datatables.net-bs4/css/dataTables.bootstrap4.min.css"/>
<link rel="stylesheet" href="~/lib_npm/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css"/>
<link rel="stylesheet" href="~/lib_npm/overlayscrollbars/styles/overlayscrollbars.min.css" />

@if (supportRtl)
{
    <link rel="stylesheet" href="~/lib_npm/@("@laylazi")/bootstrap-rtl/css/bootstrap-rtl.min.css"/>
    <link rel="stylesheet" href="~/lib/adminLTE/css/adminlte-rtl.min.css"/>
    <link rel="stylesheet" href="~/css/admin/styles.rtl.css"/>
}
else
{
    <link rel="stylesheet" href="~/lib_npm/admin-lte/css/adminlte.min.css"/>
    <link rel="stylesheet" href="~/css/admin/styles.css"/>
}

<link rel="stylesheet" href="~/lib_npm/admin-lte/plugins/select2/css/select2.min.css">

@NopHtml.GenerateCssFiles()

@* scripts *@
<script asp-location="None" src="~/lib_npm/jquery/jquery.min.js"></script>
<script src="~/lib_npm/jquery-ui-dist/jquery-ui.min.js"></script>
<script src="~/lib_npm/admin-lte/js/adminlte.min.js"></script>
<script src="~/lib_npm/overlayscrollbars/browser/overlayscrollbars.browser.es6.min.js"></script>
<script src="~/lib_npm/bootstrap-touchspin/jquery.bootstrap-touchspin.min.js"></script>
<script src="~/lib_npm/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/lib_npm/jquery-validation/jquery.validate.min.js"></script>
<script src="~/lib_npm/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
<script src="~/lib_npm/admin-lte/plugins/select2/js/select2.full.min.js"></script>

@* cldr scripts (needed for globalize) *@
<script src="~/lib_npm/cldrjs/cldr.js"></script>
<script src="~/lib_npm/cldrjs/cldr/event.js"></script>
<script src="~/lib_npm/cldrjs/cldr/supplemental.js"></script>

@* globalize scripts *@
<script src="~/lib_npm/globalize/globalize.js"></script>
<script src="~/lib_npm/globalize/globalize/number.js"></script>
<script src="~/lib_npm/globalize/globalize/date.js"></script>
<script src="~/lib_npm/globalize/globalize/currency.js"></script>

<script src="~/lib_npm/jquery-migrate/jquery-migrate.min.js"></script>
<script src="~/lib_npm/typeahead.js/typeahead.bundle.min.js"></script>
<script src="~/js/admin.common.js"></script>
<script src="~/js/admin.navigation.js"></script>
<script src="~/js/admin.search.js"></script>

<script src="~/lib_npm/datatables.net/js/dataTables.min.js"></script>
<script src="~/lib_npm/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="~/lib_npm/moment/min/moment-with-locales.min.js"></script>
<script src="~/lib_npm/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
<script src="~/lib_npm/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js"></script>
<script asp-location="Footer">
        var rootAppPath = '@(Url.Content("~/"))';
        var culture = "@GetDefaultCulture()";

        //load cldr for current culture
        $.when(
            $.get({ url: rootAppPath + "lib_npm/cldr-data/supplemental/likelySubtags.json", dataType: "json"}),
            $.get({ url: rootAppPath + "lib_npm/cldr-data/main/" + culture + "/numbers.json", dataType: "json"}),
            $.get({ url: rootAppPath + "lib_npm/cldr-data/main/" + culture + "/currencies.json", dataType: "json"}),
            $.get({ url: rootAppPath + "lib_npm/cldr-data/supplemental/numberingSystems.json", dataType: "json"}),
            $.get({ url: rootAppPath + "lib_npm/cldr-data/main/" + culture + "/ca-gregorian.json", dataType: "json"}),
            $.get({ url: rootAppPath + "lib_npm/cldr-data/main/" + culture + "/timeZoneNames.json", dataType: "json"}),
            $.get({ url: rootAppPath + "lib_npm/cldr-data/supplemental/timeData.json", dataType: "json"}),
            $.get({ url: rootAppPath + "lib_npm/cldr-data/supplemental/weekData.json", dataType: "json"}),
        ).then(function () {
            // Normalize $.get results, we only need the JSON, not the request statuses.
            return [].slice.apply(arguments, [0]).map(function (result) {
                return result[0];
            });
        }).then(Globalize.load).then(function () {
            Globalize.locale(culture);
        });
</script>

@NopHtml.GenerateScripts(ResourceLocation.Head)
@NopHtml.GenerateInlineScripts(ResourceLocation.Head)