{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAmCM,SAAS,0CACd,KAA0B,EAC1B,KAA2B;IAE3B,IAAI,cAAC,UAAU,EAAC,GAAG;IACnB,IAAI,qBAAC,iBAAiB,eAAE,WAAW,gBAAE,YAAY,EAAE,OAAO,QAAQ,EAAC,GAAG;IACtE,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE,mBAAmB;IACjD,IAAI,SAAS,CAAA,GAAA,oBAAM,EACjB,IAAM,iBAAiB,CAAC,aAAa,KAAK,YAC1C;QAAC;QAAmB;QAAY;KAAa;IAE/C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAwB;IAEvE,IAAI,OAAO,CAAA,GAAA,wBAAU,EACnB,CAAC;QACC,iBAAiB,iBAAiB;QAClC,YAAY,YAAY;IAC1B,GACA;QAAC;QAAa;QAAc;KAAW;IAGzC,IAAI,QAAQ,CAAA,GAAA,wBAAU,EAAE;QACtB,iBAAiB;QACjB,aAAa,YAAY;IAC3B,GAAG;QAAC;QAAc;QAAc;KAAW;IAE3C,IAAI,SAAS,CAAA,GAAA,wBAAU,EACrB,CAAC;QACC,iBAAiB,iBAAiB;QAClC,IAAI,QACF;aAEA,KAAK;IAET,GACA;QAAC;QAAO;QAAM;KAAO;IAGvB,OAAO,CAAA,GAAA,oBAAM,EACX,IAAO,CAAA;2BACL;oBACA;kBACA;mBACA;sBACA;0BACA;YACA,mJAAmJ;YACnJ,2EAA2E;YAC3E,SAAS,KAAO;oBAChB;QACF,CAAA,GACA;QAAC;QAAQ;QAAM;QAAO;QAAU;QAAe;QAAQ;KAAa;AAExE","sources":["packages/react-stately/src/menu/useSubmenuTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusStrategy, Key} from '@react-types/shared';\nimport type {OverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {RootMenuTriggerState} from './useMenuTriggerState';\nimport {useCallback, useMemo, useState} from 'react';\n\nexport interface SubmenuTriggerProps {\n  /** Key of the trigger item. */\n  triggerKey: Key;\n}\n\nexport interface SubmenuTriggerState extends OverlayTriggerState {\n  /** Whether the submenu is currently open. */\n  isOpen: boolean;\n  /** Controls which item will be auto focused when the submenu opens. */\n  focusStrategy: FocusStrategy | null;\n  /** Opens the submenu. */\n  open: (focusStrategy?: FocusStrategy | null) => void;\n  /** Closes the submenu. */\n  close: () => void;\n  /** Closes all menus and submenus in the menu tree. */\n  closeAll: () => void;\n  /** The level of the submenu. */\n  submenuLevel: number;\n  /** Toggles the submenu. */\n  toggle: (focusStrategy?: FocusStrategy | null) => void;\n  /** @private */\n  setOpen: () => void;\n}\n\n/**\n * Manages state for a submenu trigger. Tracks whether the submenu is currently open, the level of\n * the submenu, and controls which item will receive focus when it opens.\n */\nexport function useSubmenuTriggerState(\n  props: SubmenuTriggerProps,\n  state: RootMenuTriggerState\n): SubmenuTriggerState {\n  let {triggerKey} = props;\n  let {expandedKeysStack, openSubmenu, closeSubmenu, close: closeAll} = state;\n  let [submenuLevel] = useState(expandedKeysStack?.length);\n  let isOpen = useMemo(\n    () => expandedKeysStack[submenuLevel] === triggerKey,\n    [expandedKeysStack, triggerKey, submenuLevel]\n  );\n  let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n\n  let open = useCallback(\n    (focusStrategy?: FocusStrategy | null) => {\n      setFocusStrategy(focusStrategy ?? null);\n      openSubmenu(triggerKey, submenuLevel);\n    },\n    [openSubmenu, submenuLevel, triggerKey]\n  );\n\n  let close = useCallback(() => {\n    setFocusStrategy(null);\n    closeSubmenu(triggerKey, submenuLevel);\n  }, [closeSubmenu, submenuLevel, triggerKey]);\n\n  let toggle = useCallback(\n    (focusStrategy?: FocusStrategy | null) => {\n      setFocusStrategy(focusStrategy ?? null);\n      if (isOpen) {\n        close();\n      } else {\n        open(focusStrategy);\n      }\n    },\n    [close, open, isOpen]\n  );\n\n  return useMemo(\n    () => ({\n      focusStrategy,\n      isOpen,\n      open,\n      close,\n      closeAll,\n      submenuLevel,\n      // TODO: Placeholders that aren't used but give us parity with OverlayTriggerState so we can use this in Popover. Refactor if we update Popover via\n      // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863\n      setOpen: () => {},\n      toggle\n    }),\n    [isOpen, open, close, closeAll, focusStrategy, toggle, submenuLevel]\n  );\n}\n"],"names":[],"version":3,"file":"useSubmenuTriggerState.cjs.map"}