"use strict";

exports.__esModule = true;
exports.propOrElse = exports.getValidatedControlColor = exports.getSizeUnit = exports.getSizeBy = exports.getRgbColor = exports.getOrElse = exports.getColor = void 0;
var _get = _interopRequireDefault(require("lodash/get"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var propOrElse = exports.propOrElse = function propOrElse(pathName, defaultValue) {
  return function (props) {
    return (0, _get["default"])(props, pathName, defaultValue);
  };
};
var getOrElse = exports.getOrElse = function getOrElse(pathName, defaultValue) {
  return function (_ref) {
    var theme = _ref.theme;
    return (0, _get["default"])(theme, pathName, defaultValue);
  };
};
var getSizeUnit = exports.getSizeUnit = getOrElse(["constants", "SIZE_UNIT"], 8);
var getColor = exports.getColor = function getColor(colorPath) {
  var colorPaths = Array.isArray(colorPath) ? colorPath : [colorPath];
  return getOrElse(["colors"].concat(_toConsumableArray(colorPaths)), colorPath || "#fff");
};
var getRgbColor = exports.getRgbColor = function getRgbColor(colorPath, opacity) {
  if (opacity === void 0) {
    opacity = 1;
  }
  return function (_ref2) {
    var theme = _ref2.theme;
    var color = getColor(colorPath)({
      theme: theme
    });
    var bigint = parseInt(color.substring(1), 16);
    var r = bigint >> 16 & 255;
    var g = bigint >> 8 & 255;
    var b = bigint & 255;
    return "rgba(" + r + ", " + g + ", " + b + ", " + opacity + ")";
  };
};
var getSizeBy = exports.getSizeBy = function getSizeBy(multiplier) {
  if (multiplier === void 0) {
    multiplier = 1;
  }
  return function (props) {
    return isNaN(multiplier) ? multiplier : (getSizeUnit(props) || 0) * multiplier + "px";
  };
};
var getValidatedControlColor = exports.getValidatedControlColor = function getValidatedControlColor(defaultColorPath, defaultDisabledPath) {
  if (defaultColorPath === void 0) {
    defaultColorPath = "border";
  }
  if (defaultDisabledPath === void 0) {
    defaultDisabledPath = "disabled";
  }
  return function (_ref3) {
    var theme = _ref3.theme,
      success = _ref3.success,
      error = _ref3.error,
      disabled = _ref3.disabled;
    if (success) return getColor(["success"])({
      theme: theme
    });
    if (error) return getColor(["error"])({
      theme: theme
    });
    if (disabled) return getColor([defaultDisabledPath])({
      theme: theme
    });
    return getColor([defaultColorPath])({
      theme: theme
    });
  };
};