import { EditablePreview, EditableInput, Editable, Fade, IconButton, Flex, } from '@chakra-ui/react' import { PlusIcon } from '@/components/icons' import { useTypebot } from '@/features/editor' import { ButtonItem, ItemIndices, ItemType } from 'models' import React, { useRef, useState } from 'react' import { isNotDefined } from 'utils' type Props = { item: ButtonItem indices: ItemIndices isMouseOver: boolean } export const ButtonsItemNode = ({ item, indices, isMouseOver }: Props) => { const { deleteItem, updateItem, createItem } = useTypebot() const [itemValue, setItemValue] = useState(item.content ?? 'Click to edit') const editableRef = useRef(null) const handleInputSubmit = () => { if (itemValue === '') deleteItem(indices) else updateItem(indices, { content: itemValue === '' ? undefined : itemValue }) } const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Escape' && itemValue === 'Click to edit') deleteItem(indices) if (e.key === 'Enter' && itemValue !== '' && itemValue !== 'Click to edit') handlePlusClick() } const handlePlusClick = () => { const itemIndex = indices.itemIndex + 1 createItem( { blockId: item.blockId, type: ItemType.BUTTON }, { ...indices, itemIndex } ) } return ( } size="xs" shadow="md" colorScheme="gray" onClick={handlePlusClick} /> ) }