/**
 * users page HTML template for wssshd
 *
 * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
 *
 * 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/>.
 */

#ifndef USERS_PAGE_H
#define USERS_PAGE_H

// users page HTML template
static const char *users_page_html =
"<!DOCTYPE html>\n"
"<html lang=\"en\">\n"
"<head>\n"
"    <meta charset=\"UTF-8\">\n"
"    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
"    <title>Users - WSSSHD control panel</title>\n"
"    <link rel=\"icon\" href=\"/favicon.ico\" type=\"image/x-icon\">\n"
"    <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css\" rel=\"stylesheet\">\n"
"    <link href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css\" rel=\"stylesheet\">\n"
"</head>\n"
"<body>\n"
"<nav class=\"navbar navbar-expand-lg navbar-dark bg-primary\">\n"
"<div class=\"container\">\n"
"<a class=\"navbar-brand\" href=\"/\">\n"
"<i class=\"fas fa-terminal\"></i> WSSSHD control panel</a>\n"
"<div class=\"navbar-nav ms-auto\">\n"
"<span class=\"navbar-text me-3\">%s</span>\n"
"<a class=\"nav-link\" href=\"/logout\">Logout</a>\n"
"</div></div></nav>\n"
"<div class=\"container mt-4\">\n"
"    <div class=\"card\">\n"
"        <div class=\"card-header d-flex justify-content-between align-items-center\">\n"
"            <h3 class=\"card-title mb-0\">\n"
"                <i class=\"fas fa-users\"></i> User Management\n"
"            </h3>\n"
"            <div>\n"
"                <a href=\"/\" class=\"btn btn-outline-secondary btn-sm me-2\">\n"
"                    <i class=\"fas fa-home\"></i> Back to Home\n"
"                </a>\n"
"                <button class=\"btn btn-primary btn-sm\" data-bs-toggle=\"modal\" data-bs-target=\"#addUserModal\">\n"
"                    <i class=\"fas fa-plus\"></i> Add User\n"
"                </button>\n"
"            </div>\n"
"        </div>\n"
"        <div class=\"card-body\">\n"
"            <div class=\"table-responsive\">\n"
"                <table class=\"table table-striped\">\n"
"                    <thead>\n"
"                        <tr>\n"
"                            <th>Username</th>\n"
"                            <th>Role</th>\n"
"                            <th>Actions</th>\n"
"                        </tr>\n"
"                    </thead>\n"
"                    <tbody>\n"
"                        %s\n"
"                    </tbody>\n"
"                </table>\n"
"            </div>\n"
"        </div>\n"
"    </div>\n"
"</div>\n"
"\n"
"<!-- Add User Modal -->\n"
"<div class=\"modal fade\" id=\"addUserModal\" tabindex=\"-1\">\n"
"    <div class=\"modal-dialog\">\n"
"        <div class=\"modal-content\">\n"
"            <div class=\"modal-header\">\n"
"                <h5 class=\"modal-title\">Add New User</h5>\n"
"                <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\"></button>\n"
"            </div>\n"
"            <form id=\"addUserForm\">\n"
"                <div class=\"modal-body\">\n"
"                    <div class=\"mb-3\">\n"
"                        <label for=\"addUsername\" class=\"form-label\">Username</label>\n"
"                        <input type=\"text\" class=\"form-control\" id=\"addUsername\" name=\"username\" required>\n"
"                    </div>\n"
"                    <div class=\"mb-3\">\n"
"                        <label for=\"addPassword\" class=\"form-label\">Password</label>\n"
"                        <input type=\"password\" class=\"form-control\" id=\"addPassword\" name=\"password\" required>\n"
"                    </div>\n"
"                    <div class=\"mb-3 form-check\">\n"
"                        <input type=\"checkbox\" class=\"form-check-input\" id=\"addIsAdmin\" name=\"is_admin\">\n"
"                        <label class=\"form-check-label\" for=\"addIsAdmin\">Administrator</label>\n"
"                    </div>\n"
"                </div>\n"
"                <div class=\"modal-footer\">\n"
"                    <button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Cancel</button>\n"
"                    <button type=\"submit\" class=\"btn btn-primary\">Add User</button>\n"
"                </div>\n"
"            </form>\n"
"        </div>\n"
"    </div>\n"
"</div>\n"
"\n"
"<!-- Edit User Modal -->\n"
"<div class=\"modal fade\" id=\"editUserModal\" tabindex=\"-1\">\n"
"    <div class=\"modal-dialog\">\n"
"        <div class=\"modal-content\">\n"
"            <div class=\"modal-header\">\n"
"                <h5 class=\"modal-title\">Edit User</h5>\n"
"                <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\"></button>\n"
"            </div>\n"
"            <form id=\"editUserForm\">\n"
"                <input type=\"hidden\" id=\"editUserId\" name=\"user_id\">\n"
"                <div class=\"modal-body\">\n"
"                    <div class=\"mb-3\">\n"
"                        <label for=\"editUsername\" class=\"form-label\">Username</label>\n"
"                        <input type=\"text\" class=\"form-control\" id=\"editUsername\" name=\"username\" required>\n"
"                    </div>\n"
"                    <div class=\"mb-3\">\n"
"                        <label for=\"editPassword\" class=\"form-label\">New Password (leave empty to keep current)</label>\n"
"                        <input type=\"password\" class=\"form-control\" id=\"editPassword\" name=\"password\">\n"
"                    </div>\n"
"                    <div class=\"mb-3 form-check\">\n"
"                        <input type=\"checkbox\" class=\"form-check-input\" id=\"editIsAdmin\" name=\"is_admin\">\n"
"                        <label class=\"form-check-label\" for=\"editIsAdmin\">Administrator</label>\n"
"                    </div>\n"
"                </div>\n"
"                <div class=\"modal-footer\">\n"
"                    <button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Cancel</button>\n"
"                    <button type=\"submit\" class=\"btn btn-primary\">Update User</button>\n"
"                </div>\n"
"            </form>\n"
"        </div>\n"
"    </div>\n"
"</div>\n"
"\n"
"<script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js\"></script>\n"
"<script>\n"
"function editUser(userId, username, isAdmin) {\n"
"    document.getElementById('editUserId').value = userId;\n"
"    document.getElementById('editUsername').value = username;\n"
"    document.getElementById('editPassword').value = '';\n"
"    document.getElementById('editIsAdmin').checked = isAdmin;\n"
"    new bootstrap.Modal(document.getElementById('editUserModal')).show();\n"
"}\n"
"\n"
"function deleteUser(userId, username) {\n"
"    if (confirm(`Are you sure you want to delete user \"${username}\"?`)) {\n"
"        fetch(`/delete_user/${userId}`, {\n"
"            method: 'POST',\n"
"            headers: {'Content-Type': 'application/x-www-form-urlencoded'}\n"
"        })\n"
"        .then(response => response.json())\n"
"        .then(data => {\n"
"            if (data.success) location.reload();\n"
"            else alert('Error: ' + data.error);\n"
"        });\n"
"    }\n"
"}\n"
"\n"
"document.getElementById('addUserForm').addEventListener('submit', function(e) {\n"
"    e.preventDefault();\n"
"    const formData = new FormData(this);\n"
"    fetch('/add_user', {method: 'POST', body: formData})\n"
"    .then(response => response.json())\n"
"    .then(data => {\n"
"        if (data.success) {\n"
"            bootstrap.Modal.getInstance(document.getElementById('addUserModal')).hide();\n"
"            location.reload();\n"
"        } else alert('Error: ' + data.error);\n"
"    });\n"
"});\n"
"\n"
"document.getElementById('editUserForm').addEventListener('submit', function(e) {\n"
"    e.preventDefault();\n"
"    const formData = new FormData(this);\n"
"    const userId = document.getElementById('editUserId').value;\n"
"    fetch(`/edit_user/${userId}`, {method: 'POST', body: formData})\n"
"    .then(response => response.json())\n"
"    .then(data => {\n"
"        if (data.success) {\n"
"            bootstrap.Modal.getInstance(document.getElementById('editUserModal')).hide();\n"
"            location.reload();\n"
"        } else alert('Error: ' + data.error);\n"
"    });\n"
"});\n"
"</script>\n"
"</body>\n"
"</html>\n";

#endif /* USERS_PAGE_H */
