<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ .title }}</title>
    {{template "head" .}}
</head>
<body>
{{template "toasts" .}}
{{template "navbar" .}}

<div class="position-absolute top-50 start-50 translate-middle">
    <div class="fs-3">{{ .title }}</div>
    <hr>
    {{template "userForm" .}}
    <a class="link-secondary" href="/view/register">Register instead</a>
</div>

{{template "scripts" .}}
{{template "formScripts" .}}
<script>
    userLoggedIn().then((loggedIn) => loggedIn && redirect("/"));

    function submitForm(formData) {
        axios({method: 'POST', url: '/auth/login', data: formData})
            .then((response) => {
                setCookie("username", response.data.username, 1);
                redirect("/");
            })
            .catch((err) => {
                showErrorToast(err.response.data.message);
            });
    }
</script>
</body>
</html>
