import * as React from "react";
import * as react_jsx_runtime1 from "react/jsx-runtime";
import { MergedUnion } from "@kablamo/kerosene";
import { DefinedQueryObserverResult, QueryObserverLoadingErrorResult, QueryObserverLoadingResult, QueryObserverSuccessResult, UseQueryResult } from "@tanstack/react-query";
import { ErrorBoundaryPropsWithComponent, ErrorBoundaryPropsWithFallback, ErrorBoundaryPropsWithRender } from "react-error-boundary";

//#region src/components/Boundaries/helpers.d.ts
/**
 * Returns whether a given query has a defined result. This includes the success state of the query, as well as the
 * states for refetch in progress, as well as the refetch error state with stale data.
 * @param query React Query query
 */
declare function isDefinedQueryObserverResult<TData$1 = unknown, TError$1 = unknown>(query: UseQueryResult<TData$1, TError$1>): query is DefinedQueryObserverResult<TData$1, TError$1>;
/**
 * Returns whether a given query is in the error state with no defined result. This includes the error state when data
 * is refetching.
 * @param query React Query query
 */
declare function isQueryObserverLoadingErrorResult<TData$1 = unknown, TError$1 = unknown>(query: UseQueryResult<TData$1, TError$1>): query is QueryObserverLoadingErrorResult<TData$1, TError$1>;
/**
 * Returns whether a given query is in the loading state with no defined result. This includes the error state when data
 * is refetching.
 * @param query React Query query
 */
declare function isQueryObserverLoadingResult<TData$1 = unknown, TError$1 = unknown>(query: UseQueryResult<TData$1, TError$1>): query is QueryObserverLoadingResult<TData$1, TError$1>;
//#endregion
//#region src/components/Boundaries/types.d.ts
type ErrorFallbackProps = MergedUnion<{
  errorFallback: ErrorBoundaryPropsWithFallback["fallback"];
} | {
  errorFallbackRender: ErrorBoundaryPropsWithRender["fallbackRender"];
} | {
  ErrorFallbackComponent: ErrorBoundaryPropsWithComponent["FallbackComponent"];
}>;
//#endregion
//#region src/components/Boundaries/QueriesBoundary.d.ts
/**
 * Provides a type for the children function of `<QueriesBoundary queries={[query1, query2]} />`
 * that allows the types of a successful query to be inferred for ease of use
 * @example
 * ```ts
 * type C = ChildrenFn<readonly [
 *   UseQueryResult<Query1Data>,
 *   UseQueryResult<Query2Data>,
 * ]>;
 * // Equivalent to
 * type C = (queries: readonly [
 *   QueryObserverSuccessResult<Query1Data>,
 *   QueryObserverSuccessResult<Query2Data>,
 * ]) => React.ReactNode;
 * ```
 */
type ChildrenFn<TQueries extends ReadonlyArray<UseQueryResult>> = (queries: { [Key in keyof TQueries]: TQueries[Key] extends UseQueryResult<infer TData, infer TError> ? QueryObserverSuccessResult<TData, TError> : TQueries[Key] }) => React.ReactNode;
type QueriesBoundaryProps<TQueries extends ReadonlyArray<UseQueryResult>> = {
  children: React.ReactNode | ChildrenFn<TQueries>;
  loadingFallback: React.ReactNode;
  queries: TQueries;
} & ErrorFallbackProps;
/**
 * Utility component for managing the loading and error states for multiple React Query queries. Specifying the queries
 * automatically infers the types of the success state of the queries in the render prop children (if used).
 *
 * There are three mutually exclusive options for specifying an error fallback:
 * - `errorFallback` - JSX element
 * - `errorFallbackRender` - a function which takes `FallbackProps` and renders JSX
 * - `ErrorFallbackComponent` - a React component which takes `FallbackProps`
 *
 * @example
 * ```tsx
 * const MyComponent = () => {
 *   const query1: UseQueryResult<{ items: readonly string[] }> = useMyQuery1();
 *   const query2: UseQueryResult<{ balance: number }> = useMyQuery2();
 *
 *   return (
 *     <QueriesBoundary
 *       errorFallbackRender={({ resetErrorBoundary }) => (
 *         <>
 *           Something went wrong.{" "}
 *           <button type="button" onClick={resetErrorBoundary}>Try again</button>
 *         </>
 *       )}
 *       loadingFallback={<SkeletonComponent />}
 *       queries={[query1, query2]}
 *     >
 *       {([{ data: { items } }, { data: { balance } }]) => (
 *         <>
 *           <p>
 *             Your balance:{" "}
 *             {new Intl.NumberFormat("en-AU", { style: "currency", currency: "AUD" }).format(balance)}
 *           </p>
 *           <p>
 *             You have:{" "}
 *             {new Intl.ListFormat("en", { style: "long", type: "conunction" }).format(data.items)}
 *           </p>
 *         </>
 *       )}
 *     </QueryBoundary>
 *   );
 * };
 * ```
 *
 * @param props
 */
