'use client' import { useEffect, useMemo, useState } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { Umbrella, Wind, ThermometerSun, TramFront, Calendar as CalendarIcon, Receipt, Sparkles, Moon, Sun, } from 'lucide-react' // —————————————————————————————— // Types // —————————————————————————————— export interface FocusWeather { temp: string desc: string feelsLike?: string } export interface FocusTram { route: string minutes: number direction: string } export interface FocusEvent { id: string title: string start: string allDay?: boolean ownerName?: string color?: string } export interface FocusCountdown { label: string date: string // ISO YYYY-MM-DD } export interface FocusBill { title: string amount: string daysLeft: number } interface Props { weather: FocusWeather | null tramNext?: FocusTram | null nextEvent?: FocusEvent | null countdowns?: FocusCountdown[] bills?: FocusBill[] } // —————————————————————————————— // Focus state machine // —————————————————————————————— type FocusKind = | { kind: 'morning-outfit'; tempNow: string; feels: string; advice: string; Icon: any; accent: string } | { kind: 'tram-imminent'; route: string; minutes: number; direction: string } | { kind: 'event-upcoming'; title: string; inMinutes: number; owner?: string; color?: string } | { kind: 'countdown'; label: string; days: number } | { kind: 'bill-due'; title: string; amount: string; daysLeft: number } | { kind: 'night'; hour: number } | { kind: 'quiet'; greeting: string } function pickFocus(p: Props, hour: number): FocusKind { // 1. Bill due today / tomorrow — всегда приоритет const bill = p.bills?.find(b => b.daysLeft <= 1) if (bill) return { kind: 'bill-due', ...bill } // 2. Ближайшее событие ≤30 минут if (p.nextEvent && !p.nextEvent.allDay) { const start = new Date(p.nextEvent.start).getTime() const inMin = Math.round((start - Date.now()) / 60_000) if (inMin >= -5 && inMin <= 30) { return { kind: 'event-upcoming', title: p.nextEvent.title, inMinutes: inMin, owner: p.nextEvent.ownerName, color: p.nextEvent.color, } } } // 3. Трамвай в рабочий час, ≤3 мин const rushHour = (hour >= 7 && hour <= 10) || (hour >= 17 && hour <= 20) if (rushHour && p.tramNext && p.tramNext.minutes >= 0 && p.tramNext.minutes <= 3) { return { kind: 'tram-imminent', ...p.tramNext } } // 4. Утро (7-10) → одевалка if (hour >= 7 && hour < 11 && p.weather) { const t = parseInt(p.weather.temp, 10) const descLower = p.weather.desc?.toLowerCase() || '' const rain = /дожд|ливен|грозa|морос/.test(descLower) const snow = /снег|метел/.test(descLower) const advice = rain ? 'возьми зонт' : snow ? 'шапка и зимняя обувь' : t <= -10 ? 'пуховик, шапка, перчатки' : t < 0 ? 'шапка и перчатки' : t < 7 ? 'тёплая куртка' : t < 15 ? 'лёгкая куртка' : t < 22 ? 'свитер или рубашка' : 'футболка' const Icon = rain ? Umbrella : snow ? Wind : t < 0 ? Wind : ThermometerSun const accent = rain ? 'var(--data-cool)' : snow ? 'var(--data-info)' : t < 0 ? 'var(--data-info)' : t >= 22 ? 'var(--data-warm)' : 'var(--data-warm)' return { kind: 'morning-outfit', tempNow: p.weather.temp, feels: p.weather.feelsLike || '', advice, Icon, accent, } } // 5. Ближайший countdown (≤14 дней) const cd = (p.countdowns || []) .map(c => { const target = new Date(c.date + 'T00:00:00').getTime() const days = Math.ceil((target - Date.now()) / 86_400_000) return { label: c.label, days } }) .filter(c => c.days >= 0 && c.days <= 14) .sort((a, b) => a.days - b.days)[0] if (cd) return { kind: 'countdown', ...cd } // 6. Ночь if (hour >= 22 || hour < 5) return { kind: 'night', hour } // 7. Тихо — приветствие const greeting = hour >= 5 && hour < 12 ? 'Доброе утро' : hour >= 12 && hour < 17 ? 'Добрый день' : hour >= 17 && hour < 22 ? 'Добрый вечер' : 'Доброй ночи' return { kind: 'quiet', greeting } } // —————————————————————————————— // Presentations // —————————————————————————————— function Eyebrow({ children }: { children: React.ReactNode }) { return (