'use client';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
import { formatNumber } from '@/lib/utils/amount';
import type { IncomeStatementMonthlyData, IncomeStatementSection } from './types';
import { HIGHLIGHT_CODES } from './types';
interface MonthlyViewProps {
data: IncomeStatementMonthlyData;
selectedMonth: string | null; // null = 전체
unitLabel: string;
}
export function MonthlyView({ data, selectedMonth, unitLabel }: MonthlyViewProps) {
const { months, fiscalLabel } = data;
if (selectedMonth) {
// 개별 월 보기
const monthData = months.find((m) => m.month === selectedMonth);
if (!monthData) {
return
해당 월 데이터가 없습니다.
;
}
return (
);
}
// 전체 월 비교 보기 (가로 스크롤)
return (
);
}
// 개별 월 보기 — PeriodView와 동일한 2열(금액+소계) 구조
function SingleMonthView({
sections,
monthLabel,
fiscalLabel,
unitLabel,
}: {
sections: IncomeStatementSection[];
monthLabel: string;
fiscalLabel: string;
unitLabel: string;
}) {
return (
과 목
{fiscalLabel} {monthLabel}
금 액
{sections.map((section) => {
const isHighlight = HIGHLIGHT_CODES.includes(section.code);
const highlightClass = isHighlight ? 'bg-green-50' : '';
// 계산 항목 또는 세부과목 없는 항목
if (section.items.length === 0) {
return (
{section.code}. {section.name}
{section.currentAmount !== 0 ? formatNumber(section.currentAmount) : ''}
);
}
// 세부과목 있는 항목
const lastIdx = section.items.length - 1;
return (
);
})}
(단위: {unitLabel})
);
}
function SingleMonthSectionRows({
section,
lastIdx,
}: {
section: IncomeStatementSection;
lastIdx: number;
}) {
return (
<>
{section.code}. {section.name}
{section.items.map((item, idx) => {
const isLast = idx === lastIdx;
return (
{item.name}
{item.current !== 0 ? formatNumber(item.current) : ''}
{isLast ? formatNumber(section.currentAmount) : ''}
);
})}
>
);
}
// 전체 월 비교 보기 (가로 스크롤, 과목 열 sticky)
function AllMonthsView({
months,
fiscalLabel,
unitLabel,
}: {
months: IncomeStatementMonthlyData['months'];
fiscalLabel: string;
unitLabel: string;
}) {
const baseSections = months[0]?.sections || [];
const rows: {
type: 'section' | 'item';
code: string;
name: string;
sectionCode: string;
isHighlight: boolean;
}[] = [];
baseSections.forEach((section) => {
const isHighlight = HIGHLIGHT_CODES.includes(section.code);
rows.push({
type: 'section',
code: section.code,
name: `${section.code}. ${section.name}`,
sectionCode: section.code,
isHighlight,
});
section.items.forEach((item) => {
rows.push({
type: 'item',
code: item.code,
name: item.name,
sectionCode: section.code,
isHighlight: false,
});
});
});
const monthMaps = months.map((m) => {
const sectionMap = new Map();
const itemMap = new Map();
m.sections.forEach((s) => {
sectionMap.set(s.code, s.currentAmount);
s.items.forEach((it) => {
itemMap.set(`${s.code}-${it.code}`, it.current);
});
});
return { sectionMap, itemMap };
});
return (
과목
{months.map((m) => (
{m.label}
))}
{rows.map((row) => {
const isSection = row.type === 'section';
const highlightClass = row.isHighlight ? 'bg-green-50' : '';
const sectionBg = isSection && !row.isHighlight ? 'bg-muted/30' : '';
return (
{row.name}
{months.map((m, mi) => {
const amount = isSection
? monthMaps[mi].sectionMap.get(row.sectionCode) ?? 0
: monthMaps[mi].itemMap.get(`${row.sectionCode}-${row.code}`) ?? 0;
return (
{formatNumber(amount)}
);
})}
);
})}
(단위: {unitLabel})
);
}