import React, { useState } from 'react'; import Link from 'next/link'; interface PolicyData { title: string; slug: string; fileName: string; originalLink?: string; releaseDate: string; } interface AIPoliciesTableProps { policies: PolicyData[]; } const AIPoliciesTable: React.FC = ({ policies }) => { const groupedPoliciesByYear: { [year: string]: { [slug: string]: PolicyData[] } } = {}; policies.forEach((policy) => { const year = new Date(policy.releaseDate).getFullYear().toString(); if (!groupedPoliciesByYear[year]) { groupedPoliciesByYear[year] = {}; } if (!groupedPoliciesByYear[year][policy.slug]) { groupedPoliciesByYear[year][policy.slug] = []; } groupedPoliciesByYear[year][policy.slug].push(policy); }); const sortedYears = Object.keys(groupedPoliciesByYear).sort((a, b) => parseInt(b) - parseInt(a)); return (
{sortedYears.map((year) => ( ))}
); }; interface YearSectionProps { year: string; groupedPolicies: { [slug: string]: PolicyData[] }; } const YearSection: React.FC = ({ year, groupedPolicies }) => { const [isOpen, setIsOpen] = useState(true); return (
{isOpen && ( {Object.entries(groupedPolicies).map(([slug, policies], index) => { const zhPolicy = policies.find((policy) => policy.fileName === 'zh.md'); const enPolicy = policies.find((policy) => policy.fileName === 'en.md'); return ( ); })}
{zhPolicy?.title}
{enPolicy?.title}
{new Date(zhPolicy?.releaseDate || '').toLocaleDateString()}
{policies.map((policy) => ( policy.originalLink ? ( {policy.fileName === 'zh.md' ? '中文' : 'English'} ) : ( {policy.fileName === 'zh.md' ? '中文' : 'English'} ) ))}
)}
); }; export default AIPoliciesTable;