import { Card, Badge, IconButton, Stack, Flex, Text } from '@/components/atoms' import { DataSourceBadge } from '@/components/atoms/DataSourceBadge' import { DataSource } from '@/types/json-ui' import { Pencil, Trash, ArrowsDownUp } from '@phosphor-icons/react' interface DataSourceCardProps { dataSource: DataSource dependents?: DataSource[] onEdit: (id: string) => void onDelete: (id: string) => void } export function DataSourceCard({ dataSource, dependents = [], onEdit, onDelete }: DataSourceCardProps) { const getDependencyCount = () => { if (dataSource.type === 'computed') { return dataSource.dependencies?.length || 0 } return 0 } const renderTypeSpecificInfo = () => { if (dataSource.type === 'kv') { return ( Key: {dataSource.key || 'Not set'} ) } if (dataSource.type === 'computed') { const depCount = getDependencyCount() return ( {depCount} {depCount === 1 ? 'dependency' : 'dependencies'} ) } return null } return ( {dataSource.id} {renderTypeSpecificInfo()} {dependents.length > 0 && ( Used by {dependents.length} computed {dependents.length === 1 ? 'source' : 'sources'} )} } variant="ghost" size="sm" onClick={() => onEdit(dataSource.id)} /> } variant="ghost" size="sm" onClick={() => onDelete(dataSource.id)} className="text-destructive hover:text-destructive" disabled={dependents.length > 0} /> ) }