'use client'; import { useState } from 'react'; import { FileTextIcon, LayersIcon } from 'lucide-react'; import { Badge } from '@kit/ui/badge'; import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@kit/ui/dialog'; import { Separator } from '@kit/ui/separator'; interface SchemaFile { filename: string; topic: string; description: string; section?: string; tables?: string[]; functions?: string[]; } interface SchemaExplorerProps { searchTerm: string; schemaFiles: SchemaFile[]; } const topicColors: Record = { security: 'bg-red-100 text-red-800', types: 'bg-purple-100 text-purple-800', configuration: 'bg-blue-100 text-blue-800', accounts: 'bg-green-100 text-green-800', permissions: 'bg-orange-100 text-orange-800', teams: 'bg-teal-100 text-teal-800', billing: 'bg-yellow-100 text-yellow-800', notifications: 'bg-pink-100 text-pink-800', auth: 'bg-indigo-100 text-indigo-800', admin: 'bg-gray-100 text-gray-800', storage: 'bg-cyan-100 text-cyan-800', }; export function SchemaExplorer({ searchTerm, schemaFiles, }: SchemaExplorerProps) { const [selectedSchema, setSelectedSchema] = useState(null); const [isDialogOpen, setIsDialogOpen] = useState(false); // Filter schemas based on search term const filteredSchemas = schemaFiles.filter( (schema) => schema.filename.toLowerCase().includes(searchTerm.toLowerCase()) || schema.description.toLowerCase().includes(searchTerm.toLowerCase()) || schema.topic.toLowerCase().includes(searchTerm.toLowerCase()) || schema.section?.toLowerCase().includes(searchTerm.toLowerCase()), ); // Group schemas by topic for better organization const schemasByTopic = filteredSchemas.reduce( (acc, schema) => { if (!acc[schema.topic]) { acc[schema.topic] = []; } acc[schema.topic].push(schema); return acc; }, {} as Record, ); const handleSchemaClick = (schema: SchemaFile) => { setSelectedSchema(schema); setIsDialogOpen(true); }; const closeDialog = () => { setIsDialogOpen(false); setSelectedSchema(null); }; return (
{/* Summary */}

Total Schemas

{filteredSchemas.length}

Topics

{Object.keys(schemasByTopic).length}

Total Tables

{filteredSchemas.reduce( (acc, schema) => acc + (schema.tables?.length || 0), 0, )}

{/* Schema Files by Topic */} {Object.entries(schemasByTopic).map(([topic, schemas]) => (
{topic.toUpperCase()} {schemas.length} file{schemas.length !== 1 ? 's' : ''}
{schemas.map((schema) => ( handleSchemaClick(schema)} > {schema.filename}

{schema.description}

{schema.section && (
Section: {schema.section}
)} {(schema.tables || schema.functions) && (
{schema.tables && schema.tables.length > 0 && (
Tables: {schema.tables.slice(0, 3).join(', ')} {schema.tables.length > 3 && ` +${schema.tables.length - 3} more`}
)} {schema.functions && schema.functions.length > 0 && (
Functions: {schema.functions.slice(0, 2).join(', ')} {schema.functions.length > 2 && ` +${schema.functions.length - 2} more`}
)}
)}
))}
))} {/* Schema Details Dialog */} {selectedSchema?.filename}
{selectedSchema && ( <>

Description

{selectedSchema.description}

{selectedSchema.section && ( <>

Section

{selectedSchema.section}
)} {selectedSchema.tables && selectedSchema.tables.length > 0 && ( <>

Tables ({selectedSchema.tables.length})

{selectedSchema.tables.map((table) => ( {table} ))}
)} {selectedSchema.functions && selectedSchema.functions.length > 0 && ( <>

Functions ({selectedSchema.functions.length})

{selectedSchema.functions.map((func) => ( {func} ))}
)} )}
{filteredSchemas.length === 0 && (

{searchTerm ? 'No schemas match your search' : 'No schemas found'}

)}
); }