import React, { useState, useEffect, useRef } from 'react'; import './DatasetManager.css'; import { Dataset, LibraryEntry, DataRecord, DataValue } from '../../types'; import { HugeiconsIcon } from "@hugeicons/react"; import { AddCircleIcon, Delete02Icon, FolderAddIcon, Edit02Icon } from "@hugeicons/core-free-icons"; // Reusable Modal Component const Modal: React.FC<{ isOpen: boolean; onClose: () => void; title: string; children: React.ReactNode; actions: { label: string; onClick: () => void; className?: string }[]; size?: 'default' | 'large'; }> = ({ isOpen, onClose, title, children, actions, size = 'default' }) => { if (!isOpen) return null; const modalContentClass = `modal-content ${size === 'large' ? 'entry-editor-content' : ''}`; return (
e.stopPropagation()}>

{title}

{children}
{actions.map((action, index) => ( ))}
); }; // Data Record Editor Component const DataRecordEditor = ({ data, onChange }: { data: DataRecord, onChange: (newData: DataRecord) => void }) => { const [addingInfo, setAddingInfo] = useState<{type: 'field' | 'group'} | null>(null); const [newKey, setNewKey] = useState(''); const newKeyInputRef = useRef(null); useEffect(() => { if (addingInfo) { newKeyInputRef.current?.focus(); } }, [addingInfo]); const handleFieldChange = (key: string, value: DataValue) => { onChange({ ...data, [key]: value }); }; const handleRemoveField = (key: string) => { const { [key]: _, ...rest } = data; onChange(rest); }; const handleInitiateAdd = (type: 'field' | 'group') => { setAddingInfo({ type }); }; const handleConfirmAdd = () => { const key = newKey.trim(); if (key && !data.hasOwnProperty(key)) { onChange({ ...data, [key]: addingInfo?.type === 'group' ? {} : '' }); setNewKey(''); setAddingInfo(null); } else if (key) { alert(`The key "${key}" already exists.`); } else { setAddingInfo(null); } }; return (
{Object.keys(data).length === 0 &&

This entry is empty. Add a field or group to begin.

} {Object.entries(data).map(([key, value]) => (
{typeof value === 'object' && value !== null ? (
handleFieldChange(key, newValue)} />
) : (