// Statistics screen
const { useState: useStateS, useMemo: useMemoS } = React;
function StatCard({ label, value, delta, deltaPositive }) {
return (
{label}
{value}
{delta && (
{deltaPositive ? "+" : ""}{delta}
)}
);
}
function LineChart({ data, days = 14 }) {
if (!data || data.length < 2) {
return (
);
}
const max = Math.max(...data);
const min = Math.min(...data);
const w = 100, h = 100;
const pts = data.map((v, i) => {
const x = (i / (data.length - 1)) * w;
const y = h - ((v - min) / (max - min || 1)) * h * 0.85 - 5;
return [x, y];
});
const path = pts.map(([x, y], i) => (i === 0 ? `M ${x} ${y}` : `L ${x} ${y}`)).join(" ");
const area = path + ` L ${w} ${h} L 0 ${h} Z`;
// Generate date labels: evenly spaced across the data range
const today = new Date();
const labelCount = 7;
const step = Math.floor((data.length - 1) / (labelCount - 1));
const labels = Array.from({ length: labelCount }, (_, i) => {
const d = new Date(today);
d.setDate(d.getDate() - (data.length - 1 - i * step));
return d.toLocaleDateString("ru-RU", { day: "numeric", month: "short" }).replace(".", "");
});
const lastVal = data[data.length - 1];
return (
Обращения по дням
последние {days} дней
{lastVal > 0 && (
)}
{labels.map((l, i) => {l})}
);
}
function HeatmapChart({ data }) {
const max = data && data.length ? Math.max(...data) : 1;
return (
Обращения по часам
средние значения за 14 дней · пик в 15:00
{data.map((v, i) => {
const intensity = v / max;
const h = Math.max(8, intensity * 100);
return (
);
})}
00040812162023
);
}
function TopQuestionsChart({ data }) {
if (!data || data.length === 0) {
return (
Топ-10 частых вопросов
за последние 30 дней
Нет данных
);
}
const max = data[0].count;
return (
Топ-10 частых вопросов
за последние 30 дней
{data.map((q, i) => (
))}
);
}
function OperatorsTable({ operators }) {
return (
Операторы
эффективность за сегодня
| Имя |
Закрыто |
Ср. время |
Статус |
{operators.map((op) => (
{op.name}
{op.role === "admin" ? "Администратор" : "Агент"} · {op.tg}
|
{op.closed} |
{op.avgTime} |
{op.online ? "Онлайн" : "Офлайн"}
|
))}
);
}
function StatisticsScreen({ dailyConversations: dc, hourly: hv, operators: ops, topQuestions: tq, todayTotal, todayClosed, aiPct }) {
const dailyConversations = dc || [];
const hourly = hv || [];
const operators = ops || [];
const topQuestions = tq || [];
const [range, setRange] = useStateS("14d");
const ranges = [
{ id: "today", label: "Сегодня" },
{ id: "7d", label: "7 дней" },
{ id: "14d", label: "14 дней" },
{ id: "30d", label: "30 дней" },
];
const days = range === "today" ? 1 : range === "7d" ? 7 : range === "14d" ? 14 : 30;
return (
{/* Header */}
Статистика
данные за сегодня
{ranges.map((r) => (
))}
{/* KPI row */}
{/* Charts row */}
{/* Bottom row */}
);
}
Object.assign(window, { StatisticsScreen });