/**
 * DevExtreme (ui/file_manager/ui.file_manager.common.js)
 * Version: 19.1.10 (build 20107-0313)
 * Build date: Thu Apr 16 2020
 *
 * Copyright (c) 2012 - 2020 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
var _deferred = require("../../core/utils/deferred");
var _common = require("../../core/utils/common");
var _type = require("../../core/utils/type");
var _type2 = _interopRequireDefault(_type);

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        "default": obj
    }
}
var ErrorCode = {
    NoAccess: 0,
    FileExists: 1,
    FileNotFound: 2,
    DirectoryExists: 3,
    Other: 32767
};
var whenSome = function(arg, onSuccess, onError) {
    onSuccess = onSuccess || _common.noop;
    onError = onError || _common.noop;
    if (!Array.isArray(arg)) {
        arg = [arg]
    }
    var deferreds = arg.map(function(item, index) {
        return (0, _deferred.when)(item).then(function() {
            _type2.default.isFunction(onSuccess) && onSuccess()
        }, function(error) {
            if (!error) {
                error = {}
            }
            error.index = index;
            _type2.default.isFunction(onError) && onError(error)
        })
    });
    return _deferred.when.apply(null, deferreds)
};
module.exports = whenSome;
module.exports.ErrorCode = ErrorCode;
