import { Component, ElementRef, HostListener, Input, OnInit, } from "@angular/core"; import * as cookie from "cookie"; import { DefaultLocationUtils } from "../../browser.security.helper"; import { Defaults } from "../../default.constants"; import { ImpersonateHelper } from "../../impersonate.helper"; import { CustomWindow } from "../../custom/custom.window"; declare const window: CustomWindow; @Component({ selector: "rss-uc-header-profile", templateUrl: "./uc-header-profile.component.html", styleUrls: [ "./uc-header-profile.component.scss", "../uc-header.component.scss", ], }) export class UcHeaderProfileComponent implements OnInit { @Input() profile; @Input() profileUrl; @Input() ucSafetyUrl; @Input() config; @Input() environment; isMenuOpen: boolean = false; spoofEnabled: boolean = false; isSpoofed: boolean = false; constructor(private element: ElementRef) {} ngOnInit() { this.spoofEnabled = ImpersonateHelper.hasImpersonateAccess(); if (this.config.SPOOF_URL === undefined || this.config.SPOOF_URL === "") { this.config.SPOOF_URL = this.ucSafetyUrl; this.spoofEnabled = false; } this.isSpoofed = this.spoofEnabled && !!cookie.parse(document.cookie)[Defaults.SPOOF_USER_KEY]; } signOut() { const browserSecurity = new window.BrowserSecurity( DefaultLocationUtils, "/auth" ); browserSecurity.logout("/"); } toggleMenu() { this.isMenuOpen = !this.isMenuOpen; return false; } @HostListener("document:click", ["$event.target"]) public onClick(targetElement) { if (!this.element.nativeElement.contains(targetElement)) { this.isMenuOpen = false; } } }