'use strict';

var is = require('../is.cjs');

const hasOwnProperty = Object.prototype.hasOwnProperty;
const hasOwn = (val, key) => hasOwnProperty.call(val, key);
function resolvePropValue(options, props, key, value) {
  const opt = options[key];
  if (opt != null) {
    const hasDefault = hasOwn(opt, "default");
    if (hasDefault && value === void 0) {
      const defaultValue = opt.default;
      value = opt.type !== Function && is.isFunction(defaultValue) ? defaultValue() : defaultValue;
    }
    if (opt.type === Boolean) {
      if (!hasOwn(props, key) && !hasDefault)
        value = false;
      else if (value === "")
        value = true;
    }
  }
  return value;
}
function getDataAndAriaProps(props) {
  return Object.keys(props).reduce((memo, key) => {
    if (key.startsWith("data-") || key.startsWith("aria-"))
      memo[key] = props[key];
    return memo;
  }, {});
}
function toPx(val) {
  if (typeof val === "number")
    return `${val}px`;
  return val;
}
function renderHelper(v, props = {}, defaultV) {
  if (typeof v === "function")
    return v(props);
  return v != null ? v : defaultV;
}
function wrapPromiseFn(openFn) {
  let closeFn;
  const closePromise = new Promise((resolve) => {
    closeFn = openFn(() => {
      resolve(true);
    });
  });
  const result = () => {
    closeFn == null ? void 0 : closeFn();
  };
  result.then = (filled, rejected) => closePromise.then(filled, rejected);
  result.promise = closePromise;
  return result;
}
function withUndefined(type) {
  type.default = void 0;
  return type;
}

exports.getDataAndAriaProps = getDataAndAriaProps;
exports.renderHelper = renderHelper;
exports.resolvePropValue = resolvePropValue;
exports.toPx = toPx;
exports.withUndefined = withUndefined;
exports.wrapPromiseFn = wrapPromiseFn;
//# sourceMappingURL=util.cjs.map
