import React from 'react'; import { CrawlingResponse } from '../../types/api'; interface AnalysisResultSectionProps { onBack: () => void; onGenerate?: () => void; data: CrawlingResponse; } // 텍스트를 포맷팅 (개행 처리, 제목 스타일링, 해시태그 스타일링) const formatReportText = (text: string): React.ReactNode[] => { if (!text) return []; // 먼저 \n으로 단락 분리 const paragraphs = text.split('\n'); return paragraphs.map((paragraph, pIdx) => { // 빈 줄은 줄바꿈으로 처리 if (paragraph.trim() === '') { return
; } // 제목 패턴 (한글로 된 짧은 텍스트로 시작하는 경우) const titleMatch = paragraph.match(/^(타겟 고객|핵심 차별점|지역 특성|시즌별 포인트)$/); if (titleMatch) { return (
0 ? '16px' : '0' }}> {paragraph}
); } // 해시태그 처리 const hashtagParts = paragraph.split(/(#[^\s#]+)/g); return (
{hashtagParts.map((segment, segIdx) => { if (segment.startsWith('#')) { return ( {segment} ); } return segment; })}
); }); }; // 마크다운 report를 섹션별로 파싱 const parseReport = (report: string) => { if (!report || report.trim() === '') { return []; } const sections: { title: string; content: string }[] = []; const lines = report.split('\n'); let currentTitle = ''; let currentContent: string[] = []; let hasMarkdownHeaders = report.includes('## '); // 마크다운 헤더가 없는 경우 전체 텍스트를 하나의 섹션으로 반환 if (!hasMarkdownHeaders) { return [{ title: '분석 결과', content: report.trim() }]; } lines.forEach((line) => { if (line.startsWith('## ')) { if (currentTitle || currentContent.length > 0) { sections.push({ title: currentTitle, content: currentContent.join('\n').trim() }); } currentTitle = line.replace('## ', '').trim(); currentContent = []; } else if (!line.startsWith('# ')) { currentContent.push(line); } }); if (currentTitle || currentContent.length > 0) { sections.push({ title: currentTitle, content: currentContent.join('\n').trim() }); } return sections.filter(s => s.content && !s.title.includes('JSON')); }; const AnalysisResultSection: React.FC = ({ onBack, onGenerate, data }) => { const { processed_info, marketing_analysis } = data; const tags = marketing_analysis.tags || []; const facilities = marketing_analysis.facilities || []; const reportSections = parseReport(marketing_analysis.report); return (
{/* Back Button */}
{/* Header */}

브랜드 분석

쉽고 빠르게, 브랜드 소셜 미디어 캠페인을 만드세요.

{/* Main Content Grid */}
{/* Brand Identity */}
브랜드 정체성 AI 마케팅 분석 요약

{processed_info.customer_name}

{processed_info.region} · {processed_info.detail_region_info}

{/* Marketing Analysis Summary */}
{reportSections.length === 0 ? (
{marketing_analysis.report ? formatReportText(marketing_analysis.report) : '분석 결과가 없습니다.'}
) : (
{reportSections.map((section, idx) => (
{section.title &&

{section.title}

}
{formatReportText(section.content)}
))}
)}
{/* Right Cards */}
{/* Main Selling Points (Facilities) */}
주요 셀링 포인트
{facilities.map((facility, idx) => ( {facility} ))}
{/* Recommended Target Keywords (Tags) */}
추천 타겟 키워드
{tags.map((tag, idx) => ( {tag} ))}
{/* Bottom Button */}
); }; export default AnalysisResultSection;