import React from 'react';

interface File {
  name: string;
}

interface FileListProps {
  files: File[];
  currentFile: File | null;
  onFileClick: (file: File) => void;
  onCreateFile: () => void;
  onDeleteFile: (filename: string) => void;
  loading: boolean;
}

const FileList: React.FC<FileListProps> = ({
  files,
  currentFile,
  onFileClick,
  onCreateFile,
  onDeleteFile,
  loading,
}) => {
  return (
    <div className="bg-secondary border-r border-custom p-4">
      <div className="flex items-center justify-between mb-4">
        <h2 className="text-lg font-semibold">Files</h2>
        <button
          onClick={onCreateFile}
          className="px-3 py-1 bg-blue-500 text-white rounded hover:bg-blue-600 transition text-sm"
        >
          + New
        </button>
      </div>
      {loading && files.length === 0 ? (
        <p className="text-gray-500">Loading...</p>
      ) : (
        <ul className="space-y-2">
          {files.map((file) => (
            <li
              key={file.name}
              className={`p-2 rounded cursor-pointer transition ${
                currentFile?.name === file.name
                  ? 'bg-blue-500 text-white'
                  : 'hover:bg-gray-200'
              }`}
              onClick={() => onFileClick(file)}
            >
              <span className="truncate block">{file.name}</span>
            </li>
          ))}
        </ul>
      )}
    </div>
  );
};

export default FileList;
