import axios from './axios'
// import { API_DEFAULT_CONFIG } from 'Config/index'
import type { AxiosRequestConfig } from 'axios'
import useUserStore from 'Store/modules/user'

// 根据当前环境设置baseUrl
// const mockBaseUrl = import.meta.env.DEV ? API_DEFAULT_CONFIG.mockBaseUrl : ''
const mockBaseUrl = ''

// 封装API请求
const request = (option: AxiosRequestConfig) => {
  const userStore = useUserStore()
  if(!option.headers){
    option.headers = {
      'Content-Type': 'application/json',
      'X-Access-Token': userStore.token
    }
  }else{
    option.headers = {
      'Content-Type': 'application/json',
      'X-Access-Token': userStore.token,
      ...option.headers
    }
  }
  option['url'] = mockBaseUrl + option.url
  if (option.method?.toLowerCase() === 'get') {
    option['params'] = option.data
  }

  return axios(option)
}

export default request
