import {
  Component,
  EventEmitter,
  HostListener,
  Input,
  OnInit,
  Output,
  signal,
} from '@angular/core';

@Component({
  selector: 'abstract-isMobile',
  template: '',
})
export class AbstractIsMobileComponent implements OnInit {
  @Input() mobileBreakpoint = 768;

  @Output() onHide = new EventEmitter<any>();

  isMobile = signal(false);

  ngOnInit() {
    this.updateViewportMode();
  }

  @HostListener('window:resize')
  onResize() {
    this.updateViewportMode();
  }

  private updateViewportMode() {
    this.isMobile.set(typeof window !== 'undefined' && window.innerWidth <= this.mobileBreakpoint);
  }
}
