"use client";
import * as React from "react";
import { loadInjectionDataWidgetsForSpot } from "@open-mercato/shared/modules/widgets/injection-loader";
function useInjectionDataWidgets(spotId) {
  const [widgets, setWidgets] = React.useState([]);
  const [isLoading, setIsLoading] = React.useState(true);
  const [error, setError] = React.useState(null);
  React.useEffect(() => {
    let mounted = true;
    const load = async () => {
      try {
        setIsLoading(true);
        setError(null);
        const loaded = await loadInjectionDataWidgetsForSpot(spotId);
        if (!mounted) return;
        setWidgets(loaded);
      } catch (loadError) {
        if (!mounted) return;
        console.error(`[useInjectionDataWidgets] Failed to load widgets for spot ${spotId}:`, loadError);
        setError(loadError instanceof Error ? loadError.message : String(loadError));
        setWidgets([]);
      } finally {
        if (mounted) setIsLoading(false);
      }
    };
    void load();
    return () => {
      mounted = false;
    };
  }, [spotId]);
  return { widgets, isLoading, error };
}
export {
  useInjectionDataWidgets
};
//# sourceMappingURL=useInjectionDataWidgets.js.map
