import { useQuery } from "@tanstack/react-query";
import { supabase } from "@/integrations/supabase/client";

const FALLBACK_LOGO = "/niyamah-logo.jpg";

export function useCompanyLogo() {
  const { data, isLoading } = useQuery({
    queryKey: ["company-logo"],
    queryFn: async () => {
      const { data } = await supabase
        .from("business_settings")
        .select("setting_value")
        .eq("setting_key", "company_logo_url")
        .maybeSingle();
      return (data?.setting_value as string) || FALLBACK_LOGO;
    },
    staleTime: 5 * 60 * 1000,
  });

  return { logoUrl: data || FALLBACK_LOGO, isLoading };
}

export { FALLBACK_LOGO };
