import { useEffect, useState } from "react";
import { API } from "@/lib/constants";
import type { Meta } from "@/types/trajectory";

export function useMetadata(simId: string = "default"): Meta | null {
  const [meta, setMeta] = useState<Meta | null>(null);

  useEffect(() => {
    const params = new URLSearchParams({ sim: simId });
    fetch(`${API}/api/metadata?${params}`)
      .then((r) => r.json())
      .then(setMeta)
      .catch(console.error);
  }, [simId]);

  return meta;
}
