{"version":3,"file":"GalleryHeader.mjs","names":[],"sources":["../../../../src/components/Gallery/GalleryHeader.tsx"],"sourcesContent":["import React, { useContext, useMemo } from 'react';\nimport { sanitizeUrl } from '@braintree/sanitize-url';\n\nimport { type GalleryItem } from './GalleryContext';\nimport { Button } from '../Button';\nimport {\n  ModalContext,\n  useChatContext,\n  useComponentContext,\n  useComponentContextIcons,\n  useTranslationContext,\n} from '../../context';\nimport { getDateString, isDate } from '../../i18n/utils';\n\ntype GalleryHeaderProps = {\n  currentItem: GalleryItem;\n};\n\nconst normalizeTimestamp = (timestamp: GalleryItem['createdAt']) => {\n  if (!timestamp) return undefined;\n  return isDate(timestamp) ? timestamp.toISOString() : timestamp;\n};\n\n/**\n * Reads the timestamp off the gallery item: the gallery renders outside any `MessageProvider`, and\n * channel media mixes items from many messages.\n */\nconst GalleryTimestamp = ({ createdAt }: Pick<GalleryItem, 'createdAt'>) => {\n  const { t, tDateTimeParser } = useTranslationContext();\n  const normalizedTimestamp = normalizeTimestamp(createdAt);\n\n  const when = useMemo(\n    () =>\n      getDateString({\n        messageCreatedAt: normalizedTimestamp,\n        t,\n        tDateTimeParser,\n        timestampTranslationKey: 'timestamp.GalleryTimestamp',\n      }),\n    [normalizedTimestamp, t, tDateTimeParser],\n  );\n\n  if (!when) return null;\n\n  return (\n    <time className='str-chat__gallery__timestamp' dateTime={normalizedTimestamp}>\n      {when}\n    </time>\n  );\n};\n\nexport const GalleryHeader = ({ currentItem }: GalleryHeaderProps) => {\n  const { IconArrowDownCircle, IconXmark } = useComponentContextIcons();\n  const { MessageTimestamp } = useComponentContext();\n  const { t } = useTranslationContext();\n  const { client } = useChatContext();\n  const modalContext = useContext(ModalContext);\n  const { createdAt, message, user } = currentItem;\n\n  const headerTitle =\n    (!!user?.id && user.id === client.userID && t('common.you.label', 'You')) ||\n    user?.name ||\n    user?.id ||\n    currentItem.title ||\n    t('common.userUploadedContent.label', 'User uploaded content');\n  const downloadUrl = useMemo(() => {\n    const rawDownloadUrl = currentItem.videoUrl ?? currentItem.imageUrl;\n\n    if (!rawDownloadUrl) return undefined;\n\n    const sanitizedUrl = sanitizeUrl(rawDownloadUrl);\n\n    return sanitizedUrl === 'about:blank' ? undefined : sanitizedUrl;\n  }, [currentItem.imageUrl, currentItem.videoUrl]);\n  const downloadLabel = t('common.downloadAttachment.ariaLabel', 'Download attachment');\n\n  return (\n    <div className='str-chat__gallery__header'>\n      <div aria-hidden='true' className='str-chat__gallery__header-spacer' />\n      <div className='str-chat__gallery__header-meta'>\n        <div className='str-chat__gallery__title'>{headerTitle}</div>\n        {MessageTimestamp && message ? (\n          <MessageTimestamp\n            customClass='str-chat__gallery__timestamp'\n            message={message}\n          />\n        ) : (\n          <GalleryTimestamp createdAt={createdAt} />\n        )}\n      </div>\n      <div className='str-chat__gallery__header-actions'>\n        {downloadUrl ? (\n          <a\n            aria-label={downloadLabel}\n            className='str-chat__gallery__action-button str-chat__gallery__action-button--download'\n            download\n            href={downloadUrl}\n            rel='noreferrer'\n            target='_blank'\n            title={downloadLabel}\n          >\n            <IconArrowDownCircle />\n          </a>\n        ) : null}\n        {modalContext?.close ? (\n          <Button\n            aria-label={t('common.close.ariaLabel', 'Close')}\n            className='str-chat__gallery__action-button str-chat__gallery__action-button--close'\n            onClick={modalContext.close}\n            title={t('common.close.ariaLabel', 'Close')}\n          >\n            <IconXmark />\n          </Button>\n        ) : null}\n      </div>\n    </div>\n  );\n};\n"],"mappings":";;;;;;;;;;;AAkBA,IAAM,sBAAsB,cAAwC;CAClE,IAAI,CAAC,WAAW,OAAO,KAAA;CACvB,OAAO,OAAO,SAAS,IAAI,UAAU,YAAY,IAAI;AACvD;;;;;AAMA,IAAM,oBAAoB,EAAE,gBAAgD;CAC1E,MAAM,EAAE,GAAG,oBAAoB,sBAAsB;CACrD,MAAM,sBAAsB,mBAAmB,SAAS;CAExD,MAAM,OAAO,cAET,cAAc;EACZ,kBAAkB;EAClB;EACA;EACA,yBAAyB;CAC3B,CAAC,GACH;EAAC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