import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog';
import { Directive, inject } from '@angular/core';
import { DialogComponent } from './dialog.component';

/**
 * Base directive for dialog content components
 * Provides common dialog functionality and styling
 *
 * @template D Type of the data passed to the dialog
 * @template R Type of the result returned when the dialog closes
 */
@Directive({
  host: {
    '[class]': '["ui-dialog-content"]',
  },
})
export abstract class DialogContentDirective<D, R> {
  readonly dialog = inject(DialogComponent<D, R, DialogContentDirective<D, R>>);

  /** Reference to the dialog instance */
  readonly dialogRef = inject(DialogRef<R, DialogContentDirective<D, R>>);

  /** Data passed to the dialog */
  readonly data = inject(DIALOG_DATA) as D;

  /**
   * Closes the dialog with the specified result
   * @param result The value to return from the dialog
   */
  close(result: R): void {
    this.dialogRef.close(result);
  }
}
