import { useNetlifySDK } from "./use_netlify_sdk.js";
const createNetlifyExtensionUIFetch = ({
  fetch = globalThis.fetch,
  ...options
}) => {
  return (input, init) => {
    const headers = new Headers(init == null ? void 0 : init.headers);
    headers.set("Nf-UIExt-Extension-Slug", options.slug);
    if (options.netlifyToken != null && options.netlifyToken !== "") {
      headers.set("Nf-UIExt-Netlify-Token", options.netlifyToken);
    }
    if (options.providerToken != null && options.providerToken !== "") {
      headers.set("Nf-UIExt-Provider-Token", options.providerToken);
    }
    headers.set(
      "Nf-UIExt-Provider-Tokens",
      JSON.stringify(options.providerTokens ?? [])
    );
    if (options.siteId != null && options.siteId !== "") {
      headers.set("Nf-UIExt-Site-Id", options.siteId);
    }
    if (options.teamId != null && options.teamId !== "") {
      headers.set("Nf-UIExt-Team-Id", options.teamId);
    }
    if (options.user.id != null && options.user.id !== "") {
      headers.set("Nf-UIExt-User-Id", options.user.id);
    }
    return fetch(input, {
      ...init,
      headers
    });
  };
};
const useNetlifyExtensionUIFetch = () => {
  const sdk = useNetlifySDK();
  return (input, init) => {
    const fetch = createNetlifyExtensionUIFetch({
      netlifyToken: sdk.context.auth.netlifyToken,
      providerToken: sdk.context.auth.providerToken,
      providerTokens: sdk.context.auth.providerTokens,
      siteId: sdk.context.siteId,
      slug: sdk.extension.slug,
      teamId: sdk.context.teamId,
      user: sdk.context.user
    });
    return fetch(input, init);
  };
};
export {
  useNetlifyExtensionUIFetch
};
//# sourceMappingURL=use_netlify_extension_ui_fetch.js.map
