import React, { useState, createContext, useContext } from 'react'; import { FiPlus, FiTrash2, FiChevronDown, FiChevronUp, FiAlertTriangle, } from 'react-icons/fi'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'; import { Checkbox } from '../ui/checkbox'; import { Button } from '../ui/Button'; import Typography from '../ui/Typography'; import type { WidgetProps, TemplatesType, ArrayFieldTemplateProps, ObjectFieldTemplateProps, FieldTemplateProps } from '@rjsf/utils'; interface FieldInteractionContextType { interactedFields: Set; attemptedSubmit: boolean; markFieldInteracted: (fieldId: string) => void; markSubmitAttempted: () => void; } const FieldInteractionContext = createContext(null); export const FieldInteractionProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [interactedFields, setInteractedFields] = useState>(new Set()); const [attemptedSubmit, setAttemptedSubmit] = useState(false); const markFieldInteracted = (fieldId: string) => { setInteractedFields(prev => new Set(prev).add(fieldId)); }; const markSubmitAttempted = () => { setAttemptedSubmit(true); }; return ( {children} ); }; const useFieldInteraction = () => { const context = useContext(FieldInteractionContext); if (!context) { throw new Error('useFieldInteraction must be used within a FieldInteractionProvider'); } return context; }; type CollapsibleContainerProps = { name: string; isOpen: boolean; children: React.ReactNode; className?: string; disableGrow?: boolean; }; /** * Collapsible container component for organizing form sections * with expand/collapse functionality for better UX. */ const CollapsibleContainer: React.FC = ({ name, isOpen: initialOpen, children, className = '', disableGrow = false, }) => { const [isOpen, setIsOpen] = useState(initialOpen); return (
setIsOpen(!isOpen)}>

{name}

{isOpen ? ( ) : ( )}
{isOpen && (
{children}
)}
); }; /** * Custom input widget for RJSF using ChatPage design patterns. * Handles text input with glass morphism styling and proper event handling. */ const CustomInputWidget = (props: WidgetProps) => { const { markFieldInteracted } = useFieldInteraction(); const handleFocus = () => { props.onFocus && props.onFocus(props.id, props.value); }; const handleBlur = () => { markFieldInteracted(props.id); props.onBlur && props.onBlur(props.id, props.value); }; const handleChange = (event: React.ChangeEvent) => { markFieldInteracted(props.id); props.onChange(event.target.value); }; return ( ); }; /** * Custom textarea widget for RJSF using ChatPage design patterns. * Handles multi-line text input with glass morphism styling. */ const CustomTextareaWidget = (props: WidgetProps) => { const { markFieldInteracted } = useFieldInteraction(); const handleFocus = () => { props.onFocus && props.onFocus(props.id, props.value); }; const handleBlur = () => { markFieldInteracted(props.id); props.onBlur && props.onBlur(props.id, props.value); }; const handleChange = (event: React.ChangeEvent) => { markFieldInteracted(props.id); props.onChange(event.target.value); }; return (