import { isPlainObject, toKebabCase } from "./css.js";
function formatTokenKey(key, useKebabCase) {
  if (/^\d/.test(key)) {
    return key;
  }
  if (useKebabCase) {
    return toKebabCase(key);
  }
  return key.charAt(0) + key.slice(1);
}
function fromTokens(tokenObj, prefix, options = {}) {
  const { kebabCase = false, formatKey = formatTokenKey } = options;
  const cssVars = {};
  Object.entries(tokenObj).forEach(([key, value]) => {
    if (!isPlainObject(value)) {
      const formattedKey = formatKey(key, kebabCase);
      const varName = `--${prefix}${formattedKey}`;
      cssVars[varName] = value;
    }
  });
  Object.entries(tokenObj).forEach(([key, value]) => {
    if (isPlainObject(value)) {
      const formattedKey = formatKey(key, kebabCase);
      const nestedPrefix = `${prefix}${formattedKey}-`;
      const nestedVars = fromTokens(value, nestedPrefix, options);
      Object.assign(cssVars, nestedVars);
    }
  });
  return cssVars;
}
function toCssObject(cssVarsObj) {
  const rules = Object.entries(cssVarsObj).map(([name, value]) => `  '${name}': '${value}',`).join("\n");
  return `{
${rules}
};`;
}
function toString(cssVarsObj) {
  const rules = Object.entries(cssVarsObj).map(([name, value]) => `  '${name}': '${value}';`).join("\n");
  return `${rules}`;
}
export {
  formatTokenKey,
  fromTokens,
  toCssObject,
  toString
};
//# sourceMappingURL=variables.js.map
