/**
 * DevExtreme (cjs/integration/jquery/component_registrator.js)
 * Version: 24.1.7-build-24272-1937
 * Build date: Sat Sep 28 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
var _jquery = _interopRequireDefault(require("jquery"));
var _component_registrator_callbacks = _interopRequireDefault(require("../../core/component_registrator_callbacks"));
var _errors = _interopRequireDefault(require("../../core/errors"));

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}
if (_jquery.default) {
    const registerJQueryComponent = function(name, componentClass) {
        _jquery.default.fn[name] = function(options) {
            const isMemberInvoke = "string" === typeof options;
            let result;
            if (isMemberInvoke) {
                const memberName = options;
                const memberArgs = [].slice.call(arguments).slice(1);
                this.each((function() {
                    const instance = componentClass.getInstance(this);
                    if (!instance) {
                        throw _errors.default.Error("E0009", name)
                    }
                    const member = instance[memberName];
                    const memberValue = member.apply(instance, memberArgs);
                    if (void 0 === result) {
                        result = memberValue
                    }
                }))
            } else {
                this.each((function() {
                    const instance = componentClass.getInstance(this);
                    if (instance) {
                        instance.option(options)
                    } else {
                        new componentClass(this, options)
                    }
                }));
                result = this
            }
            return result
        }
    };
    _component_registrator_callbacks.default.add(registerJQueryComponent)
}
