"use client"; ///pages/analogeEingaenge.tsx
import React, { useState, useEffect } from "react";
import AnalogeEingaengeTabelle from "../components/main/analogeEingaenge/AnalogeEingaengeTable";
import AnalogInputsChart from "../components/main/analogeEingaenge/AnalogInputsChart";
import { fetchAnalogeEingaengeThunk } from "../redux/thunks/fetchAnalogeEingaengeThunk";
import { useAppDispatch } from "../redux/store";

function AnalogeEingaenge() {
  const [activeConfig, setActiveConfig] = useState<number | null>(null);
  //---------------------------------------------------------
  const dispatch = useAppDispatch();
  useEffect(() => {
    if (typeof window !== "undefined") {
      dispatch(fetchAnalogeEingaengeThunk());
      const interval = setInterval(() => {
        dispatch(fetchAnalogeEingaengeThunk());
      }, 10000);
      return () => clearInterval(interval);
    }
  }, [dispatch]);
  //---------------------------------------------------------

  return (
    <div className="flex flex-col gap-3 p-4 h-[calc(100vh-13vh-8vh)] laptop:h-[calc(100vh-10vh-5vh)] xl:h-[calc(100vh-10vh-6vh)] laptop:gap-0">
      <div className="container mx-auto">
        {/* Responsive Grid: 1 Spalte auf mobilen Geräten, 2 Spalten auf größeren Geräten */}
        <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
          {/* Tabelle als Card */}
          <div className="bg-white shadow-lg rounded-lg p-4 border border-gray-200">
            <h2 className="text-xl font-semibold mb-4 text-gray-700">
              Analoge Eingänge
            </h2>
            <AnalogeEingaengeTabelle />
          </div>

          {/* Diagramm als Card */}
          <div className="bg-white shadow-lg rounded-lg p-4 border border-gray-200">
            <h2 className="text-xl font-semibold mb-4 text-gray-700">
              Analoge Eingäne Messkurve
            </h2>
            <AnalogInputsChart />
          </div>
        </div>
      </div>
    </div>
  );
}

export default AnalogeEingaenge;
