import * as i0 from '@angular/core';
import { Pipe, TemplateRef, inject } from '@angular/core';
import { zCapitalCase, zFormatNum, zRemoveVietnamese } from '@shival99/z-ui/utils';
import { ZTranslateService } from '@shival99/z-ui/services';
import { DomSanitizer } from '@angular/platform-browser';
import DOMPurify from 'dompurify';

class ZCapitalizePipe {
    transform(value, type = 'first') {
        return zCapitalCase(value ?? '', type);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZCapitalizePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.9", ngImport: i0, type: ZCapitalizePipe, isStandalone: true, name: "zCapitalize" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZCapitalizePipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'zCapitalize',
                    standalone: true,
                }]
        }] });

class ZContentTypePipe {
    transform(value) {
        if (!value) {
            return 'string';
        }
        if (value instanceof TemplateRef) {
            return 'template';
        }
        if (typeof value === 'string' && this._containsHtml(value)) {
            return 'html';
        }
        return 'string';
    }
    _containsHtml(str) {
        const htmlTagPattern = /<[a-z][\s\S]*>/i;
        return htmlTagPattern.test(str);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZContentTypePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.9", ngImport: i0, type: ZContentTypePipe, isStandalone: true, name: "zContentType" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZContentTypePipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'zContentType',
                    standalone: true,
                }]
        }] });

class ZFormatNumPipe {
    _zTranslateService = inject(ZTranslateService);
    transform(value, options = {}) {
        options.locale = (options.locale ?? this._zTranslateService.getLang());
        return zFormatNum(value, options);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZFormatNumPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.9", ngImport: i0, type: ZFormatNumPipe, isStandalone: true, name: "zFormatNum", pure: false });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZFormatNumPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'zFormatNum',
                    standalone: true,
                    pure: false,
                }]
        }] });

class ZHighlightPipe {
    transform(value, searchText, klass = 'text-primary') {
        if (!searchText?.trim() || !value) {
            return value;
        }
        const normalizedValue = zRemoveVietnamese(value.toLowerCase());
        const normalizedSearch = zRemoveVietnamese(searchText.toLowerCase().trim());
        const matchIndex = normalizedValue.indexOf(normalizedSearch);
        if (matchIndex === -1) {
            return value;
        }
        const before = value.substring(0, matchIndex);
        const match = value.substring(matchIndex, matchIndex + searchText.length);
        const after = value.substring(matchIndex + searchText.length);
        return `${before}<span class="${klass}">${match}</span>${after}`;
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZHighlightPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.9", ngImport: i0, type: ZHighlightPipe, isStandalone: true, name: "zHighlight" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZHighlightPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'zHighlight',
                    standalone: true,
                }]
        }] });

class ZSafeHtmlPipe {
    _sanitizer = inject(DomSanitizer);
    transform(value) {
        if (!value) {
            return '';
        }
        return this._sanitizer.bypassSecurityTrustHtml(DOMPurify.sanitize(value));
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZSafeHtmlPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.9", ngImport: i0, type: ZSafeHtmlPipe, isStandalone: true, name: "zSafeHtml" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZSafeHtmlPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'zSafeHtml',
                    standalone: true,
                }]
        }] });

/**
 * Pipe to sanitize URLs for resource contexts (iframe src, video src, etc.)
 *
 * Usage:
 * ```html
 * <iframe [src]="url | zSafeResourceUrl"></iframe>
 * <video [src]="videoUrl | zSafeResourceUrl"></video>
 * ```
 *
 * Note: Only use this pipe with trusted URLs. Do not use with user-provided URLs
 * without proper validation, as it bypasses Angular's security.
 */
class ZSafeResourceUrlPipe {
    _sanitizer = inject(DomSanitizer);
    _allowedProtocols = new Set(['http:', 'https:', 'blob:']);
    transform(value) {
        if (!value) {
            return null;
        }
        if (!this._isAllowedResourceUrl(value)) {
            return null;
        }
        return this._sanitizer.bypassSecurityTrustResourceUrl(value);
    }
    _isAllowedResourceUrl(value) {
        const normalized = value.trim();
        if (!normalized) {
            return false;
        }
        const baseUrl = globalThis.location?.origin ?? 'http://localhost';
        try {
            const parsed = new URL(normalized, baseUrl);
            return this._allowedProtocols.has(parsed.protocol);
        }
        catch {
            return false;
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZSafeResourceUrlPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.9", ngImport: i0, type: ZSafeResourceUrlPipe, isStandalone: true, name: "zSafeResourceUrl" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZSafeResourceUrlPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'zSafeResourceUrl',
                    standalone: true,
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { ZCapitalizePipe, ZContentTypePipe, ZFormatNumPipe, ZHighlightPipe, ZSafeHtmlPipe, ZSafeResourceUrlPipe };
//# sourceMappingURL=shival99-z-ui-pipes.mjs.map
