"use strict";

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

var _rxjs = require("rxjs");

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

var _idAndIndex = require("../accounts/idAndIndex");

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

var _votingBalances = require("./votingBalances");

// 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 votingBalancesNominatorsFor(api) {
  return address => {
    return (0, _idAndIndex.idAndIndex)(api)(address).pipe((0, _operators.switchMap)((_ref) => {
      let [accountId] = _ref;
      return accountId ? api.query.staking.nominatorsFor(accountId) : (0, _rxjs.of)([]);
    }), (0, _operators.switchMap)((0, _votingBalances.votingBalances)(api)), (0, _drr.drr)());
  };
}