'use strict';

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

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _reactIntl = require('react-intl');

exports.default = () => ({
  listTypes: {
    account: {
      listNodeName: 'ns2:accounts-common-list',
      itemNodeName: 'account-list-item',
      messages: (0, _reactIntl.defineMessages)({
        resultCount: {
          'id': 'list.account.resultCount',
          'defaultMessage': '{totalItems, plural, =0 {No users} one {1 user} other {{startNum}\u2013{endNum} of {totalItems} users}} found'
        },
        searching: {
          'id': 'list.account.searching',
          'defaultMessage': 'Finding users...'
        }
      }),
      normalizeListData: (data, listTypeConfig) => {
        // Make namespace prefixes consistent. accounts-common-list is sometimes ns2 and sometimes
        var _listTypeConfig$listN = listTypeConfig.listNodeName.split(':', 2),
            _listTypeConfig$listN2 = _slicedToArray(_listTypeConfig$listN, 2);

        const listNodeNsPrefix = _listTypeConfig$listN2[0],
              listNodeName = _listTypeConfig$listN2[1];

        var _data$entrySeq$first = data.entrySeq().first(),
            _data$entrySeq$first2 = _slicedToArray(_data$entrySeq$first, 2);

        const rootNodeFullName = _data$entrySeq$first2[0],
              rootNodeData = _data$entrySeq$first2[1];

        var _rootNodeFullName$spl = rootNodeFullName.split(':', 2),
            _rootNodeFullName$spl2 = _slicedToArray(_rootNodeFullName$spl, 2);

        const rootNodeNsPrefix = _rootNodeFullName$spl2[0],
              rootNodeName = _rootNodeFullName$spl2[1];


        if (rootNodeName === listNodeName && rootNodeNsPrefix !== listNodeNsPrefix) {
          const rootNodeNsUri = rootNodeData.get(`@xmlns:${rootNodeNsPrefix}`);

          const updatedRootNodeData = rootNodeData.delete(`@xmlns:${rootNodeNsPrefix}`).set(`@xmlns:${listNodeNsPrefix}`, rootNodeNsUri);

          const updatedData = data.delete(`${rootNodeNsPrefix}:${rootNodeName}`).set(`${listNodeNsPrefix}:${listNodeName}`, updatedRootNodeData);

          return updatedData;
        }

        return data;
      },
      getItemLocationPath: item => {
        const csid = item.get('csid');

        return `/admin/account/${csid}`;
      }
    }
  }
});