"use client"; import { useState, useEffect, useCallback } from "react"; import { Printer, RefreshCw, Save, RotateCcw, Plus, Trash2, Sparkles, Loader2, Check } from "lucide-react"; import type { CalendarEvent } from "@/app/api/calendar/route"; import type { DriverData } from "@/lib/types"; import type { FxWeeklyEntry } from "@/app/api/fx-weekly/route"; import type { CotHistory } from "@/app/api/cot-history/route"; import { CURRENCY_META } from "@/lib/constants"; import { TvAdvancedChart } from "@/components/TvChart"; interface Props { calEvents: CalendarEvent[]; drivers: DriverData | null; cotHistory: CotHistory | null; } interface Theme { title: string; body: string } interface ReportState { weekLabel: string; weekFrom: string; weekTo: string; author: string; subtitle: string; themes: Theme[]; currencies: Record; notes: string; } const STORAGE_KEY = "forex-report-v2"; const G10 = ["USD","EUR","GBP","JPY","CHF","CAD","AUD","NZD"]; function fmtDate(iso: string) { if (!iso) return ""; return new Date(iso + "T12:00:00").toLocaleDateString("fr-FR", { day: "numeric", month: "long", year: "numeric" }); } function fmtShort(iso: string) { if (!iso) return ""; return new Date(iso + "T12:00:00").toLocaleDateString("fr-FR", { day: "numeric", month: "long" }); } function defaultState(weekFrom = "", weekTo = ""): ReportState { return { weekLabel: weekFrom && weekTo ? `${fmtShort(weekFrom)} — ${fmtDate(weekTo)}` : "Semaine du … au …", weekFrom, weekTo, author: "Capucine · Forex Dashboard", subtitle: "Analyse macro-fondamentale G10 · Marchés globaux", themes: [{ title: "", body: "" }, { title: "", body: "" }, { title: "", body: "" }], currencies: Object.fromEntries(G10.map(c => [c, { pct: "—", analysis: "", level: "" }])), notes: "", }; } function save(state: ReportState) { try { localStorage.setItem(STORAGE_KEY, JSON.stringify(state)); } catch { /**/ } } function load(): ReportState | null { try { const r = localStorage.getItem(STORAGE_KEY); return r ? JSON.parse(r) : null; } catch { return null; } } // ── Composants UI ───────────────────────────────────────────────────────────── function Field({ value, onChange, placeholder, multiline, className }: { value: string; onChange: (v: string) => void; placeholder?: string; multiline?: boolean; className?: string; }) { if (multiline) return (