"use strict";
import { escapeHtml } from "../../cmap/cmap-utils.js";
/** Render wiki-specific HTML content for CMap editor items. */
export class CmapEditorPresentation {
constructor({ state, translate, canonicalPageReference, referenceIndex }) {
this.state = state;
this.translate = translate;
this.canonicalPageReference = canonicalPageReference;
this.referenceIndex = referenceIndex;
}
renderItem(record) {
const safeLabel = escapeHtml(record.label || "");
const safeSynopsis = escapeHtml(record.synopsis || "");
const safeKind = escapeHtml(record.kind || "concept");
const safeImageSource = escapeHtml(record.imageSource || "");
const image = safeImageSource ? `
` : "";
const aspects = (Array.isArray(record.aspects) ? record.aspects : [])
.map((aspect) => `${escapeHtml(aspect)}`)
.join("");
const aspectList = aspects ? `
${aspects}
` : "";
const personNames = (Array.isArray(record.tags) ? record.tags : [])
.filter((tag) => tag && typeof tag === "object" && tag.type === "person" && tag.value)
.map((tag) => String(tag.value));
const peopleLabel = personNames.length ?
this.translate("person-tags-title", "Responsibility/action: {people}").replace("{people}", personNames.join(", ")) : "";
const personTags = personNames.length ?
`👤 ${personNames.map(escapeHtml).join(" · ")}
` : "";
const usageCount = record.conceptId && record.kind !== "phrase" ?
this.conceptUsage(record) : null;
const usageLabel = usageCount === null ? "" :
this.translate("concept-usage-count", "{count} placements across all concept maps")
.replace("{count}", String(usageCount));
const usage = usageCount === null ? "" :
`(${usageCount})`;
const descriptionReference = this.canonicalPageReference(record.descriptionPageSlug || "");
const descriptionExists = Boolean(descriptionReference &&
this.state.pages.some((page) => page.slug === descriptionReference));
const descriptionButton = record.descriptionPageSlug ?
`` : "";
const linkedTarget = record.pageSlug || record.cmapSlug || record.parentCmapLink;
const linkedButton = linkedTarget && record.kind !== "submap" ?
`` : "";
const externalButton = record.externalUrl ?
`` : "";
const linkedCmapClass = record.cmapSlug || record.parentCmapLink ? " cmap-card-linked-cmap" : "";
return `${descriptionButton}${linkedButton}${externalButton}${image}
${safeLabel} ${usage}
${aspectList}${personTags}${safeSynopsis ? `
${safeSynopsis}
` : ""}
`;
}
conceptUsage(record) {
const maps = this.referenceIndex.byConceptId.get(record.conceptId);
const storedTotal = maps ? Array.from(maps.values()).reduce((sum, entry) =>
sum + (typeof entry === "number" ? entry : Number(entry.count) || 0), 0) : 0;
const editor = this.state.cmapPrototype?.editor;
if (!editor || !editor.containsItemRecord(record)) {
return Math.max(1, storedTotal || Number(record.usageCount) || 1);
}
const currentSlug = this.state.currentConceptMapSource?.slug ||
this.state.currentConceptMap?.slug || null;
const entry = currentSlug && maps ? maps.get(currentSlug) : null;
const current = typeof entry === "number" ? entry : Number(entry?.count) || 0;
return Math.max(1, storedTotal - current + (Number(record.usageCount) || 1));
}
}