'use strict';
'use client';
import { c } from 'react/compiler-runtime';
import { jsxs, jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { cn } from '../../../../../fd-toolbox/lib/utils.js';
import { Button } from '../../../../fd-component-toolbox/button/Button.js';
import { Icon } from '../../../../fd-component-toolbox/icon/Icon.js';
import { useRouter } from '../../../../meta/client/framework/hooks.js';
import { navigateToItem } from './TopMenuItem.funcs.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function TopMenuItem(t0) {
  const $ = c(17);
  const {
    item
  } = t0;
  const [open, setOpen] = useState(false);
  const router = useRouter();
  let t1;
  if ($[0] !== item.nextSubgroupsOrMenuItems || $[1] !== item.text || $[2] !== open) {
    t1 = Symbol.for("react.early_return_sentinel");
    bb0: {
      const nextSubgroupsOrMenuItems = item?.nextSubgroupsOrMenuItems?.map(_temp);
      if (item.nextSubgroupsOrMenuItems && item.nextSubgroupsOrMenuItems.length > 0) {
        let t2;
        let t3;
        if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
          t2 = () => setOpen(true);
          t3 = () => setOpen(false);
          $[4] = t2;
          $[5] = t3;
        } else {
          t2 = $[4];
          t3 = $[5];
        }
        t1 = jsxs("li", {
          className: "relative",
          onMouseEnter: t2,
          onMouseLeave: t3,
          children: [jsxs(Button, {
            className: "flex size-full flex-row items-center justify-between p-2 text-xs font-normal text-nowrap text-black",
            children: [item.text, jsx(Icon, {
              name: "chevronRight"
            })]
          }), jsx("div", {
            className: cn("absolute top-0 left-full w-52 divide-y rounded-md p-3 shadow", !open && "hidden"),
            children: jsx("ul", {
              children: nextSubgroupsOrMenuItems
            })
          })]
        });
        break bb0;
      }
    }
    $[0] = item.nextSubgroupsOrMenuItems;
    $[1] = item.text;
    $[2] = open;
    $[3] = t1;
  } else {
    t1 = $[3];
  }
  if (t1 !== Symbol.for("react.early_return_sentinel")) {
    return t1;
  }
  let t2;
  if ($[6] !== item.path || $[7] !== item.routerLinkQueryParam || $[8] !== item.text || $[9] !== item.type || $[10] !== router) {
    let t3;
    if ($[12] !== item.path || $[13] !== item.routerLinkQueryParam || $[14] !== item.type || $[15] !== router) {
      t3 = () => navigateToItem(item.type, router, item.path, item.routerLinkQueryParam);
      $[12] = item.path;
      $[13] = item.routerLinkQueryParam;
      $[14] = item.type;
      $[15] = router;
      $[16] = t3;
    } else {
      t3 = $[16];
    }
    t2 = jsx("li", {
      children: jsx(Button, {
        onClick: t3,
        className: "flex size-full flex-row items-center justify-start p-2 text-xs font-normal text-nowrap text-black",
        children: item.text
      })
    });
    $[6] = item.path;
    $[7] = item.routerLinkQueryParam;
    $[8] = item.text;
    $[9] = item.type;
    $[10] = router;
    $[11] = t2;
  } else {
    t2 = $[11];
  }
  return t2;
}
function _temp(subItem) {
  return jsx(TopMenuItem, {
    item: subItem
  }, `${subItem.text}_${subItem.type}`);
}
__name(TopMenuItem, "TopMenuItem");

export { TopMenuItem };
