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

import type { ClientLogo } from "~/types/Clients";

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

  return useQuery({
    staleTime: 1000 * 60 * 60,

    key: computed(() => ["clients", locale.value]),
    query: async () => {
      try {
        const response = (await get("projects_logos")) as AxiosResponse;
        return response.data.data as ClientLogo[];
      } catch (error: any) {
        console.error(error.message);
      }
    },
  });
}
export function useServiceClientsQuery(service: string) {
  const { get } = useApi();
  const { locale } = useI18n();

  return useQuery({
    staleTime: 1000 * 60 * 60,

    key: computed(() => ["clients", locale.value, service]),
    query: async () => {
      try {
        const response = (await get(
          `projects_logos?service=${service}`,
        )) as AxiosResponse;
        return response.data.data as ClientLogo[];
      } catch (error: any) {
        console.error(error.message);
      }
    },
  });
}
