
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 = "PROSUPPLIER";
  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' ? '/' + 184 : ''}` : '';
  const loginPath = configs['AUTH'] ? configs['AUTH'][env].APPLICATION_URL : '';
  

  

// @ts-ignore




export interface NewPartnerListInput {
  
}

export interface NewPartnerListData {
  
}



// 19570 合作模式列表

  export const useGetNewPartnerList = () => {
    let isMount = true;
    const [isNewPartnerListLoading, setIsNewPartnerListLoading] = useState(false);
    const [dataNewPartnerList, setDataNewPartnerList] = useState<NewPartnerListData>({} as NewPartnerListData);
    const getNewPartnerListData = async( config?: YWRequestConfig): Promise<NewPartnerListData> => {
      
      if(isMount){
        setIsNewPartnerListLoading(true);
      }
      
      try{
        
          
          const res: any = await Request.get<NewPartnerListData>(`${basePath}/new/partner/list`, {
            loginHost: loginPath,
            ...config
          });
          
          
          
          if(isMount){
            setDataNewPartnerList(res || {});
            setIsNewPartnerListLoading(false);
          }
          return res;
      } catch(error){
        console.log(error);
        if(isMount){
          setIsNewPartnerListLoading(false);
        }
        return false as unknown as NewPartnerListData;
      }
      
    }

    useEffect(() => {
      return () => {
        isMount = false;
      };
    }, []);
  
    return {
      isNewPartnerListLoading,
      dataNewPartnerList,
      getNewPartnerListData,
    }
  }

