import { ComponentType } from 'react';
import { IdTokenClaims, UserinfoResponse } from 'openid-client';
import { AbortSignal } from 'abort-controller';

interface ChunkDependencies {
    [chunkName: string]: {
        modules: string[];
        styles: {
            relPath: string;
            css: string;
        }[];
    };
}

interface ServerAuthAuthenticated {
    isAuthenticated: true;
    credentials: ServerAuthCredentials;
}
interface ServerAuthUnauthenticated {
    error?: unknown;
    isAuthenticated: false;
}
declare type ServerAuth = ServerAuthAuthenticated | ServerAuthUnauthenticated;
interface ServerAuthCredentials {
    audience?: string;
    accessToken: string;
    claims: IdTokenClaims;
    expiresAt: number;
    idToken: string;
    scope: string[];
    user: UserinfoResponse;
}

interface ServerFunctionContext {
    auth: ServerAuth;
    signal?: AbortSignal;
}
interface ServerFunction {
    (ctx: ServerFunctionContext, ...args: any[]): any;
}

declare global {
    var __nostalgie_css: (buildPath: string, css: string) => void;
}
interface ServerRenderRequest {
    auth: ServerAuth;
    automaticReload?: boolean;
    path: string;
}
interface ServerRendererSettings {
    defaultDeadline: number;
    enableTailwind: boolean;
    maxIterations: number;
}
interface ServerRendererOptions extends Partial<ServerRendererSettings> {
}
declare class ServerRenderer {
    private readonly app;
    private readonly functions;
    private readonly chunkDependencies;
    private readonly settings;
    constructor(app: ComponentType, functions: Record<string, ServerFunction>, chunkDependencies: ChunkDependencies, options?: ServerRendererOptions);
    invokeFunction(functionName: string, ctx: ServerFunctionContext, args: any[]): Promise<any>;
    renderAppOnServer(request: ServerRenderRequest): Promise<{
        headers?: Record<string, string>;
        html: string;
        queries: number;
        renderCount: number;
        statusCode?: number;
        latency: number;
    }>;
    private serverAuthToClientAuth;
}

export { ServerRenderRequest, ServerRenderer, ServerRendererOptions };
