import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/security/attack-path/index.ts
var n = {
	initial_access: "Initial Access",
	execution: "Execution",
	persistence: "Persistence",
	privilege_escalation: "Privilege Escalation",
	defense_evasion: "Defense Evasion",
	credential_access: "Credential Access",
	discovery: "Discovery",
	lateral_movement: "Lateral Movement",
	collection: "Collection",
	exfiltration: "Exfiltration",
	impact: "Impact",
	command_and_control: "Command & Control"
}, r = class {
	el;
	pathId;
	showTechniques;
	stepClickHandler;
	currentSteps;
	boundStepHandlers = [];
	constructor(n) {
		if (this.pathId = e("cmm-attack-path"), this.showTechniques = n.showTechniques === !0, this.stepClickHandler = n.onStepClick, this.currentSteps = n.steps, this.el = document.createElement("div"), this.el.id = this.pathId, this.el.className = this.buildRootClassName(n.className), this.el.setAttribute("role", "list"), this.el.setAttribute("aria-label", n.title ?? "Attack Path"), n.title !== void 0) {
			let e = document.createElement("div");
			e.className = "cmm-attack-path__title", e.textContent = n.title, this.el.appendChild(e);
		}
		let r = document.createElement("div");
		r.className = "cmm-attack-path__steps", this.el.appendChild(r), this.renderSteps(r), t(n.container).appendChild(this.el);
	}
	update(e) {
		this.currentSteps = e, this.cleanupHandlers();
		let t = this.el.querySelector(".cmm-attack-path__steps");
		t !== null && (t.innerHTML = "", this.renderSteps(t));
	}
	destroy() {
		this.cleanupHandlers(), this.el.remove();
	}
	renderSteps(e) {
		for (let t = 0; t < this.currentSteps.length; t++) {
			let r = this.currentSteps[t];
			if (r === void 0) continue;
			let i = document.createElement("div");
			i.className = this.buildStepClassName(r), i.setAttribute("role", "listitem");
			let a = document.createElement("div");
			a.className = "cmm-attack-path__step-type", a.textContent = n[r.type], i.appendChild(a);
			let o = document.createElement("div");
			if (o.className = "cmm-attack-path__step-label", o.textContent = r.label, i.appendChild(o), r.mitigated === !0) {
				let e = document.createElement("span");
				e.className = "cmm-attack-path__shield", e.setAttribute("aria-label", "Mitigated"), e.textContent = "🛡", i.appendChild(e);
			}
			if (r.description !== void 0 || this.showTechniques && r.techniques !== void 0 && r.techniques.length > 0) {
				let e = document.createElement("div");
				if (e.className = "cmm-attack-path__popup", e.setAttribute("role", "tooltip"), r.description !== void 0) {
					let t = document.createElement("p");
					t.className = "cmm-attack-path__popup-desc", t.textContent = r.description, e.appendChild(t);
				}
				if (this.showTechniques && r.techniques !== void 0 && r.techniques.length > 0) {
					let t = document.createElement("ul");
					t.className = "cmm-attack-path__popup-techniques";
					for (let e of r.techniques) {
						let n = document.createElement("li");
						n.className = "cmm-attack-path__popup-technique", n.textContent = e, t.appendChild(n);
					}
					e.appendChild(t);
				}
				i.appendChild(e);
			}
			if (this.stepClickHandler !== void 0) {
				i.style.cursor = "pointer";
				let e = (e) => {
					e.stopPropagation(), this.stepClickHandler !== void 0 && this.stepClickHandler(r);
				};
				i.addEventListener("click", e), this.boundStepHandlers.push({
					el: i,
					handler: e
				});
			}
			if (e.appendChild(i), t < this.currentSteps.length - 1) {
				let t = document.createElement("div");
				t.className = "cmm-attack-path__arrow", t.setAttribute("aria-hidden", "true"), t.innerHTML = "&#8594;", e.appendChild(t);
			}
		}
	}
	cleanupHandlers() {
		for (let e of this.boundStepHandlers) e.el.removeEventListener("click", e.handler);
		this.boundStepHandlers.length = 0;
	}
	buildStepClassName(e) {
		let t = ["cmm-attack-path__step", `cmm-attack-path__step--${e.type}`];
		return e.severity !== void 0 && t.push(`cmm-attack-path__step--severity-${e.severity}`), e.mitigated === !0 && t.push("cmm-attack-path__step--mitigated"), t.join(" ");
	}
	buildRootClassName(e) {
		let t = ["cmm-attack-path"];
		return e && t.push(e), t.join(" ");
	}
};
//#endregion
export { r as AttackPath };

//# sourceMappingURL=index.js.map