{"version":3,"file":"PollOptionReorderHandle.mjs","names":[],"sources":["../../../../../src/components/Poll/PollCreationDialog/PollOptionReorderHandle.tsx"],"sourcesContent":["import type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport React, { useEffect, useRef } from 'react';\nimport type { PollComposerOption } from 'stream-chat';\n\nimport { useAriaLiveAnnouncer } from '../../Accessibility';\nimport { useComponentContextIcons, useTranslationContext } from '../../../context';\n\ntype PollOptionReorderHandleProps = {\n  index: number;\n  isActive: boolean;\n  onActivate: (optionId: string) => void;\n  onDeselect: () => void;\n  onMove: (direction: -1 | 1) => void;\n  option: PollComposerOption;\n  registerRef: (index: number, element: HTMLButtonElement | null) => void;\n  /** Total number of options, used for the \"position N of total\" in the active handle's label. */\n  totalOptionCount: number;\n};\n\nexport const PollOptionReorderHandle = ({\n  index,\n  isActive,\n  onActivate,\n  onDeselect,\n  onMove,\n  option,\n  registerRef,\n  totalOptionCount,\n}: PollOptionReorderHandleProps) => {\n  const { IconReorder } = useComponentContextIcons();\n  const { t } = useTranslationContext();\n  const announce = useAriaLiveAnnouncer();\n  const hasAnnouncedFocusRef = useRef(false);\n  const focusAnnouncementFrameRef = useRef<number | null>(null);\n\n  const position = index + 1;\n  const optionLabel =\n    option.text.trim() ||\n    t('poll.optionFieldSet.option.ariaLabel', 'Option {{ position }}', { position });\n  // While picked up, the label carries the option text and new position, so the focus\n  // announcement after each move already speaks them and no live-region message is needed.\n  const ariaLabel = isActive\n    ? t(\n        'poll.optionReorder.reorderPosition.ariaLabel',\n        'Reorder \"{{ option }}\" at position {{ position }} of {{ total }}',\n        {\n          option: optionLabel,\n          position,\n          total: totalOptionCount,\n        },\n      )\n    : t('poll.optionReorder.reorderOption.ariaLabel', 'Reorder option {{ position }}', {\n        position,\n      });\n\n  useEffect(\n    () => () => {\n      if (focusAnnouncementFrameRef.current === null) return;\n      cancelAnimationFrame(focusAnnouncementFrameRef.current);\n    },\n    [],\n  );\n\n  const onKeyDown = (event: ReactKeyboardEvent<HTMLButtonElement>) => {\n    if (!isActive) return;\n\n    if (event.key === 'ArrowUp') {\n      event.preventDefault();\n      onMove(-1);\n      return;\n    }\n    if (event.key === 'ArrowDown') {\n      event.preventDefault();\n      onMove(1);\n      return;\n    }\n    if (event.key === 'Escape' || event.key === 'Esc') {\n      event.preventDefault();\n      onDeselect();\n    }\n  };\n\n  return (\n    <button\n      aria-label={ariaLabel}\n      aria-pressed={isActive}\n      className='str-chat__drag-handle-button'\n      onBlur={() => {\n        if (focusAnnouncementFrameRef.current !== null) {\n          cancelAnimationFrame(focusAnnouncementFrameRef.current);\n          focusAnnouncementFrameRef.current = null;\n        }\n        hasAnnouncedFocusRef.current = false;\n        if (isActive) {\n          // Tabbing or clicking away while picked up drops the option.\n          onDeselect();\n        }\n      }}\n      onClick={() => {\n        if (isActive) {\n          onDeselect();\n          return;\n        }\n        onActivate(option.id);\n      }}\n      onFocus={() => {\n        if (isActive || hasAnnouncedFocusRef.current) return;\n\n        hasAnnouncedFocusRef.current = true;\n        focusAnnouncementFrameRef.current = requestAnimationFrame(() => {\n          announce(\n            t(\n              'poll.optionReorder.pressSpaceSelectOption.ariaLabel',\n              'Press Space to select this option, use the Up and Down arrow keys to move it, then press Space again to deselect it.',\n            ),\n            { priority: 'assertive' },\n          );\n          focusAnnouncementFrameRef.current = null;\n        });\n      }}\n      onKeyDown={onKeyDown}\n      ref={(element) => {\n        registerRef(index, element);\n      }}\n      type='button'\n    >\n      <IconReorder className='str-chat__drag-handle' />\n    </button>\n  );\n};\n"],"mappings":";;;;;;AAmBA,IAAa,2BAA2B,EACtC,OACA,UACA,YACA,YACA,QACA,QACA,aACA,uBACkC;CAClC,MAAM,EAAE,gBAAgB,yBAAyB;CACjD,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,WAAW,qBAAqB;CACtC,MAAM,uBAAuB,OAAO,KAAK;CACzC,MAAM,4BAA4B,OAAsB,IAAI;CAE5D,MAAM,WAAW,QAAQ;CACzB,MAAM,cACJ,OAAO,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