// components/Header.jsx
"use client";
import React, { useEffect, useState } from "react";
import Image from "next/image";
import "bootstrap-icons/font/bootstrap-icons.css";
import { loadWindowVariables } from "../utils/loadWindowVariables"; // Importiere die Funktion

function Header() {
  const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
  const [stationsname, setStationsname] = useState("Lädt..."); // Platzhalter
  const [cplStatus, setCplStatus] = useState("Lädt...");

  useEffect(() => {
    // Lade die Variablen vom Server und setze sie in `window`
    loadWindowVariables(apiUrl)
      .then(() => {
        // Greife auf die geladenen Variablen im `window`-Objekt zu
        setStationsname(window.deviceName || "Unbekannt");
        setCplStatus(window.hardware_version || "Unbekannt");
      })
      .catch((error) => {
        console.error("Fehler beim Laden der Variablen:", error);
      });
  }, [apiUrl]);

  return (
    <header className="bg-gray-300 flex justify-between items-center w-full h-28 relative">
      {/* Logo - Vergrößert und verschoben */}
      <div className="absolute left-32 top-32 transform -translate-y-1/2">
        <Image
          src="/images/Logo.png" // Angepasster Pfad
          alt="Logo"
          width={80}
          height={80}
          style={{ width: "auto", height: "auto" }} // Stellt sicher, dass das Seitenverhältnis korrekt bleibt
          priority={false}
        />
      </div>
      <div className="w-64 flex-shrink-0 h-full mt-24 "></div>

      {/* CPL Status und Stationsname */}
      <div className="flex items-start space-x-4 w-full">
        <div className="flex flex-col text-left pl-8">
          {/* Text immer linksbündig */}
          <h2 className="text-base ">Stationsname</h2>
          <p className="text-base  text-gray-600">{stationsname}</p>
        </div>
      </div>
      <div className="flex items-start space-x-4 w-full"></div>
      {/* Temperatur und Icons */}
      <div className="p-4 w-full lg:w-full flex flex-row gap-4 justify-between">
        {/* Temperatur und Luftfeuchtigkeit */}
        {/* 
                    <div className="flex items-center min-w-0">
          <i className="bi bi-thermometer-half"></i>
          <p className="text-lg ml-1">20.5 °C</p>
          
        </div>
        <div className="flex items-center min-w-0">
          <i className="bi bi-droplet"></i>
          <p className="text-lg ml-1">60%</p>
        </div>
            */}

        {/* Toggle Switch light and dark mode */}
        {/* 
          <div className="flex items-center space-x-4 min-w-0 flex-shrink">
          <i className="bi bi-moon"></i>
     
          <div className="flex items-center space-x-2">
            <i className="bi bi-toggle-off"></i>
            <i className="bi bi-brightness-high"></i>
          </div>
        </div>
        
        */}

        {/* User Icon */}
        <div className="flex items-center justify-end w-full">
          <i className="bi bi-person-circle text-3xl text-black mr-7"></i>
        </div>
      </div>
    </header>
  );
}

export default Header;
