/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { html } from "chrome://global/content/vendor/lit.all.mjs"; import { MozLitElement } from "chrome://global/content/lit-utils.mjs"; /** * Model Optin Component * * Displays a prompt allowing the user to opt in or out of a model download. * Can also show a progress bar while downloading. */ class ModelOptin extends MozLitElement { static properties = { headingL10nId: { type: String, fluent: true }, headingIcon: { type: String }, iconAtEnd: { type: Boolean }, messageL10nId: { type: String, fluent: true }, optinButtonL10nId: { type: String, fluent: true }, optoutButtonL10nId: { type: String, fluent: true }, footerMessageL10nId: { type: String, fluent: true }, cancelDownloadButtonL10nId: { type: String, fluent: true }, isLoading: { type: Boolean, reflect: true }, progressStatus: { type: Number }, // Expected to be a number between 0 and 100 isHidden: { type: Boolean }, }; static events = { confirm: "MlModelOptinConfirm", deny: "MlModelOptinDeny", cancelDownload: "MlModelOptinCancelDownload", messageLinkClick: "MlModelOptinMessageLinkClick", footerLinkClick: "MlModelOptinFooterLinkClick", }; static eventBehaviors = { bubbles: true, composed: true, }; constructor() { super(); this.isLoading = false; this.isHidden = false; this.iconAtEnd = false; this.optinButtonL10nId = "genai-model-optin-continue"; this.optoutButtonL10nId = "genai-model-optin-optout"; this.cancelDownloadButtonL10nId = "genai-model-optin-cancel"; this.footerMessageL10nId = ""; } dispatch(event) { this.dispatchEvent( new CustomEvent(event, { bubbles: true, composed: true }) ); } handleConfirmClick() { this.dispatch(ModelOptin.events.confirm); } handleDenyClick() { this.dispatch(ModelOptin.events.deny); this.isHidden = true; } handleCancelDownloadClick() { this.dispatch(ModelOptin.events.cancelDownload); this.isLoading = false; this.progressStatus = undefined; } handleMessageLinkClick(e) { // ftl overrides the html, need to manually watch for event in parent. if (e.target.id !== "optin-message-link") { return; } this.dispatch(ModelOptin.events.messageLinkClick); } handleFooterLinkClick(e) { // ftl overrides the html, need to manually watch for event in parent. if (e.target.id !== "optin-footer-link") { return; } this.dispatch(ModelOptin.events.footerLinkClick); } render() { return html`
${this.isLoading ? html`
` : ""}
${this.headingIcon ? html`${this.headingL10nId}` : ""}

${this.isLoading ? html`
` : html`
`} ${!this.isLoading && this.footerMessageL10nId !== "" ? html` ` : ""}
`; } } customElements.define("model-optin", ModelOptin);