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 { inject, ElementRef, DOCUMENT, CSP_NONCE, PLATFORM_ID, booleanAttribute, HostListener, HostBinding, Input, 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 */
    get _overflowX() {
        if (this.noHorizontalScroll) {
            return 'hidden';
        }
        return this._overflow;
    }
    /** @hidden */
    get _overflowY() {
        if (this.noVerticalScroll) {
            return 'hidden';
        }
        return this._overflow;
    }
    /**
     * @hidden
     */
    constructor(renderer2) {
        /** Whether overflow horizontal content should be hidden. */
        this.noHorizontalScroll = false;
        /** Whether overflow vertical content should be hidden. */
        this.noVerticalScroll = false;
        /** Whether scrollbars should be visible even if content fits. */
        this.alwaysVisible = false;
        /** @hidden */
        this._inPopover = false;
        /** @hidden */
        this.elementRef = inject(ElementRef);
        /** @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);
    }
    /** @hidden */
    get _overflow() {
        if (this.alwaysVisible) {
            return 'scroll';
        }
        return 'auto';
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: ScrollbarDirective, deps: [{ token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "20.1.4", type: ScrollbarDirective, isStandalone: true, selector: "[fdScrollbar], [fd-scrollbar]", inputs: { noHorizontalScroll: ["noHorizontalScroll", "noHorizontalScroll", booleanAttribute], noVerticalScroll: ["noVerticalScroll", "noVerticalScroll", booleanAttribute], alwaysVisible: ["alwaysVisible", "alwaysVisible", booleanAttribute] }, host: { listeners: { "scroll": "onScroll($event)" }, properties: { "style.overflow-x": "this._overflowX", "style.overflow-y": "this._overflowY" }, classAttribute: "fd-scrollbar" }, hostDirectives: [{ directive: i1.CdkScrollable }], ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: ScrollbarDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[fdScrollbar], [fd-scrollbar]',
                    host: {
                        class: 'fd-scrollbar'
                    },
                    hostDirectives: [CdkScrollable],
                    standalone: true
                }]
        }], ctorParameters: () => [{ type: i0.Renderer2 }], propDecorators: { noHorizontalScroll: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], noVerticalScroll: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], alwaysVisible: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], _overflowX: [{
                type: HostBinding,
                args: ['style.overflow-x']
            }], _overflowY: [{
                type: HostBinding,
                args: ['style.overflow-y']
            }], onScroll: [{
                type: HostListener,
                args: ['scroll', ['$event']]
            }] } });

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