/**
 * PostHog adapter for the TelemetryClient interface.
 *
 * This file is INTERNAL - consumers should only import from telemetry/types.ts
 * and use the TelemetryClient interface.
 */
import type { PostHog, Properties } from 'posthog-js';
import type { ConsentGate } from '../consent';
import type { CanvasSurface, TelemetryClient } from '../types';
export interface PostHogAdapterOptions {
    /**
     * PostHog API key.
     */
    apiKey?: string;
    /**
     * PostHog API host.
     * @default "https://telemetry.syntrologie.com"
     */
    apiHost?: string;
    /**
     * Existing PostHog client to wrap.
     */
    client?: PostHog;
    /**
     * Enable full-page autocapture (clicks, form submissions, etc.)
     * @default true
     */
    autocapture?: boolean;
    /**
     * Enable session recording.
     * @default true
     */
    sessionRecording?: boolean;
    /**
     * Pageview capture mode.
     * - true: capture only on initial page load
     * - 'history_change': auto-capture on SPA navigation (pushState/replaceState)
     * @default "history_change"
     */
    capturePageview?: boolean | 'history_change';
    /**
     * Enable page leave capture.
     * @default true
     */
    capturePageleave?: boolean;
    /**
     * Enable PostHog feature flags for segment membership.
     * When true, PostHog's /decide endpoint is called to get segment flags.
     * These flags (in_segment_*) are used for segment-based targeting.
     *
     * @default true
     */
    enableFeatureFlags?: boolean;
    /**
     * Callback when PostHog feature flags are loaded.
     * Used to update GrowthBook attributes with segment membership.
     */
    onFeatureFlagsLoaded?: (flags: Record<string, boolean | string>) => void;
    /**
     * Callback when any event is captured by PostHog.
     * Used to feed events into the EventBus for runtime decisions.
     */
    onCapture?: (eventName: string, properties?: Record<string, unknown>) => void;
    /**
     * Consent gate for GDPR compliance.
     * When provided with requireExplicitConsent, PostHog initialization is
     * deferred until consent is granted.
     */
    consent?: ConsentGate;
    /**
     * Require explicit consent before initializing PostHog.
     * When true, PostHog will not init until consent.grant() is called.
     * @default false
     */
    requireExplicitConsent?: boolean;
    /**
     * PostHog cookieless tracking mode. Captures events with a privacy-
     * preserving session-scoped hash instead of a persistent cookie.
     *
     * - 'always': never use cookies; always cookieless
     * - 'on_reject': use cookies until consent is rejected, then cookieless
     *
     * Recommended pairing for the SDK consent layer: `'on_reject'` so
     * baseline behavioral telemetry flows for all visitors regardless
     * of consent state, with full identified tracking only after grant.
     *
     * @default undefined (cookies used unconditionally)
     */
    cookieless_mode?: 'always' | 'on_reject';
    /**
     * Enable behavioral signal detection (hesitation, rage click, etc.)
     * Pass `true` for defaults, or a partial DetectorConfig to customize thresholds.
     * @default false
     */
    behavioralSignals?: boolean | Record<string, number>;
    /**
     * Callback for raw rrweb events from session recording.
     * Called with each rrweb eventWithTime before PostHog processes it.
     * Used by the event processor for behavioral signal detection.
     */
    onRRWebEvent?: (event: Record<string, unknown>) => void;
}
interface CanvasAnalyticsPayload extends Properties {
    rectangleId?: string;
    surface?: CanvasSurface;
}
/**
 * Internal adapter that implements TelemetryClient using PostHog.
 */
export declare class PostHogAdapter implements TelemetryClient {
    readonly options: PostHogAdapterOptions;
    private client?;
    private featureFlagsCallback?;
    private captureCallback?;
    private rrwebCallback?;
    constructor(options?: PostHogAdapterOptions);
    /**
     * Initialize the PostHog client. Called immediately (no consent gate)
     * or deferred (when consent gate grants).
     */
    private initPostHog;
    /**
     * Set up rrweb event interception on PostHog's session recording.
     *
     * PostHog lazy-loads the rrweb recorder. The SessionRecording wrapper has
     * an `onRRwebEmit` method, but rrweb delivers events directly to the
     * lazy-loaded recorder instance's `onRRwebEmit`, bypassing the wrapper.
     * We must find and patch the recorder instance, not the wrapper.
     *
     * The recorder instance is stored on a minified property of SessionRecording.
     * We detect it by looking for an object with both `onRRwebEmit` and `start` methods.
     */
    private setupRRWebIntercept;
    /**
     * Get all feature flags from PostHog.
     * Used to extract segment membership flags (in_segment_*).
     */
    getAllFeatureFlags(): Record<string, boolean | string> | undefined;
    /**
     * Get segment membership flags (in_segment_*) from PostHog.
     */
    getSegmentFlags(): Record<string, boolean>;
    identify(id: string, props?: Properties): void;
    alias(id: string, aliasId: string): void;
    /**
     * Opt the current visitor INTO capturing. Drives the granted-state
     * transition from the consent gate. When previously cookieless or
     * opted-out, switches to full identified capture.
     */
    optInCapturing(): void;
    /**
     * Opt the current visitor OUT of capturing. Drives the denied-state
     * transition from the consent gate. Stops sending events; existing
     * cookieless/anonymous events remain in the data warehouse.
     */
    optOutCapturing(): void;
    track(eventName: string, payload?: CanvasAnalyticsPayload): void;
    trackCanvasOpened(surface: CanvasSurface): void;
    trackCanvasClosed(surface: CanvasSurface): void;
    trackRectangleViewed(rectangleId: string, surface: CanvasSurface): void;
    trackAction(action: string, rectangleId: string, surface: CanvasSurface): void;
    register(properties: Record<string, unknown>): void;
    getSessionId(): string | undefined;
    startSessionRecording(): void;
    trackExperiment(experimentKey: string, variationId: number, variationName?: string): void;
    setPersonProperties(properties: Record<string, unknown>): void;
    setPersonPropertiesOnce(properties: Record<string, unknown>): void;
    getDistinctId(): string | undefined;
}
/**
 * Create a TelemetryClient backed by PostHog.
 */
export declare function createPostHogClient(options?: PostHogAdapterOptions): TelemetryClient;
export {};
