import { i18n } from "@mariozechner/mini-lit"; import { Button } from "@mariozechner/mini-lit/dist/Button.js"; import { html, LitElement, type TemplateResult } from "lit"; import { customElement, property } from "lit/decorators.js"; import type { CustomProvider } from "../storage/stores/custom-providers-store.js"; @customElement("custom-provider-card") export class CustomProviderCard extends LitElement { @property({ type: Object }) provider!: CustomProvider; @property({ type: Boolean }) isAutoDiscovery = false; @property({ type: Object }) status?: { modelCount: number; status: "connected" | "disconnected" | "checking"; }; @property() onRefresh?: (provider: CustomProvider) => void; @property() onEdit?: (provider: CustomProvider) => void; @property() onDelete?: (provider: CustomProvider) => void; protected createRenderRoot() { return this; } private renderStatus(): TemplateResult { if (!this.isAutoDiscovery) { return html`
${i18n("Models")}: ${this.provider.models?.length || 0}
`; } if (!this.status) return html``; const statusIcon = this.status.status === "connected" ? html`` : this.status.status === "checking" ? html`` : html``; const statusText = this.status.status === "connected" ? `${this.status.modelCount} ${i18n("models")}` : this.status.status === "checking" ? i18n("Checking...") : i18n("Disconnected"); return html`
${statusIcon} ${statusText}
`; } render(): TemplateResult { return html`
${this.provider.name}
${this.provider.type} ${this.provider.baseUrl ? html` • ${this.provider.baseUrl}` : ""}
${this.renderStatus()}
${this.isAutoDiscovery && this.onRefresh ? Button({ onClick: () => this.onRefresh?.(this.provider), variant: "ghost", size: "sm", children: i18n("Refresh"), }) : ""} ${this.onEdit ? Button({ onClick: () => this.onEdit?.(this.provider), variant: "ghost", size: "sm", children: i18n("Edit"), }) : ""} ${this.onDelete ? Button({ onClick: () => this.onDelete?.(this.provider), variant: "ghost", size: "sm", children: i18n("Delete"), }) : ""}
`; } }