import * as _angular_core from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';
import { CdkDragStart, CdkDragDrop } from '@angular/cdk/drag-drop';
import * as _masterteam_components_formula from '@masterteam/components/formula';

/**
 * Flat Formula Token Model
 *
 * The formula is represented as a FLAT array of tokens.
 * This approach provides:
 * - Better performance (no deep component nesting)
 * - Solid drag-drop behavior (functions move as complete units)
 * - Simple serialization (just join token values)
 *
 * STRUCTURE RULES:
 * - fn-open: "IF(" - function name + opening paren as ONE token
 * - fn-close: ")" - closing paren, belongs to a function
 * - fn-separator: "," - argument separator, belongs to a function
 * - Dragging any structural token moves the ENTIRE function
 * - Content tokens (property, operator, literal) can move individually
 */
/** Token types */
type TokenType = 'fn-open' | 'fn-close' | 'fn-separator' | 'property' | 'operator' | 'literal';
/** What happens when this token is dragged */
type DragBehavior = 'function' | 'single';
/**
 * Formula Token - a single element in the flat formula array
 */
interface FormulaToken {
    id: string;
    type: TokenType;
    value: string;
    functionId?: string;
    depth: number;
    argIndex?: number;
    dragBehavior: DragBehavior;
    functionName?: string;
    propertyType?: 'current' | 'children' | 'parent';
    literalType?: 'string' | 'number' | 'boolean';
}
/**
 * Function structure info - tracks open/close pairs
 */
interface FunctionInfo {
    id: string;
    name: string;
    openIndex: number;
    closeIndex: number;
    argCount: number;
    depth: number;
}
/** Generate unique token ID */
declare function generateTokenId(): string;
/** Generate unique function ID */
declare function generateFunctionId(): string;
/** Parse function signature like "SUM(values)" or "IF(cond, a, b)" */
declare function parseSignature(signature: string): {
    name: string;
    args: string[];
};
/**
 * Create a function's tokens from signature
 * e.g., "IF(condition, trueVal, falseVal)" creates:
 * - fn-open: "IF("
 * - fn-separator: "," (x2)
 * - fn-close: ")"
 */
declare function createFunctionTokens(signature: string, depth?: number): FormulaToken[];
/**
 * Create a property token
 */
declare function createPropertyToken(propertyKey: string, propertyType?: 'current' | 'children' | 'parent', depth?: number, functionId?: string, argIndex?: number): FormulaToken;
/**
 * Create an operator token
 */
declare function createOperatorToken(symbol: string, depth?: number, functionId?: string, argIndex?: number): FormulaToken;
/**
 * Create a literal token
 */
declare function createLiteralToken(value: string | number | boolean, depth?: number, functionId?: string, argIndex?: number): FormulaToken;
/**
 * Find the complete range of a function in the token array
 * This includes ALL tokens between fn-open and fn-close (including nested content)
 * Returns [startIndex, endIndex] inclusive
 */
declare function findFunctionRange(tokens: FormulaToken[], functionId: string): [number, number] | null;
/**
 * Get all tokens belonging to a function (including nested content)
 */
declare function getFunctionTokens(tokens: FormulaToken[], functionId: string): FormulaToken[];
/**
 * Validate if a drop position is allowed
 */
declare function isValidDropPosition(tokens: FormulaToken[], dropIndex: number, draggedTokens: FormulaToken[]): boolean;
/**
 * Serialize tokens to formula string
 */
declare function serializeTokens(tokens: FormulaToken[]): string;
/**
 * Clone a token with new ID
 */
declare function cloneToken(token: FormulaToken): FormulaToken;
/**
 * Clone multiple tokens with new IDs and new function IDs
 */
declare function cloneTokens(tokens: FormulaToken[]): FormulaToken[];
/**
 * Update depth for all tokens (after move)
 */
declare function recalculateDepths(tokens: FormulaToken[]): FormulaToken[];
/**
 * Find which argument index a position belongs to within a function
 */
declare function getArgumentIndexAtPosition(tokens: FormulaToken[], functionId: string, position: number): number;

/**
 * Smart Formula Block - Types and Factory Functions
 * Defines the block structure and creation helpers
 */
