import { icon } from "@mariozechner/mini-lit/dist/icons.js"; import { LitElement } from "lit"; import { customElement, property } from "lit/decorators.js"; import { html } from "lit/html.js"; import { FileSpreadsheet, FileText, X } from "lucide"; import { AttachmentOverlay } from "../dialogs/AttachmentOverlay.js"; import type { Attachment } from "../utils/attachment-utils.js"; import { i18n } from "../utils/i18n.js"; @customElement("attachment-tile") export class AttachmentTile extends LitElement { @property({ type: Object }) attachment!: Attachment; @property({ type: Boolean }) showDelete = false; @property() onDelete?: () => void; protected override createRenderRoot(): HTMLElement | DocumentFragment { return this; } override connectedCallback(): void { super.connectedCallback(); this.style.display = "block"; this.classList.add("max-h-16"); } private handleClick = () => { AttachmentOverlay.open(this.attachment); }; override render() { const hasPreview = !!this.attachment.preview; const isImage = this.attachment.type === "image"; const isPdf = this.attachment.mimeType === "application/pdf"; const isExcel = this.attachment.mimeType?.includes("spreadsheetml") || this.attachment.fileName.toLowerCase().endsWith(".xlsx") || this.attachment.fileName.toLowerCase().endsWith(".xls"); // Choose the appropriate icon const getDocumentIcon = () => { if (isExcel) return icon(FileSpreadsheet, "md"); return icon(FileText, "md"); }; return html`
${ hasPreview ? html`
${this.attachment.fileName} ${ isPdf ? html`
${i18n("PDF")}
` : "" }
` : html`
${getDocumentIcon()}
${ this.attachment.fileName.length > 10 ? `${this.attachment.fileName.substring(0, 8)}...` : this.attachment.fileName }
` } ${ this.showDelete ? html` ` : "" }
`; } }