// pdp-provider.jsx — pdp-provider.html (redirect-handoff PDP: disclosure + reputation
// above the fold, plus the one generic error-banner instance used in this whole bundle:
// the provider's live-availability check failing.)

function readPdpItem(fallbackId) {
  const p = new URLSearchParams(location.search);
  const id = p.get("item");
  return (id && getItem(id)) || getItem(fallbackId);
}

function PdpProviderPage() {
  const item = readPdpItem("provider-compliance-review");
  const [checking, setChecking] = React.useState(false);
  const [down, setDown] = React.useState(true);

  const retry = () => {
    setChecking(true);
    setTimeout(() => { setChecking(false); setDown(false); }, 1000);
  };

  const error = down
    ? {
        title: "Provider availability check failed.",
        message: `${item.provider.name}'s booking calendar didn't respond in time. You can still open the provider directly — the handoff doesn't depend on this check — or retry it.`,
        onRetry: retry,
      }
    : null;

  return <ProductDetail item={item} error={checking ? { ...error, title: "Checking…" } : error} />;
}

window.__PAGE__ = PdpProviderPage;
