@using Microsoft.AspNetCore.Components.Web
@using Moonlight.App.Extensions
@using Moonlight.App.Repositories
@using Moonlight.App.Services
@using Moonlight.App.Services.Sessions
@namespace Moonlight.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@inject ConfigService ConfigService
@inject BundleService BundleService
@inject LoadingMessageRepository LoadingMessageRepository

@{
    var headerConfig = ConfigService
        .GetSection("Moonlight")
        .GetSection("Html")
        .GetSection("Headers");

    var moonlightConfig = ConfigService
        .GetSection("Moonlight");
}

<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
    <meta charset="utf-8"/>

    <meta property="og:locale" content="de_DE"/>
    <meta property="og:type" content="article"/>
    <meta content="@(headerConfig.GetValue<string>("Title"))" property="og:title"/>
    <meta content="@(headerConfig.GetValue<string>("Description"))" property="og:description"/>
    <meta content="@(moonlightConfig.GetValue<string>("AppUrl"))" property="og:url"/>
    <meta content="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logolong.png" property="og:image"/>
    <meta content="@(headerConfig.GetValue<string>("Color"))" data-react-helmet="true" name="theme-color"/>

    <meta content="@(headerConfig.GetValue<string>("Description"))" name="description"/>
    <meta content="@(headerConfig.GetValue<string>("Keywords"))" name="keywords"/>

    <link rel="shortcut icon" href="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logo.svg"/>

    @*This import is not in the bundle because the files it references are linked relative to the current lath*@
    <link rel="stylesheet" type="text/css" href="/assets/css/boxicons.min.css"/>
    
    @if (BundleService.BundledFinished)
    {
        <link rel="stylesheet" type="text/css" href="/api/moonlight/resources/bundle/css?idontwannabecached=@(BundleService.CacheId)"/>
    }
    else
    {
        foreach (var cssFile in BundleService.CssFiles)
        {
            if (cssFile.StartsWith("http"))
            {
                <link rel="stylesheet" type="text/css" href="@(cssFile)">
            }
            else
            {
                <style>
                    @cssFile
                </style>
            }
        }
    }

    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <base href="~/"/>
    <component type="typeof(HeadOutlet)" render-mode="ServerPrerendered"/>

    <title>Loading</title>
</head>
<body
    class="app-default"
    cz-shortcut-listen="true"
    data-kt-app-layout="dark-sidebar"
    data-kt-app-header-fixed="true"
    data-kt-app-sidebar-fixed="true"
    data-kt-app-sidebar-hoverable="true"
    data-kt-app-sidebar-push-header="true"
    data-kt-app-sidebar-push-toolbar="true"
    data-kt-app-sidebar-push-footer="true"
    data-kt-app-toolbar-enabled="true">

@RenderBody()

<div id="flashbang" class="flashbanglight"></div>

<div class="app-page-loader flex-column">
    <img alt="Logo" src="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logo.svg" class="h-25px"/>

    @{
        string loadingMessage;

        try
        {
            loadingMessage = LoadingMessageRepository.Get().Random().Message;
        }
        catch (Exception)
        {
            loadingMessage = "";
        }
    }

    <div class="d-flex align-items-center mt-5">
        <span class="spinner-border text-primary" role="status"></span>
        <span class="text-muted fs-6 fw-semibold ms-5">@(loadingMessage)</span>
    </div>
</div>

@if (BundleService.BundledFinished)
{
    <script src="/api/moonlight/resources/bundle/js?idontwannabecached=@(BundleService.CacheId)">
    </script>
}
else
{
    foreach (var jsFile in BundleService.JsFiles)
    {
        if (jsFile.StartsWith("http"))
        {
            <script src="@(jsFile)"></script>
        }
        else
        {
            @Html.Raw("<script>" + jsFile +"</script>")
        }
    }
}
</body>
</html>