<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ICA VESP Dashboard</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-dark-blue: #00264d;
            --primary-red: #ED1C24;
            --secondary-white: #FFFFFF;
            --background-color: #F0F4F8;
            --text-color: #333333;
            --border-radius: 10px;
            --box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
        }

        *, *::before, *::after {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            outline: none;
        }

        body {
            font-family: 'Roboto', Arial, sans-serif;
            background-color: var(--background-color);
            color: var(--text-color);
            line-height: 1.6;
        }

        .container {
            width: 90%;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        header {
            background-color: var(--primary-dark-blue);
            color: var(--secondary-white);
            padding: 1rem 0;
            box-shadow: var(--box-shadow);
            margin-bottom: 20px;
        }

        .header-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo-container {
            display: flex;
            align-items: center;
        }

        .logo-image {
            height: 40px;
            margin-right: 10px;
        }

        .logo-text {
            font-size: 20px;
            font-weight: 700;
            color: var(--secondary-white);
        }

        nav ul {
            list-style: none;
            display: flex;
            align-items: center;
        }

        nav li {
            margin-left: 15px;
        }

        nav a {
            color: var(--secondary-white);
            text-decoration: none;
            font-weight: 500;
            padding: 8px 12px;
            transition: background-color 0.3s, opacity 0.3s;
            border-radius: var(--border-radius);
        }

        nav a:hover, nav a.active {
            background-color: var(--primary-red);
        }

        .card {
            background: #ffffff;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            padding: 20px;
            margin-bottom: 20px;
            transition: transform 0.3s, box-shadow 0.3s;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
        }

        h1, h2, h3 {
            color: var(--primary-dark-blue);
            margin-bottom: 15px;
        }

        .case-details {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            margin-top: 20px;
        }

        video {
            width: 100%;
            border-radius: var(--border-radius);
            margin-top: 10px;
            box-shadow: var(--box-shadow);
        }

        table {
            width: 100%;
            border-collapse: collapse;
            background-color: var(--secondary-white);
            border-radius: var(--border-radius);
            overflow: hidden;
            box-shadow: var(--box-shadow);
        }

        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
            cursor: pointer;
        }

        th {
            background-color: var(--primary-dark-blue);
            color: var(--secondary-white);
        }

        tr:last-child td {
            border-bottom: none;
        }

        .badge {
            padding: 5px 10px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: bold;
            text-transform: uppercase;
        }

        .badge-pending { background-color: #FFA500; color: var(--secondary-white); }
        .badge-approved { background-color: #28A745; color: var(--secondary-white); }
        .badge-rejected { background-color: var(--primary-red); color: var(--secondary-white); }
        .badge-completed { background-color: #5bc0de; color: var(--secondary-white); }
        .badge-high { background-color: #d9534f; color: var(--secondary-white); }
        .badge-medium { background-color: #f0ad4e; color: var(--secondary-white); }
        .badge-low { background-color: #5bc0de; color: var(--secondary-white); }

        .tab-content {
            display: none;
        }

        .tab-content.active {
            display: block;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 20px;
        }

        button {
            background-color: var(--primary-dark-blue);
            color: var(--secondary-white);
            border: none;
            padding: 8px 15px;
            border-radius: var(--border-radius);
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s, transform 0.3s, box-shadow 0.3s;
        }

        button:hover {
            transform: translateY(-3px);
            background-color: #001f3d;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }

        button.secondary {
            background-color: var(--secondary-white);
            color: var(--primary-dark-blue);
            border: 1px solid var(--primary-dark-blue);
        }

        button.secondary:hover {
            background-color: #e0e0e0;
        }

        input, textarea, select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: var(--border-radius);
            margin-bottom: 10px;
            transition: border-color 0.3s, box-shadow 0.3s;
        }

        input:focus, textarea:focus, select:focus {
            border-color: var(--primary-dark-blue);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        .priority-select {
            width: auto;
            display: inline-block;
        }

        @media (max-width: 768px) {
            .header-content {
                flex-direction: column;
                align-items: flex-start;
            }

            nav ul {
                margin-top: 10px;
            }

            nav li {
                margin-left: 0;
                margin-right: 20px;
            }
                        /* Login Page Styles */
            .login-container {
                max-width: 400px;
                margin: 100px auto;
                padding: 30px;
                background: var(--secondary-white);
                border-radius: var(--border-radius);
                box-shadow: var(--box-shadow);
                display: none; /* Hidden by default */
            }
            
            .login-logo {
                text-align: center;
                margin-bottom: 30px;
            }
            
            .login-logo img {
                height: 60px;
            }
            
            .form-group {
                margin-bottom: 20px;
            }
            
            .form-group label {
                display: block;
                margin-bottom: 5px;
                font-weight: 500;
            }
            
            /* Enhanced Analytics Styles */
            .analytics-grid {
                display: grid;
                grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
                gap: 20px;
                margin-bottom: 30px;
            }
            
            .metric-card {
                background: var(--secondary-white);
                padding: 20px;
                border-radius: var(--border-radius);
                box-shadow: var(--box-shadow);
            }
            
            .metric-value {
                font-size: 24px;
                font-weight: bold;
                color: var(--primary-dark-blue);
                margin: 10px 0;
            }
            
            .chart-container {
                height: 300px;
                margin: 20px 0;
            }
            
            /* Enhanced Form Styles */
            .form-section {
                margin-bottom: 25px;
                padding: 20px;
                background: #f8f9fa;
                border-radius: var(--border-radius);
            }
            
            .form-grid {
                display: grid;
                grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
                gap: 15px;
            }
        }
    </style>
</head>
<body>
    <!-- Add this right after <body> -->
<div id="login-page" class="login-container">
    <div class="login-logo">
        <img src="https://file.go.gov.sg/icalogo.png" alt="ICA Logo">
        <h2>ICA VESP Dashboard</h2>
    </div>
    <form id="login-form" onsubmit="return handleLogin(event)">
        <div class="form-group">
            <label for="username">Username</label>
            <input type="text" id="username" name="username" required>
        </div>
        <div class="form-group">
            <label for="password">Password</label>
            <input type="password" id="password" name="password" required>
        </div>
        <div class="form-group">
            <label for="department">Department</label>
            <select id="department" name="department" required>
                <option value="">Select Department</option>
                <option value="operations">Operations</option>
                <option value="enforcement">Enforcement</option>
                <option value="admin">Administration</option>
            </select>
        </div>
        <button type="submit" class="login-btn">Login</button>
    </form>
</div>
<header>
    <div class="container header-content">
        <div class="logo-container">
            <img src="https://file.go.gov.sg/icalogo.png" alt="ICA Logo" class="logo-image">
            <span class="logo-text">ICA Video Platform</span>
        </div>
        <nav>
            <ul>
                <li><a href="#" class="nav-link active" data-target="dashboard">Dashboard</a></li>
                <li><a href="#" class="nav-link" data-target="upload">Upload</a></li>
                <li><a href="#" class="nav-link" data-target="requests">Requests</a></li>
                <li><a href="#" class="nav-link" data-target="cases">Cases</a></li>
                <li><a href="#" class="nav-link" data-target="analytics">Analytics</a></li>
                <li><a href="#" class="nav-link" data-target="admin">Admin</a></li>
                <li><a href="#" id="logout">Logout</a></li>
            </ul>
        </nav>
    </div>
</header>

<div id="dashboard" class="container tab-content active">
    <h1>Dashboard Overview</h1>
    <div class="case-details">
        <h3>Case: Unauthorized Exit Incident</h3>
        <p>Case Number: ICA-2023-007</p>
        <video controls>
            <source src="videoplayback.mp4" type="video/mp4">
            Your browser does not support the video tag.
        </video>
        <p>Status: <span class="badge badge-approved">Completed</span></p>
    </div>
</div>

<div id="upload" class="container tab-content">
    <h2>Upload Video</h2>
    <div class="card">
        <form id="upload-form" enctype="multipart/form-data">
            <label for="upload-case-number">Case Number:</label>
            <input type="text" id="upload-case-number" name="case-number" required>

            <label for="video-file">Video File:</label>
            <input type="file" id="video-file" name="video-file" accept="video/*" required>

            <button type="submit">Upload Video</button>
        </form>
    </div>
</div>

<div id="requests" class="container tab-content">
    <h2>Submit Evidence Request</h2>
    <div class="card">
        <form id="request-form">
            <div class="form-section">
                <h3>Officer Information</h3>
                <div class="form-grid">
                    <div class="form-group">
                        <label for="officer-name">Officer Name</label>
                        <input type="text" id="officer-name" name="officer-name" required>
                    </div>
                    <div class="form-group">
                        <label for="officer-id">Officer ID</label>
                        <input type="text" id="officer-id" name="officer-id" required>
                    </div>
                    <div class="form-group">
                        <label for="department">Department</label>
                        <select id="department" name="department" required>
                            <option value="">Select Department</option>
                            <option value="operations">Operations</option>
                            <option value="enforcement">Enforcement</option>
                        </select>
                    </div>
                </div>
            </div>

            <!-- Rest of the form sections... -->
        </form>
    </div>
</div>

<div id="cases" class="container tab-content">
    <h2>Active Cases</h2>
    <div class="card">
        <table>
            <thead>
                <tr>
                    <th>Case Number</th>
                    <th>Description</th>
                    <th>Priority</th> <!-- New Priority column -->
                    <th>Status</th>
                    <th>Last Updated</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                <tr data-case="ICA-2023-007" data-description="Security Breach Investigation">
                    <td>ICA-2023-007</td>
                    <td>Security Breach Investigation</td>
                    <td><span class="badge badge-medium">Medium</span></td> <!-- Priority Badge -->
                    <td><span class="badge badge-pending">Pending</span></td>
                    <td>2023-05-01</td>
                    <td><button onclick="viewCase('ICA-2023-007')">View Details</button></td>
                </tr>
                <tr data-case="ICA-2023-008" data-description="Unauthorized Exit Incident">
                    <td>ICA-2023-008</td>
                    <td>Unauthorized Exit Incident</td>
                    <td><span class="badge badge-high">High</span></td> <!-- Priority Badge -->
                    <td><span class="badge badge-approved">Completed</span></td>
                    <td>2023-04-20</td>
                    <td><button onclick="viewCase('ICA-2023-008')">View Details</button></td>
                </tr>
                <tr data-case="ICA-2023-009" data-description="Access Control Failure">
                    <td>ICA-2023-009</td>
                    <td>Access Control Failure</td>
                    <td><span class="badge badge-low">Low</span></td> <!-- Priority Badge -->
                    <td><span class="badge badge-rejected">Rejected</span></td>
                    <td>2023-03-28</td>
                    <td><button onclick="viewCase('ICA-2023-009')">View Details</button></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

<div id="analytics" class="container tab-content">
    <h2>Analytics Dashboard</h2>
    <div class="analytics-grid">
        <div class="metric-card">
            <h3>Video Processing</h3>
            <div class="metric-value">124</div>
            <p>Videos processed this month</p>
            <div class="chart-container" id="videoProcessingChart"></div>
        </div>
        <div class="metric-card">
            <h3>Request Response Time</h3>
            <div class="metric-value">85%</div>
            <p>SLA compliance rate</p>
            <div class="chart-container" id="slaChart"></div>
        </div>
        <div class="metric-card">
            <h3>Case Priority Distribution</h3>
            <div class="chart-container" id="priorityChart"></div>
        </div>
    </div>
    
    <div class="card">
        <h3>Department Performance</h3>
        <table id="performance-table">
            <thead>
                <tr>
                    <th>Department</th>
                    <th>Cases Handled</th>
                    <th>Avg. Response Time</th>
                    <th>SLA Compliance</th>
                </tr>
            </thead>
            <tbody>
                <!-- Data will be populated via JavaScript -->
            </tbody>
        </table>
    </div>
</div>

<div id="admin" class="container tab-content">
    <h2>Admin Panel</h2>
    <div class="card">
        <h3>Manage Users</h3>
        <form id="admin-manage-users-form">
            <label for="user-email">Email Address:</label>
            <input type="email" id="user-email" name="user-email" required>

            <label for="user-role">Role:</label>
            <select id="user-role" name="user-role">
                <option value="ops-officer">Ops Officer</option>
                <option value="enforcement-officer">Enforcement Officer</option>
                <option value="admin">Admin</option>
            </select>

            <button type="submit">Add User</button>
        </form>
    </div>
    <div class="card">
        <h3>Current Users</h3>
        <table>
            <thead>
                <tr>
                    <th>User</th>
                    <th>Email</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody id="user-list">
                <tr>
                    <td>Alice</td>
                    <td><PRESIDIO_ANONYMIZED_EMAIL_ADDRESS></td>
                    <td><button onclick="removeUser('alice@ica.gov.sg')">Remove</button></td>
                </tr>
                <tr>
                    <td>Bob</td>
                    <td><PRESIDIO_ANONYMIZED_EMAIL_ADDRESS></td>
                    <td><button onclick="removeUser('bob@ica.gov.sg')">Remove</button></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // Function to handle tab switching
        function showSection(event) {
            event.preventDefault();
            const targetId = event.currentTarget.getAttribute('data-target');
            const sections = document.querySelectorAll('.container.tab-content');
            const navLinks = document.querySelectorAll('.nav-link');

            sections.forEach(section => section.classList.remove('active'));
            navLinks.forEach(link => link.classList.remove('active'));

            document.getElementById(targetId).classList.add('active');
            event.currentTarget.classList.add('active');
        }

            // Add this to your existing script section
            function handleLogin(event) {
                event.preventDefault();
                const username = document.getElementById('username').value;
                const password = document.getElementById('password').value;
                const department = document.getElementById('department').value;
            
                // Add your authentication logic here
                // For demo purposes:
                if (username && password) {
                    document.getElementById('login-page').style.display = 'none';
                    document.querySelector('header').style.display = 'block';
                    document.getElementById('dashboard').classList.add('active');
                    // Store user info in session
                    sessionStorage.setItem('user', JSON.stringify({
                        username,
                        department,
                        loggedIn: true
                    }));
                }
            }
            
            // Check login status on page load
            document.addEventListener('DOMContentLoaded', () => {
                const user = JSON.parse(sessionStorage.getItem('user'));
                if (!user || !user.loggedIn) {
                    document.querySelector('header').style.display = 'none';
                    document.getElementById('login-page').style.display = 'block';
                } else {
                    document.getElementById('login-page').style.display = 'none';
                    document.querySelector('header').style.display = 'block';
                }
            });
            
            // Add logout handling
            document.getElementById('logout').addEventListener('click', (e) => {
                e.preventDefault();
                sessionStorage.removeItem('user');
                window.location.reload();
            });

        // Assign event listeners to navigation links
        document.querySelectorAll('.nav-link').forEach(link => {
            link.addEventListener('click', showSection);
        });

        function viewCase(caseId) {
            const caseRow = document.querySelector(`tr[data-case="${caseId}"]`);
            const description = caseRow.getAttribute('data-description');

            const dashboardContent = `
                <h3>Case: ${description}</h3>
                <p>Case Number: ${caseId}</p>
                <video controls>
                    <source src="${caseId}.mp4" type="video/mp4">
                    Your browser does not support the video tag.
                </video>
                <p>Status: ${caseRow.querySelector('.badge').outerHTML}</p>
            `;

            const sections = document.querySelectorAll('.container.tab-content');
            const dashboardSection = document.getElementById('dashboard');
            dashboardSection.innerHTML = dashboardContent;

            document.querySelector('.nav-link.active').classList.remove('active');
            document.querySelector('a[data-target="dashboard"]').classList.add('active');
            sections.forEach(section => section.classList.remove('active'));
            dashboardSection.classList.add('active');
        }

        function removeUser(email) {
            const confirmRemoval = confirm(`Are you sure you want to remove the user with email: ${email}?`);
            if (confirmRemoval) {
                alert(`User ${email} removed successfully.`);
                const rows = document.querySelectorAll('#user-list tr');
                rows.forEach(row => {
                    if (row.textContent.includes(email)) {
                        row.remove();
                    }
                });
            }
        }

        const enableTableSorting = () => {
            document.querySelectorAll('th').forEach(header => {
                header.addEventListener('click', function() {
                    const table = header.closest('table');
                    const tbody = table.querySelector('tbody');
                    const rowsArray = Array.from(tbody.querySelectorAll('tr'));
                    const headerIndex = Array.from(header.parentNode.children).indexOf(header);
                    const isAsc = header.getAttribute('data-sort') === 'asc';

                    rowsArray.sort((a, b) => {
                        const aText = a.children[headerIndex].innerText;
                        const bText = b.children[headerIndex].innerText;
                        return isAsc ? aText.localeCompare(bText) : bText.localeCompare(aText);
                    });

                    rowsArray.forEach(row => tbody.appendChild(row));
                    header.setAttribute('data-sort', isAsc ? 'desc' : 'asc');
                });
            });
        };

        enableTableSorting();

        document.getElementById('request-form').addEventListener('submit', function(event) {
            event.preventDefault();
            alert('Video evidence request submitted.');
        });

        document.getElementById('retrieve-form').addEventListener('submit', function(event) {
            event.preventDefault();
            const caseNumber = document.getElementById('case-number').value;
            alert('Video retrieval initiated.');

            const caseRow = document.querySelector(`tr[data-case="${caseNumber}"]`);
            if (caseRow) {
                caseRow.querySelector('.badge').classList.remove('badge-pending', 'badge-approved', 'badge-rejected');
                caseRow.querySelector('.badge').classList.add('badge-completed');
                caseRow.querySelector('.badge').innerText = 'Completed';
            }
        });

        document.getElementById('admin-manage-users-form').addEventListener('submit', function(event) {
            event.preventDefault();
            const email = document.getElementById('user-email').value;
            alert(`User ${email} added successfully.`);
        document.addEventListener('DOMContentLoaded', () => {
    const table = document.querySelector('table');
    const headers = table.querySelectorAll('th');
    const tbody = table.querySelector('tbody');

    const enableTableSorting = () => {
        headers.forEach((header, headerIndex) => {
            header.addEventListener('click', () => {
                const rowsArray = Array.from(tbody.querySelectorAll('tr'));
                const isAsc = header.getAttribute('data-sort') !== 'asc';

                // Toggle sorted class for styling
                headers.forEach(h => h.classList.remove('sorted-asc', 'sorted-desc'));
                header.classList.add(isAsc ? 'sorted-asc' : 'sorted-desc');

                rowsArray.sort((a, b) => {
                    const aText = a.children[headerIndex].textContent.trim();
                    const bText = b.children[headerIndex].textContent.trim();

                    // Check if the content is numeric
                    const aValue = isNaN(aText) ? aText : parseFloat(aText);
                    const bValue = isNaN(bText) ? bText : parseFloat(bText);

                    if (typeof aValue === 'number' && typeof bValue === 'number') {
                        return isAsc ? aValue - bValue : bValue - aValue;
                    } else {
                        return isAsc ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
                    }
                });

                // Clear and re-append rows in sorted order
                tbody.innerHTML = '';
                rowsArray.forEach(row => tbody.appendChild(row));

                // Update sort direction attribute
                header.setAttribute('data-sort', isAsc ? 'asc' : 'desc');
            });
        });
    };

    enableTableSorting();
});

        });
    });
</script>
</body>
</html>