
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 DesktopHomeCommonEntryTreeItem {
        
          // 云分类id
          cloudCategoryId?: string;
        
          // 云分类名称
          cloudCategoryName?: string;
        
          // 平台下的模块列表 ,QuickEntryModuleVO
          moduleList?: DesktopHomeCommonEntryTreeItem[];
        
      }
    
  


export interface DesktopHomeCommonEntryTreeInput {
  
}

export interface DesktopHomeCommonEntryTreeData {
  
    
      // T
      list?: DesktopHomeCommonEntryTreeItem[];
    
  
}



// 20970 显示待加入常用功能的菜单数据

  export const useGetDesktopHomeCommonEntryTree = () => {
    let isMount = true;
    const [isDesktopHomeCommonEntryTreeLoading, setIsDesktopHomeCommonEntryTreeLoading] = useState(false);
    const [dataDesktopHomeCommonEntryTree, setDataDesktopHomeCommonEntryTree] = useState<DesktopHomeCommonEntryTreeData>({} as DesktopHomeCommonEntryTreeData);
    const getDesktopHomeCommonEntryTreeData = async( config?: YWRequestConfig): Promise<DesktopHomeCommonEntryTreeData> => {
      
      if(isMount){
        setIsDesktopHomeCommonEntryTreeLoading(true);
      }
      
      try{
        
          
          const res: any = await Request.get<DesktopHomeCommonEntryTreeData>(`${basePath}/desktop/home/common/entry/tree`, {
            loginHost: loginPath,
            ...config
          });
          
          
          
          if(isMount){
            setDataDesktopHomeCommonEntryTree(res || {});
            setIsDesktopHomeCommonEntryTreeLoading(false);
          }
          return res;
      } catch(error){
        console.log(error);
        if(isMount){
          setIsDesktopHomeCommonEntryTreeLoading(false);
        }
        return false as unknown as DesktopHomeCommonEntryTreeData;
      }
      
    }

    useEffect(() => {
      return () => {
        isMount = false;
      };
    }, []);
  
    return {
      isDesktopHomeCommonEntryTreeLoading,
      dataDesktopHomeCommonEntryTree,
      getDesktopHomeCommonEntryTreeData,
    }
  }

