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


export interface DesktopCloudListInput {
  
}

export interface DesktopCloudListData {
  
    
      // 
      list?: DesktopCloudListItem[];
    
  
}



// 20833 获取云分类列表

  export const useGetDesktopCloudList = () => {
    let isMount = true;
    const [isDesktopCloudListLoading, setIsDesktopCloudListLoading] = useState(false);
    const [dataDesktopCloudList, setDataDesktopCloudList] = useState<DesktopCloudListData>({} as DesktopCloudListData);
    const getDesktopCloudListData = async( config?: YWRequestConfig): Promise<DesktopCloudListData> => {
      
      if(isMount){
        setIsDesktopCloudListLoading(true);
      }
      
      try{
        
          
          const res: any = await Request.get<DesktopCloudListData>(`${basePath}/desktop/cloud/list`, {
            loginHost: loginPath,
            ...config
          });
          
          
          
          if(isMount){
            setDataDesktopCloudList(res || {});
            setIsDesktopCloudListLoading(false);
          }
          return res;
      } catch(error){
        console.log(error);
        if(isMount){
          setIsDesktopCloudListLoading(false);
        }
        return false as unknown as DesktopCloudListData;
      }
      
    }

    useEffect(() => {
      return () => {
        isMount = false;
      };
    }, []);
  
    return {
      isDesktopCloudListLoading,
      dataDesktopCloudList,
      getDesktopCloudListData,
    }
  }

