import { cookies, draftMode } from "next/headers";
import { deserializeSiteVersion } from "../api/site-version";
import { MAKESWIFT_SITE_VERSION_COOKIE, PRERENDER_BYPASS_COOKIE } from "./api-handler/preview";
async function getSiteVersion() {
  const { isEnabled: isDraftModeEnabled } = await draftMode();
  if (!isDraftModeEnabled)
    return null;
  const allCookies = await cookies();
  const cookie = allCookies.get(MAKESWIFT_SITE_VERSION_COOKIE);
  if (cookie == null) {
    if (allCookies.get(PRERENDER_BYPASS_COOKIE) == null) {
      console.error(
        "WARNING: Draft mode is enabled, but both the site version and the prerender bypass cookies are missing.\nThis is abnormal and could cause Makeswift editing and preview to not work as expected.\nDouble-check that you're not forcing static rendering (export const dynamic = 'force-static') on your Makeswift pages.\nMore info: https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic"
      );
    }
    return null;
  }
  return deserializeSiteVersion(cookie.value);
}
export {
  getSiteVersion
};
//# sourceMappingURL=app-router-site-version.js.map