import { Component, ElementRef, OnDestroy, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { ActiveSidebarService } from 'src/app/core/services/active-sidebar.service';

@Component({
  templateUrl: './base.component.html',
  selector: 'app-base',
})
export class BaseComponent  {
  constructor(public ChcekSidebar: ActiveSidebarService) {}

  @ViewChild('headerElement') headerElement!: ElementRef;
  headerHeight: number = 0;
  resizeObserver!: ResizeObserver;
  ngAfterViewInit() {
    this.resizeObserver = new ResizeObserver(entries => {
      for (let entry of entries) {
        if (entry.target === this.headerElement.nativeElement) {
          this.headerHeight = entry.contentRect.height;
        }
      }
    });
    
    if (this.headerElement && this.headerElement.nativeElement) {
      this.resizeObserver.observe(this.headerElement.nativeElement);
    }
  }

  ngOnDestroy() {
    if (this.resizeObserver && this.headerElement && this.headerElement.nativeElement) {
      this.resizeObserver.unobserve(this.headerElement.nativeElement);
    }
  }
}
