/** * Copyright Aquera Inc 2025 * * This source code is licensed under the BSD-3-Clause license found in the * LICENSE file in the root directory of this source tree. */ import { html, type TemplateResult } from 'lit'; import { virtualize } from '@lit-labs/virtualizer/virtualize.js'; import { unsafeHTML } from 'lit/directives/unsafe-html.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { classMap } from 'lit/directives/class-map.js'; export class VirtualSelectRenderer { static getVirtualizedContent( data: any[], searchEnabled: boolean, renderItemFunction: (item: any) => string, value: string | string[], multiple: boolean, getDisplayText?: (item: any) => string, getItemValue?: (item: any) => string, getItemDescription?: (item: any) => string, getItemPrefix?: (item: any) => string, getItemSuffix?: (item: any) => string, showNoResults?: boolean, noResultsMessage?: string, loading?: boolean, onScroll?: (e: Event) => void, allowHtmlLabel?: boolean, enableDescription?: boolean ): TemplateResult { return html`
`; } static getItemRenderFunction( item: any, renderItemFunction: (item: any) => string, value: string | string[], multiple: boolean, getDisplayText?: (item: any) => string, getItemValue?: (item: any) => string, getItemDescription?: (item: any) => string, getItemPrefix?: (item: any) => string, getItemSuffix?: (item: any) => string, allowHtmlLabel?: boolean, enableDescription?: boolean, ): TemplateResult { if(!item) { return html``; } const displayTextFn = getDisplayText || renderItemFunction; const valueFn = getItemValue || ((item: any) => item?.value || item); const optionValue = valueFn(item); const displayText = displayTextFn(item); const isDisabled = item?.disabled || false; const className = item?.className; const description = (getItemDescription ? getItemDescription(item) : item?.description) ?? ''; const prefix = (getItemPrefix ? getItemPrefix(item) : item?.prefix) ?? ''; const suffix = (getItemSuffix ? getItemSuffix(item) : item?.suffix) ?? ''; let isSelected = false; if (multiple) { isSelected = Array.isArray(value) && value.some(v => String(v) === String(optionValue)); } else { isSelected = (Array.isArray(value) ? value[0] : value) === optionValue; } return html`