import w from "./index-emotion-hash.esm.js";
import x from "./index-emotion-unitless.esm.js";
import A from "./index-emotion-memoize.esm.js";
var _ = /[A-Z]|^ms/g, C = /_EMO_([^_]+?)_([^]*?)_EMO_/g, p = function(n) {
  return n.charCodeAt(1) === 45;
}, y = function(n) {
  return n != null && typeof n != "boolean";
}, h = /* @__PURE__ */ A(function(r) {
  return p(r) ? r : r.replace(_, "-$&").toLowerCase();
}), d = function(n, e) {
  switch (n) {
    case "animation":
    case "animationName":
      if (typeof e == "string")
        return e.replace(C, function(u, a, t) {
          return c = {
            name: a,
            styles: t,
            next: c
          }, a;
        });
  }
  return x[n] !== 1 && !p(n) && typeof e == "number" && e !== 0 ? e + "px" : e;
};
function m(r, n, e) {
  if (e == null)
    return "";
  var u = e;
  if (u.__emotion_styles !== void 0)
    return u;
  switch (typeof e) {
    case "boolean":
      return "";
    case "object": {
      var a = e;
      if (a.anim === 1)
        return c = {
          name: a.name,
          styles: a.styles,
          next: c
        }, a.name;
      var t = e;
      if (t.styles !== void 0) {
        var f = t.next;
        if (f !== void 0)
          for (; f !== void 0; )
            c = {
              name: f.name,
              styles: f.styles,
              next: c
            }, f = f.next;
        var s = t.styles + ";";
        return s;
      }
      return V(r, n, e);
    }
    case "function": {
      if (r !== void 0) {
        var i = c, o = e(r);
        return c = i, m(r, n, o);
      }
      break;
    }
  }
  var l = e;
  if (n == null)
    return l;
  var v = n[l];
  return v !== void 0 ? v : l;
}
function V(r, n, e) {
  var u = "";
  if (Array.isArray(e))
    for (var a = 0; a < e.length; a++)
      u += m(r, n, e[a]) + ";";
  else
    for (var t in e) {
      var f = e[t];
      if (typeof f != "object") {
        var s = f;
        n != null && n[s] !== void 0 ? u += t + "{" + n[s] + "}" : y(s) && (u += h(t) + ":" + d(t, s) + ";");
      } else if (Array.isArray(f) && typeof f[0] == "string" && (n == null || n[f[0]] === void 0))
        for (var i = 0; i < f.length; i++)
          y(f[i]) && (u += h(t) + ":" + d(t, f[i]) + ";");
      else {
        var o = m(r, n, f);
        switch (t) {
          case "animation":
          case "animationName": {
            u += h(t) + ":" + o + ";";
            break;
          }
          default:
            u += t + "{" + o + "}";
        }
      }
    }
  return u;
}
var b = /label:\s*([^\s;{]+)\s*(;|$)/g, c;
function I(r, n, e) {
  if (r.length === 1 && typeof r[0] == "object" && r[0] !== null && r[0].styles !== void 0)
    return r[0];
  var u = !0, a = "";
  c = void 0;
  var t = r[0];
  if (t == null || t.raw === void 0)
    u = !1, a += m(e, n, t);
  else {
    var f = t;
    a += f[0];
  }
  for (var s = 1; s < r.length; s++)
    if (a += m(e, n, r[s]), u) {
      var i = t;
      a += i[s];
    }
  b.lastIndex = 0;
  for (var o = "", l; (l = b.exec(a)) !== null; )
    o += "-" + l[1];
  var v = w(a) + o;
  return {
    name: v,
    styles: a,
    next: c
  };
}
export {
  I as serializeStyles
};
