import { Directive, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { NumberInput, coerceNumberProperty } from '@angular/cdk/coercion';

@Directive({ selector: '[sharedOnInit]', standalone: true })
export class OnInitDirective implements OnInit {
  @Output('sharedOnInit') onInit = new EventEmitter<void>();

  @Input('sharedOnInitDelay')
  delay: NumberInput = 0;

  constructor() {}

  ngOnInit(): void {
    setTimeout(() => this.onInit.emit(), coerceNumberProperty(this.delay));
  }
}
