/**
 * DevExtreme (integration/jquery/deferred.js)
 * Version: 16.2.15
 * Build date: Tue Mar 12 2019
 *
 * Copyright (c) 2012 - 2019 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
var $ = require("jquery"),
    compareVersion = require("../../core/utils/version").compare;
exports.fromPromise = function(promise, context) {
    var isDeferred = promise && $.isFunction(promise.done) && $.isFunction(promise.fail);
    if (isDeferred) {
        return promise
    }
    var d = $.Deferred();
    promise.then(function() {
        d.resolveWith.apply(d, [context].concat([$.makeArray(arguments)]))
    }, function() {
        d.rejectWith.apply(d, [context].concat([$.makeArray(arguments)]))
    });
    return d
};
exports.when = compareVersion($.fn.jquery, [3]) < 0 ? $.when : function(singleArg) {
    if (0 === arguments.length) {
        return $.Deferred().resolve()
    } else {
        if (1 === arguments.length) {
            return singleArg && singleArg.then ? singleArg : $.Deferred().resolve(singleArg)
        } else {
            return $.when.apply($, arguments)
        }
    }
};
