import { useQuery } from "@tanstack/react-query";
import { apiGet } from "../../../lib/api/methods";
import { PUBLIC_SETTINGS } from "./endpoints";

type SocialLinksResponse = {
  facebook: string;
  instagram: string;
  twitter: string;
  linkedIn: string;
  youtube: string;
  customLink: string;
};

export default function useFetchSocialLinks() {
  const { data, isLoading, error, isError } = useQuery({
    queryKey: ["social-links"],
    queryFn: async () => {
      const response = await apiGet<SocialLinksResponse>(
        PUBLIC_SETTINGS.GET_SOCIAL_LINKS,
      );
      return response.data;
    },
    staleTime: 30 * 60 * 1000,
    gcTime: 60 * 60 * 1000,
  });

  return {
    facebook: data?.facebook,
    instagram: data?.instagram,
    twitter: data?.twitter,
    linkedIn: data?.linkedIn,
    youtube: data?.youtube,
    customLink: data?.customLink,
    loading: isLoading,
    error,
    isError,
  };
}
