import { booleanAttribute, Component, Directive, ElementRef, Input, Optional } from '@angular/core';
import { KbqSidepanelRef } from './sidepanel-ref';
import { KbqSidepanelService } from './sidepanel.service';
import * as i0 from "@angular/core";
import * as i1 from "./sidepanel-ref";
import * as i2 from "./sidepanel.service";
import * as i3 from "@koobiq/components/button";
import * as i4 from "@koobiq/components/icon";
import * as i5 from "@koobiq/components/title";
/**
 * Button that will close the current sidepanel.
 */
export class KbqSidepanelClose {
    constructor(sidepanelRef, elementRef, sidepanelService) {
        this.sidepanelRef = sidepanelRef;
        this.elementRef = elementRef;
        this.sidepanelService = sidepanelService;
    }
    ngOnInit() {
        if (!this.sidepanelRef) {
            // When this directive is included in a sidepanel via TemplateRef (rather than being
            // in a Component), the SidepanelRef isn't available via injection because embedded
            // views cannot be given a custom injector. Instead, we look up the SidepanelRef by
            // ID.
            // This must occur in `onInit`, as the ID binding for the sidepanel container won't
            // be resolved at constructor time. We use setTimeout by same reason.
            setTimeout(() => {
                this.sidepanelRef = getClosestSidepanel(this.elementRef, this.sidepanelService.openedSidepanels);
            });
        }
    }
    ngOnChanges(changes) {
        const proxiedChange = changes.kbqSidepanelClose || changes.sidepanelResult;
        if (proxiedChange) {
            this.sidepanelResult = proxiedChange.currentValue;
        }
    }
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelClose, deps: [{ token: i1.KbqSidepanelRef, optional: true }, { token: i0.ElementRef }, { token: i2.KbqSidepanelService }], target: i0.ɵɵFactoryTarget.Directive }); }
    /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: KbqSidepanelClose, selector: "button[kbq-sidepanel-close], button[kbqSidepanelClose]", inputs: { sidepanelResult: ["kbq-sidepanel-close", "sidepanelResult"], kbqSidepanelClose: "kbqSidepanelClose" }, host: { listeners: { "click": "sidepanelRef.close(sidepanelResult)" }, classAttribute: "kbq-sidepanel-close" }, usesOnChanges: true, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelClose, decorators: [{
            type: Directive,
            args: [{
                    selector: 'button[kbq-sidepanel-close], button[kbqSidepanelClose]',
                    host: {
                        '(click)': 'sidepanelRef.close(sidepanelResult)',
                        class: 'kbq-sidepanel-close'
                    }
                }]
        }], ctorParameters: () => [{ type: i1.KbqSidepanelRef, decorators: [{
                    type: Optional
                }] }, { type: i0.ElementRef }, { type: i2.KbqSidepanelService }], propDecorators: { sidepanelResult: [{
                type: Input,
                args: ['kbq-sidepanel-close']
            }], kbqSidepanelClose: [{
                type: Input
            }] } });
/**
 * Header of a sidepanel.
 */
