{"version":3,"file":"renderUtils.mjs","names":[],"sources":["../../src/Menu/renderUtils.tsx"],"sourcesContent":["import type { Key, ReactNode } from 'react';\nimport { isValidElement } from 'react';\n\nimport Icon, { type IconSize } from '@/Icon';\n\nimport type { BaseMenuItemType } from './baseItem';\nimport type { MenuCheckboxItemType } from './checkboxItem';\nimport type { MenuItemType, SubMenuType } from './type';\n\nexport type IconSpaceMode = 'global' | 'group';\n\nexport type IconAlign = 'center' | 'start';\n\nexport interface RenderOptions {\n  iconAlign?: IconAlign;\n  iconSpaceMode?: IconSpaceMode;\n  indicatorOnRight?: boolean;\n  reserveIconSpace?: boolean;\n}\n\nexport interface RenderItemContentOptions {\n  iconAlign?: IconAlign;\n  indicatorOnRight?: boolean;\n  reserveIconSpace?: boolean;\n  submenu?: boolean;\n}\n\ntype KeyableItem = { key?: Key };\n\nexport const getItemKey = (item: KeyableItem, fallback: string): Key => {\n  if (item && 'key' in item && item.key !== undefined) return item.key;\n  return fallback;\n};\n\ntype LabelableItem = {\n  key?: Key;\n  label?: ReactNode;\n  title?: ReactNode;\n};\n\nexport const getItemLabel = (\n  item: MenuItemType | SubMenuType | MenuCheckboxItemType | LabelableItem,\n): ReactNode => {\n  if (item.label !== undefined) return item.label;\n  if ('title' in item && item.title !== undefined) return item.title;\n  return item.key;\n};\n\nexport const renderIcon = (icon: MenuItemType['icon'], size?: IconSize): ReactNode => {\n  if (!icon) return null;\n  if (isValidElement(icon)) return icon;\n  return <Icon icon={icon} size={size} />;\n};\n\nexport const hasAnyIcon = (items: BaseMenuItemType[], recursive = false): boolean => {\n  return items.some((item) => {\n    if (!item) return false;\n    if ((item as MenuCheckboxItemType).type === 'checkbox') return true;\n    if ('icon' in item && item.icon) return true;\n    if (recursive && 'children' in item && item.children) {\n      return hasAnyIcon(item.children as BaseMenuItemType[], true);\n    }\n    return false;\n  });\n};\n\nexport const hasCheckboxAndIcon = (items: BaseMenuItemType[]): boolean => {\n  let hasCheckbox = false;\n  let hasIcon = false;\n  for (const item of items) {\n    if (!item) continue;\n    if ((item as MenuCheckboxItemType).type === 'checkbox') {\n      hasCheckbox = true;\n    }\n    if ('icon' in item && item.icon) {\n      hasIcon = true;\n    }\n    if (hasCheckbox && hasIcon) return true;\n  }\n  return false;\n};\n"],"mappings":";;;;AA6BA,MAAa,cAAc,MAAmB,aAA0B;CACtE,IAAI,QAAQ,SAAS,QAAQ,KAAK,QAAQ,KAAA,GAAW,OAAO,KAAK;CACjE,OAAO;AACT;AAQA,MAAa,gBACX,SACc;CACd,IAAI,KAAK,UAAU,KAAA,GAAW,OAAO,KAAK;CAC1C,IAAI,WAAW,QAAQ,KAAK,UAAU,KAAA,GAAW,OAAO,KAAK;CAC7D,OAAO,KAAK;AACd;AAEA,MAAa,cAAc,MAA4B,SAA+B;CACpF,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,eAAe,IAAI,GAAG,OAAO;CACjC,OAAO,oBAAC,MAAD;EAAY;EAAY;CAAO,CAAA;AACxC;AAEA,MAAa,cAAc,OAA2B,YAAY,UAAmB;CACnF,OAAO,MAAM,MAAM,SAAS;EAC1B,IAAI,CAAC,MAAM,OAAO;EAClB,IAAK,KAA8B,SAAS,YAAY,OAAO;EAC/D,IAAI,UAAU,QAAQ,KAAK,MAAM,OAAO;EACxC,IAAI,aAAa,cAAc,QAAQ,KAAK,UAC1C,OAAO,WAAW,KAAK,UAAgC,IAAI;EAE7D,OAAO;CACT,CAAC;AACH;AAEA,MAAa,sBAAsB,UAAuC;CACxE,IAAI,cAAc;CAClB,IAAI,UAAU;CACd,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,CAAC,MAAM;EACX,IAAK,KAA8B,SAAS,YAC1C,cAAc;EAEhB,IAAI,UAAU,QAAQ,KAAK,MACzB,UAAU;EAEZ,IAAI,eAAe,SAAS,OAAO;CACrC;CACA,OAAO;AACT"}