import { EventBus } from '../core/EventBus';
import React from 'react';
export type TelemetryEventCategory = 'gameplay' | 'combat' | 'navigation' | 'interaction' | 'economy' | 'social' | 'progression' | 'performance' | 'ui' | 'error' | 'custom';
export type HeatmapType = 'death' | 'traversal' | 'interaction' | 'combat' | 'loot' | 'custom';
export type SessionEventType = 'position' | 'action' | 'input' | 'state-change' | 'camera' | 'dialogue' | 'inventory' | 'quest';
export interface TelemetryEvent {
    id: string;
    category: TelemetryEventCategory;
    name: string;
    timestamp: number;
    sessionId: string;
    userId?: string;
    data: Record<string, unknown>;
    position?: {
        x: number;
        y: number;
        z?: number;
    };
    sceneId?: string;
    /** Build/version where this event occurred */
    buildVersion?: string;
}
export interface TelemetryConfig {
    enabled: boolean;
    /** Batch size before flush */
    batchSize: number;
    /** Flush interval (ms) */
    flushIntervalMs: number;
    /** Max events to keep in memory */
    maxBufferSize: number;
    /** Filter: only collect these categories (empty = all) */
    categories: TelemetryEventCategory[];
    /** Sample rate (0–1): fraction of events to keep */
    sampleRate: number;
    /** Custom endpoint for sending events */
    endpoint?: string;
}
export declare const DEFAULT_TELEMETRY_CONFIG: TelemetryConfig;
export interface HeatmapConfig {
    type: HeatmapType;
    /** Grid cell size in world units */
    cellSize: number;
    /** World bounds */
    bounds: {
        minX: number;
        minY: number;
        maxX: number;
        maxY: number;
    };
    /** Color gradient (value 0→1 mapped to colors) */
    colorStops: {
        value: number;
        color: string;
    }[];
    /** Max value for normalization (0 = auto) */
    maxValue: number;
    /** Gaussian blur radius (cells) */
    blurRadius: number;
}
export interface HeatmapCell {
    x: number;
    y: number;
    value: number;
    events: number;
}
export declare const DEFAULT_HEATMAP_CONFIG: HeatmapConfig;
export interface SessionFrame {
    timestamp: number;
    delta: number;
    events: SessionRecordedEvent[];
}
export interface SessionRecordedEvent {
    type: SessionEventType;
    data: Record<string, unknown>;
}
export interface SessionRecording {
    id: string;
    sessionId: string;
    startedAt: number;
    endedAt: number;
    durationMs: number;
    frameCount: number;
    frames: SessionFrame[];
    metadata: {
        sceneId: string;
        buildVersion: string;
        playerLevel?: number;
        tags: string[];
    };
    /** Compressed size in bytes (if compressed) */
    sizeBytes: number;
}
export interface SessionRecordingConfig {
    enabled: boolean;
    /** Target frames per second for recording */
    fps: number;
    /** Max recording duration (ms, 0 = unlimited) */
    maxDurationMs: number;
    /** What events to record */
    recordTypes: SessionEventType[];
    /** Record player position every frame */
    recordPosition: boolean;
    /** Compress recording data */
    compress: boolean;
}
export declare const DEFAULT_RECORDING_CONFIG: SessionRecordingConfig;
export interface FunnelStep {
    id: string;
    name: string;
    description?: string;
    /** Number of users/sessions that reached this step */
    count: number;
    /** Drop-off rate from previous step */
    dropOffRate: number;
}
export interface FunnelDefinition {
    id: string;
    name: string;
    steps: {
        id: string;
        name: string;
        eventName: string;
    }[];
}
export declare class TelemetryPipeline {
    private config;
    private buffer;
    private flushed;
    private flushTimer;
    private sessionId;
    private eventCounter;
    private eventBus;
    constructor(eventBus: EventBus, config?: Partial<TelemetryConfig>);
    private generateId;
    /** Track a telemetry event */
    track(category: TelemetryEventCategory, name: string, data?: Record<string, unknown>, position?: {
        x: number;
        y: number;
        z?: number;
    }): void;
    /** Flush buffered events */
    flush(): TelemetryEvent[];
    private startFlushTimer;
    /** Get all events (current buffer + flushed) */
    getAllEvents(): TelemetryEvent[];
    /** Get events by category */
    getByCategory(category: TelemetryEventCategory): TelemetryEvent[];
    /** Get event count by name */
    countByName(name: string): number;
    getSessionId(): string;
    getBufferSize(): number;
    getTotalEvents(): number;
    clear(): void;
    destroy(): void;
}
export declare class HeatmapGenerator {
    private config;
    private grid;
    private totalEvents;
    constructor(config?: Partial<HeatmapConfig>);
    private cellKey;
    private worldToCell;
    /** Add an event at a world position */
    addEvent(x: number, y: number, weight?: number): void;
    /** Add events from telemetry data */
    addFromTelemetry(events: TelemetryEvent[]): void;
    /** Get the grid as an array of cells with normalized values */
    getCells(): HeatmapCell[];
    /** Apply Gaussian blur to the grid */
    getBlurredCells(): HeatmapCell[];
    /** Render heatmap to a canvas */
    renderToCanvas(ctx: CanvasRenderingContext2D, width: number, height: number): void;
    private interpolateColor;
    private lerpColor;
    getTotalEvents(): number;
    getConfig(): Readonly<HeatmapConfig>;
    clear(): void;
}
export declare class SessionRecorder {
    private config;
    private recording;
    private frames;
    private startedAt;
    private lastFrameTime;
    private pendingEvents;
    private recordTimer;
    private sessionId;
    constructor(config?: Partial<SessionRecordingConfig>);
    /** Start recording */
    start(): void;
    /** Stop recording and return the session */
    stop(sceneId?: string, buildVersion?: string): SessionRecording;
    /** Add an event to the current frame batch */
    recordEvent(type: SessionEventType, data: Record<string, unknown>): void;
    /** Record player position (convenience) */
    recordPosition(x: number, y: number, z?: number): void;
    private captureFrame;
    isRecording(): boolean;
    getFrameCount(): number;
    getDurationMs(): number;
}
export declare class SessionPlayer {
    private recording;
    private currentFrame;
    private playing;
    private speed;
    private playTimer;
    private onFrame;
    load(recording: SessionRecording): void;
    /** Start playback */
    play(onFrame: (frame: SessionFrame, index: number) => void): void;
    private advanceFrame;
    stop(): void;
    pause(): void;
    seek(frameIndex: number): void;
    setSpeed(speed: number): void;
    getProgress(): number;
    isPlaying(): boolean;
}
export declare class FunnelTracker {
    private funnels;
    private progress;
    define(funnel: FunnelDefinition): void;
    /** Record that a session reached a funnel step */
    recordStep(funnelId: string, stepEventName: string, sessionId: string): void;
    /** Get funnel analysis */
    analyze(funnelId: string): FunnelStep[];
    getFunnels(): FunnelDefinition[];
}
export declare class GameplayAnalytics {
    readonly telemetry: TelemetryPipeline;
    readonly recorder: SessionRecorder;
    readonly funnels: FunnelTracker;
    private heatmaps;
    private eventBus;
    constructor(eventBus: EventBus, telemetryConfig?: Partial<TelemetryConfig>, recordingConfig?: Partial<SessionRecordingConfig>);
    /** Create or get a heatmap */
    heatmap(id: string, config?: Partial<HeatmapConfig>): HeatmapGenerator;
    /** Track and automatically distribute to relevant heatmaps */
    trackEvent(category: TelemetryEventCategory, name: string, data?: Record<string, unknown>, position?: {
        x: number;
        y: number;
        z?: number;
    }): void;
    /** Get summary stats */
    getSummary(): {
        totalEvents: number;
        sessionId: string;
        heatmapCount: number;
        isRecording: boolean;
        recordedFrames: number;
    };
    destroy(): void;
}
export declare function useGameplayAnalytics(eventBus: EventBus, telemetryConfig?: Partial<TelemetryConfig>, recordingConfig?: Partial<SessionRecordingConfig>): {
    analytics: GameplayAnalytics;
    trackEvent: (category: TelemetryEventCategory, name: string, data?: Record<string, unknown>, position?: {
        x: number;
        y: number;
        z?: number;
    }) => void;
    summary: {
        totalEvents: number;
        sessionId: string;
        heatmapCount: number;
        isRecording: boolean;
        recordedFrames: number;
    };
    refreshSummary: () => void;
    startRecording: () => void;
    stopRecording: (sceneId?: string) => SessionRecording;
    heatmap: (id: string, config?: Partial<HeatmapConfig>) => HeatmapGenerator;
};
export interface AnalyticsDashboardProps {
    analytics: GameplayAnalytics;
    className?: string;
    style?: React.CSSProperties;
}
export declare const AnalyticsDashboard: React.FC<AnalyticsDashboardProps>;
