import type { UseFileBrowserWidgetType } from '../useFileBrowserWidget';
import { EntryRow } from './EntryRow';

type RecentTabProps = {
  fileBrowserManager: UseFileBrowserWidgetType;
};

export const RecentTab = ({ fileBrowserManager }: RecentTabProps) => {
  const { recents, openFile, isPinned, togglePin } = fileBrowserManager;

  if (recents.length === 0) {
    return <p className="text-xs text-duck-dark/40 py-4 text-center">No recent files</p>;
  }

  return (
    <ul className="space-y-0.5">
      {recents.map((f) => (
        <EntryRow
          key={f.path}
          name={f.name}
          subtitle={f.path}
          type="file"
          pinned={isPinned(f.path)}
          onPin={() => togglePin(f.path, f.name)}
          onClick={() => openFile(f.path, f.name)}
        />
      ))}
    </ul>
  );
};
