import * as i0 from '@angular/core';
import { EventEmitter, ElementRef, Directive, ViewChild, Input, Output } from '@angular/core';
import { isNullOrUndefined } from '@ironsource/fusion-ui/utils';
import * as i1 from '@ironsource/fusion-ui/services/stogare';
import { StorageType } from '@ironsource/fusion-ui/services/stogare';

const _c0 = ["menuAction"];
class HeaderBaseComponent {
    set menuAction(value) {
        this.onMenuActionChanged(value);
    }
    set state(value) {
        this.onStateChanged(value);
    }
    get state() {
        return this._state;
    }
    get menuAction() {
        return this._menuAction;
    }
    constructor(renderer, storageService) {
        this.renderer = renderer;
        this.storageService = storageService;
        this.primaryMenuIconName = { iconName: 'user', iconVersion: 'v1' };
        this.menuItemClick = new EventEmitter();
        this.menuStateChanged = new EventEmitter();
        this.logoClick = new EventEmitter();
        this.userData = {};
        this.isUserMenuOpened = false;
        this.isHelpMenuOpened = false;
    }
    changeMenuState() {
        this.isMainMenuCollapsed = !this.isMainMenuCollapsed;
        this.storageService.set(StorageType.SessionStorage, 'menuCollapsed', this.isMainMenuCollapsed);
        // this.windowRef.nativeWindow.sessionStorage.setItem('menuCollapsed', JSON.stringify(this.isMainMenuCollapsed));
        this.menuStateChanged.emit(this.isMainMenuCollapsed);
    }
    onOutsideMenuClick(target) {
        if (isNullOrUndefined(target.closest('fusion-dynamic-components.menu-item-content'))) {
            this.isUserMenuOpened = false;
        }
    }
    onUserMenuClicked() {
        this.isUserMenuOpened = !this.isUserMenuOpened;
    }
    onMenuItemClicked(event, item) {
        event.preventDefault();
        this.menuItemClick.emit(item);
    }
    onHelpMenuClicked() {
        this.isHelpMenuOpened = !this.isHelpMenuOpened;
    }
    onOutsideHelpMenuClick(target) {
        if (isNullOrUndefined(target.closest('fusion-dynamic-components.menu-item-content'))) {
            this.isHelpMenuOpened = false;
        }
    }
    onLogoClicked($event) {
        $event.preventDefault();
        this.logoClick.emit();
    }
    onStateChanged(value) {
        if (this._state && this._state.element) {
            this.clearMenuActionContent();
        }
        if (value && value.element) {
            this.handleMenuActionElement(value.element);
        }
        this._state = value;
    }
    onMenuActionChanged(value) {
        this._menuAction = value;
        if (value && this.state && this.state.element) {
            this.handleMenuActionElement(this.state.element);
        }
    }
    handleMenuActionElement(element) {
        const nativeElem = this.menuAction ? this.menuAction.nativeElement : null;
        if (nativeElem) {
            this.clearMenuActionContent();
            this.renderer.appendChild(nativeElem, element);
        }
    }
    clearMenuActionContent() {
        const nativeElem = this.menuAction ? this.menuAction.nativeElement : null;
        while (nativeElem && nativeElem.firstChild) {
            this.renderer.removeChild(nativeElem, nativeElem.firstChild);
        }
    }
    static { this.ɵfac = function HeaderBaseComponent_Factory(t) { return new (t || HeaderBaseComponent)(i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i1.StorageService)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: HeaderBaseComponent, viewQuery: function HeaderBaseComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(_c0, 5, ElementRef);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.menuAction = _t.first);
        } }, inputs: { primaryMenuIconName: "primaryMenuIconName", primaryMenuItems: "primaryMenuItems", secondaryMenuItems: "secondaryMenuItems", userName: "userName", headerMenuUserNameIcon: "headerMenuUserNameIcon", state: "state", isMainMenuCollapsed: "isMainMenuCollapsed" }, outputs: { menuItemClick: "menuItemClick", menuStateChanged: "menuStateChanged", logoClick: "logoClick" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(HeaderBaseComponent, [{
        type: Directive
    }], () => [{ type: i0.Renderer2 }, { type: i1.StorageService }], { menuAction: [{
            type: ViewChild,
            args: ['menuAction', { read: ElementRef }]
        }], primaryMenuIconName: [{
            type: Input
        }], primaryMenuItems: [{
            type: Input
        }], secondaryMenuItems: [{
            type: Input
        }], userName: [{
            type: Input
        }], headerMenuUserNameIcon: [{
            type: Input
        }], state: [{
            type: Input
        }], isMainMenuCollapsed: [{
            type: Input
        }], menuItemClick: [{
            type: Output
        }], menuStateChanged: [{
            type: Output
        }], logoClick: [{
            type: Output
        }] }); })();

const MENU_OPTIONS_DEFUALT_VALUE = {
    svgOptions: { assetsPath: '' }
};

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

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