"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExactMatcher = void 0;
class ExactMatcher {
    constructor() {
        this.name = 'ExactMatcher';
    }
    match(searchBlock, content) {
        const parts = content.split(searchBlock);
        if (parts.length === 1) {
            return {
                found: false,
                unique: false,
                confidence: 0,
                candidates: [],
            };
        }
        if (parts.length > 2) {
            return {
                found: true,
                unique: false,
                confidence: 1.0,
                candidates: this.extractAllCandidates(searchBlock, content),
            };
        }
        return {
            found: true,
            unique: true,
            confidence: 1.0,
            before: parts[0],
            after: parts[1],
        };
    }
    extractAllCandidates(searchBlock, content) {
        const candidates = [];
        const lines = content.split('\n');
        const searchLines = searchBlock.split('\n');
        let currentIndex = 0;
        while (true) {
            const foundIndex = content.indexOf(searchBlock, currentIndex);
            if (foundIndex === -1)
                break;
            const startLine = content.substring(0, foundIndex).split('\n').length - 1;
            const endLine = startLine + searchLines.length - 1;
            const beforeAnchor = startLine > 0 ? lines[startLine - 1] : undefined;
            const afterAnchor = endLine < lines.length - 1 ? lines[endLine + 1] : undefined;
            candidates.push({
                block: searchBlock,
                startLine,
                endLine,
                confidence: 1.0,
                beforeAnchor,
                afterAnchor,
            });
            currentIndex = foundIndex + 1;
        }
        return candidates;
    }
}
exports.ExactMatcher = ExactMatcher;
//# sourceMappingURL=exact.matcher.js.map