import { useState, useEffect, useRef, useCallback } from 'react'; import { useGameStore } from '@/store'; import { formatNumber, formatMoney, formatPercent } from '@ai-tycoon/shared'; import type { ConsumerTierId } from '@ai-tycoon/shared'; import { Users, Check } from 'lucide-react'; const TIER_ORDER: ConsumerTierId[] = ['free', 'plus', 'pro', 'team']; const TIER_COLORS: Record = { free: 'border-surface-500', plus: 'border-blue-500', pro: 'border-purple-500', team: 'border-orange-500', }; function useAppliedFeedback() { const [show, setShow] = useState(false); const timerRef = useRef>(undefined); const trigger = useCallback(() => { setShow(true); clearTimeout(timerRef.current); timerRef.current = setTimeout(() => setShow(false), 1200); }, []); useEffect(() => () => clearTimeout(timerRef.current), []); return { show, trigger }; } export function ConsumerTiersPanel() { const consumerTiers = useGameStore((s) => s.market.consumerTiers); const setConsumerTierPrice = useGameStore((s) => s.setConsumerTierPrice); const toggleConsumerTier = useGameStore((s) => s.toggleConsumerTier); const feedback = useAppliedFeedback(); return (
Consumer Subscriptions
Total: {formatNumber(consumerTiers.totalUsers)} Satisfaction: 0.7 ? 'text-success' : consumerTiers.satisfaction > 0.4 ? 'text-warning' : 'text-danger'}`}>{formatPercent(consumerTiers.satisfaction)}
{TIER_ORDER.map(tierId => { const tier = consumerTiers.tiers[tierId]; const revenue = tierId === 'free' ? 0 : tier.userCount * tier.config.price / 86400; return (

{tier.config.name}

{tierId !== 'free' && ( )} {tierId === 'free' && ( Always On )}
{formatNumber(tier.userCount)}
users
{tierId !== 'free' && (
{ setConsumerTierPrice(tierId, Number(e.target.value)); feedback.trigger(); }} className="w-full bg-surface-800 border border-surface-600 rounded px-2 py-1 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-accent/50" min={1} step={5} />
)}
Tokens/mo {formatNumber(tier.config.tokenAllowance)}
Churn {formatPercent(tier.churnRate)}/t
{tierId !== 'free' && (
Revenue/s {formatMoney(revenue)}
)}
); })}
); }