// 模拟 IPage 接口
interface IPage {
    // 可根据实际情况添加接口方法
}

// 模拟 Key 类型
type Key = string;

// 模拟 RoutedEventArgs 类型
class RoutedEventArgs {
    constructor() {}
}

// 模拟 FrameworkPropertyMetadata 类型
class FrameworkPropertyMetadata {
    constructor(type: any) {}
}

// 模拟 Panel 类型
class Panel {
    children: HTMLElement[] = [];
    inputBindings: any[] = [];
    addChild(child: HTMLElement) {
        this.children.push(child);
    }
    addInputBinding(binding: any) {
        this.inputBindings.push(binding);
    }
}

// 模拟 StackPanel 类型
class StackPanel extends Panel {}

// 模拟 TextBlock 类型
class TextBlock {
    textContent: string = '';
}

// 模拟 Button 类型
class Button {
    content: string = '';
    command: DelegateCommand | null = null;
    verticalAlignment: string = 'center';
}

// 模拟 KeyBinding 类型
class KeyBinding {
    key: Key;
    command: DelegateCommand;
    constructor(key: Key, command: DelegateCommand) {
        this.key = key;
        this.command = command;
    }
}

// 模拟 PageDialogBase 类
class PageDialogBase {
    InternalOpen(ownerPage: IPage, dialog: any, param1: boolean, param2: string) {}
    Close() {}
}

// 定义 DelegateCommand 类
class DelegateCommand {
    private excuteDelegate: ((parameter: any) => void) | null = null;

    constructor(excuteDelegate: (parameter: any) => void) {
        this.excuteDelegate = excuteDelegate;
    }

    CanExecute(parameter: any): boolean {
        return true;
    }

    CanExecuteChanged: (() => void) | null = null;

    Execute(parameter: any) {
        if (this.excuteDelegate) {
            this.excuteDelegate(parameter);
        }
    }
}

// 定义 PageMessageBoxExt 类
class PageMessageBoxExt extends PageDialogBase {
    private _pageContent: { [key: string]: string } | null = null;
    MessageDialogMode: Key = '';
    PageMessage: string = '';

    static {
        // 模拟样式键设置
    }

    constructor(
        ownerPage: IPage,
        messageBoxText: string,
        Content: { [key: string]: string },
        DefaultFocus: Key = ''
    ) {
        super();
        this.PageMessage = messageBoxText;
        this._pageContent = Content;
        // 模拟 Loaded 事件
        this.MessageBoxExt_Loaded(null, new RoutedEventArgs());
        // 模拟窗口启动位置设置
        super.InternalOpen(ownerPage, this, false, DefaultFocus);
    }

    private ChangeCommand(key: Key) {
        this.MessageDialogMode = key;
        super.Close();
    }

    private MessageBoxExt_Loaded(sender: any, e: RoutedEventArgs) {
        const _btnPanel = new StackPanel();
        const block = new TextBlock();
        block.textContent = this.PageMessage;
        if (this._pageContent) {
            this.SetButtonContentHotkey(_btnPanel, this._pageContent);
        }
    }

    private SetButtonContentHotkey(
        panelContainer: Panel,
        contentHotKey: { [key: string]: string }
    ) {
        for (const key in contentHotKey) {
            if (contentHotKey.hasOwnProperty(key)) {
                const k = key;
                const kb = new KeyBinding(k, new DelegateCommand(() => this.ChangeCommand(k)));
                const b = new Button();
                b.content = `${contentHotKey[k]}(${k})`;
                b.command = new DelegateCommand(() => this.ChangeCommand(k));
                panelContainer.addChild(b as unknown as HTMLElement);
                panelContainer.addInputBinding(kb);
            }
        }
    }
}

export { PageMessageBoxExt };