import { n as PUBLISHED_SYNC_TAG_PREFIX, t as DRAFT_SYNC_TAG_PREFIX } from "../constants.js";
import { cookies } from "next/headers";
import "server-only";
import { ClientPerspective, ClientReturn, ContentSourceMap, LiveEventGoAway, QueryParams, SanityClient, SyncTag } from "next-sanity";

//#region src/experimental/live.d.ts

/**
* @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.
*/
declare function resolvePerspectiveFromCookies({
  cookies: jar
}: {
  cookies: Awaited<ReturnType<typeof cookies>>;
}): Promise<Exclude<ClientPerspective, "raw">>;
/**
* @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.
*/
interface SanityFetchOptions<QueryString extends string> {
  query: QueryString;
  params?: QueryParams;
  /**
  * @defaultValue 'published'
  */
  perspective?: Exclude<ClientPerspective, "raw">;
  /**
  * Enables stega encoding of the data, this is typically only used in draft mode in conjunction with `perspective: 'drafts'` and with `@sanity/visual-editing` setup.
  * @defaultValue `false`
  */
  stega?: boolean;
  /**
  * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.
  * @see https://www.sanity.io/docs/reference-api-request-tags
  * @defaultValue 'next-loader.fetch'
  */
  requestTag?: string;
  /**
  * Custom cache tags that can be used with next's `revalidateTag` and `updateTag` functions for custom webhook on-demand revalidation.
  */
  tags?: string[];
}
/**
* @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.
*/
type DefinedSanityFetchType = <const QueryString extends string>(options: SanityFetchOptions<QueryString>) => Promise<{
  data: ClientReturn<QueryString, unknown>;
  /**
  * The Content Source Map can be used for custom setups like `encodeSourceMap` for `data-sanity` attributes, or `stegaEncodeSourceMap` for stega encoding in your own way.
  * The Content Source Map is only fetched by default in draft mode, if `stega` is `true`. Otherwise your client configuration will need to have `resultSourceMap: 'withKeyArraySelector' | true`
  */
  sourceMap: ContentSourceMap | null;
  /**
  * The cache tags used with `next/cache`, useful for debugging.
  */
  tags: string[];
}>;
/**
* @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.
*/
interface DefinedSanityLiveProps {
  /**
  * Automatic refresh of RSC when the component <SanityLive /> is mounted.
  * @defaultValue `false`
  */
  refreshOnMount?: boolean;
  /**
  * Automatically refresh when window gets focused
  * @defaultValue `false`
  */
  refreshOnFocus?: boolean;
  /**
  * Automatically refresh when the browser regains a network connection (via navigator.onLine)
  * @defaultValue `false`
  */
  refreshOnReconnect?: boolean;
  /**
  * Automatically refresh on an interval when the Live Event API emits a `goaway` event, which indicates that the connection is rejected or closed.
  * This typically happens if the connection limit is reached, or if the connection is idle for too long.
  * To disable this long polling fallback behavior set `intervalOnGoAway` to `false` or `0`.
  * You can also use `onGoAway` to handle the `goaway` event in your own way, and read the reason why the event was emitted.
  * @defaultValue `30_000` 30 seconds interval
  */
  intervalOnGoAway?: number | false;
  /**
  * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.
  * @see https://www.sanity.io/docs/reference-api-request-tags
  * @defaultValue 'next-loader.live'
  */
  requestTag?: string;
  /**
  * Handle errors from the Live Events subscription.
  * By default it's reported using `console.error`, you can override this prop to handle it in your own way.
  */
  onError?: (error: unknown) => void;
  /**
  * Handle the `goaway` event if the connection is rejected/closed.
  * `event.reason` will be a string of why the event was emitted, for example `'connection limit reached'`.
  * When this happens the `<SanityLive />` will fallback to long polling with a default interval of 30 seconds, providing your own `onGoAway` handler does not change this behavior.
  * If you want to disable long polling set `intervalOnGoAway` to `false` or `0`.
  */
  onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void;
  /**
  * Override how cache tags are invalidated, you need to pass a server action here.
  * You can also pass a `use client` function here, and have `router.refresh()` be called if the promise resolves to `'refresh'`.
  */
  revalidateSyncTags?: (tags: `${typeof PUBLISHED_SYNC_TAG_PREFIX | typeof DRAFT_SYNC_TAG_PREFIX}${SyncTag}`[]) => Promise<void | "refresh">;
  /**
  * Control how the draft mode perspective is resolved, by default it resolves from the `sanity-preview-perspective` cookie.
  */
  resolveDraftModePerspective?: () => Promise<ClientPerspective>;
}
/**
* @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.
*/
interface DefineSanityLiveOptions {
  /**
  * Required for `sanityFetch` and `SanityLive` to work
  */
  client: SanityClient;
  /**
  * Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.
  * This token is not shared with the browser.
  */
  serverToken?: string | false;
  /**
  * Optional. This token is shared with the browser, and should only have access to query published documents.
  * It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.
  */
  browserToken?: string | false;
}
/**
* @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.
*/
declare function defineLive(config: DefineSanityLiveOptions): {
  /**
  * Use this function to fetch data from Sanity in your React Server Components.
  */
  sanityFetch: DefinedSanityFetchType;
  /**
  * Render this in your root layout.tsx to make your page revalidate on new content live, automatically.
  */
  SanityLive: React.ComponentType<DefinedSanityLiveProps>;
};
//#endregion
export { DefineSanityLiveOptions, DefinedSanityFetchType, DefinedSanityLiveProps, SanityFetchOptions, defineLive, resolvePerspectiveFromCookies };
//# sourceMappingURL=live.d.ts.map