import { MatDialog } from "@angular/material/dialog";
import { CompComfirmDialogComponent } from "../app/comp-comfirm-dialog/comp-comfirm-dialog.component";
import { CompEditObjectComponent } from "../app/comp-table/comp-edit-object/comp-edit-object.component";


export interface ParseSchema{
    title:string,
    subTitle?:string,
    className:string,
    fieldsArray:Array<ParseField>,
    include?:Array<string>,
    buttons?:Array<any>,
    emptyImg?:String,
    emptyDesc?:String,
}
export interface ParseField{
  key:string
  name:string
  type:string
  isDisabled?:boolean
  targetClass?:string
  showName?:string
  isHeader?:boolean
  options?:Array<ParseFiledOption>
}
export interface ParseFiledOption{
  label:string
  value:string
}

/**
   * 创建集装箱
   * @param dialog 
   * @param cluster 
   * @param afterClosed 
   */
 export function openObjectEditDialog(dialog: MatDialog,schema:ParseSchema, object?: Parse.Object, afterClosed?: Function): void {
    let dialogRef = dialog.open(CompEditObjectComponent, {
      data: {
        title: schema?.title,
        fieldsArray: schema?.fieldsArray,
        default: {
        //   center: this.center?.toPointer(),
        //   type: "cluster",
        //   isOnline: true,
        },
        schema:schema,
        object: object,
      },
    });

    dialogRef.afterClosed().subscribe(result => {
      console.log('The dialog was closed', result);
      afterClosed && afterClosed(result)
    });
  }
  export function confirmDialog(dialog:MatDialog, options: {
    title: string,
    mode?: string,
    danger?: boolean,
    message?: string,
    handleOK?: Function
  }) {
    let dialogRef = dialog.open(CompComfirmDialogComponent, {
      data: {
        title: options?.title,
        message: options?.message,
        mode: options?.mode,
        danger: options?.danger,
      },
    });

    dialogRef.afterClosed().subscribe(isOK => {
      isOK && options?.handleOK && options?.handleOK()
    });
  }