import { defaultIconProps } from "../icon/defaults.js";
import { defaultIconCustomisations } from "../customisations/defaults.js";
import { calculateSize } from "./size.js";
import { wrapSVGContent } from "./defs.js";
var isUnsetKeyword = (e) => e === "unset" || e === "undefined" || e === "none";
function iconToSVG(a, o) {
	let s = {
		...defaultIconProps,
		...a
	}, c = {
		...defaultIconCustomisations,
		...o
	}, l = {
		left: s.left,
		top: s.top,
		width: s.width,
		height: s.height
	}, u = s.body;
	[s, c].forEach((e) => {
		let n = [], r = e.hFlip, i = e.vFlip, a = e.rotate;
		r ? i ? a += 2 : (n.push("translate(" + (l.width + l.left).toString() + " " + (0 - l.top).toString() + ")"), n.push("scale(-1 1)"), l.top = l.left = 0) : i && (n.push("translate(" + (0 - l.left).toString() + " " + (l.height + l.top).toString() + ")"), n.push("scale(1 -1)"), l.top = l.left = 0);
		let o;
		switch (a < 0 && (a -= Math.floor(a / 4) * 4), a %= 4, a) {
			case 1:
				o = l.height / 2 + l.top, n.unshift("rotate(90 " + o.toString() + " " + o.toString() + ")");
				break;
			case 2:
				n.unshift("rotate(180 " + (l.width / 2 + l.left).toString() + " " + (l.height / 2 + l.top).toString() + ")");
				break;
			case 3:
				o = l.width / 2 + l.left, n.unshift("rotate(-90 " + o.toString() + " " + o.toString() + ")");
				break;
		}
		a % 2 == 1 && (l.left !== l.top && (o = l.left, l.left = l.top, l.top = o), l.width !== l.height && (o = l.width, l.width = l.height, l.height = o)), n.length && (u = wrapSVGContent(u, "<g transform=\"" + n.join(" ") + "\">", "</g>"));
	});
	let d = c.width, f = c.height, p = l.width, m = l.height, h, g;
	d === null ? (g = f === null ? "1em" : f === "auto" ? m : f, h = calculateSize(g, p / m)) : (h = d === "auto" ? p : d, g = f === null ? calculateSize(h, m / p) : f === "auto" ? m : f);
	let _ = {}, v = (e, n) => {
		isUnsetKeyword(n) || (_[e] = n.toString());
	};
	v("width", h), v("height", g);
	let y = [
		l.left,
		l.top,
		p,
		m
	];
	return _.viewBox = y.join(" "), {
		attributes: _,
		viewBox: y,
		body: u
	};
}
export { iconToSVG };
