import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/security/vulnerability-card/index.ts
var n = {
	critical: "Critical",
	high: "High",
	medium: "Medium",
	low: "Low",
	info: "Info"
}, r = {
	open: "Open",
	in_progress: "In Progress",
	resolved: "Resolved",
	accepted: "Accepted",
	false_positive: "False Positive"
};
function i(e) {
	let t = document.createElement("div");
	return t.textContent = e, t.innerHTML;
}
function a(e) {
	return (e instanceof Date ? e : new Date(e)).toLocaleDateString(void 0, {
		year: "numeric",
		month: "short",
		day: "numeric"
	});
}
var o = class {
	el;
	cardId;
	compact;
	showReferences;
	clickHandler;
	currentData;
	refsExpanded = !1;
	boundCardClick;
	constructor(n) {
		if (this.cardId = e("cmm-vuln-card"), this.compact = n.compact === !0, this.showReferences = n.showReferences !== !1, this.clickHandler = n.onClick, this.currentData = n.data, this.el = document.createElement("div"), this.el.id = this.cardId, this.el.className = this.buildRootClassName(n.className), this.clickHandler !== void 0) {
			this.el.style.cursor = "pointer";
			let e = () => {
				this.clickHandler !== void 0 && this.clickHandler(this.currentData);
			};
			this.boundCardClick = e, this.el.addEventListener("click", e);
		} else this.boundCardClick = null;
		this.renderContent(), t(n.container).appendChild(this.el);
	}
	update(e) {
		this.currentData = e, this.el.innerHTML = "", this.renderContent();
	}
	destroy() {
		this.boundCardClick !== null && this.el.removeEventListener("click", this.boundCardClick), this.el.remove();
	}
	renderContent() {
		let e = this.currentData, t = document.createElement("div");
		t.className = "cmm-vuln-card__header";
		let i = document.createElement("span");
		i.className = `cmm-vuln-card__severity cmm-vuln-card__severity--${e.severity}`, i.textContent = n[e.severity], t.appendChild(i);
		let o = document.createElement("span");
		o.className = "cmm-vuln-card__id", o.textContent = e.id, t.appendChild(o);
		let s = document.createElement("span");
		if (s.className = "cmm-vuln-card__title", s.textContent = e.title, t.appendChild(s), e.status !== void 0) {
			let n = r[e.status];
			if (n !== void 0) {
				let r = document.createElement("span");
				r.className = `cmm-vuln-card__status cmm-vuln-card__status--${e.status}`, r.textContent = n, t.appendChild(r);
			}
		}
		this.el.appendChild(t);
		let c = document.createElement("div");
		c.className = "cmm-vuln-card__body";
		let l = document.createElement("p");
		if (l.className = "cmm-vuln-card__description", this.compact && e.description.length > 150 ? (l.textContent = e.description.slice(0, 150) + "...", l.title = e.description) : l.textContent = e.description, c.appendChild(l), e.cvss !== void 0) {
			let t = document.createElement("div");
			t.className = "cmm-vuln-card__cvss";
			let n = document.createElement("span");
			n.className = "cmm-vuln-card__cvss-label", n.textContent = "CVSS:", t.appendChild(n);
			let r = document.createElement("span");
			if (r.className = "cmm-vuln-card__cvss-value", r.textContent = e.cvss.toFixed(1), t.appendChild(r), e.cvssVector !== void 0) {
				let n = document.createElement("span");
				n.className = "cmm-vuln-card__cvss-vector", n.textContent = e.cvssVector, n.title = e.cvssVector, t.appendChild(n);
			}
			c.appendChild(t);
		}
		if (e.cwe !== void 0) {
			let t = document.createElement("div");
			t.className = "cmm-vuln-card__cwe";
			let n = document.createElement("a");
			n.className = "cmm-vuln-card__cwe-link", n.href = `https://cwe.mitre.org/data/definitions/${e.cwe.replace("CWE-", "")}.html`, n.target = "_blank", n.rel = "noopener noreferrer", n.textContent = e.cwe, t.appendChild(n), c.appendChild(t);
		}
		this.el.appendChild(c);
		let u = document.createElement("div");
		if (u.className = "cmm-vuln-card__meta", e.published !== void 0) {
			let t = document.createElement("span");
			t.className = "cmm-vuln-card__date", t.textContent = `Published: ${a(e.published)}`, u.appendChild(t);
		}
		if (e.modified !== void 0) {
			let t = document.createElement("span");
			t.className = "cmm-vuln-card__date", t.textContent = `Modified: ${a(e.modified)}`, u.appendChild(t);
		}
		if (e.affected !== void 0 && e.affected.length > 0) {
			let t = document.createElement("div");
			t.className = "cmm-vuln-card__affected";
			let n = document.createElement("span");
			n.className = "cmm-vuln-card__affected-label", n.textContent = "Affected:", t.appendChild(n);
			for (let n of e.affected) {
				let e = document.createElement("span");
				e.className = "cmm-vuln-card__affected-chip", e.textContent = n, t.appendChild(e);
			}
			u.appendChild(t);
		}
		if (u.childNodes.length > 0 && this.el.appendChild(u), e.tags !== void 0 && e.tags.length > 0) {
			let t = document.createElement("div");
			t.className = "cmm-vuln-card__tags";
			for (let n of e.tags) {
				let e = document.createElement("span");
				e.className = "cmm-vuln-card__tag", e.textContent = n, t.appendChild(e);
			}
			this.el.appendChild(t);
		}
		if (this.showReferences && e.references !== void 0 && e.references.length > 0) {
			let t = document.createElement("div");
			if (t.className = "cmm-vuln-card__references", this.compact) {
				let n = document.createElement("button");
				n.className = "cmm-vuln-card__refs-toggle", n.type = "button", n.textContent = this.refsExpanded ? `Hide References (${String(e.references.length)})` : `Show References (${String(e.references.length)})`, n.addEventListener("click", (e) => {
					e.stopPropagation(), this.refsExpanded = !this.refsExpanded, this.el.innerHTML = "", this.renderContent();
				}), t.appendChild(n), this.refsExpanded && this.appendRefList(t, e.references);
			} else {
				let n = document.createElement("div");
				n.className = "cmm-vuln-card__refs-title", n.textContent = `References (${String(e.references.length)})`, t.appendChild(n), this.appendRefList(t, e.references);
			}
			this.el.appendChild(t);
		}
	}
	appendRefList(e, t) {
		let n = document.createElement("ul");
		n.className = "cmm-vuln-card__refs-list";
		for (let e of t) {
			let t = document.createElement("li");
			t.className = "cmm-vuln-card__refs-item";
			let r = document.createElement("a");
			r.className = "cmm-vuln-card__refs-link", r.href = e.url, r.target = "_blank", r.rel = "noopener noreferrer", r.innerHTML = i(e.title), t.appendChild(r), n.appendChild(t);
		}
		e.appendChild(n);
	}
	buildRootClassName(e) {
		let t = ["cmm-vuln-card"];
		return this.compact && t.push("cmm-vuln-card--compact"), e && t.push(e), t.join(" ");
	}
};
//#endregion
export { o as VulnerabilityCard };

//# sourceMappingURL=index.js.map