import styled, { CSSProperties } from 'styled-components'; import { Button } from '../buttonv2/Buttonv2.component'; import { useCallback, useMemo } from 'react'; import { Box } from '../box/Box'; import { Icon } from '../icon/Icon.component'; const CustomButton = styled(Button)<{ isVisible?: boolean }>` ${(props) => !props.isVisible ? ` display: none; ` : ''} `; const isEmptyItem = (item) => item.key === '' && item.value === ''; type AddButtonProps = { index: number; items: Array; insertEntry: () => void; disabled?: boolean; iconStyle?: CSSProperties; }; export const AddButton = ({ index, items, insertEntry, disabled, iconStyle, }: AddButtonProps) => { const itemsLength = items.length; const itemsIndex = items[index]; const itemsIndexKey = (items[index] as { key: string }).key; const itemsIndexValue = (items[index] as { value: string }).value; const isDisabled = useMemo(() => { if (itemsIndex && itemsIndexKey === '' && itemsIndexValue === '') { return true; } return disabled || false; }, [itemsIndex, itemsIndexKey, itemsIndexValue, disabled]); const isVisible = useMemo(() => { return !(itemsLength > 0 && index !== itemsLength - 1); }, [itemsLength, index]); const onClickFn = useCallback(() => { if (!(itemsLength > 0 && index !== itemsLength - 1)) { insertEntry(); } }, [itemsLength, index, insertEntry]); return ( <> {!isVisible && } } /> ); }; type SubButtonProps = { index: number; items: Array; deleteEntry: (arg0: number) => void; disabled?: boolean; iconStyle?: CSSProperties; }; export const SubButton = ({ index, items, deleteEntry, disabled, iconStyle, }: SubButtonProps) => { let isDisabled = disabled || false; if (items.length === 1 && isEmptyItem(items[0])) { isDisabled = true; } return (