import { useQuery } from "@pinia/colada";
import { useApi } from "~/composables/useApi";
import type { AxiosResponse } from "axios";

export function useGlobalTestimonialsQuery() {
  const { get } = useApi();
  const { locale } = useI18n();

  return useQuery({
    staleTime: 1000 * 60 * 60,
    key: computed(() => ["testimonials", locale.value]),
    query: async () => {
      try {
        const response = await get<AxiosResponse>(`testimonials`);
        return response.data.data;
      } catch (error: any) {
        console.error(error.message);
      }
    },
  });
}
export function useServiceTestimonialsQuery(service: string) {
  const { get } = useApi();
  const { locale } = useI18n();

  return useQuery({
    staleTime: 1000 * 60 * 60,
    key: computed(() => ["testimonials", locale.value, service]),
    query: async () => {
      try {
        const response = await get<AxiosResponse>(
          `testimonials?service=${service}`,
        );
        return response.data.data;
      } catch (error: any) {
        console.error(error.message);
      }
    },
  });
}
