import React, { useState, useEffect, useRef } from 'react'; import CriterionInput from '../CriterionInput'; import CardEditor from '../CardEditor'; import BlankCardsCounter from '../BlankCardsCounter'; import AddLevelButton from '../AddLevelButton'; import { FiZoomIn, FiMaximize } from 'react-icons/fi'; export default function Step1BaseScale({ criterionName, handleCriterionChange, levels, handleLevelChange, handleAddLevel, handleRemoveLevel, blankCards, handleBlankCardChange, errors, handleGenerateBaseScale, isLoading }) { const [isZoomActive, setIsZoomActive] = useState(true); const containerRef = useRef(null); const tableRef = useRef(null); const [dimensions, setDimensions] = useState({ container: 1000, table: 0, tableHeight: 0 }); useEffect(() => { const updateMeasurements = () => { if (containerRef.current && tableRef.current) { setDimensions({ container: containerRef.current.offsetWidth, table: tableRef.current.scrollWidth, tableHeight: tableRef.current.offsetHeight, }); } }; const timeoutId = setTimeout(updateMeasurements, 50); window.addEventListener('resize', updateMeasurements); return () => { clearTimeout(timeoutId); window.removeEventListener('resize', updateMeasurements); }; }, [levels, blankCards]); const needsZoom = dimensions.table > dimensions.container; const dynamicScale = needsZoom ? (dimensions.container / dimensions.table) * 0.95 : 1; const currentScale = isZoomActive && needsZoom ? dynamicScale : 1; const isScaledLayout = isZoomActive && needsZoom && currentScale < 1 && dimensions.tableHeight > 0; const scaledViewportHeight = isScaledLayout ? dimensions.tableHeight * currentScale + 12 : undefined; return (