<%# Copyright (C) 2023  Grisshink

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>. %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Сообщения</title>
    <style>
        :root {
            --foreground-color: <%= color.foreground %>;
            --background-color: <%= color.background %>;
            --form-background:  <%= color.form %>;
        }
    </style>
    <link rel="stylesheet" href="/style.css">
</head>
<body>
    <% if (loggedIn) { %>
        <%- include('nav') -%> 
    <% } %>
    <div class="messages-container">
        <h2>Сообщения</h2>
        <% if (mail.length === 0) { %> 
            <div class="container">
                <p class="error">Кажется тут немного пустовато... Попробуйте отправить себе сообщение <a href="/">отсюда</a></p>
            </div>
        <% } else { %>
            <ul class="mail-list">
                <% for (let i = mail.length - 1; i >= 0; i--) { %>
                    <li>
                        <a href="/mail/<%= i %>">
                            <div class="message"><strong>Сообщение:</strong> <%= mail[i].message %> </div>
                            <div><strong>От:</strong> <%= mail[i].name %> | <i><%= new Date(mail[i].timestamp).toLocaleString() %></i></div>
                        </a>
                    </li>
                <% } %>
            </ul>
        <% } %> 
    </div>
</body>
</html>