import {MatDialog, MatDialogConfig} from '@angular/material';
import {Resource} from 'ngx-jsonapi';
import {ComponentType} from '@angular/cdk/typings/portal';
import {TemplateRef} from '@angular/core';
import {DialogComponent} from './baseComponent/dialog/dialog.component';

export class Dialog extends MatDialog {


    /**
     * @param componentOrTemplateRef  baray baz kardan dialog marbot be component khodesh
     * @param {Resource} resource
     * @returns {MatDialogRef<any>}
     */
    openWithData<T>(componentOrTemplateRef , resource?: Resource) {
        const dialogConfig = new MatDialogConfig();
        dialogConfig.disableClose = true;
        dialogConfig.autoFocus = true;
        dialogConfig.data = resource;
        dialogConfig.width = '50%';
        return super.open(componentOrTemplateRef, dialogConfig);
    }

    openForAlert(message: string) {
        const dialogConfig = new MatDialogConfig();
        dialogConfig.disableClose = true;
        dialogConfig.autoFocus = true;
        dialogConfig.width = '50%';
        dialogConfig.data = {
            message: message,
            type: 'alert'
        };
        return super.open(DialogComponent, dialogConfig);

    }

}
