/*
 * @license
 * Copyright Endlessjs. All Rights Reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 */
var __decorate = (this && this.__decorate) || function (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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Directive, ElementRef, Input, Output, EventEmitter, } from '@angular/core';
import { skip, takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { ElAdjustment, ElPosition } from '../cdk/overlay/overlay-position';
import { ElTrigger } from '../cdk/overlay/overlay-trigger';
import { ElDynamicOverlay } from '../cdk/overlay/dynamic/dynamic-overlay';
import { ElDynamicOverlayHandler } from '../cdk/overlay/dynamic/dynamic-overlay-handler';
import { ElTooltipComponent } from './tooltip.component';
/**
 *
 * Tooltip directive for small text/icon hints.
 *
 * ### Installation
 *
 * Import `ElTooltipModule` to your feature module.
 * ```ts
 * @NgModule({
 *   imports: [
 *     // ...
 *     ElTooltipModule,
 *   ],
 * })
 * export class PageModule { }
 * ```
 * ### Usage
 *
 * @stacked-example(Showcase, tooltip/tooltip-showcase.component)
 *
 * Tooltip can accept a hint text and/or an icon:
 * @stacked-example(With Icon, tooltip/tooltip-with-icon.component)
 *
 * Same way as Popover, tooltip can accept placement position with `elTooltipPlacement` property:
 * @stacked-example(Placements, tooltip/tooltip-placements.component)
 *
 * It is also possible to specify tooltip color using `elTooltipStatus` property:
 * @stacked-example(Colored Tooltips, tooltip/tooltip-colors.component)
 *
 * Tooltip has a number of triggers which provides an ability to show and hide the component in different ways:
 *
 * - Click mode shows the component when a user clicks on the host element and hides when the user clicks
 * somewhere on the document outside the component.
 * - Hint provides capability to show the component when the user hovers over the host element
 * and hide when the user hovers out of the host.
 * - Hover works like hint mode with one exception - when the user moves mouse from host element to
 * the container element the component remains open, so that it is possible to interact with it content.
 * - Focus mode is applied when user focuses the element.
 * - Noop mode - the component won't react to the user interaction.
 */
var ElTooltipDirective = /** @class */ (function () {
    function ElTooltipDirective(hostRef, dynamicOverlayHandler) {
        this.hostRef = hostRef;
        this.dynamicOverlayHandler = dynamicOverlayHandler;
        this.destroy$ = new Subject();
        this.tooltipComponent = ElTooltipComponent;
        this.offset = 8;
        this.context = {};
        /**
         * Position will be calculated relatively host element based on the position.
         * Can be top, right, bottom, left, start or end.
         */
        this.position = ElPosition.TOP;
        this._adjustment = ElAdjustment.CLOCKWISE;
        this.tooltipClass = '';
        /**
         * Describes when the container will be shown.
         * Available options: `click`, `hover`, `hint`, `focus` and `noop`
         * */
        this.trigger = ElTrigger.HINT;
        this.elTooltipShowStateChange = new EventEmitter();
    }
    Object.defineProperty(ElTooltipDirective.prototype, "adjustment", {
        /**
         * Container position will change automatically based on this strategy if container can't fit view port.
         * Set this property to `noop` value if you want to disable automatic adjustment.
         * Available values: `clockwise` (default), `counterclockwise`, `vertical`, `horizontal`, `noop`.
         */
        get: function () {
            return this._adjustment;
        },
        set: function (value) {
            if (!value) {
                // @breaking-change Remove @5.0.0
                console.warn("Falsy values for 'elPopoverAdjustment' are deprecated and will be removed in Endlessjs 5.\n Use 'noop' instead.");
                value = ElAdjustment.NOOP;
            }
            this._adjustment = value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ElTooltipDirective.prototype, "icon", {
        /**
         * Accepts icon name or icon config object
         * @param {string | ElIconConfig} icon name or config object
         */
        set: function (icon) {
            this.context = Object.assign(this.context, { icon: icon });
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ElTooltipDirective.prototype, "status", {
        /**
         *
         * @param {string} status
         */
        set: function (status) {
            this.context = Object.assign(this.context, { status: status });
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ElTooltipDirective.prototype, "isShown", {
        get: function () {
            return !!(this.dynamicOverlay && this.dynamicOverlay.isAttached);
        },
        enumerable: true,
        configurable: true
    });
    ElTooltipDirective.prototype.ngOnInit = function () {
        this.dynamicOverlayHandler
            .host(this.hostRef)
            .componentType(this.tooltipComponent)
            .offset(this.offset);
    };
    ElTooltipDirective.prototype.ngOnChanges = function () {
        this.rebuild();
    };
    ElTooltipDirective.prototype.ngAfterViewInit = function () {
        var _this = this;
        this.dynamicOverlay = this.configureDynamicOverlay()
            .build();
        this.dynamicOverlay.isShown
            .pipe(skip(1), takeUntil(this.destroy$))
            .subscribe(function (isShown) { return _this.elTooltipShowStateChange.emit({ isShown: isShown }); });
    };
    ElTooltipDirective.prototype.rebuild = function () {
        this.dynamicOverlay = this.configureDynamicOverlay()
            .rebuild();
    };
    ElTooltipDirective.prototype.show = function () {
        this.dynamicOverlay.show();
    };
    ElTooltipDirective.prototype.hide = function () {
        this.dynamicOverlay.hide();
    };
    ElTooltipDirective.prototype.toggle = function () {
        this.dynamicOverlay.toggle();
    };
    ElTooltipDirective.prototype.ngOnDestroy = function () {
        this.dynamicOverlayHandler.destroy();
        this.destroy$.next();
        this.destroy$.complete();
    };
    ElTooltipDirective.prototype.configureDynamicOverlay = function () {
        return this.dynamicOverlayHandler
            .position(this.position)
            .trigger(this.trigger)
            .adjustment(this.adjustment)
            .content(this.content)
            .context(this.context)
            .overlayConfig({ panelClass: this.tooltipClass });
    };
    __decorate([
        Input('elTooltip'),
        __metadata("design:type", String)
    ], ElTooltipDirective.prototype, "content", void 0);
    __decorate([
        Input('elTooltipPlacement'),
        __metadata("design:type", String)
    ], ElTooltipDirective.prototype, "position", void 0);
    __decorate([
        Input('elTooltipAdjustment'),
        __metadata("design:type", String),
        __metadata("design:paramtypes", [String])
    ], ElTooltipDirective.prototype, "adjustment", null);
    __decorate([
        Input('elTooltipClass'),
        __metadata("design:type", String)
    ], ElTooltipDirective.prototype, "tooltipClass", void 0);
    __decorate([
        Input('elTooltipIcon'),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], ElTooltipDirective.prototype, "icon", null);
    __decorate([
        Input('elTooltipStatus'),
        __metadata("design:type", String),
        __metadata("design:paramtypes", [String])
    ], ElTooltipDirective.prototype, "status", null);
    __decorate([
        Input('elTooltipTrigger'),
        __metadata("design:type", String)
    ], ElTooltipDirective.prototype, "trigger", void 0);
    __decorate([
        Output(),
        __metadata("design:type", Object)
    ], ElTooltipDirective.prototype, "elTooltipShowStateChange", void 0);
    ElTooltipDirective = __decorate([
        Directive({
            selector: '[elTooltip]',
            exportAs: 'elTooltip',
            providers: [ElDynamicOverlayHandler, ElDynamicOverlay],
        }),
        __metadata("design:paramtypes", [ElementRef,
            ElDynamicOverlayHandler])
    ], ElTooltipDirective);
    return ElTooltipDirective;
}());
export { ElTooltipDirective };
//# sourceMappingURL=tooltip.directive.js.map