'use strict';

exports.__esModule = true;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.find = find;
exports.map = map;
exports.mapCloneElement = mapCloneElement;

var _react = require('react');

var React = _interopRequireWildcard(_react);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function find(children, func, context) {
  var index = 0;
  var result = void 0;

  React.Children.forEach(children, function (child) {
    if (result) {
      return;
    }
    index += 1;
    if (func.call(context, child, index)) {
      result = child;
    }
  });

  return result;
}

function map(children, func, context) {
  var index = 0;
  return React.Children.map(children, function (child) {
    if (!React.isValidElement(child)) {
      return child;
    }
    var handle = func.call(context, child, index);
    index += 1;
    return handle;
  });
}

function mapCloneElement(children, func, context) {
  return map(children, function (child, index) {
    return React.cloneElement(child, _extends({
      key: index
    }, func(child, index)));
  }, context);
}

function some(children, func, context) {
  var index = 0;
  var result = false;

  React.Children.forEach(children, function (child) {
    if (result) {
      return;
    }
    if (!React.isValidElement(child)) {
      return;
    }

    /* eslint-disable */
    if (func.call(context, child, index += 1)) {
      result = true;
    }
  });

  return result;
}

exports.default = {
  mapCloneElement: mapCloneElement,
  some: some,
  map: map,
  find: find
};