import React, { useEffect } from 'react'
import VehicleInstances from './instances/vehicleInstances';
import { useVehicleStore } from '../../../store/simulation/useVehicleStore';
import { useFloorItems } from '../../../store/store';

function Vehicles() {

    const { vehicles, addVehicle } = useVehicleStore();

    const { floorItems } = useFloorItems();

    const vehicleStatusSample: VehicleEventSchema[] = [
        {
            modelUuid: "9356f710-4727-4b50-bdb2-9c1e747ecc74",
            modelName: "AGV",
            position: [97.9252965204558, 0, 37.96138815638661],
            rotation: [0, 0, 0],
            state: "idle",
            type: "vehicle",
            speed: 2.5,
            point: {
                uuid: "point-789",
                position: [0, 1, 0],
                rotation: [0, 0, 0],
                action: {
                    actionUuid: "action-456",
                    actionName: "Deliver to Zone A",
                    actionType: "travel",
                    unLoadDuration: 10,
                    loadCapacity: 2,
                    pickUpPoint: { x: 98.71483985219794, y: 0, z: 28.66321267938962 },
                    unLoadPoint: { x: 105.71483985219794, y: 0, z: 28.66321267938962 },
                    triggers: [
                        {
                            triggerUuid: "trig-001",
                            triggerName: "Start Travel",
                            triggerType: "onComplete",
                            delay: 0,
                            triggeredAsset: {
                                triggeredModel: { modelName: "ArmBot-X", modelUuid: "arm-001" },
                                triggeredPoint: { pointName: "Pickup Arm Point", pointUuid: "arm-point-01" },
                                triggeredAction: { actionName: "Grab Widget", actionUuid: "grab-001" }
                            }
                        },
                        {
                            triggerUuid: "trig-002",
                            triggerName: "Complete Travel",
                            triggerType: "onComplete",
                            delay: 2,
                            triggeredAsset: null
                        }
                    ]
                }
            }
        },
        {
            modelUuid: "b06960bb-3d2e-41f7-a646-335f389c68b4",
            modelName: "AGV",
            position: [89.61609306554463, 0, 33.634136622267356],
            rotation: [0, 0, 0],
            state: "idle",
            type: "vehicle",
            speed: 2.5,
            point: {
                uuid: "point-789",
                position: [0, 1, 0],
                rotation: [0, 0, 0],
                action: {
                    actionUuid: "action-456",
                    actionName: "Deliver to Zone A",
                    actionType: "travel",
                    material: "crate",
                    unLoadDuration: 10,
                    loadCapacity: 2,
                    pickUpPoint: { x: 90, y: 0, z: 28 },
                    unLoadPoint: { x: 20, y: 0, z: 10 },
                    triggers: [
                        {
                            triggerUuid: "trig-001",
                            triggerName: "Start Travel",
                            triggerType: "onStart",
                            delay: 0,
                            triggeredAsset: {
                                triggeredModel: { modelName: "ArmBot-X", modelUuid: "arm-001" },
                                triggeredPoint: { pointName: "Pickup Arm Point", pointUuid: "arm-point-01" },
                                triggeredAction: { actionName: "Grab Widget", actionUuid: "grab-001" }
                            }
                        },
                        {
                            triggerUuid: "trig-002",
                            triggerName: "Complete Travel",
                            triggerType: "onComplete",
                            delay: 2,
                            triggeredAsset: null
                        }
                    ]
                }
            }
        }, {
            modelUuid: "e729a4f1-11d2-4778-8d6a-468f1b4f6b79",
            modelName: "forklift",
            position: [98.85729337188162, 0, 38.36616546567653],
            rotation: [0, 0, 0],
            state: "idle",
            type: "vehicle",
            speed: 2.5,
            point: {
                uuid: "point-789",
                position: [0, 1, 0],
                rotation: [0, 0, 0],
                action: {
                    actionUuid: "action-456",
                    actionName: "Deliver to Zone A",
                    actionType: "travel",
                    unLoadDuration: 15,
                    loadCapacity: 5,
                    pickUpPoint: { x: 98.71483985219794, y: 0, z: 28.66321267938962 },
                    unLoadPoint: { x: 20, y: 0, z: 10 },
                    triggers: [
                        {
                            triggerUuid: "trig-001",
                            triggerName: "Start Travel",
                            triggerType: "onStart",
                            delay: 0,
                            triggeredAsset: {
                                triggeredModel: { modelName: "ArmBot-X", modelUuid: "arm-001" },
                                triggeredPoint: { pointName: "Pickup Arm Point", pointUuid: "arm-point-01" },
                                triggeredAction: { actionName: "Grab Widget", actionUuid: "grab-001" }
                            }
                        },
                        {
                            triggerUuid: "trig-002",
                            triggerName: "Complete Travel",
                            triggerType: "onComplete",
                            delay: 2,
                            triggeredAsset: null
                        }
                    ]
                }
            }
        }
    ];


    useEffect(() => {
        addVehicle('123', vehicleStatusSample[0]);
        // addVehicle('123', vehicleStatusSample[1]);
        // addVehicle('123', vehicleStatusSample[2]);
    }, [])

    useEffect(() => {
        console.log('vehicles: ', vehicles);
    }, [vehicles])


    return (
        <>
            <VehicleInstances />
        </>
    )
}

export default Vehicles;