import { isPlatformBrowser, AsyncPipe } from '@angular/common';
import * as i0 from '@angular/core';
import { EventEmitter, PLATFORM_ID, Component, Inject, Input, Output } from '@angular/core';
import { NavBarComponent } from '@testlocallibrary/shared-kernel/components/nav-bar';
import { NavBarUrlsVM } from '@testlocallibrary/shared-kernel/models/view-models';
import { WHMCSApiEnum, CurrencyEnum, LocalStorageKeysEnum, LanguageEnum } from '@testlocallibrary/shared-kernel/models/enums';
import { AppsUrlLinksConst } from '@testlocallibrary/shared-kernel/models/constants';
import * as i1 from '@testlocallibrary/shared-kernel/services/local-storage';
import * as i2 from '@angular/router';
import * as i3 from '@testlocallibrary/shared-kernel/services/active-url-link';

const NavBarUrlsConst = {
    cartUrl: `${AppsUrlLinksConst.white}/{language}/cart/`,
    contactUsUrl: `${AppsUrlLinksConst.ldc}/{language}/contact-us-form/`,
    clientAreaUrl: WHMCSApiEnum.ProfileURL,
    loginUrl: `${AppsUrlLinksConst.white}/{language}/login/`
};

class NavBarContainerComponent {
    constructor(localStorageService, router, activeLinkService, localStorage, platformId) {
        this.localStorageService = localStorageService;
        this.router = router;
        this.activeLinkService = activeLinkService;
        this.localStorage = localStorage;
        this.platformId = platformId;
        this.navBarContentVM = [];
        this.cartCount$ = undefined;
        this.isCartVisible = false;
        this.isCurrencyVisible = false;
        this.isLanguageVisible = false;
        this.isSignInVisible = false;
        this.currency = new EventEmitter();
        this.clientInfo = {};
        this.navBarUrlsVM = new NavBarUrlsVM();
        this.url = '';
        this.activeLink = '';
        this.isBrowser = isPlatformBrowser(platformId);
        this.currency.emit(CurrencyEnum.egp);
        // if (this.isLoggedIn()) {
        //   this.clientInfo = JSON.parse(
        //     this.localStorage.getFromLocalStorage(LocalStorageKeysEnum.clientDetails)
        //   );
        // }
    }
    ngOnInit() {
        this.setNavBarUrls();
        this.activeLink = this.activeLinkService.updateActiveLink();
    }
    isLoggedIn() {
        return JSON.parse(this.localStorage.getFromLocalStorage(LocalStorageKeysEnum.clientDetails)) != null;
    }
    changeLanguage(language) {
        this.localStorageService.saveToLocalStorage(LocalStorageKeysEnum.Language, language);
        this.changeUrl(language);
    }
    changeUrl(language) {
        if (this.isBrowser) {
            if (!this.router.url.includes(`/${language}/`)) {
                this.url = this.router.url.includes('/ar/')
                    ? this.router.url.replace('/ar/', `/${language}/`)
                    : this.router.url.replace('/en/', `/${language}/`);
                window.location.href = this.url;
            }
        }
    }
    changeCurrency(currency) {
        this.localStorageService.saveToLocalStorage(LocalStorageKeysEnum.Currency, currency);
        this.currency.emit(currency);
    }
    setNavBarUrls() {
        let language = this.localStorageService.getFromLocalStorage(LocalStorageKeysEnum.Language) || LanguageEnum.En;
        this.navBarUrlsVM = NavBarUrlsConst;
        this.navBarUrlsVM.cartUrl = this.navBarUrlsVM.cartUrl?.replace('{language}', language);
        this.navBarUrlsVM.contactUsUrl = this.navBarUrlsVM.contactUsUrl?.replace('{language}', language);
        this.navBarUrlsVM.loginUrl = this.navBarUrlsVM.loginUrl?.replace('{language}', language);
    }
    onSignOutClicked() {
        this.localStorage.removeFromLocalStorage(LocalStorageKeysEnum.clientDetails);
        this.localStorage.removeFromLocalStorage(LocalStorageKeysEnum.promocode);
        location.reload();
    }
    onSignInClicked() {
        if (this.isBrowser) {
            window.location.href = '/en/login';
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NavBarContainerComponent, deps: [{ token: i1.LocalStorageService }, { token: i2.Router }, { token: i3.ActiveUrlLinkService }, { token: i1.LocalStorageService }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: NavBarContainerComponent, isStandalone: true, selector: "lib-nav-bar-container", inputs: { navBarContentVM: "navBarContentVM", cartCount$: "cartCount$", isCartVisible: "isCartVisible", isCurrencyVisible: "isCurrencyVisible", isLanguageVisible: "isLanguageVisible", isSignInVisible: "isSignInVisible" }, outputs: { currency: "currency" }, ngImport: i0, template: "<lib-nav-bar\r\n  [navBarContentVM]=\"navBarContentVM\"\r\n  [cartCount$]=\"cartCount$\"\r\n  (language)=\"changeLanguage($event)\"\r\n  [isCartVisible]=\"isCartVisible\"\r\n  [isCurrencyVisible]=\"isCurrencyVisible\"\r\n  [isLanguageVisible]=\"isLanguageVisible\"\r\n  [navBarUrlsVM]=\"navBarUrlsVM\"\r\n  [isLinkUrlActive]=\"activeLink\"\r\n  [isSignInVisible]=\"isSignInVisible\"\r\n  (currency)=\"changeCurrency($event)\"\r\n  (signOut)=\"onSignOutClicked()\"\r\n  (signIn)=\"onSignInClicked()\"\r\n  [isLoggedIn]=\"isLoggedIn()\"\r\n  [clientInfo]=\"clientInfo\"\r\n></lib-nav-bar>\r\n", styles: [""], dependencies: [{ kind: "component", type: NavBarComponent, selector: "lib-nav-bar", inputs: ["navBarContentVM", "cartCount$", "isCartVisible", "isCurrencyVisible", "isLanguageVisible", "isSignInVisible", "isLinkUrlActive", "navBarUrlsVM", "isLoggedIn", "clientInfo"], outputs: ["language", "currency", "signOut", "signIn"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NavBarContainerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'lib-nav-bar-container', standalone: true, imports: [NavBarComponent, AsyncPipe], template: "<lib-nav-bar\r\n  [navBarContentVM]=\"navBarContentVM\"\r\n  [cartCount$]=\"cartCount$\"\r\n  (language)=\"changeLanguage($event)\"\r\n  [isCartVisible]=\"isCartVisible\"\r\n  [isCurrencyVisible]=\"isCurrencyVisible\"\r\n  [isLanguageVisible]=\"isLanguageVisible\"\r\n  [navBarUrlsVM]=\"navBarUrlsVM\"\r\n  [isLinkUrlActive]=\"activeLink\"\r\n  [isSignInVisible]=\"isSignInVisible\"\r\n  (currency)=\"changeCurrency($event)\"\r\n  (signOut)=\"onSignOutClicked()\"\r\n  (signIn)=\"onSignInClicked()\"\r\n  [isLoggedIn]=\"isLoggedIn()\"\r\n  [clientInfo]=\"clientInfo\"\r\n></lib-nav-bar>\r\n" }]
        }], ctorParameters: function () { return [{ type: i1.LocalStorageService }, { type: i2.Router }, { type: i3.ActiveUrlLinkService }, { type: i1.LocalStorageService }, { type: Object, decorators: [{
                    type: Inject,
                    args: [PLATFORM_ID]
                }] }]; }, propDecorators: { navBarContentVM: [{
                type: Input
            }], cartCount$: [{
                type: Input
            }], isCartVisible: [{
                type: Input
            }], isCurrencyVisible: [{
                type: Input
            }], isLanguageVisible: [{
                type: Input
            }], isSignInVisible: [{
                type: Input
            }], currency: [{
                type: Output
            }] } });

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

export { NavBarContainerComponent, NavBarUrlsConst };
//# sourceMappingURL=testlocallibrary-shared-kernel-components-nav-bar-container.mjs.map
