<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Staff Turnover Report - {{ hotelName() }} Management</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary-green: #1a936f;
            --secondary-green: #88d498;
            --light-green: #c6dabf;
            --dark-green: #114b5f;
            --accent: #f3e9d2;
            --light-gray: #f8f9fa;
            --medium-gray: #e9ecef;
            --text-dark: #343a40;
            --text-medium: #6c757d;
            --danger: #dc3545;
            --warning: #ffc107;
            --info: #17a2b8;
            --success: #28a745;
        }
        
        body {
            margin-right:250px;
            margin-left:250px;
            background-color: #f8f9fa;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            color: var(--text-dark);
        }
        
        .navbar {
            background: linear-gradient(90deg, var(--dark-green) 0%, var(--primary-green) 100%);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .main-content {
            margin: 20px;
            padding: 20px;
            margin-top: 20px;
        }
        
        /* Card Styling */
        .report-card {
            border-radius: 12px;
            border: none;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            margin-bottom: 25px;
            overflow: hidden;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .report-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
        }
        
        .card-header {
            background: linear-gradient(90deg, var(--primary-green) 0%, var(--secondary-green) 100%);
            color: white;
            border-radius: 12px 12px 0 0 !important;
            padding: 18px 25px;
            border-bottom: none;
        }
        
        .card-header h5, .card-header h6 {
            margin: 0;
            font-weight: 600;
        }
        
        .card-header i {
            margin-right: 10px;
        }
        
        /* Stats Card */
        .stats-card {
            border-radius: 12px;
            padding: 20px;
            background: white;
            box-shadow: 0 3px 15px rgba(0, 0, 0, 0.07);
            height: 100%;
            border-left: 5px solid var(--primary-green);
            transition: all 0.3s ease;
        }
        
        .stats-card:hover {
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
            transform: translateY(-3px);
        }
        
        .stats-icon {
            width: 60px;
            height: 60px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            margin-bottom: 15px;
        }
        
        .stats-icon.bg-primary {
            background: linear-gradient(135deg, var(--primary-green), var(--secondary-green));
            color: white;
        }
        
        .stats-icon.bg-success {
            background: linear-gradient(135deg, #28a745, #20c997);
            color: white;
        }
        
        .stats-icon.bg-danger {
            background: linear-gradient(135deg, #dc3545, #fd7e14);
            color: white;
        }
        
        .stats-icon.bg-warning {
            background: linear-gradient(135deg, #ffc107, #fd7e14);
            color: white;
        }
        
        .stats-icon.bg-info {
            background: linear-gradient(135deg, #17a2b8, #0dcaf0);
            color: white;
        }
        
        .stats-value {
            font-size: 32px;
            font-weight: 700;
            color: var(--dark-green);
            margin: 10px 0 5px 0;
            line-height: 1;
        }
        
        .stats-label {
            font-size: 14px;
            color: var(--text-medium);
            text-transform: uppercase;
            letter-spacing: 0.5px;
            font-weight: 500;
        }
        
        /* Turnover Rate Badge */
        .turnover-badge {
            display: inline-block;
            padding: 8px 16px;
            border-radius: 20px;
            font-weight: 600;
            font-size: 14px;
        }
        
        .turnover-low {
            background-color: rgba(40, 167, 69, 0.15);
            color: #28a745;
            border: 1px solid rgba(40, 167, 69, 0.3);
        }
        
        .turnover-medium {
            background-color: rgba(255, 193, 7, 0.15);
            color: #d39e00;
            border: 1px solid rgba(255, 193, 7, 0.3);
        }
        
        .turnover-high {
            background-color: rgba(220, 53, 69, 0.15);
            color: #dc3545;
            border: 1px solid rgba(220, 53, 69, 0.3);
        }
        
        /* Table Styling */
        .report-table {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
        }
        
        .report-table thead th {
            background-color: var(--light-gray);
            border-bottom: 2px solid var(--medium-gray);
            padding: 16px 15px;
            font-weight: 600;
            color: var(--dark-green);
            vertical-align: middle;
            font-size: 14px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
        
        .report-table tbody td {
            padding: 16px 15px;
            border-bottom: 1px solid var(--medium-gray);
            vertical-align: middle;
            font-size: 14px;
        }
        
        .report-table tbody tr:hover {
            background-color: rgba(26, 147, 111, 0.05);
        }
        
        .report-table tbody tr:last-child td {
            border-bottom: none;
        }
        
        /* Department Tag */
        .dept-tag {
            display: inline-block;
            background-color: rgba(26, 147, 111, 0.1);
            color: var(--primary-green);
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 13px;
            font-weight: 500;
            border: 1px solid rgba(26, 147, 111, 0.2);
        }
        
        /* Tenure Display */
        .tenure-display {
            text-align: center;
            padding: 30px 20px;
        }
        
        .tenure-value {
            font-size: 72px;
            font-weight: 700;
            background: linear-gradient(135deg, var(--primary-green), var(--secondary-green));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            line-height: 1;
            margin-bottom: 10px;
        }
        
        .tenure-label {
            color: var(--text-medium);
            font-size: 16px;
            font-weight: 500;
        }
        
        /* Chart Container */
        .chart-container {
            position: relative;
            height: 300px;
            padding: 20px;
        }
        
        /* Print Styles */
        @media print {
            .no-print {
                display: none !important;
            }
            
            .report-card {
                box-shadow: none !important;
                border: 1px solid #ddd !important;
            }
            
            .stats-card {
                box-shadow: none !important;
                border: 1px solid #ddd !important;
            }
        }
        
        /* Button Styling */
        .btn-primary {
            background-color: var(--primary-green);
            border-color: var(--primary-green);
        }
        
        .btn-primary:hover {
            background-color: var(--dark-green);
            border-color: var(--dark-green);
        }
        
        .btn-outline-primary {
            color: var(--primary-green);
            border-color: var(--primary-green);
        }
        
        .btn-outline-primary:hover {
            background-color: var(--primary-green);
            color: white;
        }
        
        /* Alert Styling */
        .alert {
            border-radius: 10px;
            border: none;
            padding: 20px;
        }
        
        .alert-info {
            background-color: rgba(23, 162, 184, 0.1);
            color: var(--info);
            border-left: 4px solid var(--info);
        }
        
        /* Page Header */
        .page-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 1px solid var(--medium-gray);
        }
        
        .header-content .page-title {
            font-size: 32px;
            font-weight: 700;
            color: var(--dark-green);
            margin-bottom: 5px;
        }
        
        .header-content .page-subtitle {
            color: var(--text-medium);
            font-size: 16px;
            margin: 0;
        }
        
        /* Trend Indicator */
        .trend-indicator {
            display: inline-flex;
            align-items: center;
            font-size: 13px;
            font-weight: 500;
            padding: 4px 10px;
            border-radius: 15px;
            margin-left: 10px;
        }
        
        .trend-up {
            background-color: rgba(220, 53, 69, 0.1);
            color: #dc3545;
        }
        
        .trend-down {
            background-color: rgba(40, 167, 69, 0.1);
            color: #28a745;
        }
        
        .trend-up i, .trend-down i {
            margin-right: 3px;
        }
        
        /* Footer */
        .report-footer {
            background-color: var(--light-gray);
            border-top: 1px solid var(--medium-gray);
            padding: 15px 25px;
            font-size: 14px;
            color: var(--text-medium);
            border-radius: 0 0 12px 12px;
        }
        
        /* Empty State */
        .empty-state {
            padding: 60px 20px;
            text-align: center;
        }
        
        .empty-icon {
            font-size: 64px;
            color: var(--medium-gray);
            margin-bottom: 20px;
        }
        
        /* Progress Bar for Turnover Rate */
        .progress-turnover {
            height: 10px;
            border-radius: 5px;
            background-color: var(--medium-gray);
            overflow: hidden;
            margin-top: 5px;
        }
        
        .progress-turnover-bar {
            height: 100%;
            border-radius: 5px;
        }
        
        /* Responsive */
        @media (max-width: 768px) {
            .main-content {
                margin: 10px;
                padding: 15px;
            }
            
            .page-header {
                flex-direction: column;
                gap: 15px;
            }
            
            .stats-value {
                font-size: 28px;
            }
            
            .tenure-value {
                font-size: 56px;
            }
            
            .header-content .page-title {
                font-size: 26px;
            }
        }
        
        /* Animation */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .fade-in {
            animation: fadeIn 0.5s ease-out forwards;
        }
    </style>
</head>
<body>
    <div class="main-content">
        <!-- Page Header -->
        <div class="page-header">
            <div class="header-content">
                <h1 class="page-title">Staff Turnover Report</h1>
                <p class="page-subtitle">Comprehensive analysis of staff turnover and retention metrics</p>
            </div>
            <div class="header-actions no-print">
                <a href="{{ route('staff.index') }}" class="btn btn-outline-primary">
                    <i class="fas fa-arrow-left me-2"></i>Back to Staff
                </a>
                <button onclick="window.print()" class="btn btn-primary ms-2">
                    <i class="fas fa-print me-2"></i>Print Report
                </button>
            </div>
        </div>

        <!-- Key Statistics -->
        <div class="row mb-4 fade-in">
            <div class="col-md-3 mb-4">
                <div class="stats-card">
                    <div class="stats-icon bg-primary">
                        <i class="fas fa-users"></i>
                    </div>
                    <div class="stats-value">{{ $totalStaff ?? 0 }}</div>
                    <div class="stats-label">Total Staff</div>
                </div>
            </div>
            <div class="col-md-3 mb-4">
                <div class="stats-card">
                    <div class="stats-icon bg-success">
                        <i class="fas fa-user-check"></i>
                    </div>
                    <div class="stats-value">{{ $activeStaff ?? 0 }}</div>
                    <div class="stats-label">Active Staff</div>
                </div>
            </div>
            <div class="col-md-3 mb-4">
                <div class="stats-card">
                    <div class="stats-icon bg-danger">
                        <i class="fas fa-user-slash"></i>
                    </div>
                    <div class="stats-value">{{ $laid_offStaff ?? 0 }}</div>
                    <div class="stats-label">Laid Off Staff</div>
                </div>
            </div>
            <div class="col-md-3 mb-4">
                <div class="stats-card">
                    <div class="stats-icon bg-warning">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <div class="stats-value">{{ number_format($turnoverRate ?? 0, 1) }}%</div>
                    <div class="stats-label">Turnover Rate</div>
                    <div class="progress-turnover mt-3">
                        <div class="progress-turnover-bar bg-warning" style="width: {{ min($turnoverRate ?? 0, 100) }}%"></div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Department-wise Turnover Analysis -->
        <div class="report-card fade-in">
            <div class="card-header">
                <h5 class="mb-0"><i class="fas fa-building"></i> Department-wise Turnover Analysis</h5>
            </div>
            <div class="card-body">
                @if($departmentTurnover && count($departmentTurnover) > 0)
                    <div class="table-responsive">
                        <table class="table report-table">
                            <thead>
                                <tr>
                                    <th>Department</th>
                                    <th>Total Staff</th>
                                    <th>Active</th>
                                    <th>Laid Off</th>
                                    <th>Turnover Rate</th>
                                    <th>Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($departmentTurnover as $dept)
                                @php
                                    $total = $dept->total_staff ?? 0;
                                    $laidOff = $dept->laid_off ?? 0;
                                    $inactive = $dept->inactive ?? 0;
                                    $active = $total - $laidOff - $inactive;
                                    $deptTurnoverRate = $total > 0 ? ($laidOff / $total) * 100 : 0;
                                @endphp
                                <tr>
                                    <td>
                                        <span class="dept-tag">{{ $dept->department ?? 'Unassigned' }}</span>
                                    </td>
                                    <td>
                                        <strong>{{ $total }}</strong>
                                    </td>
                                    <td>
                                        <span class="text-success">{{ $active }}</span>
                                    </td>
                                    <td>
                                        <span class="text-danger">{{ $laidOff }}</span>
                                    </td>
                                    <td>
                                        <span class="turnover-badge {{ $deptTurnoverRate > 10 ? 'turnover-high' : ($deptTurnoverRate > 5 ? 'turnover-medium' : 'turnover-low') }}">
                                            {{ number_format($deptTurnoverRate, 1) }}%
                                        </span>
                                    </td>
                                    <td>
                                        @if($deptTurnoverRate > 15)
                                            <span class="trend-indicator trend-up">
                                                <i class="fas fa-arrow-up"></i>High Risk
                                            </span>
                                        @elseif($deptTurnoverRate > 8)
                                            <span class="trend-indicator trend-up">
                                                <i class="fas fa-exclamation-triangle"></i>Moderate Risk
                                            </span>
                                        @else
                                            <span class="trend-indicator trend-down">
                                                <i class="fas fa-check-circle"></i>Stable
                                            </span>
                                        @endif
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="empty-state">
                        <div class="empty-icon">
                            <i class="fas fa-chart-pie"></i>
                        </div>
                        <h4>No Department Data Available</h4>
                        <p class="text-muted">Department turnover data will appear here once staff are assigned to departments.</p>
                    </div>
                @endif
            </div>
        </div>

        <div class="row">
            <!-- Monthly Turnover Trend -->
            <div class="col-md-8 fade-in">
                <div class="report-card h-100">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-chart-bar"></i> Monthly Turnover Trend (Last 12 Months)</h5>
                    </div>
                    <div class="card-body">
                        @if($monthlyTurnover && count($monthlyTurnover) > 0)
                            <div class="table-responsive">
                                <table class="table report-table">
                                    <thead>
                                        <tr>
                                            <th>Month</th>
                                            <th>Laid Off Staff</th>
                                            <th>Trend</th>
                                            <th>Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @php
                                            $previousCount = null;
                                        @endphp
                                        @foreach($monthlyTurnover as $month)
                                        @php
                                            $currentCount = $month->count;
                                            $trend = '';
                                            if ($previousCount !== null) {
                                                if ($currentCount > $previousCount) {
                                                    $trend = 'up';
                                                } elseif ($currentCount < $previousCount) {
                                                    $trend = 'down';
                                                } else {
                                                    $trend = 'stable';
                                                }
                                            }
                                            $previousCount = $currentCount;
                                        @endphp
                                        <tr>
                                            <td>
                                                <strong>{{ date('F Y', strtotime($month->month . '-01')) }}</strong>
                                            </td>
                                            <td>
                                                <span class="text-danger">{{ $currentCount }}</span>
                                            </td>
                                            <td>
                                                @if($trend == 'up')
                                                    <i class="fas fa-arrow-up text-danger"></i>
                                                @elseif($trend == 'down')
                                                    <i class="fas fa-arrow-down text-success"></i>
                                                @elseif($trend == 'stable')
                                                    <i class="fas fa-minus text-muted"></i>
                                                @endif
                                            </td>
                                            <td>
                                                @if($currentCount >= 5)
                                                    <span class="badge bg-danger">Critical</span>
                                                @elseif($currentCount >= 3)
                                                    <span class="badge bg-warning">High</span>
                                                @elseif($currentCount >= 1)
                                                    <span class="badge bg-info">Moderate</span>
                                                @else
                                                    <span class="badge bg-success">Low</span>
                                                @endif
                                            </td>
                                        </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        @else
                            <div class="alert alert-info">
                                <i class="fas fa-info-circle me-2"></i> 
                                No monthly turnover data available for the last 12 months.
                            </div>
                        @endif
                    </div>
                </div>
            </div>

            <!-- Tenure Statistics -->
            <div class="col-md-4 fade-in">
                <div class="report-card h-100">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-clock"></i> Tenure Statistics</h5>
                    </div>
                    <div class="card-body">
                        <div class="tenure-display">
                            <div class="tenure-value">{{ number_format($averageTenure ?? 0, 1) }}</div>
                            <div class="tenure-label">Average Tenure (Years)</div>
                        </div>
                        
                        <div class="row mt-4">
                            <div class="col-6 text-center">
                                <div class="stats-value">{{ $inactiveStaff ?? 0 }}</div>
                                <div class="stats-label">Inactive</div>
                            </div>
                            <div class="col-6 text-center">
                                <div class="stats-value">{{ $suspendedStaff ?? 0 }}</div>
                                <div class="stats-label">Suspended</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Additional Metrics -->
        <div class="row mt-4">
            <div class="col-md-6 fade-in">
                <div class="report-card h-100">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-chart-pie"></i> Staff Status Distribution</h5>
                    </div>
                    <div class="card-body">
                        <div class="chart-container">
                            <canvas id="statusChart"></canvas>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="col-md-6 fade-in">
                <div class="report-card h-100">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-exclamation-triangle"></i> Turnover Risk Analysis</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <div class="stats-card">
                                    <div class="stats-icon bg-info">
                                        <i class="fas fa-exclamation-circle"></i>
                                    </div>
                                    <div class="stats-value">
                                        @php
                                            $highRiskDepts = 0;
                                            if($departmentTurnover) {
                                                foreach($departmentTurnover as $dept) {
                                                    $total = $dept->total_staff ?? 0;
                                                    $laidOff = $dept->laid_off ?? 0;
                                                    $rate = $total > 0 ? ($laidOff / $total) * 100 : 0;
                                                    if($rate > 15) $highRiskDepts++;
                                                }
                                            }
                                        @endphp
                                        {{ $highRiskDepts }}
                                    </div>
                                    <div class="stats-label">High Risk Departments</div>
                                </div>
                            </div>
                            <div class="col-md-6 mb-3">
                                <div class="stats-card">
                                    <div class="stats-icon bg-warning">
                                        <i class="fas fa-user-clock"></i>
                                    </div>
                                    <div class="stats-value">
                                        @php
                                            $recentHires = 0;
                                            // Assuming you have a way to calculate recent hires (last 3 months)
                                            // This is a placeholder - you'll need to implement this in your controller
                                        @endphp
                                        {{ $recentHires }}
                                    </div>
                                    <div class="stats-label">Recent Hires (< 3 months)</div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="alert alert-info mt-3">
                            <div class="d-flex align-items-center">
                                <i class="fas fa-lightbulb fa-2x me-3"></i>
                                <div>
                                    <h6 class="mb-1">Recommendation</h6>
                                    <p class="mb-0">
                                        @if(($turnoverRate ?? 0) > 15)
                                            <strong>Immediate action required:</strong> Consider reviewing retention policies and employee engagement programs.
                                        @elseif(($turnoverRate ?? 0) > 8)
                                            <strong>Monitor closely:</strong> Keep an eye on high-risk departments and conduct exit interviews.
                                        @else
                                            <strong>Healthy turnover rate:</strong> Continue with current retention strategies.
                                        @endif
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Report Footer -->
        <div class="report-footer no-print">
            <div class="row">
                <div class="col-md-6">
                    <small class="text-muted">
                        <i class="fas fa-calendar-alt me-1"></i>
                        Report generated: {{ now()->format('F j, Y \a\t g:i A') }}
                    </small>
                </div>
                <div class="col-md-6 text-md-end">
                    <small class="text-muted">
                        <i class="fas fa-hotel me-1"></i>
                        {{ hotelName() }}
                    </small>
                </div>
            </div>
        </div>
    </div>

    <!-- Scripts -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Staff Status Pie Chart
            const ctx = document.getElementById('statusChart').getContext('2d');
            const statusChart = new Chart(ctx, {
                type: 'doughnut',
                data: {
                    labels: ['Active', 'Inactive', 'Suspended', 'Laid Off'],
                    datasets: [{
                        data: [
                            {{ $activeStaff ?? 0 }},
                            {{ $inactiveStaff ?? 0 }},
                            {{ $suspendedStaff ?? 0 }},
                            {{ $laid_offStaff ?? 0 }}
                        ],
                        backgroundColor: [
                            '#28a745',
                            '#6c757d',
                            '#ffc107',
                            '#dc3545'
                        ],
                        borderWidth: 2,
                        borderColor: '#fff'
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    cutout: '65%',
                    plugins: {
                        legend: {
                            position: 'bottom',
                            labels: {
                                padding: 20,
                                usePointStyle: true,
                                font: {
                                    size: 12
                                }
                            }
                        },
                        tooltip: {
                            callbacks: {
                                label: function(context) {
                                    const label = context.label || '';
                                    const value = context.raw || 0;
                                    const total = context.dataset.data.reduce((a, b) => a + b, 0);
                                    const percentage = Math.round((value / total) * 100);
                                    return `${label}: ${value} (${percentage}%)`;
                                }
                            }
                        }
                    }
                }
            });

            // Add animation to stats cards
            const observerOptions = {
                threshold: 0.1,
                rootMargin: '0px 0px -50px 0px'
            };

            const observer = new IntersectionObserver((entries) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) {
                        entry.target.classList.add('fade-in');
                    }
                });
            }, observerOptions);

            // Observe all fade-in elements
            document.querySelectorAll('.fade-in').forEach(el => {
                observer.observe(el);
            });

            // Print functionality enhancement
            const printButton = document.querySelector('button[onclick="window.print()"]');
            if (printButton) {
                printButton.addEventListener('click', function() {
                    // Add loading state
                    const originalHTML = this.innerHTML;
                    this.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Preparing...';
                    this.disabled = true;
                    
                    // Reset button after a short delay
                    setTimeout(() => {
                        this.innerHTML = originalHTML;
                        this.disabled = false;
                    }, 1500);
                });
            }
        });

        // Auto-format numbers on page
        document.querySelectorAll('.stats-value').forEach(element => {
            const text = element.textContent;
            if (text.includes('%')) {
                // Already formatted
            } else if (!isNaN(text) && text.trim() !== '') {
                const num = parseFloat(text);
                if (num >= 1000) {
                    element.textContent = (num / 1000).toFixed(1) + 'k';
                }
            }
        });
    </script>
</body>
</html>
