// composables/useHadithaSearchComposable.js
import { useStorage } from "@vueuse/core";

export const useHadithaSearchComposable = <T>(url: string, options = {}) => {
  // Get the authentication token (e.g., from a cookie or local storage)
  // const token = useCookie('auth-token') // Assuming you store the token in a cookie
  let token = useStorage("id_token", "GuestAccess");
  const config = useRuntimeConfig();
  console.info(config);

  const baseURL =
    config.public.NUXT_PUBLIC_BASE_URL + config.public.NUXT_PUBLIC_API_NAME;

  // Add headers to the request
  const headers = {
    Authorization: token.value,
    ...options.headers, // Merge with any existing headers
  };

  // Use useFetch with the headers
  return useFetch<T>(url, {
    ...options,
    baseURL,
    headers,
  });
};