import { I as ISymbolType, C as Config, A as ASTNode } from '../types-BDMPkFsT.js';

type InterpreterResult = ISymbolType | string | null;

type FlattenCallback<T> = (key: string, value: InterpreterResult) => T;
/**
 * Flatten a DictionarySymbol into key-value pairs
 *
 * @param result - The InterpreterResult to flatten (only DictionarySymbol will be flattened)
 * @param prefix - The prefix to prepend to keys
 * @param callback - Callback function that receives each flattened key-value pair
 *
 * @example
 * const result: Record<string, unknown> = {};
 * flattenChildrenObject(dictionarySymbol, "root", (key, value) => {
 *   result[key] = value;
 * });
 */
declare function flattenChildrenObject<T>(result: InterpreterResult, prefix: string, callback: FlattenCallback<T>): void;
/**
 * Flatten a Map structure into key-value pairs
 *
 * @param map - The map to flatten (from Dictionary.value)
 * @param prefix - The prefix to prepend to keys
 * @param callback - Callback function that receives each flattened key-value pair
 *
 * @example
 * const result = new Map<string, unknown>();
 * flattenChildrenMap(dictionarySymbol.value, "root", (key, value) => {
 *   result.set(key, value);
 * });
 */
declare function flattenChildrenMap<T>(map: Map<string, InterpreterResult>, prefix: string, callback: FlattenCallback<T>): void;

interface TokenBuilder<T = unknown> {
    onResolve(tokenName: string, value: InterpreterResult): void;
    onError(tokenName: string, error: Error, originalValue: string): void;
    getResult(): T;
    readonly name: string;
}
type BuilderFormat = "nested" | "flat" | "map";
type OutputFormat = "string" | "symbols";

declare class MapBuilder implements TokenBuilder<Map<string, string | InterpreterResult>> {
    private outputFormat;
    readonly name = "map";
    private result;
    private successfullyResolved;
    constructor(outputFormat?: "string" | "symbols");
    onResolve(tokenName: string, value: InterpreterResult): void;
    onError(tokenName: string, _error: Error, originalValue: string): void;
    getResult(): Map<string, string | InterpreterResult>;
    getResolvedTokens(): Map<string, InterpreterResult>;
}

/**
 * Nested Object Builder
 *
 * Builds a nested object structure incrementally as tokens are resolved.
 * Converts flat token paths to nested structure.
 * Example: "color.primary" -> { color: { primary: value } }
 */
declare class NestedObjectBuilder implements TokenBuilder<Record<string, unknown>> {
    readonly name = "nested";
    private result;
    onResolve(tokenName: string, value: InterpreterResult): void;
    onError(tokenName: string, _error: Error, originalValue: string): void;
    getResult(): Record<string, unknown>;
}
/**
 * Flat Object Builder
 *
 * Builds a flat key-value object incrementally as tokens are resolved.
 * Example: "color.primary" -> { "color.primary": value }
 */
declare class FlatObjectBuilder implements TokenBuilder<Record<string, unknown>> {
    readonly name = "flat";
    private result;
    onResolve(tokenName: string, value: InterpreterResult): void;
    onError(tokenName: string, _error: Error, originalValue: string): void;
    getResult(): Record<string, unknown>;
}

declare class DependencyError extends Error {
    readonly dependencyChain: string[];
    readonly rootError: Error;
    constructor(tokenName: string, dependencyName: string, originalError: Error);
    private static extractChain;
    private static extractRootError;
}

declare const defaultObjectParsers: ObjectParser[];

/**
 * Matches objects with shape { value: number, unit: string }.
 */
declare const numberWithUnitParser: ObjectParser;

/**
 * ObjectParser allows custom transformation of structured values into interpreter symbols.
 * This is useful for parsing complex nested structures like { value: 1, unit: "rem" } into NumberWithUnitSymbol.
 *
 * @example
 * const numberWithUnitParser: ObjectParser = {
 *   predicate: (value) => isObject(value) && 'value' in value && 'unit' in value,
 *   toSymbol: ({ value, unit }, config) => new NumberWithUnitSymbol(value, unit, config)
 * }
 */
type ObjectParser = {
    /**
     * Check if this parser should handle the given value
     */
    predicate: (value: unknown) => boolean;
    /**
     * Convert the matched value to an interpreter symbol
     */
    toSymbol: (value: any, config?: Config) => ISymbolType;
};

/**
 * Structured token data containing value and optional type information
 */
interface TokenData {
    $value: unknown;
    $type?: string;
}

declare enum LintSeverity {
    ERROR = "error",
    WARNING = "warning",
    INFO = "info"
}
interface LintIssue {
    ruleId: string;
    code: string;
    severity: LintSeverity;
    message: string;
    tokenName: string;
    line?: number;
    data?: Record<string, unknown>;
}
interface LintResult {
    issues: LintIssue[];
    errors: LintIssue[];
    warnings: LintIssue[];
    hasErrors: boolean;
}
interface LintContext {
    tokenName: string;
    tokenType?: string;
    config?: Config;
    allTokens: Map<string, TokenData>;
    resolvedTokens?: Map<string, InterpreterResult>;
    ast?: ASTNode;
}
interface LintRule {
    id: string;
    severity: LintSeverity;
    tokenTypes?: string[];
    validate(value: InterpreterResult, context: LintContext): LintIssue[];
}
interface LintConfig {
    rules?: Record<string, boolean | LintSeverity>;
}

declare class LintRunner {
    private rules;
    private config;
    constructor(config?: LintConfig);
    addRule(rule: LintRule): this;
    lintResult(options: {
        tokenName: string;
        tokenType: string | undefined;
        result: InterpreterResult;
        allTokens: Map<string, TokenData>;
        resolvedTokens?: Map<string, InterpreterResult>;
        config?: Config;
        ast?: ASTNode;
    }): LintIssue[];
    private isRuleEnabled;
    private applyOverrides;
    aggregateResults(issues: LintIssue[]): LintResult;
}