declare const QueriesBoundary: <const TQueries extends ReadonlyArray<UseQueryResult>>({
  children,
  errorFallback,
  errorFallbackRender,
  ErrorFallbackComponent,
  loadingFallback,
  queries
}: QueriesBoundaryProps<TQueries>) => React.JSX.Element;
//#endregion
//#region src/components/Boundaries/QueryBoundary.d.ts
type QueryBoundaryProps<TData$1 = unknown, TError$1 = unknown> = {
  children: React.ReactNode | ((query: DefinedQueryObserverResult<TData$1, TError$1>) => React.ReactNode);
  loadingFallback: React.ReactNode;
  query: UseQueryResult<TData$1, TError$1>;
} & ErrorFallbackProps;
/**
 * Utility component for managing the loading and error states for a single React Query query. Specifying the query
 * automatically infers the type of the success state of the query in the render prop children (if used).
 *
 * There are three mutually exclusive options for specifying an error fallback:
 * - `errorFallback` - JSX element
 * - `errorFallbackRender` - a function which takes `FallbackProps` and renders JSX
 * - `ErrorFallbackComponent` - a React component which takes `FallbackProps`
 *
 * @example
 * ```tsx
 * const MyComponent = () => {
 *   const query: UseQueryResult<{ items: readonly string[] }> = useMyQuery();
 *   return (
 *     <QueryBoundary
 *       errorFallbackRender={({ resetErrorBoundary }) => (
 *         <>
 *           Something went wrong.{" "}
 *           <button type="button" onClick={resetErrorBoundary}>Try again</button>
 *         </>
 *       )}
 *       loadingFallback={<LoadingSpinner />}
 *       query={query}
 *     >
 *       {({ data }) => (
 *         <p>
 *           You have:{" "}
 *           {new Intl.ListFormat("en", { style: "long", type: "conunction" }).format(data.items)}
 *         </p>
 *       )}
 *     </QueryBoundary>
 *   );
 * };
 * ```
 *
 * @param props
 */
declare const QueryBoundary: <TData$1 = unknown, TError$1 = unknown>({
  children,
  errorFallback,
  errorFallbackRender,
  ErrorFallbackComponent,
  loadingFallback,
  query
}: QueryBoundaryProps<TData$1, TError$1>) => React.JSX.Element;
//#endregion
//#region src/components/Boundaries/SuspenseBoundary.d.ts
type SuspenseBoundaryProps = {
  children: React.ReactNode;
  loadingFallback: React.ReactNode;
} & ErrorFallbackProps;
/**
 * Utility component for managing loading and error states for Suspense components. Also integrates with React Query to
 * provide a QueryErrorResetBoundary.
 *
 * There are three mutually exclusive options for specifying an error fallback:
 * - `errorFallback` - JSX element
 * - `errorFallbackRender` - a function which takes `FallbackProps` and renders JSX
 * - `ErrorFallbackComponent` - a React component which takes `FallbackProps`
 *
 * @example
 * ```tsx
 * const SuspendingComponent = () => {
 *   const query: UseSuspensQueryResult<{ balance: number }> = useMySuspenseQuery();
 *   return (
 *     <p>
 *       Your balance:{" "}
 *       {new Intl.NumberFormat("en-AU", { style: "currency", currency: "AUD" }).format(balance)}
 *     </p>
 *   );
 * };
 *
 * const MyComponent = () => (
 *   <SuspenseBoundary
 *     errorFallbackRender={({ resetErrorBoundary }) => (
 *       <>
 *         Something went wrong.{" "}
 *         <button type="button" onClick={resetErrorBoundary}>Try again</button>
 *       </>
 *     )}
 *     loadingFallback={<LoadingSpinner />}
 *   >
 *     <SuspendingComponent />
 *   </SuspenseBoundary>
 * );
 * ```
 *
 * @param props
 */
declare const SuspenseBoundary: ({
  children,
  errorFallback,
  errorFallbackRender,
  ErrorFallbackComponent,
  loadingFallback
}: SuspenseBoundaryProps) => react_jsx_runtime1.JSX.Element;
//#endregion
export { QueriesBoundary, type QueriesBoundaryProps, QueryBoundary, type QueryBoundaryProps, SuspenseBoundary, type SuspenseBoundaryProps, isDefinedQueryObserverResult, isQueryObserverLoadingErrorResult, isQueryObserverLoadingResult };
//# sourceMappingURL=react-query.d.cts.map