{"version":3,"sources":["../../../../src/components/Tree/TreeItemLayout/useTreeItemLayout.ts"],"sourcesContent":["'use client';\n\nimport type * as React from 'react';\nimport {\n  useTreeContext_unstable,\n  useTreeItemContext_unstable,\n  useTreeItemLayoutBase_unstable,\n} from '@fluentui/react-tree';\nimport { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';\n\nimport type { TreeItemLayoutProps, TreeItemLayoutState } from './TreeItemLayout.types';\n\n/**\n * Returns the state for a TreeItemLayout component, given its props and ref.\n * The returned state can be modified with hooks before being passed to `renderTreeItemLayout`.\n */\nexport const useTreeItemLayout = (props: TreeItemLayoutProps, ref: React.Ref<HTMLElement>): TreeItemLayoutState => {\n  const state: TreeItemLayoutState = useTreeItemLayoutBase_unstable(props, ref);\n  const navigationMode = useTreeContext_unstable(ctx => ctx.navigationMode ?? 'tree');\n  const treeItemRef = useTreeItemContext_unstable(ctx => ctx.treeItemRef);\n\n  // Clicking the selector focuses the native input, which does not handle tree navigation,\n  // so focus is moved back to the tree item unless the consumer prevented the click.\n  const focusTreeItem = useEventCallback((event: React.MouseEvent<HTMLInputElement>) => {\n    if (!event.defaultPrevented) {\n      treeItemRef?.current?.focus();\n    }\n  });\n\n  if (state.selector) {\n    // eslint-disable-next-line react-hooks/immutability\n    state.selector.onClick = mergeCallbacks(state.selector.onClick, focusTreeItem);\n  }\n\n  if (state.actions) {\n    // Arrow keys move between the actions, wrapping around unless the tree is a treegrid, where ArrowLeft\n    // moves focus back to the tree item from the last action it reaches: the first one, or the last one in RTL.\n    // eslint-disable-next-line react-hooks/immutability\n    state.actions.focusgroup = `toolbar inline${navigationMode === 'tree' ? ' wrap' : ''}`;\n  }\n\n  return state;\n};\n"],"names":["useTreeItemLayout","props","ref","state","useTreeItemLayoutBase_unstable","navigationMode","useTreeContext_unstable","ctx","treeItemRef","useTreeItemContext_unstable","focusTreeItem","useEventCallback","event","defaultPrevented","current","focus","selector","onClick","mergeCallbacks","actions","focusgroup"],"mappings":"AAAA;;;;;+BAgBaA;;;eAAAA;;;2BATN;gCAC0C;AAQ1C,MAAMA,oBAAoB,CAACC,OAA4BC;IAC5D,MAAMC,QAA6BC,IAAAA,yCAA8B,EAACH,OAAOC;IACzE,MAAMG,iBAAiBC,IAAAA,kCAAuB,EAACC,CAAAA,MAAOA,IAAIF,cAAc,IAAI;IAC5E,MAAMG,cAAcC,IAAAA,sCAA2B,EAACF,CAAAA,MAAOA,IAAIC,WAAW;IAEtE,yFAAyF;IACzF,mFAAmF;IACnF,MAAME,gBAAgBC,IAAAA,gCAAgB,EAAC,CAACC;QACtC,IAAI,CAACA,MAAMC,gBAAgB,EAAE;YAC3BL,aAAaM,SAASC;QACxB;IACF;IAEA,IAAIZ,MAAMa,QAAQ,EAAE;QAClB,oDAAoD;QACpDb,MAAMa,QAAQ,CAACC,OAAO,GAAGC,IAAAA,8BAAc,EAACf,MAAMa,QAAQ,CAACC,OAAO,EAAEP;IAClE;IAEA,IAAIP,MAAMgB,OAAO,EAAE;QACjB,sGAAsG;QACtG,4GAA4G;QAC5G,oDAAoD;QACpDhB,MAAMgB,OAAO,CAACC,UAAU,GAAG,CAAC,cAAc,EAAEf,mBAAmB,SAAS,UAAU,IAAI;IACxF;IAEA,OAAOF;AACT"}