import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { Input } from "@ember/component"; import { hash } from "@ember/helper"; import { on } from "@ember/modifier"; import { action } from "@ember/object"; import { htmlSafe } from "@ember/template"; import PluginOutlet from "discourse/components/plugin-outlet"; import concatClass from "discourse/helpers/concat-class"; import icon from "discourse-common/helpers/d-icon"; import escape from "discourse-common/lib/escape"; import { iconHTML } from "discourse-common/lib/icon-library"; import { i18n } from "discourse-i18n"; const MAX_COMPONENTS = 4; export default class ThemesListItem extends Component { @tracked childrenExpanded = false; get displayHasMore() { return this.args.theme?.get("childThemes.length") > MAX_COMPONENTS; } get displayComponents() { return this.hasComponents && this.args.theme?.isActive; } get hasComponents() { return this.children.length > 0; } @action handleClick(event) { if (!event.target.classList.contains("others-count")) { this.args.navigateToTheme(); } } get children() { let children = this.args.theme?.get("childThemes.[]"); if (this.args.theme?.get("component") || !children) { return []; } children = this.childrenExpanded ? children : children.slice(0, MAX_COMPONENTS); return children.map((t) => { const name = escape(t.name); return t.enabled ? name : `${iconHTML("ban")} ${name}`; }); } get childrenString() { return this.children.join(", "); } get moreCount() { const childrenCount = this.args.theme?.get("childThemes.length"); if ( this.args.theme?.get("component") || !childrenCount || this.childrenExpanded ) { return 0; } return childrenCount - MAX_COMPONENTS; } @action toggleChildrenExpanded(event) { event?.preventDefault(); this.childrenExpanded = !this.childrenExpanded; } }