import { Alert, Chip, Stack, Typography } from '@mui/material'; import { useTranslation } from 'react-i18next'; import type { CandlePredictConfig, CandlePredictInterval, CandlePredictRound } from '../types'; import { PoolBar } from './PoolBar'; type Props = { config: CandlePredictConfig; interval: CandlePredictInterval; round: CandlePredictRound | null; }; /** Admin-only live pool totals and internal settlement rule summary. */ export function AdminPoolInsights({ config, interval, round }: Props) { const { t } = useTranslation(); if (!config.poolWinnerRule) return null; const isDailyRevenue = config.poolWinnerRule === 'daily_revenue'; const parts: string[] = []; const tieTolerancePercent = interval.tieTolerancePercent ?? config.tieTolerancePercent ?? 0; const tieToleranceMaxPercent = interval.tieToleranceMaxPercent ?? config.tieToleranceMaxPercent ?? 100; // Prefer global catalog toggles as master switch (same as settlement). // Interval may only further disable — never re-enable rules the catalog turned off. const tieToleranceMinEnabled = (config.tieToleranceMinEnabled ?? true) && interval.tieToleranceMinEnabled !== false; const tieToleranceMaxEnabled = (config.tieToleranceMaxEnabled ?? true) && interval.tieToleranceMaxEnabled !== false; if (tieToleranceMinEnabled) { parts.push(t('candlePredict.adminInsights.neutralMin', { percent: tieTolerancePercent })); } if (tieToleranceMaxEnabled) { parts.push(t('candlePredict.adminInsights.neutralMax', { percent: tieToleranceMaxPercent })); } const neutralityPart = parts.length > 0 ? parts.join(' · ') : t('candlePredict.adminInsights.neutralNone'); const rulesSummary = isDailyRevenue ? [ t('candlePredict.adminInsights.dailyRevenueSummary', { target: config.dailyRevenueTarget ?? 0, net: config.dailyRevenueNetToday ?? 0, }), t('candlePredict.adminInsights.dailyRevenueNeutralityPrefix'), neutralityPart, ].join(' ') : neutralityPart; const poolWinnerLabel = config.poolWinnerRule === 'majority' ? t('candlePredict.adminInsights.poolWinnerMajority') : config.poolWinnerRule === 'daily_revenue' ? t('candlePredict.adminInsights.poolWinnerDailyRevenue') : t('candlePredict.adminInsights.poolWinnerMinority'); return ( {t('candlePredict.adminInsights.title')} {rulesSummary} {t('candlePredict.adminInsights.footer')} {round && } ); }