import React, { FC, lazy, Suspense, useEffect, useRef, useState } from "react"; import {__} from "../../globals"; import type { ComponentRuntimeData, ComponentRuntimeDataWithParentType } from "../components"; import type { BuyXGetXOptions } from "./BuyXGetX.card"; import { FieldType } from "../fields"; import { EmulatedButton } from "../EmulatedButton"; import classNames from "classnames"; import { SmoothHeight } from "./SmoothHeight"; export type DuplicateFieldsProps = { componentRuntimeData: ComponentRuntimeDataWithParentType onUpdate?: (data) => void, } const SingleFieldRenderer = lazy(() => import('../../Fields').then(module => ({default: module.SingleFieldRenderer})) ); // this component seems to unmount on update so we have to set the opened state here. yes, this will make subsequent getx opens show this but its better than the buggy impl. when switching from 'duplicate' to 'fix' and have the uh section close on us const enabledIt = { current: false } export const DuplicateFields: FC = ({componentRuntimeData, onUpdate}) => { const [isEnabled, setIsEnabled] = useState(false) const canShow = isEnabled || componentRuntimeData.options.quantityType === 'duplicate' || enabledIt.current useEffect(() => { // always open it if (canShow) { enabledIt.current = true } }, [canShow]) return

{__('Advanced')}
{!canShow && }

{canShow && }
}