{"version":3,"file":"Card.mjs","names":[],"sources":["../../../../../src/components/Attachment/LinkPreview/Card.tsx"],"sourcesContent":["import React from 'react';\nimport { BaseImage as DefaultBaseImage } from '../../BaseImage';\nimport { SafeAnchor } from '../../SafeAnchor';\nimport { useAttachmentContext } from '../../../context/AttachmentContext';\n\nimport type { Attachment } from 'stream-chat';\nimport type { RenderAttachmentProps } from '../utils';\nimport type { Dimensions } from '../../../types/types';\nimport { UnableToRenderCard } from './UnableToRenderCard';\nimport clsx from 'clsx';\nimport { useComponentContext, useComponentContextIcons } from '../../../context';\n\ntype CardRootProps = {\n  cardUrl: string | undefined;\n  children: React.ReactNode;\n  type?: CardProps['type'];\n};\n\nconst CardRoot = ({ cardUrl, children, type }: CardRootProps) => {\n  const className = clsx(\n    `str-chat__message-attachment-card str-chat__message-attachment-card--${type}`,\n  );\n\n  return cardUrl ? (\n    <SafeAnchor\n      className={className}\n      href={cardUrl}\n      rel='noopener noreferrer'\n      target='_blank'\n    >\n      {children}\n    </SafeAnchor>\n  ) : (\n    <div className={className}>{children}</div>\n  );\n};\n\ntype CardHeaderProps = Pick<CardProps, 'title' | 'type' | 'image_url' | 'thumb_url'> & {\n  dimensions: Dimensions;\n  image?: string;\n};\n\nconst CardHeader = (props: CardHeaderProps) => {\n  const { dimensions, image, image_url, thumb_url, title } = props;\n  const { BaseImage = DefaultBaseImage } = useComponentContext();\n\n  return image ? (\n    <div\n      className='str-chat__message-attachment-card--header str-chat__message-attachment-card-react--header'\n      data-testid={'card-header'}\n    >\n      <BaseImage\n        alt={title || image}\n        data-testid='image-test'\n        src={image_url ?? thumb_url}\n        title={title || image}\n        {...dimensions}\n      />\n    </div>\n  ) : null;\n};\n\ntype CardContentProps = RenderAttachmentProps['attachment'];\n\nconst CardContent = (props: CardContentProps) => {\n  const { IconLink } = useComponentContextIcons();\n  const { og_scrape_url, text, title, title_link } = props;\n  const url = title_link || og_scrape_url;\n\n  return (\n    <div className='str-chat__message-attachment-card--content'>\n      {title && <div className='str-chat__message-attachment-card--title'>{title}</div>}\n      {text && <div className='str-chat__message-attachment-card--text'>{text}</div>}\n      {url && (\n        <div\n          className='str-chat__message-attachment-card--source-link'\n          data-testid='card-source-link'\n        >\n          <IconLink />\n          <div className='str-chat__message-attachment-card--url'>{url}</div>\n        </div>\n      )}\n    </div>\n  );\n};\n\nexport type CardProps = RenderAttachmentProps['attachment'] & {\n  compact?: boolean;\n};\n\nconst UnMemoizedCard = (props: CardProps) => {\n  const { giphy, image_url, og_scrape_url, thumb_url, title, title_link, type } = props;\n  const { giphyVersion: giphyVersionName } = useAttachmentContext();\n  const cardUrl = title_link || og_scrape_url;\n\n  let image = thumb_url || image_url;\n  const dimensions: { height?: string; width?: string } = {};\n\n  if (type === 'giphy' && typeof giphy !== 'undefined') {\n    const giphyVersion =\n      giphy[giphyVersionName as keyof NonNullable<Attachment['giphy']>];\n    image = giphyVersion.url;\n    dimensions.height = giphyVersion.height;\n    dimensions.width = giphyVersion.width;\n  }\n\n  if (!title && !cardUrl && !image) {\n    return <UnableToRenderCard />;\n  }\n\n  return (\n    <CardRoot cardUrl={cardUrl} type={type}>\n      <CardHeader {...props} dimensions={dimensions} image={image} />\n      <CardContent {...props} />\n    </CardRoot>\n  );\n};\n\n/** Layout for a link preview card. */\nexport const Card = React.memo(UnMemoizedCard) as typeof UnMemoizedCard;\n"],"mappings":";;;;;;;;;;AAkBA,IAAM,YAAY,EAAE,SAAS,UAAU,WAA0B;CAC/D,MAAM,YAAY,KAChB,wEAAwE,MAC1E;CAEA,OAAO,UACL,oBAAC,YAAD;EACa;EACX,MAAM;EACN,KAAI;EACJ,QAAO;EAEN;CACS,CAAA,IAEZ,oBAAC,OAAD;EAAgB;EAAY;CAAc,CAAA;AAE9C;AAOA,IAAM,cAAc,UAA2B;CAC7C,MAAM,EAAE,YAAY,OAAO,WAAW,WAAW,UAAU;CAC3D,MAAM,EAAE,WAAA,cAAY,cAAqB,oBAAoB;CAE7D,OAAO,QACL,oBAAC,OAAD;EAC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