<?php
/**
 * Component: Stat Card
 * 
 * Expected variables:
 * @var string $kpi_icon   Icon name (e.g., 'solar:user-bold')
 * @var string $kpi_value  Value to display (e.g., '10', 'R$ 500,00')
 * @var string $kpi_label  Label text (e.g., 'Total Clientes')
 * @var string $kpi_color  (Optional) Hex color for icon/bg (default: var(--primary))
 * @var string $kpi_link   (Optional) URL if the card acts as a link
 * @var string $kpi_bg_color (Optional) Specific background color for icon wrapper (overrides default opacity calculation)
 * @var string $kpi_text_color (Optional) Specific text color for icon (overrides default)
 */

$icon = $kpi_icon ?? 'solar:question-circle-bold';
$value = $kpi_value ?? '0';
$label = $kpi_label ?? 'Label';

// Color logic
$color = $kpi_color ?? ''; 
$link = $kpi_link ?? null;

// Determine separate styles if passed, or calculate from base color
$iconStyle = "";
if (!empty($kpi_bg_color) && !empty($kpi_text_color)) {
    $iconStyle = "background:{$kpi_bg_color};color:{$kpi_text_color}";
} elseif (!empty($color)) {
    $iconStyle = "background:{$color}20;color:{$color}";
}

// Tag type
$tag = $link ? "a" : "div";
$hrefAttr = $link ? "href=\"{$link}\"" : "";
$extraClass = $link ? "cursor-pointer transition-transform hover:scale-105" : "";
$extraStyle = $link ? "text-decoration: none !important; color: inherit !important; display: block; transition: all 0.3s ease;" : ""; 
?>

<<?php echo $tag; ?> <?php echo $hrefAttr; ?> class="stat-card <?php echo $extraClass; ?>" style="<?php echo $extraStyle; ?>" <?php if($link): ?>onmouseover="this.style.transform='scale(1.02)'" onmouseout="this.style.transform='scale(1)'"<?php endif; ?>>
    <div class="stat-icon" style="<?php echo $iconStyle; ?>">
        <iconify-icon icon="<?php echo $icon; ?>"></iconify-icon>
    </div>
    <div class="stat-content">
        <span class="stat-value"><?php echo $value; ?></span>
        <span class="stat-label"><?php echo $label; ?></span>
    </div>
</<?php echo $tag; ?>>
