'use strict';

var hash = require('@emotion/hash');
var canUseDom = require('../_util/canUseDom.js');
var dynamicCSS = require('../vc-util/Dom/dynamicCSS.js');

function flattenToken(token) {
  let str = "";
  Object.keys(token).forEach((key) => {
    const value = token[key];
    str += key;
    if (value && typeof value === "object")
      str += flattenToken(value);
    else
      str += value;
  });
  return str;
}
function token2key(token, salt) {
  return hash(`${salt}_${flattenToken(token)}`);
}
const layerKey = `layer-${Date.now()}-${Math.random()}`.replace(/\./g, "");
const layerWidth = "903px";
function supportSelector(styleStr, handleElement) {
  var _a;
  if (canUseDom.default()) {
    dynamicCSS.updateCSS(styleStr, layerKey);
    const ele = document.createElement("div");
    ele.style.position = "fixed";
    ele.style.left = "0";
    ele.style.top = "0";
    handleElement == null ? void 0 : handleElement(ele);
    document.body.appendChild(ele);
    if (process.env.NODE_ENV !== "production") {
      ele.innerHTML = "Test";
      ele.style.zIndex = "9999999";
    }
    const support = getComputedStyle(ele).width === layerWidth;
    (_a = ele.parentNode) == null ? void 0 : _a.removeChild(ele);
    dynamicCSS.removeCSS(layerKey);
    return support;
  }
  return false;
}
let canLayer;
function supportLayer() {
  if (canLayer === void 0) {
    canLayer = supportSelector(
      `@layer ${layerKey} { .${layerKey} { width: ${layerWidth}!important; } }`,
      (ele) => {
        ele.className = layerKey;
      }
    );
  }
  return canLayer;
}
const withInstall = (comp) => {
  const c = comp;
  c.install = function(app) {
    app.component(c.displayName || c.name, comp);
  };
  return comp;
};

exports.flattenToken = flattenToken;
exports.supportLayer = supportLayer;
exports.token2key = token2key;
exports.withInstall = withInstall;
//# sourceMappingURL=util.js.map
