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copyright 2020 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 {AriaButtonProps} from '../button/useButton';\n\nimport {Collection, FocusableElement, Node, RefObject} from '@react-types/shared';\nimport {getRowLabelledBy} from './utils';\nimport {GridRowAria, GridRowProps, useGridRow} from '../grid/useGridRow';\nimport {HTMLAttributes} from 'react';\n// @ts-ignore\nimport intlMessages from '../../intl/table/*.json';\nimport {ITableCollection} from 'react-stately/private/table/TableCollection';\nimport {mergeProps} from '../utils/mergeProps';\nimport {TableState} from 'react-stately/useTableState';\nimport {TreeGridState} from 'react-stately/private/table/useTreeGridState';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useSyntheticLinkProps} from '../utils/openLink';\n\nconst EXPANSION_KEYS = {\n  expand: {\n    ltr: 'ArrowRight',\n    rtl: 'ArrowLeft'\n  },\n  'collapse': {\n    ltr: 'ArrowLeft',\n    rtl: 'ArrowRight'\n  }\n};\n\nexport interface TableRowAria extends GridRowAria {\n  expandButtonProps: AriaButtonProps\n}\n\n/**\n * Provides the behavior and accessibility implementation for a row in a table.\n * @param props - Props for the row.\n * @param state - State of the table, as returned by `useTableState`.\n */\nexport function useTableRow<T>(props: GridRowProps<T>, state: TableState<T> | TreeGridState<T>, ref: RefObject<FocusableElement | null>): TableRowAria {\n  let {node, isVirtualized} = props;\n  let {rowProps, ...states} = useGridRow<T, ITableCollection<T>, TableState<T>>(props, state as TableState<T>, ref);\n  let {direction} = useLocale();\n\n  if (isVirtualized && state.treeColumn == null) {\n    rowProps['aria-rowindex'] = node.index + 1 + state.collection.headerRows.length; // aria-rowindex is 1 based\n  } else {\n    delete rowProps['aria-rowindex'];\n  }\n\n  let isExpanded = state.treeColumn != null && (state.expandedKeys === 'all' || state.expandedKeys.has(node.key));\n  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/table');\n  let labelProps = useLabels({\n    'aria-label': isExpanded ? stringFormatter.format('collapse') : stringFormatter.format('expand'),\n    'aria-labelledby': getRowLabelledBy(state as TableState<T>, node.key)\n  });\n\n  let treeGridRowProps: HTMLAttributes<HTMLElement> = {};\n  let expandButtonProps: AriaButtonProps = {};\n  if (state.treeColumn != null) {\n    let treeNode = state.collection.getItem(node.key);\n    if (treeNode != null) {\n      let lastChild = getLastChild(state.collection, node);\n      let hasChildRows = treeNode.props?.hasChildRows || treeNode.props?.UNSTABLE_childItems || lastChild?.type !== 'cell';\n      let parent = state.collection.getItem(node.parentKey!)!;\n      let isParentBody = parent.type === 'tablebody' || parent.type === 'body';\n      let lastSibling = getLastChild(state.collection, parent)!;\n      while (lastSibling && lastSibling.type !== 'item' && lastSibling.prevKey != null) {\n        lastSibling = state.collection.getItem(lastSibling.prevKey)!;\n      }\n\n      treeGridRowProps = {\n        onKeyDown: (e) => {\n          if ((e.key === EXPANSION_KEYS['expand'][direction]) && state.selectionManager.focusedKey === treeNode.key && hasChildRows && state.expandedKeys !== 'all' && !state.expandedKeys.has(treeNode.key)) {\n            state.toggleKey(treeNode.key);\n            e.stopPropagation();\n          } else if ((e.key === EXPANSION_KEYS['collapse'][direction]) && state.selectionManager.focusedKey === treeNode.key) {\n            if (state.expandedKeys !== 'all') {\n              if (hasChildRows && state.expandedKeys.has(treeNode.key)) {\n                state.toggleKey(treeNode.key);\n                e.stopPropagation();\n              } else if (!state.expandedKeys.has(treeNode.key) && treeNode.parentKey && treeNode.level > 0) {\n                // Item is a leaf or already collapsed, move focus to parent\n                state.selectionManager.setFocusedKey(treeNode.parentKey);\n                e.stopPropagation();\n              }\n            } else if (state.expandedKeys === 'all') {\n              state.toggleKey(treeNode.key);\n              e.stopPropagation();\n            }\n          }\n        },\n        'aria-expanded': hasChildRows ? state.expandedKeys === 'all' || state.expandedKeys.has(node.key) : undefined,\n        'aria-level': treeNode.level + 1,\n        'aria-posinset': treeNode.index - (isParentBody ? 0 : state.collection.columnCount) + 1,\n        'aria-setsize': lastSibling.index - (isParentBody ? 0  : state.collection.columnCount) + 1\n      };\n\n      expandButtonProps = {\n        isDisabled: states.isDisabled,\n        onPress: () => {\n          if (!states.isDisabled) {\n            state.toggleKey(node.key);\n            state.selectionManager.setFocused(true);\n            state.selectionManager.setFocusedKey(node.key);\n          }\n        },\n        excludeFromTabOrder: true,\n        preventFocusOnPress: true,\n        // @ts-ignore\n        'data-react-aria-prevent-focus': true,\n        ...labelProps\n      };\n    }\n  }\n\n  let syntheticLinkProps = useSyntheticLinkProps(node.props);\n  let linkProps = states.hasAction ? syntheticLinkProps : {};\n  return {\n    rowProps: {\n      ...mergeProps(rowProps, treeGridRowProps, linkProps),\n      'aria-labelledby': getRowLabelledBy(state as TableState<T>, node.key)\n    },\n    expandButtonProps,\n    ...states\n  };\n}\n\nfunction getLastChild(collection: Collection<Node<unknown>>, node: Node<unknown>) {\n  if ('lastChildKey' in node) {\n    return node.lastChildKey != null ? collection.getItem(node.lastChildKey) : null;\n  } else {\n    return Array.from(node.childNodes).findLast(item => item.parentKey === node.key);\n  }\n}\n"],"names":[],"version":3,"file":"useTableRow.cjs.map"}