import {type CSSResultGroup, html, unsafeCSS} from 'lit'; import {property} from 'lit/decorators.js'; import ZincElement from '../../internal/zinc-element'; import styles from './order-table.scss'; interface OrderTableData { headers: string[]; items: { caption?: string; summary?: string; data: string[]; sub?: { caption?: string; summary?: string; data: string[]; }[]; }[]; tax?: string; discount?: string; total?: string; paid?: string; remaining?: string; } /** * @summary Short summary of the component's intended use. * @documentation https://zinc.style/components/order-table * @status experimental * @since 1.0 * * @dependency zn-example * * @event zn-event-name - Emitted as an example. * * @slot - The default slot. * @slot example - An example slot. * * @csspart base - The component's base wrapper. * * @cssproperty --example - An example CSS custom property. */ export default class ZnOrderTable extends ZincElement { static styles: CSSResultGroup = unsafeCSS(styles); @property({type: Object, reflect: true}) data: OrderTableData; private isMobile: boolean = false; private modifiedData: OrderTableData; connectedCallback() { this.isMobile = window.innerWidth < 768; this.modifiedData = this.data; window.addEventListener('resize', this.resizeEventHandler); if (this.data === null || this.data === undefined) { if (this.childNodes.length > 0 && this.childNodes[0].nodeType === 3) { // @ts-ignore const data: ChildNode & { textContent: string } = this.childNodes[0]; try { this.data = JSON.parse(data?.textContent) as OrderTableData; } catch (e) { /* empty */ } } } super.connectedCallback(); } disconnectedCallback() { window.removeEventListener('resize', this.resizeEventHandler); } resizeEventHandler = () => { if (window.innerWidth < 768 && !this.isMobile) { this.isMobile = true; this.requestUpdate(); } else if (window.innerWidth >= 768 && this.isMobile) { this.isMobile = false; this.requestUpdate(); } } render() { this.modifiedData = this.data; if (this.isMobile) { return html`