import { useMemo, useState } from "react";
import { Canvas } from "@react-three/fiber";
import { Environment, KeyboardControls } from "@react-three/drei";

import World from "./world/world";
import Controls from "./controls/controls";
import TransformControl from "./controls/transformControls";
import PostProcessing from "./postProcessing/postProcessing"
import Sun from "./environment/sky";
import CamModelsGroup from "../collaboration/collabCams";
import Shadows from "./environment/shadow";
import MqttEvents from "../../services/factoryBuilder/mqtt/mqttEvents";

import background from "../../assets/textures/hdr/mudroadpuresky2k.hdr";
import SelectionControls from "./controls/selection/selectionControls";
import MeasurementTool from "./tools/measurementTool";
import Simulation from "../simulation/simulation";
import DroppedObjects from "../../components/ui/componets/DroppedFloatingWidgets";

// import Simulation from "./simulationtemp/simulation";
import ZoneCentreTarget from "../../components/ui/componets/zoneCameraTarget";
import ProductionCapacity from "../../components/layout/3D-cards/cards/ProductionCapacity";
import Dropped3dWidgets from "../../components/ui/componets/Dropped3dWidget";
import { useWidgetSubOption } from "../../store/store";

export default function Scene() {

  const map = useMemo(() => [
    { name: "forward", keys: ["ArrowUp", "w", "W"] },
    { name: "backward", keys: ["ArrowDown", "s", "S"] },
    { name: "left", keys: ["ArrowLeft", "a", "A"] },
    { name: "right", keys: ["ArrowRight", "d", "D"] },
  ], [])

  return (
    <KeyboardControls map={map}>
      <Canvas
        // style={{ width: "100vw", height: "100vh" }}
        eventPrefix="client"
        gl={{ powerPreference: "high-performance", antialias: true }}
        onContextMenu={(e) => {
          e.preventDefault();
        }}

      >
        <Dropped3dWidgets />
        <Controls />
        <TransformControl />
        <SelectionControls />
        <MeasurementTool />
        <World />
        <ZoneCentreTarget />
        <Simulation />
        <PostProcessing />
        <Sun />
        <Shadows />
        <CamModelsGroup />
        <MqttEvents />
        <Environment files={background} environmentIntensity={1.5} />
      </Canvas>
    </KeyboardControls>
  );
}
