import { store } from '../store/index';

/**
 * 判断当前登录客户的功能权限
 * @param funKey 
 * @returns 
 */
export function isHaveFunByClient(funKey: string) {
	try {
		// 当为1时则标识是体验用户，拥有全部能力
		const userInfos = store.state.userInfos.userInfos;
		const clientIsEnterpriseMode = userInfos.client.clientIsEnterpriseMode;
		const clientCode = userInfos.client.code;
		if (clientIsEnterpriseMode !== 1) {
			const permissions = store.state.funPerission[funKey];

			if (!permissions || !Array.isArray(permissions)) {
				throw new Error(`Invalid permissions for value: ${funKey}`);
			}

			const hasPermission = permissions.includes(clientCode);
			console.log(hasPermission);
			if (!hasPermission) {
				return false;
			}
			return true;
		}
	} catch (error) {
		console.error('funperission error:', error);
	}
}
