"use client";

import { useCallback, useState } from "react";
import MapComponent from "@app/OlMap/MapComponent";
import Timeline from "@app/OlMap/Controls/Timeline";
import MapToolbar from "@app/OlMap/Controls/Toolbar";

import SCADADeviceList from "@components/olmap/SCADADeviceList";
import SCADADataPanel from "@components/olmap/SCADADataPanel";

export default function Home() {
  const [selectedDeviceIds, setSelectedDeviceIds] = useState<string[]>([]);
  const [panelVisible, setPanelVisible] = useState<boolean>(false);

  const handleSelectionChange = useCallback((ids: string[]) => {
    setSelectedDeviceIds(ids);
    setPanelVisible(ids.length > 0);
  }, []);

  const handleDeviceClick = useCallback(() => {
    setPanelVisible(true);
  }, []);

  return (
    <div className="relative w-full h-full overflow-hidden">
      <MapComponent>
        <MapToolbar queryType="realtime" />
        <Timeline />
        <SCADADeviceList
          onDeviceClick={handleDeviceClick}
          onSelectionChange={handleSelectionChange}
          selectedDeviceIds={selectedDeviceIds}
        />
        <SCADADataPanel deviceIds={selectedDeviceIds} visible={panelVisible} />
      </MapComponent>
    </div>
  );
}
