<?php defined('BASEPATH') or exit('No direct script access allowed');

$label = isset($label) ? $label : '';
$value = isset($value) ? $value : '';
$value_html = isset($value_html) ? $value_html : '';
$hint = isset($hint) ? $hint : '';
$icon = isset($icon) ? $icon : '';
$tone = isset($tone) ? $tone : 'neutral';
$class = isset($class) ? $class : '';

$tone_map = array(
	'neutral' => 'erp-stat-card--neutral',
	'primary' => 'erp-stat-card--primary',
	'success' => 'erp-stat-card--success',
	'warning' => 'erp-stat-card--warning',
	'danger' => 'erp-stat-card--danger',
);

$tone_class = isset($tone_map[$tone]) ? $tone_map[$tone] : $tone_map['neutral'];
$display_value = $value_html !== '' ? $value_html : html_escape($value);
?>

<div class="erp-stat-card <?= $tone_class; ?><?= $class ? ' ' . $class : ''; ?>">
	<div class="flex items-start justify-between gap-3">
		<div class="min-w-0 flex-1">
			<?php if ($label !== '') { ?>
				<p class="erp-stat-label"><?= html_escape($label); ?></p>
			<?php } ?>
			<div class="erp-stat-value"><?= $display_value; ?></div>
			<?php if ($hint !== '') { ?>
				<p class="erp-stat-hint"><?= html_escape($hint); ?></p>
			<?php } ?>
		</div>
		<?php if ($icon !== '') { ?>
			<span class="erp-stat-icon">
				<i data-lucide="<?= html_escape($icon); ?>" class="h-4 w-4"></i>
			</span>
		<?php } ?>
	</div>
</div>
