import { useMemo } from 'react'; import { useParams, useLocation } from 'react-router'; import { useReport } from '../hooks/useReport'; import { useEnrichment } from '../hooks/useEnrichment'; import { ReportNav } from '../components/report/ReportNav'; import { ScreenshotProvider } from '../contexts/ScreenshotContext'; // Report section components import { SectionErrorBoundary } from '../components/report/ui/SectionErrorBoundary'; import ReportHeader from '../components/report/ReportHeader'; import ClinicSnapshot from '../components/report/ClinicSnapshot'; import ChannelOverview from '../components/report/ChannelOverview'; import YouTubeAudit from '../components/report/YouTubeAudit'; import InstagramAudit from '../components/report/InstagramAudit'; import FacebookAudit from '../components/report/FacebookAudit'; import OtherChannels from '../components/report/OtherChannels'; import ProblemDiagnosis from '../components/report/ProblemDiagnosis'; import TransformationProposal from '../components/report/TransformationProposal'; import RoadmapTimeline from '../components/report/RoadmapTimeline'; import KPIDashboard from '../components/report/KPIDashboard'; const REPORT_SECTIONS = [ { id: 'header', label: '개요' }, { id: 'clinic-snapshot', label: '의원 현황' }, { id: 'channel-overview', label: '채널 종합' }, { id: 'youtube-audit', label: 'YouTube' }, { id: 'instagram-audit', label: 'Instagram' }, { id: 'facebook-audit', label: 'Facebook' }, { id: 'other-channels', label: '기타 채널' }, { id: 'problem-diagnosis', label: '문제 진단' }, { id: 'roadmap', label: '로드맵' }, { id: 'kpi-dashboard', label: 'KPI' }, ]; export default function ReportPage() { const { id } = useParams<{ id: string }>(); const location = useLocation(); const { data: baseData, isLoading, error, isEnriched, socialHandles: dbSocialHandles, } = useReport(id); // Build enrichment params — skip if already enriched (data from DB) const enrichmentParams = useMemo(() => { if (!baseData || isEnriched) return null; // Priority: location.state socialHandles > DB socialHandles > transformed data const state = location.state as Record | undefined; const metadata = state?.metadata as Record | undefined; const stateSocialHandles = metadata?.socialHandles as Record | undefined; const handles = stateSocialHandles || dbSocialHandles; // Instagram: support array of handles (multi-account) or single handle const igHandles: string[] = Array.isArray(handles?.instagram) ? handles.instagram.filter(Boolean) as string[] : handles?.instagram ? [handles.instagram as string] : []; const ytHandle = handles?.youtube || baseData.youtubeAudit?.handle || undefined; const fbHandle = handles?.facebook || undefined; return { reportId: baseData.id, clinicName: baseData.clinicSnapshot.name, instagramHandles: igHandles.length > 0 ? igHandles : undefined, youtubeChannelId: ytHandle || undefined, facebookHandle: fbHandle as string | undefined, address: baseData.clinicSnapshot.location || undefined, }; }, [baseData, isEnriched, dbSocialHandles, location.state]); const { status: enrichStatus, enrichedReport } = useEnrichment(baseData, enrichmentParams); // Use enriched data when available, otherwise base data const data = enrichedReport || baseData; if (isLoading) { return (

리포트를 불러오는 중...

); } if (error || !data) { return (

오류가 발생했습니다

{error ?? '리포트를 찾을 수 없습니다.'}

); } return (
{/* Enrichment status indicator */} {enrichStatus === 'loading' && (
채널 데이터 보강 중...
)}
); }