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

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

// Get provider ID
$provider_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($provider_id <= 0) {
    header("Location: list_insurance_providers.php");
    exit();
}

// Fetch provider details
$query = "SELECT * FROM insurance_providers WHERE provider_id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $provider_id);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows === 0) {
    header("Location: list_insurance_providers.php");
    exit();
}

$provider = $result->fetch_assoc();

// Get statistics
$stats_query = "SELECT 
                COUNT(DISTINCT p.patient_id) as total_patients,
                COUNT(DISTINCT CASE WHEN p.is_active = 1 THEN p.patient_id END) as active_patients,
                COUNT(DISTINCT v.visit_id) as total_visits,
                COALESCE(SUM(i.total_amount), 0) as total_billed,
                COALESCE(SUM(i.amount_paid), 0) as total_paid,
                COALESCE(SUM(i.insurance_covered), 0) as total_claimed
                FROM patients p
                LEFT JOIN patient_visits v ON p.patient_id = v.patient_id
                LEFT JOIN invoices i ON p.patient_id = i.patient_id
                WHERE p.insurance_provider_id = ?";
$stats_stmt = $conn->prepare($stats_query);
$stats_stmt->bind_param("i", $provider_id);
$stats_stmt->execute();
$stats = $stats_stmt->get_result()->fetch_assoc();

// Get recent patients (limit 10)
$patients_query = "SELECT 
                    p.patient_id, u.full_name, p.patient_number, p.insurance_number,
                    p.policy_number, p.is_active, p.created_at,
                    COUNT(DISTINCT v.visit_id) as visit_count
                   FROM patients p
                   INNER JOIN users u ON p.user_id = u.user_id
                   LEFT JOIN patient_visits v ON p.patient_id = v.patient_id
                   WHERE p.insurance_provider_id = ?
                   GROUP BY p.patient_id, u.full_name, p.patient_number, p.insurance_number, p.policy_number, p.is_active, p.created_at
                   ORDER BY p.created_at DESC LIMIT 10";
$patients_stmt = $conn->prepare($patients_query);
$patients_stmt->bind_param("i", $provider_id);
$patients_stmt->execute();
$patients_result = $patients_stmt->get_result();

// Get recent pre-authorizations
$preauth_query = "SELECT pa.preauth_id, pa.preauth_number, pa.auth_status, pa.request_date,
                   pa.requested_amount, pa.approved_amount, u.full_name as patient_name
                  FROM insurance_pre_authorizations pa
                  INNER JOIN patients p ON pa.patient_id = p.patient_id
                  INNER JOIN users u ON p.user_id = u.user_id
                  WHERE pa.provider_id = ? ORDER BY pa.request_date DESC LIMIT 10";
$preauth_stmt = $conn->prepare($preauth_query);
$preauth_stmt->bind_param("i", $provider_id);
$preauth_stmt->execute();
$preauth_result = $preauth_stmt->get_result();

// Get recent claims
$claims_query = "SELECT ic.claim_id, ic.claim_number, ic.claim_status, ic.claim_date,
                  ic.claim_amount, ic.approved_amount, u.full_name as patient_name
                 FROM insurance_claims ic
                 INNER JOIN patients p ON ic.patient_id = p.patient_id
                 INNER JOIN users u ON p.user_id = u.user_id
                 WHERE ic.provider_id = ? ORDER BY ic.claim_date DESC LIMIT 10";
$claims_stmt = $conn->prepare($claims_query);
$claims_stmt->bind_param("i", $provider_id);
$claims_stmt->execute();
$claims_result = $claims_stmt->get_result();

$initials = strtoupper(substr($provider['provider_name'], 0, 2));
$colors = ['#3b82f6', '#ef4444', '#10b981', '#f59e0b', '#8b5cf6', '#ec4899'];
$color = $colors[ord($initials[0]) % count($colors)];
?>

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

