import React, { useEffect, useRef, useState } from "react"; import InputWithDropDown from "../../../../ui/inputs/InputWithDropDown"; import LabledDropdown from "../../../../ui/inputs/LabledDropdown"; import { AddIcon, RemoveIcon, ResizeHeightIcon, } from "../../../../icons/ExportCommonIcons"; import RenameInput from "../../../../ui/inputs/RenameInput"; import { handleResize } from "../../../../../functions/handleResizePannel"; import { handleActionToggle } from "./functions/handleActionToggle"; import { handleDeleteAction } from "./functions/handleDeleteAction"; import DefaultAction from "./actions/DefaultAction"; import SpawnAction from "./actions/SpawnAction"; import SwapAction from "./actions/SwapAction"; import DespawnAction from "./actions/DespawnAction"; import TravelAction from "./actions/TravelAction"; import PickAndPlaceAction from "./actions/PickAndPlaceAction"; import ProcessAction from "./actions/ProcessAction"; import StorageAction from "./actions/StorageAction"; import Trigger from "./trigger/Trigger"; import { useSelectedEventData, useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore"; const EventProperties: React.FC = () => { const actionsContainerRef = useRef(null); const [activeOption, setActiveOption] = useState("default"); const [selectedItem, setSelectedItem] = useState<{ item: { uuid: string; name: string } | null; }>({ item: null }); const { selectedEventData } = useSelectedEventData(); const { getEventByModelUuid } = useProductStore(); const { selectedProduct } = useSelectedProduct(); useEffect(() => { const actions = getActions(); if (actions.length > 0 && !selectedItem.item) { setSelectedItem({ item: actions[0] }); } }, [selectedEventData]); const getCurrentEventData = () => { if (!selectedEventData?.data || !selectedProduct) return null; const event = getEventByModelUuid(selectedProduct.productId, selectedEventData.data.modelUuid); return event || null; }; const getAssetType = () => { const event = getCurrentEventData(); if (!event) return null; switch (event.type) { case 'transfer': return 'conveyor'; case 'vehicle': return 'vehicle'; case 'roboticArm': return 'roboticArm'; case 'machine': return 'machine'; case 'storageUnit': return 'storageUnit'; default: return null; } }; const getAvailableActions = () => { switch (getAssetType()) { case "conveyor": return { defaultOption: "default", options: ["default", "spawn", "swap", "despawn"], }; case "vehicle": return { defaultOption: "travel", options: ["travel"], }; case "roboticArm": return { defaultOption: "pickAndPlace", options: ["pickAndPlace"], }; case "machine": return { defaultOption: "process", options: ["process"], }; case "storageUnit": return { defaultOption: "store", options: ["store", "spawn"], }; default: return { defaultOption: "default", options: ["default"], }; } }; // Get actions based on asset type const getActions = () => { if (!selectedEventData?.data) return []; const event = selectedEventData.data; switch (getAssetType()) { case "conveyor": return (event as ConveyorEventSchema).points .find((point) => point.uuid === selectedEventData?.selectedPoint) ?.action?.triggers.map((trigger) => ({ uuid: trigger.triggerUuid, name: trigger.triggerName, })) || []; case "vehicle": return (event as VehicleEventSchema).point.action.triggers.map( (trigger) => ({ uuid: trigger.triggerUuid, name: trigger.triggerName, }) ) || []; case "roboticArm": return (event as RoboticArmEventSchema).point.actions.flatMap( (action) => action.triggers.map((trigger) => ({ uuid: trigger.triggerUuid, name: trigger.triggerName, })) ) || []; case "machine": return (event as MachineEventSchema).point.action.triggers.map( (trigger) => ({ uuid: trigger.triggerUuid, name: trigger.triggerName, }) ) || []; case "storageUnit": return [ { uuid: (event as StorageEventSchema).point.action.actionUuid, name: (event as StorageEventSchema).point.action.actionName, }, ]; default: return []; } }; const handleActionToggle = (actionUuid: string) => { const actions = getActions(); const selected = actions.find(action => action.uuid === actionUuid); if (selected) { setSelectedItem({ item: selected }); } }; const handleDeleteAction = (actionUuid: string) => { }; const actions = getActions(); const getSpeed = () => { if (!selectedEventData) return "0.5"; if ("speed" in selectedEventData.data) return selectedEventData.data.speed.toString(); return "0.5"; }; return ( <> {getCurrentEventData() &&
{selectedEventData?.data.modelName}
{ }} onChange={(value) => console.log(value)} />
{ }} onChange={(value) => console.log(value)} />
{getAssetType() === 'roboticArm' &&
Actions
{ }}> Add
{actions.map((action) => (
handleActionToggle(action.uuid)} >
{actions.length > 1 && (
handleDeleteAction(action.uuid)} >
)}
))}
handleResize(e, actionsContainerRef)} >
}
setActiveOption(option)} /> {activeOption === "default" && } {activeOption === "spawn" && } {activeOption === "swap" && } {activeOption === "despawn" && } {activeOption === "travel" && } {activeOption === "pickAndPlace" && } {activeOption === "process" && } {activeOption === "store" && }
} ); }; export default EventProperties;