
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 DesktopCloudUserLockModulesItem {
        
          // 模块id
          moduleId?: string;
        
          // 模块名称
          moduleName?: string;
        
          // 模块标识
          moduleNameEn?: string;
        
          // 模块图标icon
          moduleIcon?: string;
        
          // 模块描述
          moduleRemark?: string;
        
      }
    
  


export interface DesktopCloudUserLockModulesInput {
  
}

export interface DesktopCloudUserLockModulesData {
  
    
      // T
      list?: DesktopCloudUserLockModulesItem[];
    
  
}



// 21148 获取用户锁住的模块

  export const useGetDesktopCloudUserLockModules = () => {
    let isMount = true;
    const [isDesktopCloudUserLockModulesLoading, setIsDesktopCloudUserLockModulesLoading] = useState(false);
    const [dataDesktopCloudUserLockModules, setDataDesktopCloudUserLockModules] = useState<DesktopCloudUserLockModulesData>({} as DesktopCloudUserLockModulesData);
    const getDesktopCloudUserLockModulesData = async( config?: YWRequestConfig): Promise<DesktopCloudUserLockModulesData> => {
      
      if(isMount){
        setIsDesktopCloudUserLockModulesLoading(true);
      }
      
      try{
        
          
          const res: any = await Request.get<DesktopCloudUserLockModulesData>(`${basePath}/desktop/cloud/user/lock/modules`, {
            loginHost: loginPath,
            ...config
          });
          
          
          
          if(isMount){
            setDataDesktopCloudUserLockModules(res || {});
            setIsDesktopCloudUserLockModulesLoading(false);
          }
          return res;
      } catch(error){
        console.log(error);
        if(isMount){
          setIsDesktopCloudUserLockModulesLoading(false);
        }
        return false as unknown as DesktopCloudUserLockModulesData;
      }
      
    }

    useEffect(() => {
      return () => {
        isMount = false;
      };
    }, []);
  
    return {
      isDesktopCloudUserLockModulesLoading,
      dataDesktopCloudUserLockModules,
      getDesktopCloudUserLockModulesData,
    }
  }

