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 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 } = useReport(id); // Extract enrichment params from location state (socialHandles from API) or base data const enrichmentParams = useMemo(() => { if (!baseData) return null; const state = location.state as Record | undefined; const metadata = state?.metadata as Record | undefined; const socialHandles = metadata?.socialHandles as Record | undefined; // Priority: API socialHandles > transformed data > undefined const igHandle = socialHandles?.instagram || baseData.instagramAudit?.accounts?.[0]?.handle || undefined; const ytHandle = socialHandles?.youtube || baseData.youtubeAudit?.handle || undefined; return { reportId: baseData.id, clinicName: baseData.clinicSnapshot.name, instagramHandle: igHandle || undefined, youtubeChannelId: ytHandle || undefined, address: baseData.clinicSnapshot.location || undefined, }; }, [baseData, 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' && (
채널 데이터 보강 중...
)}
); }