import { Download } from 'lucide-react';
import { useI18n } from '../hooks/useI18n';
import type { Download as DownloadType } from '../types';

interface DownloadTableProps {
  downloads: DownloadType[];
  showChecksum?: boolean;
}

export default function DownloadTable({ downloads, showChecksum = false }: DownloadTableProps) {
  const { t } = useI18n();

  return (
    <table className="download-table">
      <thead>
        <tr>
          <th>{t('common.platform')}</th>
          <th>{t('common.arch')}</th>
          <th>{t('common.size')}</th>
          {showChecksum && <th>{t('downloads.checksum')}</th>}
          <th></th>
        </tr>
      </thead>
      <tbody>
        {downloads.map((dl, i) => (
          <tr key={`${dl.platform}-${dl.arch}-${i}`}>
            <td>{dl.platform}</td>
            <td>{dl.arch}</td>
            <td>{dl.size}</td>
            {showChecksum && <td className="sha256">{dl.sha256}</td>}
            <td>
              <a href={dl.url} className="btn btn-sm" target="_blank" rel="noopener noreferrer">
                <Download size={14} /> {t('common.download')}
              </a>
            </td>
          </tr>
        ))}
      </tbody>
    </table>
  );
}
