<?php
session_start();
include 'layouts/dbconn.php';
include 'layouts/session.php';

if (!isset($_SESSION['user_id'])) {
    header('Location: login.php');
    exit();
}

$allowed_roles = ['SUPER_ADMIN', 'HOSPITAL_ADMIN', 'ENT_DOCTOR', 'ENT_CONSULTANT', 'NURSE', 'LAB_TECHNICIAN'];
if (!in_array($_SESSION['role_code'], $allowed_roles)) {
    header('Location: dashboard.php');
    exit();
}

$user_id = $_SESSION['user_id'];
$patient_id = isset($_GET['patient_id']) ? (int)$_GET['patient_id'] : 0;

if (!$patient_id) {
    header('Location: list_patients.php');
    exit();
}

// Fetch patient details
$patient_sql = "SELECT 
                    p.patient_id, p.patient_number, p.registration_type,
                    p.allergies, p.chronic_conditions, p.current_medications,
                    p.blood_group, u.user_id, u.full_name, u.phone_primary,
                    u.email, u.gender, u.date_of_birth,
                    TIMESTAMPDIFF(YEAR, u.date_of_birth, CURDATE()) as age,
                    ip.provider_name
                FROM patients p
                INNER JOIN users u ON p.user_id = u.user_id
                LEFT JOIN insurance_providers ip ON p.insurance_provider_id = ip.provider_id
                WHERE p.patient_id = ?";

$stmt = $conn->prepare($patient_sql);
$stmt->bind_param("i", $patient_id);
$stmt->execute();
$patient_result = $stmt->get_result();

if ($patient_result->num_rows === 0) {
    header('Location: list_patients.php');
    exit();
}

$patient = $patient_result->fetch_assoc();

// Fetch medical records (appointments without diagnosis fields)
$records_sql = "SELECT 
                    a.appointment_id,
                    a.appointment_number,
                    a.appointment_date,
                    a.appointment_time,
                    a.appointment_type,
                    a.status as appointment_status,
                    a.chief_complaint,
                    a.notes,
                    a.room_number,
                    a.checked_in_at,
                    a.completed_at,
                    d.full_name as doctor_name
                FROM appointments a
                INNER JOIN users d ON a.doctor_id = d.user_id
                WHERE a.patient_id = ? 
                AND a.status IN ('COMPLETED', 'IN_PROGRESS', 'CHECKED_IN')
                ORDER BY a.appointment_date DESC, a.appointment_time DESC";

$stmt = $conn->prepare($records_sql);
$stmt->bind_param("i", $patient_id);
$stmt->execute();
$records_result = $stmt->get_result();

// Fetch lab test results
$lab_sql = "SELECT 
                lot.order_test_id,
                lot.result_value,
                lot.result_unit,
                lot.reference_range,
                lot.interpretation,
                lot.abnormal_flag,
                lot.status,
                lo.order_number,
                lo.ordered_at,
                lo.completed_at,
                ett.test_name,
                ett.category,
                u.full_name as ordered_by_name
            FROM lab_order_tests lot
            INNER JOIN lab_orders lo ON lot.order_id = lo.order_id
            INNER JOIN ent_test_types ett ON lot.test_type_id = ett.test_type_id
            LEFT JOIN users u ON lo.ordered_by = u.user_id
            WHERE lo.patient_id = ?
            AND lot.status = 'COMPLETED'
            ORDER BY lo.completed_at DESC
            LIMIT 20";

$stmt = $conn->prepare($lab_sql);
$stmt->bind_param("i", $patient_id);
$stmt->execute();
$lab_results = $stmt->get_result();

// Fetch prescriptions
$prescription_sql = "SELECT 
                        pr.prescription_id, pr.medication_name, pr.dosage,
                        pr.frequency, pr.duration, pr.instructions,
                        pr.prescribed_date, pr.status,
                        d.full_name as doctor_name, a.appointment_date
                    FROM prescriptions pr
                    INNER JOIN users d ON pr.doctor_id = d.user_id
                    LEFT JOIN appointments a ON pr.appointment_id = a.appointment_id
                    WHERE pr.patient_id = ?
                    ORDER BY pr.prescribed_date DESC
                    LIMIT 20";

