import {
  TwindContext
} from "./chunk.DXADCDEM.js";
import {
  Re,
  ne
} from "./chunk.PSO6NFST.js";

// src/runtime/styling/index.ts
import {
  createElement,
  useContext
} from "react";

// node_modules/twind/css/css.js
var f = (e, t) => !!~e.indexOf(t);
var x = (e, t = 1) => e.slice(t);
var T = (e) => e.replace(/[A-Z]/g, "-$&").toLowerCase();
var S = (e, t) => {
  for (; typeof e == "function"; )
    e = e(t);
  return e;
};
var A = (e, t) => f("rg", (typeof t)[5]) || Array.isArray(t) && e[0] != "@";
var a = (e, t, r) => t ? Object.keys(t).reduce((n, s) => {
  let i = S(t[s], r);
  return A(s, i) ? n[T(s)] = i : n[s] = s[0] == "@" && f("fig", s[1]) ? (n[s] || []).concat(i) : a(n[s] || {}, i, r), n;
}, e) : e;
var B = typeof CSS != "undefined" && CSS.escape || ((e) => {
  let t = e.charCodeAt(0), r = "";
  return t >= 48 && t <= 57 && (r = "\\" + t.toString(16) + " ", e = x(e)), r + e.replace(/[!./:#]/g, "\\$&");
});
var D = (e, t) => {
  let r = (n, s) => Array.isArray(s) ? s.reduce(r, n) : a(n, S(s, t), t);
  return e.reduce(r, {});
};
var K = /\s*(?:([\w-%@]+)\s*:?\s*([^{;]+?)\s*(?:;|$|})|([^;}{]*?)\s*{)|(})/gi;
var V = /\/\*[\s\S]*?\*\/|\s+|\n/gm;
var d = (e, t) => e.reduceRight((r, n) => ({[n]: r}), t);
var l = (e, t, r) => {
  r && e.push(d(t, r));
};
var j = (e, t, r) => {
  let n = e[0], s = [];
  for (let i = 0; i < t.length; ) {
    let o = S(t[i], r);
    o && typeof o == "object" ? (s.push(n, o), n = e[++i]) : n += (o || "") + e[++i];
  }
  return s.push(n), s;
};
var P = (e, t) => {
  let r = [], n = [], s, i;
  for (let o = 0; o < e.length; o++) {
    let u = e[o];
    if (typeof u == "string") {
      for (; i = K.exec(u.replace(V, " ")); )
        if (!!i[0]) {
          if (i[4] && (s = l(n, r, s), r.pop()), i[3])
            s = l(n, r, s), r.push(i[3]);
          else if (!i[4]) {
            s || (s = {});
            let c = i[2] && /\S/.test(i[2]) ? i[2] : e[++o];
            c && (i[1] == "@apply" ? a(s, S(Re(c), t), t) : s[i[1]] = c);
          }
        }
    } else
      s = l(n, r, s), n.push(d(r, u));
  }
  return l(n, r, s), n;
};
var C = (e, t) => D(Array.isArray(e[0]) && Array.isArray(e[0].raw) ? P(j(e[0], e.slice(1), t), t) : e, t);
var m = (...e) => ne(C, e);

// src/runtime/styling/index.ts
function styledComponent(component, parentDirective) {
  return function boundStyled(...args) {
    const directive = m(parentDirective, m(...args));
    return function boundStyledElement(props) {
      return renderStyled(component, props, directive);
    };
  };
}
function styledHtml(elementType, parentDirective) {
  return function boundStyled(...args) {
    const directive = m(parentDirective, m(...args));
    return function boundStyledElement(props) {
      return renderStyled(elementType, props, directive);
    };
  };
}
function renderStyled(elementType, {className, ...props} = {}, directive) {
  const tw = useContext(TwindContext);
  const styledClassName = tw(directive);
  return createElement(elementType, {
    ...props,
    className: `${className ? `${className} ` : ""}${styledClassName}`
  });
}
var styled = new Proxy(renderStyled, {
  apply(_target, _this, [elementType, ...args]) {
    const directive = m(...args);
    return typeof elementType === "string" ? styledHtml(elementType, directive) : styledComponent(elementType, directive);
  },
  get(_t, elementType) {
    return styledHtml(elementType);
  }
});

export {
  styled
};
