import React, { useEffect } from 'react'
import VehicleInstances from './instances/vehicleInstances';

import { useVehicleStore } from '../../../store/simulation/useVehicleStore';

function Vehicles() {

    const { vehicles, addVehicle } = useVehicleStore();

    const vehicleStatusSample: VehicleStatus[] = [
        {
            modelUuid: "2c01ed76-359a-485b-83d4-052cfcdb9d89",
            modelName: "AGV",
            position: [10, 0, 5],
            rotation: [0, 0, 0],
            state: "idle",
            type: "vehicle",
            speed: 2.5,
            point: {
                uuid: "point-789",
                position: [93.42159216649789, 0, 23.790878603572857],
                rotation: [0, 0, 0],
                action: {
                    actionUuid: "action-456",
                    actionName: "Deliver to Zone A",
                    actionType: "travel",
                    material: "crate",
                    unLoadDuration: 15,
                    loadCapacity: 5,
                    pickUpPoint: { x: 5, y: 0, z: 3 },
                    unLoadPoint: { x: 20, y: 0, z: 10 },
                    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
                        }
                    ]
                }
            },
            productId: "prod-890",
            isActive: false,
            idleTime: 0,
            activeTime: 0,
            currentLoad: 0,
            distanceTraveled: 0
        },
        {
            modelUuid: "311130b9-4f2e-425a-b3b5-5039cb348806",
            modelName: "AGV",
            position: [95.69567023145055, 0, 33.18042399595448],
            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: 15,
                    loadCapacity: 5,
                    pickUpPoint: { x: 5, y: 0, z: 3 },
                    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
                        }
                    ]
                }
            },
            productId: "prod-890",
            isActive: false,
            idleTime: 0,
            activeTime: 0,
            currentLoad: 0,
            distanceTraveled: 0
        }, {
            modelUuid: "fa54132c-8333-4832-becb-5281f5e11549",
            modelName: "AGV",
            position: [102.71483985219794, 0, 23.66321267938962],
            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: 15,
                    loadCapacity: 5,
                    pickUpPoint: { x: 5, y: 0, z: 3 },
                    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
                        }
                    ]
                }
            },
            productId: "prod-890",
            isActive: false,
            idleTime: 0,
            activeTime: 0,
            currentLoad: 0,
            distanceTraveled: 0
        }
    ];


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

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


    return (
        <>

            <VehicleInstances vehicles={vehicles} />

        </>
    )
}

export default Vehicles;