import * as i1 from '@angular/cdk/overlay';
import { CdkScrollable } from '@angular/cdk/overlay';
import { isPlatformBrowser } from '@angular/common';
import * as i0 from '@angular/core';
import { input, booleanAttribute, inject, ElementRef, computed, DOCUMENT, CSP_NONCE, PLATFORM_ID, Directive, NgModule } from '@angular/core';
import scrollbarStyles from 'fundamental-styles/dist/js/scrollbar';

let scrollbarElementsQuantity = 0;
let styleSheet = null;
/**
 * The scrollbar directive.
 *
 * Children usage:
 * ```html
 * <div fd-scrollbar>
 * <div fd-scrollbar noVerticalScroll>
 * <div fd-scrollbar [noVerticalScroll]="true">
 * <div fd-scrollbar noHorizontalScroll>
 * <div fd-scrollbar [noHorizontalScroll]="true">
 * ```
 */
class ScrollbarDirective {
    /**
     * @hidden
     */
    constructor(renderer2) {
        /** Whether overflow horizontal content should be hidden. */
        this.noHorizontalScroll = input(false, { ...(ngDevMode ? { debugName: "noHorizontalScroll" } : {}), transform: booleanAttribute });
        /** Whether overflow vertical content should be hidden. */
        this.noVerticalScroll = input(false, { ...(ngDevMode ? { debugName: "noVerticalScroll" } : {}), transform: booleanAttribute });
        /** Whether scrollbars should be visible even if content fits. */
        this.alwaysVisible = input(false, { ...(ngDevMode ? { debugName: "alwaysVisible" } : {}), transform: booleanAttribute });
        /** @hidden Whether the scrollbar is inside a popover and should stop scroll event propagation. */
        this._inPopover = false;
        /** @hidden */
        this.elementRef = inject(ElementRef);
        /** @hidden */
        this._overflowX = computed(() => this.noHorizontalScroll() ? 'hidden' : this.alwaysVisible() ? 'scroll' : 'auto', ...(ngDevMode ? [{ debugName: "_overflowX" }] : []));
        /** @hidden */
        this._overflowY = computed(() => this.noVerticalScroll() ? 'hidden' : this.alwaysVisible() ? 'scroll' : 'auto', ...(ngDevMode ? [{ debugName: "_overflowY" }] : []));
        /** @hidden */
        this._document = inject(DOCUMENT);
        /** @hidden */
        this._csp_nonce = inject(CSP_NONCE, {
            optional: true
        });
        scrollbarElementsQuantity++;
        const platform = inject(PLATFORM_ID);
        if (!styleSheet && isPlatformBrowser(platform)) {
            styleSheet = renderer2.createElement('style');
            styleSheet.innerHTML = scrollbarStyles.cssSource;
            if (this._csp_nonce) {
                styleSheet?.setAttribute('nonce', this._csp_nonce);
            }
            renderer2.appendChild(this._document.head, styleSheet);
        }
    }
    /** @hidden */
    onScroll(event) {
        if (this._inPopover) {
            event.stopImmediatePropagation();
        }
    }
    /** @hidden */
    ngOnDestroy() {
        if (--scrollbarElementsQuantity === 0) {
            styleSheet?.remove();
            styleSheet = null;
        }
    }
    /** method to invoke scroll */
    scroll(options) {
        this.elementRef.nativeElement.scroll(options);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ScrollbarDirective, deps: [{ token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.0", type: ScrollbarDirective, isStandalone: true, selector: "[fdScrollbar], [fd-scrollbar]", inputs: { noHorizontalScroll: { classPropertyName: "noHorizontalScroll", publicName: "noHorizontalScroll", isSignal: true, isRequired: false, transformFunction: null }, noVerticalScroll: { classPropertyName: "noVerticalScroll", publicName: "noVerticalScroll", isSignal: true, isRequired: false, transformFunction: null }, alwaysVisible: { classPropertyName: "alwaysVisible", publicName: "alwaysVisible", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "scroll": "onScroll($event)" }, properties: { "style.overflow-x": "_overflowX()", "style.overflow-y": "_overflowY()" }, classAttribute: "fd-scrollbar" }, hostDirectives: [{ directive: i1.CdkScrollable }], ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ScrollbarDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[fdScrollbar], [fd-scrollbar]',
                    host: {
                        class: 'fd-scrollbar',
                        '[style.overflow-x]': '_overflowX()',
                        '[style.overflow-y]': '_overflowY()',
                        '(scroll)': 'onScroll($event)'
                    },
                    hostDirectives: [CdkScrollable]
                }]
        }], ctorParameters: () => [{ type: i0.Renderer2 }], propDecorators: { noHorizontalScroll: [{ type: i0.Input, args: [{ isSignal: true, alias: "noHorizontalScroll", required: false }] }], noVerticalScroll: [{ type: i0.Input, args: [{ isSignal: true, alias: "noVerticalScroll", required: false }] }], alwaysVisible: [{ type: i0.Input, args: [{ isSignal: true, alias: "alwaysVisible", required: false }] }] } });

/**
 * @deprecated
 * Use direct imports of components and directives.
 */
class ScrollbarModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ScrollbarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.1.0", ngImport: i0, type: ScrollbarModule, imports: [ScrollbarDirective], exports: [ScrollbarDirective] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ScrollbarModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: ScrollbarModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [ScrollbarDirective],
                    exports: [ScrollbarDirective]
                }]
        }] });

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

export { ScrollbarDirective, ScrollbarModule };
//# sourceMappingURL=fundamental-ngx-core-scrollbar.mjs.map
