import { TypingBubble } from '@/components' import { isMobile } from '@/utils/isMobileSignal' import { createSignal, onCleanup, onMount } from 'solid-js' import { clsx } from 'clsx' import { CustomEmbedBubble as CustomEmbedBubbleProps } from '@indite.io/schemas' import { executeCode } from '@/features/blocks/logic/script/executeScript' import { botContainerHeight } from '@/utils/botContainerHeightSignal' import { InputSubmitContent } from '@/types' type Props = { content: CustomEmbedBubbleProps['content'] onTransitionEnd?: (ref?: HTMLDivElement) => void onCompleted: (reply?: InputSubmitContent) => void } let typingTimeout: NodeJS.Timeout export const showAnimationDuration = 400 export const CustomEmbedBubble = (props: Props) => { let ref: HTMLDivElement | undefined const [isTyping, setIsTyping] = createSignal( props.onTransitionEnd ? true : false ) let containerRef: HTMLDivElement | undefined onMount(() => { executeCode({ args: { ...props.content.initFunction.args, botElement: containerRef, }, content: props.content.initFunction.content, }) if (props.content.waitForEventFunction) executeCode({ args: { ...props.content.waitForEventFunction.args, continueFlow: (text: string) => props.onCompleted(text ? { type: 'text', value: text } : undefined), }, content: props.content.waitForEventFunction.content, }) typingTimeout = setTimeout(() => { setIsTyping(false) setTimeout(() => props.onTransitionEnd?.(ref), showAnimationDuration) }, 2000) }) onCleanup(() => { if (typingTimeout) clearTimeout(typingTimeout) }) return (