/**
 * DevExtreme (cjs/events/short.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.visibility = exports.resize = exports.keyboard = exports.hover = exports.focus = exports.dxClick = exports.click = exports.active = void 0;
var _events_engine = _interopRequireDefault(require("./core/events_engine"));
var _keyboard_processor = _interopRequireDefault(require("./core/keyboard_processor"));
var _index = require("./utils/index");

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}

function addNamespace(event, namespace) {
    return namespace ? (0, _index.addNamespace)(event, namespace) : event
}

function executeAction(action, args) {
    return "function" === typeof action ? action(args) : action.execute(args)
}
const active = {
    on: ($el, active, inactive, opts) => {
        const {
            selector: selector,
            showTimeout: showTimeout,
            hideTimeout: hideTimeout,
            namespace: namespace
        } = opts;
        _events_engine.default.on($el, addNamespace("dxactive", namespace), selector, {
            timeout: showTimeout
        }, event => executeAction(active, {
            event: event,
            element: event.currentTarget
        }));
        _events_engine.default.on($el, addNamespace("dxinactive", namespace), selector, {
            timeout: hideTimeout
        }, event => executeAction(inactive, {
            event: event,
            element: event.currentTarget
        }))
    },
    off: ($el, _ref) => {
        let {
            namespace: namespace,
            selector: selector
        } = _ref;
        _events_engine.default.off($el, addNamespace("dxactive", namespace), selector);
        _events_engine.default.off($el, addNamespace("dxinactive", namespace), selector)
    }
};
exports.active = active;
const resize = {
    on: function($el, resize) {
        let {
            namespace: namespace
        } = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
        _events_engine.default.on($el, addNamespace("dxresize", namespace), resize)
    },
    off: function($el) {
        let {
            namespace: namespace
        } = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
        _events_engine.default.off($el, addNamespace("dxresize", namespace))
    }
};
exports.resize = resize;
const hover = {
    on: ($el, start, end, _ref2) => {
        let {
            selector: selector,
            namespace: namespace
        } = _ref2;
        _events_engine.default.on($el, addNamespace("dxhoverend", namespace), selector, event => end(event));
        _events_engine.default.on($el, addNamespace("dxhoverstart", namespace), selector, event => executeAction(start, {
            element: event.target,
            event: event
        }))
    },
    off: ($el, _ref3) => {
        let {
            selector: selector,
            namespace: namespace
        } = _ref3;
        _events_engine.default.off($el, addNamespace("dxhoverstart", namespace), selector);
        _events_engine.default.off($el, addNamespace("dxhoverend", namespace), selector)
    }
};
exports.hover = hover;
const visibility = {
    on: ($el, shown, hiding, _ref4) => {
        let {
            namespace: namespace
        } = _ref4;
        _events_engine.default.on($el, addNamespace("dxhiding", namespace), hiding);
        _events_engine.default.on($el, addNamespace("dxshown", namespace), shown)
    },
    off: ($el, _ref5) => {
        let {
            namespace: namespace
        } = _ref5;
        _events_engine.default.off($el, addNamespace("dxhiding", namespace));
        _events_engine.default.off($el, addNamespace("dxshown", namespace))
    }
};
exports.visibility = visibility;
const focus = {
    on: ($el, focusIn, focusOut, _ref6) => {
        let {
            namespace: namespace
        } = _ref6;
        _events_engine.default.on($el, addNamespace("focusin", namespace), focusIn);
        _events_engine.default.on($el, addNamespace("focusout", namespace), focusOut)
    },
    off: ($el, _ref7) => {
        let {
            namespace: namespace
        } = _ref7;
        _events_engine.default.off($el, addNamespace("focusin", namespace));
        _events_engine.default.off($el, addNamespace("focusout", namespace))
    },
    trigger: $el => _events_engine.default.trigger($el, "focus")
};
exports.focus = focus;
const dxClick = {
    on: function($el, click) {
        let {
            namespace: namespace
        } = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
        _events_engine.default.on($el, addNamespace("dxclick", namespace), click)
    },
    off: function($el) {
        let {
            namespace: namespace
        } = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
        _events_engine.default.off($el, addNamespace("dxclick", namespace))
    }
};
exports.dxClick = dxClick;
const click = {
    on: function($el, click) {
        let {
            namespace: namespace
        } = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
        _events_engine.default.on($el, addNamespace("click", namespace), click)
    },
    off: function($el) {
        let {
            namespace: namespace
        } = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
        _events_engine.default.off($el, addNamespace("click", namespace))
    }
};
exports.click = click;
let index = 0;
const keyboardProcessors = {};
const generateListenerId = () => "keyboardProcessorId".concat(index++);
const keyboard = {
    on: (element, focusTarget, handler) => {
        const listenerId = "keyboardProcessorId".concat(index++);
        keyboardProcessors[listenerId] = new _keyboard_processor.default({
            element: element,
            focusTarget: focusTarget,
            handler: handler
        });
        return listenerId
    },
    off: listenerId => {
        if (listenerId && keyboardProcessors[listenerId]) {
            keyboardProcessors[listenerId].dispose();
            delete keyboardProcessors[listenerId]
        }
    },
    _getProcessor: listenerId => keyboardProcessors[listenerId]
};
exports.keyboard = keyboard;
