'use client';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
import { formatNumber } from '@/lib/utils/amount';
import type { IncomeStatementData } from './types';
import { HIGHLIGHT_CODES } from './types';
interface PeriodViewProps {
data: IncomeStatementData;
showPrevious: boolean;
unitLabel: string;
}
export function PeriodView({ data, showPrevious, unitLabel }: PeriodViewProps) {
const { period, sections } = data;
const colSpan = showPrevious ? 5 : 3; // 과목 + (금액+소계) * 기수
return (
{/* 1행: 과목 + 기수 헤더 (녹색 배경) */}
과 목
{period.current.label}
{showPrevious && (
{period.previous.label}
)}
{/* 2행: 금 액 서브헤더 */}
금 액
{showPrevious && (
금 액
)}
{sections.map((section) => {
const isHighlight = HIGHLIGHT_CODES.includes(section.code);
const hasItems = section.items.length > 0;
return (
);
})}
{/* 하단 단위 표기 */}
(단위: {unitLabel})
);
}
interface SectionRowsProps {
code: string;
name: string;
currentAmount: number;
previousAmount: number;
items: { code: string; name: string; current: number; previous: number }[];
isHighlight: boolean;
hasItems: boolean;
showPrevious: boolean;
}
function SectionRows({
code,
name,
currentAmount,
previousAmount,
items,
isHighlight,
hasItems,
showPrevious,
}: SectionRowsProps) {
const highlightClass = isHighlight ? 'bg-green-50' : '';
// 계산 항목 (III, V, VIII, X 등) — 소계열에만 금액 표시
if (!hasItems && isHighlight) {
return (
{code}. {name}
{formatNumber(currentAmount)}
{showPrevious && (
<>
{formatNumber(previousAmount)}
>
)}
);
}
// 세부과목 없는 합계 항목 (VIII 등) — 소계열에만 금액
if (!hasItems) {
return (
{code}. {name}
{currentAmount !== 0 ? formatNumber(currentAmount) : ''}
{showPrevious && (
<>
{previousAmount !== 0 ? formatNumber(previousAmount) : ''}
>
)}
);
}
// 세부 과목이 있는 항목 (I, II, IV, VI, VII, IX)
const lastIdx = items.length - 1;
return (
<>
{/* 섹션 헤더 — 금액 표시 안 함 */}
{code}. {name}
{showPrevious && (
<>
>
)}
{/* 세부 과목 행 — 들여쓰기 */}
{items.map((item, idx) => {
const isLast = idx === lastIdx;
return (
{item.name}
{/* 금액 열 */}
{item.current !== 0 ? formatNumber(item.current) : ''}
{/* 소계 열 — 마지막 세부항목에만 섹션 합계 표시 */}
{isLast ? formatNumber(currentAmount) : ''}
{showPrevious && (
<>
{item.previous !== 0 ? formatNumber(item.previous) : ''}
{isLast ? formatNumber(previousAmount) : ''}
>
)}
);
})}
>
);
}