{"version":3,"file":"wizard.mjs","names":[],"sources":["../../../../package/common/wizard/wizard.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport cx from 'classnames';\nimport styles from './wizard.module.pcss';\nimport type { WizardProps } from './wizard.types';\n\nexport default function Wizard({\n  currentStep = 0,\n  stepCount = 0,\n  renderStep = () => null,\n  className,\n  style,\n  classNames,\n  styles: slotStyles,\n  ...rest\n}: WizardProps) {\n  const [height, setHeight] = useState<number | undefined>(undefined);\n  const [showOtherContent, setShowOtherContent] = useState(false);\n  const [prevStep, setPrevStep] = useState(currentStep);\n  const stepRefs = useRef<(HTMLDivElement | null)[]>([]);\n  const resizeObserverRef = useRef<ResizeObserver | null>(null);\n\n  // When currentStep changes, briefly show off-screen steps so they animate out.\n  if (currentStep !== prevStep) {\n    setPrevStep(currentStep);\n    setShowOtherContent(true);\n  }\n\n  useEffect(() => {\n    if (!showOtherContent) return;\n    const id = setTimeout(() => setShowOtherContent(false), 400);\n    return () => clearTimeout(id);\n  }, [showOtherContent]);\n\n  // Track the height of the active step via ResizeObserver.\n  useEffect(() => {\n    resizeObserverRef.current?.disconnect();\n    const el = stepRefs.current[currentStep];\n    if (!el) return;\n    setHeight(el.clientHeight);\n    resizeObserverRef.current = new ResizeObserver(() => {\n      setHeight(el.clientHeight);\n    });\n    resizeObserverRef.current.observe(el);\n    return () => resizeObserverRef.current?.disconnect();\n  }, [currentStep, stepCount]);\n\n  const rootStyle: React.CSSProperties = {\n    ...(height !== undefined ? { height: `${height}px` } : {}),\n    ...slotStyles?.root,\n    ...style,\n  };\n\n  return (\n    <div {...rest} className={cx(styles.wizard, classNames?.root, className)} style={rootStyle}>\n      <div\n        className={cx(styles.wizardContentContainer, classNames?.container)}\n        style={{\n          width: `${stepCount * 100}%`,\n          marginLeft: `-${currentStep * 100}%`,\n          ...slotStyles?.container,\n        }}\n      >\n        {Array.from({ length: stepCount }, (_, index) => (\n          <div\n            key={`wizardStep${index}`}\n            ref={(ref) => {\n              stepRefs.current[index] = ref;\n            }}\n            className={cx(styles.wizardContent, classNames?.step)}\n            style={{\n              width: `${100 / stepCount}%`,\n              marginLeft: `${(100 / stepCount) * index}%`,\n              ...slotStyles?.step,\n            }}\n          >\n            <div\n              className={cx(\n                { [styles.wizardContentOutOfFrame]: currentStep !== index && !showOtherContent },\n                classNames?.stepContent,\n              )}\n              style={slotStyles?.stepContent}\n              inert={currentStep !== index ? true : undefined}\n            >\n              {renderStep(index)}\n            </div>\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n"],"mappings":"8KAKA,SAAwB,EAAO,CAC7B,cAAc,EACd,YAAY,EACZ,iBAAmB,KACnB,YACA,QACA,aACA,OAAQ,EACR,GAAG,GACW,CACd,GAAM,CAAC,EAAQ,GAAa,EAA6B,IAAA,EAAS,EAC5D,CAAC,EAAkB,GAAuB,EAAS,EAAK,EACxD,CAAC,EAAU,GAAe,EAAS,CAAW,EAC9C,EAAW,EAAkC,CAAC,CAAC,EAC/C,EAAoB,EAA8B,IAAI,EAGxD,IAAgB,IAClB,EAAY,CAAW,EACvB,EAAoB,EAAI,GAG1B,MAAgB,CACd,GAAI,CAAC,EAAkB,OACvB,IAAM,EAAK,eAAiB,EAAoB,EAAK,EAAG,GAAG,EAC3D,UAAa,aAAa,CAAE,CAC9B,EAAG,CAAC,CAAgB,CAAC,EAGrB,MAAgB,CACd,EAAkB,SAAS,WAAW,EACtC,IAAM,EAAK,EAAS,QAAQ,GACvB,KAML,OALA,EAAU,EAAG,YAAY,EACzB,EAAkB,QAAU,IAAI,mBAAqB,CACnD,EAAU,EAAG,YAAY,CAC3B,CAAC,EACD,EAAkB,QAAQ,QAAQ,CAAE,MACvB,EAAkB,SAAS,WAAW,CACrD,EAAG,CAAC,EAAa,CAAS,CAAC,EAE3B,IAAM,EAAiC,CACrC,GAAI,IAAW,IAAA,GAAwC,CAAC,EAA7B,CAAE,OAAQ,GAAG,EAAO,GAAI,EACnD,GAAG,GAAY,KACf,GAAG,CACL,EAEA,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