"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.info = info;

var _operators = require("rxjs/operators");

var _drr = require("../util/drr");

// Copyright 2017-2019 @polkadot/api-derive authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
function query(api) {
  return api.queryMulti([api.query.elections.members, api.query.elections.candidates, api.query.elections.candidateCount, api.query.elections.desiredSeats, api.query.elections.nextVoterSet, api.query.elections.termDuration, api.query.elections.voteCount, api.query.elections.voterCount]);
}
/**
 * @name info
 * @returns An object containing the combined results of the storage queries for
 * all relevant election module properties.
 * @example
 * <BR>
 *
 * ```javascript
 * api.derive.elections.info(({ members, candidates }) => {
 *   console.log(`There are currently ${members.length} council members and ${candidates.length} prospective council candidates.`);
 * });
 * ```
 */


function info(api) {
  return () => {
    return query(api).pipe((0, _operators.map)((_ref) => {
      let [members, candidates, candidateCount, desiredSeats, nextVoterSet, termDuration, voteCount, voterCount] = _ref;
      return {
        members: members.reduce((record, _ref2) => {
          let [accountId, blockNumber] = _ref2;
          record[accountId.toString()] = blockNumber;
          return record;
        }, {}),
        candidates,
        candidateCount,
        desiredSeats,
        nextVoterSet,
        termDuration,
        voteCount,
        voterCount
      };
    }), (0, _drr.drr)());
  };
}