import '../style.scss';
import Link from 'next/link';
import { DisclosureRow, CORP_CLS_LABEL, CorpClsCode } from '@/types/market';
import { dartViewerUrl } from '@/lib/utils/market';

function corpClsLabel(cls: string): string {
	return CORP_CLS_LABEL[cls as CorpClsCode] ?? cls;
}

// 공시 컴팩트 리스트 — 개요/피드 공용 (RSC). 회사명 | 법인구분 | 보고서명(DART 링크) | 접수일
export default function DisclosureList({ rows }: { rows: DisclosureRow[] })
{
	if (rows.length === 0) {
		return <p className='market__empty'>표시할 공시가 없습니다.</p>;
	}

	return (
		<ul className='market__disclosure-list'>
			{rows.map(row => (
				<li key={row.rceptNo} className='market__disclosure-item'>
					{row.stockCode ? (
						<Link href={`/stock/${row.stockCode}?tab=disclosure`} className='market__disclosure-corp'>
							{row.corpName}
						</Link>
					) : (
						<span className='market__disclosure-corp'>{row.corpName}</span>
					)}
					<span className='market__cls-badge'>{corpClsLabel(row.corpCls)}</span>
					<a
						href={dartViewerUrl(row.rceptNo)}
						target='_blank'
						rel='noopener noreferrer'
						className='market__disclosure-report'
						title={row.reportNm}
					>
						{row.reportNm}
					</a>
					<span className='market__disclosure-date'>{row.rceptDt}</span>
				</li>
			))}
		</ul>
	);
}
