// 假设 MultilevelMenuItemLeaf 类型的定义
class MultilevelMenuItemLeaf {
    // 这里可以添加 MultilevelMenuItemLeaf 的属性和方法
}

// 事件总线类，用于模拟路由事件
class EventBus {
    private events: { [key: string]: Function[] } = {};

    on(eventName: string, callback: Function) {
        if (!this.events[eventName]) {
            this.events[eventName] = [];
        }
        this.events[eventName].push(callback);
    }

    off(eventName: string, callback: Function) {
        if (this.events[eventName]) {
            this.events[eventName] = this.events[eventName].filter(cb => cb !== callback);
        }
    }

    emit(eventName: string, ...args: any[]) {
        if (this.events[eventName]) {
            this.events[eventName].forEach(cb => cb(...args));
        }
    }
}

class MultilevelMenu {
    private eventBus: EventBus = new EventBus();
    public focusable: boolean = true;

    constructor() {
        this.focusable = true;
    }

    private raiseRoutedEvent(source: any, eventName: string) {
        // 简单模拟 TemplatedParent 和 ToggleButton 的判断
        if (source && source.templatedParent && source.templatedParent.isToggleButton) {
            return;
        }
        this.eventBus.emit(eventName);
    }

    public onMouseLeftClickItem(callback: () => void) {
        this.eventBus.on("MouseLeftClickItem", callback);
    }

    public offMouseLeftClickItem(callback: () => void) {
        this.eventBus.off("MouseLeftClickItem", callback);
    }

    public onPreviewMouseLeftButtonDown(e: any) {
        this.raiseRoutedEvent(e.originalSource, "MouseLeftClickItem");
    }

    public openItemEvent: ((leaf: MultilevelMenuItemLeaf) => void)[] = [];

    public onOpenItem(callback: (leaf: MultilevelMenuItemLeaf) => void) {
        this.openItemEvent.push(callback);
    }
    //TODO 后续在处理
    // internal  raiseOpenItemEvent(leaf: MultilevelMenuItemLeaf) {
    //     this.openItemEvent.forEach(callback => callback(leaf));
    // }
}

export { MultilevelMenu, MultilevelMenuItemLeaf };
