"use client";
import * as React from "react";
import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
const SYSTEM_ENTITY_RECORDS_BLOCKED_CODE = "system_entity_records_blocked";
function useRecordsEntityGuard(entityId) {
  const [state, setState] = React.useState(entityId ? "checking" : "allowed");
  React.useEffect(() => {
    if (!entityId) {
      setState("allowed");
      return;
    }
    let cancelled = false;
    setState("checking");
    apiCall(`/api/entities/records?entityId=${encodeURIComponent(entityId)}&page=1&pageSize=1`).then((res) => {
      if (cancelled) return;
      const blocked = res.status === 400 && res.result?.code === SYSTEM_ENTITY_RECORDS_BLOCKED_CODE;
      setState(blocked ? "blocked" : "allowed");
    }).catch(() => {
      if (!cancelled) setState("allowed");
    });
    return () => {
      cancelled = true;
    };
  }, [entityId]);
  return state;
}
export {
  useRecordsEntityGuard
};
//# sourceMappingURL=useRecordsEntityGuard.js.map
