import { trigger, transition, style, animate } from '@angular/animations';
import { CdkTrapFocus, CdkMonitorFocus } from '@angular/cdk/a11y';
import { hasModifierKey } from '@angular/cdk/keycodes';
import { Overlay, CdkOverlayOrigin, CdkConnectedOverlay } from '@angular/cdk/overlay';
import { DOCUMENT } from '@angular/common';
import * as i0 from '@angular/core';
import { output, Directive, inject, ElementRef, input, booleanAttribute, numberAttribute, contentChild, viewChild, viewChildren, signal, computed, Component, ChangeDetectionStrategy, ViewEncapsulation, NgModule } from '@angular/core';
import { toObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { AbstractControl, NgControl } from '@angular/forms';
import { KbqAutocompleteTrigger } from '@koobiq/components/autocomplete';
import * as i2 from '@koobiq/components/button';
import { KbqButtonModule } from '@koobiq/components/button';
import * as i1 from '@koobiq/components/core';
import { KbqAnimationDurations, KbqAnimationCurves, KbqFocusMonitor, PopUpPlacements, KbqComponentColors } from '@koobiq/components/core';
import { KbqDropdownTrigger } from '@koobiq/components/dropdown';
import { KbqLabel, KbqFormField } from '@koobiq/components/form-field';
import { KbqIcon } from '@koobiq/components/icon';
import { KbqSelect } from '@koobiq/components/select';
import { KbqTooltipTrigger } from '@koobiq/components/tooltip';
import { KbqTreeSelect } from '@koobiq/components/tree-select';
import { skip } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

const KBQ_INLINE_EDIT_ACTION_BUTTONS_ANIMATION = trigger('panelAnimation', [
    transition(':enter', [
        style({ transform: 'translateY(100%)', opacity: 0 }),
        animate(`${KbqAnimationDurations.Instant} ${KbqAnimationCurves.DecelerationCurve}`, style({ transform: 'translateY(0%)', opacity: 1 }))
    ])
]);
const baseClass = 'kbq-inline-edit';
/** @docs-private */
class KbqFocusRegionItem {
    constructor() {
        this.tabOut = output();
        this.isFocused = false;
    }
    onTabOut(event) {
        if (this.isFocused) {
            this.tabOut.emit(event);
        }
        this.isFocused = !this.isFocused;
    }
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqFocusRegionItem, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: KbqFocusRegionItem, isStandalone: true, selector: "[kbqFocusRegionItem]", outputs: { tabOut: "tabOut" }, host: { listeners: { "focusin": "isFocused = true", "keydown.tab": "onTabOut($event)", "keydown.shift.tab": "onTabOut($event)" } }, exportAs: ["kbqFocusRegionItem"], ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqFocusRegionItem, decorators: [{
            type: Directive,
            args: [{
                    standalone: true,
                    selector: '[kbqFocusRegionItem]',
                    exportAs: 'kbqFocusRegionItem',
                    host: {
                        '(focusin)': 'isFocused = true',
                        '(keydown.tab)': 'onTabOut($event)',
                        '(keydown.shift.tab)': 'onTabOut($event)'
                    }
                }]
        }] });
/** Directive for easy using styles of inline edit placeholder publicly. */
class KbqInlineEditPlaceholder {
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEditPlaceholder, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: KbqInlineEditPlaceholder, isStandalone: true, selector: "[kbqInlineEditPlaceholder]", host: { classAttribute: "kbq-inline-edit__placeholder" }, exportAs: ["kbqInlineEditPlaceholder"], ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEditPlaceholder, decorators: [{
            type: Directive,
            args: [{
                    standalone: true,
                    selector: '[kbqInlineEditPlaceholder]',
                    exportAs: 'kbqInlineEditPlaceholder',
                    host: {
                        class: 'kbq-inline-edit__placeholder'
                    }
                }]
        }] });
/**
 * This directive enhances element acting as dropdown trigger,
 * visually indicating the active state with the `kbq-active` class.
 * Also, it prevents click/keydown events from being propagated to disable mode toggling of parent component.
 */
class KbqInlineEditMenu {
    constructor() {
        /** @docs-private */
        this.dropdownTrigger = inject(KbqDropdownTrigger, { optional: true });
    }
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEditMenu, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: KbqInlineEditMenu, isStandalone: true, selector: "[kbqInlineEditMenu]", host: { attributes: { "role": "button" }, listeners: { "click": "$event.stopPropagation()", "keydown.enter": "$event.stopPropagation()", "keydown.space": "$event.stopPropagation()" }, properties: { "class.kbq-active": "dropdownTrigger?.opened" }, classAttribute: "kbq-inline-edit__menu" }, exportAs: ["kbqInlineEditMenu"], ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEditMenu, decorators: [{
            type: Directive,
            args: [{
                    standalone: true,
                    selector: '[kbqInlineEditMenu]',
                    exportAs: 'kbqInlineEditMenu',
                    host: {
                        role: 'button',
                        class: 'kbq-inline-edit__menu',
                        '[class.kbq-active]': 'dropdownTrigger?.opened',
                        '(click)': '$event.stopPropagation()',
                        '(keydown.enter)': '$event.stopPropagation()',
                        '(keydown.space)': '$event.stopPropagation()'
                    }
                }]
        }] });
