{:*
    Generic and theme snippets
*:}

{:*
    For use in conjunction with "allow" and contains the accepted languages
*:}
{:declare; lang-accept >>
    en
    es
    fr
    de
:}

{:*
    One of the accepted languages or “english”.
*:}
{:snippet; lang >>
    {:allow;
        {:flg; replace :} lang-accept >> {:lang;:}
    :}{:else;
        en
    :}
:}

{:*
    Available themes, obtained from the schema.
    Here the {:;:} before {:;theme:} is NECESSARY to leave at least one space between words.
*:}
{:declare; themes >>
    {:each; site->themes key theme >>
        {:;:} {:;theme:}
    :}
:}

{:*
    Prevent the theme variable from containing anything other than an available theme.
*:}
{:snippet; current-theme >>
    {:allow; themes >>
        {:;site->theme:}
    :}{:else;
        {:;site->themes->0:}
    :}
:}

{:*
    This kind of tasks are more efficient in javascript, just as an example.
*:}
{:snippet; check-{:snippet; lang :} >> ✔ :}

{:snippet; active-{:snippet; current-theme :} >>
    active
:}

{:*
    Cookies for user preferences
*:}
{:snippet; set-cookies >>
        {:^;:} {:* <-- unnecessary, just for nice output *:}
        <script>
            document.cookie = "theme={:snippet; current-theme :}; path=/";
            document.cookie = "lang={:snippet; lang :}; path=/";
        </script>
:}

{:*
    Default contents
*:}
{:snippet; theme-contents >>

:}

{:*
    Default foofer
*:}
{:snippet; theme-footer >>
            {:^;:} {:* <-- unnecessary, just for nice output *:}
            <footer id="footer">
                <div class="row">
                    <div class="col-lg-12">
                        <ul class="list-unstyled">
                            <li class="float-end"><a href="#top">Back to top</a></li>
                            <li>Neutral TS</li>
                            <li><a href="https://docs.rs/neutralts/0.0.0-dev/neutralts/">Docs</a></li>
                            <li><a href="https://crates.io/crates/neutralts">Rust</a></li>
                            <li><a href="https://gitlab.com/neutralfw/neutralts">Repository</a></li>
                        </ul>
                        <p>Themes from   <a href="https://bootswatch.com/">Bootswatch</a> and <a href="https://getbootstrap.com/" rel="nofollow">Bootstrap</a>.</p>
                    </div>
                </div>
            </footer>
:}

{:*
    CSS theme from: https://bootswatch.com/
*:}
{:snippet; current-css-theme >>
        {:^;:} {:* <-- unnecessary, just for nice output *:}
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/5.3.3/{:snippet; current-theme :}/bootstrap.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
:}

{:*
    JS theme from: https://getbootstrap.com/
*:}
{:snippet; current-js-theme >>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.bundle.min.js" integrity="sha512-7Pi/otdlbbCR+LnW+F7PwFcSDJOuUJB3OxtEHbg4vSMvzvJjde4Po1v4BR9Gdc9aXNUNFVUY+SK51wWT8WF0Gg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
:}

{:*
    https://highlightjs.org/
*:}
{:snippet; highlight-js >>
    {:moveto; </head >>
        {:^;:} {:* <-- unnecessary, just for nice output *:}
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/default.min.css" integrity="sha512-hasIneQUHlh06VNBe7f6ZcHmeRTLIaQWFd43YriJ0UND19bvYRauxthDg8E4eVNPm9bRUhr5JGeqH7FRFXQu5g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    {:;:} {:* <-- unnecessary, just for nice output *:}
    :}
    {:moveto; </body >>
        {:^;:} {:* <-- unnecessary, just for nice output *:}
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js" integrity="sha512-EBLzUL8XLl+va/zAsmXwS7Z2B1F9HUHkZwyS/VKwh3S7T/U0nF4BaU29EP/ZSf6zgiIxYAnKLu6bJ8dqpmX5uw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
        <script>hljs.highlightAll();</script>
    {:;:} {:* <-- unnecessary, just for nice output *:}
    :}
:}

{:*
    Custom CSS from: https://bootswatch.com/
*:}
{:snippet; bootswatch-css-custom >>
        {:^;:} {:* <-- unnecessary, just for nice output *:}
        <style>
            {:include; {:flg; noparse :} >> #/../css/custom.bootswatch.min.css :}
        </style>
:}

{:*
    CSS with neutral vars.
*:}
{:snippet; dynamic-css >>
        {:^;:} {:* <-- unnecessary, just for nice output *:}
        <style>
            {:include; #/../css/dynamic.css :}
        </style>
:}

{:*
    JS with neutral vars.
*:}
{:snippet; dynamic-js >>
        {:^;:} {:* <-- unnecessary, just for nice output *:}
        <script>
            {:include; #/../js/dynamic.js :}
        </script>
:}

{:declare; fw-theme-supported >>
    actix-web
    rocket
    warp
    php
:}

{:declare; fw-lang-supported >>
    actix-web
    rocket
    warp
    php
:}

{:*
    Main navigation bar
*:}
{:snippet; theme-navbar >>
        {:^;:} {:* <-- unnecessary, just for nice output *:}
        <nav class="px-md-2 navbar navbar-expand-lg fixed-top bg-primary" data-bs-theme="dark">
            <div class="container-fluid">
                <a class="navbar-brand" href="/">{:;site->name:}</a>
                <button class="navbar-toggler collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse" id="navbarColor01" style="">
                    <ul class="navbar-nav me-auto">
                        <li class="nav-item">
                            <a class="nav-link" href="/">{:trans; Home :}</a>
                        </li>
                        {:snippet; menu-error :}
                        {:snippet; menu-themes :}
                    </ul>
                    <ul class="d-flex navbar-nav ms-md-auto">
                        {:snippet; menu-lang :}
                    </ul>
                </div>
            </div>
        </nav>
:}

{:snippet; menu-themes >>
    {:eval; {:allow; fw-theme-supported >> {:;current-fw:} :} >>
                        <li class="nav-item dropdown" data-bs-theme="light">
                            <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" id="themes" aria-expanded="false">{:trans; Theme :} ({:snippet; current-theme :})</a>
                            <div class="dropdown-menu" aria-labelledby="themes">
                            {:each; site->themes key theme >>
                                {:^;:} {:* <-- unnecessary, just for nice output *:}
                                <a class="dropdown-item {:snippet; active-{:;theme:} :}" href="?theme={:;theme:}">{:;theme:} ({:;key:})</a>
                            :}
                            </div>
                        </li>
    :}
:}

{:snippet; menu-lang >>
    {:eval; {:allow; fw-lang-supported >> {:;current-fw:} :} >>
                        <li class="nav-item dropdown" data-bs-theme="light">
                            <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" id="language">{:trans; Language :}</a>
                            <div class="dropdown-menu dropdown-menu-end">
                            {:each; site->languages key lang >>
                                {:^;:} {:* <-- unnecessary, just for nice output *:}
                                <a class="dropdown-item" href="?lang={:;lang:}">{:trans; ref-locale-{:;lang:} :} {:snippet; check-{:;lang:} :}</a>
                            :}
                            </div>
                        </li>
    :}
:}

{:snippet; menu-error >>
                        <li class="nav-item dropdown" data-bs-theme="light">
                            <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" id="language">{:trans; Error :}</a>
                            <div class="dropdown-menu dropdown-menu">
                                <a class="dropdown-item" href="/?theme=fake">403</a>
                                <a class="dropdown-item" href="/non-existent-page">404</a>
                            </div>
                        </li>
:}