import { useMemo, type ReactNode } from 'react' import { TextInput, View, type StyleProp, type ViewProps, type ViewStyle } from 'react-native' import { useControlledState } from '@helpwave/hightide-utils/hooks' import { HightideIconRegistry } from '../../icons/HightideIconRegistry' import { IconButton } from '../user-interaction/IconButton' import { useTheme } from '../../global-contexts/theme/ThemeContext' import type { ChatMessageComposerInputStyle, ChatMessageComposerStyle } from '../../theme/types/components/chat' import type { StyleOverwrite } from '../../theme/types/resolver' import { StyleAdapterUtils } from '../../theme' export type ChatMessageComposerProps = Omit & { value?: string, initialValue?: string, onValueChange?: (value: string) => void, onSend: (value: string) => void, placeholder?: string, sendLabel?: string, disabled?: boolean, actions?: ReactNode, trailing?: ReactNode, style?: StyleProp, composerStyle?: StyleOverwrite, ChatMessageComposerStyle>, inputStyle?: StyleOverwrite, ChatMessageComposerInputStyle>, } export const ChatMessageComposer = ({ value: controlledValue, initialValue, onValueChange, onSend, placeholder, sendLabel = 'Send', disabled = false, actions, trailing, style, composerStyle, inputStyle, ...props }: ChatMessageComposerProps) => { const { theme } = useTheme() const [value, setValue] = useControlledState({ value: controlledValue, onValueChange, defaultValue: initialValue ?? '', }) const state = useMemo(() => ({}), []) const resolvedComposerStyle = useMemo( () => theme.components.chat.messageComposer.container(state, composerStyle), [theme, state, composerStyle] ) const resolvedInputStyle = useMemo( () => theme.components.chat.messageComposer.input(state, inputStyle), [theme, state, inputStyle] ) const placeholderColor = useMemo( () => theme.components.chat.messageComposer.placeholderColor(state), [theme, state] ) const send = () => { const trimmed = (value ?? '').trim() if (!trimmed || disabled) { return } onSend(trimmed) setValue('') } return ( {actions != null && ( {actions} )} {trailing} ) }