{:* Neutral TS - License in the terms described in the LICENSE file. *:}

{:*
    Snippets that depend on the APP
    -------------------------------

    You may wish to consult the following documentation:

    {:;:} (unprintable)  https://docs.rs/neutralts/latest/neutralts/doc/index.html#-unprintable
    {:; … :} (var)       https://docs.rs/neutralts/latest/neutralts/doc/index.html#---var
    {:declare; … :}      https://docs.rs/neutralts/latest/neutralts/doc/index.html#declare--
    {:allow; … :}        https://docs.rs/neutralts/latest/neutralts/doc/index.html#allow--
    {:snippet; … :}      https://docs.rs/neutralts/latest/neutralts/doc/index.html#snippet--
*:}

{:*
    Avoid arbitrary routes.
    In the schema we have defined the routes as follows:

    {
      "data": {
        "site": {
            "validRoutes": [
                "home",
                "login",
                "logout",
                "help",
                "error"
            ]
        }
    }

    The {:;:} is NECESSARY to leave at least one space between words.
*:}
{:declare; valid-routes >>
    {:each; site->validRoutes none route >>
        {:;:} {:;route:}
    :}
:}

{:*
    Avoid arbitrary themes.
*:}
{:declare; valid-themes >>
    {:each; site->validThemes none theme >>
        {:;:} {:;theme:}
    :}
:}

{:*
    Avoid arbitrary navbar.
*:}
{:declare; valid-navbar >>
    {:each; site->navbarColors key color >>
        {:;:} {:;key:}
    :}
:}

{:*
    Avoid arbitrary langs.
*:}
{:declare; valid-langs >>
    {:each; site->languages none lang >>
        {:;:} {:;lang:}
    :}
:}

{:*
    We check the path, if it fails it will be an empty string, then
    we will check if this snippet is empty and act accordingly.
*:}
{:snippet; route >>
    {:allow; valid-routes >> {:;route:} :}
:}

{:*
    We check the user's language, if it is not in the list, english.
*:}
{:snippet; lang >>
    {:allow; valid-langs >> {:lang;:} :}{:else; en :}
:}

{:*
    To simplify this example, we create the user preference cookies with JavaScript.
*:}
{:snippet; set-cookies >>
    {:^;:}
    <script>
        document.cookie = "theme={:snippet; theme :}; path=/";
        document.cookie = "navbar={:snippet; navbar :}; path=/";
        document.cookie = "lang={:snippet; lang :}; path=/";
    </script>
:}
