import { Pipe } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/platform-browser";
/**
 * Pipe to highlight search terms within text.
 * Usage: {{ text | highlightSearch:searchTerm }}
 *
 * The matching portions will be wrapped in a <mark class="search-highlight"> tag.
 */
export class HighlightSearchPipe {
    sanitizer;
    constructor(sanitizer) {
        this.sanitizer = sanitizer;
    }
    transform(value, searchTerm) {
        if (!value) {
            return '';
        }
        if (!searchTerm || searchTerm.trim() === '') {
            return value;
        }
        // Escape special regex characters in the search term
        const escapedSearchTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
        // Create a case-insensitive regex
        const regex = new RegExp(`(${escapedSearchTerm})`, 'gi');
        // Replace matches with highlighted version
        const highlighted = value.replace(regex, '<mark class="search-highlight">$1</mark>');
        // Return as SafeHtml to allow innerHTML binding
        return this.sanitizer.bypassSecurityTrustHtml(highlighted);
    }
    static ɵfac = function HighlightSearchPipe_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || HighlightSearchPipe)(i0.ɵɵdirectiveInject(i1.DomSanitizer, 16)); };
    static ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ name: "highlightSearch", type: HighlightSearchPipe, pure: true, standalone: false });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(HighlightSearchPipe, [{
        type: Pipe,
        args: [{
                standalone: false,
                name: 'highlightSearch'
            }]
    }], () => [{ type: i1.DomSanitizer }], null); })();
//# sourceMappingURL=highlight-search.pipe.js.map