/* Copyright 2025 Google LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import { SignalWatcher } from "@lit-labs/signals"; import { provide } from "@lit/context"; import { LitElement, html, css, nothing, HTMLTemplateResult, unsafeCSS, } from "lit"; import { customElement, state } from "lit/decorators.js"; import { theme as uiTheme } from "./theme/theme.js"; import { A2UIClient } from "./client.js"; import { SnackbarAction, SnackbarMessage, SnackbarUUID, SnackType, } from "./types/types.js"; import { type Snackbar } from "./ui/snackbar.js"; import { repeat } from "lit/directives/repeat.js"; import { v0_8 } from "@a2ui/lit"; import * as UI from "@a2ui/lit/ui"; // Demo elements. import "./ui/ui.js"; import { registerContactComponents } from "./ui/custom-components/register-components.js"; // Register custom components for the contact app registerContactComponents(); @customElement("a2ui-contact") export class A2UIContactFinder extends SignalWatcher(LitElement) { @provide({ context: UI.Context.themeContext }) accessor theme: v0_8.Types.Theme = uiTheme; @state() accessor #requesting = false; @state() accessor #error: string | null = null; @state() accessor #lastMessages: v0_8.Types.ServerToClientMessage[] = []; static styles = [ unsafeCSS(v0_8.Styles.structuralStyles), css` :host { display: block; max-width: 640px; margin: 0 auto; min-height: 100%; } #surfaces { display: flex; flex-direction: column; width: 100%; padding: var(--bb-grid-size-3) 0; animation: fadeIn 1s cubic-bezier(0, 0, 0.3, 1) 0.3s backwards; & a2ui-surface { align-items: center; } } form { display: flex; flex-direction: column; flex: 1; gap: 16px; align-items: center; padding: 16px 0; animation: fadeIn 1s cubic-bezier(0, 0, 0.3, 1) 1s backwards; & > div { display: flex; flex: 1; gap: 16px; align-items: center; width: 100%; & > input { display: block; flex: 1; border-radius: 32px; padding: 16px 24px; border: 1px solid var(--p-60); font-size: 16px; } & > button { display: flex; align-items: center; background: var(--p-40); color: var(--n-100); border: none; padding: 8px 16px; border-radius: 32px; opacity: 0.5; &:not([disabled]) { cursor: pointer; opacity: 1; } } } } .rotate { animation: rotate 1s linear infinite; } .pending { width: 100%; min-height: 200px; display: flex; align-items: center; justify-content: center; animation: fadeIn 1s cubic-bezier(0, 0, 0.3, 1) 0.3s backwards; & .g-icon { margin-right: 8px; } } .error { color: var(--e-40); background-color: var(--e-95); border: 1px solid var(--e-80); padding: 16px; border-radius: 8px; } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } @keyframes rotate { from { rotate: 0deg; } to { rotate: 360deg; } } `, ]; #processor = v0_8.Data.createSignalA2uiMessageProcessor(); #a2uiClient = new A2UIClient(); #snackbar: Snackbar | undefined = undefined; #pendingSnackbarMessages: Array<{ message: SnackbarMessage; replaceAll: boolean; }> = []; render() { return [ this.#maybeRenderForm(), this.#maybeRenderData(), this.#maybeRenderError(), ]; } #maybeRenderError() { if (!this.#error) return nothing; return html`