import * as i0 from '@angular/core';
import { input, numberAttribute, booleanAttribute, EventEmitter, signal, inject, effect, HostBinding, Output, ViewChild, ChangeDetectionStrategy, Component } from '@angular/core';
import * as i1 from '@angular/forms';
import { Validators, NgControl, FormsModule } from '@angular/forms';
import * as i2 from 'primeng/slider';
import { SliderModule } from 'primeng/slider';
import { FieldValidation } from '@masterteam/components/field-validation';
import { isInvalid } from '@masterteam/components';

class SliderField {
    input;
    field = input(true, ...(ngDevMode ? [{ debugName: "field" }] : []));
    label = input(...(ngDevMode ? [undefined, { debugName: "label" }] : []));
    animate = input(true, ...(ngDevMode ? [{ debugName: "animate" }] : []));
    class = input('', ...(ngDevMode ? [{ debugName: "class" }] : []));
    min = input(0, { ...(ngDevMode ? { debugName: "min" } : {}), transform: numberAttribute });
    max = input(100, { ...(ngDevMode ? { debugName: "max" } : {}), transform: numberAttribute });
    step = input(undefined, { ...(ngDevMode ? { debugName: "step" } : {}), transform: numberAttribute });
    hideNumber = input(false, { ...(ngDevMode ? { debugName: "hideNumber" } : {}), transform: booleanAttribute });
    unit = input('', ...(ngDevMode ? [{ debugName: "unit" }] : []));
    readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : []));
    pInputs = input(...(ngDevMode ? [undefined, { debugName: "pInputs" }] : []));
    required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : []));
    onChange = new EventEmitter();
    onSlideEnd = new EventEmitter();
    styleClass;
    requiredValidator = Validators.required;
    value = signal(null, ...(ngDevMode ? [{ debugName: "value" }] : []));
    disabled = signal(false, ...(ngDevMode ? [{ debugName: "disabled" }] : []));
    onTouched = () => { };
    onModelChange = () => { };
    ngControl = inject(NgControl, { self: true });
    isInvalid = isInvalid;
    constructor() {
        if (this.ngControl) {
            this.ngControl.valueAccessor = this;
        }
        effect(() => {
            if (this.ngControl.control && this.required()) {
                this.ngControl.control.addValidators(Validators.required);
                this.ngControl.control.updateValueAndValidity();
            }
        });
    }
    applyInputsToInput() {
        Object.assign(this.input, this.pInputs());
    }
    ngOnInit() {
        this.styleClass = this.class();
    }
    onValueChange(value) {
        this.onModelChange(value);
        this.value.set(value);
    }
    ngOnChanges(changes) {
        if (changes['pInputs']) {
            this.applyInputsToInput();
        }
    }
    writeValue(value) {
        this.value.set(value);
    }
    registerOnChange(fn) {
        this.onModelChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(disabled) {
        this.disabled.set(disabled);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: SliderField, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: SliderField, isStandalone: true, selector: "mt-slider-field", inputs: { field: { classPropertyName: "field", publicName: "field", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, animate: { classPropertyName: "animate", publicName: "animate", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, step: { classPropertyName: "step", publicName: "step", isSignal: true, isRequired: false, transformFunction: null }, hideNumber: { classPropertyName: "hideNumber", publicName: "hideNumber", isSignal: true, isRequired: false, transformFunction: null }, unit: { classPropertyName: "unit", publicName: "unit", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, pInputs: { classPropertyName: "pInputs", publicName: "pInputs", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { onChange: "onChange", onSlideEnd: "onSlideEnd" }, host: { properties: { "class": "this.styleClass" }, classAttribute: "grid gap-1" }, viewQueries: [{ propertyName: "input", first: true, predicate: ["input"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: "@if (label()) {\n  <label\n    [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\n    [for]=\"ngControl?.name || label()\"\n    [class.mb-3]=\"hideNumber()\"\n    >{{ label() }}</label\n  >\n}\n<div\n  class=\"flex items-center gap-3 w-full\"\n  [style.padding-inline-start]=\"'calc(var(--p-slider-handle-width) / 2)'\"\n>\n  <p-slider\n    #input\n    [ngModel]=\"value()\"\n    (ngModelChange)=\"onValueChange($event)\"\n    (onChange)=\"onChange.emit($event)\"\n    (onSlideEnd)=\"onTouched(); onSlideEnd.emit($event)\"\n    [disabled]=\"disabled() || readonly()\"\n    [animate]=\"animate()\"\n    [id]=\"ngControl?.name || label()\"\n    [min]=\"min()\"\n    [max]=\"max()\"\n    [step]=\"step()\"\n    [invalid]=\"isInvalid(ngControl?.control)\"\n    class=\"grow\"\n  ></p-slider>\n  @if (!hideNumber()) {\n    <span class=\"leading-none\">{{ value() ? value() + unit() : \"-\" }}</span>\n  }\n</div>\n\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\n", styles: [""], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "ngmodule", type: SliderModule }, { kind: "component", type: i2.Slider, selector: "p-slider", inputs: ["animate", "min", "max", "orientation", "step", "range", "styleClass", "ariaLabel", "ariaLabelledBy", "tabindex", "autofocus"], outputs: ["onChange", "onSlideEnd"] }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: SliderField, decorators: [{
            type: Component,
            args: [{ selector: 'mt-slider-field', standalone: true, imports: [FormsModule, SliderModule, FieldValidation], changeDetection: ChangeDetectionStrategy.OnPush, host: {
                        class: 'grid gap-1',
                    }, template: "@if (label()) {\n  <label\n    [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\n    [for]=\"ngControl?.name || label()\"\n    [class.mb-3]=\"hideNumber()\"\n    >{{ label() }}</label\n  >\n}\n<div\n  class=\"flex items-center gap-3 w-full\"\n  [style.padding-inline-start]=\"'calc(var(--p-slider-handle-width) / 2)'\"\n>\n  <p-slider\n    #input\n    [ngModel]=\"value()\"\n    (ngModelChange)=\"onValueChange($event)\"\n    (onChange)=\"onChange.emit($event)\"\n    (onSlideEnd)=\"onTouched(); onSlideEnd.emit($event)\"\n    [disabled]=\"disabled() || readonly()\"\n    [animate]=\"animate()\"\n    [id]=\"ngControl?.name || label()\"\n    [min]=\"min()\"\n    [max]=\"max()\"\n    [step]=\"step()\"\n    [invalid]=\"isInvalid(ngControl?.control)\"\n    class=\"grow\"\n  ></p-slider>\n  @if (!hideNumber()) {\n    <span class=\"leading-none\">{{ value() ? value() + unit() : \"-\" }}</span>\n  }\n</div>\n\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\n" }]
        }], ctorParameters: () => [], propDecorators: { input: [{
                type: ViewChild,
                args: ['input', { static: true }]
            }], field: [{ type: i0.Input, args: [{ isSignal: true, alias: "field", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], animate: [{ type: i0.Input, args: [{ isSignal: true, alias: "animate", required: false }] }], class: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "min", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], step: [{ type: i0.Input, args: [{ isSignal: true, alias: "step", required: false }] }], hideNumber: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideNumber", required: false }] }], unit: [{ type: i0.Input, args: [{ isSignal: true, alias: "unit", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], pInputs: [{ type: i0.Input, args: [{ isSignal: true, alias: "pInputs", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], onChange: [{
                type: Output
            }], onSlideEnd: [{
                type: Output
            }], styleClass: [{
                type: HostBinding,
                args: ['class']
            }] } });

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

export { SliderField };
//# sourceMappingURL=masterteam-components-slider-field.mjs.map
