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