import { StackProps, Stack, Heading, HStack, Input, Flex, FormControl, FormLabel, NumberInput, NumberInputField, NumberInputStepper, NumberIncrementStepper, NumberDecrementStepper, Switch, Text, Tag, } from '@chakra-ui/react' import { ColorPicker } from 'components/theme/GeneralSettings/ColorPicker' import { useTypebot } from 'contexts/TypebotContext' import { useState, useEffect } from 'react' import { BubbleParams } from 'typebot-js' type ChatEmbedSettingsProps = { onUpdateSettings: ( windowSettings: Pick ) => void } export const ChatEmbedSettings = ({ onUpdateSettings, ...props }: ChatEmbedSettingsProps & StackProps) => { const { typebot } = useTypebot() const [proactiveMessageChecked, setProactiveMessageChecked] = useState(false) const [rememberProMessageChecked] = useState(true) const [customIconInputValue, setCustomIconInputValue] = useState('') const [inputValues, setInputValues] = useState({ messageDelay: '0', messageContent: 'I have a question for you!', }) const [bubbleColor, setBubbleColor] = useState( typebot?.theme.chat.buttons.backgroundColor ?? '#0042DA' ) useEffect(() => { if (proactiveMessageChecked) { onUpdateSettings({ button: { color: bubbleColor, iconUrl: customIconInputValue, }, proactiveMessage: { delay: parseInt(inputValues.messageDelay) * 1000, textContent: inputValues.messageContent, rememberClose: rememberProMessageChecked, }, }) } else { onUpdateSettings({ button: { color: bubbleColor, iconUrl: customIconInputValue, }, proactiveMessage: undefined, }) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [ inputValues, bubbleColor, rememberProMessageChecked, customIconInputValue, proactiveMessageChecked, ]) return ( Chat bubble settings Button color Custom button icon Optional setCustomIconInputValue(e.target.value)} /> Enable popup message? setProactiveMessageChecked(!proactiveMessageChecked) } isChecked={proactiveMessageChecked} /> {proactiveMessageChecked && ( <> Appearance delay setInputValues({ ...inputValues, messageDelay, }) } value={inputValues.messageDelay} min={0} > Message content setInputValues({ ...inputValues, messageContent: e.target.value, }) } value={inputValues.messageContent} /> )} ) }