<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard - Gitea Webhook Ambassador</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/dashboard.css">
</head>
<body>
    <header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
        <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">Gitea Webhook Ambassador</a>
        <div class="navbar-nav">
            <div class="nav-item text-nowrap">
                <span class="px-3 text-white">
                    <span class="health-indicator"></span>
                    <span id="healthStatus">checking...</span>
                </span>
            </div>
        </div>
    </header>

    <div class="container-fluid">
        <div class="row">
            <nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
                <div class="position-sticky pt-3">
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link active" href="#projects" data-bs-toggle="tab">
                                Projects
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#api-keys" data-bs-toggle="tab">
                                API Keys
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#logs" data-bs-toggle="tab">
                                Logs
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
                <div class="tab-content" id="myTabContent">
                    <!-- Projects Tab -->
                    <div class="tab-pane fade show active" id="projects">
                        <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                            <h1 class="h2">Projects</h1>
                            <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addProjectModal">
                                Add Project
                            </button>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped" id="projectsTable">
                                <thead>
                                    <tr>
                                        <th>Name</th>
                                        <th>Jenkins Job</th>
                                        <th>Gitea Repository</th>
                                    </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                        </div>
                    </div>

                    <!-- API Keys Tab -->
                    <div class="tab-pane fade" id="api-keys">
                        <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                            <h1 class="h2">API Keys</h1>
                            <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#generateKeyModal">
                                Generate New Key
                            </button>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped" id="apiKeysTable">
                                <thead>
                                    <tr>
                                        <th>Description</th>
                                        <th>Key</th>
                                        <th>Created</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                        </div>
                    </div>

                    <!-- Logs Tab -->
                    <div class="tab-pane fade" id="logs">
                        <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                            <h1 class="h2">Logs</h1>
                        </div>
                        <form id="logQueryForm" class="row g-3 mb-3">
                            <div class="col-md-3">
                                <label for="startTime" class="form-label">Start Time</label>
                                <input type="datetime-local" class="form-control" id="startTime">
                            </div>
                            <div class="col-md-3">
                                <label for="endTime" class="form-label">End Time</label>
                                <input type="datetime-local" class="form-control" id="endTime">
                            </div>
                            <div class="col-md-2">
                                <label for="logLevel" class="form-label">Log Level</label>
                                <select class="form-select" id="logLevel">
                                    <option value="">All</option>
                                    <option value="error">Error</option>
                                    <option value="warn">Warning</option>
                                    <option value="info">Info</option>
                                    <option value="debug">Debug</option>
                                </select>
                            </div>
                            <div class="col-md-3">
                                <label for="logQuery" class="form-label">Search Query</label>
                                <input type="text" class="form-control" id="logQuery" placeholder="Search logs...">
                            </div>
                            <div class="col-md-1">
                                <label class="form-label">&nbsp;</label>
                                <button type="submit" class="btn btn-primary w-100">Search</button>
                            </div>
                        </form>
                        <div id="logEntries" class="border rounded p-3 bg-light"></div>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <!-- Add Project Modal -->
    <div class="modal fade" id="addProjectModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Add New Project</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <form id="addProjectForm">
                    <div class="modal-body">
                        <div class="mb-3">
                            <label for="projectName" class="form-label">Project Name</label>
                            <input type="text" class="form-control" id="projectName" required>
                        </div>
                        <div class="mb-3">
                            <label for="jenkinsJob" class="form-label">Jenkins Job</label>
                            <input type="text" class="form-control" id="jenkinsJob" required>
                        </div>
                        <div class="mb-3">
                            <label for="giteaRepo" class="form-label">Gitea Repository</label>
                            <input type="text" class="form-control" id="giteaRepo" required>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-primary">Add Project</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Generate API Key Modal -->
    <div class="modal fade" id="generateKeyModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Generate New API Key</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <form id="generateKeyForm">
                    <div class="modal-body">
                        <div class="mb-3">
                            <label for="keyDescription" class="form-label">Key Description</label>
                            <input type="text" class="form-control" id="keyDescription" required>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-primary">Generate Key</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="/js/jquery-3.7.1.min.js"></script>
    <script src="/js/bootstrap.bundle.min.js"></script>
    <script src="/js/dashboard.js"></script>
</body>
</html> 