import { QueryClient } from '@tanstack/react-query';

import axios from 'axios';

const api = axios.create({
  baseURL: import.meta.env.VITE_API_URL,
});

// Adicionar token temporariamente aos headers
const token = import.meta.env.VITE_API_TOKEN || '';
if (token) {
  api.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}

export const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      refetchOnWindowFocus: true,
      staleTime: 1000 * 30, // 30 seconds
    },
  },
});

export { api };
