import * as i0 from '@angular/core';
import { input, numberAttribute, booleanAttribute, EventEmitter, signal, computed, 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(false, ...(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" }] : []));
    displayValue = computed(() => {
        const value = this.value();
        if (value === null || value === undefined) {
            return '-';
        }
        return `${value}${this.unit()}`;
    }, ...(ngDevMode ? [{ debugName: "displayValue" }] : []));
    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() || !hideNumber()) {\r\n  <div class=\"flex items-end justify-between gap-3\">\r\n    @if (label()) {\r\n      <label\r\n        class=\"leading-none\"\r\n        [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\r\n        [for]=\"ngControl?.name || label()\"\r\n        >{{ label() }}</label\r\n      >\r\n    }\r\n    @if (!hideNumber()) {\r\n      <span\r\n        class=\"min-w-12 text-right text-sm font-medium leading-none text-muted-color tabular-nums\"\r\n      >\r\n        {{ displayValue() }}\r\n      </span>\r\n    }\r\n  </div>\r\n}\r\n<div class=\"w-full my-2\">\r\n  <p-slider\r\n    #input\r\n    [ngModel]=\"value()\"\r\n    (ngModelChange)=\"onValueChange($event)\"\r\n    (onChange)=\"onChange.emit($event)\"\r\n    (onSlideEnd)=\"onTouched(); onSlideEnd.emit($event)\"\r\n    [disabled]=\"disabled() || readonly()\"\r\n    [animate]=\"animate()\"\r\n    [id]=\"ngControl?.name || label()\"\r\n    [min]=\"min()\"\r\n    [max]=\"max()\"\r\n    [step]=\"step()\"\r\n    [invalid]=\"isInvalid(ngControl?.control)\"\r\n    class=\"block w-full\"\r\n  ></p-slider>\r\n</div>\r\n\r\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\r\n", styles: [":host{--p-slider-track-size: .75rem}:host ::ng-deep .p-slider{background:var(--p-surface-200);border-radius:9999px}:host ::ng-deep .p-slider.p-slider-horizontal{height:var(--p-slider-track-size)}:host ::ng-deep .p-slider-range{border-radius:inherit}\n"], 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() || !hideNumber()) {\r\n  <div class=\"flex items-end justify-between gap-3\">\r\n    @if (label()) {\r\n      <label\r\n        class=\"leading-none\"\r\n        [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\r\n        [for]=\"ngControl?.name || label()\"\r\n        >{{ label() }}</label\r\n      >\r\n    }\r\n    @if (!hideNumber()) {\r\n      <span\r\n        class=\"min-w-12 text-right text-sm font-medium leading-none text-muted-color tabular-nums\"\r\n      >\r\n        {{ displayValue() }}\r\n      </span>\r\n    }\r\n  </div>\r\n}\r\n<div class=\"w-full my-2\">\r\n  <p-slider\r\n    #input\r\n    [ngModel]=\"value()\"\r\n    (ngModelChange)=\"onValueChange($event)\"\r\n    (onChange)=\"onChange.emit($event)\"\r\n    (onSlideEnd)=\"onTouched(); onSlideEnd.emit($event)\"\r\n    [disabled]=\"disabled() || readonly()\"\r\n    [animate]=\"animate()\"\r\n    [id]=\"ngControl?.name || label()\"\r\n    [min]=\"min()\"\r\n    [max]=\"max()\"\r\n    [step]=\"step()\"\r\n    [invalid]=\"isInvalid(ngControl?.control)\"\r\n    class=\"block w-full\"\r\n  ></p-slider>\r\n</div>\r\n\r\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\r\n", styles: [":host{--p-slider-track-size: .75rem}:host ::ng-deep .p-slider{background:var(--p-surface-200);border-radius:9999px}:host ::ng-deep .p-slider.p-slider-horizontal{height:var(--p-slider-track-size)}:host ::ng-deep .p-slider-range{border-radius:inherit}\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
