"use client" import { useEffect, useState } from "react" import { procurementConfig } from "@/lib/api/procurement-config" import { ProcurementConfig } from "@/types/procurement" /** Everything off — what a screen assumes until the real flags arrive (or if they cannot be read). */ export const PROCUREMENT_CONFIG_OFF: ProcurementConfig = { vendorContactMode: "None", vendorAddressEnabled: false, vendorPaymentTermsEnabled: false, vendorTaxRegEnabled: false, poTaxEnabled: false, updatedAt: null, updatedBy: null, } /** * Loads the Procurement configuration flags. A failed read leaves every optional field hidden * rather than blocking the screen — the server rejects gated values on its own anyway. */ export function useProcurementConfig(): { config: ProcurementConfig; loaded: boolean } { const [config, setConfig] = useState(PROCUREMENT_CONFIG_OFF) const [loaded, setLoaded] = useState(false) useEffect(() => { let active = true procurementConfig() .then((c) => { if (active) setConfig(c) }) .catch(() => {}) .finally(() => { if (active) setLoaded(true) }) return () => { active = false } }, []) return { config, loaded } }