/** Block type */
type BlockType = 'function' | 'property' | 'operator' | 'literal';
/** Argument slot for functions */
interface ArgumentSlot {
    id: string;
    name: string;
    blocks: SmartBlock[];
    placeholder?: string;
}
/** Smart block structure */
interface SmartBlock {
    id: string;
    type: BlockType;
    value: string;
    functionName?: string;
    signature?: string;
    arguments?: ArgumentSlot[];
    propertyType?: 'current' | 'children' | 'parent';
    propertyKey?: string;
    operatorSymbol?: string;
    literalValue?: string | number | boolean;
}
/** Generate unique block ID */
declare function generateSmartBlockId(): string;
/** Create a function block from signature */
declare function createFunctionBlock(signature: string, name?: string): SmartBlock;
/** Create a property block */
declare function createPropertyBlock(propertyKey: string, propertyType?: 'current' | 'children' | 'parent'): SmartBlock;
/** Create an operator block */
declare function createOperatorBlock(symbol: string): SmartBlock;
/** Create a literal block */
declare function createLiteralBlock(value: string | number | boolean): SmartBlock;
/** Deep clone a block with new IDs */
declare function cloneBlock(block: SmartBlock): SmartBlock;

/**
 * Validation Result Models
 * API response types for formula validation
 */
/** Validation error/warning severity */
type ValidationSeverity = 'Error' | 'Warning';
/** Validation error or warning */
interface ValidationError {
    message: string;
    line: number;
    column: number;
    severity: ValidationSeverity;
}
/** Validation warning (same structure as error) */
type ValidationWarning = ValidationError;
/** Complete validation result from API */
interface ValidationResult {
    isValid: boolean;
    errors: ValidationError[];
    warnings: ValidationWarning[];
    dependencies: string[];
    complexity: number;
}
/** Validation request payload */
interface ValidationRequest {
    formula: string;
    knownProperties?: string[];
    levelSchemaId?: number;
    templateId?: number;
}
/** Autocomplete suggestion */
interface AutocompleteSuggestion {
    text: string;
    displayText: string;
    type: 'Function' | 'Property' | 'Operator' | 'Context';
    description: string;
    insertText: string;
    category?: string;
}
/** Autocomplete context */
interface AutocompleteContext {
    type: 'None' | 'Function' | 'Property' | 'Operator';
    scope: string;
    prefix: string;
}
/** Autocomplete response from API */
interface AutocompleteResponse {
    suggestions: AutocompleteSuggestion[];
    context: AutocompleteContext;
}
/** Autocomplete request payload */
interface AutocompleteRequest {
    formula: string;
    cursorPosition: number;
    knownProperties?: string[];
    levelSchemaId?: number;
}
/** API error response */
interface ApiErrorResponse {
    error: string;
    message?: string;
}

/**
 * Formula Block Model - Types for formula functions and operators
 */
/** Function category types */
type FunctionCategory = 'Math' | 'Aggregation' | 'Logic' | 'Hierarchy' | 'Date' | 'String' | 'PhaseGate';
/** Parameter definition for a function */
interface ParameterDefinition {
    name: string;
    type: string;
    description: string;
    required: boolean;
    defaultValue?: unknown;
}
/** Function definition */
interface FunctionDefinition {
    name: string;
    category: FunctionCategory;
    description: string;
    signature: string;
    parameters: ParameterDefinition[];
    returnType: string;
    examples: string[];
}
/** Function category group */
interface FunctionCategoryGroup {
    name: FunctionCategory;
    displayName: string;
    functions: FunctionDefinition[];
}
/** Operator definition */
interface OperatorDefinition {
    symbol: string;
    name: string;
    type: 'arithmetic' | 'comparison' | 'logical';
    description: string;
    precedence: number;
}

