import { ChangeDetectionStrategy, Component } from '@angular/core';
import { DialogContentDirective } from '../dialog-content.directive';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { isaActionCheck } from '@isa/icons';
import { asapScheduler } from 'rxjs';

/**
 * Input data for the message dialog
 */
export interface FeedbackDialogData {
  /** The message text to display in the dialog */
  message: string;
  /** Optional flag to control whether the dialog auto-closes (default is true) */
  autoClose?: boolean;
  /** Optional delay in milliseconds before the dialog auto-closes (default is 1500ms) */
  autoCloseDelay?: number;
}

/**
 * A simple feedback dialog component that displays a message and an icon.
 * The dialog can be configured to auto-close after a short delay.
 */
@Component({
  selector: 'ui-feedback-dialog',
  templateUrl: './feedback-dialog.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [NgIcon],
  providers: [provideIcons({ isaActionCheck })],
  host: {
    '[class]': '["ui-feedback-dialog"]',
  },
})
export class FeedbackDialogComponent extends DialogContentDirective<
  FeedbackDialogData,
  void
> {
  constructor() {
    super();
    if (this.data?.autoClose ?? true) {
      asapScheduler.schedule(
        () => this.close(),
        this.data?.autoCloseDelay ?? 1500,
      );
    }
  }
}
