
import { useState,  useEffect } from 'react';

import Request, {YWRequestConfig} from '@ywfe/request';
// @ts-ignore
import * as querystring from 'querystring';
// @ts-ignore
import { ParsedUrlQueryInput } from 'querystring';
// @ts-ignore
import * as R from 'ramda';
import {configs} from './config';


  const projectId = "PROAUTH";
  let env;
  if(typeof window === 'undefined'){
    env = (process.env.REACT_APP_ENV === 'prod' ? 'prod': process.env.REACT_APP_ENV) || 'prod';
  } else {
    env = window.localStorage.getItem('env') || (process.env.REACT_APP_ENV === 'prod' ? 'prod': process.env.REACT_APP_ENV) || 'prod';
  }
  
  const basePath = configs[projectId] ? configs[projectId][env].API_BASE_URL + `${env === 'mock' ? '/' + 88 : ''}` : '';
  const loginPath = configs['AUTH'] ? configs['AUTH'][env].APPLICATION_URL : '';
  

  

// @ts-ignore



  
    
      export interface DesktopHomeCommonFunctionListItem {
        
          // 菜单id
          resourceId?: string;
        
          // 菜单名称
          resourceName?: string;
        
          // 英文名
          nameEn?: string;
        
          // 路径
          url?: string;
        
          // 是否拥有权限	
          isHasResourcce?: boolean;
        
          // 模块id
          moduleId?: string;
        
          // 模块名称
          moduleName?: string;
        
          // 模块英文名
          moduleNameEn?: string;
        
          // ICON地址
          moduleIcon?: string;
        
      }
    
  


export interface DesktopHomeCommonFunctionListInput {
  
}

export interface DesktopHomeCommonFunctionListData {
  
    
      // T
      list?: DesktopHomeCommonFunctionListItem[];
    
  
}



// 20946 显示用户的常用功能

  export const useGetDesktopHomeCommonFunctionList = () => {
    let isMount = true;
    const [isDesktopHomeCommonFunctionListLoading, setIsDesktopHomeCommonFunctionListLoading] = useState(false);
    const [dataDesktopHomeCommonFunctionList, setDataDesktopHomeCommonFunctionList] = useState<DesktopHomeCommonFunctionListData>({} as DesktopHomeCommonFunctionListData);
    const getDesktopHomeCommonFunctionListData = async( config?: YWRequestConfig): Promise<DesktopHomeCommonFunctionListData> => {
      
      if(isMount){
        setIsDesktopHomeCommonFunctionListLoading(true);
      }
      
      try{
        
          
          const res: any = await Request.get<DesktopHomeCommonFunctionListData>(`${basePath}/desktop/home/common/function/list`, {
            loginHost: loginPath,
            ...config
          });
          
          
          
          if(isMount){
            setDataDesktopHomeCommonFunctionList(res || {});
            setIsDesktopHomeCommonFunctionListLoading(false);
          }
          return res;
      } catch(error){
        console.log(error);
        if(isMount){
          setIsDesktopHomeCommonFunctionListLoading(false);
        }
        return false as unknown as DesktopHomeCommonFunctionListData;
      }
      
    }

    useEffect(() => {
      return () => {
        isMount = false;
      };
    }, []);
  
    return {
      isDesktopHomeCommonFunctionListLoading,
      dataDesktopHomeCommonFunctionList,
      getDesktopHomeCommonFunctionListData,
    }
  }

