(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/operators'), require('mt-ngx-bootstrap/component-loader'), require('mt-ngx-bootstrap/utils'), require('@angular/animations'), require('mt-ngx-bootstrap/positioning')) :
    typeof define === 'function' && define.amd ? define('mt-ngx-bootstrap/dropdown', ['exports', '@angular/core', 'rxjs/operators', 'mt-ngx-bootstrap/component-loader', 'mt-ngx-bootstrap/utils', '@angular/animations', 'mt-ngx-bootstrap/positioning'], factory) :
    (global = global || self, factory((global['mt-ngx-bootstrap'] = global['mt-ngx-bootstrap'] || {}, global['mt-ngx-bootstrap'].dropdown = {}), global.ng.core, global.rxjs.operators, global.componentLoader, global.utils, global.ng.animations, global.positioning));
}(this, (function (exports, core, operators, componentLoader, utils, animations, positioning) { 'use strict';

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation. All rights reserved.
    Licensed under the Apache License, Version 2.0 (the "License"); you may not use
    this file except in compliance with the License. You may obtain a copy of the
    License at http://www.apache.org/licenses/LICENSE-2.0

    THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
    WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
    MERCHANTABLITY OR NON-INFRINGEMENT.

    See the Apache Version 2.0 License for specific language governing permissions
    and limitations under the License.
    ***************************************************************************** */
    /* global Reflect, Promise */

    var extendStatics = function(d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };

    function __extends(d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }

    var __assign = function() {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };

    function __rest(s, e) {
        var t = {};
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
            t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
                t[p[i]] = s[p[i]];
        return t;
    }

    function __decorate(decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    }

    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); }
    }

    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
    }

    function __awaiter(thisArg, _arguments, P, generator) {
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
            function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
            function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }

    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f) throw new TypeError("Generator is already executing.");
            while (_) try {
                if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
                if (y = 0, t) op = [op[0] & 2, t.value];
                switch (op[0]) {
                    case 0: case 1: t = op; break;
                    case 4: _.label++; return { value: op[1], done: false };
                    case 5: _.label++; y = op[1]; op = [0]; continue;
                    case 7: op = _.ops.pop(); _.trys.pop(); continue;
                    default:
                        if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                        if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                        if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                        if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                        if (t[2]) _.ops.pop();
                        _.trys.pop(); continue;
                }
                op = body.call(thisArg, _);
            } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
            if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
        }
    }

    function __exportStar(m, exports) {
        for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
    }

    function __values(o) {
        var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
        if (m) return m.call(o);
        return {
            next: function () {
                if (o && i >= o.length) o = void 0;
                return { value: o && o[i++], done: !o };
            }
        };
    }

    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m) return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
        }
        catch (error) { e = { error: error }; }
        finally {
            try {
                if (r && !r.done && (m = i["return"])) m.call(i);
            }
            finally { if (e) throw e.error; }
        }
        return ar;
    }

    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }

    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }

    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
    }

    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }

    function __asyncValues(o) {
        if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
    }

    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
        return cooked;
    };

    function __importStar(mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
        result.default = mod;
        return result;
    }

    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }

    /**
     * @fileoverview added by tsickle
     * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /**
     * Default dropdown configuration
     */
    var BsDropdownConfig = /** @class */ (function () {
        function BsDropdownConfig() {
            /**
             * default dropdown auto closing behavior
             */
            this.autoClose = true;
            /**
             * default dropdown auto closing behavior
             */
            this.insideClick = false;
            /**
             * turn on/off animation
             */
            this.isAnimated = false;
        }
        BsDropdownConfig.decorators = [
            { type: core.Injectable }
        ];
        return BsDropdownConfig;
    }());
    if (false) {
        /**
         * default dropdown auto closing behavior
         * @type {?}
         */
        BsDropdownConfig.prototype.autoClose;
        /**
         * default dropdown auto closing behavior
         * @type {?}
         */
        BsDropdownConfig.prototype.insideClick;
        /**
         * turn on/off animation
         * @type {?}
         */
        BsDropdownConfig.prototype.isAnimated;
    }

    /**
     * @fileoverview added by tsickle
     * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    var BsDropdownState = /** @class */ (function () {
        function BsDropdownState() {
            var _this = this;
            this.direction = 'down';
            this.isOpenChange = new core.EventEmitter();
            this.isDisabledChange = new core.EventEmitter();
            this.toggleClick = new core.EventEmitter();
            this.dropdownMenu = new Promise((/**
             * @param {?} resolve
             * @return {?}
             */
            function (resolve) {
                _this.resolveDropdownMenu = resolve;
            }));
        }
        BsDropdownState.decorators = [
            { type: core.Injectable }
        ];
        /** @nocollapse */
        BsDropdownState.ctorParameters = function () { return []; };
        return BsDropdownState;
    }());
    if (false) {
        /** @type {?} */
        BsDropdownState.prototype.direction;
        /** @type {?} */
        BsDropdownState.prototype.autoClose;
        /** @type {?} */
        BsDropdownState.prototype.insideClick;
        /** @type {?} */
        BsDropdownState.prototype.isAnimated;
        /** @type {?} */
        BsDropdownState.prototype.isOpenChange;
        /** @type {?} */
        BsDropdownState.prototype.isDisabledChange;
        /** @type {?} */
        BsDropdownState.prototype.toggleClick;
        /** @type {?} */
        BsDropdownState.prototype.counts;
        /**
         * Content to be displayed as popover.
         * @type {?}
         */
        BsDropdownState.prototype.dropdownMenu;
        /** @type {?} */
        BsDropdownState.prototype.resolveDropdownMenu;
    }

    /**
     * @fileoverview added by tsickle
     * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /** @type {?} */
    var DROPDOWN_ANIMATION_TIMING = '220ms cubic-bezier(0, 0, 0.2, 1)';
    /** @type {?} */
    var dropdownAnimation = [
        animations.style({ height: 0, overflow: 'hidden' }),
        animations.animate(DROPDOWN_ANIMATION_TIMING, animations.style({ height: '*', overflow: 'hidden' }))
    ];

    /**
     * @fileoverview added by tsickle
     * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    var BsDropdownContainerComponent = /** @class */ (function () {
        function BsDropdownContainerComponent(_state, cd, _renderer, _element, _builder) {
            var _this = this;
            this._state = _state;
            this.cd = cd;
            this._renderer = _renderer;
            this._element = _element;
            this.isOpen = false;
            this._factoryDropDownAnimation = _builder.build(dropdownAnimation);
            this._subscription = _state.isOpenChange.subscribe((/**
             * @param {?} value
             * @return {?}
             */
            function (value) {
                _this.isOpen = value;
                /** @type {?} */
                var dropdown = _this._element.nativeElement.querySelector('.dropdown-menu');
                _this._renderer.addClass(_this._element.nativeElement.querySelector('div'), 'open');
                if (dropdown && !utils.isBs3()) {
                    _this._renderer.addClass(dropdown, 'show');
                    if (dropdown.classList.contains('dropdown-menu-right')) {
                        _this._renderer.setStyle(dropdown, 'left', 'auto');
                        _this._renderer.setStyle(dropdown, 'right', '0');
                    }
                    if (_this.direction === 'up') {
                        _this._renderer.setStyle(dropdown, 'top', 'auto');
                        _this._renderer.setStyle(dropdown, 'transform', 'translateY(-101%)');
                    }
                }
                if (dropdown && _this._state.isAnimated) {
                    _this._factoryDropDownAnimation.create(dropdown)
                        .play();
                }
                _this.cd.markForCheck();
                _this.cd.detectChanges();
            }));
        }
        Object.defineProperty(BsDropdownContainerComponent.prototype, "direction", {
            get: /**
             * @return {?}
             */
            function () {
                return this._state.direction;
            },
            enumerable: true,
            configurable: true
        });
        /** @internal */
        /**
         * \@internal
         * @param {?} el
         * @return {?}
         */
        BsDropdownContainerComponent.prototype._contains = /**
         * \@internal
         * @param {?} el
         * @return {?}
         */
        function (el) {
            return this._element.nativeElement.contains(el);
        };
        /**
         * @return {?}
         */
        BsDropdownContainerComponent.prototype.ngOnDestroy = /**
         * @return {?}
         */
        function () {
            this._subscription.unsubscribe();
        };
        BsDropdownContainerComponent.decorators = [
            { type: core.Component, args: [{
                        selector: 'bs-dropdown-container',
                        changeDetection: core.ChangeDetectionStrategy.OnPush,
                        host: {
                            style: 'display:block;position: absolute;z-index: 1040'
                        },
                        template: "\n    <div [class.dropup]=\"direction === 'up'\"\n         [class.dropdown]=\"direction === 'down'\"\n         [class.show]=\"isOpen\"\n         [class.open]=\"isOpen\"><ng-content></ng-content>\n    </div>\n  "
                    }] }
        ];
        /** @nocollapse */
        BsDropdownContainerComponent.ctorParameters = function () { return [
            { type: BsDropdownState },
            { type: core.ChangeDetectorRef },
            { type: core.Renderer2 },
            { type: core.ElementRef },
            { type: animations.AnimationBuilder }
        ]; };
        return BsDropdownContainerComponent;
    }());
    if (false) {
        /** @type {?} */
        BsDropdownContainerComponent.prototype.isOpen;
        /**
         * @type {?}
         * @private
         */
        BsDropdownContainerComponent.prototype._factoryDropDownAnimation;
        /**
         * @type {?}
         * @private
         */
        BsDropdownContainerComponent.prototype._subscription;
        /**
         * @type {?}
         * @private
         */
        BsDropdownContainerComponent.prototype._state;
        /**
         * @type {?}
         * @private
         */
        BsDropdownContainerComponent.prototype.cd;
        /**
         * @type {?}
         * @private
         */
        BsDropdownContainerComponent.prototype._renderer;
        /**
         * @type {?}
         * @private
         */
        BsDropdownContainerComponent.prototype._element;
    }

    /**
     * @fileoverview added by tsickle
     * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    var BsDropdownDirective = /** @class */ (function () {
        function BsDropdownDirective(_elementRef, _renderer, _viewContainerRef, _cis, _state, _config, _builder) {
            this._elementRef = _elementRef;
            this._renderer = _renderer;
            this._viewContainerRef = _viewContainerRef;
            this._cis = _cis;
            this._state = _state;
            this._config = _config;
            // todo: move to component loader
            this._isInlineOpen = false;
            this._subscriptions = [];
            this._isInited = false;
            // set initial dropdown state from config
            this._state.autoClose = this._config.autoClose;
            this._state.insideClick = this._config.insideClick;
            this._state.isAnimated = this._config.isAnimated;
            this._factoryDropDownAnimation = _builder.build(dropdownAnimation);
            // create dropdown component loader
            this._dropdown = this._cis
                .createLoader(this._elementRef, this._viewContainerRef, this._renderer)
                .provide({ provide: BsDropdownState, useValue: this._state });
            this.onShown = this._dropdown.onShown;
            this.onHidden = this._dropdown.onHidden;
            this.isOpenChange = this._state.isOpenChange;
        }
        Object.defineProperty(BsDropdownDirective.prototype, "autoClose", {
            get: /**
             * @return {?}
             */
            function () {
                return this._state.autoClose;
            },
            /**
             * Indicates that dropdown will be closed on item or document click,
             * and after pressing ESC
             */
            set: /**
             * Indicates that dropdown will be closed on item or document click,
             * and after pressing ESC
             * @param {?} value
             * @return {?}
             */
            function (value) {
                this._state.autoClose = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BsDropdownDirective.prototype, "isAnimated", {
            get: /**
             * @return {?}
             */
            function () {
                return this._state.isAnimated;
            },
            /**
             * Indicates that dropdown will be animated
             */
            set: /**
             * Indicates that dropdown will be animated
             * @param {?} value
             * @return {?}
             */
            function (value) {
                this._state.isAnimated = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BsDropdownDirective.prototype, "insideClick", {
            get: /**
             * @return {?}
             */
            function () {
                return this._state.insideClick;
            },
            /**
             * This attribute indicates that the dropdown shouldn't close on inside click when autoClose is set to true
             */
            set: /**
             * This attribute indicates that the dropdown shouldn't close on inside click when autoClose is set to true
             * @param {?} value
             * @return {?}
             */
            function (value) {
                this._state.insideClick = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BsDropdownDirective.prototype, "isDisabled", {
            get: /**
             * @return {?}
             */
            function () {
                return this._isDisabled;
            },
            /**
             * Disables dropdown toggle and hides dropdown menu if opened
             */
            set: /**
             * Disables dropdown toggle and hides dropdown menu if opened
             * @param {?} value
             * @return {?}
             */
            function (value) {
                this._isDisabled = value;
                this._state.isDisabledChange.emit(value);
                if (value) {
                    this.hide();
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BsDropdownDirective.prototype, "isOpen", {
            /**
             * Returns whether or not the popover is currently being shown
             */
            get: /**
             * Returns whether or not the popover is currently being shown
             * @return {?}
             */
            function () {
                if (this._showInline) {
                    return this._isInlineOpen;
                }
                return this._dropdown.isShown;
            },
            set: /**
             * @param {?} value
             * @return {?}
             */
            function (value) {
                if (value) {
                    this.show();
                }
                else {
                    this.hide();
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BsDropdownDirective.prototype, "isBs4", {
            get: /**
             * @return {?}
             */
            function () {
                return !utils.isBs3();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BsDropdownDirective.prototype, "_showInline", {
            get: /**
             * @private
             * @return {?}
             */
            function () {
                return !this.container;
            },
            enumerable: true,
            configurable: true
        });
        /**
         * @return {?}
         */
        BsDropdownDirective.prototype.ngOnInit = /**
         * @return {?}
         */
        function () {
            var _this = this;
            // fix: seems there are an issue with `routerLinkActive`
            // which result in duplicated call ngOnInit without call to ngOnDestroy
            // read more: https://github.com/valor-software/ngx-bootstrap/issues/1885
            if (this._isInited) {
                return;
            }
            this._isInited = true;
            // attach DOM listeners
            this._dropdown.listen({
                // because of dropdown inline mode
                outsideClick: false,
                triggers: this.triggers,
                show: (/**
                 * @return {?}
                 */
                function () { return _this.show(); })
            });
            // toggle visibility on toggle element click
            this._subscriptions.push(this._state.toggleClick.subscribe((/**
             * @param {?} value
             * @return {?}
             */
            function (value) { return _this.toggle(value); })));
            // hide dropdown if set disabled while opened
            this._subscriptions.push(this._state.isDisabledChange
                .pipe(operators.filter((/**
             * @param {?} value
             * @return {?}
             */
            function (value) { return value; })))
                .subscribe((/**
             * @param {?} value
             * @return {?}
             */
            function (value) { return _this.hide(); })));
        };
        /**
         * Opens an element’s popover. This is considered a “manual” triggering of
         * the popover.
         */
        /**
         * Opens an element’s popover. This is considered a “manual” triggering of
         * the popover.
         * @return {?}
         */
        BsDropdownDirective.prototype.show = /**
         * Opens an element’s popover. This is considered a “manual” triggering of
         * the popover.
         * @return {?}
         */
        function () {
            var _this = this;
            if (this.isOpen || this.isDisabled) {
                return;
            }
            if (this._showInline) {
                if (!this._inlinedMenu) {
                    this._state.dropdownMenu.then((/**
                     * @param {?} dropdownMenu
                     * @return {?}
                     */
                    function (dropdownMenu) {
                        _this._dropdown.attachInline(dropdownMenu.viewContainer, dropdownMenu.templateRef);
                        _this._inlinedMenu = _this._dropdown._inlineViewRef;
                        _this.addBs4Polyfills();
                        _this._renderer.addClass(_this._inlinedMenu.rootNodes[0].parentNode, 'open');
                        _this.playAnimation();
                    }))
                        // swallow errors
                        .catch();
                }
                this.addBs4Polyfills();
                this._isInlineOpen = true;
                this.onShown.emit(true);
                this._state.isOpenChange.emit(true);
                this.playAnimation();
                return;
            }
            this._state.dropdownMenu.then((/**
             * @param {?} dropdownMenu
             * @return {?}
             */
            function (dropdownMenu) {
                // check direction in which dropdown should be opened
                /** @type {?} */
                var _dropup = _this.dropup ||
                    (typeof _this.dropup !== 'undefined' && _this.dropup);
                _this._state.direction = _dropup ? 'up' : 'down';
                /** @type {?} */
                var _placement = _this.placement || (_dropup ? 'top start' : 'bottom start');
                // show dropdown
                _this._dropdown
                    .attach(BsDropdownContainerComponent)
                    .to(_this.container)
                    .position({ attachment: _placement })
                    .show({
                    content: dropdownMenu.templateRef,
                    placement: _placement
                });
                _this._state.isOpenChange.emit(true);
            }))
                // swallow error
                .catch();
        };
        /**
         * Closes an element’s popover. This is considered a “manual” triggering of
         * the popover.
         */
        /**
         * Closes an element’s popover. This is considered a “manual” triggering of
         * the popover.
         * @return {?}
         */
        BsDropdownDirective.prototype.hide = /**
         * Closes an element’s popover. This is considered a “manual” triggering of
         * the popover.
         * @return {?}
         */
        function () {
            if (!this.isOpen) {
                return;
            }
            if (this._showInline) {
                this.removeShowClass();
                this.removeDropupStyles();
                this._isInlineOpen = false;
                this.onHidden.emit(true);
            }
            else {
                this._dropdown.hide();
            }
            this._state.isOpenChange.emit(false);
        };
        /**
         * Toggles an element’s popover. This is considered a “manual” triggering of
         * the popover. With parameter <code>true</code> allows toggling, with parameter <code>false</code>
         * only hides opened dropdown. Parameter usage will be removed in ngx-bootstrap v3
         */
        /**
         * Toggles an element’s popover. This is considered a “manual” triggering of
         * the popover. With parameter <code>true</code> allows toggling, with parameter <code>false</code>
         * only hides opened dropdown. Parameter usage will be removed in ngx-bootstrap v3
         * @param {?=} value
         * @return {?}
         */
        BsDropdownDirective.prototype.toggle = /**
         * Toggles an element’s popover. This is considered a “manual” triggering of
         * the popover. With parameter <code>true</code> allows toggling, with parameter <code>false</code>
         * only hides opened dropdown. Parameter usage will be removed in ngx-bootstrap v3
         * @param {?=} value
         * @return {?}
         */
        function (value) {
            if (this.isOpen || !value) {
                return this.hide();
            }
            return this.show();
        };
        /** @internal */
        /**
         * \@internal
         * @param {?} event
         * @return {?}
         */
        BsDropdownDirective.prototype._contains = /**
         * \@internal
         * @param {?} event
         * @return {?}
         */
        function (event) {
            return this._elementRef.nativeElement.contains(event.target) ||
                (this._dropdown.instance && this._dropdown.instance._contains(event.target));
        };
        /**
         * @return {?}
         */
        BsDropdownDirective.prototype.ngOnDestroy = /**
         * @return {?}
         */
        function () {
            var e_1, _a;
            try {
                // clean up subscriptions and destroy dropdown
                for (var _b = __values(this._subscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var sub = _c.value;
                    sub.unsubscribe();
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_1) throw e_1.error; }
            }
            this._dropdown.dispose();
        };
        /**
         * @param {?} event
         * @return {?}
         */
        BsDropdownDirective.prototype.navigationClick = /**
         * @param {?} event
         * @return {?}
         */
        function (event) {
            /** @type {?} */
            var ref = this._elementRef.nativeElement.querySelector('.dropdown-menu');
            if (!ref) {
                return;
            }
            /** @type {?} */
            var firstActive = this._elementRef.nativeElement.ownerDocument.activeElement;
            console.log(firstActive);
            /** @type {?} */
            var allRef = ref.querySelectorAll('.dropdown-item');
            switch (event.keyCode) {
                case 38:
                    // arriba
                    if (this._state.counts > 0) {
                        allRef[--this._state.counts].focus();
                    }
                    break;
                case 40:
                    // abajo
                    if (this._state.counts + 1 < allRef.length) {
                        if (firstActive.classList !== allRef[this._state.counts].classList) {
                            allRef[this._state.counts].focus();
                        }
                        else {
                            allRef[++this._state.counts].focus();
                        }
                    }
                    break;
                default:
            }
            event.preventDefault();
        };
        /**
         * @private
         * @return {?}
         */
        BsDropdownDirective.prototype.addBs4Polyfills = /**
         * @private
         * @return {?}
         */
        function () {
            if (!utils.isBs3()) {
                this.addShowClass();
                this.checkRightAlignment();
                this.addDropupStyles();
            }
        };
        /**
         * @private
         * @return {?}
         */
        BsDropdownDirective.prototype.playAnimation = /**
         * @private
         * @return {?}
         */
        function () {
            if (this._state.isAnimated && this._inlinedMenu) {
                this._factoryDropDownAnimation.create(this._inlinedMenu.rootNodes[0])
                    .play();
            }
        };
        /**
         * @private
         * @return {?}
         */
        BsDropdownDirective.prototype.addShowClass = /**
         * @private
         * @return {?}
         */
        function () {
            if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
                this._renderer.addClass(this._inlinedMenu.rootNodes[0], 'show');
            }
        };
        /**
         * @private
         * @return {?}
         */
        BsDropdownDirective.prototype.removeShowClass = /**
         * @private
         * @return {?}
         */
        function () {
            if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
                this._renderer.removeClass(this._inlinedMenu.rootNodes[0], 'show');
            }
        };
        /**
         * @private
         * @return {?}
         */
        BsDropdownDirective.prototype.checkRightAlignment = /**
         * @private
         * @return {?}
         */
        function () {
            if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
                /** @type {?} */
                var isRightAligned = this._inlinedMenu.rootNodes[0].classList.contains('dropdown-menu-right');
                this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'left', isRightAligned ? 'auto' : '0');
                this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'right', isRightAligned ? '0' : 'auto');
            }
        };
        /**
         * @private
         * @return {?}
         */
        BsDropdownDirective.prototype.addDropupStyles = /**
         * @private
         * @return {?}
         */
        function () {
            if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
                // a little hack to not break support of bootstrap 4 beta
                this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'top', this.dropup ? 'auto' : '100%');
                this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'transform', this.dropup ? 'translateY(-101%)' : 'translateY(0)');
                this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'bottom', 'auto');
            }
        };
        /**
         * @private
         * @return {?}
         */
        BsDropdownDirective.prototype.removeDropupStyles = /**
         * @private
         * @return {?}
         */
        function () {
            if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
                this._renderer.removeStyle(this._inlinedMenu.rootNodes[0], 'top');
                this._renderer.removeStyle(this._inlinedMenu.rootNodes[0], 'transform');
                this._renderer.removeStyle(this._inlinedMenu.rootNodes[0], 'bottom');
            }
        };
        BsDropdownDirective.decorators = [
            { type: core.Directive, args: [{
                        selector: '[bsDropdown],[dropdown]',
                        exportAs: 'bs-dropdown',
                        providers: [BsDropdownState],
                        host: {
                            '[class.dropup]': 'dropup',
                            '[class.open]': 'isOpen',
                            '[class.show]': 'isOpen && isBs4'
                        }
                    },] }
        ];
        /** @nocollapse */
        BsDropdownDirective.ctorParameters = function () { return [
            { type: core.ElementRef },
            { type: core.Renderer2 },
            { type: core.ViewContainerRef },
            { type: componentLoader.ComponentLoaderFactory },
            { type: BsDropdownState },
            { type: BsDropdownConfig },
            { type: animations.AnimationBuilder }
        ]; };
        BsDropdownDirective.propDecorators = {
            placement: [{ type: core.Input }],
            triggers: [{ type: core.Input }],
            container: [{ type: core.Input }],
            dropup: [{ type: core.Input }],
            autoClose: [{ type: core.Input }],
            isAnimated: [{ type: core.Input }],
            insideClick: [{ type: core.Input }],
            isDisabled: [{ type: core.Input }],
            isOpen: [{ type: core.Input }],
            isOpenChange: [{ type: core.Output }],
            onShown: [{ type: core.Output }],
            onHidden: [{ type: core.Output }],
            navigationClick: [{ type: core.HostListener, args: ['keydown.arrowDown', ['$event'],] }, { type: core.HostListener, args: ['keydown.arrowUp', ['$event'],] }]
        };
        return BsDropdownDirective;
    }());
    if (false) {
        /**
         * Placement of a popover. Accepts: "top", "bottom", "left", "right"
         * @type {?}
         */
        BsDropdownDirective.prototype.placement;
        /**
         * Specifies events that should trigger. Supports a space separated list of
         * event names.
         * @type {?}
         */
        BsDropdownDirective.prototype.triggers;
        /**
         * A selector specifying the element the popover should be appended to.
         * @type {?}
         */
        BsDropdownDirective.prototype.container;
        /**
         * This attribute indicates that the dropdown should be opened upwards
         * @type {?}
         */
        BsDropdownDirective.prototype.dropup;
        /**
         * Emits an event when isOpen change
         * @type {?}
         */
        BsDropdownDirective.prototype.isOpenChange;
        /**
         * Emits an event when the popover is shown
         * @type {?}
         */
        BsDropdownDirective.prototype.onShown;
        /**
         * Emits an event when the popover is hidden
         * @type {?}
         */
        BsDropdownDirective.prototype.onHidden;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._dropdown;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._isInlineOpen;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._inlinedMenu;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._isDisabled;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._subscriptions;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._isInited;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._factoryDropDownAnimation;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._elementRef;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._renderer;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._viewContainerRef;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._cis;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._state;
        /**
         * @type {?}
         * @private
         */
        BsDropdownDirective.prototype._config;
    }

    /**
     * @fileoverview added by tsickle
     * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    var BsDropdownMenuDirective = /** @class */ (function () {
        // tslint:disable:no-any
        function BsDropdownMenuDirective(_state, _viewContainer, _templateRef) {
            _state.resolveDropdownMenu({
                templateRef: _templateRef,
                viewContainer: _viewContainer
            });
        }
        BsDropdownMenuDirective.decorators = [
            { type: core.Directive, args: [{
                        selector: '[bsDropdownMenu],[dropdownMenu]',
                        exportAs: 'bs-dropdown-menu'
                    },] }
        ];
        /** @nocollapse */
        BsDropdownMenuDirective.ctorParameters = function () { return [
            { type: BsDropdownState },
            { type: core.ViewContainerRef },
            { type: core.TemplateRef }
        ]; };
        return BsDropdownMenuDirective;
    }());

    /**
     * @fileoverview added by tsickle
     * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    var BsDropdownToggleDirective = /** @class */ (function () {
        function BsDropdownToggleDirective(_changeDetectorRef, _dropdown, _element, _renderer, _state) {
            var _this = this;
            this._changeDetectorRef = _changeDetectorRef;
            this._dropdown = _dropdown;
            this._element = _element;
            this._renderer = _renderer;
            this._state = _state;
            this.isDisabled = null;
            this._subscriptions = [];
            // sync is open value with state
            this._subscriptions.push(this._state.isOpenChange.subscribe((/**
             * @param {?} value
             * @return {?}
             */
            function (value) {
                _this.isOpen = value;
                if (value) {
                    _this._documentClickListener = _this._renderer.listen('document', 'click', (/**
                     * @param {?} event
                     * @return {?}
                     */
                    function (event) {
                        if (_this._state.autoClose && event.button !== 2 &&
                            !_this._element.nativeElement.contains(event.target) &&
                            !(_this._state.insideClick && _this._dropdown._contains(event))) {
                            _this._state.toggleClick.emit(false);
                            _this._changeDetectorRef.detectChanges();
                        }
                    }));
                    _this._escKeyUpListener = _this._renderer.listen(_this._element.nativeElement, 'keyup.esc', (/**
                     * @return {?}
                     */
                    function () {
                        if (_this._state.autoClose) {
                            _this._state.toggleClick.emit(false);
                            _this._changeDetectorRef.detectChanges();
                        }
                    }));
                }
                else {
                    _this._documentClickListener();
                    _this._escKeyUpListener();
                }
            })));
            // populate disabled state
            this._subscriptions.push(this._state.isDisabledChange.subscribe((/**
             * @param {?} value
             * @return {?}
             */
            function (value) { return (_this.isDisabled = value || null); })));
        }
        /**
         * @return {?}
         */
        BsDropdownToggleDirective.prototype.onClick = /**
         * @return {?}
         */
        function () {
            this._state.counts = 0;
            if (this.isDisabled) {
                return;
            }
            this._state.toggleClick.emit(true);
        };
        /**
         * @return {?}
         */
        BsDropdownToggleDirective.prototype.ngOnDestroy = /**
         * @return {?}
         */
        function () {
            var e_1, _a;
            if (this._documentClickListener) {
                this._documentClickListener();
            }
            if (this._escKeyUpListener) {
                this._escKeyUpListener();
            }
            try {
                for (var _b = __values(this._subscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var sub = _c.value;
                    sub.unsubscribe();
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_1) throw e_1.error; }
            }
        };
        BsDropdownToggleDirective.decorators = [
            { type: core.Directive, args: [{
                        selector: '[bsDropdownToggle],[dropdownToggle]',
                        exportAs: 'bs-dropdown-toggle',
                        host: {
                            '[attr.aria-haspopup]': 'true'
                        }
                    },] }
        ];
        /** @nocollapse */
        BsDropdownToggleDirective.ctorParameters = function () { return [
            { type: core.ChangeDetectorRef },
            { type: BsDropdownDirective },
            { type: core.ElementRef },
            { type: core.Renderer2 },
            { type: BsDropdownState }
        ]; };
        BsDropdownToggleDirective.propDecorators = {
            isDisabled: [{ type: core.HostBinding, args: ['attr.disabled',] }],
            isOpen: [{ type: core.HostBinding, args: ['attr.aria-expanded',] }],
            onClick: [{ type: core.HostListener, args: ['click', [],] }]
        };
        return BsDropdownToggleDirective;
    }());
    if (false) {
        /** @type {?} */
        BsDropdownToggleDirective.prototype.isDisabled;
        /** @type {?} */
        BsDropdownToggleDirective.prototype.isOpen;
        /**
         * @type {?}
         * @private
         */
        BsDropdownToggleDirective.prototype._subscriptions;
        /**
         * @type {?}
         * @private
         */
        BsDropdownToggleDirective.prototype._documentClickListener;
        /**
         * @type {?}
         * @private
         */
        BsDropdownToggleDirective.prototype._escKeyUpListener;
        /**
         * @type {?}
         * @private
         */
        BsDropdownToggleDirective.prototype._changeDetectorRef;
        /**
         * @type {?}
         * @private
         */
        BsDropdownToggleDirective.prototype._dropdown;
        /**
         * @type {?}
         * @private
         */
        BsDropdownToggleDirective.prototype._element;
        /**
         * @type {?}
         * @private
         */
        BsDropdownToggleDirective.prototype._renderer;
        /**
         * @type {?}
         * @private
         */
        BsDropdownToggleDirective.prototype._state;
    }

    /**
     * @fileoverview added by tsickle
     * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    var BsDropdownModule = /** @class */ (function () {
        function BsDropdownModule() {
        }
        // tslint:disable-next-line:no-any
        // tslint:disable-next-line:no-any
        /**
         * @param {?=} config
         * @return {?}
         */
        BsDropdownModule.forRoot = 
        // tslint:disable-next-line:no-any
        /**
         * @param {?=} config
         * @return {?}
         */
        function (config) {
            return {
                ngModule: BsDropdownModule,
                providers: [
                    componentLoader.ComponentLoaderFactory,
                    positioning.PositioningService,
                    BsDropdownState,
                    {
                        provide: BsDropdownConfig,
                        useValue: config ? config : { autoClose: true, insideClick: false }
                    }
                ]
            };
        };
        BsDropdownModule.decorators = [
            { type: core.NgModule, args: [{
                        declarations: [
                            BsDropdownMenuDirective,
                            BsDropdownToggleDirective,
                            BsDropdownContainerComponent,
                            BsDropdownDirective
                        ],
                        exports: [
                            BsDropdownMenuDirective,
                            BsDropdownToggleDirective,
                            BsDropdownDirective
                        ],
                        entryComponents: [BsDropdownContainerComponent]
                    },] }
        ];
        return BsDropdownModule;
    }());

    exports.BsDropdownConfig = BsDropdownConfig;
    exports.BsDropdownContainerComponent = BsDropdownContainerComponent;
    exports.BsDropdownDirective = BsDropdownDirective;
    exports.BsDropdownMenuDirective = BsDropdownMenuDirective;
    exports.BsDropdownModule = BsDropdownModule;
    exports.BsDropdownState = BsDropdownState;
    exports.BsDropdownToggleDirective = BsDropdownToggleDirective;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=mt-ngx-bootstrap-dropdown.umd.js.map
