import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/security/mitre-matrix/index.ts
var n = [
	"Initial Access",
	"Execution",
	"Persistence",
	"Privilege Escalation",
	"Defense Evasion",
	"Credential Access",
	"Discovery",
	"Lateral Movement",
	"Collection",
	"Command and Control",
	"Exfiltration",
	"Impact"
], r = class {
	el;
	matrixId;
	tactics;
	showCounts;
	highlightDetected;
	techniqueClickHandler;
	currentTechniques;
	boundTechHandlers = [];
	constructor(r) {
		this.matrixId = e("cmm-mitre-matrix"), this.tactics = r.tactics ?? n, this.showCounts = r.showCounts === !0, this.highlightDetected = r.highlightDetected !== !1, this.techniqueClickHandler = r.onTechniqueClick, this.currentTechniques = r.techniques, this.el = document.createElement("div"), this.el.id = this.matrixId, this.el.className = this.buildRootClassName(r.className), this.el.setAttribute("role", "grid"), this.el.setAttribute("aria-label", "MITRE ATT&CK Matrix"), this.renderMatrix(), t(r.container).appendChild(this.el);
	}
	update(e) {
		this.currentTechniques = e, this.cleanupHandlers(), this.el.innerHTML = "", this.renderMatrix();
	}
	destroy() {
		this.cleanupHandlers(), this.el.remove();
	}
	renderMatrix() {
		let e = /* @__PURE__ */ new Map();
		for (let t of this.tactics) e.set(t, []);
		for (let t of this.currentTechniques) {
			let n = e.get(t.tactic);
			n !== void 0 && n.push(t);
		}
		let t = document.createElement("div");
		t.className = "cmm-mitre-matrix__grid";
		for (let n of this.tactics) {
			let r = document.createElement("div");
			r.className = "cmm-mitre-matrix__column", r.setAttribute("role", "gridcell");
			let i = document.createElement("div");
			i.className = "cmm-mitre-matrix__tactic", i.textContent = n, r.appendChild(i);
			let a = e.get(n);
			if (a !== void 0) for (let e of a) {
				let t = document.createElement("div");
				t.className = this.buildTechClassName(e), t.title = `${e.id}: ${e.name}`;
				let n = document.createElement("span");
				n.className = "cmm-mitre-matrix__tech-name", n.textContent = e.name, t.appendChild(n);
				let i = document.createElement("span");
				if (i.className = "cmm-mitre-matrix__tech-id", i.textContent = e.id, t.appendChild(i), this.showCounts && e.count !== void 0 && e.count > 0) {
					let n = document.createElement("span");
					n.className = "cmm-mitre-matrix__tech-count", n.textContent = String(e.count), t.appendChild(n);
				}
				let a = document.createElement("div");
				a.className = "cmm-mitre-matrix__tooltip", a.setAttribute("role", "tooltip");
				let o = document.createElement("div");
				o.className = "cmm-mitre-matrix__tooltip-id", o.textContent = e.id, a.appendChild(o);
				let s = document.createElement("div");
				if (s.className = "cmm-mitre-matrix__tooltip-name", s.textContent = e.name, a.appendChild(s), e.detected === !0) {
					let e = document.createElement("div");
					e.className = "cmm-mitre-matrix__tooltip-detected", e.textContent = "Detected", a.appendChild(e);
				}
				if (e.count !== void 0 && e.count > 0) {
					let t = document.createElement("div");
					t.className = "cmm-mitre-matrix__tooltip-count", t.textContent = `Detections: ${String(e.count)}`, a.appendChild(t);
				}
				if (t.appendChild(a), this.techniqueClickHandler !== void 0) {
					t.style.cursor = "pointer";
					let n = (t) => {
						t.stopPropagation(), this.techniqueClickHandler !== void 0 && this.techniqueClickHandler(e);
					};
					t.addEventListener("click", n), this.boundTechHandlers.push({
						el: t,
						handler: n
					});
				}
				r.appendChild(t);
			}
			t.appendChild(r);
		}
		this.el.appendChild(t);
	}
	cleanupHandlers() {
		for (let e of this.boundTechHandlers) e.el.removeEventListener("click", e.handler);
		this.boundTechHandlers.length = 0;
	}
	buildTechClassName(e) {
		let t = ["cmm-mitre-matrix__technique"];
		return this.highlightDetected && e.detected === !0 && t.push("cmm-mitre-matrix__technique--detected"), e.severity !== void 0 && t.push(`cmm-mitre-matrix__technique--${e.severity}`), t.join(" ");
	}
	buildRootClassName(e) {
		let t = ["cmm-mitre-matrix"];
		return e && t.push(e), t.join(" ");
	}
};
//#endregion
export { r as MitreMatrix };

//# sourceMappingURL=index.js.map