import { useFetch as _useFetch } from '#app'
import { webSiteFlagRelation, webSiteLanguageRelation } from "../utils/common";

export async function useFetchRaw<T = any>(url: string, options?: any) {
  const config = useRuntimeConfig()
  const { appType, serverPath } = config.public as any;
  // url = url.replace('/api/', serverPath)
  const newOptions = {
    ...(options ?? {}),
    headers: {
      ...(options?.headers || {}),
      'Web-Site': webSiteFlagRelation[appType],
      Language: webSiteLanguageRelation[appType]
    },
  }
  const { data, error, pending, refresh, execute } = await _useFetch<T>(url, newOptions)
  return {
    data: {
      _rawValue: data.value,
    },
    error,
    pending,
    refresh,
    execute,
  }
}
