import * as i0 from '@angular/core';
import { EventEmitter, Directive, Input, Output, ViewChild } from '@angular/core';
import { isNullOrUndefined, isUndefined } from '@ironsource/fusion-ui/utils';
import { BehaviorSubject } from 'rxjs';
import * as i1 from '@ironsource/fusion-ui/services/window';

var HeaderSizes;
(function (HeaderSizes) {
    HeaderSizes[HeaderSizes["Normal"] = 0] = "Normal";
    HeaderSizes[HeaderSizes["Small"] = 1] = "Small";
})(HeaderSizes || (HeaderSizes = {}));

const _c0 = ["header"];
class HeaderOverlayBaseComponent {
    set isOpen(value) {
        this.isOverlayOpen = value;
        this.isOpened.emit(this.isOverlayOpen);
    }
    get isOpen() {
        return this.isOverlayOpen;
    }
    constructor(windowRef, elemRef, cd) {
        this.windowRef = windowRef;
        this.elemRef = elemRef;
        this.cd = cd;
        this.width = '100%';
        this.height = '';
        this.showFooter = true;
        this.clickOutsideActivate = true;
        this.closed = new EventEmitter();
        this.saved = new EventEmitter();
        this.isOpened = new EventEmitter();
        this.headerSizes = HeaderSizes;
        this.propagateChange = (_) => { };
    }
    ngOnInit() {
        this.headerComponentData$ = new BehaviorSubject({
            isActive: this.isActive,
            isOpen: this.isOpen,
            componentData: this.componentData
        });
    }
    toggleOverlay() {
        const position = this.elemRef.nativeElement.getBoundingClientRect();
        this.side = 'right';
        if (this.windowRef.nativeWindow.screen.width - position.x < window.screen.width / 2) {
            this.side = 'left';
        }
        this.isOpen = !this.isOpen;
    }
    close() {
        if (this.isOpen) {
            this.isOpen = false;
            this.closed.emit();
        }
    }
    onOutsideClick() {
        this.close();
    }
    writeValue(value) {
        if (!isNullOrUndefined(value)) {
            this.componentData = value;
            if (!isUndefined(value.isOpen)) {
                this.isOpen = value.isOpen;
            }
            if (!isUndefined(value.isActive)) {
                this.isActive = value.isActive;
            }
            if (!isUndefined(value.error)) {
                this.error = value.error;
            }
            this.headerComponentData$.next({
                isActive: this.isActive,
                isOpen: this.isOpen,
                componentData: this.componentData
            });
        }
    }
    registerOnChange(fn) {
        this.propagateChange = fn;
    }
    registerOnTouched(fn) { }
    static { this.ɵfac = function HeaderOverlayBaseComponent_Factory(t) { return new (t || HeaderOverlayBaseComponent)(i0.ɵɵdirectiveInject(i1.WindowService), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: HeaderOverlayBaseComponent, viewQuery: function HeaderOverlayBaseComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(_c0, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.header = _t.first);
        } }, inputs: { headerComponent: "headerComponent", width: "width", height: "height", showFooter: "showFooter", size: "size", element: "element", clickOutsideActivate: "clickOutsideActivate" }, outputs: { closed: "closed", saved: "saved", isOpened: "isOpened" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(HeaderOverlayBaseComponent, [{
        type: Directive
    }], () => [{ type: i1.WindowService }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }], { headerComponent: [{
            type: Input
        }], width: [{
            type: Input
        }], height: [{
            type: Input
        }], showFooter: [{
            type: Input
        }], size: [{
            type: Input
        }], element: [{
            type: Input
        }], clickOutsideActivate: [{
            type: Input
        }], closed: [{
            type: Output
        }], saved: [{
            type: Output
        }], isOpened: [{
            type: Output
        }], header: [{
            type: ViewChild,
            args: ['header']
        }] }); })();

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

export { HeaderOverlayBaseComponent, HeaderSizes };
//# sourceMappingURL=ironsource-fusion-ui-components-header-overlay-common-base.mjs.map
