'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsx, jsxs } from 'react/jsx-runtime';
import { cn } from '../../../../fd-toolbox/lib/utils.js';
import { Button } from '../../../fd-component-toolbox/button/Button.js';
import { sidebarStatuses } from '../../enums/sidebar-status.js';
import { Icon, iconNames } from '../../../fd-component-toolbox/icon/Icon.js';
import { SidebarDropdownMenu } from './sidebar-dropdown-menu/SidebarDropdownMenu.js';
import { toolbarLayoutTypes } from '../client-layout/client-layout-config.js';
import { useSidebarItems } from './sidebar-resources-provider.js';
import { useAuth } from '../../providers/auth-provider/AuthProvider.js';
import { useSidebarContext } from '../../providers/sidebar-provider/SidebarContext.js';
import { elements } from '../../../../fd-toolbox/constants/elements.js';
import { useEmptyRef } from '../../../../fd-toolbox/hooks/use-empty-ref.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function Sidebar(t0) {
  const $ = c(11);
  const {
    className,
    toolbarLayoutType
  } = t0;
  const {
    sidebarItems
  } = useSidebarItems();
  const sidebarRef = useEmptyRef();
  const authContext = useAuth();
  const sidebarContext = useSidebarContext();
  const sidebarState = sidebarContext?.sidebarStatus ?? sidebarStatuses.minified;
  let t1;
  let t2;
  if ($[0] !== authContext || $[1] !== className || $[2] !== sidebarContext || $[3] !== sidebarItems || $[4] !== sidebarRef || $[5] !== sidebarState || $[6] !== toolbarLayoutType) {
    t2 = Symbol.for("react.early_return_sentinel");
    bb0: {
      let t3;
      if ($[9] !== sidebarContext) {
        t3 = state => sidebarContext?.setSidebarStatus?.(state);
        $[9] = sidebarContext;
        $[10] = t3;
      } else {
        t3 = $[10];
      }
      const setSidebarState = __name(t3, "setSidebarState");
      const openSidebar = sidebarState === sidebarStatuses.fixedOpen;
      if (toolbarLayoutType === toolbarLayoutTypes.topBarOnly) {
        t2 = void 0;
        break bb0;
      }
      t1 = jsx("section", {
        id: elements.sidebar,
        className: "hidden md:block",
        children: authContext.loginState.loggedIn && jsx("div", {
          ref: sidebarRef,
          className: cn("bg-fd-tertiary-900 after:shadow-toolbar-rounded group absolute inset-0 z-20 h-full transition-[width] duration-75 ease-in after:pointer-events-none after:absolute after:top-0 after:-right-5 after:block after:h-2 after:w-5 after:rounded-tl-lg after:content-['']", className, sidebarState === sidebarStatuses.fixedOpen && "relative -mr-16 w-60", sidebarState === sidebarStatuses.minified && "w-14"),
          children: jsxs("div", {
            className: "flex size-full min-w-14 flex-col items-start justify-between p-3 pb-0",
            children: [jsx("nav", {
              className: "flex w-full flex-col gap-y-1 overflow-x-visible scroll-smooth whitespace-nowrap",
              children: sidebarItems.map(sidebarItem => jsx(SidebarDropdownMenu, {
                label: sidebarItem.displayName,
                icon: sidebarItem.icon,
                url: sidebarItem.link,
                openSidebar,
                submenu: false
              }, sidebarItem.displayName))
            }), jsx("div", {
              className: cn("flex w-full flex-row-reverse justify-center pb-3", openSidebar && "justify-normal"),
              children: jsx(Button, {
                id: elements.sidebarToggleButton,
                onClick: () => setSidebarState(sidebarState === sidebarStatuses.fixedOpen ? sidebarStatuses.minified : sidebarStatuses.fixedOpen),
                className: cn("hover:bg-fd-tertiary-700 flex items-center justify-center rounded-md bg-transparent shadow-none duration-75 ease-in", openSidebar && "w-fit justify-end"),
                children: jsx("div", {
                  className: cn("border-fd-tertiary-50 text-fd-tertiary-50 size-4 shrink-0 grow-0 basis-4 border", openSidebar && "flex items-center"),
                  children: openSidebar ? jsx(Icon, {
                    name: iconNames.caretLeftIcon,
                    color: "fd-tertiary-50"
                  }) : jsx("div", {
                    className: "bg-fd-tertiary-50 h-3.5 w-1.5"
                  })
                })
              })
            })]
          })
        })
      });
    }
    $[0] = authContext;
    $[1] = className;
    $[2] = sidebarContext;
    $[3] = sidebarItems;
    $[4] = sidebarRef;
    $[5] = sidebarState;
    $[6] = toolbarLayoutType;
    $[7] = t1;
    $[8] = t2;
  } else {
    t1 = $[7];
    t2 = $[8];
  }
  if (t2 !== Symbol.for("react.early_return_sentinel")) {
    return t2;
  }
  return t1;
}
__name(Sidebar, "Sidebar");

export { Sidebar as default };