<head>
    <?php includeFileWithVariables('layouts/title-meta.php', array('title' => htmlspecialchars($provider['provider_name']))); ?>
    <?php include 'layouts/head-css.php'; ?>
    
    <style>
        .stats-card {
            background: white;
            border-radius: 12px;
            padding: 1.5rem;
            box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
            border: 1px solid #e2e8f0;
            transition: all 0.3s;
        }
        
        .stats-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        
        .stats-icon {
            width: 48px;
            height: 48px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
        }
        
        .stats-value {
            font-size: 1.875rem;
            font-weight: 700;
            color: #1e293b;
        }
        
        .stats-label {
            color: #64748b;
            font-size: 0.875rem;
            font-weight: 500;
        }
        
        .info-card {
            background: white;
            border-radius: 12px;
            box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
            border: 1px solid #e2e8f0;
            margin-bottom: 1.5rem;
            overflow: hidden;
        }
        
        .info-card-header {
            padding: 1.25rem 1.5rem;
            border-bottom: 1px solid #e2e8f0;
            background: #f8fafc;
        }
        
        .info-card-header h5 {
            margin: 0;
            font-weight: 600;
            color: #1e293b;
            font-size: 1rem;
        }
        
        .info-card-body {
            padding: 1.5rem;
        }
        
        .info-row {
            display: flex;
            justify-content: space-between;
            padding: 0.875rem 0;
            border-bottom: 1px solid #f1f5f9;
        }
        
        .info-row:last-child {
            border-bottom: none;
        }
        
        .info-label {
            font-weight: 500;
            color: #64748b;
            font-size: 0.875rem;
        }
        
        .info-value {
            color: #1e293b;
            font-weight: 500;
            font-size: 0.875rem;
            text-align: right;
        }
        
        .badge {
            padding: 0.375rem 0.75rem;
            border-radius: 6px;
            font-weight: 500;
            font-size: 0.75rem;
            text-transform: uppercase;
        }
        
        .badge-active {
            background: #d1fae5;
            color: #065f46;
        }
        
        .badge-inactive {
            background: #fee2e2;
            color: #991b1b;
        }
        
        .badge-smart {
            background: #dbeafe;
            color: #1e40af;
        }
        
        .custom-table {
            width: 100%;
            margin: 0;
        }
        
        .custom-table thead th {
            background: #f8fafc;
            border-bottom: 2px solid #e2e8f0;
            color: #475569;
            font-weight: 600;
            font-size: 0.875rem;
            text-transform: uppercase;
            padding: 1rem;
        }
        
        .custom-table tbody td {
            padding: 1rem;
            vertical-align: middle;
            border-bottom: 1px solid #f1f5f9;
            font-size: 0.875rem;
        }
        
        .custom-table tbody tr:hover {
            background: #f8fafc;
        }
        
        .empty-state {
            text-align: center;
            padding: 3rem;
            color: #64748b;
        }
        
        .empty-state i {
            font-size: 3rem;
            color: #cbd5e1;
            margin-bottom: 1rem;
        }
        
        .provider-logo-lg {
            width: 80px;
            height: 80px;
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            color: white;
            font-size: 1.5rem;
        }
    </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">
                                <div class="d-flex align-items-center">
                                    <a href="list_insurance_providers.php" class="btn btn-light btn-sm me-3">
                                        <i class="ri-arrow-left-line"></i> Back
                                    </a>
                                    <h4 class="mb-0"><?php echo htmlspecialchars($provider['provider_name']); ?></h4>
                                </div>
                                <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_insurance_providers.php">Providers</a></li>
                                        <li class="breadcrumb-item active"><?php echo htmlspecialchars($provider['provider_name']); ?></li>
                                    </ol>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Provider Header Card -->
                    <div class="info-card mb-4">
                        <div class="info-card-body">
                            <div class="row align-items-center">
                                <div class="col-auto">
                                    <div class="provider-logo-lg" style="background: <?php echo $color; ?>;">
                                        <?php echo $initials; ?>
                                    </div>
                                </div>
                                <div class="col">
                                    <h3 class="mb-2"><?php echo htmlspecialchars($provider['provider_name']); ?></h3>
                                    <div class="d-flex align-items-center gap-2 flex-wrap">
                                        <span class="badge <?php echo $provider['is_active'] ? 'badge-active' : 'badge-inactive'; ?>">
                                            <?php echo $provider['is_active'] ? 'Active' : 'Inactive'; ?>
                                        </span>
                                        <?php if ($provider['smart_enabled']): ?>
                                        <span class="badge badge-smart">
                                            <i class="ri-flashlight-line me-1"></i>SMART Enabled
                                        </span>
                                        <?php endif; ?>
                                        <span class="badge" style="background: #f1f5f9; color: #475569;">
                                            Code: <?php echo htmlspecialchars($provider['provider_code']); ?>
                                        </span>
                                    </div>
                                </div>
                                <?php if (in_array($_SESSION['role_code'], ['SUPER_ADMIN', 'HOSPITAL_ADMIN'])): ?>
                                <div class="col-auto">
                                    <a href="edit_insurance_provider.php?id=<?php echo $provider_id; ?>" class="btn btn-primary">
                                        <i class="ri-edit-line me-1"></i> Edit Provider
                                    </a>
                                </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>

                    <!-- Statistics Cards -->
                    <div class="row mb-4">
                        <div class="col-xl-3 col-md-6 mb-3">
                            <div class="stats-card">
                                <div class="stats-icon" style="background: #dbeafe;">
                                    <i class="ri-user-line" style="color: #1e40af;"></i>
                                </div>
                                <div class="stats-value"><?php echo number_format($stats['total_patients']); ?></div>
                                <div class="stats-label">Total Patients</div>
                            </div>
                        </div>
                        <div class="col-xl-3 col-md-6 mb-3">
                            <div class="stats-card">
                                <div class="stats-icon" style="background: #d1fae5;">
                                    <i class="ri-user-check-line" style="color: #065f46;"></i>
                                </div>
                                <div class="stats-value"><?php echo number_format($stats['active_patients']); ?></div>
                                <div class="stats-label">Active Patients</div>
                            </div>
                        </div>
                        <div class="col-xl-3 col-md-6 mb-3">
                            <div class="stats-card">
                                <div class="stats-icon" style="background: #fef3c7;">
                                    <i class="ri-calendar-check-line" style="color: #92400e;"></i>
                                </div>
                                <div class="stats-value"><?php echo number_format($stats['total_visits']); ?></div>
                                <div class="stats-label">Total Visits</div>
                            </div>
                        </div>
                        <div class="col-xl-3 col-md-6 mb-3">
                            <div class="stats-card">
                                <div class="stats-icon" style="background: #e0e7ff;">
                                    <i class="ri-money-dollar-circle-line" style="color: #3730a3;"></i>
                                </div>
                                <div class="stats-value" style="font-size: 1.5rem;">KES <?php echo number_format($stats['total_billed'], 0); ?></div>
                                <div class="stats-label">Total Billed</div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <!-- Left Column -->
                        <div class="col-lg-4">
                            <!-- Contact Information -->
                            <div class="info-card">
                                <div class="info-card-header">
                                    <h5><i class="ri-contacts-line me-2"></i>Contact Information</h5>
                                </div>
                                <div class="info-card-body">
                                    <?php if ($provider['contact_person'] || $provider['phone'] || $provider['email'] || $provider['address']): ?>
                                        <?php if ($provider['contact_person']): ?>
                                        <div class="info-row">
                                            <div class="info-label">Contact Person</div>
                                            <div class="info-value"><?php echo htmlspecialchars($provider['contact_person']); ?></div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php if ($provider['phone']): ?>
                                        <div class="info-row">
                                            <div class="info-label">Phone</div>
                                            <div class="info-value">
                                                <i class="ri-phone-line me-1"></i><?php echo htmlspecialchars($provider['phone']); ?>
                                            </div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php if ($provider['email']): ?>
                                        <div class="info-row">
                                            <div class="info-label">Email</div>
                                            <div class="info-value">
                                                <i class="ri-mail-line me-1"></i><?php echo htmlspecialchars($provider['email']); ?>
                                            </div>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php if ($provider['address']): ?>
                                        <div class="info-row">
                                            <div class="info-label">Address</div>
                                            <div class="info-value"><?php echo htmlspecialchars($provider['address']); ?></div>
                                        </div>
                                        <?php endif; ?>
                                    <?php else: ?>
                                        <div class="empty-state" style="padding: 2rem;">
                                            <i class="ri-contacts-line"></i>
                                            <p class="mb-0">No contact information available</p>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <!-- Coverage & Billing -->
                            <div class="info-card">
                                <div class="info-card-header">
                                    <h5><i class="ri-money-dollar-circle-line me-2"></i>Coverage & Billing</h5>
                                </div>
                                <div class="info-card-body">
                                    <?php if ($provider['consultation_rate']): ?>
                                    <div class="info-row">
                                        <div class="info-label">Consultation Rate</div>
                                        <div class="info-value">KES <?php echo number_format($provider['consultation_rate']); ?></div>
                                    </div>
                                    <?php endif; ?>
                                    
                                    <?php if ($provider['coverage_limit']): ?>
                                    <div class="info-row">
                                        <div class="info-label">Coverage Limit</div>
                                        <div class="info-value">KES <?php echo number_format($provider['coverage_limit']); ?></div>
                                    </div>
                                    <?php endif; ?>
                                    
                                    <div class="info-row">
                                        <div class="info-label">Coverage %</div>
                                        <div class="info-value">
                                            <span class="badge" style="background: #d1fae5; color: #065f46;">
                                                <?php echo number_format($provider['coverage_percentage'], 1); ?>%
                                            </span>
                                        </div>
                                    </div>
                                    
                                    <div class="info-row">
                                        <div class="info-label">Copay %</div>
                                        <div class="info-value">
                                            <span class="badge" style="background: #fef3c7; color: #92400e;">
                                                <?php echo number_format($provider['copay_percentage'], 1); ?>%
                                            </span>
                                        </div>
                                    </div>
                                    
                                    <div class="info-row">
                                        <div class="info-label">Processing Days</div>
                                        <div class="info-value"><?php echo $provider['claim_processing_days']; ?> days</div>
                                    </div>
                                </div>
                            </div>

                            <!-- SMART Integration -->
                            <?php if ($provider['smart_enabled']): ?>
                            <div class="info-card">
                                <div class="info-card-header">
                                    <h5><i class="ri-flashlight-line me-2"></i>SMART Integration</h5>
                                </div>
                                <div class="info-card-body">
                                    <div class="info-row">
                                        <div class="info-label">SMART Enabled</div>
                                        <div class="info-value">
                                            <span class="badge badge-smart"><i class="ri-check-line me-1"></i>Yes</span>
                                        </div>
                                    </div>
                                    
                                    <?php if ($provider['smart_provider_key']): ?>
                                    <div class="info-row">
                                        <div class="info-label">Provider Key</div>
                                        <div class="info-value">
                                            <code style="background: #f1f5f9; padding: 0.25rem 0.5rem; border-radius: 4px; font-size: 0.75rem;">
                                                <?php echo htmlspecialchars($provider['smart_provider_key']); ?>
                                            </code>
                                        </div>
                                    </div>
                                    <?php endif; ?>
                                    
                                    <?php if ($provider['smart_medical_aid_code']): ?>
                                    <div class="info-row">
                                        <div class="info-label">Medical Aid Code</div>
                                        <div class="info-value">
                                            <code style="background: #f1f5f9; padding: 0.25rem 0.5rem; border-radius: 4px; font-size: 0.75rem;">
                                                <?php echo htmlspecialchars($provider['smart_medical_aid_code']); ?>
                                            </code>
                                        </div>
                                    </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <?php endif; ?>

                            <!-- Financial Summary -->
                            <div class="info-card">
                                <div class="info-card-header">
                                    <h5><i class="ri-line-chart-line me-2"></i>Financial Summary</h5>
                                </div>
                                <div class="info-card-body">
                                    <div class="info-row">
                                        <div class="info-label">Total Billed</div>
                                        <div class="info-value"><strong>KES <?php echo number_format($stats['total_billed'], 2); ?></strong></div>
                                    </div>
                                    <div class="info-row">
                                        <div class="info-label">Total Paid</div>
                                        <div class="info-value" style="color: #10b981;">KES <?php echo number_format($stats['total_paid'], 2); ?></div>
                                    </div>
                                    <div class="info-row">
                                        <div class="info-label">Insurance Covered</div>
                                        <div class="info-value">KES <?php echo number_format($stats['total_claimed'], 2); ?></div>
                                    </div>
                                    <div class="info-row">
                                        <div class="info-label">Outstanding</div>
                                        <div class="info-value" style="color: #ef4444;">
                                            <strong>KES <?php echo number_format($stats['total_billed'] - $stats['total_paid'], 2); ?></strong>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Right Column -->
                        <div class="col-lg-8">
                            <!-- Recent Patients -->
                            <div class="info-card">
                                <div class="info-card-header">
                                    <h5 class="mb-0"><i class="ri-user-line me-2"></i>Recent Patients</h5>
                                </div>
                                <div class="table-responsive">
                                    <?php if ($patients_result && $patients_result->num_rows > 0): ?>
                                    <table class="custom-table">
                                        <thead>
                                            <tr>
                                                <th>Patient</th>
                                                <th>Patient No.</th>
                                                <th>Insurance No.</th>
                                                <th>Policy No.</th>
                                                <th>Visits</th>
                                                <th>Status</th>
                                                <th>Registered</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php while($patient = $patients_result->fetch_assoc()): ?>
                                            <tr>
                                                <td><a href="patient_profile.php?id=<?php echo $patient['patient_id']; ?>" style="font-weight: 600;"><?php echo htmlspecialchars($patient['full_name']); ?></a></td>
                                                <td><?php echo htmlspecialchars($patient['patient_number']); ?></td>
                                                <td><?php echo htmlspecialchars($patient['insurance_number'] ?: '-'); ?></td>
                                                <td><?php echo htmlspecialchars($patient['policy_number'] ?: '-'); ?></td>
                                                <td><span class="badge" style="background: #dbeafe; color: #1e40af;"><?php echo $patient['visit_count']; ?></span></td>
                                                <td><span class="badge <?php echo $patient['is_active'] ? 'badge-active' : 'badge-inactive'; ?>"><?php echo $patient['is_active'] ? 'Active' : 'Inactive'; ?></span></td>
                                                <td><?php echo date('M j, Y', strtotime($patient['created_at'])); ?></td>
                                            </tr>
                                            <?php endwhile; ?>
                                        </tbody>
                                    </table>
                                    <?php else: ?>
                                    <div class="empty-state"><i class="ri-user-line"></i><h6>No Patients</h6><p class="mb-0">No patients registered with this provider yet</p></div>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <!-- Recent Pre-Authorizations -->
                            <div class="info-card">
                                <div class="info-card-header">
                                    <h5 class="mb-0"><i class="ri-file-shield-line me-2"></i>Recent Pre-Authorizations</h5>
                                </div>
                                <div class="table-responsive">
                                    <?php if ($preauth_result && $preauth_result->num_rows > 0): ?>
                                    <table class="custom-table">
                                        <thead>
                                            <tr><th>Preauth No.</th><th>Patient</th><th>Date</th><th>Requested</th><th>Approved</th><th>Status</th></tr>
                                        </thead>
                                        <tbody>
                                            <?php while($preauth = $preauth_result->fetch_assoc()): 
                                            $bg_colors = ['DRAFT'=>'#f1f5f9','SUBMITTED'=>'#dbeafe','PENDING'=>'#fef3c7','APPROVED'=>'#d1fae5','REJECTED'=>'#fee2e2','CANCELLED'=>'#f1f5f9'];
                                            $txt_colors = ['DRAFT'=>'#475569','SUBMITTED'=>'#1e40af','PENDING'=>'#92400e','APPROVED'=>'#065f46','REJECTED'=>'#991b1b','CANCELLED'=>'#475569'];
                                            ?>
                                            <tr>
                                                <td><a href="view_preauthorization.php?id=<?php echo $preauth['preauth_id']; ?>" style="font-weight: 600;"><?php echo htmlspecialchars($preauth['preauth_number']); ?></a></td>
                                                <td><?php echo htmlspecialchars($preauth['patient_name']); ?></td>
                                                <td><?php echo date('M j, Y', strtotime($preauth['request_date'])); ?></td>
                                                <td>KES <?php echo number_format($preauth['requested_amount'], 2); ?></td>
                                                <td><?php echo $preauth['approved_amount'] ? 'KES '.number_format($preauth['approved_amount'], 2) : '<span class="text-muted">-</span>'; ?></td>
                                                <td><span class="badge" style="background: <?php echo $bg_colors[$preauth['auth_status']]; ?>; color: <?php echo $txt_colors[$preauth['auth_status']]; ?>;"><?php echo $preauth['auth_status']; ?></span></td>
                                            </tr>
                                            <?php endwhile; ?>
                                        </tbody>
                                    </table>
                                    <?php else: ?>
                                    <div class="empty-state"><i class="ri-file-shield-line"></i><h6>No Pre-Authorizations</h6><p class="mb-0">No pre-authorizations yet</p></div>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <!-- Recent Claims -->
                            <div class="info-card">
                                <div class="info-card-header">
                                    <h5 class="mb-0"><i class="ri-file-text-line me-2"></i>Recent Claims</h5>
                                </div>
                                <div class="table-responsive">
                                    <?php if ($claims_result && $claims_result->num_rows > 0): ?>
                                    <table class="custom-table">
                                        <thead>
                                            <tr><th>Claim No.</th><th>Patient</th><th>Date</th><th>Amount</th><th>Approved</th><th>Status</th></tr>
                                        </thead>
                                        <tbody>
                                            <?php while($claim = $claims_result->fetch_assoc()): 
                                            $claim_bg = ['PENDING'=>'#fef3c7','SUBMITTED'=>'#dbeafe','UNDER_REVIEW'=>'#e0e7ff','APPROVED'=>'#d1fae5','REJECTED'=>'#fee2e2','PARTIAL'=>'#fef3c7','PAID'=>'#d1fae5'];
                                            $claim_txt = ['PENDING'=>'#92400e','SUBMITTED'=>'#1e40af','UNDER_REVIEW'=>'#3730a3','APPROVED'=>'#065f46','REJECTED'=>'#991b1b','PARTIAL'=>'#92400e','PAID'=>'#065f46'];
                                            ?>
                                            <tr>
                                                <td><a href="view_claim.php?id=<?php echo $claim['claim_id']; ?>" style="font-weight: 600;"><?php echo htmlspecialchars($claim['claim_number']); ?></a></td>
                                                <td><?php echo htmlspecialchars($claim['patient_name']); ?></td>
                                                <td><?php echo date('M j, Y', strtotime($claim['claim_date'])); ?></td>
                                                <td>KES <?php echo number_format($claim['claim_amount'], 2); ?></td>
                                                <td><?php echo $claim['approved_amount'] ? 'KES '.number_format($claim['approved_amount'], 2) : '<span class="text-muted">-</span>'; ?></td>
                                                <td><span class="badge" style="background: <?php echo $claim_bg[$claim['claim_status']]; ?>; color: <?php echo $claim_txt[$claim['claim_status']]; ?>;"><?php echo $claim['claim_status']; ?></span></td>
                                            </tr>
                                            <?php endwhile; ?>
                                        </tbody>
                                    </table>
                                    <?php else: ?>
                                    <div class="empty-state"><i class="ri-file-text-line"></i><h6>No Claims</h6><p class="mb-0">No claims submitted yet</p></div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include 'layouts/footer.php'; ?>
        </div>
    </div>

    <?php include 'layouts/vendor-scripts.php'; ?>
    <script src="assets/js/app.js"></script>
</body>
</html>