export class KbqSidepanelHeader {
    constructor() {
        /** Add button for close sidepanel. Default false */
        this.closeable = false;
        /** Enables text truncation. Default true */
        this.truncateText = true;
    }
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelHeader, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    /** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: KbqSidepanelHeader, selector: "kbq-sidepanel-header", inputs: { closeable: ["closeable", "closeable", booleanAttribute], truncateText: ["truncateText", "truncateText", booleanAttribute] }, host: { properties: { "class.kbq-sidepanel-header_truncate-text": "truncateText" }, classAttribute: "kbq-sidepanel-header" }, ngImport: i0, template: `
        <div class="kbq-sidepanel-title" kbq-title>
            <ng-content />
        </div>

        @if (closeable) {
            <button kbq-button kbq-sidepanel-close [color]="'contrast'" [kbqStyle]="'transparent'">
                <i kbq-icon="kbq-xmark_16" [color]="'contrast'"></i>
            </button>
        }
    `, isInline: true, dependencies: [{ kind: "component", type: i3.KbqButton, selector: "[kbq-button]", inputs: ["kbqStyle", "disabled", "tabIndex"] }, { kind: "directive", type: i3.KbqButtonCssStyler, selector: "[kbq-button]" }, { kind: "component", type: i4.KbqIcon, selector: "[kbq-icon]", inputs: ["small", "autoColor", "kbq-icon"] }, { kind: "directive", type: i5.KbqTitleDirective, selector: "[kbq-title]", exportAs: ["kbqTitle"] }, { kind: "directive", type: KbqSidepanelClose, selector: "button[kbq-sidepanel-close], button[kbqSidepanelClose]", inputs: ["kbq-sidepanel-close", "kbqSidepanelClose"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelHeader, decorators: [{
            type: Component,
            args: [{
                    selector: 'kbq-sidepanel-header',
                    template: `
        <div class="kbq-sidepanel-title" kbq-title>
            <ng-content />
        </div>

        @if (closeable) {
            <button kbq-button kbq-sidepanel-close [color]="'contrast'" [kbqStyle]="'transparent'">
                <i kbq-icon="kbq-xmark_16" [color]="'contrast'"></i>
            </button>
        }
    `,
                    host: {
                        class: 'kbq-sidepanel-header',
                        '[class.kbq-sidepanel-header_truncate-text]': 'truncateText'
                    }
                }]
        }], propDecorators: { closeable: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], truncateText: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }] } });
/**
 * Scrollable content container of a sidepanel.
 */
export class KbqSidepanelBody {
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelBody, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: KbqSidepanelBody, selector: "kbq-sidepanel-body, [kbq-sidepanel-body], kbqSidepanelBody", host: { classAttribute: "kbq-sidepanel-body kbq-scrollbar" }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelBody, decorators: [{
            type: Directive,
            args: [{
                    selector: 'kbq-sidepanel-body, [kbq-sidepanel-body], kbqSidepanelBody',
                    host: {
                        class: 'kbq-sidepanel-body kbq-scrollbar'
                    }
                }]
        }] });
/**
 * Footer of a sidepanel.
 */
export class KbqSidepanelFooter {
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelFooter, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: KbqSidepanelFooter, selector: "kbq-sidepanel-footer, [kbq-sidepanel-footer], kbqSidepanelFooter", host: { classAttribute: "kbq-sidepanel-footer" }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelFooter, decorators: [{
            type: Directive,
            args: [{
                    selector: 'kbq-sidepanel-footer, [kbq-sidepanel-footer], kbqSidepanelFooter',
                    host: {
                        class: 'kbq-sidepanel-footer'
                    }
                }]
        }] });
/**
 * Actions block of a sidepanel footer.
 */
export class KbqSidepanelActions {
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelActions, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: KbqSidepanelActions, selector: "kbq-sidepanel-actions, [kbq-sidepanel-actions], kbqSidepanelActions", host: { classAttribute: "kbq-sidepanel-actions" }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqSidepanelActions, decorators: [{
            type: Directive,
            args: [{
                    selector: 'kbq-sidepanel-actions, [kbq-sidepanel-actions], kbqSidepanelActions',
                    host: {
                        class: 'kbq-sidepanel-actions'
                    }
                }]
        }] });
/**
 * Finds the closest KbqSidepanelRef to an element by looking at the DOM.
 * @param element Element relative to which to look for a sidepanel.
 * @param openSidepanels References to the currently-open sidepanels.
 */
function getClosestSidepanel(element, openSidepanels) {
    let parent = element.nativeElement.parentElement;
    while (parent && !parent.classList.contains('kbq-sidepanel-container')) {
        parent = parent.parentElement;
    }
    return parent ? openSidepanels.find((sidepanel) => sidepanel.id === parent.id) : null;
}
//# sourceMappingURL=data:application/json;base64, 