// 定义枚举类型
export enum MessageBoxButton {
  OK = 'OK',
  OKCancel = 'OKCancel',
  YesNo = 'YesNo',
  YesNoCancel = 'YesNoCancel'
}

export enum MessageBoxImage {
  None = 'None',
  Information = 'Information',
  Warning = 'Warning',
  Error = 'Error',
  Question = 'Question'
}

export enum MessageBoxResult {
  None = 'None',
  OK = 'OK',
  Cancel = 'Cancel',
  Yes = 'Yes',
  No = 'No'
}

// 模拟 IPage 接口
export interface IPage {}

// 模拟 PageDialogBase 类
class PageDialogBase {
  InternalOpen(ownerPage: IPage, content: any, param1: boolean, defaultButton: string) {
    // 实现逻辑
  }
  Close() {
    // 实现逻辑
  }
}

export class PageMessageBox extends PageDialogBase {
  private _result: MessageBoxResult;
  private _content: any;
  public static CloseCommand = () => {};

  private _pageMessageBoxButton: MessageBoxButton = MessageBoxButton.OK;
  private _pageMessageBoxImage: MessageBoxImage = MessageBoxImage.None;

  constructor() {
    super();
    this._content = {};
  }

  get PageMessageBoxButton(): MessageBoxButton {
    return this._pageMessageBoxButton;
  }

  private set PageMessageBoxButton(value: MessageBoxButton) {
    this._pageMessageBoxButton = value;
  }

  get PageMessageBoxImage(): MessageBoxImage {
    return this._pageMessageBoxImage;
  }

  private set PageMessageBoxImage(value: MessageBoxImage) {
    this._pageMessageBoxImage = value;
  }

  public Show(
    ownerPage: IPage,
    content: any,
    caption: string | null,
    button: MessageBoxButton,
    icon: MessageBoxImage,
    defaultResult: MessageBoxResult
  ): MessageBoxResult {
    this._content = content;
    this.Title = caption || '提示信息';
    this._result = defaultResult;
    this.PageMessageBoxButton = button;
    this.PageMessageBoxImage = icon;

    let defaultButton = '';

    switch (defaultResult) {
      case MessageBoxResult.Cancel:
        defaultButton = '取消';
        break;
      case MessageBoxResult.No:
        defaultButton = '否';
        break;
      case MessageBoxResult.None:
        defaultButton = '';
        break;
      case MessageBoxResult.OK:
        defaultButton = '确定';
        break;
      case MessageBoxResult.Yes:
        defaultButton = '是';
        break;
      default:
        break;
    }

    super.InternalOpen(ownerPage, this._content, true, defaultButton);

    return this._result;
  }

  private OnExecutedRoutedEvent(parameter: string) {
    this._result = MessageBoxResult[parameter as keyof typeof MessageBoxResult];
    this.Close();
  }

  private static OnCanExecuteRoutedEvent(sender: any): boolean {
    return sender instanceof PageMessageBox;
  }
}