/**
 * Customizable component that enables edit-in-place logic for specified control and it's view.
 * This component is projecting edit/view mode templates and adds keyboard/pointer handlers.
 * Edit mode opens in a positioned overlay that matches the view mode width or can be customized.
 */
class KbqInlineEdit {
    constructor() {
        this.elementRef = inject(ElementRef);
        this.kbqFocusMonitor = inject(KbqFocusMonitor, { host: true });
        this.overlay = inject(Overlay);
        this.document = inject(DOCUMENT);
        /**
         * Whether to show save/cancel action buttons in edit mode.
         * @default false
         */
        this.showActions = input(false, { transform: booleanAttribute });
        /**
         * Whether to automatically show validation error tooltips on save attempts.
         * @default true
         */
        this.showTooltipOnError = input(true, { transform: booleanAttribute });
        /** Custom validation tooltip message. */
        this.validationTooltip = input();
        /**
         * Disables the component, preventing interaction and mode switching. Only allows menu dropdown.
         * @default false
         */
        this.disabled = input(false, { transform: booleanAttribute });
        /** Custom width in pixels for the edit mode overlay. Auto-calculated if not set. */
        this.editModeWidth = input(undefined, { transform: numberAttribute });
        /** User-defined tooltip placement */
        this.tooltipPlacement = input();
        /** Handler function to retrieve the current value */
        this.getValueHandler = input();
        /** Handler function to update the value */
        this.setValueHandler = input();
        /**
         * Customizable function that checks if saving on enter available.
         */
        this.canSaveOnEnter = input((event) => hasModifierKey(event, 'ctrlKey', 'metaKey') || !(event.target instanceof HTMLTextAreaElement));
        /** Emitted when the inline edit is saved successfully. */
        this.saved = output();
        /** Emitted when the inline edit is canceled and changes are discarded. */
        this.canceled = output();
        /** Emitted when mode switched to edit/view */
        this.modeChange = output();
        /** @docs-private */
        this.menu = contentChild(KbqInlineEditMenu);
        /** @docs-private */
        this.label = contentChild(KbqLabel);
        /** @docs-private */
        this.formFieldRef = contentChild(KbqFormField);
        /** @docs-private */
        this.overlayOrigin = viewChild.required(CdkOverlayOrigin);
        /** @docs-private */
        this.tooltipTrigger = viewChild(KbqTooltipTrigger);
        /** @docs-private */
        this.overlayDir = viewChild(CdkConnectedOverlay);
        /** @docs-private */
        this.regionItems = viewChildren(KbqFocusRegionItem);
        /** @docs-private */
        this.mode = signal('view');
        /** @docs-private */
        this.overlayWidth = signal('');
        /** @docs-private */
        this.scrollStrategy = signal(this.overlay.scrollStrategies.reposition());
        /** @docs-private */
        this.modeAsReadonly = computed(() => this.mode());
        /** @docs-private */
        this.className = computed(() => `${baseClass}_${this.mode()}`);
        /** @docs-private */
        this.isEditMode = computed(() => this.mode() === 'edit');
        /** @docs-private */
        this.tabIndex = computed(() => (this.isEditMode() || this.disabled() ? -1 : 0));
        /** @docs-private */
        this.placements = PopUpPlacements;
        /** @docs-private */
        this.colors = KbqComponentColors;
        toObservable(this.mode)
            .pipe(skip(1), takeUntilDestroyed())
            .subscribe((currentMode) => this.modeChange.emit(currentMode));
    }
    /** @docs-private */
    toggleMode() {
        this.mode.update((mode) => (mode === 'view' ? 'edit' : 'view'));
    }
    /** @docs-private */
    onClick(event) {
        if (this.disabled() || this.isEditMode())
            return;
        event.preventDefault();
        event.stopPropagation();
        this.kbqFocusMonitor.focusVia(this.overlayOrigin().elementRef, 'program');
        this.toggleMode();
    }
    /** @docs-private */
    onAttach() {
        this.setOverlayWidth();
        this.setOverlayKeydownListener();
        const formFieldRef = this.formFieldRef();
        formFieldRef?.control.stateChanges
            .pipe(takeUntil(this.overlayDir().overlayRef.detachments()))
            .subscribe(() => {
            if (!this.isInvalid()) {
                const tooltipTrigger = this.tooltipTrigger();
                tooltipTrigger?.isOpen && tooltipTrigger?.hide();
            }
        });
        setTimeout(() => {
            formFieldRef?.focus();
            this.initialValue = this.getValue();
            const input = this.getInputNativeElement();
            if (this.initialValue)
                input?.select();
            if (formFieldRef) {
                this.openPanel(formFieldRef);
            }
        }, 0);
    }
    /** @docs-private */
    save($event) {
        if (this.isInvalid()) {
            $event?.stopPropagation();
            this.showTooltipOnError() && this.tooltipTrigger()?.show();
        }
        else {
            this.toggleMode();
            this.saved.emit();
        }
    }
    /** @docs-private */
    cancel() {
        this.setValue(this.initialValue);
        const input = this.getInputNativeElement();
        if (input) {
            input.selectionStart = input.selectionEnd = null;
        }
        this.toggleMode();
        this.canceled.emit();
    }
    /** @docs-private */
    onOverlayKeydown(event) {
        this.formFieldRef()?.control.ngControl?.control?.markAsTouched();
        const canSaveOnEnter = this.canSaveOnEnter();
        switch (event.key) {
            case 'Escape': {
                this.cancel();
                break;
            }
            case 'Enter': {
                if (canSaveOnEnter(event)) {
                    event.preventDefault();
                    this.formFieldRef()?.control.ngControl?.control?.markAsTouched();
                    setTimeout(() => this.save(event));
                }
                break;
            }
            default: {
                return;
            }
        }
    }
    /**
     * Sets up Tab key listeners on region items.
     * Single item: Tab moves to next edit.
     * Multiple items: Shift+Tab on first or Tab on last moves to next edit.
     */
    setOverlayKeydownListener() {
        const regionItems = this.regionItems();
        if (regionItems.length === 0)
            return;
        const firstItem = regionItems.at(0);
        const lastItem = regionItems.at(regionItems.length - 1);
        if (regionItems.length === 1) {
            firstItem?.tabOut.subscribe((event) => this.saveAndFocusNextInlineEdit(event));
        }
        else {
            firstItem?.tabOut.subscribe((event) => hasModifierKey(event, 'shiftKey') && this.saveAndFocusNextInlineEdit(event));
            lastItem?.tabOut.subscribe((event) => !hasModifierKey(event, 'shiftKey') && this.saveAndFocusNextInlineEdit(event));
        }
    }
    saveAndFocusNextInlineEdit(event) {
        this.save(event);
        if (this.isInvalid())
            return;
        setTimeout(() => {
            const activeElement = this.document.activeElement;
            if (activeElement?.classList?.contains('kbq-inline-edit__focus_container')) {
                activeElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' }));
            }
        });
    }
    isInvalid() {
        const formFieldRef = this.formFieldRef();
        if (!formFieldRef)
            return false;
        return formFieldRef.invalid;
    }
    getValue() {
        const getValueHandler = this.getValueHandler();
        if (getValueHandler)
            return getValueHandler();
        const control = this.coerceControl();
        return control?.value;
    }
    setValue(value) {
        const setValue = this.setValueHandler();
        if (setValue) {
            setValue(this.initialValue);
            return;
        }
        const control = this.coerceControl();
        if (!control)
            return;
        if (control instanceof AbstractControl) {
            control.setValue(value);
        }
        else {
            control.value = value;
        }
    }
    coerceControl() {
        const formFieldRef = this.formFieldRef();
        if (!formFieldRef)
            return null;
        if (formFieldRef.control.ngControl instanceof NgControl) {
            return formFieldRef.control.ngControl.control;
        }
        return formFieldRef.control;
    }
    setOverlayWidth() {
        const editModeWidth = this.editModeWidth();
        if (editModeWidth) {
            this.overlayWidth.set(editModeWidth);
            return;
        }
        const elementRef = this.label()
            ? this.overlayOrigin().elementRef
            : this.elementRef;
        this.overlayWidth.set(elementRef?.nativeElement.offsetWidth ?? '');
    }
    // @TODO refactor this (#DS-4181)
    openPanel(formFieldRef) {
        const control = formFieldRef.control;
        if (control instanceof KbqSelect || control instanceof KbqTreeSelect) {
            control.open();
        }
        else if (control instanceof KbqAutocompleteTrigger) {
            control.openPanel();
        }
    }
    getInputNativeElement() {
        return this.overlayDir()?.overlayRef.overlayElement.querySelector('input:not([type="file"]),textarea') ?? null;
    }
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEdit, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    /** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: KbqInlineEdit, isStandalone: true, selector: "kbq-inline-edit", inputs: { showActions: { classPropertyName: "showActions", publicName: "showActions", isSignal: true, isRequired: false, transformFunction: null }, showTooltipOnError: { classPropertyName: "showTooltipOnError", publicName: "showTooltipOnError", isSignal: true, isRequired: false, transformFunction: null }, validationTooltip: { classPropertyName: "validationTooltip", publicName: "validationTooltip", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, editModeWidth: { classPropertyName: "editModeWidth", publicName: "editModeWidth", isSignal: true, isRequired: false, transformFunction: null }, tooltipPlacement: { classPropertyName: "tooltipPlacement", publicName: "tooltipPlacement", isSignal: true, isRequired: false, transformFunction: null }, getValueHandler: { classPropertyName: "getValueHandler", publicName: "getValueHandler", isSignal: true, isRequired: false, transformFunction: null }, setValueHandler: { classPropertyName: "setValueHandler", publicName: "setValueHandler", isSignal: true, isRequired: false, transformFunction: null }, canSaveOnEnter: { classPropertyName: "canSaveOnEnter", publicName: "canSaveOnEnter", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { saved: "saved", canceled: "canceled", modeChange: "modeChange" }, host: { listeners: { "click": "onClick($event)", "keydown.enter": "onClick($event)", "keydown.space": "onClick($event)" }, properties: { "class": "className()", "class.kbq-inline-edit_with-label": "!!label()", "class.kbq-inline-edit_with-menu": "!!menu()", "class.kbq-inline-edit_disabled": "disabled()" }, classAttribute: "kbq-inline-edit" }, queries: [{ propertyName: "menu", first: true, predicate: KbqInlineEditMenu, descendants: true, isSignal: true }, { propertyName: "label", first: true, predicate: KbqLabel, descendants: true, isSignal: true }, { propertyName: "formFieldRef", first: true, predicate: KbqFormField, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "overlayOrigin", first: true, predicate: CdkOverlayOrigin, descendants: true, isSignal: true }, { propertyName: "tooltipTrigger", first: true, predicate: KbqTooltipTrigger, descendants: true, isSignal: true }, { propertyName: "overlayDir", first: true, predicate: CdkConnectedOverlay, descendants: true, isSignal: true }, { propertyName: "regionItems", predicate: KbqFocusRegionItem, descendants: true, isSignal: true }], exportAs: ["kbqInlineEdit"], hostDirectives: [{ directive: i1.KbqFocusMonitor }], ngImport: i0, template: "@if (label()) {\n    <div class=\"kbq-inline-edit__label\">\n        <ng-content select=\"kbq-label\" />\n    </div>\n}\n\n<div class=\"kbq-inline-edit__view-container\">\n    <ng-content select=\"[kbqInlineEditViewMode]\" />\n\n    <div\n        #overlayOrigin\n        class=\"kbq-inline-edit__focus_container kbq-inline-edit__overlay-origin\"\n        cdkMonitorElementFocus\n        cdkOverlayOrigin\n        [tabIndex]=\"tabIndex()\"\n        (keydown.enter)=\"onClick($event)\"\n    ></div>\n\n    @if (menu() && mode() === 'view') {\n        <div class=\"kbq-inline-edit__menu-mask kbq-mask\">\n            <div class=\"kbq-inline-edit__menu-mask-fade kbq-mask__fade\"></div>\n            <div class=\"kbq-inline-edit__menu-mask-container kbq-mask__container\">\n                <ng-content select=\"[kbqInlineEditMenu]\" />\n            </div>\n        </div>\n    }\n\n    <ng-template\n        cdkConnectedOverlay\n        cdkConnectedOverlayLockPosition\n        [cdkConnectedOverlayOpen]=\"isEditMode()\"\n        [cdkConnectedOverlayOrigin]=\"overlayOrigin\"\n        [cdkConnectedOverlayOffsetY]=\"-overlayOrigin.offsetHeight\"\n        [cdkConnectedOverlayWidth]=\"overlayWidth()\"\n        [cdkConnectedOverlayDisableClose]=\"true\"\n        [cdkConnectedOverlayScrollStrategy]=\"scrollStrategy()\"\n        [cdkConnectedOverlayHasBackdrop]=\"false\"\n        (attach)=\"onAttach()\"\n        (overlayOutsideClick)=\"save($event)\"\n        (overlayKeydown)=\"onOverlayKeydown($event)\"\n    >\n        <div class=\"kbq-inline-edit__panel\" cdkTrapFocus cdkTrapFocusAutoCapture>\n            <div\n                class=\"kbq-inline-edit__control-container\"\n                kbqFocusRegionItem\n                [kbqTooltipColor]=\"colors.Error\"\n                [kbqTooltip]=\"validationTooltip() ?? ''\"\n                [kbqTooltipArrow]=\"false\"\n                [kbqTrigger]=\"'manual'\"\n                [kbqPlacement]=\"tooltipPlacement() ?? placements.TopLeft\"\n            >\n                <ng-content select=\"[kbqInlineEditEditMode]\" />\n            </div>\n\n            @if (showActions()) {\n                <div class=\"kbq-inline-edit__action-buttons\" role=\"group\" [@panelAnimation]>\n                    <button kbq-button [color]=\"'contrast'\" (click)=\"save($event)\">\n                        <i kbq-icon=\"kbq-check_16\"></i>\n                    </button>\n                    <button\n                        kbqFocusRegionItem\n                        kbq-button\n                        [color]=\"'contrast-fade'\"\n                        (click)=\"cancel()\"\n                        (keydown.enter)=\"cancel()\"\n                    >\n                        <i kbq-icon=\"kbq-xmark_16\"></i>\n                    </button>\n                </div>\n            }\n        </div>\n    </ng-template>\n</div>\n", styles: [".kbq-inline-edit{display:flex;flex-direction:column;justify-content:center;border-radius:var(--kbq-size-border-radius);padding:var(--kbq-inline-edit-padding-vertical) var(--kbq-inline-edit-padding-horizontal);min-height:var(--kbq-inline-edit-height);box-sizing:border-box;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)}.kbq-inline-edit.kbq-inline-edit_view:not(.kbq-inline-edit_disabled):hover{--kbq-inline-edit-background: var(--kbq-states-background-transparent-hover);--kbq-mask-background: var(--kbq-states-background-contrast-less-hover);cursor:pointer}.kbq-inline-edit.kbq-inline-edit_view:not(.kbq-inline-edit_disabled):active,.kbq-inline-edit.kbq-inline-edit_view:not(.kbq-inline-edit_disabled):has(.kbq-inline-edit__menu.kbq-active){--kbq-inline-edit-background: var(--kbq-states-background-transparent-active);--kbq-mask-background: var(--kbq-states-background-contrast-less-active)}.kbq-inline-edit.kbq-inline-edit_view.kbq-inline-edit_disabled:hover,.kbq-inline-edit.kbq-inline-edit_view.kbq-inline-edit_disabled:has(.kbq-inline-edit__menu.kbq-active){--kbq-mask-background: var(--kbq-background-bg)}.kbq-inline-edit .kbq-label{color:var(--kbq-inline-edit-label-color)}.kbq-inline-edit .kbq-inline-edit__focus_container{background:var(--kbq-inline-edit-background);border-color:var(--kbq-inline-edit-background)}.kbq-inline-edit .kbq-inline-edit__focus_container:focus-visible{outline:none}.kbq-inline-edit .kbq-inline-edit__focus_container.cdk-keyboard-focused{outline:1px solid var(--kbq-states-line-focus-theme);border-color:var(--kbq-states-line-focus-theme)}.kbq-inline-edit:not(.kbq-inline-edit_with-label){--kbq-inline-edit-padding-horizontal: calc(var(--kbq-size-m) - var(--kbq-size-border-width))}.kbq-inline-edit.kbq-inline-edit_with-label{padding-top:var(--kbq-inline-edit-padding-vertical);padding-bottom:var(--kbq-inline-edit-padding-vertical)}.kbq-inline-edit.kbq-inline-edit_with-label.kbq-inline-edit_edit .kbq-inline-edit__view-container{position:relative}.kbq-inline-edit.kbq-inline-edit_with-label .kbq-inline-edit__label{margin-bottom:var(--kbq-size-3xs)}.kbq-inline-edit.kbq-inline-edit_view .kbq-inline-edit__view-container{text-overflow:ellipsis}.kbq-inline-edit:hover .kbq-inline-edit__menu-mask,.kbq-inline-edit.cdk-keyboard-focused .kbq-inline-edit__menu-mask{opacity:1}.kbq-inline-edit .kbq-inline-edit__placeholder{color:var(--kbq-foreground-contrast-secondary)}.kbq-inline-edit{position:relative}.kbq-inline-edit .kbq-mask{display:flex;position:absolute;top:0;right:0}.kbq-inline-edit .kbq-mask .kbq-mask__fade{background:var(--kbq-mask-background, transparent);mask-image:linear-gradient(90deg,transparent,var(--kbq-black-default))}.kbq-inline-edit .kbq-mask .kbq-mask__container{background:var(--kbq-mask-background, transparent)}.kbq-inline-edit .kbq-inline-edit__menu-mask{opacity:0;height:100%;justify-content:flex-end;border-top-right-radius:var(--kbq-size-border-radius);border-bottom-right-radius:var(--kbq-size-border-radius)}.kbq-inline-edit .kbq-inline-edit__menu-mask:has(.kbq-inline-edit__menu.kbq-pressed,.kbq-inline-edit__menu.cdk-keyboard-focused){opacity:1}.kbq-inline-edit .kbq-inline-edit__menu-mask .kbq-inline-edit__menu-mask-fade{width:32px}.kbq-inline-edit .kbq-inline-edit__menu-mask .kbq-inline-edit__menu-mask-container{display:flex;justify-content:flex-end;min-width:40px;border-radius:inherit}.kbq-inline-edit .kbq-inline-edit__menu-mask .kbq-inline-edit__menu{display:inline-flex;align-self:flex-start;padding:var(--kbq-size-s);z-index:2}.kbq-inline-edit .kbq-inline-edit__focus_container{position:absolute;top:0;left:0;width:calc(100% - 2 * var(--kbq-size-border-width));height:calc(100% - 2 * var(--kbq-size-border-width));border:var(--kbq-size-border-width) solid transparent;border-radius:var(--kbq-size-border-radius);z-index:1}.kbq-inline-edit__panel{width:100%}.kbq-inline-edit__panel .kbq-inline-edit__control-container{border-radius:var(--kbq-size-border-radius)}.kbq-inline-edit__panel .kbq-inline-edit__action-buttons{position:absolute;left:calc(-1 * var(--kbq-inline-edit-padding-horizontal));display:inline-flex;flex-direction:row;gap:var(--kbq-size-xxs);padding:var(--kbq-size-xxs) var(--kbq-size-s) var(--kbq-size-s)}.kbq-inline-edit__panel .kbq-inline-edit__control-container,.kbq-inline-edit__panel .kbq-inline-edit__action-buttons>.kbq-button-icon{box-shadow:var(--kbq-shadow-popup)}\n", ":where(.kbq-inline-edit,.kbq-inline-edit__panel){--kbq-inline-edit-background: transparent;--kbq-inline-edit-height: var(--kbq-size-3xl);--kbq-inline-edit-padding-horizontal: var(--kbq-size-s);--kbq-inline-edit-padding-vertical: 5px;--kbq-inline-edit-panel-shadow: var(--kbq-shadow-popup);--kbq-inline-edit-label-color: var(--kbq-foreground-contrast-secondary)}\n"], dependencies: [{ kind: "directive", type: CdkConnectedOverlay, selector: "[cdk-connected-overlay], [connected-overlay], [cdkConnectedOverlay]", inputs: ["cdkConnectedOverlayOrigin", "cdkConnectedOverlayPositions", "cdkConnectedOverlayPositionStrategy", "cdkConnectedOverlayOffsetX", "cdkConnectedOverlayOffsetY", "cdkConnectedOverlayWidth", "cdkConnectedOverlayHeight", "cdkConnectedOverlayMinWidth", "cdkConnectedOverlayMinHeight", "cdkConnectedOverlayBackdropClass", "cdkConnectedOverlayPanelClass", "cdkConnectedOverlayViewportMargin", "cdkConnectedOverlayScrollStrategy", "cdkConnectedOverlayOpen", "cdkConnectedOverlayDisableClose", "cdkConnectedOverlayTransformOriginOn", "cdkConnectedOverlayHasBackdrop", "cdkConnectedOverlayLockPosition", "cdkConnectedOverlayFlexibleDimensions", "cdkConnectedOverlayGrowAfterOpen", "cdkConnectedOverlayPush", "cdkConnectedOverlayDisposeOnNavigation"], outputs: ["backdropClick", "positionChange", "attach", "detach", "overlayKeydown", "overlayOutsideClick"], exportAs: ["cdkConnectedOverlay"] }, { kind: "directive", type: CdkOverlayOrigin, selector: "[cdk-overlay-origin], [overlay-origin], [cdkOverlayOrigin]", exportAs: ["cdkOverlayOrigin"] }, { kind: "ngmodule", type: KbqButtonModule }, { kind: "component", type: i2.KbqButton, selector: "[kbq-button]", inputs: ["kbqStyle", "disabled", "tabIndex"] }, { kind: "directive", type: i2.KbqButtonCssStyler, selector: "[kbq-button]" }, { kind: "component", type: KbqIcon, selector: "[kbq-icon]", inputs: ["small", "autoColor", "kbq-icon"] }, { kind: "directive", type: KbqTooltipTrigger, selector: "[kbqTooltip]", inputs: ["hideWithTimeout", "kbqVisible", "kbqPlacement", "kbqRelativeToPointer", "kbqPlacementPriority", "kbqTooltip", "kbqTooltipDisabled", "kbqEnterDelay", "kbqLeaveDelay", "kbqTrigger", "kbqTooltipClass", "kbqTooltipContext", "kbqTooltipColor", "kbqTooltipArrow", "kbqTooltipOffset"], outputs: ["kbqPlacementChange", "kbqVisibleChange"], exportAs: ["kbqTooltip"] }, { kind: "directive", type: KbqFocusRegionItem, selector: "[kbqFocusRegionItem]", outputs: ["tabOut"], exportAs: ["kbqFocusRegionItem"] }, { kind: "directive", type: CdkTrapFocus, selector: "[cdkTrapFocus]", inputs: ["cdkTrapFocus", "cdkTrapFocusAutoCapture"], exportAs: ["cdkTrapFocus"] }, { kind: "directive", type: CdkMonitorFocus, selector: "[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]", outputs: ["cdkFocusChange"], exportAs: ["cdkMonitorFocus"] }], animations: [KBQ_INLINE_EDIT_ACTION_BUTTONS_ANIMATION], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEdit, decorators: [{
            type: Component,
            args: [{ standalone: true, selector: 'kbq-inline-edit', exportAs: 'kbqInlineEdit', host: {
                        class: baseClass,
                        '[class]': 'className()',
                        '[class.kbq-inline-edit_with-label]': '!!label()',
                        '[class.kbq-inline-edit_with-menu]': '!!menu()',
                        '[class.kbq-inline-edit_disabled]': 'disabled()',
                        '(click)': 'onClick($event)',
                        '(keydown.enter)': 'onClick($event)',
                        '(keydown.space)': 'onClick($event)'
                    }, hostDirectives: [KbqFocusMonitor], imports: [
                        CdkConnectedOverlay,
                        CdkOverlayOrigin,
                        KbqButtonModule,
                        KbqIcon,
                        KbqTooltipTrigger,
                        KbqFocusRegionItem,
                        CdkTrapFocus,
                        CdkMonitorFocus
                    ], animations: [KBQ_INLINE_EDIT_ACTION_BUTTONS_ANIMATION], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: "@if (label()) {\n    <div class=\"kbq-inline-edit__label\">\n        <ng-content select=\"kbq-label\" />\n    </div>\n}\n\n<div class=\"kbq-inline-edit__view-container\">\n    <ng-content select=\"[kbqInlineEditViewMode]\" />\n\n    <div\n        #overlayOrigin\n        class=\"kbq-inline-edit__focus_container kbq-inline-edit__overlay-origin\"\n        cdkMonitorElementFocus\n        cdkOverlayOrigin\n        [tabIndex]=\"tabIndex()\"\n        (keydown.enter)=\"onClick($event)\"\n    ></div>\n\n    @if (menu() && mode() === 'view') {\n        <div class=\"kbq-inline-edit__menu-mask kbq-mask\">\n            <div class=\"kbq-inline-edit__menu-mask-fade kbq-mask__fade\"></div>\n            <div class=\"kbq-inline-edit__menu-mask-container kbq-mask__container\">\n                <ng-content select=\"[kbqInlineEditMenu]\" />\n            </div>\n        </div>\n    }\n\n    <ng-template\n        cdkConnectedOverlay\n        cdkConnectedOverlayLockPosition\n        [cdkConnectedOverlayOpen]=\"isEditMode()\"\n        [cdkConnectedOverlayOrigin]=\"overlayOrigin\"\n        [cdkConnectedOverlayOffsetY]=\"-overlayOrigin.offsetHeight\"\n        [cdkConnectedOverlayWidth]=\"overlayWidth()\"\n        [cdkConnectedOverlayDisableClose]=\"true\"\n        [cdkConnectedOverlayScrollStrategy]=\"scrollStrategy()\"\n        [cdkConnectedOverlayHasBackdrop]=\"false\"\n        (attach)=\"onAttach()\"\n        (overlayOutsideClick)=\"save($event)\"\n        (overlayKeydown)=\"onOverlayKeydown($event)\"\n    >\n        <div class=\"kbq-inline-edit__panel\" cdkTrapFocus cdkTrapFocusAutoCapture>\n            <div\n                class=\"kbq-inline-edit__control-container\"\n                kbqFocusRegionItem\n                [kbqTooltipColor]=\"colors.Error\"\n                [kbqTooltip]=\"validationTooltip() ?? ''\"\n                [kbqTooltipArrow]=\"false\"\n                [kbqTrigger]=\"'manual'\"\n                [kbqPlacement]=\"tooltipPlacement() ?? placements.TopLeft\"\n            >\n                <ng-content select=\"[kbqInlineEditEditMode]\" />\n            </div>\n\n            @if (showActions()) {\n                <div class=\"kbq-inline-edit__action-buttons\" role=\"group\" [@panelAnimation]>\n                    <button kbq-button [color]=\"'contrast'\" (click)=\"save($event)\">\n                        <i kbq-icon=\"kbq-check_16\"></i>\n                    </button>\n                    <button\n                        kbqFocusRegionItem\n                        kbq-button\n                        [color]=\"'contrast-fade'\"\n                        (click)=\"cancel()\"\n                        (keydown.enter)=\"cancel()\"\n                    >\n                        <i kbq-icon=\"kbq-xmark_16\"></i>\n                    </button>\n                </div>\n            }\n        </div>\n    </ng-template>\n</div>\n", styles: [".kbq-inline-edit{display:flex;flex-direction:column;justify-content:center;border-radius:var(--kbq-size-border-radius);padding:var(--kbq-inline-edit-padding-vertical) var(--kbq-inline-edit-padding-horizontal);min-height:var(--kbq-inline-edit-height);box-sizing:border-box;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)}.kbq-inline-edit.kbq-inline-edit_view:not(.kbq-inline-edit_disabled):hover{--kbq-inline-edit-background: var(--kbq-states-background-transparent-hover);--kbq-mask-background: var(--kbq-states-background-contrast-less-hover);cursor:pointer}.kbq-inline-edit.kbq-inline-edit_view:not(.kbq-inline-edit_disabled):active,.kbq-inline-edit.kbq-inline-edit_view:not(.kbq-inline-edit_disabled):has(.kbq-inline-edit__menu.kbq-active){--kbq-inline-edit-background: var(--kbq-states-background-transparent-active);--kbq-mask-background: var(--kbq-states-background-contrast-less-active)}.kbq-inline-edit.kbq-inline-edit_view.kbq-inline-edit_disabled:hover,.kbq-inline-edit.kbq-inline-edit_view.kbq-inline-edit_disabled:has(.kbq-inline-edit__menu.kbq-active){--kbq-mask-background: var(--kbq-background-bg)}.kbq-inline-edit .kbq-label{color:var(--kbq-inline-edit-label-color)}.kbq-inline-edit .kbq-inline-edit__focus_container{background:var(--kbq-inline-edit-background);border-color:var(--kbq-inline-edit-background)}.kbq-inline-edit .kbq-inline-edit__focus_container:focus-visible{outline:none}.kbq-inline-edit .kbq-inline-edit__focus_container.cdk-keyboard-focused{outline:1px solid var(--kbq-states-line-focus-theme);border-color:var(--kbq-states-line-focus-theme)}.kbq-inline-edit:not(.kbq-inline-edit_with-label){--kbq-inline-edit-padding-horizontal: calc(var(--kbq-size-m) - var(--kbq-size-border-width))}.kbq-inline-edit.kbq-inline-edit_with-label{padding-top:var(--kbq-inline-edit-padding-vertical);padding-bottom:var(--kbq-inline-edit-padding-vertical)}.kbq-inline-edit.kbq-inline-edit_with-label.kbq-inline-edit_edit .kbq-inline-edit__view-container{position:relative}.kbq-inline-edit.kbq-inline-edit_with-label .kbq-inline-edit__label{margin-bottom:var(--kbq-size-3xs)}.kbq-inline-edit.kbq-inline-edit_view .kbq-inline-edit__view-container{text-overflow:ellipsis}.kbq-inline-edit:hover .kbq-inline-edit__menu-mask,.kbq-inline-edit.cdk-keyboard-focused .kbq-inline-edit__menu-mask{opacity:1}.kbq-inline-edit .kbq-inline-edit__placeholder{color:var(--kbq-foreground-contrast-secondary)}.kbq-inline-edit{position:relative}.kbq-inline-edit .kbq-mask{display:flex;position:absolute;top:0;right:0}.kbq-inline-edit .kbq-mask .kbq-mask__fade{background:var(--kbq-mask-background, transparent);mask-image:linear-gradient(90deg,transparent,var(--kbq-black-default))}.kbq-inline-edit .kbq-mask .kbq-mask__container{background:var(--kbq-mask-background, transparent)}.kbq-inline-edit .kbq-inline-edit__menu-mask{opacity:0;height:100%;justify-content:flex-end;border-top-right-radius:var(--kbq-size-border-radius);border-bottom-right-radius:var(--kbq-size-border-radius)}.kbq-inline-edit .kbq-inline-edit__menu-mask:has(.kbq-inline-edit__menu.kbq-pressed,.kbq-inline-edit__menu.cdk-keyboard-focused){opacity:1}.kbq-inline-edit .kbq-inline-edit__menu-mask .kbq-inline-edit__menu-mask-fade{width:32px}.kbq-inline-edit .kbq-inline-edit__menu-mask .kbq-inline-edit__menu-mask-container{display:flex;justify-content:flex-end;min-width:40px;border-radius:inherit}.kbq-inline-edit .kbq-inline-edit__menu-mask .kbq-inline-edit__menu{display:inline-flex;align-self:flex-start;padding:var(--kbq-size-s);z-index:2}.kbq-inline-edit .kbq-inline-edit__focus_container{position:absolute;top:0;left:0;width:calc(100% - 2 * var(--kbq-size-border-width));height:calc(100% - 2 * var(--kbq-size-border-width));border:var(--kbq-size-border-width) solid transparent;border-radius:var(--kbq-size-border-radius);z-index:1}.kbq-inline-edit__panel{width:100%}.kbq-inline-edit__panel .kbq-inline-edit__control-container{border-radius:var(--kbq-size-border-radius)}.kbq-inline-edit__panel .kbq-inline-edit__action-buttons{position:absolute;left:calc(-1 * var(--kbq-inline-edit-padding-horizontal));display:inline-flex;flex-direction:row;gap:var(--kbq-size-xxs);padding:var(--kbq-size-xxs) var(--kbq-size-s) var(--kbq-size-s)}.kbq-inline-edit__panel .kbq-inline-edit__control-container,.kbq-inline-edit__panel .kbq-inline-edit__action-buttons>.kbq-button-icon{box-shadow:var(--kbq-shadow-popup)}\n", ":where(.kbq-inline-edit,.kbq-inline-edit__panel){--kbq-inline-edit-background: transparent;--kbq-inline-edit-height: var(--kbq-size-3xl);--kbq-inline-edit-padding-horizontal: var(--kbq-size-s);--kbq-inline-edit-padding-vertical: 5px;--kbq-inline-edit-panel-shadow: var(--kbq-shadow-popup);--kbq-inline-edit-label-color: var(--kbq-foreground-contrast-secondary)}\n"] }]
        }], ctorParameters: () => [] });

const COMPONENTS = [
    KbqInlineEdit,
    KbqInlineEditPlaceholder,
    KbqInlineEditMenu
];
class KbqInlineEditModule {
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEditModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEditModule, imports: [KbqInlineEdit,
            KbqInlineEditPlaceholder,
            KbqInlineEditMenu], exports: [KbqInlineEdit,
            KbqInlineEditPlaceholder,
            KbqInlineEditMenu] }); }
    /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEditModule, imports: [KbqInlineEdit] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqInlineEditModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: COMPONENTS,
                    exports: COMPONENTS
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { KbqFocusRegionItem, KbqInlineEdit, KbqInlineEditMenu, KbqInlineEditModule, KbqInlineEditPlaceholder };
//# sourceMappingURL=koobiq-components-inline-edit.mjs.map
