import { Injectable } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { ComponentType } from '@angular/cdk/portal';
import { BaseButtonService } from './base-button.service';

@Injectable({
  providedIn: 'root'
})
export class CreationService extends BaseButtonService {

  public component: ComponentType<unknown> | undefined
  public width: string = "50vw";

  constructor(private readonly dialog: MatDialog) {
    super()
  }

  openDialog(): MatDialogRef<unknown, any> | undefined {
    return this.component
      ? this.dialog.open(this.component, {
        width: this.width
      })
      : undefined;
  }

  disposeComponent(){
    this.component = undefined;
  }
}