import * as i0 from '@angular/core';
import { Inject, Optional, Pipe, Injectable } from '@angular/core';
import { SD_CORE_CONFIGURATION } from '@sd-angular/core/configurations';
import { NumberUtilities, DateUtilities } from '@sd-angular/core/utilities/extensions';
import * as i1 from '@angular/platform-browser';
import { of, interval } from 'rxjs';
import { map } from 'rxjs/operators';
import { SD_EMPTY_STR } from '@sd-angular/core/utilities/models';

class SdFormatNumberPipe {
    coreConfiguration;
    constructor(coreConfiguration) {
        this.coreConfiguration = coreConfiguration;
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    transform(value, digits) {
        const fixedValue = NumberUtilities.isNumber(value) ? (+value).toFixed(digits ?? 2) : null;
        // Nếu format VN thì dùng định dạng VN
        if (this.coreConfiguration?.format?.number === '1.234.567,89') {
            return NumberUtilities.toVN(fixedValue);
        }
        // Ngược lại dùng định dạng ISO
        return NumberUtilities.toISO(fixedValue);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdFormatNumberPipe, deps: [{ token: SD_CORE_CONFIGURATION, optional: true }], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.17", ngImport: i0, type: SdFormatNumberPipe, isStandalone: true, name: "sdFormatNumber" });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdFormatNumberPipe, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdFormatNumberPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'sdFormatNumber',
                    standalone: true,
                }]
        }, {
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }], ctorParameters: () => [{ type: undefined, decorators: [{
                    type: Inject,
                    args: [SD_CORE_CONFIGURATION]
                }, {
                    type: Optional
                }] }] });

class SdSafeHtmlPipe {
    sanitizer;
    constructor(sanitizer) {
        this.sanitizer = sanitizer;
    }
    transform(html) {
        if (typeof html === 'number') {
            return html;
        }
        if (!html) {
            return undefined;
        }
        return this.sanitizer.bypassSecurityTrustHtml(html);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdSafeHtmlPipe, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.17", ngImport: i0, type: SdSafeHtmlPipe, isStandalone: true, name: "sdSafeHtml" });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdSafeHtmlPipe, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdSafeHtmlPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'sdSafeHtml',
                    standalone: true,
                }]
        }, {
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }], ctorParameters: () => [{ type: i1.DomSanitizer }] });

/* eslint-disable @typescript-eslint/no-explicit-any */
class SdTimeDifferentPipe {
    maxSecond = 60;
    maxMinute = this.maxSecond * 60;
    maxHour = this.maxMinute * 24;
    maxDay = this.maxHour * 30;
    maxMonth = this.maxHour * 365;
    transform(value, format, different) {
        if (!DateUtilities.isDate(value)) {
            return of('');
        }
        if (!different) {
            return of(DateUtilities.toFormat(value, format));
        }
        if (Math.round((new Date().getTime() - new Date(value).getTime()) / 1000) < 0) {
            return of(DateUtilities.toFormat(value, format));
        }
        return interval(1000).pipe(map(() => {
            const timeDifferent = Math.round((new Date().getTime() - new Date(value).getTime()) / 1000);
            if (different === 'month' && timeDifferent < this.maxMonth) {
                return DateUtilities.timeDifference(value);
            }
            if (different === 'day' && timeDifferent < this.maxDay) {
                return DateUtilities.timeDifference(value);
            }
            if (different === 'hour' && timeDifferent < this.maxHour) {
                return DateUtilities.timeDifference(value);
            }
            if (different === 'minute' && timeDifferent < this.maxMinute) {
                return DateUtilities.timeDifference(value);
            }
            if (different === 'second' && timeDifferent < this.maxSecond) {
                return DateUtilities.timeDifference(value);
            }
            return DateUtilities.toFormat(value, format);
        }));
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdTimeDifferentPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.17", ngImport: i0, type: SdTimeDifferentPipe, isStandalone: true, name: "sdTimeDifferent" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdTimeDifferentPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'sdTimeDifferent',
                    standalone: true,
                }]
        }] });

/* eslint-disable @typescript-eslint/no-explicit-any */
class SdEmptyPipe {
    transform(value) {
        if (value === undefined || value === null || value === '') {
            return SD_EMPTY_STR;
        }
        return value;
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdEmptyPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.17", ngImport: i0, type: SdEmptyPipe, isStandalone: true, name: "sdEmpty" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdEmptyPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'sdEmpty',
                    standalone: true,
                }]
        }] });

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

export { SdEmptyPipe, SdFormatNumberPipe, SdSafeHtmlPipe, SdTimeDifferentPipe };
//# sourceMappingURL=sd-angular-core-pipes.mjs.map
