"use client";
import Image from "next/image";
import header from "./Header.module.css";
import Link from "next/link";
import BarNavigation from "../BarNavigation/BarNavigation";
import { useEffect, useState } from "react";

function Header() {
  const [role, setRole] = useState("");

  useEffect(() => {
    const cookies = Object.fromEntries(
      document.cookie.split("; ").map((c) => c.split("="))
    );
    setRole(cookies.role || "");
  }, []);

  return (
    <header className={header.header}>
      <Link
        href="https://www.unam.mx/"
        target="_blank"
        className={header.center}
        style={{
          display: "flex",
          alignItems: "center",
          margin: "10px 5px",
        }}
      >
        <div className={header.logoContainer}>
          <Image
            className={header.logo}
            src="/logo_fes.png"
            alt="Logo FES"
            fill
            style={{ objectFit: "contain" }}
          />
        </div>
      </Link>
      <div className={header.yellowPart}></div>
      <div className={header.containerBarNav}>
        {role === "ADMINISTRADOR" && <BarNavigation />}
        {role === "SUPER ADMINISTRADOR   (quita sanciones)" && <BarNavigation />}
        {role === "SERVICIO SOCIAL" && <BarNavigation/>}
        {role === "ATENCION A USUARIO" && <BarNavigation/>}
      </div>
    </header>
  );
}

export default Header;
//IO
