'use strict';
import { c } from 'react/compiler-runtime';
import { jsx, jsxs } from 'react/jsx-runtime';
import { Icon, iconSizes, iconNames, defaultSidebarIconName } from '../../../../fd-component-toolbox/icon/Icon.js';
import { useState, useEffect } from 'react';
import { Sheet, SheetTrigger, SheetContent, SheetHeader } from '../../../../fd-component-toolbox/sheet/Sheet.js';
import { cn } from '../../../../../fd-toolbox/lib/utils.js';
import { Link } from '../../../../fd-component-toolbox/link/Link.js';
import { UserDropdownMenu } from '../../../menu/user-dropdown-menu/UserDropdownMenu.js';
import { createToolbarMenuSubgroups } from '../toolbar-menu-subgroups.js';
import { elements } from '../../../../../fd-toolbox/constants/elements.js';
import { useSidebarItems } from '../../sidebar/sidebar-resources-provider.js';
import { useAuth } from '../../../providers/auth-provider/AuthProvider.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function HamburgerMenu(t0) {
  const $ = c(14);
  const {
    className,
    userWorkspaces,
    visibleWorkspaces
  } = t0;
  const [isMenuOpen, setIsMenuOpen] = useState(false);
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = [];
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const [menuSubgroups, setMenuSubgroups] = useState(t1);
  const {
    sidebarItems
  } = useSidebarItems();
  const authContext = useAuth();
  let t2;
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = () => {
      setMenuSubgroups(createToolbarMenuSubgroups());
    };
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  let t3;
  if ($[2] !== authContext.loginState) {
    t3 = [authContext.loginState];
    $[2] = authContext.loginState;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  useEffect(t2, t3);
  let t4;
  if ($[4] !== className || $[5] !== isMenuOpen || $[6] !== menuSubgroups || $[7] !== sidebarItems || $[8] !== userWorkspaces || $[9] !== visibleWorkspaces) {
    let t5;
    if ($[11] !== className) {
      t5 = props => jsx("div", {
        ...props,
        className: cn("hover:bg-fd-tertiary-700 m-1 mr-3 flex size-8 cursor-pointer items-center justify-center rounded-md", className),
        children: jsx(Icon, {
          name: iconNames.hamburgerMenu,
          size: iconSizes.small,
          color: "text-white"
        })
      });
      $[11] = className;
      $[12] = t5;
    } else {
      t5 = $[12];
    }
    let t6;
    if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
      t6 = sidebarItem => jsx(Link, {
        onClick: () => {
          setIsMenuOpen(false);
        },
        href: sidebarItem?.link ?? " #",
        className: "text-fd-tertiary-50 hover:bg-fd-tertiary-700 flex w-auto shrink-0 cursor-pointer flex-row items-center justify-start px-7 py-3 text-base",
        children: jsxs("div", {
          className: "relative flex flex-row items-center gap-3",
          children: [jsx("label", {
            className: "hover:cursor-pointer [&>svg]:size-5",
            children: jsx(Icon, {
              name: sidebarItem?.icon ?? defaultSidebarIconName,
              color: "text-fd-tertiary-50"
            })
          }), jsx("p", {
            className: "left-full block font-medium text-nowrap",
            children: sidebarItem.displayName
          })]
        })
      }, sidebarItem.displayName);
      $[13] = t6;
    } else {
      t6 = $[13];
    }
    t4 = jsxs(Sheet, {
      open: isMenuOpen,
      onOpenChange: setIsMenuOpen,
      children: [jsx(SheetTrigger, {
        render: t5
      }), jsxs(SheetContent, {
        className: cn("bg-fd-tertiary-900 flex h-full w-fit flex-col border-none p-0 pb-4", !isMenuOpen && "hidden"),
        side: "left",
        children: [jsx(SheetHeader, {
          className: "bg-fd-tertiary-900 min-h-12 flex-row items-center space-y-0 px-7",
          children: jsx("div", {
            className: "m-0 flex items-start justify-start p-0",
            children: jsx(UserDropdownMenu, {
              id: elements.userDropdownMenu.userDropdownMenuId,
              items: menuSubgroups,
              userWorkspaces,
              visibleWorkspaces,
              parentContextName: elements.hamburgerMenu
            })
          })
        }), jsx("div", {
          className: "text-fd-tertiary-50 flex h-[93%] w-full flex-col",
          children: sidebarItems.map(t6)
        })]
      })]
    });
    $[4] = className;
    $[5] = isMenuOpen;
    $[6] = menuSubgroups;
    $[7] = sidebarItems;
    $[8] = userWorkspaces;
    $[9] = visibleWorkspaces;
    $[10] = t4;
  } else {
    t4 = $[10];
  }
  return t4;
}
__name(HamburgerMenu, "HamburgerMenu");

export { HamburgerMenu };