$stmt = $conn->prepare($prescription_sql);
$stmt->bind_param("i", $patient_id);
$stmt->execute();
$prescriptions_result = $stmt->get_result();

// Fetch vital signs
$vitals_sql = "SELECT 
                    v.vital_id, v.recorded_date, v.blood_pressure,
                    v.temperature, v.pulse_rate, v.respiratory_rate,
                    v.weight, v.height, v.bmi, v.oxygen_saturation,
                    n.full_name as nurse_name
                FROM vital_signs v
                LEFT JOIN users n ON v.recorded_by = n.user_id
                WHERE v.patient_id = ?
                ORDER BY v.recorded_date DESC
                LIMIT 10";

$stmt = $conn->prepare($vitals_sql);
$stmt->bind_param("i", $patient_id);
$stmt->execute();
$vitals_result = $stmt->get_result();

// Get statistics
$stats_sql = "SELECT 
                (SELECT COUNT(*) FROM appointments WHERE patient_id = ? AND status = 'COMPLETED') as total_visits,
                (SELECT COUNT(*) FROM lab_order_tests lot 
                 INNER JOIN lab_orders lo ON lot.order_id = lo.order_id 
                 WHERE lo.patient_id = ? AND lot.status = 'COMPLETED') as total_lab_tests,
                (SELECT COUNT(*) FROM prescriptions WHERE patient_id = ?) as total_prescriptions,
                (SELECT MAX(appointment_date) FROM appointments WHERE patient_id = ? AND status = 'COMPLETED') as last_visit";

$stmt = $conn->prepare($stats_sql);
$stmt->bind_param("iiii", $patient_id, $patient_id, $patient_id, $patient_id);
$stmt->execute();
$stats = $stmt->get_result()->fetch_assoc();
?>

<?php include 'layouts/main.php'; ?>

