import OnlinePredictionOutlined from "@mui/icons-material/OnlinePredictionOutlined";
import PeopleAltOutlined from "@mui/icons-material/PeopleAltOutlined";
import PersonAddAltOutlined from "@mui/icons-material/PersonAddAltOutlined";
import { KpiCard } from "@/shared/ui/KpiCard.jsx";

const countFormatter = new Intl.NumberFormat("zh-CN");

export function DashboardStats({ overview }) {
  return (
    <section className="kpi-grid dashboard-profile-kpis" aria-label="用户核心指标">
      <KpiCard
        icon={PeopleAltOutlined}
        label="总人数"
        value={formatCount(overview?.totalUsers)}
        unit="人"
        sub="已完成资料，排除机器人/快捷账号"
      />
      <KpiCard
        icon={PersonAddAltOutlined}
        label="当天新增"
        value={formatCount(overview?.newUsers)}
        unit="人"
        tone="success"
        sub="按当前显示时区统计"
      />
      <KpiCard
        icon={OnlinePredictionOutlined}
        label="当前日活"
        value={formatCount(overview?.activeUsers)}
        unit="人"
        tone="info"
        sub="当天去重活跃用户"
      />
    </section>
  );
}

function formatCount(value) {
  const count = Number(value);
  return countFormatter.format(Number.isFinite(count) && count > 0 ? count : 0);
}
