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

@Component({
  selector: 'abstract-dialog',
  template: '',
})
export abstract class AbstractDialog {
  @Input({ required: true })
  set visible(v: boolean) {
    this.visibleSignal.set(!!v);
    this.visibleChange.emit(!!v);
    if (!v) {
      this.onClose.emit();
    }
  }
  get visible() {
    return this.visibleSignal();
  }
  private visibleSignal = signal(false);

  @Output() onClose = new EventEmitter<void>();

  close() {
    this.visible = false;
  }

  @Output() visibleChange = new EventEmitter<boolean>();
}
