import { LitElement, html, css } from "lit"; import "./nav-bar.js"; import "./page-home.js"; import "./page-items.js"; class AppRoot extends LitElement { static properties = { user: { type: Object, state: true }, route: { type: String, state: true }, items: { type: Array, state: true } }; constructor() { super(); this.user = null; this.route = 'home'; this.items = []; } static styles = css` :host { display: block; min-height: 100vh; } `; #navigate(route) { this.route = route; } #addItem(item) { this.items = [...this.items, item]; } #removeItem(id) { this.items = this.items.filter(i => i.id !== id); } render() { return html` this.#navigate(e.detail.route)} >
${this.#renderRoute()}
`; } #renderRoute() { switch (this.route) { case "home": return html``; case "items": return html` this.#addItem(e.detail.item)} @remove-item=${(e) => this.#removeItem(e.detail.id)} >`; default: return html``; } } } customElements.define('app-root', AppRoot);