import React from 'react' import { AvatarProps } from '@typebot.io/schemas' import { Heading, HStack, Popover, PopoverContent, Stack, Switch, Image, Flex, Box, Portal, PopoverAnchor, useDisclosure, } from '@chakra-ui/react' import { ImageUploadContent } from '@/components/ImageUploadContent' import { DefaultAvatar } from '../DefaultAvatar' import { useOutsideClick } from '@/hooks/useOutsideClick' type Props = { uploadFilePath: string title: string avatarProps?: AvatarProps isDefaultCheck?: boolean onAvatarChange: (avatarProps: AvatarProps) => void } export const AvatarForm = ({ uploadFilePath, title, avatarProps, isDefaultCheck = false, onAvatarChange, }: Props) => { const { isOpen, onOpen, onClose } = useDisclosure() const isChecked = avatarProps ? avatarProps.isEnabled : isDefaultCheck const handleOnCheck = () => onAvatarChange({ ...avatarProps, isEnabled: !isChecked }) const handleImageUrl = (url: string) => onAvatarChange({ isEnabled: isChecked, url }) const popoverContainerRef = React.useRef(null) useOutsideClick({ ref: popoverContainerRef, handler: onClose, isEnabled: isOpen, }) const isDefaultAvatar = !avatarProps?.url || avatarProps.url.includes('{{') return ( {title} {isChecked && ( {isDefaultAvatar ? ( ) : ( Website image )} e.stopPropagation()} onPointerDown={(e) => e.stopPropagation()} > )} ) }