import React, { ReactNode, HTMLAttributes } from 'react';

interface TableProps extends HTMLAttributes<HTMLTableElement> {
  children: ReactNode;
  className?: string;
}

export function Table({ children, className = '', ...props }: TableProps) {
  return (
    <div style={{ overflowX: 'auto' }}>
      <table className={`w-full ${className}`} {...props}>
        {children}
      </table>
    </div>
  );
}

interface TableHeadProps extends HTMLAttributes<HTMLTableSectionElement> {
  children: ReactNode;
}

export function TableHead({ children, ...props }: TableHeadProps) {
  return (
    <thead {...props}>
      {children}
    </thead>
  );
}

interface TableBodyProps extends HTMLAttributes<HTMLTableSectionElement> {
  children: ReactNode;
}

export function TableBody({ children, ...props }: TableBodyProps) {
  return (
    <tbody {...props}>
      {children}
    </tbody>
  );
}

interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {
  children: ReactNode;
  className?: string;
}

export function TableRow({ children, className = '', ...props }: TableRowProps) {
  const baseClasses = 'border-b border-charcoal-outline/50 hover:bg-iron-gray/30 transition-colors';
  const classes = className ? `${baseClasses} ${className}` : baseClasses;

  return (
    <tr className={classes} {...props}>
      {children}
    </tr>
  );
}

interface TableHeaderProps extends HTMLAttributes<HTMLTableCellElement> {
  children: ReactNode;
  className?: string;
}

export function TableHeader({ children, className = '', ...props }: TableHeaderProps) {
  const baseClasses = 'text-left py-3 px-4 text-xs font-medium text-gray-400 uppercase';
  const classes = className ? `${baseClasses} ${className}` : baseClasses;

  return (
    <th className={classes} {...props}>
      {children}
    </th>
  );
}

interface TableCellProps extends HTMLAttributes<HTMLTableCellElement> {
  children: ReactNode;
  className?: string;
}

export function TableCell({ children, className = '', ...props }: TableCellProps) {
  const baseClasses = 'py-3 px-4';
  const classes = className ? `${baseClasses} ${className}` : baseClasses;

  return (
    <td className={classes} {...props}>
      {children}
    </td>
  );
}
