<?php
/**
 * SalonPro X - Statistics Card Component
 * Usage: <?php component('stats_card', ['label' => 'Revenue', 'value' => 'Rs. 150,000', 'icon' => 'fa-money', 'trend' => '+12%', 'color' => 'gold']); ?>
 * @var string $label Statistic label
 * @var string $value Statistic value
 * @var string $icon Font Awesome icon class
 * @var string $trend Trend indicator (optional)
 * @var string $color Color theme: gold, red, green, blue, purple (default: gold)
 * @var string $link Optional link URL
 * @var string $bgClass Optional background class
 */
$label = $label ?? '';
$value = $value ?? '0';
$icon = $icon ?? 'fa-chart-line';
$trend = $trend ?? '';
$color = $color ?? 'gold';
$link = $link ?? '';
$bgClass = $bgClass ?? '';

$colorMap = [
    'gold' => ['bg' => 'rgba(200, 164, 78, 0.1)', 'text' => '#C8A44E', 'border' => 'rgba(200, 164, 78, 0.2)'],
    'red' => ['bg' => 'rgba(220, 53, 69, 0.1)', 'text' => '#DC3545', 'border' => 'rgba(220, 53, 69, 0.2)'],
    'green' => ['bg' => 'rgba(40, 167, 69, 0.1)', 'text' => '#28A745', 'border' => 'rgba(40, 167, 69, 0.2)'],
    'blue' => ['bg' => 'rgba(23, 162, 184, 0.1)', 'text' => '#17A2B8', 'border' => 'rgba(23, 162, 184, 0.2)'],
    'purple' => ['bg' => 'rgba(153, 102, 255, 0.1)', 'text' => '#9966FF', 'border' => 'rgba(153, 102, 255, 0.2)'],
];
$colors = $colorMap[$color] ?? $colorMap['gold'];
$trendUp = str_starts_with($trend, '+');
$trendDown = str_starts_with($trend, '-');

$cardContent = '<div class="stats-card glass-card ' . e($bgClass) . '" style="--stats-color: ' . $colors['text'] . ';">';
$cardContent .= '<div class="stats-icon" style="background: ' . $colors['bg'] . '; color: ' . $colors['text'] . '; border-color: ' . $colors['border'] . ';">';
$cardContent .= '<i class="fas ' . e($icon) . '"></i>';
$cardContent .= '</div>';
$cardContent .= '<div class="stats-info">';
$cardContent .= '<span class="stats-label">' . e($label) . '</span>';
$cardContent .= '<span class="stats-value">' . $value . '</span>';
if ($trend) {
    $trendIcon = $trendUp ? 'fa-arrow-up' : ($trendDown ? 'fa-arrow-down' : 'fa-minus');
    $trendColor = $trendUp ? '#28A745' : ($trendDown ? '#DC3545' : '#6C757D');
    $cardContent .= '<span class="stats-trend" style="color: ' . $trendColor . ';">';
    $cardContent .= '<i class="fas ' . $trendIcon . ' me-1"></i>' . e($trend);
    $cardContent .= '</span>';
}
$cardContent .= '</div>';
$cardContent .= '</div>';

if ($link) {
    echo '<a href="' . e($link) . '" class="stats-card-link">' . $cardContent . '</a>';
} else {
    echo $cardContent;
}
?>