<head>
    <?php includeFileWithVariables('layouts/title-meta.php', array('title' => 'Medical Records')); ?>
    <?php include 'layouts/head-css.php'; ?>
    <link href="assets/libs/sweetalert2/sweetalert2.min.css" rel="stylesheet">
    
    <style>
        .patient-header-card {
            background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
            border-radius: 12px;
            padding: 2rem;
            color: white;
            margin-bottom: 2rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        
        .patient-header-content {
            display: flex;
            align-items: center;
            gap: 2rem;
        }
        
        .patient-avatar-large {
            width: 80px;
            height: 80px;
            border-radius: 12px;
            background: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            font-weight: 700;
            border: 3px solid rgba(255, 255, 255, 0.3);
        }
        
        .tabs-container {
            background: white;
            border-radius: 12px;
            box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
            border: 1px solid #e2e8f0;
            margin-bottom: 2rem;
        }
        
        .nav-tabs-custom {
            border-bottom: 2px solid #f1f5f9;
            padding: 1rem 1.5rem 0;
            display: flex;
            gap: 1rem;
            overflow-x: auto;
        }
        
        .nav-tab {
            padding: 0.75rem 1.5rem;
            border: none;
            background: none;
            color: #64748b;
            font-weight: 600;
            cursor: pointer;
            border-bottom: 3px solid transparent;
            transition: all 0.2s;
            white-space: nowrap;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .nav-tab:hover {
            color: #3b82f6;
        }
        
        .nav-tab.active {
            color: #3b82f6;
            border-bottom-color: #3b82f6;
        }
        
        .tab-content {
            padding: 1.5rem;
        }
        
        .tab-pane {
            display: none;
        }
        
        .tab-pane.active {
            display: block;
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1rem;
            margin-bottom: 2rem;
        }
        
        .stat-card {
            background: white;
            border-radius: 10px;
            padding: 1.25rem;
            border: 1px solid #e2e8f0;
            transition: all 0.2s;
        }
        
        .stat-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        
        .stat-value {
            font-size: 1.5rem;
            font-weight: 700;
            color: #1e293b;
            margin-bottom: 0.5rem;
        }
        
        .stat-label {
            color: #64748b;
            font-size: 0.875rem;
        }
        
        .record-card {
            background: white;
            border: 1px solid #e2e8f0;
            border-radius: 10px;
            padding: 1.5rem;
            margin-bottom: 1rem;
            transition: all 0.2s;
        }
        
        .record-card:hover {
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        
        .record-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
            padding-bottom: 0.75rem;
            border-bottom: 1px solid #f1f5f9;
        }
        
        .record-date {
            font-size: 1.125rem;
            font-weight: 600;
            color: #3b82f6;
        }
        
        .record-time {
            color: #64748b;
            font-size: 0.875rem;
        }
        
        .record-detail {
            margin-bottom: 0.75rem;
        }
        
        .record-label {
            font-weight: 600;
            color: #475569;
            font-size: 0.875rem;
        }
        
        .record-value {
            color: #1e293b;
            margin-top: 0.25rem;
        }
        
        .badge-status {
            padding: 0.25rem 0.75rem;
            border-radius: 6px;
            font-size: 0.75rem;
            font-weight: 600;
        }
        
        .badge-completed {
            background: #d1fae5;
            color: #065f46;
        }
        
        .badge-in-progress {
            background: #fef3c7;
            color: #92400e;
        }
        
        .empty-state {
            text-align: center;
            padding: 3rem 1rem;
            color: #64748b;
        }
        
        .empty-state i {
            font-size: 3rem;
            color: #cbd5e1;
            margin-bottom: 1rem;
        }
        
        .alert-box {
            background: #fee2e2;
            border: 1px solid #fecaca;
            border-radius: 8px;
            padding: 1rem;
            margin-bottom: 1rem;
        }
        
        .alert-box strong {
            color: #991b1b;
        }
        
        .alert-box p {
            color: #7f1d1d;
            margin: 0.5rem 0 0 0;
        }
        
        @media (max-width: 768px) {
            .patient-header-content {
                flex-direction: column;
                text-align: center;
            }
            
            .stats-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>

<body>
    <div id="layout-wrapper">
        <?php include 'layouts/menu.php'; ?>
        
        <div class="main-content">
            <div class="page-content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-12">
                            <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                                <h4 class="mb-sm-0">Medical Records</h4>
                                <div class="page-title-right">
                                    <ol class="breadcrumb m-0">
                                        <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
                                        <li class="breadcrumb-item"><a href="list_patients.php">Patients</a></li>
                                        <li class="breadcrumb-item active">Medical Records</li>
                                    </ol>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Patient Header -->
                    <div class="patient-header-card">
                        <div class="patient-header-content">
                            <div class="patient-avatar-large">
                                <?php echo strtoupper(substr($patient['full_name'], 0, 2)); ?>
                            </div>
                            <div>
                                <h2 style="margin: 0 0 0.5rem 0;"><?php echo htmlspecialchars($patient['full_name']); ?></h2>
                                <p style="margin: 0; opacity: 0.9;">
                                    <?php echo htmlspecialchars($patient['patient_number']); ?> • 
                                    <?php echo $patient['age']; ?> years, <?php echo ucfirst(strtolower($patient['gender'])); ?> • 
                                    <?php echo htmlspecialchars($patient['phone_primary']); ?>
                                </p>
                            </div>
                        </div>
                    </div>

                    <!-- Medical Alerts -->
                    <?php if (!empty($patient['allergies'])): ?>
                    <div class="alert-box">
                        <strong><i class="ri-alert-line me-1"></i>Allergies:</strong>
                        <p><?php echo nl2br(htmlspecialchars($patient['allergies'])); ?></p>
                    </div>
                    <?php endif; ?>

                    <!-- Statistics -->
                    <div class="stats-grid">
                        <div class="stat-card">
                            <div class="stat-value"><?php echo number_format($stats['total_visits']); ?></div>
                            <div class="stat-label">Total Visits</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-value"><?php echo number_format($stats['total_lab_tests']); ?></div>
                            <div class="stat-label">Lab Tests</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-value"><?php echo number_format($stats['total_prescriptions']); ?></div>
                            <div class="stat-label">Prescriptions</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-value"><?php echo $stats['last_visit'] ? date('d M Y', strtotime($stats['last_visit'])) : 'N/A'; ?></div>
                            <div class="stat-label">Last Visit</div>
                        </div>
                    </div>

                    <!-- Tabs -->
                    <div class="tabs-container">
                        <div class="nav-tabs-custom">
                            <button class="nav-tab active" onclick="showTab('consultations')">
                                <i class="ri-stethoscope-line"></i> Consultations
                            </button>
                            <button class="nav-tab" onclick="showTab('lab')">
                                <i class="ri-flask-line"></i> Lab Results
                            </button>
                            <button class="nav-tab" onclick="showTab('prescriptions')">
                                <i class="ri-capsule-line"></i> Prescriptions
                            </button>
                            <button class="nav-tab" onclick="showTab('vitals')">
                                <i class="ri-heart-pulse-line"></i> Vital Signs
                            </button>
                        </div>
                        
                        <div class="tab-content">
                            <!-- Consultations Tab -->
                            <div id="consultations" class="tab-pane active">
                                <?php if ($records_result->num_rows > 0): ?>
                                    <?php while ($record = $records_result->fetch_assoc()): ?>
                                    <div class="record-card">
                                        <div class="record-header">
                                            <div>
                                                <div class="record-date">
                                                    <?php echo date('d M Y', strtotime($record['appointment_date'])); ?>
                                                </div>
                                                <div class="record-time">
                                                    <i class="ri-time-line"></i> <?php echo date('h:i A', strtotime($record['appointment_time'])); ?>
                                                </div>
                                            </div>
                                            <span class="badge-status badge-<?php echo strtolower(str_replace('_', '-', $record['appointment_status'])); ?>">
                                                <?php echo str_replace('_', ' ', $record['appointment_status']); ?>
                                            </span>
                                        </div>
                                        
                                        <div class="record-detail">
                                            <div class="record-label">Appointment Number</div>
                                            <div class="record-value"><?php echo htmlspecialchars($record['appointment_number']); ?></div>
                                        </div>
                                        
                                        <div class="record-detail">
                                            <div class="record-label">Appointment Type</div>
                                            <div class="record-value"><?php echo str_replace('_', ' ', $record['appointment_type']); ?></div>
                                        </div>
                                        
                                        <div class="record-detail">
                                            <div class="record-label">Doctor</div>
                                            <div class="record-value"><?php echo htmlspecialchars($record['doctor_name']); ?></div>
                                        </div>
                                        
                                        <?php if ($record['chief_complaint']): ?>
                                        <div class="record-detail">
                                            <div class="record-label">Chief Complaint</div>
                                            <div class="record-value"><?php echo nl2br(htmlspecialchars($record['chief_complaint'])); ?></div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php if ($record['room_number']): ?>
                                        <div class="record-detail">
                                            <div class="record-label">Room</div>
                                            <div class="record-value"><?php echo htmlspecialchars($record['room_number']); ?></div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php if ($record['notes']): ?>
                                        <div class="record-detail">
                                            <div class="record-label">Notes</div>
                                            <div class="record-value"><?php echo nl2br(htmlspecialchars($record['notes'])); ?></div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php if ($record['completed_at']): ?>
                                        <div class="record-detail">
                                            <div class="record-label">Completed At</div>
                                            <div class="record-value">
                                                <i class="ri-check-line"></i> <?php echo date('d M Y h:i A', strtotime($record['completed_at'])); ?>
                                            </div>
                                        </div>
                                        <?php endif; ?>
                                    </div>
                                    <?php endwhile; ?>
                                <?php else: ?>
                                    <div class="empty-state">
                                        <i class="ri-stethoscope-line"></i>
                                        <h5>No Consultation Records</h5>
                                        <p>No completed consultations found for this patient.</p>
                                    </div>
                                <?php endif; ?>
                            </div>

                            <!-- Lab Results Tab -->
                            <div id="lab" class="tab-pane">
                                <?php if ($lab_results->num_rows > 0): ?>
                                    <?php while ($lab = $lab_results->fetch_assoc()): ?>
                                    <div class="record-card">
                                        <div class="record-header">
                                            <div>
                                                <div class="record-date"><?php echo htmlspecialchars($lab['test_name']); ?></div>
                                                <div class="record-time">
                                                    <i class="ri-flask-line"></i> <?php echo htmlspecialchars($lab['category']); ?>
                                                </div>
                                            </div>
                                            <?php if ($lab['abnormal_flag']): ?>
                                            <span class="badge-status badge-<?php echo strtolower($lab['abnormal_flag']); ?>">
                                                <?php echo $lab['abnormal_flag']; ?>
                                            </span>
                                            <?php endif; ?>
                                        </div>
                                        
                                        <div class="record-detail">
                                            <div class="record-label">Order Number</div>
                                            <div class="record-value"><?php echo htmlspecialchars($lab['order_number']); ?></div>
                                        </div>
                                        
                                        <?php if ($lab['result_value']): ?>
                                        <div class="record-detail">
                                            <div class="record-label">Result</div>
                                            <div class="record-value">
                                                <?php echo htmlspecialchars($lab['result_value']); ?>
                                                <?php if ($lab['result_unit']): ?>
                                                    <?php echo htmlspecialchars($lab['result_unit']); ?>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php if ($lab['reference_range']): ?>
                                        <div class="record-detail">
                                            <div class="record-label">Reference Range</div>
                                            <div class="record-value"><?php echo htmlspecialchars($lab['reference_range']); ?></div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php if ($lab['interpretation']): ?>
                                        <div class="record-detail">
                                            <div class="record-label">Interpretation</div>
                                            <div class="record-value"><?php echo nl2br(htmlspecialchars($lab['interpretation'])); ?></div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <div class="record-detail">
                                            <div class="record-label">Ordered By</div>
                                            <div class="record-value"><?php echo htmlspecialchars($lab['ordered_by_name']); ?></div>
                                        </div>
                                        
                                        <?php if ($lab['completed_at']): ?>
                                        <div class="record-detail">
                                            <div class="record-label">Completed</div>
                                            <div class="record-value">
                                                <i class="ri-calendar-check-line"></i> <?php echo date('d M Y h:i A', strtotime($lab['completed_at'])); ?>
                                            </div>
                                        </div>
                                        <?php endif; ?>
                                    </div>
                                    <?php endwhile; ?>
                                <?php else: ?>
                                    <div class="empty-state">
                                        <i class="ri-flask-line"></i>
                                        <h5>No Lab Results</h5>
                                        <p>No lab test results found for this patient.</p>
                                    </div>
                                <?php endif; ?>
                            </div>

                            <!-- Prescriptions Tab -->
                            <div id="prescriptions" class="tab-pane">
                                <?php if ($prescriptions_result->num_rows > 0): ?>
                                    <?php while ($rx = $prescriptions_result->fetch_assoc()): ?>
                                    <div class="record-card">
                                        <div class="record-header">
                                            <div>
                                                <div class="record-date"><?php echo htmlspecialchars($rx['medication_name']); ?></div>
                                                <div class="record-time">
                                                    <i class="ri-calendar-line"></i> <?php echo date('d M Y', strtotime($rx['prescribed_date'])); ?>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <div class="record-detail">
                                            <div class="record-label">Dosage</div>
                                            <div class="record-value"><?php echo htmlspecialchars($rx['dosage']); ?></div>
                                        </div>
                                        
                                        <div class="record-detail">
                                            <div class="record-label">Frequency</div>
                                            <div class="record-value"><?php echo htmlspecialchars($rx['frequency']); ?></div>
                                        </div>
                                        
                                        <div class="record-detail">
                                            <div class="record-label">Duration</div>
                                            <div class="record-value"><?php echo htmlspecialchars($rx['duration']); ?></div>
                                        </div>
                                        
                                        <?php if ($rx['instructions']): ?>
                                        <div class="record-detail">
                                            <div class="record-label">Instructions</div>
                                            <div class="record-value"><?php echo nl2br(htmlspecialchars($rx['instructions'])); ?></div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <div class="record-detail">
                                            <div class="record-label">Prescribed By</div>
                                            <div class="record-value"><?php echo htmlspecialchars($rx['doctor_name']); ?></div>
                                        </div>
                                    </div>
                                    <?php endwhile; ?>
                                <?php else: ?>
                                    <div class="empty-state">
                                        <i class="ri-capsule-line"></i>
                                        <h5>No Prescriptions</h5>
                                        <p>No prescriptions found for this patient.</p>
                                    </div>
                                <?php endif; ?>
                            </div>

                            <!-- Vital Signs Tab -->
                            <div id="vitals" class="tab-pane">
                                <?php if ($vitals_result->num_rows > 0): ?>
                                    <?php while ($vital = $vitals_result->fetch_assoc()): ?>
                                    <div class="record-card">
                                        <div class="record-header">
                                            <div>
                                                <div class="record-date"><?php echo date('d M Y', strtotime($vital['recorded_date'])); ?></div>
                                                <div class="record-time">
                                                    <i class="ri-time-line"></i> <?php echo date('h:i A', strtotime($vital['recorded_date'])); ?>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <div class="row">
                                            <div class="col-md-3">
                                                <div class="record-detail">
                                                    <div class="record-label">Blood Pressure</div>
                                                    <div class="record-value"><?php echo htmlspecialchars($vital['blood_pressure']); ?> mmHg</div>
                                                </div>
                                            </div>
                                            <div class="col-md-3">
                                                <div class="record-detail">
                                                    <div class="record-label">Temperature</div>
                                                    <div class="record-value"><?php echo htmlspecialchars($vital['temperature']); ?> °C</div>
                                                </div>
                                            </div>
                                            <div class="col-md-3">
                                                <div class="record-detail">
                                                    <div class="record-label">Pulse Rate</div>
                                                    <div class="record-value"><?php echo htmlspecialchars($vital['pulse_rate']); ?> bpm</div>
                                                </div>
                                            </div>
                                            <div class="col-md-3">
                                                <div class="record-detail">
                                                    <div class="record-label">Weight</div>
                                                    <div class="record-value"><?php echo htmlspecialchars($vital['weight']); ?> kg</div>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <?php if ($vital['nurse_name']): ?>
                                        <div class="record-detail mt-2">
                                            <div class="record-label">Recorded By</div>
                                            <div class="record-value"><?php echo htmlspecialchars($vital['nurse_name']); ?></div>
                                        </div>
                                        <?php endif; ?>
                                    </div>
                                    <?php endwhile; ?>
                                <?php else: ?>
                                    <div class="empty-state">
                                        <i class="ri-heart-pulse-line"></i>
                                        <h5>No Vital Signs</h5>
                                        <p>No vital signs recorded for this patient.</p>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include 'layouts/footer.php'; ?>
        </div>
    </div>

    <?php include 'layouts/vendor-scripts.php'; ?>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    
    <script>
    function showTab(tabName) {
        // Hide all tabs
        document.querySelectorAll('.tab-pane').forEach(pane => {
            pane.classList.remove('active');
        });
        
        // Remove active from all nav tabs
        document.querySelectorAll('.nav-tab').forEach(tab => {
            tab.classList.remove('active');
        });
        
        // Show selected tab
        document.getElementById(tabName).classList.add('active');
        
        // Activate clicked nav tab
        event.target.closest('.nav-tab').classList.add('active');
    }
    </script>

    <script src="assets/js/app.js"></script>
</body>
</html>