{"version":3,"file":"ImageTag.mjs","names":[],"sources":["../../../../src/ai/image-tag/ImageTag.tsx"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { CleanIconButton, LoadingSpinner, Tooltip } from '@neo4j-ndl/react';\nimport classNames from 'classnames';\nimport { useState } from 'react';\n\nimport { type CommonProps } from '../../_common/types';\nimport { XMarkIconOutline } from '../../icons/generated/heroIcons/XMarkIconOutline';\n\ntype ImageTagProps = {\n  /** The source of the image */\n  src: string;\n  /** The alt text of the image */\n  alt: string;\n  /** The name of the image */\n  fileName: string;\n  /** The type of the image, e.g. 'jpg', 'png', 'gif', etc. */\n  fileType: string;\n  /** Callback function triggered either when the image tag is clicked, or when the remove button is clicked (if isRemovable is true) */\n  onClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n  /** Whether the image tag is removable */\n  isRemovable?: boolean;\n  /** Whether the image tag is loading */\n  isLoading?: boolean;\n};\n\n/**\n * The component is used to display an image in a chat, or in a prompt.\n * It can be removable and it can be loading.\n *\n * @alpha - Changes to this component may be breaking.\n */\nconst ImageTag = ({\n  src,\n  fileName,\n  fileType,\n  alt,\n  onClick,\n  isRemovable = false,\n  isLoading = false,\n  ref,\n  className,\n  style,\n  htmlAttributes,\n  ...restProps\n}: CommonProps<React.ElementType, ImageTagProps>) => {\n  const Component = isRemovable !== true ? 'button' : 'div';\n  const classes = classNames('ndl-ai-image-tag', className);\n\n  const image = `${fileName}.${fileType}`;\n  const [isRemoveActive, setIsRemoveActive] = useState(false);\n\n  return (\n    <Tooltip\n      type=\"simple\"\n      placement=\"bottom\"\n      hoverDelay={{ close: 0, open: 500 }}\n    >\n      <Tooltip.Trigger hasButtonWrapper>\n        <Component\n          ref={ref}\n          className={classes}\n          style={style}\n          {...(isRemovable ? {} : { onClick })}\n          // what is read by screen readers here?\n          {...restProps}\n          {...htmlAttributes}\n        >\n          <img src={src} alt={alt} />\n          {isRemovable && (\n            <>\n              <div className=\"ndl-ai-image-tag-remove-wrapper\" />\n              <CleanIconButton\n                onClick={onClick}\n                description={null}\n                htmlAttributes={{\n                  'aria-label': `Remove ${image}`,\n                  onBlur: () => setIsRemoveActive(false),\n                  onFocus: () => setIsRemoveActive(true),\n                  onMouseEnter: () => setIsRemoveActive(true),\n                  onMouseLeave: () => setIsRemoveActive(false),\n                }}\n                size=\"small\"\n                className=\"ndl-ai-image-tag-remove\"\n              >\n                <XMarkIconOutline />\n              </CleanIconButton>\n            </>\n          )}\n          {isLoading && (\n            <div className=\"ndl-ai-image-tag-loading-overlay\">\n              <LoadingSpinner size=\"medium\" />\n            </div>\n          )}\n        </Component>\n      </Tooltip.Trigger>\n      <Tooltip.Content>\n        {isRemoveActive ? `Remove ${image}` : image}\n      </Tooltip.Content>\n    </Tooltip>\n  );\n};\n\nexport { ImageTag };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;;;AAXF,MAAM,YAAY,SAamC;CAbnC,IAAA,EAChB,KACA,UACA,UACA,KACA,SACA,cAAc,OACd,YAAY,OACZ,KACA,WACA,OACA,mBAAA,MACG,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,YAAY,gBAAgB,OAAO,WAAW;CACpD,MAAM,UAAU,WAAW,oBAAoB,SAAS;CAExD,MAAM,QAAQ,GAAG,SAAS,GAAG;CAC7B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