import '../style.scss'; import '@/app/styles/data-table.scss'; import { Metadata } from 'next'; import MarketNav from '../_components/MarketNav'; import Sparkline from '../_components/Sparkline'; import MacroTable from '../_components/MacroTable'; import { fetchMacroIndicators } from '@/lib/api/macro'; import { MACRO_CODES, MACRO_CODE_LABEL, MacroIndicator } from '@/types/macro'; import { changeDirection, changeSymbol } from '@/lib/utils/stock'; import { macroPeriodLabel, formatMacroValue } from '@/lib/utils/market'; export const metadata: Metadata = { title: '거시지표 — 개미투자', description: '한국 거시경제지표 대시보드 — 고용률·실업률·취업자수·소비자물가지수·수출입액 추이 (KOSIS 수집)' }; // 지표당 조회할 최근 시점 수 (월간 기준 1년) const MACRO_LIMIT = 12; // 백엔드는 코드 오름차순 반환 → 화면 고정 순서(MACRO_CODES)로 재정렬 (미정의 코드는 뒤로) function sortByCode(list: MacroIndicator[]): MacroIndicator[] { const order = new Map(MACRO_CODES.map((code, index) => [code, index])); return [...list].sort((a, b) => (order.get(a.code) ?? MACRO_CODES.length) - (order.get(b.code) ?? MACRO_CODES.length)); } export default async function MarketMacroPage() { const res = await fetchMacroIndicators({ codes: [...MACRO_CODES], limit: MACRO_LIMIT }); const indicators = res.success ? sortByCode(res.data?.list ?? []) : []; return (

거시지표

고용·물가·수출입 최근 추이 (KOSIS)
{!res.success ? (
거시지표 데이터를 불러오지 못했습니다. 잠시 후 다시 시도해 주세요.
) : indicators.length === 0 ? (
표시할 거시지표 데이터가 없습니다. 수집이 시작되면 자동으로 표시됩니다.
) : ( <> {/* 지표별 카드 — 최신값·단위·직전 대비 증감·추이 */}
{indicators.map(indicator => { const label = MACRO_CODE_LABEL[indicator.code] ?? indicator.name; const previous = indicator.points.length > 1 ? indicator.points[indicator.points.length - 2] : null; const delta = indicator.latestValue !== null && previous !== null ? indicator.latestValue - previous.value : null; const direction = changeDirection(delta); return (
{label} {macroPeriodLabel(indicator.latestPeriod)}
{formatMacroValue(indicator.latestValue)} {indicator.unit ? {indicator.unit} : null} {delta === null ? ( '직전 대비 —' ) : ( <> {formatMacroValue(Math.abs(delta))} 직전 대비 )} p.value)} label={`${label} 추이`} />
{macroPeriodLabel(indicator.points[0]?.period)} ~ {macroPeriodLabel(indicator.latestPeriod)} {indicator.points.length}개 시점
); })}
{/* 최근 N기간 매트릭스 */}

최근 추이

지표별 최근 {MACRO_LIMIT}개 시점
)}
); }