import { useAdminsStore } from '@/stores/admins'
import axioss from 'axios'

const baseURL = 'https://dlearn.liara.run'

const axios = axioss.create({ baseURL })

axios.interceptors.request.use((config) => {
    const admin = useAdminsStore()
    config.headers.Authorization = `Bearer ${admin.token}`
    return config
})

// axios.interceptors.response.use(
//     async (res) => {
//         if(!res.data?.url || !res.data?.urls){
//             res.data = JSON.parse(JSON.stringify(res.data).replaceAll('/uploads', baseURL + '/uploads'))
//             return res
//         }
//     },
//     async (error) => {
//         const status = error?.response?.status

//         if (status === 401)
//             return window.location.href = '/login?to=' + window.location.href;

//         return error?.response
//     }
// )

export default axios
