import { CdkTrapFocus } from '@angular/cdk/a11y';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { Overlay } from '@angular/cdk/overlay';
import { ChangeDetectionStrategy, Component, Directive, ElementRef, EventEmitter, InjectionToken, Input, Output, ViewChild, ViewEncapsulation, booleanAttribute, inject, numberAttribute } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { KbqComponentColors, KbqPopUp, KbqPopUpTrigger, POSITION_TO_CSS_MAP, PopUpPlacements, PopUpSizes, PopUpTriggers, applyPopupMargins } from '@koobiq/components/core';
import { NEVER, fromEvent, merge } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { kbqPopoverAnimations } from './popover-animations';
import * as i0 from "@angular/core";
import * as i1 from "@koobiq/components/button";
import * as i2 from "@angular/cdk/a11y";
import * as i3 from "@koobiq/components/icon";
import * as i4 from "@angular/cdk/observers";
import * as i5 from "@angular/common";
export const defaultOffsetYWithArrow = 8;
export class KbqPopoverComponent extends KbqPopUp {
    constructor() {
        super(...arguments);
        this.prefix = 'kbq-popover';
        this.isTrapFocus = false;
        this.hasCloseButton = false;
        this.debounceTime = 15;
        this.isContentTopOverflow = false;
        this.isContentBottomOverflow = false;
        this.componentColors = KbqComponentColors;
    }
    ngAfterViewInit() {
        if (!this.popoverContent)
            return;
        this.checkContentOverflow(this.popoverContent.nativeElement);
        fromEvent(this.popoverContent.nativeElement, 'scroll')
            .pipe(debounceTime(this.debounceTime), takeUntilDestroyed(this.destroyRef))
            .subscribe((event) => {
            this.checkContentOverflow(event.target);
        });
        this.cdkTrapFocus.focusTrap.focusFirstTabbableElement();
        this.visibleChange.subscribe((state) => {
            if (this.offset !== null && state) {
                applyPopupMargins(this.renderer, this.elementRef.nativeElement, this.prefix, `${this.offset.toString()}px`);
            }
        });
    }
    onContentChange() {
        this.checkContentOverflow(this.popoverContent.nativeElement);
    }
    checkContentOverflow(contentElement) {
        const { scrollTop, offsetHeight, scrollHeight } = contentElement;
        this.isContentTopOverflow = scrollTop > 0;
        this.isContentBottomOverflow = scrollTop + offsetHeight < scrollHeight;
        super.detectChanges();
    }
    updateClassMap(placement, customClass, size) {
        super.updateClassMap(placement, customClass, { [`${this.prefix}_${size}`]: !!size });
    }
    updateTrapFocus(isTrapFocus) {
        this.isTrapFocus = isTrapFocus;
    }
    onEscape() {
        this.hide(0);
        this.trigger.focus();
    }
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqPopoverComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    /** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: KbqPopoverComponent, selector: "kbq-popover-component", host: { listeners: { "keydown.esc": "onEscape()" } }, viewQueries: [{ propertyName: "popoverContent", first: true, predicate: ["popoverContent"], descendants: true }, { propertyName: "elementRef", first: true, predicate: ["popover"], descendants: true }, { propertyName: "cdkTrapFocus", first: true, predicate: CdkTrapFocus, descendants: true }], usesInheritance: true, ngImport: i0, template: "<div\n    #popover\n    class=\"kbq-popover\"\n    [class.kbq-popover_arrowless]=\"!arrow\"\n    [cdkTrapFocus]=\"isTrapFocus\"\n    [ngClass]=\"classMap\"\n    [@state]=\"visibility\"\n    (@state.done)=\"animationDone($event)\"\n    (@state.start)=\"animationStart()\"\n>\n    <div\n        class=\"kbq-popover__container\"\n        [class.kbq-popover__container_with-footer]=\"footer\"\n        [class.kbq-popover__container_with-header]=\"header\"\n    >\n        @if (header) {\n            <div\n                class=\"kbq-popover__header\"\n                [class.kbq-popover__header_default-paddings]=\"defaultPaddings\"\n                [class.kbq-popover__header_top-overflow]=\"isContentTopOverflow\"\n                [class.kbq-popover__header_with-close-button]=\"hasCloseButton\"\n            >\n                @if (isTemplateRef(header)) {\n                    <ng-container [ngTemplateOutlet]=\"$any(header)\" [ngTemplateOutletContext]=\"context\" />\n                }\n                @if (!isTemplateRef(header)) {\n                    <div class=\"kbq-popover__header-text\">{{ header }}</div>\n                }\n            </div>\n        }\n\n        @if (content) {\n            <div\n                #popoverContent\n                class=\"kbq-popover__content kbq-scrollbar\"\n                [class.kbq-popover__content_default-paddings]=\"defaultPaddings\"\n                (cdkObserveContent)=\"onContentChange()\"\n            >\n                @if (hasCloseButton && !header) {\n                    <div class=\"kbq-popover__close-container\">\n                        <ng-container [ngTemplateOutlet]=\"closeButton\" />\n                    </div>\n                }\n                @if (isTemplateRef(content)) {\n                    <ng-container [ngTemplateOutlet]=\"$any(content)\" [ngTemplateOutletContext]=\"context\" />\n                }\n                @if (!isTemplateRef(content)) {\n                    <div>{{ content }}</div>\n                }\n            </div>\n        }\n\n        @if (footer) {\n            <div\n                class=\"kbq-popover__footer\"\n                [class.kbq-popover__footer_default-paddings]=\"defaultPaddings\"\n                [class.kbq-popover__footer_bottom-overflow]=\"isContentBottomOverflow\"\n            >\n                @if (isTemplateRef(footer)) {\n                    <ng-container [ngTemplateOutlet]=\"$any(footer)\" [ngTemplateOutletContext]=\"context\" />\n                }\n                @if (!isTemplateRef(footer)) {\n                    <div>{{ footer }}</div>\n                }\n            </div>\n        }\n    </div>\n\n    @if (hasCloseButton && header) {\n        <div class=\"kbq-popover__close-container\">\n            <ng-container [ngTemplateOutlet]=\"closeButton\" />\n        </div>\n    }\n\n    <ng-template #closeButton>\n        <div class=\"kbq-popover__close\">\n            <button kbq-button class=\"kbq-button_transparent\" [color]=\"componentColors.Contrast\" (click)=\"hide(0)\">\n                <i kbq-icon=\"kbq-xmark_16\" [color]=\"componentColors.Contrast\"></i>\n            </button>\n        </div>\n    </ng-template>\n\n    @if (arrow) {\n        <div class=\"kbq-popover__arrow\"></div>\n    }\n</div>\n", styles: ["@keyframes kbq-progress{0%{background-position:0 0}to{background-position:64px 0}}.kbq-progress{position:relative}.kbq-progress:after{content:\"\";position:absolute;border-radius:inherit;inset:0;background:linear-gradient(135deg,#0000000a 12px,#ffffff1a 12px 22px,#0000000a 22px 34px,#ffffff1a 34px) repeat;background-size:32px 32px;animation:kbq-progress 1s linear infinite}.kbq-group{display:flex;flex-direction:row}.kbq-group .kbq-group_justified>.kbq-group-item{width:100%}.kbq-group .kbq-group-item+.kbq-group-item{margin-left:calc(-1 * var(--kbq-size-border-width))}.kbq-group>.kbq-group-item:first-child:not(:last-child){border-bottom-right-radius:0;border-top-right-radius:0}.kbq-group>.kbq-group-item:first-child:not(:last-child)>.kbq-form-field__container{border-bottom-right-radius:0;border-top-right-radius:0}.kbq-group>.kbq-group-item:last-child:not(:first-child){border-bottom-left-radius:0;border-top-left-radius:0}.kbq-group>.kbq-group-item:last-child:not(:first-child)>.kbq-form-field__container{border-bottom-left-radius:0;border-top-left-radius:0}.kbq-group>.kbq-group-item:not(:first-child):not(:last-child){border-radius:0}.kbq-group>.kbq-group-item:not(:first-child):not(:last-child)>.kbq-form-field__container{border-radius:0}.kbq-vertical-group{display:flex;flex-direction:column}.kbq-vertical-group>.kbq-group-item:first-child:not(:last-child){border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-right-radius:var(--kbq-size-border-radius)}.kbq-vertical-group>.kbq-group-item:first-child:not(:last-child)>.kbq-form-field__container{border-bottom-right-radius:0;border-bottom-left-radius:0}.kbq-vertical-group>.kbq-group-item:last-child:not(:first-child){border-top-right-radius:0;border-top-left-radius:0;border-bottom-left-radius:var(--kbq-size-border-radius)}.kbq-vertical-group>.kbq-group-item:last-child:not(:first-child)>.kbq-form-field__container{border-top-right-radius:0;border-top-left-radius:0}.kbq-vertical-group>.kbq-group-item:not(:first-child):not(:last-child){border-radius:0}.kbq-vertical-group>.kbq-group-item:not(:first-child):not(:last-child)>.kbq-form-field__container{border-radius:0}.kbq-vertical-group .kbq-group-item+.kbq-group-item{margin-top:calc(-1 * var(--kbq-size-border-width))}.kbq-truncate-line{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.kbq-no-select{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.kbq-popover{position:relative;border-radius:var(--kbq-popover-size-container-border-radius);box-sizing:border-box;list-style:none;white-space:pre-line;z-index:1}.kbq-popover.kbq-popover_small{max-width:var(--kbq-popover-size-container-width-small)}.kbq-popover.kbq-popover_small .kbq-popover__content{padding:var(--kbq-size-l)}.kbq-popover.kbq-popover_medium{max-width:var(--kbq-popover-size-container-width-medium)}.kbq-popover.kbq-popover_large{max-width:var(--kbq-popover-size-container-width-large)}.kbq-popover.kbq-popover_placement-top,.kbq-popover.kbq-popover_placement-top-left,.kbq-popover.kbq-popover_placement-top-right{margin-bottom:8px}.kbq-popover.kbq-popover_placement-right,.kbq-popover.kbq-popover_placement-right-top,.kbq-popover.kbq-popover_placement-right-bottom{margin-left:8px}.kbq-popover.kbq-popover_placement-bottom,.kbq-popover.kbq-popover_placement-bottom-left,.kbq-popover.kbq-popover_placement-bottom-right{margin-top:8px}.kbq-popover.kbq-popover_placement-left,.kbq-popover.kbq-popover_placement-left-top,.kbq-popover.kbq-popover_placement-left-bottom{margin-right:8px}.kbq-popover__content{overflow-y:auto}.kbq-popover__content.kbq-popover__content_default-paddings{padding:var(--kbq-popover-size-content-padding-top) var(--kbq-popover-size-content-padding-horizontal) var(--kbq-popover-size-content-padding-bottom)}.kbq-popover__container{overflow:hidden;display:flex;flex-direction:column;max-height:var(--kbq-popover-size-container-max-height);border-radius:var(--kbq-popover-size-container-border-radius)}.kbq-popover__container.kbq-popover__container_with-header .kbq-popover__content{padding-top:var(--kbq-size-s)}.kbq-popover__container.kbq-popover__container_with-footer .kbq-popover__content_default-paddings.kbq-popover__content{padding-bottom:var(--kbq-size-s)}.kbq-popover__content .kbq-popover__close-container{display:flex;justify-content:flex-end;height:0}.kbq-popover__content .kbq-popover__close-container .kbq-popover__close{top:auto;right:auto;transform:translateY(-50%) translate(50%)}.kbq-popover__header{display:flex;align-items:center;overflow:hidden}.kbq-popover__header .kbq-popover__header-text{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.kbq-popover__header.kbq-popover__header_default-paddings{padding:var(--kbq-popover-size-header-padding-top) var(--kbq-popover-size-header-padding-horizontal) var(--kbq-popover-size-header-padding-bottom) var(--kbq-popover-size-header-padding-horizontal)}.kbq-popover__header_top-overflow{position:relative;z-index:2;box-shadow:var(--kbq-shadow-overflow-normal-bottom)}.kbq-popover__header_with-close-button{padding-right:var(--kbq-size-4xl)}.kbq-popover__footer.kbq-popover__footer_default-paddings{padding:var(--kbq-popover-size-footer-padding-vertical) var(--kbq-popover-size-footer-padding-horizontal)}.kbq-popover__footer_bottom-overflow{position:relative;z-index:2;box-shadow:var(--kbq-shadow-overflow-normal-top)}.kbq-popover__arrow{position:absolute;z-index:-1;width:12px;height:12px;transform:rotate(45deg)}.kbq-popover_placement-top .kbq-popover__arrow{bottom:-5.5px;left:50%;margin-left:-5.5px}.kbq-popover_placement-top-left .kbq-popover__arrow{bottom:-5.5px;left:24px}.kbq-popover_placement-top-right .kbq-popover__arrow{bottom:-5.5px;right:24px}.kbq-popover_placement-right .kbq-popover__arrow{left:-5.5px;top:50%;margin-top:-5.5px}.kbq-popover_placement-right-top .kbq-popover__arrow{left:-5.5px;top:24px}.kbq-popover_placement-right-bottom .kbq-popover__arrow{left:-5.5px;bottom:24px}.kbq-popover_placement-left .kbq-popover__arrow{right:-5.5px;top:50%;margin-top:-5.5px}.kbq-popover_placement-left-top .kbq-popover__arrow{right:-5.5px;top:24px}.kbq-popover_placement-left-bottom .kbq-popover__arrow{right:-5.5px;bottom:24px}.kbq-popover_placement-bottom .kbq-popover__arrow{top:-5.5px;left:50%;margin-left:-5.5px}.kbq-popover_placement-bottom-left .kbq-popover__arrow{top:-5.5px;left:24px}.kbq-popover_placement-bottom-right .kbq-popover__arrow{top:-5.5px;right:24px}.kbq-popover__close{position:absolute;z-index:2;top:var(--kbq-size-s);right:var(--kbq-size-s);border-radius:var(--kbq-size-border-radius)}.kbq-popover{box-shadow:var(--kbq-popover-borderless-shadow)}.kbq-popover.kbq-popover_arrowless{box-shadow:var(--kbq-popover-container-shadow)}.kbq-popover__container{background:var(--kbq-popover-container-background)}.kbq-popover__arrow{box-shadow:var(--kbq-popover-borderless-shadow);background:var(--kbq-popover-container-background)}.kbq-popover__close{background-color:var(--kbq-background-overlay-inverse)}.kbq-popover__header{color:var(--kbq-popover-header-text-color)}.kbq-popover__content{color:var(--kbq-popover-content-text-color)}.kbq-popover__header{font-size:var(--kbq-typography-subheading-font-size);font-style:var(--kbq-typography-subheading-font-style);font-weight:var(--kbq-typography-subheading-font-weight);line-height:var(--kbq-typography-subheading-line-height);font-family:var(--kbq-typography-subheading-font-family);text-transform:var(--kbq-typography-subheading-text-transform);font-feature-settings:var(--kbq-typography-subheading-font-feature-settings);letter-spacing:var(--kbq-typography-subheading-letter-spacing)}.kbq-popover__content{font-size:var(--kbq-typography-text-normal-font-size);font-style:var(--kbq-typography-text-normal-font-style);font-weight:var(--kbq-typography-text-normal-font-weight);line-height:var(--kbq-typography-text-normal-line-height);font-family:var(--kbq-typography-text-normal-font-family);text-transform:var(--kbq-typography-text-normal-text-transform);font-feature-settings:var(--kbq-typography-text-normal-font-feature-settings);letter-spacing:var(--kbq-typography-text-normal-letter-spacing)}\n", ".kbq-popover{--kbq-popover-size-container-width-small: 200px;--kbq-popover-size-container-width-medium: 400px;--kbq-popover-size-container-width-large: 640px;--kbq-popover-size-container-border-radius: var(--kbq-size-m);--kbq-popover-size-container-max-height: 480px;--kbq-popover-size-close-button-width: 32px;--kbq-popover-size-close-button-margin-right: -16px;--kbq-popover-size-close-button-margin-top: -10px;--kbq-popover-size-header-padding-horizontal: var(--kbq-size-xxl);--kbq-popover-size-header-padding-top: var(--kbq-size-l);--kbq-popover-size-header-padding-bottom: var(--kbq-size-xs);--kbq-popover-size-content-padding-top: var(--kbq-size-xxl);--kbq-popover-size-content-padding-bottom: var(--kbq-size-3xl);--kbq-popover-size-content-padding-horizontal: var(--kbq-size-xxl);--kbq-popover-size-content-padding-with-header-top: var(--kbq-size-s);--kbq-popover-size-content-padding-with-footer-bottom: var(--kbq-size-s);--kbq-popover-size-footer-padding-vertical: var(--kbq-size-l);--kbq-popover-size-footer-padding-horizontal: var(--kbq-size-xxl);--kbq-popover-container-background: var(--kbq-background-card);--kbq-popover-container-shadow: var(--kbq-shadow-popup);--kbq-popover-header-text-color: var(--kbq-foreground-contrast);--kbq-popover-header-scroll-shadow: var(--kbq-shadow-overflow-normal-bottom);--kbq-popover-content-text-color: var(--kbq-foreground-contrast);--kbq-popover-footer-scroll-shadow: var(--kbq-shadow-overflow-normal-top);--kbq-popover-borderless-shadow: 0 2px 8px var(--kbq-shadow-key), 0 3px 8px var(--kbq-shadow-ambient)}\n"], dependencies: [{ kind: "component", type: i1.KbqButton, selector: "[kbq-button]", inputs: ["kbqStyle", "disabled", "tabIndex"] }, { kind: "directive", type: i1.KbqButtonCssStyler, selector: "[kbq-button]" }, { kind: "directive", type: i2.CdkTrapFocus, selector: "[cdkTrapFocus]", inputs: ["cdkTrapFocus", "cdkTrapFocusAutoCapture"], exportAs: ["cdkTrapFocus"] }, { kind: "component", type: i3.KbqIcon, selector: "[kbq-icon]", inputs: ["small", "autoColor", "kbq-icon"] }, { kind: "directive", type: i4.CdkObserveContent, selector: "[cdkObserveContent]", inputs: ["cdkObserveContentDisabled", "debounce"], outputs: ["cdkObserveContent"], exportAs: ["cdkObserveContent"] }, { kind: "directive", type: i5.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i5.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], animations: [kbqPopoverAnimations.popoverState], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqPopoverComponent, decorators: [{
            type: Component,
            args: [{ selector: 'kbq-popover-component', preserveWhitespaces: false, host: {
                        '(keydown.esc)': 'onEscape()'
                    }, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, animations: [kbqPopoverAnimations.popoverState], template: "<div\n    #popover\n    class=\"kbq-popover\"\n    [class.kbq-popover_arrowless]=\"!arrow\"\n    [cdkTrapFocus]=\"isTrapFocus\"\n    [ngClass]=\"classMap\"\n    [@state]=\"visibility\"\n    (@state.done)=\"animationDone($event)\"\n    (@state.start)=\"animationStart()\"\n>\n    <div\n        class=\"kbq-popover__container\"\n        [class.kbq-popover__container_with-footer]=\"footer\"\n        [class.kbq-popover__container_with-header]=\"header\"\n    >\n        @if (header) {\n            <div\n                class=\"kbq-popover__header\"\n                [class.kbq-popover__header_default-paddings]=\"defaultPaddings\"\n                [class.kbq-popover__header_top-overflow]=\"isContentTopOverflow\"\n                [class.kbq-popover__header_with-close-button]=\"hasCloseButton\"\n            >\n                @if (isTemplateRef(header)) {\n                    <ng-container [ngTemplateOutlet]=\"$any(header)\" [ngTemplateOutletContext]=\"context\" />\n                }\n                @if (!isTemplateRef(header)) {\n                    <div class=\"kbq-popover__header-text\">{{ header }}</div>\n                }\n            </div>\n        }\n\n        @if (content) {\n            <div\n                #popoverContent\n                class=\"kbq-popover__content kbq-scrollbar\"\n                [class.kbq-popover__content_default-paddings]=\"defaultPaddings\"\n                (cdkObserveContent)=\"onContentChange()\"\n            >\n                @if (hasCloseButton && !header) {\n                    <div class=\"kbq-popover__close-container\">\n                        <ng-container [ngTemplateOutlet]=\"closeButton\" />\n                    </div>\n                }\n                @if (isTemplateRef(content)) {\n                    <ng-container [ngTemplateOutlet]=\"$any(content)\" [ngTemplateOutletContext]=\"context\" />\n                }\n                @if (!isTemplateRef(content)) {\n                    <div>{{ content }}</div>\n                }\n            </div>\n        }\n\n        @if (footer) {\n            <div\n                class=\"kbq-popover__footer\"\n                [class.kbq-popover__footer_default-paddings]=\"defaultPaddings\"\n                [class.kbq-popover__footer_bottom-overflow]=\"isContentBottomOverflow\"\n            >\n                @if (isTemplateRef(footer)) {\n                    <ng-container [ngTemplateOutlet]=\"$any(footer)\" [ngTemplateOutletContext]=\"context\" />\n                }\n                @if (!isTemplateRef(footer)) {\n                    <div>{{ footer }}</div>\n                }\n            </div>\n        }\n    </div>\n\n    @if (hasCloseButton && header) {\n        <div class=\"kbq-popover__close-container\">\n            <ng-container [ngTemplateOutlet]=\"closeButton\" />\n        </div>\n    }\n\n    <ng-template #closeButton>\n        <div class=\"kbq-popover__close\">\n            <button kbq-button class=\"kbq-button_transparent\" [color]=\"componentColors.Contrast\" (click)=\"hide(0)\">\n                <i kbq-icon=\"kbq-xmark_16\" [color]=\"componentColors.Contrast\"></i>\n            </button>\n        </div>\n    </ng-template>\n\n    @if (arrow) {\n        <div class=\"kbq-popover__arrow\"></div>\n    }\n</div>\n", styles: ["@keyframes kbq-progress{0%{background-position:0 0}to{background-position:64px 0}}.kbq-progress{position:relative}.kbq-progress:after{content:\"\";position:absolute;border-radius:inherit;inset:0;background:linear-gradient(135deg,#0000000a 12px,#ffffff1a 12px 22px,#0000000a 22px 34px,#ffffff1a 34px) repeat;background-size:32px 32px;animation:kbq-progress 1s linear infinite}.kbq-group{display:flex;flex-direction:row}.kbq-group .kbq-group_justified>.kbq-group-item{width:100%}.kbq-group .kbq-group-item+.kbq-group-item{margin-left:calc(-1 * var(--kbq-size-border-width))}.kbq-group>.kbq-group-item:first-child:not(:last-child){border-bottom-right-radius:0;border-top-right-radius:0}.kbq-group>.kbq-group-item:first-child:not(:last-child)>.kbq-form-field__container{border-bottom-right-radius:0;border-top-right-radius:0}.kbq-group>.kbq-group-item:last-child:not(:first-child){border-bottom-left-radius:0;border-top-left-radius:0}.kbq-group>.kbq-group-item:last-child:not(:first-child)>.kbq-form-field__container{border-bottom-left-radius:0;border-top-left-radius:0}.kbq-group>.kbq-group-item:not(:first-child):not(:last-child){border-radius:0}.kbq-group>.kbq-group-item:not(:first-child):not(:last-child)>.kbq-form-field__container{border-radius:0}.kbq-vertical-group{display:flex;flex-direction:column}.kbq-vertical-group>.kbq-group-item:first-child:not(:last-child){border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-right-radius:var(--kbq-size-border-radius)}.kbq-vertical-group>.kbq-group-item:first-child:not(:last-child)>.kbq-form-field__container{border-bottom-right-radius:0;border-bottom-left-radius:0}.kbq-vertical-group>.kbq-group-item:last-child:not(:first-child){border-top-right-radius:0;border-top-left-radius:0;border-bottom-left-radius:var(--kbq-size-border-radius)}.kbq-vertical-group>.kbq-group-item:last-child:not(:first-child)>.kbq-form-field__container{border-top-right-radius:0;border-top-left-radius:0}.kbq-vertical-group>.kbq-group-item:not(:first-child):not(:last-child){border-radius:0}.kbq-vertical-group>.kbq-group-item:not(:first-child):not(:last-child)>.kbq-form-field__container{border-radius:0}.kbq-vertical-group .kbq-group-item+.kbq-group-item{margin-top:calc(-1 * var(--kbq-size-border-width))}.kbq-truncate-line{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.kbq-no-select{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.kbq-popover{position:relative;border-radius:var(--kbq-popover-size-container-border-radius);box-sizing:border-box;list-style:none;white-space:pre-line;z-index:1}.kbq-popover.kbq-popover_small{max-width:var(--kbq-popover-size-container-width-small)}.kbq-popover.kbq-popover_small .kbq-popover__content{padding:var(--kbq-size-l)}.kbq-popover.kbq-popover_medium{max-width:var(--kbq-popover-size-container-width-medium)}.kbq-popover.kbq-popover_large{max-width:var(--kbq-popover-size-container-width-large)}.kbq-popover.kbq-popover_placement-top,.kbq-popover.kbq-popover_placement-top-left,.kbq-popover.kbq-popover_placement-top-right{margin-bottom:8px}.kbq-popover.kbq-popover_placement-right,.kbq-popover.kbq-popover_placement-right-top,.kbq-popover.kbq-popover_placement-right-bottom{margin-left:8px}.kbq-popover.kbq-popover_placement-bottom,.kbq-popover.kbq-popover_placement-bottom-left,.kbq-popover.kbq-popover_placement-bottom-right{margin-top:8px}.kbq-popover.kbq-popover_placement-left,.kbq-popover.kbq-popover_placement-left-top,.kbq-popover.kbq-popover_placement-left-bottom{margin-right:8px}.kbq-popover__content{overflow-y:auto}.kbq-popover__content.kbq-popover__content_default-paddings{padding:var(--kbq-popover-size-content-padding-top) var(--kbq-popover-size-content-padding-horizontal) var(--kbq-popover-size-content-padding-bottom)}.kbq-popover__container{overflow:hidden;display:flex;flex-direction:column;max-height:var(--kbq-popover-size-container-max-height);border-radius:var(--kbq-popover-size-container-border-radius)}.kbq-popover__container.kbq-popover__container_with-header .kbq-popover__content{padding-top:var(--kbq-size-s)}.kbq-popover__container.kbq-popover__container_with-footer .kbq-popover__content_default-paddings.kbq-popover__content{padding-bottom:var(--kbq-size-s)}.kbq-popover__content .kbq-popover__close-container{display:flex;justify-content:flex-end;height:0}.kbq-popover__content .kbq-popover__close-container .kbq-popover__close{top:auto;right:auto;transform:translateY(-50%) translate(50%)}.kbq-popover__header{display:flex;align-items:center;overflow:hidden}.kbq-popover__header .kbq-popover__header-text{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.kbq-popover__header.kbq-popover__header_default-paddings{padding:var(--kbq-popover-size-header-padding-top) var(--kbq-popover-size-header-padding-horizontal) var(--kbq-popover-size-header-padding-bottom) var(--kbq-popover-size-header-padding-horizontal)}.kbq-popover__header_top-overflow{position:relative;z-index:2;box-shadow:var(--kbq-shadow-overflow-normal-bottom)}.kbq-popover__header_with-close-button{padding-right:var(--kbq-size-4xl)}.kbq-popover__footer.kbq-popover__footer_default-paddings{padding:var(--kbq-popover-size-footer-padding-vertical) var(--kbq-popover-size-footer-padding-horizontal)}.kbq-popover__footer_bottom-overflow{position:relative;z-index:2;box-shadow:var(--kbq-shadow-overflow-normal-top)}.kbq-popover__arrow{position:absolute;z-index:-1;width:12px;height:12px;transform:rotate(45deg)}.kbq-popover_placement-top .kbq-popover__arrow{bottom:-5.5px;left:50%;margin-left:-5.5px}.kbq-popover_placement-top-left .kbq-popover__arrow{bottom:-5.5px;left:24px}.kbq-popover_placement-top-right .kbq-popover__arrow{bottom:-5.5px;right:24px}.kbq-popover_placement-right .kbq-popover__arrow{left:-5.5px;top:50%;margin-top:-5.5px}.kbq-popover_placement-right-top .kbq-popover__arrow{left:-5.5px;top:24px}.kbq-popover_placement-right-bottom .kbq-popover__arrow{left:-5.5px;bottom:24px}.kbq-popover_placement-left .kbq-popover__arrow{right:-5.5px;top:50%;margin-top:-5.5px}.kbq-popover_placement-left-top .kbq-popover__arrow{right:-5.5px;top:24px}.kbq-popover_placement-left-bottom .kbq-popover__arrow{right:-5.5px;bottom:24px}.kbq-popover_placement-bottom .kbq-popover__arrow{top:-5.5px;left:50%;margin-left:-5.5px}.kbq-popover_placement-bottom-left .kbq-popover__arrow{top:-5.5px;left:24px}.kbq-popover_placement-bottom-right .kbq-popover__arrow{top:-5.5px;right:24px}.kbq-popover__close{position:absolute;z-index:2;top:var(--kbq-size-s);right:var(--kbq-size-s);border-radius:var(--kbq-size-border-radius)}.kbq-popover{box-shadow:var(--kbq-popover-borderless-shadow)}.kbq-popover.kbq-popover_arrowless{box-shadow:var(--kbq-popover-container-shadow)}.kbq-popover__container{background:var(--kbq-popover-container-background)}.kbq-popover__arrow{box-shadow:var(--kbq-popover-borderless-shadow);background:var(--kbq-popover-container-background)}.kbq-popover__close{background-color:var(--kbq-background-overlay-inverse)}.kbq-popover__header{color:var(--kbq-popover-header-text-color)}.kbq-popover__content{color:var(--kbq-popover-content-text-color)}.kbq-popover__header{font-size:var(--kbq-typography-subheading-font-size);font-style:var(--kbq-typography-subheading-font-style);font-weight:var(--kbq-typography-subheading-font-weight);line-height:var(--kbq-typography-subheading-line-height);font-family:var(--kbq-typography-subheading-font-family);text-transform:var(--kbq-typography-subheading-text-transform);font-feature-settings:var(--kbq-typography-subheading-font-feature-settings);letter-spacing:var(--kbq-typography-subheading-letter-spacing)}.kbq-popover__content{font-size:var(--kbq-typography-text-normal-font-size);font-style:var(--kbq-typography-text-normal-font-style);font-weight:var(--kbq-typography-text-normal-font-weight);line-height:var(--kbq-typography-text-normal-line-height);font-family:var(--kbq-typography-text-normal-font-family);text-transform:var(--kbq-typography-text-normal-text-transform);font-feature-settings:var(--kbq-typography-text-normal-font-feature-settings);letter-spacing:var(--kbq-typography-text-normal-letter-spacing)}\n", ".kbq-popover{--kbq-popover-size-container-width-small: 200px;--kbq-popover-size-container-width-medium: 400px;--kbq-popover-size-container-width-large: 640px;--kbq-popover-size-container-border-radius: var(--kbq-size-m);--kbq-popover-size-container-max-height: 480px;--kbq-popover-size-close-button-width: 32px;--kbq-popover-size-close-button-margin-right: -16px;--kbq-popover-size-close-button-margin-top: -10px;--kbq-popover-size-header-padding-horizontal: var(--kbq-size-xxl);--kbq-popover-size-header-padding-top: var(--kbq-size-l);--kbq-popover-size-header-padding-bottom: var(--kbq-size-xs);--kbq-popover-size-content-padding-top: var(--kbq-size-xxl);--kbq-popover-size-content-padding-bottom: var(--kbq-size-3xl);--kbq-popover-size-content-padding-horizontal: var(--kbq-size-xxl);--kbq-popover-size-content-padding-with-header-top: var(--kbq-size-s);--kbq-popover-size-content-padding-with-footer-bottom: var(--kbq-size-s);--kbq-popover-size-footer-padding-vertical: var(--kbq-size-l);--kbq-popover-size-footer-padding-horizontal: var(--kbq-size-xxl);--kbq-popover-container-background: var(--kbq-background-card);--kbq-popover-container-shadow: var(--kbq-shadow-popup);--kbq-popover-header-text-color: var(--kbq-foreground-contrast);--kbq-popover-header-scroll-shadow: var(--kbq-shadow-overflow-normal-bottom);--kbq-popover-content-text-color: var(--kbq-foreground-contrast);--kbq-popover-footer-scroll-shadow: var(--kbq-shadow-overflow-normal-top);--kbq-popover-borderless-shadow: 0 2px 8px var(--kbq-shadow-key), 0 3px 8px var(--kbq-shadow-ambient)}\n"] }]
        }], propDecorators: { popoverContent: [{
                type: ViewChild,
                args: ['popoverContent']
            }], elementRef: [{
                type: ViewChild,
                args: ['popover']
            }], cdkTrapFocus: [{
                type: ViewChild,
                args: [CdkTrapFocus]
            }] } });
export const KBQ_POPOVER_SCROLL_STRATEGY = new InjectionToken('kbq-popover-scroll-strategy');
/** @docs-private */
export function kbqPopoverScrollStrategyFactory(overlay) {
    return () => overlay.scrollStrategies.reposition({ scrollThrottle: 20 });
}
/** @docs-private */
export const KBQ_POPOVER_SCROLL_STRATEGY_FACTORY_PROVIDER = {
    provide: KBQ_POPOVER_SCROLL_STRATEGY,
    deps: [Overlay],
    useFactory: kbqPopoverScrollStrategyFactory
};
/** Creates an error to be thrown if the user supplied an invalid popover position. */
export function getKbqPopoverInvalidPositionError(position) {
    return Error(`KbqPopover position "${position}" is invalid.`);
}
export class KbqPopoverTrigger extends KbqPopUpTrigger {
    constructor() {
        super(...arguments);
        this.scrollStrategy = inject(KBQ_POPOVER_SCROLL_STRATEGY);
        /** prevents closure by any event */
        this.preventClose = false;
        /** disables default padding for all popover elements (header, content and footer) */
        this.defaultPaddings = true;
        this._hasBackdrop = false;
        this._trigger = `${PopUpTriggers.Click}, ${PopUpTriggers.Keydown}`;
        this._size = PopUpSizes.Medium;
        this._context = null;
        this._hasCloseButton = false;
        this._closeOnScroll = null;
        this.backdropClass = 'cdk-overlay-transparent-backdrop';
        // @TODO add realization for arrow (#DS-2514)
        this.arrow = true;
        this.offset = defaultOffsetYWithArrow;
        this.placementChange = new EventEmitter();
        this.visibleChange = new EventEmitter();
        this.originSelector = '.kbq-popover';
        this.hideIfNotInViewPort = () => {
            if (!this.scrollable)
                return;
            const rect = this.elementRef.nativeElement.getBoundingClientRect();
            const containerRect = this.scrollable.getElementRef().nativeElement.getBoundingClientRect();
            if (!(rect.bottom >= containerRect.top &&
                rect.right >= containerRect.left &&
                rect.top <= containerRect.bottom &&
                rect.left <= containerRect.right)) {
                this.hide();
            }
        };
    }
    get popoverVisible() {
        return this.visible;
    }
    set popoverVisible(value) {
        super.updateVisible(value);
    }
    get popoverPlacement() {
        return this.placement;
    }
    set popoverPlacement(value) {
        super.updatePlacement(value);
    }
    get popoverPlacementPriority() {
        return this.placementPriority;
    }
    set popoverPlacementPriority(value) {
        super.updatePlacementPriority(value);
    }
    get hasBackdrop() {
        return this._hasBackdrop;
    }
    set hasBackdrop(value) {
        this._hasBackdrop = coerceBooleanProperty(value);
    }
    get header() {
        return this._header;
    }
    set header(value) {
        this._header = value;
        this.updateData();
    }
    get content() {
        return this._content;
    }
    set content(value) {
        this._content = value;
        this.updateData();
    }
    get footer() {
        return this._footer;
    }
    set footer(value) {
        this._footer = value;
        this.updateData();
    }
    get disabled() {
        return this._disabled;
    }
    set disabled(value) {
        this._disabled = coerceBooleanProperty(value);
        if (this._disabled) {
            this.hide();
        }
    }
    get trigger() {
        return this._trigger;
    }
    set trigger(value) {
        if (value) {
            this._trigger = value;
            if (this.trigger.includes(PopUpTriggers.Hover)) {
                this.hideWithTimeout = true;
                this.leaveDelay = this.leaveDelay ?? 500;
            }
        }
        else {
            this._trigger = `${PopUpTriggers.Click}, ${PopUpTriggers.Keydown}`;
        }
        this.initListeners();
    }
    get size() {
        return this._size;
    }
    set size(value) {
        if ([PopUpSizes.Small, PopUpSizes.Medium, PopUpSizes.Large].includes(value)) {
            this._size = value;
            this.updateClassMap();
        }
        else {
            this._size = PopUpSizes.Medium;
        }
    }
    get customClass() {
        return this._customClass;
    }
    set customClass(value) {
        this._customClass = value;
        this.updateClassMap();
    }
    /** Context for popover templates (kbqPopoverHeader, kbqPopoverContent and kbqPopoverFooter). */
    get context() {
        return this._context;
    }
    set context(ctx) {
        this._context = ctx;
        this.updateData();
    }
    get hasCloseButton() {
        return this._hasCloseButton;
    }
    set hasCloseButton(value) {
        this._hasCloseButton = value;
        this.updateData();
    }
    /**
     * Controls the behavior of closing the component on scroll.
     * The default value is `false`.
     * Use CloseScrollStrategy as alternative
     */
    get closeOnScroll() {
        return this._closeOnScroll;
    }
    set closeOnScroll(value) {
        this._closeOnScroll = coerceBooleanProperty(value);
    }
    get hasClickTrigger() {
        return this.trigger.includes(PopUpTriggers.Click);
    }
    get overlayConfig() {
        return {
            panelClass: 'kbq-popover__panel',
            hasBackdrop: this.hasBackdrop,
            backdropClass: this.backdropClass
        };
    }
    ngOnInit() {
        super.ngOnInit();
        this.scrollable
            ?.elementScrolled()
            .pipe(takeUntilDestroyed(this.destroyRef))
            .subscribe(this.hideIfNotInViewPort);
    }
    ngAfterContentInit() {
        if (this.closeOnScroll === null) {
            this.scrollDispatcher.scrolled().subscribe((scrollable) => {
                if (!scrollable?.getElementRef().nativeElement.classList.contains('kbq-hide-nested-popup'))
                    return;
                const parentRects = scrollable.getElementRef().nativeElement.getBoundingClientRect();
                const childRects = this.elementRef.nativeElement.getBoundingClientRect();
                if (childRects.bottom < parentRects.top || childRects.top > parentRects.bottom) {
                    this.hide();
                }
            });
        }
    }
    updateData() {
        if (!this.instance)
            return;
        this.instance.header = this.header;
        this.instance.content = this.content;
        this.instance.context = this.context && { $implicit: this.context };
        this.instance.arrow = this.arrow;
        this.instance.offset = this.offset;
        this.instance.footer = this.footer;
        this.instance.hasCloseButton = this.hasCloseButton;
        this.instance.defaultPaddings = this.defaultPaddings;
        this.instance.updateTrapFocus(this.trigger !== PopUpTriggers.Focus);
        if (this.isOpen) {
            this.updatePosition(true);
        }
    }
    /** Updates the position of the current popover. */
    updatePosition(reapplyPosition = false) {
        this.overlayRef = this.createOverlay();
        const position = this.overlayRef.getConfig().positionStrategy
            .withPositions(this.getAdjustedPositions())
            .withPush(true);
        if (reapplyPosition) {
            setTimeout(() => position.reapplyLastPosition());
        }
    }
    getOverlayHandleComponentType() {
        return KbqPopoverComponent;
    }
    updateClassMap(newPlacement = this.placement) {
        if (!this.instance) {
            return;
        }
        this.instance.updateClassMap(POSITION_TO_CSS_MAP[newPlacement], this.customClass, this.size);
        this.instance.markForCheck();
    }
    closingActionsForClick() {
        if (this.hasClickTrigger) {
            return this.defaultClosingActions();
        }
        return [];
    }
    defaultClosingActions() {
        return [
            this.overlayRef.backdropClick(),
            this.hasBackdrop ? NEVER : this.overlayRef.outsidePointerEvents()
        ];
    }
    closingActions() {
        return merge(...this.closingActionsForClick(), this.closeOnScroll ? this.scrollDispatcher.scrolled() : NEVER);
    }
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqPopoverTrigger, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
    /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "18.2.14", type: KbqPopoverTrigger, selector: "[kbqPopover]", inputs: { preventClose: ["kbqPopoverPreventClose", "preventClose", booleanAttribute], defaultPaddings: ["defaultPaddings", "defaultPaddings", booleanAttribute], popoverVisible: ["kbqPopoverVisible", "popoverVisible"], popoverPlacement: ["kbqPopoverPlacement", "popoverPlacement"], popoverPlacementPriority: ["kbqPopoverPlacementPriority", "popoverPlacementPriority"], hasBackdrop: "hasBackdrop", header: ["kbqPopoverHeader", "header"], content: ["kbqPopoverContent", "content"], footer: ["kbqPopoverFooter", "footer"], disabled: ["kbqPopoverDisabled", "disabled"], trigger: ["kbqTrigger", "trigger"], size: ["kbqPopoverSize", "size"], customClass: ["kbqPopoverClass", "customClass"], context: ["kbqPopoverContext", "context"], hasCloseButton: "hasCloseButton", closeOnScroll: "closeOnScroll", backdropClass: "backdropClass", arrow: ["kbqPopoverArrow", "arrow", booleanAttribute], offset: ["kbqPopoverOffset", "offset", numberAttribute], leaveDelay: ["kbqLeaveDelay", "leaveDelay", numberAttribute] }, outputs: { placementChange: "kbqPopoverPlacementChange", visibleChange: "kbqPopoverVisibleChange" }, host: { listeners: { "keydown": "keydownHandler($event)", "touchend": "touchendHandler()" }, properties: { "class.kbq-popover_open": "isOpen", "class.kbq-active": "hasClickTrigger && isOpen" } }, exportAs: ["kbqPopover"], usesInheritance: true, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqPopoverTrigger, decorators: [{
            type: Directive,
            args: [{
                    selector: '[kbqPopover]',
                    exportAs: 'kbqPopover',
                    host: {
                        '[class.kbq-popover_open]': 'isOpen',
                        '[class.kbq-active]': 'hasClickTrigger && isOpen',
                        '(keydown)': 'keydownHandler($event)',
                        '(touchend)': 'touchendHandler()'
                    }
                }]
        }], propDecorators: { preventClose: [{
                type: Input,
                args: [{ alias: 'kbqPopoverPreventClose', transform: booleanAttribute }]
            }], defaultPaddings: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], popoverVisible: [{
                type: Input,
                args: ['kbqPopoverVisible']
            }], popoverPlacement: [{
                type: Input,
                args: ['kbqPopoverPlacement']
            }], popoverPlacementPriority: [{
                type: Input,
                args: ['kbqPopoverPlacementPriority']
            }], hasBackdrop: [{
                type: Input
            }], header: [{
                type: Input,
                args: ['kbqPopoverHeader']
            }], content: [{
                type: Input,
                args: ['kbqPopoverContent']
            }], footer: [{
                type: Input,
                args: ['kbqPopoverFooter']
            }], disabled: [{
                type: Input,
                args: ['kbqPopoverDisabled']
            }], trigger: [{
                type: Input,
                args: ['kbqTrigger']
            }], size: [{
                type: Input,
                args: ['kbqPopoverSize']
            }], customClass: [{
                type: Input,
                args: ['kbqPopoverClass']
            }], context: [{
                type: Input,
                args: ['kbqPopoverContext']
            }], hasCloseButton: [{
                type: Input
            }], closeOnScroll: [{
                type: Input
            }], backdropClass: [{
                type: Input
            }], arrow: [{
                type: Input,
                args: [{ alias: 'kbqPopoverArrow', transform: booleanAttribute }]
            }], offset: [{
                type: Input,
                args: [{ alias: 'kbqPopoverOffset', transform: numberAttribute }]
            }], leaveDelay: [{
                type: Input,
                args: [{ alias: 'kbqLeaveDelay', transform: numberAttribute }]
            }], placementChange: [{
                type: Output,
                args: ['kbqPopoverPlacementChange']
            }], visibleChange: [{
                type: Output,
                args: ['kbqPopoverVisibleChange']
            }] } });
//# sourceMappingURL=data:application/json;base64, 