import {MatDialog, MatDialogConfig} from '@angular/material';
import {Resource} from 'ngx-jsonapi';
import {DialogComponent} from './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);
    }

    openWithDataAndWidth<T>(componentOrTemplateRef, resource: Resource, width: string) {
        const dialogConfig = new MatDialogConfig();
        dialogConfig.disableClose = true;
        dialogConfig.autoFocus = true;
        dialogConfig.data = resource;
        dialogConfig.width = width;
        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);
    }
}
