import { ChangeDetectorRef, Component, Input, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; import { CommonModule } from '@angular/common'; import { MatToolbarModule } from '@angular/material/toolbar'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { MatDrawer, MatSidenavModule } from '@angular/material/sidenav'; import { Router} from '@angular/router'; import { MediaMatcher } from '@angular/cdk/layout'; import { AppMenuComponent } from '../app-menu/app-menu.component'; import { MatTooltipModule } from '@angular/material/tooltip'; import { CredentialService } from '../../services/credential.service'; import { FormControl,ReactiveFormsModule } from '@angular/forms'; import { SharedStateService } from '../../services/shared-state.service'; import { Location } from '@angular/common'; @Component({ selector: 'app-layout', imports: [CommonModule, MatToolbarModule, MatSidenavModule, MatButtonModule, MatIconModule, AppMenuComponent, MatTooltipModule,ReactiveFormsModule], templateUrl: './app-layout.component.html', styleUrl: './app-layout.component.scss', standalone: true, }) export class AppLayoutComponent implements OnInit, OnDestroy { @ViewChild(MatDrawer, { static: false }) drawer?: MatDrawer; mediaQuery: MediaQueryList; mediaQueryListener: () => void; sideNavOpen = false; searchValue = new FormControl(''); constructor(public credentialService: CredentialService, public router: Router, private location:Location, private state: SharedStateService, public changeDetector: ChangeDetectorRef, media: MediaMatcher) { this.mediaQuery = media.matchMedia('(max-width: 600px)'); this.mediaQueryListener = () => { this.sideNavOpen = !this.mediaQuery.matches changeDetector.detectChanges(); } } toggle() { if (this.drawer) { this.drawer.toggle(); } } ngOnInit() { this.sideNavOpen = !this.mediaQuery.matches; this.mediaQuery.addEventListener('change', this.mediaQueryListener); } ngOnDestroy(): void { this.mediaQuery.removeEventListener('change', this.mediaQueryListener); } logout() { this.credentialService.logoutAcount(); this.router.navigate(['/']) } startSearch(){ console.log("updated to", this.searchValue.value,this.router.url) if (this.router.url.startsWith('/persons')) { this.router.navigate(['/persons']); } this.state.searchValue.set(this.searchValue.value); } navigateBack(){ this.location.back() } }