'use strict';

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

var index = require('./index.js');
var array = require('../array.js');
var selectorAll = require('../selectorAll.js');

function arrayAll(select) {
  return function() {
    return array.default(select.apply(this, arguments));
  };
}

function selection_selectAll(select) {
  if (typeof select === "function") select = arrayAll(select);
  else select = selectorAll.default(select);

  for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
    for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
      if (node = group[i]) {
        subgroups.push(select.call(node, node.__data__, i, group));
        parents.push(node);
      }
    }
  }

  return new index.Selection(subgroups, parents);
}

exports.default = selection_selectAll;
