import { html, LitElement, nothing, TemplateResult } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; import { SearchServiceInterface } from '../src/search-service-interface'; import { SearchResponse } from '../src/responses/search-response'; import { ExtraInfo } from '../src/responses/extra-info'; @customElement('item-detail-query') export class ItemDetailQuery extends LitElement { @property({ type: Object }) searchService?: SearchServiceInterface; @state() isSearching = false; @state() response?: SearchResponse; @state() error?: Error; private get itemResults(): ExtraInfo | null | undefined { return this.response?.response.extraInfo; } render(): TemplateResult { return html`
Item Query
${this.isSearching ? html`

Searching...

` : nothing} ${this.itemResults ? html`

Item Details:

${JSON.stringify(this.itemResults, null, 2)}
` : nothing} ${this.error ? html`

Error:

${this.error}
` : nothing} `; } async search(event: Event): Promise { event.preventDefault(); const itemId = (this.shadowRoot?.getElementById( 'item-input' ) as HTMLInputElement)?.value; this.error = undefined; this.response = undefined; this.isSearching = true; const results = await this.searchService?.itemDetails(itemId); this.response = results?.success; this.error = results?.error; this.isSearching = false; } }