"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.fromKebabToCamelCase = exports.flattenObject = exports.deprecate = exports.assert = void 0;
exports.getAriaProps = getAriaProps;
exports.getDataProps = getDataProps;
exports.secondsToTimeString = exports.numberWithLimit = exports.mergeRefs = exports.isValidDateTimeNumber = exports.isUndefined = exports.isString = exports.isNumber = exports.isHTMLElement = exports.isFunction = exports.isElement = exports.isBoolean = exports.isArray = exports.getValueFromNumberOrString = void 0;
exports.wrapEvent = wrapEvent;
var _complement2 = _interopRequireDefault(require("ramda/src/complement"));
var _equals2 = _interopRequireDefault(require("ramda/src/equals"));
var _toString2 = _interopRequireDefault(require("ramda/src/toString"));
var _pipe2 = _interopRequireDefault(require("ramda/src/pipe"));
var _isNil2 = _interopRequireDefault(require("ramda/src/isNil"));
var _anyPass2 = _interopRequireDefault(require("ramda/src/anyPass"));
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var assert = exports.assert = function assert(expression, errorMessage, options) {
  if (process.env.NODE_ENV !== 'production') {
    if (!expression) {
      if (options && options.level === 'warn') {
        console.warn(errorMessage);
      } else {
        throw new Error(errorMessage);
      }
    }
  }
  return true;
};
var deprecate = exports.deprecate = function deprecate(message) {
  return function (target) {
    if (process.env.NODE_ENV !== 'production') {
      return typeof Proxy === 'undefined' ? target : new Proxy(target, {
        get: function get(getTarget, getProp) {
          console.warn("Deprecated: ".concat(message));
          return getTarget[getProp];
        },
        apply: function apply(applyTarget, thisArg, argumentsList) {
          return applyTarget.apply(thisArg, argumentsList);
        }
      });
    }
    return target;
  };
};
var isUndefined = exports.isUndefined = function isUndefined(x) {
  return typeof x === 'undefined';
};
var isElement = exports.isElement = function isElement(x) {
  return _react.default.isValidElement(x);
};
var isNumber = exports.isNumber = function isNumber(x) {
  return typeof x === 'number' && !Number.isNaN(x);
};
var isString = exports.isString = function isString(x) {
  return typeof x === 'string';
};
var isBoolean = exports.isBoolean = function isBoolean(x) {
  return typeof x === 'boolean';
};
var isArray = exports.isArray = function isArray(x) {
  return Array.isArray(x);
};
var isFunction = exports.isFunction = function isFunction(x) {
  return typeof x === 'function';
};
var isHTMLElement = exports.isHTMLElement = function isHTMLElement(x) {
  return typeof HTMLElement !== 'undefined' ? x instanceof HTMLElement : false;
};
var convertToDate = function convertToDate(value) {
  return new Date(value);
};
var isInvalid = (0, _anyPass2.default)([_isNil2.default, (0, _pipe2.default)(convertToDate, _toString2.default, (0, _equals2.default)('Invalid Date'))]);
var isValidDateTimeNumber = exports.isValidDateTimeNumber = (0, _complement2.default)(isInvalid);
var getValueFromNumberOrString = exports.getValueFromNumberOrString = function getValueFromNumberOrString(value, theme) {
  if (value && theme) {
    return "".concat(isNumber(value) ? "".concat(theme.spacing.unit(value), "px") : value);
  }
  return null;
};
var numberWithLimit = exports.numberWithLimit = function numberWithLimit(amount, limit) {
  var isOverLimit = amount > limit;
  return isOverLimit ? "".concat(limit, "+") : "".concat(amount);
};
var mergeRefs = exports.mergeRefs = function mergeRefs(refs) {
  return function (value) {
    refs.forEach(function (ref) {
      if (typeof ref === 'function') {
        ref(value);
      } else if (ref != null) {
        ref.current = value;
      }
    });
  };
};
function wrapEvent(theirHandler, ourHandler) {
  return function (event) {
    if (theirHandler) theirHandler(event);
    if (!event.defaultPrevented) {
      ourHandler(event);
    }
  };
}
var fromKebabToCamelCase = exports.fromKebabToCamelCase = function fromKebabToCamelCase(str) {
  return str.replace(/-./g, function (match) {
    return match[1].toUpperCase();
  });
};
var secondsToTimeString = exports.secondsToTimeString = function secondsToTimeString(seconds) {
  var h = Math.floor(seconds / 3600);
  var m = Math.floor(seconds % 3600 / 60);
  var s = Math.round(seconds % 60);
  return [h, m > 9 ? m : "0".concat(m), s > 9 ? s : "0".concat(s)].filter(Boolean).join(':');
};
var flattenObject = exports.flattenObject = function flattenObject(obj) {
  var flattened = {};
  Object.keys(obj).forEach(function (key) {
    if (_typeof(obj[key]) === 'object' && obj[key] !== null) {
      var nested = flattenObject(obj[key]);
      Object.keys(nested).forEach(function (nestedKey) {
        flattened["".concat(key, ".").concat(nestedKey)] = nested[nestedKey];
      });
    } else {
      flattened[key] = obj[key];
    }
  });
  return flattened;
};
function getAriaProps(props) {
  var filteredProps = {};
  Object.keys(props).forEach(function (prop) {
    if (prop.startsWith('aria-')) {
      filteredProps[prop] = props[prop];
    }
  });
  return filteredProps;
}
function getDataProps(props) {
  var filteredProps = {};
  Object.keys(props).forEach(function (prop) {
    if (prop.startsWith('data-')) {
      filteredProps[prop] = props[prop];
    }
  });
  return filteredProps;
}