{"mappings":";;AAAA;;;;;;;;;;CAUC;AAmCM,SAAS,0CAAuB,KAA0B,EAAE,KAA2B;IAC5F,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,eAAO,EAAE,mBAAmB;IACjD,IAAI,SAAS,CAAA,GAAA,cAAM,EAAE,IAAM,iBAAiB,CAAC,aAAa,KAAK,YAAY;QAAC;QAAmB;QAAY;KAAa;IACxH,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAwB;IAEvE,IAAI,OAAO,CAAA,GAAA,kBAAU,EAAE,CAAC;QACtB,iBAAiB,iBAAiB;QAClC,YAAY,YAAY;IAC1B,GAAG;QAAC;QAAa;QAAc;KAAW;IAE1C,IAAI,QAAQ,CAAA,GAAA,kBAAU,EAAE;QACtB,iBAAiB;QACjB,aAAa,YAAY;IAC3B,GAAG;QAAC;QAAc;QAAc;KAAW;IAE3C,IAAI,SAAS,CAAA,GAAA,kBAAU,EAAE,CAAC;QACxB,iBAAiB,iBAAiB;QAClC,IAAI,QACF;aAEA,KAAK;IAET,GAAG;QAAC;QAAO;QAAM;KAAO;IAExB,OAAO,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;2BACpB;oBACA;kBACA;mBACA;sBACA;0BACA;YACA,mJAAmJ;YACnJ,2EAA2E;YAC3E,SAAS,KAAO;oBAChB;QACF,CAAA,GAAI;QAAC;QAAQ;QAAM;QAAO;QAAU;QAAe;QAAQ;KAAa;AAC1E","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 the submenu, and\n * controls which item will receive focus when it opens.\n */\nexport function useSubmenuTriggerState(props: SubmenuTriggerProps, state: RootMenuTriggerState): SubmenuTriggerState  {\n  let {triggerKey} = props;\n  let {expandedKeysStack, openSubmenu, closeSubmenu, close: closeAll} = state;\n  let [submenuLevel] = useState(expandedKeysStack?.length);\n  let isOpen = useMemo(() => expandedKeysStack[submenuLevel] === triggerKey, [expandedKeysStack, triggerKey, submenuLevel]);\n  let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n\n  let open = useCallback((focusStrategy?: FocusStrategy | null) => {\n    setFocusStrategy(focusStrategy ?? null);\n    openSubmenu(triggerKey, submenuLevel);\n  }, [openSubmenu, submenuLevel, triggerKey]);\n\n  let close = useCallback(() => {\n    setFocusStrategy(null);\n    closeSubmenu(triggerKey, submenuLevel);\n  }, [closeSubmenu, submenuLevel, triggerKey]);\n\n  let toggle = useCallback((focusStrategy?: FocusStrategy | null) => {\n    setFocusStrategy(focusStrategy ?? null);\n    if (isOpen) {\n      close();\n    } else {\n      open(focusStrategy);\n    }\n  }, [close, open, isOpen]);\n\n  return useMemo(() => ({\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  }), [isOpen, open, close, closeAll, focusStrategy, toggle, submenuLevel]);\n}\n"],"names":[],"version":3,"file":"useSubmenuTriggerState.mjs.map"}