import * as utils from "@helpers"; import { msg } from "@lit/localize"; import { Task } from "@lit/task"; import type { PropertiesPicker, Resource } from "@src/component"; import MediaTrendExplorerStyle from "@styles/orbit/mediatrendexplorer/tems-mediatrendexplorer.scss?inline"; import { css, html, nothing, unsafeCSS } from "lit"; import { customElement, property } from "lit/decorators.js"; @customElement("solid-tems-mediatrendexplorer") export class TemsMediatrendexplorer extends utils.OrbitComponent { @property({ attribute: "header", type: String }) header?: string = "Media Trend Explorer"; cherryPickedProperties: PropertiesPicker[] = [ { key: "@id", value: "@id" }, { key: "update_date", value: "update_date" }, { key: "keyword", value: "keyword" }, { key: "location", value: "location", expand: true }, { key: "country", value: "country" }, { key: "iframe", value: "iframe" }, { key: "topics", value: "topics", expand: true }, { key: "name", value: "name" }, { key: "providers", value: "providers", expand: true }, { key: "image", value: "image", expand: true }, { key: "url", value: "url" }, ]; static styles = css` ${unsafeCSS(MediaTrendExplorerStyle)} `; _getResource = new Task(this, { task: async ([dataSrc, objSrc]) => { if ( !dataSrc || !this.orbit || (!this.noRouter && this.route && !this.route.startsWith(this.currentRoute)) ) return; if (!this.hasCachedDatas || this.oldDataSrc !== dataSrc) { this.datas = await this._getProxyValue(dataSrc); this.hasCachedDatas = true; } if (this.oldDataSrc !== dataSrc) { this.oldDataSrc = dataSrc; } this.object = this.datas.find((obj: Resource) => obj["@id"] === objSrc); return utils.sort(this.datas, "keyword", "asc"); }, args: () => [ this.defaultDataSrc, this.dataSrc, this.caching, this.currentRoute, ], }); _selectKeyword(e: Event) { e.preventDefault(); if (this.route) utils.requestNavigation(this.route, e.target?.value); } render() { return ( this.gatekeeper() || this._getResource.render({ pending: () => html``, complete: (datas) => { if (!datas) { return nothing; } return html` `} > ${msg("Select a keyword")} ${datas.map((d) => { return html` ${d.keyword} `; })} ${this.object ? html`` : nothing} `; }, }) ); } }