import type {ClientPerspective} from '@sanity/client'

/**
 * @alpha
 */
export declare interface PreviewUrlValidateUrlResult {
  isValid: boolean
  /**
   * If the URL is valid, and there's a parameter for what preview path to redirect to, it will be here
   */
  redirectTo?: string | undefined
  /**
   * If the URL is valid, and the studio URL is known and valid, then its origin will be here
   */
  studioOrigin?: string | undefined
  /**
   * The initial perspective the Studio was using when starting to load the preview.
   * It can change over time and should also be handled with `postMessage` listeners.
   * The value can be arbitrary and has to be validated to make sure it's a valid perspective.
   */
  studioPreviewPerspective?: string | null | undefined
}

/**
 * A subset type that's compatible with most SanityClient typings,
 * this makes it easier to use this package in libraries that may use `import type { SanityClient } from 'sanity'`
 * as well as those that use `import type { SanityClient } from '@sanity/client'`
 * @public
 */
export declare type SanityClientLike = {
  config(): {
    token?: string
  }
  withConfig(config: {
    apiVersion?: string
    useCdn?: boolean
    perspective?: ClientPerspective
    resultSourceMap?: boolean
  }): SanityClientLike
  fetch<
    R,
    Q = {
      [key: string]: any
    },
  >(
    query: string,
    params: Q,
    options: {
      tag?: string
    },
  ): Promise<R>
}

/** @internal */
export declare const urlSearchParamPreviewPathname = 'sanity-preview-pathname'

/** @internal */
export declare const urlSearchParamPreviewSecret = 'sanity-preview-secret'

/**
 * @public
 */
export declare function validatePreviewUrl(
  _client: SanityClientLike,
  previewUrl: string,
  /**
   * @deprecated - this option is automatically determined based on the environment
   */
  disableCacheNoStore?: boolean,
): Promise<PreviewUrlValidateUrlResult>

export {}
