/**
 * PlanBody — 마케팅 기획 본문 (읽기 전용 섹션) 의 순수 렌더링 컴포넌트.
 *
 * 각 섹션은 데이터가 비어있으면 `EmptySection` 으로 fallback 되어
 * "데이터가 없습니다" 안내가 표시됩니다.
 */
import type { MarketingPlan } from '../types/plan';
import { EmptySection } from '@/features/report/components/ui/EmptySection';
import PlanHeader from './PlanHeader';
import BrandingGuide from './BrandingGuide';
import ChannelStrategy from './ChannelStrategy';
import ContentStrategy from './ContentStrategy';
import ContentCalendar from './ContentCalendar';
import AssetCollection from './AssetCollection';
import RepurposingProposal from './RepurposingProposal';

interface PlanBodyProps {
  data: MarketingPlan;
}

function hasValue<T>(v: T | null | undefined): v is T {
  return v != null;
}

function nonEmpty<T>(arr: T[] | null | undefined): arr is T[] {
  return Array.isArray(arr) && arr.length > 0;
}

export default function PlanBody({ data }: PlanBodyProps) {
  // 플랜 데이터엔 직접 social handle 필드가 없어 website 만 전달.
  // 정식 연동 시 플랜이 source report 의 socialHandles 를 같이 가져와야 함 (TODO).
  const socialHandles = {
    website: data.targetUrl || null,
  };

  return (
    <div data-plan-content>
      <PlanHeader
        clinicName={data.clinicName}
        clinicNameEn={data.clinicNameEn}
        date={data.createdAt}
        targetUrl={data.targetUrl}
        socialHandles={socialHandles}
      />

      {hasValue(data.brandGuide) ? (
        <BrandingGuide data={data.brandGuide} clinicName={data.clinicName} />
      ) : (
        <EmptySection id="branding-guide" title="Brand Guide" subtitle="브랜딩 가이드" />
      )}

      {nonEmpty(data.channelStrategies) ? (
        <ChannelStrategy channels={data.channelStrategies} />
      ) : (
        <EmptySection id="channel-strategy" title="Channel Strategy" subtitle="채널 전략" />
      )}

      {hasValue(data.contentStrategy) ? (
        <ContentStrategy data={data.contentStrategy} />
      ) : (
        <EmptySection id="content-strategy" title="Content Strategy" subtitle="콘텐츠 전략" />
      )}

      {hasValue(data.calendar) ? (
        <ContentCalendar data={data.calendar} />
      ) : (
        <EmptySection id="content-calendar" title="Content Calendar" subtitle="콘텐츠 캘린더" />
      )}

      {hasValue(data.assetCollection) ? (
        <AssetCollection data={data.assetCollection} />
      ) : (
        <EmptySection id="asset-collection" title="Asset Collection" subtitle="에셋 수집" />
      )}

      {nonEmpty(data.repurposingProposals) ? (
        <RepurposingProposal proposals={data.repurposingProposals} />
      ) : (
        <EmptySection id="repurposing-proposal" title="Repurposing Proposals" subtitle="리퍼포징 제안" />
      )}
    </div>
  );
}
