import { useState, useEffect } from "react";
import { s as supabase } from "./client-Dz5aErML.js";
const DEFAULTS = {
  whatsappNumber: "6282312715218",
  whatsappNumber2: "",
  instagramUrl: "https://instagram.com/rental.pergamff",
  tiktokUrl: "",
  whatsappChannelUrl: ""
};
function useSiteSettings() {
  const [settings, setSettings] = useState(DEFAULTS);
  const [loading, setLoading] = useState(true);
  const refetch = async () => {
    const { data } = await supabase.from("site_settings").select("whatsapp_number, instagram_url, tiktok_url, whatsapp_channel_url, whatsapp_number_2").maybeSingle();
    if (data) {
      setSettings({
        whatsappNumber: data.whatsapp_number ?? DEFAULTS.whatsappNumber,
        whatsappNumber2: data.whatsapp_number_2 ?? "",
        instagramUrl: data.instagram_url ?? DEFAULTS.instagramUrl,
        tiktokUrl: data.tiktok_url ?? "",
        whatsappChannelUrl: data.whatsapp_channel_url ?? ""
      });
    }
    setLoading(false);
  };
  useEffect(() => {
    refetch();
    const channelId = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
    const channelName = `site-settings-realtime-${channelId}`;
    const channel = supabase.channel(channelName);
    channel.on("postgres_changes", { event: "*", schema: "public", table: "site_settings" }, () => {
      refetch();
    }).subscribe();
    return () => {
      supabase.removeChannel(channel);
    };
  }, []);
  return { settings, loading, refetch };
}
export {
  useSiteSettings as u
};
