// 假设 MultilevelMenuItemBase 和 MultilevelMenu 类在其他地方定义
class MultilevelMenuItemBase {
    // 这里可以添加 MultilevelMenuItemBase 的属性和方法，当前为空
}

class MultilevelMenu {
    static MouseLeftClickItemEvent: any;
}

// 扩充属性类
class MultMenuTreeItemLeafAppendProperty {
    Key: string;
    Value: string;

    constructor() {
        this.Key = '';
        this.Value = '';
    }
}

class MultilevelMenuItemLeaf extends MultilevelMenuItemBase {
    private _treeItemLeafAppendPropertyCollection: MultMenuTreeItemLeafAppendProperty[] = [];
    MenuCode: string;
    Action: string;
    Title: string;
    Tag: string;
    Rights: string;

    constructor() {
        super();
        this.MenuCode = '';
        this.Action = '';
        this.Title = '';
        this.Tag = '';
        this.Rights = '';
    }

    OnPreviewMouseLeftButtonDown(e: any) {
        //TODO缺少方法 原始文件中没有这个方法 这个是微软系统自带的方法需要业务重写
        //super.OnPreviewMouseLeftButtonDown && super.OnPreviewMouseLeftButtonDown(e);
        this.RaiseRoutedEvent(e.OriginalSource as HTMLElement, MultilevelMenu.MouseLeftClickItemEvent);
    }

    private RaiseRoutedEvent(source: HTMLElement, routedEvent: any) {
        // 如果单击的是展开按钮，则不处理，直接返回
        // 此处代码未实现展开按钮判断逻辑
        const args = { type: routedEvent };
        this.dispatchEvent(args);
    }

    private dispatchEvent(args: any) {
        // 简单模拟事件触发
        console.log('Event dispatched:', args.type);
    }

    get TreeItemLeafAppendPropertyCollection(): MultMenuTreeItemLeafAppendProperty[] {
        return this._treeItemLeafAppendPropertyCollection;
    }

    set TreeItemLeafAppendPropertyCollection(value: MultMenuTreeItemLeafAppendProperty[]) {
        this._treeItemLeafAppendPropertyCollection = value;
    }

    getProperty(propertyName: string): string | null {
        return this.GetOrSetProperty(propertyName, null);
    }

    setProperty(propertyName: string, value: string) {
        this.GetOrSetProperty(propertyName, value);
    }

    private GetOrSetProperty(propertyName: string, value: string | null): string | null {
        switch (propertyName) {
            case 'MenuCode':
                if (value === null) {
                    return this.MenuCode;
                } else {
                    this.MenuCode = value;
                    return null;
                }
            case 'Action':
                if (value === null) {
                    return this.Action;
                } else {
                    this.Action = value;
                    return null;
                }
            case 'Title':
                if (value === null) {
                    return this.Title;
                } else {
                    this.Title = value;
                    return null;
                }
            case 'Tag':
                if (value === null) {
                    return this.Tag;
                } else {
                    this.Tag = value;
                    return null;
                }
            case 'Rights':
                if (value === null) {
                    return this.Rights;
                } else {
                    this.Rights = value;
                    return null;
                }
            default:
                for (const item of this._treeItemLeafAppendPropertyCollection) {
                    if (item.Key === propertyName) {
                        if (value === null) {
                            return item.Value;
                        } else {
                            item.Value = value;
                            return null;
                        }
                    }
                }
                break;
        }
        return null;
    }
}

export { MultilevelMenuItemLeaf, MultMenuTreeItemLeafAppendProperty };
