{"version":3,"file":"FileTag.mjs","names":[],"sources":["../../../../src/ai/file-tag/FileTag.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 FileTagProps = {\n  /** The icon that represents the file type */\n  icon: React.ReactNode;\n  /** The name of the file */\n  fileName: string;\n  /** The type of the file, e.g. 'pdf', 'docx', 'txt', etc. */\n  fileType: string;\n  /** Callback function triggered either when the file 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 file tag is removable */\n  isRemovable?: boolean;\n  /** Whether the file tag is loading */\n  isLoading?: boolean;\n};\n\n/**\n * The component is used to display a file 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 FileTag = ({\n  onClick,\n  isRemovable = false,\n  fileName,\n  fileType,\n  icon,\n  className,\n  style,\n  htmlAttributes,\n  ref,\n  isLoading = false,\n  ...restProps\n}: CommonProps<React.ElementType, FileTagProps>) => {\n  const Component = isRemovable !== true ? 'button' : 'div';\n  const classes = classNames('ndl-ai-file-tag', className);\n\n  const file = `${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          <div className=\"ndl-ai-file-tag-leading\">\n            {isLoading ? <LoadingSpinner size=\"medium\" /> : icon}\n          </div>\n          <div className=\"ndl-ai-file-tag-content\">\n            <span className=\"ndl-ai-file-tag-content-title\">{fileName}</span>\n            <span className=\"ndl-ai-file-tag-content-type\">\n              {fileType?.toUpperCase()}\n            </span>\n          </div>\n          {isRemovable && (\n            <CleanIconButton\n              onClick={onClick}\n              description={null}\n              htmlAttributes={{\n                'aria-label': `Remove ${file}`,\n                onBlur: () => setIsRemoveActive(false),\n                onFocus: () => setIsRemoveActive(true),\n                onMouseEnter: () => setIsRemoveActive(true),\n                onMouseLeave: () => setIsRemoveActive(false),\n              }}\n              size=\"small\"\n              className=\"ndl-ai-file-tag-remove\"\n            >\n              <XMarkIconOutline />\n            </CleanIconButton>\n          )}\n        </Component>\n      </Tooltip.Trigger>\n      <Tooltip.Content>\n        {isRemoveActive ? `Remove ${file}` : file}\n      </Tooltip.Content>\n    </Tooltip>\n  );\n};\n\nexport { FileTag };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;;;AAVF,MAAM,WAAW,SAYmC;CAZnC,IAAA,EACf,SACA,cAAc,OACd,UACA,UACA,MACA,WACA,OACA,gBACA,KACA,YAAY,UAAA,MACT,YAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,YAAY,gBAAgB,OAAO,WAAW;CACpD,MAAM,UAAU,WAAW,mBAAmB,SAAS;CAEvD,MAAM,OAAO,GAAG,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