"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseQueryText = parseQueryText;
const operators_1 = require("./operators");
/**
 * Parse user input text to extract property, operator, and value components.
 * Handles partial input (e.g., user typing "Status !" to complete the operator).
 */
function parseQueryText(filteringText, filteringProperties) {
    const property = (0, operators_1.matchFilteringProperty)(filteringProperties, filteringText);
    if (!property) {
        const freeTextOperator = (0, operators_1.matchOperator)(operators_1.QUERY_OPERATORS, filteringText);
        if (freeTextOperator) {
            return {
                step: "free-text",
                operator: freeTextOperator,
                value: filteringText.substring(freeTextOperator.length).trimStart(),
            };
        }
        return {
            step: "free-text",
            value: filteringText,
        };
    }
    const textWithoutProperty = filteringText
        .substring(property.label.length)
        .trimStart();
    const operator = (0, operators_1.matchOperator)(operators_1.QUERY_OPERATORS, textWithoutProperty);
    if (operator) {
        return {
            step: "property",
            property,
            operator,
            value: textWithoutProperty.substring(operator.length).trimStart(),
        };
    }
    const operatorPrefix = (0, operators_1.matchOperatorPrefix)(operators_1.QUERY_OPERATORS, textWithoutProperty);
    if (operatorPrefix !== null) {
        return { step: "operator", property, operatorPrefix };
    }
    return {
        step: "free-text",
        value: filteringText,
    };
}
//# sourceMappingURL=parse-query-text.js.map