function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

import { __rest } from "tslib";
import { screenRate } from './env';
import React, { Children } from "react";
export function makeChain() {
  for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
    fns[_key] = arguments[_key];
  }

  if (fns.length === 1) {
    return fns[0];
  }

  return function chainedFunction() {
    var i = 0;
    var j = fns.length;

    for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
      args[_key2] = arguments[_key2];
    }

    for (; i < j; i++) {
      if (fns[i] && fns[i].apply) {
        fns[i].apply(this, args);
      }
    }
  };
}
export function px2rpx(val) {
  return val / screenRate;
}
export function stopPropagation(e) {
  if (!e) {
    return;
  }

  if (e.stopPropagation) {
    e.stopPropagation();
    return;
  }

  if (_typeof(e.originalEvent) === 'object' && e.originalEvent.stopPropagation) {
    e.originalEvent.stopPropagation();
  }
}
export function getDataSourceFromChildren(children) {
  if (!children) {
    return [];
  }

  return Children.map(children, function (child) {
    var _a = child.props,
        value = _a.value,
        text = _a.text,
        childText = _a.children,
        rest = __rest(_a, ["value", "text", "children"]);

    return Object.assign({
      value: value,
      label: childText || text
    }, rest);
  });
}
export function getDataSource(dataSource, children) {
  var ds = dataSource;

  if (!dataSource && Children.count(children) > 0) {
    ds = getDataSourceFromChildren(children);
  }

  return ds || [];
}