
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 DesktopCloudListTreeItem {
        
          // 云分类id
          cloudCategoryId?: string;
        
          // 云分类名称
          cloudCategoryName?: string;
        
          // 
          moduleList?: DesktopCloudListTreeItem[];
        
      }
    
  


export interface DesktopCloudListTreeInput {
  
}

export interface DesktopCloudListTreeData {
  
    
      // 
      list?: DesktopCloudListTreeItem[];
    
  
}



// 20971 获取云模块的列表

  export const useGetDesktopCloudListTree = () => {
    let isMount = true;
    const [isDesktopCloudListTreeLoading, setIsDesktopCloudListTreeLoading] = useState(false);
    const [dataDesktopCloudListTree, setDataDesktopCloudListTree] = useState<DesktopCloudListTreeData>({} as DesktopCloudListTreeData);
    const getDesktopCloudListTreeData = async( config?: YWRequestConfig): Promise<DesktopCloudListTreeData> => {
      
      if(isMount){
        setIsDesktopCloudListTreeLoading(true);
      }
      
      try{
        
          
          const res: any = await Request.get<DesktopCloudListTreeData>(`${basePath}/desktop/cloud/list/tree`, {
            loginHost: loginPath,
            ...config
          });
          
          
          
          if(isMount){
            setDataDesktopCloudListTree(res || {});
            setIsDesktopCloudListTreeLoading(false);
          }
          return res;
      } catch(error){
        console.log(error);
        if(isMount){
          setIsDesktopCloudListTreeLoading(false);
        }
        return false as unknown as DesktopCloudListTreeData;
      }
      
    }

    useEffect(() => {
      return () => {
        isMount = false;
      };
    }, []);
  
    return {
      isDesktopCloudListTreeLoading,
      dataDesktopCloudListTree,
      getDesktopCloudListTreeData,
    }
  }

