import { useWorkspace } from '../../../components/Workspace';
import { FileBrowserApp } from './FileBrowserApp';

const cwdToPath = (cwd: string) => (cwd === '~' ? '/' : cwd.slice(1));

export const FileBrowserPanelWrapper = () => {
  const { cwd, initialFilePath, defaultFileSort } = useWorkspace();
  const basePath = cwdToPath(cwd);
  const initialPath = basePath === '/' ? initialFilePath : undefined;
  return <FileBrowserApp basePath={basePath} rootOverride={basePath !== '/' ? 'home' : undefined} initialPath={initialPath} defaultSort={defaultFileSort} />;
};
