import React, { useEffect, useRef } from "react"; import { AddIcon, ArrowIcon, RemoveIcon, ResizeHeightIcon, } from "../../../icons/ExportCommonIcons"; import RenameInput from "../../../ui/inputs/RenameInput"; import { handleResize } from "../../../../functions/handleResizePannel"; import { useSelectedProduct } from "../../../../store/simulation/useSimulationStore"; import { useProductStore } from "../../../../store/simulation/useProductStore"; import { generateUUID } from "three/src/math/MathUtils"; interface Event { pathName: string; } interface ListProps { val: Event; } const List: React.FC = ({ val }) => { return (
{val.pathName}
); }; const Simulations: React.FC = () => { const productsContainerRef = useRef(null); const { products, addProduct, removeProduct, renameProduct } = useProductStore(); const { selectedProduct, setSelectedProduct } = useSelectedProduct(); useEffect(() => { if (products.length > 0 && selectedProduct.productId === '' && selectedProduct.productName === '') { setSelectedProduct(products[0].productId, products[0].productName); } }, [products, selectedProduct]); const handleAddProduct = () => { addProduct(`Product ${products.length + 1}`, generateUUID()); }; const handleRemoveProduct = (productId: string) => { const currentIndex = products.findIndex(p => p.productId === productId); const isSelected = selectedProduct.productId === productId; const updatedProducts = products.filter(p => p.productId !== productId); if (isSelected) { if (updatedProducts.length > 0) { let newSelectedIndex = currentIndex; if (currentIndex >= updatedProducts.length) { newSelectedIndex = updatedProducts.length - 1; } setSelectedProduct( updatedProducts[newSelectedIndex].productId, updatedProducts[newSelectedIndex].productName ); } else { setSelectedProduct('', ''); } } removeProduct(productId); }; const handleRenameProduct = (productId: string, newName: string) => { renameProduct(productId, newName); if (selectedProduct.productId === productId) { setSelectedProduct(productId, newName); } }; const selectedProductData = products.find( (product) => product.productId === selectedProduct.productId ); const events: Event[] = selectedProductData?.eventsData.map((event, index) => ({ pathName: `${event.modelName} - ${event.type} #${index + 1}`, })) || []; return (
Simulations
Products
Add
{products.map((product, index) => (
setSelectedProduct(product.productId, product.productName)} > handleRenameProduct(product.productId, newName)} />
{products.length > 1 && (
handleRemoveProduct(product.productId)} >
)}
))}
handleResize(e, productsContainerRef)} >
Events
{events.map((event, index) => ( ))}
Need to Compare Layout?
Click 'Compare' to review and analyze the layout differences between them.
); }; export default Simulations;