import { InjectionToken } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Subject } from 'rxjs';

const SD_FORM_CONFIGURATION = new InjectionToken('sd.form.configuration');

class SdFormControl extends FormControl {
    sdChanges = new Subject();
    untouchChanges = new Subject();
    touchChanges = new Subject();
    pristineChanges = new Subject();
    constructor(formState, validatorOrOpts, asyncValidator) {
        super(formState, validatorOrOpts, asyncValidator);
    }
    markAsUntouched(opts) {
        super.markAsUntouched(opts);
        this.untouchChanges.next(true);
        this.sdChanges.next(true);
    }
    markAsTouched(opts) {
        super.markAsTouched(opts);
        this.touchChanges.next(true);
        this.sdChanges.next(true);
    }
    markAsPristine(opts) {
        super.markAsPristine(opts);
        this.pristineChanges.next(true);
        this.sdChanges.next(true);
    }
}

const HandleSdCustomValidator = (func) => {
    return async (c) => {
        const value = c.value === 0 ? c.value : c.value || null;
        if (func && typeof func === 'function') {
            const result = func(value);
            if (result instanceof Promise) {
                const message = await result;
                if (message) {
                    return {
                        customValidator: message,
                    };
                }
                return null;
            }
            if (result) {
                return {
                    customValidator: result,
                };
            }
            return null;
        }
        return null;
    };
};

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

export { HandleSdCustomValidator, SD_FORM_CONFIGURATION, SdFormControl };
//# sourceMappingURL=sd-angular-core-forms-models.mjs.map
