/* *
 *
 *  Popup generator for Stock tools
 *
 *  (c) 2009-2026 Highsoft AS
 *  Author: Sebastian Bochan
 *
 *  Integration of this software requires a license.
 *  - For commercial use, see www.highcharts.com/license
 *  - For non-commercial, see www.highcharts.com/license-eula
 *
 *
 * */
'use strict';
import H from '../../../Core/Globals.js';
var composed = H.composed;
import Popup from './Popup.js';
import { addEvent, pushUnique, wrap } from '../../../Shared/Utilities.js';
/* *
 *
 *  Functions
 *
 * */
/** @internal */
function compose(NavigationBindingsClass, PointerClass) {
    if (pushUnique(composed, 'Popup')) {
        addEvent(NavigationBindingsClass, 'closePopup', onNavigationBindingsClosePopup);
        addEvent(NavigationBindingsClass, 'showPopup', onNavigationBindingsShowPopup);
        wrap(PointerClass.prototype, 'onContainerMouseDown', wrapPointerOnContainerMouserDown);
    }
}
/** @internal */
function onNavigationBindingsClosePopup() {
    if (this.popup) {
        this.popup.closePopup();
    }
}
/** @internal */
function onNavigationBindingsShowPopup(config) {
    if (!this.popup) {
        // Add popup to main container
        this.popup = new Popup(this.chart.container, (this.chart.options.navigation.iconsURL ||
            (this.chart.options.stockTools &&
                this.chart.options.stockTools.gui.iconsURL) ||
            'renderer'), this.chart);
    }
    this.popup.showForm(config.formType, this.chart, config.options, config.onSubmit);
}
/**
 * `onContainerMouseDown` blocks internal popup events, due to e.preventDefault.
 * Related issue #4606
 * @internal
 */
function wrapPointerOnContainerMouserDown(proceed, e) {
    // Elements is not in popup
    if (!this.inClass(e.target, 'highcharts-popup')) {
        proceed.apply(this, Array.prototype.slice.call(arguments, 1));
    }
}
/* *
 *
 *  Default Export
 *
 * */
/** @internal */
var PopupComposition = {
    compose: compose
};
/** @internal */
export default PopupComposition;
