import { ViewTool } from '@/utils';

/**
 * AppIndexView 部件模型
 *
 * @export
 * @class AppIndexViewModel
 */
export default class AppIndexViewModel {

    /**
     * 菜单项集合
     *
     * @private
     * @type {any[]}
     * @memberof AppIndexViewModel
     */
    private items: any[] = [
                {
        	id: 'A20112C0-6FC7-48FC-B14C-24C66A924503',
        	name: 'user_menus',
        	text: '用户菜单',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '用户菜单',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
                {
        	id: '70669C0B-37A4-4121-95D8-DCCB0827F20D',
        	name: 'top_menus',
        	text: '顶部菜单',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '顶部菜单',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
                {
        	id: '7428CF1E-09D0-477F-838B-3CB98A776FBA',
        	name: 'left_exp',
        	text: '左侧菜单',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '左侧菜单',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        	items: [
                		        {
                	id: '8739EFEE-ED1F-40E0-9BDB-438466E895D7',
                	name: 'menuitem1',
                	text: '功能位置',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '功能位置',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: '',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                	items: [
                        		        {
                        	id: '83E50A95-6762-4A67-9052-69DE75A60E3B',
                        	name: 'menuitem6',
                        	text: '功能位置状态管理',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '功能位置状态管理',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: '',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_3',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'eamlocation-state-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: 'E3BFAB38-B5C1-487A-B68B-61F6EF513C58',
                        	name: 'menuitem7',
                        	text: '功能位置状态模型管理',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '功能位置状态模型管理',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: '',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_2',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'eamlocation-state-model-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '6B6D828E-5B2A-4DF2-B437-0DDD328DAD7D',
                        	name: 'menuitem8',
                        	text: '功能位置类型',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '功能位置类型',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: '',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_4',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'eamlocation-type-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '6E2E7A7B-EDEF-460B-84A7-A2777BDD996E',
                        	name: 'menuitem9',
                        	text: '功能位置',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '功能位置',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: '',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_5',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'eamlocation-grid-view',
                        	resourcetag: '',
                        }
                        ,
                	],
                }
                ,
                		        {
                	id: '78652037-98D2-48D1-8600-4DBFCD9243F0',
                	name: 'menuitem2',
                	text: '资产管理',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '资产管理',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: '',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                }
                ,
                		        {
                	id: '5FD0497E-7F0C-4AFA-931A-64FECFAD6B0D',
                	name: 'menuitem3',
                	text: '维护申请',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '维护申请',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: '',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                }
                ,
                		        {
                	id: '4803F5BD-7CF9-4A67-BCA6-DCB022B56291',
                	name: 'menuitem4',
                	text: '工单管理',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '工单管理',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: '',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                }
                ,
                		        {
                	id: '38802802-F256-487F-B526-7E2A58541A6C',
                	name: 'menuitem5',
                	text: '维护计划',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '维护计划',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: '',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                }
                ,
        	],
        }
        ,
    ];

	/**
	 * 应用功能集合
	 *
	 * @private
	 * @type {any[]}
	 * @memberof AppIndexViewModel
	 */
	private funcs: any[] = [
        {
            appfunctag: '_5',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'eamlocationgridview',
            deResParameters: [],
            routepath: '/appindexview/:appindexview?/eamlocations/:eamlocation?/gridview/:gridview?',
            parameters: [
                { pathName: 'eamlocations', parameterName: 'eamlocation' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_2',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'eamlocationstatemodelgridview',
            deResParameters: [],
            routepath: '/appindexview/:appindexview?/eamlocationstatemodels/:eamlocationstatemodel?/gridview/:gridview?',
            parameters: [
                { pathName: 'eamlocationstatemodels', parameterName: 'eamlocationstatemodel' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_3',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'eamlocationstategridview',
            deResParameters: [],
            routepath: '/appindexview/:appindexview?/eamlocationstates/:eamlocationstate?/gridview/:gridview?',
            parameters: [
                { pathName: 'eamlocationstates', parameterName: 'eamlocationstate' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_4',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'eamlocationtypegridview',
            deResParameters: [],
            routepath: '/appindexview/:appindexview?/eamlocationtypes/:eamlocationtype?/gridview/:gridview?',
            parameters: [
                { pathName: 'eamlocationtypes', parameterName: 'eamlocationtype' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
	];

	/**
	 * 根据当前路由查找激活菜单
	 *
	 * @param {*} route
	 * @returns {*}
	 * @memberof AppIndexViewModel
	 */
	public findActiveMenuByRoute(route: any): any {
		if (route) {
			const func = this.funcs.find((item: any) => {
				if (item.openmode === '') {
					const url: string = ViewTool.buildUpRoutePath(route, route.params, [], item.parameters, [], {});
					return url === route.fullPath;
				}
			});
            if (func) {
			    return this.findMenuByFuncTag(func.appfunctag);
            }
		}
	}

	/**
	 * 根据应用功能id查找菜单项
	 *
	 * @param {string} tag
	 * @param {any[]} [menus=this.items]
	 * @returns {*}
	 * @memberof AppIndexViewModel
	 */
	public findMenuByFuncTag(tag: string, menus: any[] = this.items): any {
		let menu: any;
		menus.every((item: any) => {
			if (item.appfunctag === tag) {
				menu = item;
				return false;
			}
			if (item.items) {
				menu = this.findMenuByFuncTag(tag, item.items);
				if (menu) {
					return false;
				}
			}
			return true;
		});
		return menu;
	}

	/**
	 * 查找默认打开菜单
	 *
	 * @param {any[]} [menus=this.items]
	 * @returns {*}
	 * @memberof AppIndexViewModel
	 */
	public findDefaultOpenMenu(menus: any[] = this.items): any {
		let menu: any;
		menus.every((item: any) => {
			if (item.opendefault === true) {
				menu = item;
				return false;
			}
			if (item.items) {
				menu = this.findMenuByFuncTag(item.items);
				if (menu) {
					return false;
				}
			}
			return true;
		});
		return menu;
	}

    /**
     * 获取所有菜单项集合
     *
     * @returns {any[]}
     * @memberof AppIndexViewModel
     */
    public getAppMenuItems(): any[] {
        return this.items;
    }

	/**
	 * 根据名称获取菜单组
	 *
	 * @param {string} name
	 * @returns {*}
	 * @memberof AppIndexViewModel
	 */
	public getMenuGroup(name: string): any {
		return this.items.find((item: any) => Object.is(item.name, name));
	}

    /**
     * 获取所有应用功能集合
     *
     * @returns {any[]}
     * @memberof AppIndexViewModel
     */
    public getAppFuncs(): any[] {
        return this.funcs;
    }
}