import { mdiClose, mdiPuzzle, mdiSwapHorizontal } from "@mdi/js"; import type { CSSResultGroup } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; import { atLeastVersion } from "../../../../src/common/config/version"; import "../../../../src/components/ha-dialog-header"; import "../../../../src/components/ha-icon-button"; import "../../../../src/components/ha-icon-next"; import "../../../../src/components/ha-md-dialog"; import type { HaMdDialog } from "../../../../src/components/ha-md-dialog"; import "../../../../src/components/ha-md-list"; import "../../../../src/components/ha-md-list-item"; import "../../../../src/components/ha-svg-icon"; import { getConfigEntry, type ConfigEntry, } from "../../../../src/data/config_entries"; import type { HassioAddonDetails } from "../../../../src/data/hassio/addon"; import type { Supervisor } from "../../../../src/data/supervisor/supervisor"; import { mdiHomeAssistant } from "../../../../src/resources/home-assistant-logo-svg"; import { haStyle } from "../../../../src/resources/styles"; import type { HomeAssistant } from "../../../../src/types"; import { brandsUrl } from "../../../../src/util/brands-url"; import type { SystemManagedDialogParams } from "./show-dialog-system-managed"; @customElement("dialog-system-managed") class HassioSystemManagedDialog extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @state() private _supervisor?: Supervisor; @state() private _addon?: HassioAddonDetails; @state() private _open = false; @state() private _configEntry?: ConfigEntry; @query("ha-md-dialog") private _dialog?: HaMdDialog; public async showDialog( dialogParams: SystemManagedDialogParams ): Promise { this._addon = dialogParams.addon; this._supervisor = dialogParams.supervisor; this._open = true; this._loadConfigEntry(); } private _dialogClosed() { this._addon = undefined; this._supervisor = undefined; this._configEntry = undefined; this._open = false; } public closeDialog() { this._dialog?.close(); return true; } protected render() { if (!this._addon || !this._open || !this._supervisor) { return nothing; } const addonImage = atLeastVersion(this.hass.config.version, 0, 105) && this._addon.icon ? `/api/hassio/addons/${this._addon.slug}/icon` : undefined; return html` ${this._addon?.name}
${addonImage ? html`${this._addon.name}` : html``}
${this._supervisor.localize("addon.system_managed.title")}.
${this._supervisor.localize("addon.system_managed.description")} ${this._configEntry ? html`

${this._supervisor.localize( "addon.system_managed.managed_by" )}:

${this._configEntry.title} ${this._configEntry.title} ` : nothing}
`; } private _onImageLoad(ev) { ev.target.style.visibility = "initial"; } private _onImageError(ev) { ev.target.style.visibility = "hidden"; } private async _loadConfigEntry() { if (this._addon?.system_managed_config_entry) { try { const { config_entry } = await getConfigEntry( this.hass, this._addon.system_managed_config_entry ); this._configEntry = config_entry; } catch (err) { // eslint-disable-next-line no-console console.error(err); } } } static get styles(): CSSResultGroup { return [ haStyle, css` .icons { display: flex; justify-content: center; align-items: center; gap: 16px; --mdc-icon-size: 48px; margin-bottom: 32px; } .icons img { width: 48px; } .icons .primary { color: var(--primary-color); } .actions { display: flex; justify-content: space-between; } .integration-icon { width: 24px; } ha-md-list-item { --md-list-item-leading-space: 4px; --md-list-item-trailing-space: 4px; } `, ]; } } declare global { interface HTMLElementTagNameMap { "dialog-system-managed": HassioSystemManagedDialog; } }