import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { concat } from "@ember/helper"; import { action } from "@ember/object"; import DButton from "discourse/components/d-button"; import { i18n } from "discourse-i18n"; class ExpandableList extends Component { @tracked isExpanded = false; get maxItemsToShow() { return this.args.maxItemsToShow ?? 5; } get hasMore() { return this.args.items?.length > this.maxItemsToShow; } get visibleItems() { if (!this.args.items) { return []; } return this.isExpanded ? this.args.items : this.args.items.slice(0, this.maxItemsToShow); } get remainingCount() { return this.args.items?.length - this.maxItemsToShow; } get expandToggleLabel() { if (this.isExpanded) { return i18n("discourse_ai.features.collapse_list"); } else { return i18n("discourse_ai.features.expand_list", { count: this.remainingCount, }); } } @action toggleExpanded() { this.isExpanded = !this.isExpanded; } @action isLastItem(index) { return index === this.visibleItems.length - 1; } } export default class AiFeaturesList extends Component { get sortedModules() { if (!this.args.modules || !this.args.modules.length) { return []; } return this.args.modules.toSorted((a, b) => a.module_name.localeCompare(b.module_name) ); } @action isSpamModule(aModule) { return aModule.module_name === "spam"; } @action hasGroups(feature) { return this.groupList(feature).length > 0; } @action groupList(feature) { const groups = []; const groupIds = new Set(); if (feature.personas) { feature.personas.forEach((persona) => { if (persona.allowed_groups) { persona.allowed_groups.forEach((group) => { if (!groupIds.has(group.id)) { groupIds.add(group.id); groups.push(group); } }); } }); } return groups; } }