declare class DependencyGraph<N = string> {
    private nodes;
    addNode(node: N, dependencies?: N[] | Set<N>): void;
    getNodes(): Map<N, Set<N>>;
    entryNodes(): N[];
    private findCycle;
    topologicalSort(): N[];
}

/**
 * Reference path (token name)
 */
type RefPath = string;
/**
 * Result of token interpretation - can be a successful value or an error
 */
type TokenResult = InterpreterResult | Error;
/**
 * Unresolved token data containing AST and dependency information
 */
interface UnresolvedToken {
    ast: ASTNode;
    dependencies: Set<RefPath>;
}

type ResolvedTokens = Map<RefPath, TokenResult>;
type UnresolvedTokens = Map<RefPath, UnresolvedToken>;
type ProcessorResult = {
    graph: DependencyGraph<RefPath>;
    resolved: ResolvedTokens;
    unresolved: UnresolvedTokens;
    subFieldPaths?: Set<RefPath>;
    lintIssues?: LintIssue[];
};
type ProcessorCallbacks = {
    onResolve?: (tokenName: RefPath, value: InterpreterResult) => void;
    onError?: (tokenName: RefPath, error: Error, originalValue: string) => void;
};
type ProcessorOutput = ProcessorResult & {
    tokens: Map<RefPath, InterpreterResult>;
    errors: Map<RefPath, Error>;
    resolver: TokenResolver;
};
/**
 * TokenResolver - Resolves tokens with dependencies using prefix-aware resolution
 *
 * @example
 * const processor = new TokenResolver();
 * const tokens = new Map([
 *   ["a", { $value: "10" }],
 *   ["b", { $value: "{a} * 2" }],
 * ]);
 * const result = processor.build(tokens);
 */
declare class TokenResolver {
    private resolver?;
    private tokens?;
    private config?;
    private objectParsers?;
    processTokens(tokens: Map<RefPath, string | TokenData>, callbacks?: ProcessorCallbacks, config?: Config, objectParsers?: ObjectParser[], linter?: LintRunner): ProcessorResult;
    /**
     * Find all tokens affected by a change to the given token.
     *
     * Uses BFS traversal on the reverse dependency graph to identify
     * the changed token plus all tokens that transitively depend on it.
     *
     * @param tokenName - The token that changed
     * @returns Object containing affected tokens and a subgraph showing their relationships
     *
     * @example
     * const { resolver } = new TokenResolver().build(tokens);
     * const { tokens, subgraph } = resolver.getTokenDependencyGraph("color.primary");
     * console.log(tokens); // Set(['color.primary', 'button.background', ...])
     */
    getTokenDependencyGraph(tokenName: string): {
        tokens: Set<string>;
        subgraph: DependencyGraph<string>;
    };
    build(tokens: Map<RefPath, TokenData>, config?: Config, objectParsers?: ObjectParser[]): ProcessorOutput;
    /**
     * Update a single token and recompute only affected tokens.
     *
     * This method provides efficient incremental updates by:
     * 1. Using the existing resolver's cached reference values
     * 2. Only reprocessing the updated token and its dependents
     * 3. Reusing resolved values for unaffected tokens
     *
     * @param tokenName - Name of the token to update (empty string allowed)
     * @param tokenValue - New value for the token
     * @param tokenType - Type of the token (e.g., "color", "dimension", etc.)
     * @returns The resolved value and dependency subgraph
     *
     * @example
     * const { resolver } = new TokenResolver().build(allTokens);
     * const result = resolver.updateToken("color.primary", "#FF0000", "color");
     * console.log(result.resolvedValue); // Resolved value for color.primary
     */
    updateToken(tokenName: string, tokenValue: string, tokenType?: string): {
        resolvedValue: InterpreterResult | Error;
        affectedTokens: Set<string>;
        subgraph: DependencyGraph<string>;
    };
}

interface ProcessOptions {
    config?: Config;
    output?: OutputFormat;
    builder?: TokenBuilder<any>;
    objectParsers?: ObjectParser[];
    linter?: LintRunner;
}
interface ProcessSetsOptions extends ProcessOptions {
    activeSets?: string[];
    activeTheme?: string;
}
interface ProcessResult<T = Map<string, string | InterpreterResult>> extends ProcessorOutput {
    output: T;
    lint?: LintResult;
}
type ProcessFilesOptions<T = any> = {
    path: string;
    outputPath?: string;
    schemas?: string[];
    activeSets?: string[];
    activeTheme?: string;
    output?: "string" | "symbols";
    builder?: TokenBuilder<T>;
    objectParsers?: ObjectParser[];
};

/**
 * Process flat token collection.
 */
declare function processTokens<T = Map<string, string | InterpreterResult>>(tokens: Map<string, TokenData> | Map<string, string> | Record<string, any>, options?: ProcessOptions): ProcessResult<T>;
/**
 * Process token sets with theme or set selection.
 */
declare function processTokenSets<T = Map<string, string | InterpreterResult>>(normalizedFiles: Record<string, unknown>, options?: ProcessSetsOptions): ProcessResult<T>;

export { type BuilderFormat, DependencyError, FlatObjectBuilder, type FlattenCallback, MapBuilder, NestedObjectBuilder, type ObjectParser, type OutputFormat, type ProcessFilesOptions, type ProcessOptions, type ProcessResult, type ProcessSetsOptions, type ProcessorOutput, type ProcessorResult, type TokenBuilder, TokenResolver, defaultObjectParsers, flattenChildrenMap, flattenChildrenObject, numberWithUnitParser, processTokenSets, processTokens };
