"use strict";
const common_vendor = require("../../../../common/vendor.js");
const uni_modules_tdesignUniapp_components_common_config = require("./config.js");
const uni_modules_tdesignUniapp_components_common_validator = require("./validator.js");
const uni_modules_tdesignUniapp_components_common_wechat = require("./wechat.js");
const systemInfo = uni_modules_tdesignUniapp_components_common_wechat.getWindowInfo();
const appBaseInfo = uni_modules_tdesignUniapp_components_common_wechat.getAppBaseInfo();
const deviceInfo = uni_modules_tdesignUniapp_components_common_wechat.getDeviceInfo();
function coalesce(...args) {
  for (let i = 0; i < args.length; i += 1) {
    if (args[i] !== null && args[i] !== void 0) {
      return args[i];
    }
  }
  return args[args.length - 1];
}
const classNames = function(...args) {
  const hasOwn = {}.hasOwnProperty;
  const classes = [];
  args.forEach((arg) => {
    if (!arg)
      return;
    const argType = typeof arg;
    if (argType === "string" || argType === "number") {
      classes.push(arg);
    } else if (Array.isArray(arg) && arg.length) {
      const inner = classNames(...arg);
      if (inner) {
        classes.push(inner);
      }
    } else if (argType === "object") {
      for (const key in arg) {
        if (hasOwn.call(arg, key) && arg[key]) {
          classes.push(key);
        }
      }
    }
  });
  return classes.join(" ");
};
const styles = function(styleObj) {
  return Object.keys(styleObj).map((styleKey) => `${styleKey}: ${styleObj[styleKey]}`).join("; ");
};
const getRect = function(context, selector, needAll = false, useH5Origin = false) {
  return new Promise((resolve, reject) => {
    common_vendor.index.createSelectorQuery().in(context)[needAll ? "selectAll" : "select"](selector).boundingClientRect((rect) => {
      if (rect) {
        resolve(rect);
      } else {
        reject(rect);
      }
    }).exec();
  });
};
(deviceInfo == null ? void 0 : deviceInfo.environment) === "wxwork";
["mac", "windows"].includes(deviceInfo == null ? void 0 : deviceInfo.platform);
const addUnit = function(value) {
  if (!uni_modules_tdesignUniapp_components_common_validator.isDef(value)) {
    return void 0;
  }
  value = String(value);
  return uni_modules_tdesignUniapp_components_common_validator.isNumeric(value) ? `${value}px` : value;
};
const getCharacterLength = (type, char, max) => {
  const str = String(coalesce(char, ""));
  if (str.length === 0) {
    return {
      length: 0,
      characters: ""
    };
  }
  if (type === "maxcharacter") {
    let len = 0;
    for (let i = 0; i < str.length; i += 1) {
      let currentStringLength = 0;
      if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
        currentStringLength = 2;
      } else {
        currentStringLength = 1;
      }
      if (len + currentStringLength > max) {
        return {
          length: len,
          characters: str.slice(0, i)
        };
      }
      len += currentStringLength;
    }
    return {
      length: len,
      characters: str
    };
  }
  if (type === "maxlength") {
    const length = str.length > max ? max : str.length;
    return {
      length,
      characters: str.slice(0, length)
    };
  }
  return {
    length: str.length,
    characters: str
  };
};
const unitConvert = (value) => {
  if (typeof value === "string") {
    if (value.includes("rpx")) {
      return parseInt(value, 10) * coalesce(systemInfo == null ? void 0 : systemInfo.screenWidth, 750) / 750;
    }
    return parseInt(value, 10);
  }
  return coalesce(value, 0);
};
const setIcon = (iconName, icon, defaultIcon) => {
  if (icon) {
    if (typeof icon === "string") {
      return {
        [`${iconName}Name`]: icon,
        [`${iconName}Data`]: {}
      };
    }
    if (typeof icon === "object") {
      return {
        [`${iconName}Name`]: "",
        [`${iconName}Data`]: icon
      };
    }
    return {
      [`${iconName}Name`]: defaultIcon,
      [`${iconName}Data`]: {}
    };
  }
  return {
    [`${iconName}Name`]: "",
    [`${iconName}Data`]: {}
  };
};
const toCamel = (str) => str.replace(/-(\w)/g, (match, m1) => m1.toUpperCase());
const toPascal = (name) => name.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
function hyphenate(str) {
  const hyphenateRE = /\B([A-Z])/g;
  return str.replace(hyphenateRE, "-$1").toLowerCase();
}
const getCurrentPage = function() {
  const pages = getCurrentPages();
  return pages[pages.length - 1];
};
const uniqueFactory = (compName) => {
  let number = 0;
  return () => {
    const uniqueId = `${uni_modules_tdesignUniapp_components_common_config.prefix}_${compName}_${number}`;
    number += 1;
    return uniqueId;
  };
};
const calcIcon = (icon, defaultIcon) => {
  if (icon && (uni_modules_tdesignUniapp_components_common_validator.isBoolean(icon) && defaultIcon || uni_modules_tdesignUniapp_components_common_validator.isString(icon))) {
    return { name: uni_modules_tdesignUniapp_components_common_validator.isBoolean(icon) ? defaultIcon : icon };
  }
  if (uni_modules_tdesignUniapp_components_common_validator.isObject(icon)) {
    return icon;
  }
  return null;
};
const nextTick = () => new Promise((resolve) => {
  setTimeout(() => {
    resolve();
  }, 33);
});
exports.addUnit = addUnit;
exports.appBaseInfo = appBaseInfo;
exports.calcIcon = calcIcon;
exports.classNames = classNames;
exports.coalesce = coalesce;
exports.getCharacterLength = getCharacterLength;
exports.getCurrentPage = getCurrentPage;
exports.getRect = getRect;
exports.hyphenate = hyphenate;
exports.nextTick = nextTick;
exports.setIcon = setIcon;
exports.styles = styles;
exports.systemInfo = systemInfo;
exports.toCamel = toCamel;
exports.toPascal = toPascal;
exports.uniqueFactory = uniqueFactory;
exports.unitConvert = unitConvert;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/tdesign-uniapp/components/common/utils.js.map