declare class FormulaEditor implements ControlValueAccessor {
    readonly placeholder: _angular_core.InputSignal<string>;
    readonly initialTokens: _angular_core.InputSignal<FormulaToken[]>;
    readonly disabled: _angular_core.InputSignal<boolean>;
    readonly formulaChange: _angular_core.OutputEmitterRef<string>;
    readonly tokensChange: _angular_core.OutputEmitterRef<FormulaToken[]>;
    readonly onBlur: _angular_core.OutputEmitterRef<void>;
    readonly onFocus: _angular_core.OutputEmitterRef<void>;
    readonly tokens: _angular_core.WritableSignal<FormulaToken[]>;
    /** Index range being dragged [start, end] inclusive */
    private draggedRange;
    /** Is currently dragging */
    readonly isDragging: _angular_core.WritableSignal<boolean>;
    /** Hovered function ID for highlighting */
    readonly hoveredFunctionId: _angular_core.WritableSignal<string | null>;
    /** Is focused */
    readonly isFocused: _angular_core.WritableSignal<boolean>;
    private onChange;
    private onTouched;
    /** Line numbers based on token count */
    readonly lines: _angular_core.Signal<any[]>;
    /** Serialized formula string */
    readonly formulaString: _angular_core.Signal<string>;
    constructor();
    writeValue(value: FormulaToken[] | null): void;
    registerOnChange(fn: (value: FormulaToken[]) => void): void;
    registerOnTouched(fn: () => void): void;
    /**
     * Add a block from toolbar (converts SmartBlock to tokens)
     */
    addBlock(block: SmartBlock): void;
    /**
     * Add tokens directly
     */
    addTokens(newTokens: FormulaToken[]): void;
    /**
     * Clear all tokens
     */
    clear(): void;
    /**
     * Get current formula string
     */
    serialize(): string;
    /**
     * Get current tokens
     */
    getTokens(): FormulaToken[];
    handleFocus(): void;
    handleBlur(): void;
    /**
     * Handle drag start - determine what tokens to drag
     */
    onDragStart(event: CdkDragStart, token: FormulaToken, index: number): void;
    /**
     * Handle drop - reorder tokens in the formula
     */
    onDrop(event: CdkDragDrop<FormulaToken[]>): void;
    /**
     * Reset drag state
     */
    private resetDragState;
    /**
     * Handle drag end
     * NOTE: CDK fires cdkDragEnded BEFORE cdkDropListDropped
     * So we don't reset draggedRange here - onDrop handles it
     */
    onDragEnd(): void;
    /**
     * Remove a token or function
     */
    removeToken(token: FormulaToken, index: number): void;
    onTokenHover(token: FormulaToken): void;
    onTokenLeave(): void;
    /**
     * Check if token should be highlighted
     * Only structural tokens (fn-open, fn-close, fn-separator) get highlighted
     * Content tokens (property, operator, literal) inside function are NOT highlighted
     */
    isHighlighted(token: FormulaToken): boolean;
    /** Base token classes */
    private readonly baseTokenClasses;
    /**
     * Get Tailwind classes for a token
     */
    getTokenClasses(token: FormulaToken): string;
    /**
     * Convert SmartBlock to FormulaTokens
     */
    private smartBlockToTokens;
    private emit;
    /**
     * Track function for ngFor
     */
    trackByToken(_index: number, token: FormulaToken): string;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<FormulaEditor, never>;
    static ɵcmp: _angular_core.ɵɵComponentDeclaration<FormulaEditor, "mt-formula-editor", never, { "placeholder": { "alias": "placeholder"; "required": false; "isSignal": true; }; "initialTokens": { "alias": "initialTokens"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; }, { "formulaChange": "formulaChange"; "tokensChange": "tokensChange"; "onBlur": "onBlur"; "onFocus": "onFocus"; }, never, never, true, never>;
}

type ToolbarTab = 'functions' | 'properties' | 'operators';
interface OperatorGroup {
    type: string;
    operators: OperatorDefinition[];
}
declare class FormulaToolbar {
    /** Known properties to show in properties tab */
    readonly knownProperties: _angular_core.InputSignal<string[]>;
    /** Function categories (from API or static data) */
    readonly functionCategories: _angular_core.InputSignal<FunctionCategoryGroup[]>;
    /** Operators list */
    readonly operators: _angular_core.InputSignal<OperatorDefinition[]>;
    /** Initial active tab */
    readonly initialTab: _angular_core.InputSignal<ToolbarTab>;
    /** Placeholder for search input */
    readonly searchPlaceholder: _angular_core.InputSignal<string>;
    /** Labels */
    readonly labels: _angular_core.InputSignal<{
        functions?: string;
        properties?: string;
        operators?: string;
        noFunctionsFound?: string;
        noPropertiesAvailable?: string;
        noOperatorsFound?: string;
    }>;
    /** Insert event - emits SmartBlock for the editor */
    readonly onBlockInsert: _angular_core.OutputEmitterRef<SmartBlock>;
    /** Tab change event */
    readonly onTabChange: _angular_core.OutputEmitterRef<ToolbarTab>;
    /** Active tab */
    readonly activeTab: _angular_core.WritableSignal<ToolbarTab>;
    /** Tab options */
    readonly tabOptions: {
        label: string;
        value: ToolbarTab;
    }[];
    /** Search query */
    readonly searchQuery: _angular_core.WritableSignal<string>;
    /** Custom value input */
    readonly customValue: _angular_core.WritableSignal<string>;
    /** Detected type of custom value */
    readonly customValueType: _angular_core.Signal<"string" | "number" | "text">;
    /** Preview of custom value */
    readonly customValuePreview: _angular_core.Signal<string>;
    /** CSS class for custom value type */
    readonly customValueTypeClass: _angular_core.Signal<"bg-rose-100 text-rose-700 hover:bg-rose-200 dark:bg-rose-900/30 dark:text-rose-300 dark:hover:bg-rose-900/50" | "bg-emerald-100 text-emerald-700 hover:bg-emerald-200 dark:bg-emerald-900/30 dark:text-emerald-300 dark:hover:bg-emerald-900/50" | "bg-slate-100 text-slate-700 hover:bg-slate-200 dark:bg-slate-700 dark:text-slate-300 dark:hover:bg-slate-600">;
    constructor();
    /** Filtered categories based on search */
    readonly filteredCategories: _angular_core.Signal<FunctionCategoryGroup[]>;
    /** Filtered properties based on search */
    readonly filteredProperties: _angular_core.Signal<string[]>;
    /** Filtered operators based on search */
    readonly filteredOperators: _angular_core.Signal<OperatorDefinition[]>;
    /** Count of filtered items per tab */
    readonly filteredFunctionsCount: _angular_core.Signal<number>;
    readonly filteredPropertiesCount: _angular_core.Signal<number>;
    readonly filteredOperatorsCount: _angular_core.Signal<number>;
    /** Smart search effect - switches to tab with results */
    private readonly smartSearchEffect;
    /** Group operators by type */
    readonly operatorGroups: _angular_core.Signal<OperatorGroup[]>;
    /** Total item count for current tab */
    readonly itemCount: _angular_core.Signal<number>;
    readonly labelFunctions: _angular_core.Signal<string>;
    readonly labelProperties: _angular_core.Signal<string>;
    readonly labelOperators: _angular_core.Signal<string>;
    readonly labelNoFunctions: _angular_core.Signal<string>;
    readonly labelNoProperties: _angular_core.Signal<string>;
    readonly labelNoOperators: _angular_core.Signal<string>;
    /** Get count for a specific tab (filtered when searching) */
    getTabCount(tab: ToolbarTab): number;
    /** Check if a tab has results when searching */
    tabHasResults(tab: ToolbarTab): boolean;
    /** Set active tab */
    setActiveTab(tab: ToolbarTab): void;
    /** Emit block insert event */
    insertBlock(block: SmartBlock): void;
    /** Clear search */
    clearSearch(): void;
    /** Insert custom value */
    insertCustomValue(): void;
    /** Clear custom value input */
    clearCustomValue(): void;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<FormulaToolbar, never>;
    static ɵcmp: _angular_core.ɵɵComponentDeclaration<FormulaToolbar, "mt-formula-toolbar", never, { "knownProperties": { "alias": "knownProperties"; "required": false; "isSignal": true; }; "functionCategories": { "alias": "functionCategories"; "required": false; "isSignal": true; }; "operators": { "alias": "operators"; "required": false; "isSignal": true; }; "initialTab": { "alias": "initialTab"; "required": false; "isSignal": true; }; "searchPlaceholder": { "alias": "searchPlaceholder"; "required": false; "isSignal": true; }; "labels": { "alias": "labels"; "required": false; "isSignal": true; }; }, { "onBlockInsert": "onBlockInsert"; "onTabChange": "onTabChange"; }, never, never, true, never>;
}

type ToolbarItemType = 'function' | 'property' | 'operator';
declare class FormulaToolbarItem {
    /** Item type */
    readonly type: _angular_core.InputSignal<ToolbarItemType>;
    /** Item value (function name, property key, operator symbol) */
    readonly value: _angular_core.InputSignal<string>;
    /** Display value (optional, defaults to value) */
    readonly display: _angular_core.InputSignal<string | undefined>;
    /** Description for tooltip */
    readonly description: _angular_core.InputSignal<string>;
    /** Function signature (for functions only, e.g., "SUM(values)") */
    readonly signature: _angular_core.InputSignal<string | undefined>;
    /** Property type for properties */
    readonly propertyType: _angular_core.InputSignal<"current" | "children" | "parent">;
    /** Insert event - emits SmartBlock */
    readonly onInsert: _angular_core.OutputEmitterRef<SmartBlock>;
    /** Computed display value */
    readonly displayValue: _angular_core.Signal<string>;
    /** Build SmartBlock from item data */
    readonly smartBlock: _angular_core.Signal<SmartBlock>;
    /** Item CSS class based on type */
    readonly itemClass: _angular_core.Signal<"bg-slate-200 text-slate-700 hover:bg-slate-300 dark:bg-slate-700 dark:text-slate-300 dark:hover:bg-slate-600" | "bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-900/30 dark:text-amber-300 dark:hover:bg-amber-900/50" | "bg-sky-100 text-sky-700 hover:bg-sky-200 dark:bg-sky-900/30 dark:text-sky-300 dark:hover:bg-sky-900/50" | "bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300">;
    /** Handle click - emit the SmartBlock */
    handleClick(): void;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<FormulaToolbarItem, never>;
    static ɵcmp: _angular_core.ɵɵComponentDeclaration<FormulaToolbarItem, "mt-formula-toolbar-item", never, { "type": { "alias": "type"; "required": true; "isSignal": true; }; "value": { "alias": "value"; "required": true; "isSignal": true; }; "display": { "alias": "display"; "required": false; "isSignal": true; }; "description": { "alias": "description"; "required": false; "isSignal": true; }; "signature": { "alias": "signature"; "required": false; "isSignal": true; }; "propertyType": { "alias": "propertyType"; "required": false; "isSignal": true; }; }, { "onInsert": "onInsert"; }, never, never, true, never>;
}

declare class FormulaStatusBar {
    /** Validation result */
    readonly validation: _angular_core.InputSignal<ValidationResult | null>;
    /** Labels for i18n support */
    readonly labels: _angular_core.InputSignal<{
        valid?: string;
        invalid?: string;
        complexity?: string;
        dependencies?: string;
    }>;
    /** Is formula valid */
    readonly isValid: _angular_core.Signal<boolean>;
    /** Complexity score */
    readonly complexity: _angular_core.Signal<number>;
    /** Dependencies list */
    readonly dependencies: _angular_core.Signal<string[]>;
    /** Dependencies as text */
    readonly dependenciesText: _angular_core.Signal<string>;
    /** First error */
    readonly firstError: _angular_core.Signal<_masterteam_components_formula.ValidationError | null>;
    /** Complexity CSS class */
    readonly complexityClass: _angular_core.Signal<"text-emerald-600 dark:text-emerald-400" | "text-amber-600 dark:text-amber-400" | "text-rose-600 dark:text-rose-400">;
    readonly labelValid: _angular_core.Signal<string>;
    readonly labelInvalid: _angular_core.Signal<string>;
    readonly labelComplexity: _angular_core.Signal<string>;
    readonly labelDependencies: _angular_core.Signal<string>;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<FormulaStatusBar, never>;
    static ɵcmp: _angular_core.ɵɵComponentDeclaration<FormulaStatusBar, "mt-formula-status-bar", never, { "validation": { "alias": "validation"; "required": false; "isSignal": true; }; "labels": { "alias": "labels"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
}

export { FormulaEditor, FormulaStatusBar, FormulaToolbar, FormulaToolbarItem, cloneBlock, cloneToken, cloneTokens, createFunctionBlock, createFunctionTokens, createLiteralBlock, createLiteralToken, createOperatorBlock, createOperatorToken, createPropertyBlock, createPropertyToken, findFunctionRange, generateFunctionId, generateSmartBlockId, generateTokenId, getArgumentIndexAtPosition, getFunctionTokens, isValidDropPosition, parseSignature, recalculateDepths, serializeTokens };
export type { ApiErrorResponse, ArgumentSlot, AutocompleteContext, AutocompleteRequest, AutocompleteResponse, AutocompleteSuggestion, BlockType, DragBehavior, FormulaToken, FunctionCategory, FunctionCategoryGroup, FunctionDefinition, FunctionInfo, OperatorDefinition, ParameterDefinition, SmartBlock, TokenType, ToolbarItemType, ToolbarTab, ValidationError, ValidationRequest, ValidationResult, ValidationSeverity, ValidationWarning };
