import { css } from "@theme-ui/css";
function parseProps(props, source) {
  if (!props || !props.sx && !props.css) return props;
  const next = {};
  for (const key in props) {
    if (key === "sx") continue;
    next[key] = props[key];
  }
  next.css = (theme) => {
    var _a, _b, _c;
    if (!theme || typeof theme !== "object" || !("breakpoints" in theme) || (((_a = theme.breakpoints) == null ? void 0 : _a.length) ?? 0) === 0 || !("colors" in theme) || !("rawColors" in theme)) {
      let error = "@edgeandnode/jsx: no theme found, make sure `GDSProvider` has `useThemeUI` when rendering components that require Theme UI";
      throw new Error(error);
    }
    if (!((_b = theme.colors) == null ? void 0 : _b.White)) {
      throw new Error(
        "@edgeandnode/jsx: the provided theme seems empty, make sure there’s only one version of `@emotion/react` and Theme UI installed (check the lockfile)"
      );
    }
    let sx = props.sx;
    if (((_c = theme.breakpoints) == null ? void 0 : _c.length) === 2 && sx && typeof sx === "object" && hasArrayOrFunctionValues(sx)) {
      sx = Object.fromEntries(
        Object.entries(sx).map(([property, value]) => {
          const values = typeof value === "function" ? value(theme) : value;
          if (!Array.isArray(values) || values.length <= 2) {
            return [property, values];
          }
          return [property, values.filter((_value, index) => index !== 1)];
        })
      );
    }
    const styles = css(sx)(theme);
    const raw = typeof props.css === "function" ? props.css(theme) : props.css;
    return [styles, raw];
  };
  return next;
}
function hasArrayOrFunctionValues(obj) {
  for (const key in obj) {
    if (Array.isArray(obj[key]) || typeof obj[key] === "function") {
      return true;
    }
  }
  return false;
}
export {
  parseProps
};
