import React from "react"; import { Group, Center, Text, Badge, ActionIcon, Tooltip, getDefaultZIndex, } from "@mantine/core"; import { Spotlight } from "@mantine/spotlight"; import { Link } from "react-router-dom"; import { IconFile, IconDownload } from "@tabler/icons-react"; import { buildPageUrl } from "@/features/page/page.utils"; import { getPageIcon } from "@/lib"; import { IAttachmentSearch, IPageSearch, } from "@/features/search/types/search.types"; import DOMPurify from "dompurify"; import { useTranslation } from "react-i18next"; interface SearchResultItemProps { result: IPageSearch | IAttachmentSearch; isAttachmentResult: boolean; showSpace?: boolean; } export function SearchResultItem({ result, isAttachmentResult, showSpace, }: SearchResultItemProps) { const { t } = useTranslation(); if (isAttachmentResult) { const attachmentResult = result as IAttachmentSearch; const handleDownload = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); const downloadUrl = `/api/files/${attachmentResult.id}/${attachmentResult.fileName}`; window.open(downloadUrl, "_blank"); }; return ( {attachmentResult.fileName} {attachmentResult.space.name} • {attachmentResult.page.title} {attachmentResult?.highlight && ( )} ); } else { const pageResult = result as IPageSearch; return ( {getPageIcon(pageResult?.icon)} {pageResult.title} {showSpace && pageResult.space && ( {pageResult.space.name} )} {pageResult?.highlight && ( )} ); } }