import { DiamondFillIcon, DiamondIcon, Hash, KeyRound, Link, Table2, } from '@liam-hq/ui' import clsx from 'clsx' import { Command } from 'cmdk' import { type ComponentProps, type FC, useMemo } from 'react' import { getTableColumnElementId, getTableColumnLinkHref, getTableIndexElementId, getTableLinkHref, } from '../../../../../../features' import { useSchemaOrThrow } from '../../../../../../stores' import { getTableIndexLinkHref } from '../../../../utils/url/getTableIndexLinkHref' import type { CommandPaletteSuggestion } from '../types' import { getSuggestionText } from '../utils' import styles from './CommandPaletteOptions.module.css' import { useTableOptionSelect } from './hooks/useTableOptionSelect' import { type ColumnType, getColumnTypeMap } from './utils/getColumnTypeMap' type Props = { tableName: string suggestion: CommandPaletteSuggestion | null } const ColumnIcon: FC & { columnType: ColumnType }> = ({ columnType, ...props }) => { switch (columnType) { case 'PRIMARY_KEY': return case 'FOREIGN_KEY': return case 'NOT_NULL': return case 'NULLABLE': return } } export const TableDetailOptions: FC = ({ tableName, suggestion }) => { const schema = useSchemaOrThrow() const { optionSelectHandler } = useTableOptionSelect(suggestion) const table = schema.current.tables[tableName] const columnTypeMap = useMemo( () => (table ? getColumnTypeMap(table) : {}), [table], ) if (!table) { return null } return ( optionSelectHandler(event, table.name)} > {table.name} {Object.values(table.columns).map((column) => ( optionSelectHandler( event, table.name, getTableColumnElementId(table.name, column.name), ) } > {columnTypeMap[column.name] && ( )} {column.name} ))} {Object.values(table.indexes).map((index) => ( optionSelectHandler( event, table.name, getTableIndexElementId(table.name, index.name), ) } > {index.name} ))} ) }