{"version":3,"file":"PollHeader.mjs","names":[],"sources":["../../../../src/components/Poll/PollHeader.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { usePollContext, useTranslationContext } from '../../context';\nimport { useStateStore } from '../../store';\nimport type { PollOptionResponseData, PollState } from 'stream-chat';\n\ntype PollStateSelectorReturnValue = {\n  enforce_unique_vote: boolean;\n  is_closed: boolean | undefined;\n  max_votes_allowed: number | undefined;\n  name: string;\n  options: PollOptionResponseData[];\n};\nconst pollStateSelector = (nextValue: PollState): PollStateSelectorReturnValue => ({\n  enforce_unique_vote: nextValue.enforce_unique_vote,\n  is_closed: nextValue.is_closed,\n  max_votes_allowed: nextValue.max_votes_allowed,\n  name: nextValue.name,\n  options: nextValue.options,\n});\n\nexport const PollHeader = () => {\n  const { t } = useTranslationContext();\n\n  const { poll } = usePollContext();\n  const { enforce_unique_vote, is_closed, max_votes_allowed, name, options } =\n    useStateStore(poll.state, pollStateSelector);\n\n  const selectionInstructions = useMemo(() => {\n    if (is_closed) return t('poll.header.voteEnded.label', 'Vote ended');\n    if (enforce_unique_vote || options.length === 1)\n      return t('poll.header.selectOne.label', 'Select one');\n    if (max_votes_allowed)\n      return t('poll.header.selectUp.label', {\n        count: max_votes_allowed > options.length ? options.length : max_votes_allowed,\n        defaultValue_one: 'Select up to {{count}}',\n        defaultValue_other: 'Select up to {{count}}',\n      });\n    if (options.length > 1)\n      return t('poll.header.selectOneMore.label', 'Select one or more');\n    return '';\n  }, [is_closed, enforce_unique_vote, max_votes_allowed, options.length, t]);\n\n  if (!name) return null;\n\n  return (\n    <div className='str-chat__poll-header'>\n      <div className='str-chat__poll-title'>{name}</div>\n      <div className='str-chat__poll-subtitle'>{selectionInstructions}</div>\n    </div>\n  );\n};\n"],"mappings":";;;;;;AAYA,IAAM,qBAAqB,eAAwD;CACjF,qBAAqB,UAAU;CAC/B,WAAW,UAAU;CACrB,mBAAmB,UAAU;CAC7B,MAAM,UAAU;CAChB,SAAS,UAAU;AACrB;AAEA,IAAa,mBAAmB;CAC9B,MAAM,EAAE,MAAM,sBAAsB;CAEpC,MAAM,EAAE,SAAS,eAAe;CAChC,MAAM,EAAE,qBAAqB,WAAW,mBAAmB,MAAM,YAC/D,cAAc,KAAK,OAAO,iBAAiB;CAE7C,MAAM,wBAAwB,cAAc;EAC1C,IAAI,WAAW,OAAO,EAAE,+BAA+B,YAAY;EACnE,IAAI,uBAAuB,QAAQ,WAAW,GAC5C,OAAO,EAAE,+BAA+B,YAAY;EACtD,IAAI,mBACF,OAAO,EAAE,8BAA8B;GACrC,OAAO,oBAAoB,QAAQ,SAAS,QAAQ,SAAS;GAC7D,kBAAkB;GAClB,oBAAoB;EACtB,CAAC;EACH,IAAI,QAAQ,SAAS,GACnB,OAAO,EAAE,mCAAmC,oBAAoB;EAClE,OAAO;CACT,GAAG;EAAC;EAAW;EAAqB;EAAmB,QAAQ;EAAQ;CAAC,CAAC;CAEzE,IAAI,CAAC,MAAM,OAAO;CAElB,OACE,qBAAC,OAAD;EAAK,WAAU;YAAf,CACE,oBAAC,OAAD;GAAK,WAAU;aAAwB;EAAU,CAAA,GACjD,oBAAC,OAAD;GAAK,WAAU;aAA2B;EAA2B,CAAA,CAClE;;AAET"}