/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var camelCase = require('lodash/camelCase');
var isUndefined = require('lodash/isUndefined');
var isNull = require('lodash/isNull');
var isArray = require('lodash/isArray');
var isNumber = require('lodash/isNumber');
var isString = require('lodash/isString');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase);
var isUndefined__default = /*#__PURE__*/_interopDefaultLegacy(isUndefined);
var isNull__default = /*#__PURE__*/_interopDefaultLegacy(isNull);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
var isNumber__default = /*#__PURE__*/_interopDefaultLegacy(isNumber);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);

var _excluded = ["from", "to", "direction"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function omit(obj, fields) {
  var shallowCopy = _objectSpread({}, obj);
  for (var i = 0; i < fields.length; i++) {
    var key = fields[i];
    delete shallowCopy[key];
  }
  return shallowCopy;
}
function removeEmptyAttrs(obj) {
  var newObj = {};
  Object.keys(obj).forEach(function (key) {
    if (!isUndefined__default["default"](obj[key]) || isNull__default["default"](obj[key])) newObj[key] = obj[key];
  });
  return newObj;
}
function getTabElementByValue() {
  var tabs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var value = arguments.length > 1 ? arguments[1] : undefined;
  var _tabs$filter = tabs.filter(function (item) {
      var id = item.id;
      return "".concat(id) === "".concat(value);
    }),
    _tabs$filter2 = _slicedToArray__default["default"](_tabs$filter, 1),
    result = _tabs$filter2[0];
  return result || null;
}
function firstUpperCase(str) {
  return str.toLowerCase().replace(/( |^)[a-z]/g, function (_char) {
    return _char.toUpperCase();
  });
}
function getBackgroundColor(color) {
  if (isString__default["default"](color)) return color;
  if (isArray__default["default"](color)) {
    if (color[0] && color[0][0] === "#") color.unshift("90deg");
    return "linear-gradient( ".concat(color.join(","), " )");
  }
  var from = color.from,
    to = color.to,
    _color$direction = color.direction,
    direction = _color$direction === void 0 ? "to right" : _color$direction,
    rest = _objectWithoutProperties__default["default"](color, _excluded);
  var keys = Object.keys(rest);
  if (keys.length) {
    keys = keys.sort(function (a, b) {
      return parseFloat(a.substr(0, a.length - 1)) - parseFloat(b.substr(0, b.length - 1));
    });
    var tempArr = keys.map(function (key) {
      return "".concat(rest[key], " ").concat(key);
    });
    return "linear-gradient(".concat(direction, ", ").concat(tempArr.join(","), ")");
  }
  return "linear-gradient(".concat(direction, ", ").concat(from, ", ").concat(to, ")");
}
function getPropsApiByEvent(eventName) {
  return camelCase__default["default"]("on-".concat(eventName));
}
function getCharacterLength(str, maxCharacter) {
  var hasMaxCharacter = isNumber__default["default"](maxCharacter);
  if (!str || str.length === 0) {
    if (hasMaxCharacter) {
      return {
        length: 0,
        characters: str
      };
    }
    return 0;
  }
  var len = 0;
  for (var i = 0; i < str.length; i++) {
    var currentStringLength = 0;
    if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) currentStringLength = 2;else currentStringLength = 1;
    if (hasMaxCharacter && len + currentStringLength > maxCharacter) {
      return {
        length: len,
        characters: str.slice(0, i)
      };
    }
    len += currentStringLength;
  }
  if (hasMaxCharacter) {
    return {
      length: len,
      characters: str
    };
  }
  return len;
}
function pxCompat(param) {
  return isNumber__default["default"](param) ? "".concat(param, "px") : param;
}

exports.firstUpperCase = firstUpperCase;
exports.getBackgroundColor = getBackgroundColor;
exports.getCharacterLength = getCharacterLength;
exports.getPropsApiByEvent = getPropsApiByEvent;
exports.getTabElementByValue = getTabElementByValue;
exports.omit = omit;
exports.pxCompat = pxCompat;
exports.removeEmptyAttrs = removeEmptyAttrs;
//# sourceMappingURL=helper.js.map
