<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CORASS - Project Management Dashboard</title>
    <link rel="icon" type="image/png" href="https://kwarapoly.corass.ng/assets/Image/kp.png">
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <style>
        :root {
            --primary-color: #27ae60;
            --primary-dark: #024a00;
            --primary-light: #2ecc71;
            --sidebar-bg: linear-gradient(180deg, #2c3e50 0%, #34495e 100%);
            --header-bg: linear-gradient(135deg, var(--primary-color), var(--primary-light));
            --stats-icon-bg: linear-gradient(135deg, var(--primary-color), var(--primary-light));
            --body-bg: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-light) 100%);
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: var(--body-bg);
            min-height: 100vh;
            color: #333;
        }

        .dashboard-container {
            display: flex;
            min-height: 100vh;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            margin: 20px;
            border-radius: 20px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }

        /* Sidebar Styles */
        .sidebar {
            width: 280px;
            background: var(--sidebar-bg);
            color: white;
            padding: 0;
            position: relative;
            overflow-y: auto;
            transition: all 0.3s ease;
        }

        .sidebar::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="rgba(255,255,255,0.05)"/><circle cx="75" cy="75" r="1" fill="rgba(255,255,255,0.05)"/><circle cx="50" cy="10" r="0.5" fill="rgba(255,255,255,0.03)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
            pointer-events: none;
        }

        .logo-section {
            padding: 30px 25px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            position: relative;
            z-index: 1;
        }

        .logo-icon {
            width: 45px;
            height: 45px;
            background: linear-gradient(135deg, #fafafa, #ffffff);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            color: white;
            box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
        }

        .logo-text {
            font-size: 24px;
            font-weight: 700;
            letter-spacing: 1px;
        }

        .timestamp {
            font-size: 11px;
            color: rgba(255, 255, 255, 0.6);
            margin-top: 15px;
            padding: 8px 12px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 6px;
            border-left: 3px solid var(--primary-color);
        }

        .nav-item {
            margin: 5px 20px;
            padding: 15px 20px;
            border-radius: 12px;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 15px;
            position: relative;
            overflow: hidden;
            color: white;
            text-decoration: none;
        }

        .nav-item::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            height: 100%;
            width: 4px;
            background: var(--primary-color);
            transform: scaleY(0);
            transition: transform 0.3s ease;
        }

        .nav-item:hover::before,
        .nav-item.active::before {
            transform: scaleY(1);
        }

        .nav-item:hover,
        .nav-item.active {
            background: rgba(255, 255, 255, 0.1);
            transform: translateX(5px);
        }

        .nav-item.active {
            background: linear-gradient(135deg, rgba(39, 174, 96, 0.2), rgba(46, 204, 113, 0.1));
            color: var(--primary-light);
        }

        /* Main Content Styles */
        .main-content {
            flex: 1;
            background: #f8fafc;
            display: flex;
            flex-direction: column;
        }

        .header {
            background: var(--header-bg);
            color: white;
            box-shadow: 0 4px 20px rgba(39, 174, 96, 0.2);
        }

        .user-profile {
            display: flex;
            align-items: center;
            gap: 15px;
            background: rgba(255, 255, 255, 0.1);
            padding: 10px 20px;
            border-radius: 50px;
            backdrop-filter: blur(10px);
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .user-profile:hover {
            background: rgba(255, 255, 255, 0.2);
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: linear-gradient(135deg, #fff, #f1f1f1);
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary-color);
            font-weight: bold;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        /* Stats Card */
        .stats-card {
            background: linear-gradient(135deg, #fff, #f8fafc);
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
            border: 1px solid rgba(255, 255, 255, 0.2);
            position: relative;
            overflow: hidden;
        }

        .stats-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, var(--primary-color), var(--primary-light), #3498db);
        }

        .stats-content {
            background: #fff;
            border: 1px solid #eee;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .stats-icon {
            width: 80px;
            height: 80px;
            background: var(--stats-icon-bg);
            border-radius: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 32px;
            color: white;
            box-shadow: 0 10px 25px rgba(39, 174, 96, 0.3);
        }

        /* Filter Section */
        .filter-section {
            background: white;
            border-radius: 16px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
            border: 1px solid #e1e8ed;
        }

        .filter-btn {
            background: var(--header-bg);
            color: white;
            border: none;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .filter-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(39, 174, 96, 0.3);
            color: white;
        }

        /* Table Styles */
        .table-container {
            background: white;
            border-radius: 16px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
            border: 1px solid #e1e8ed;
            overflow-x: auto;
        }

        .table th {
            background: linear-gradient(135deg, #f8fafc, #e1e8ed);
            color: #2c3e50;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            border-bottom: 2px solid #e1e8ed;
            white-space: nowrap;
        }

        .table tr:hover {
            background: #f8fafc;
        }

        .status-badge {
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .status-approved {
            background: linear-gradient(135deg, #d4edda, #c3e6cb);
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .status-printed {
            background: linear-gradient(135deg, #e8f4fd, #d1ecf1);
            color: #0c5460;
            border: 1px solid #bee5eb;
        }

        .status-pending {
            background: linear-gradient(135deg, #fff3cd, #ffeaa7);
            color: #856404;
            border: 1px solid #ffeaa7;
        }

        .project-title {
            font-weight: 600;
            color: #2c3e50;
            line-height: 1.4;
            max-width: 300px;
            white-space: normal;
        }

        .student-info {
            font-weight: 600;
            color: var(--primary-color);
        }

        .matric-number {
            font-family: 'Courier New', monospace;
            background: #f8fafc;
            padding: 4px 8px;
            border-radius: 6px;
            font-size: 12px;
            color: #5a6c7d;
        }

        .action-btn {
            padding: 8px 12px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s ease;
            background: #f8fafc;
            color: #5a6c7d;
        }

        .action-btn:hover {
            background: var(--primary-color);
            color: white;
            transform: translateY(-1px);
        }

        .status-btn {
            background: #3498db !important;
            color: white !important;
        }

        .status-btn:hover {
            background: #2980b9 !important;
        }

        .view-btn {
            background: #95a5a6 !important;
            color: white !important;
        }

        .view-btn:hover {
            background: #7f8c8d !important;
        }

        /* Dropdown Menu */
        .dropdown-menu {
            border-radius: 8px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
            border: 1px solid #e1e8ed;
            min-width: 180px;
        }

        .dropdown-item {
            transition: all 0.2s ease;
            border-bottom: 1px solid #f8fafc;
        }

        .dropdown-item:last-child {
            border-bottom: none;
        }

        .dropdown-item:hover {
            background: #f8fafc;
            color: var(--primary-color);
            transform: translateX(5px);
        }

        /* Pagination */
        .pagination-btn {
            border: 1px solid #e1e8ed;
            background: #f8fafc;
            color: #2c3e50;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .pagination-btn:hover {
            background: var(--primary-color);
            color: white;
            border-color: var(--primary-color);
        }

        .pagination-btn.active {
            background: var(--primary-color);
            color: white;
            border-color: var(--primary-color);
        }

        /* Responsive Styles */
        @media (max-width: 992px) {
            .dashboard-container {
                flex-direction: column;
                margin: 10px;
            }

            .sidebar {
                width: 100%;
                position: fixed;
                z-index: 1000;
                height: auto;
                max-height: 0;
                overflow: hidden;
                transition: max-height 0.3s ease;
            }

            .sidebar.open {
                max-height: 1000px;
            }

            .main-content {
                margin-top: 60px;
            }
        }

        @media (max-width: 768px) {
            .header h1 {
                font-size: 22px;
            }

            .stats-icon {
                width: 60px;
                height: 60px;
                font-size: 24px;
            }

            .stats-info h2 {
                font-size: 28px;
            }

            .stats-info p {
                font-size: 14px;
            }
        }

        @media (max-width: 576px) {
            .user-profile span:not(#currentTime) {
                display: none;
            }

            .table th:nth-child(3),
            .table td:nth-child(3),
            .table th:nth-child(4),
            .table td:nth-child(4),
            .table th:nth-child(7),
            .table td:nth-child(7) {
                display: none;
            }
        }

        /* Card-based table for very small screens */
        @media (max-width: 480px) {
            .table-container {
                overflow-x: visible;
            }

            .table {
                display: block;
            }

            .table thead {
                display: none;
            }

            .table tbody {
                display: block;
            }

            .table tr {
                display: block;
                margin-bottom: 20px;
                background: white;
                border-radius: 10px;
                box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
                overflow: hidden;
            }

            .table td {
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 12px 15px;
                border-bottom: 1px solid #f1f5f9;
                white-space: normal;
            }

            .table td:before {
                content: attr(data-label);
                font-weight: 600;
                color: #2c3e50;
                margin-right: 15px;
                flex: 0 0 120px;
            }

            .table td:last-child {
                border-bottom: none;
            }

            .table td:last-child {
                justify-content: center;
                padding: 15px;
                background: #f8fafc;
            }

            .table td:last-child .action-btn {
                margin: 0 5px;
            }
        }

        @keyframes pulse {
            0% {
                transform: scale(1);
            }

            50% {
                transform: scale(1.05);
            }

            100% {
                transform: scale(1);
            }
        }
    </style>
</head>

<body>
    <div class="dashboard-container">
                <div class="sidebar" id="sidebar">
            <div class="logo-section p-4">
                <div class="d-flex align-items-center gap-3">
                    <div class="logo-icon">
                        <img src="https://kwarapoly.corass.ng/assets/Image/kp.png" width="40px" alt="Kp logo">
                    </div>
                    <div class="logo-text">CORASS</div>
                </div>
                <div class="timestamp mt-3 p-2" id="timestamp">
                    <i class="fas fa-clock"></i>
                    Loading time...
                </div>
            </div>

            <nav class="nav-section py-3">
                <a href="#" class="nav-item active">
                    <i class="fas fa-tachometer-alt"></i>
                    <span>Dashboard</span>
                </a>

                <a href="/user/logout" class="nav-item">
                    <i class="fas fa-arrow-right-from-bracket"></i>
                    <span>Log Out</span>
                </a>
            </nav>
        </div>

        <div class="main-content">
                        <header class="header p-3 p-md-4 d-flex justify-content-between align-items-center">
                <button class="btn d-lg-none mobile-menu-toggle" id="menuToggle">
                    <i class="fas fa-bars text-white"></i>
                </button>
                <h1 class="m-0 d-flex align-items-center gap-3">
                    <i class="fas fa-chart-line"></i>
                    <span class="d-none d-md-inline">Project Printing Officer Dashboard</span>
                    <span class="d-md-none">PPO Dashboard</span>
                </h1>
                <div class="user-profile">
                    <div class="user-avatar">
                        <i class="fas fa-user"></i>
                    </div>
                    <span  class="d-none d-md-inline"><%= user.firstname %></span>
                    <span ><%= user.firstname %></span>
                </div>
            </header>


            <div class="content-area p-3 p-md-4">
                <div class="stats-card p-4 mb-4">
                    <div class="row g-3">
                        <div class="col-md-4">
                            <div class="stats-content p-3 d-flex align-items-center gap-3">
                                <div class="stats-icon">
                                    <i class="fas fa-book"></i>
                                </div>
                                <div class="stats-info">
                                    <h2 class="mb-1">
                                        <%= totalDocument %>
                                    </h2>
                                    <p class="m-0">Total Assigned Student</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="stats-content p-3 d-flex align-items-center gap-3">
                                <div class="stats-icon">
                                    <i class="fas fa-book"></i>
                                </div>
                                <div class="stats-info">
                                    <h2 class="mb-1">
                                        <%= completedDocument %>
                                    </h2>
                                    <p class="m-0">Total Printed</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="stats-content p-3 d-flex align-items-center gap-3">
                                <div class="stats-icon">
                                    <i class="fas fa-book"></i>
                                </div>
                                <div class="stats-info">
                                    <h2 class="mb-1">
                                        <%= pendingDocuments %>
                                    </h2>
                                    <p class="m-0">Total Pending</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Filter Section -->
                <form class="filter-section p-4 mb-4" method="GET" action="">
                    <div class="filter-header d-flex justify-content-between align-items-center mb-3">
                        <div class="filter-title d-flex align-items-center gap-2">
                            <i class="fas fa-filter"></i>
                            <h2 class="m-0 fs-5">Filter by Student</h2>
                        </div>
                    </div>
                    <div class="filter-controls row g-3">
                        <div class="col-md-4">
                            <input type="text" name="matricNumber" class="form-control" placeholder="Enter Matric Number"
                                value="<%= typeof matricNumber !== 'undefined' ? matricNumber : '' %>">
                        </div>
                        <div class="col-md-4">
                            <select name="status" class="form-select">
                                <option value="">All Status</option>
                                <option value="total" <%=status==='total' ? 'selected' : '' %>>Total Document</option>
                                <option value="pending" <%=status==='pending' ? 'selected' : '' %>>Pending</option>
                                <option value="printed" <%=status==='printed' ? 'selected' : '' %>>Printed</option>
                                <option value="rejected" <%=status==='rejected' ? 'selected' : '' %>>Rejected</option>
                            </select>
                        </div>
                        <div class="col-md-2">
                            <button type="submit" class="btn filter-btn w-100">
                                <i class="fas fa-search me-2"></i>
                                Filter
                            </button>
                        </div>
                        <div class="col-md-2">
                            <a href="/ppo-dashboard" class="btn filter-btn w-100">
                                <i class="fas fa-times me-2"></i>
                                Clear
                            </a>
                        </div>
                    </div>
                </form>

                <!-- Table Section - Updated for Responsiveness -->
                <div class="table-container">
                    <div class="mb-3 text-end">
                        <a class="btn btn-success" href="/ppo-download?matricNumber=<%= matricNumber || '' %>&status=<%= status || '' %>">
                            <i class="fas fa-file-csv me-2"></i>Export to CSV
                        </a>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead>
                                <tr>
                                    <th>Topic</th>
                                    <th>Student</th>
                                    <th class="d-none d-md-table-cell">Student Contact</th>
                                    <th class="d-none d-md-table-cell">Student Level</th>
                                    <th>Student Matric</th>
                                    <th>Print Status</th>
                                    <th class="d-none d-md-table-cell">Document Available?</th>
                                    <th>Date Submitted</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <% if (projects && projects.length> 0) { %>
                                    <% projects.forEach(project=> {
                                        const student = project.project_topic?.student;
                                        const profile = project?.profile;
                                        const status = project?.project_topics[0]?.project_submissions[0]?.is_approved ?
                                        'approved' : (project?.project_topics[0]?.project_submissions[0]?.active === false ?
                                        'rejected' : 'pending');
                                        const doc = project?.project_topics[0]?.project_submissions[0]?.id;
                                        %>
                                        <tr>
                                            <td data-label="Topic">
                                                <div class="project-title">
                                                    <%= project.project_topics[0]?.topic || "N/A" %>
                                                </div>
                                            </td>
                                            <td data-label="Student">
                                                <div class="student-info">
                                                    <%= `${profile?.firstname || '' } ${profile?.middlename || '' }
                                                        ${profile?.lastname || '' }`.trim() %>
                                                </div>
                                            </td>
                                            <td class="d-none d-md-table-cell" data-label="Contact">
                                                <div class="student-info">
                                                    <%= `${project?.email || '' } | ${project?.phone || '' } ` %>
                                                </div>
                                            </td>
                                            <td class="d-none d-md-table-cell" data-label="Level">
                                                <span class="matric-number">
                                                    <%= project?.profile?.level?.name || "N/A" %> (<%=
                                                            project?.profile?.study_mode?.name || "N/A" %>)
                                                </span>
                                            </td>
                                            <td data-label="Matric">
                                                <span class="matric-number">
                                                    <%= project.username || "N/A" %>
                                                </span>
                                            </td>
                                            <td data-label="Payment">
                                                <span class="status-badge status-<%= status %>">
                                                    <% if (project?.is_printed ===true) { %>
                                                        <i class="fas fa-check-circle"></i> printed
                                                    <% } else { %>
                                                        <i class="fas fa-clock"></i> pending
                                                    <% } %>
                                                </span>
                                            </td>
                                            <td class="d-none d-md-table-cell" data-label="Document">
                                                <span class="status-badge status-<%= status %>">
                                                    <% if (doc) { %>
                                                        <i class="fas fa-check-circle"></i> Yes
                                                    <% } else { %>
                                                        <i class="fas fa-times-circle"></i> No
                                                    <% } %>
                                                </span>
                                            </td>
                                            <td data-label="Date Submitted">
                                                <%= new Date(project?.project_topics[0]?.project_submissions[0]?.createdAt).toLocaleDateString('en-US',
                                                { weekday: 'long', month: 'short', day: 'numeric', year: 'numeric' }) %>
                                            </td>
                                            <td data-label="Actions">
                                                <% if (doc) { %>
                                                <div class="d-flex gap-2 justify-content-center">
                                                    <a class="action-btn view-btn" title="Download Document" target="_blank"
                                                        href="/view-project-ppo/<%= project?.project_topics[0]?.project_submissions[0]?.id %>">
                                                        <i class="fas fa-download"></i>
                                                    </a>

                                                    <div class="dropdown">
                                                        <button class="action-btn status-btn dropdown-toggle" type="button"
                                                            data-bs-toggle="dropdown" aria-expanded="false">
                                                            <i class="fas fa-edit"></i>
                                                        </button>
                                                        <ul class="dropdown-menu">
                                                            <li><a class="dropdown-item" href="#" data-id="<%= project?.id %>"
                                                                    onclick="updateStatus(this, 'printed')">
                                                                    <i class="fas fa-print me-2"></i>Mark as Printed
                                                                </a></li>
                                                        </ul>
                                                    </div>
                                                </div>
                                                <%}%>
                                            </td>
                                        </tr>
                                        <% }); %>
                                    <% } else { %>
                                        <tr>
                                            <td colspan="9" class="text-center py-4">No records found.</td>
                                        </tr>
                                    <% } %>
                            </tbody>
                        </table>
                         <% if (totalPages> 1) { %>
                        <div class="pagination">
                            <% if (currentPage> 1) { %>
                                <a href="?page=<%= currentPage - 1 %><%= queryString %>" class="pagination-btn">
                                    <i class="fas fa-chevron-left"></i> Previous
                                </a>
                                <% } %>
                                
                                <% for (let i=1; i<=totalPages; i++) { %>
                                    <a href="?page=<%= i %><%= queryString %>" 
                                       class="pagination-btn <%= i === currentPage ? 'active' : '' %>">
                                        <%= i %>
                                    </a>
                                    <% } %>
                                    
                                    <% if (currentPage < totalPages) { %>
                                        <a href="?page=<%= currentPage + 1 %><%= queryString %>" class="pagination-btn">
                                            Next <i class="fas fa-chevron-right"></i>
                                        </a>
                                        <% } %>
                        </div>
                        <% } %>
                    </div>

                    <!-- Your existing pagination code -->
                </div>
            </div>
        </div>
    </div>

    <footer class="footer py-3 text-white text-center">
        <div class="container">
            <div class="row">
                <div class="col-md-6 text-md-start">
                    COPYRIGHT &copy;
                    <script>document.write(new Date().getFullYear())</script>
                    <a class="ms-1 text-white" href="">CORASS</a>,
                    <span>All rights Reserved</span>
                </div>
                <div class="col-md-6 text-md-end mt-2 mt-md-0">
                    Centralized Online Research Assessment and Submission System
                    <i class="fas fa-file-alt ms-1"></i>
                </div>
            </div>
        </div>
    </footer>


    <!-- Bootstrap JS Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Update timestamp with Nigeria time
        function updateNigeriaTime() {
            const options = {
                timeZone: 'Africa/Lagos',
                weekday: 'long',
                year: 'numeric',
                month: 'long',
                day: 'numeric',
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit',
                hour12: false
            };

            const now = new Date();
            const nigeriaTime = now.toLocaleString('en-US', options);
            const timeOnly = now.toLocaleTimeString('en-US', {
                timeZone: 'Africa/Lagos',
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit',
                hour12: false
            });

            document.getElementById('timestamp').innerHTML = `
                <i class="fas fa-clock"></i>
                ${nigeriaTime}<br>
                (West Africa Standard Time)
            `;

            document.getElementById('currentTime').textContent = timeOnly;
        }

        // Update time every second
        updateNigeriaTime();
        setInterval(updateNigeriaTime, 1000);

        // Mobile menu toggle
        document.getElementById('menuToggle').addEventListener('click', function () {
            document.getElementById('sidebar').classList.toggle('open');
        });

        // Set user name (you would replace this with actual user data)
        document.getElementById('userName').textContent = "<%= user.firstname%>"; 

        // Update status functionality
        function updateStatus(item, newStatus) {
            const projectId = item.getAttribute('data-id');
            const row = item.closest('tr');
            const statusCell = row.querySelector('td:nth-child(5) .status-badge');

            // Send to backend
            fetch('/update-print-status', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ id: projectId, status: newStatus }),
            })
                .then((res) => res.json())
                .then((data) => {
                    if (data.success) {
                        showNotification(`Status updated to ${newStatus}`, 'success');
                    } else {
                        showNotification(data.message || 'Status update failed', 'danger');
                    }
                })
                .catch((err) => {
                    console.error('Error:', err);
                    showNotification('Network error while updating status', 'danger');
                });
        }

        // Notification system
        function showNotification(message, type = 'info') {
            // Create toast notification using Bootstrap
            const toastContainer = document.createElement('div');
            toastContainer.className = 'position-fixed top-0 end-0 p-3';
            toastContainer.style.zIndex = '1100';

            const toast = document.createElement('div');
            toast.className = `toast show align-items-center text-white bg-${type === 'success' ? 'success' : type === 'danger' ? 'danger' : 'info'} border-0`;
            toast.role = 'alert';
            toast.ariaLive = 'assertive';
            toast.ariaAtomic = 'true';

            toast.innerHTML = `
                <div class="d-flex">
                    <div class="toast-body">
                        <i class="fas fa-${type === 'success' ? 'check-circle' : 'info-circle'} me-2"></i>
                        ${message}
                    </div>
                    <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
                </div>
            `;

            toastContainer.appendChild(toast);
            document.body.appendChild(toastContainer);

            // Auto hide after 3 seconds
            setTimeout(() => {
                toast.classList.remove('show');
                setTimeout(() => toastContainer.remove(), 300);
            }, 3000);
        }
    </script>
</body>
</html>