{"version":3,"file":"PollOptionWithVotes.mjs","names":[],"sources":["../../../../../../src/components/Poll/PollActions/PollResults/PollOptionWithVotes.tsx"],"sourcesContent":["import React from 'react';\nimport { PollOptionWithVotesHeader } from './PollOptionWithVotesHeader';\nimport { PollVoteListing } from '../../PollVote';\nimport { useStateStore } from '../../../../store';\nimport { useChannel, usePollContext, useTranslationContext } from '../../../../context';\nimport { useChannelCapabilities } from '../../../Channel/hooks/useChannelCapabilities';\nimport type {\n  PollOptionResponseData,\n  PollState,\n  PollVoteResponseData,\n} from 'stream-chat';\nimport { Button } from '../../../Button';\nimport clsx from 'clsx';\n\ntype PollStateSelectorReturnValue = {\n  latest_votes_by_option: Record<string, PollVoteResponseData[]>;\n};\n\nconst pollStateSelector = (nextValue: PollState): PollStateSelectorReturnValue => ({\n  latest_votes_by_option: nextValue.latest_votes_by_option,\n});\n\nexport type PollOptionWithVotesProps = {\n  option: PollOptionResponseData;\n  orderNumber: number;\n  countVotesPreview?: number;\n  showAllVotes?: () => void;\n};\n\nexport const PollOptionWithVotes = ({\n  countVotesPreview,\n  option,\n  orderNumber,\n  showAllVotes,\n}: PollOptionWithVotesProps) => {\n  const channel = useChannel();\n  const { t } = useTranslationContext();\n  const channelCapabilities = useChannelCapabilities({ cid: channel.cid });\n  const { poll } = usePollContext();\n  const { latest_votes_by_option } = useStateStore(poll.state, pollStateSelector);\n\n  const votes = latest_votes_by_option && latest_votes_by_option[option.id];\n  const voteCount = votes?.length ?? 0;\n  const isVotesPreview = typeof countVotesPreview === 'number';\n\n  return (\n    <div\n      className={clsx('str-chat__poll-option', {\n        'str-chat__poll-option--has-more-votes':\n          isVotesPreview && voteCount > countVotesPreview,\n        'str-chat__poll-option--has-votes': voteCount,\n      })}\n    >\n      <PollOptionWithVotesHeader option={option} optionOrderNumber={orderNumber} />\n      {!!votes && <PollVoteListing votes={votes.slice(0, countVotesPreview)} />}\n      {channelCapabilities.has('query-poll-votes') &&\n        showAllVotes &&\n        isVotesPreview &&\n        votes?.length > countVotesPreview && (\n          <div className='str-chat__poll-option__show-all-votes-button-container'>\n            <Button\n              appearance='ghost'\n              className='str-chat__poll-option__show-all-votes-button'\n              onClick={showAllVotes}\n              size='md'\n              variant='secondary'\n            >\n              {t('poll.optionVotes.view.text', 'View all')}\n            </Button>\n          </div>\n        )}\n    </div>\n  );\n};\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAM,qBAAqB,eAAwD,EACjF,wBAAwB,UAAU,uBACpC;AASA,IAAa,uBAAuB,EAClC,mBACA,QACA,aACA,mBAC8B;CAC9B,MAAM,UAAU,WAAW;CAC3B,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,sBAAsB,uBAAuB,EAAE,KAAK,QAAQ,IAAI,CAAC;CACvE,MAAM,EAAE,SAAS,eAAe;CAChC,MAAM,EAAE,2BAA2B,cAAc,KAAK,OAAO,iBAAiB;CAE9E,MAAM,QAAQ,0BAA0B,uBAAuB,OAAO;CACtE,MAAM,YAAY,OAAO,UAAU;CACnC,MAAM,iBAAiB,OAAO,sBAAsB;CAEpD,OACE,qBAAC,OAAD;EACE,WAAW,KAAK,yBAAyB;GACvC,yCACE,kBAAkB,YAAY;GAChC,oCAAoC;EACtC,CAAC;YALH;GAOE,oBAAC,2BAAD;IAAmC;IAAQ,mBAAmB;GAAc,CAAA;GAC3E,CAAC,CAAC,SAAS,oBAAC,iBAAD,EAAiB,OAAO,MAAM,MAAM,GAAG,iBAAiB,EAAI,CAAA;GACvE,oBAAoB,IAAI,kBAAkB,KACzC,gBACA,kBACA,OAAO,SAAS,qBACd,oBAAC,OAAD;IAAK,WAAU;cACb,oBAAC,QAAD;KACE,YAAW;KACX,WAAU;KACV,SAAS;KACT,MAAK;KACL,SAAQ;eAEP,EAAE,8BAA8B,UAAU;IACrC,CAAA;GACL,CAAA;EAEN;;AAET"}