import { useEffect, useState } from 'react' import { AnimatePresence, motion, useAnimation } from 'framer-motion' import { cn } from 'ui' interface TabProps { label: string | JSX.Element isActive: boolean onClick: VoidFunction } const Tab = ({ isActive, label, onClick }: TabProps) => ( ) interface Tab { label: string | JSX.Element paragraph?: string panel: JSX.Element } interface Props { tabs: Tab[] intervalDuration?: number updateFrequency?: number className?: string } const EnterpriseFormQuotes = ({ tabs, intervalDuration = 25, updateFrequency = 10, className, }: Props) => { const [activeTab, setActiveTab] = useState(0) const [progress, setProgress] = useState(0) const [isPaused, setIsPaused] = useState(false) const controls = useAnimation() const restartInterval = (tabIndex: number) => { setProgress(0) setActiveTab(tabIndex) } const animation = { width: '100%', transition: { duration: intervalDuration, ease: 'linear' }, } useEffect(() => { const progressIncrement = (100 / intervalDuration) * (updateFrequency / 1000) controls.start(animation) const progressInterval = setInterval(() => { if (isPaused) return setProgress(0) setProgress((prevProgress) => (prevProgress + progressIncrement) % 101) }, updateFrequency) return () => { clearInterval(progressInterval) setProgress(0) } }, [activeTab, controls, isPaused]) useEffect(() => { if (progress >= 100.9) { setActiveTab((prevActiveTab) => (prevActiveTab === tabs.length - 1 ? 0 : prevActiveTab + 1)) } }, [progress]) const handleTabClick = (tabIndex: number) => { restartInterval(tabIndex) } return (