import React, { useEffect, useState } from "react";
import Header from "./Header";
import useModuleStore, {
  useSubModuleStore,
} from "../../../store/useModuleStore";
import {
  AnalysisIcon,
  MechanicsIcon,
  PropertiesIcon,
  SimulationIcon,
} from "../../icons/SimulationIcons";
import useToggleStore from "../../../store/useUIToggleStore";
import MachineMechanics from "./mechanics/MachineMechanics";
import Visualization from "./visualization/Visualization";
import GlobalProperties from "./properties/GlobalProperties";
import AsstePropertiies from "./properties/AssetProperties";
import Analysis from "./analysis/Analysis";
import Simulations from "./simulation/Simulations";
import { useSelectedActionSphere } from "../../../store/store";
import ZoneProperties from "./properties/ZoneProperties";

const SideBarRight: React.FC = () => {
  const { activeModule } = useModuleStore();
  const [activeList] = useState("properties");
  const { toggleUI } = useToggleStore();
  const { selectedActionSphere } = useSelectedActionSphere();
  const { subModule, setSubModule } = useSubModuleStore();
  // Reset activeList whenever activeModule changes
  useEffect(() => {
    if (activeModule !== "simulation") setSubModule("properties");
    if (activeModule === "simulation") setSubModule("mechanics");
  }, [activeModule]);

  return (
    <div className="sidebar-right-wrapper">
      <Header />
      {toggleUI && (
        <div className="sidebar-actions-container">
          {/* {activeModule === "builder" && ( */}
          <div
            className={`sidebar-action-list ${
              subModule === "properties" ? "active" : ""
            }`}
            onClick={() => setSubModule("properties")}
          >
            <PropertiesIcon isActive={subModule === "properties"} />
          </div>
          {/* )} */}
          {activeModule === "simulation" && (
            <>
              <div
                className={`sidebar-action-list ${
                  subModule === "mechanics" ? "active" : ""
                }`}
                onClick={() => setSubModule("mechanics")}
              >
                <MechanicsIcon isActive={activeList === "mechanics"} />
              </div>
              <div
                className={`sidebar-action-list ${
                  subModule === "simulations" ? "active" : ""
                }`}
                onClick={() => setSubModule("simulations")}
              >
                <SimulationIcon isActive={activeList === "simulations"} />
              </div>
              <div
                className={`sidebar-action-list ${
                  subModule === "analysis" ? "active" : ""
                }`}
                onClick={() => setSubModule("analysis")}
              >
                <AnalysisIcon isActive={activeList === "analysis"} />
              </div>
            </>
          )}
        </div>
      )}
      {/* process builder */}
      {toggleUI &&
        activeList === "properties" &&
        activeModule !== "visualization" && (
          <div className="sidebar-right-container">
            <div className="sidebar-right-content-container">
              <GlobalProperties />
              {/* <ZoneProperties /> */}
              {/* <AsstePropertiies /> */}
            </div>
          </div>
        )}

      {/* simulation */}

      {toggleUI && activeModule === "simulation" && (
        <>
          {subModule === "mechanics" && selectedActionSphere && (
            <div className="sidebar-right-container">
              <div className="sidebar-right-content-container">
                <MachineMechanics />
              </div>
            </div>
          )}
          {subModule === "mechanics" && !selectedActionSphere && (
            <div className="sidebar-right-container">
              <div className="sidebar-right-content-container">
                <MachineMechanics />
              </div>
            </div>
          )}
          {subModule === "analysis" && (
            <div className="sidebar-right-container">
              <div className="sidebar-right-content-container">
                <Analysis />
              </div>
            </div>
          )}
          {activeList === "simulations" && (
            <div className="sidebar-right-container">
              <div className="sidebar-right-content-container">
                <Simulations />
              </div>
            </div>
          )}
        </>
      )}

      {/* realtime visualization */}
      {toggleUI && activeModule === "visualization" && <Visualization />}
    </div>
  );
};

export default SideBarRight;
