import * as i0 from '@angular/core';
import { input, 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/multiselect';
import { MultiSelectModule } from 'primeng/multiselect';
import { FieldValidation } from '@masterteam/components/field-validation';
import { isInvalid } from '@masterteam/components';

class MultiSelectField {
    multiSelect;
    field = input(true, ...(ngDevMode ? [{ debugName: "field" }] : []));
    label = input(...(ngDevMode ? [undefined, { debugName: "label" }] : []));
    placeholder = input(...(ngDevMode ? [undefined, { debugName: "placeholder" }] : []));
    class = input('', ...(ngDevMode ? [{ debugName: "class" }] : []));
    readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : []));
    pInputs = input(...(ngDevMode ? [undefined, { debugName: "pInputs" }] : []));
    options = input(...(ngDevMode ? [undefined, { debugName: "options" }] : []));
    optionValue = input(...(ngDevMode ? [undefined, { debugName: "optionValue" }] : []));
    optionLabel = input(...(ngDevMode ? [undefined, { debugName: "optionLabel" }] : []));
    filter = input(false, ...(ngDevMode ? [{ debugName: "filter" }] : []));
    filterBy = input(...(ngDevMode ? [undefined, { debugName: "filterBy" }] : []));
    dataKey = input(...(ngDevMode ? [undefined, { debugName: "dataKey" }] : []));
    showClear = input(false, ...(ngDevMode ? [{ debugName: "showClear" }] : []));
    display = input('chip', ...(ngDevMode ? [{ debugName: "display" }] : []));
    required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : []));
    onChange = 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();
            }
        });
    }
    applyInputsToMultiSelect() {
        Object.assign(this.multiSelect, this.pInputs());
    }
    ngOnInit() {
        this.styleClass = this.class();
        if (this.pInputs()) {
            this.applyInputsToMultiSelect();
        }
    }
    onValueChange(value) {
        this.onModelChange(value);
        this.value.set(value);
        this.onChange.emit(value);
    }
    ngOnChanges(changes) {
        if (changes['pInputs']) {
            this.applyInputsToMultiSelect();
        }
    }
    writeValue(value) {
        this.value.set(value);
        this.multiSelect.writeValue(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: MultiSelectField, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: MultiSelectField, isStandalone: true, selector: "mt-multi-select-field", inputs: { field: { classPropertyName: "field", publicName: "field", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", 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 }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: false, transformFunction: null }, optionValue: { classPropertyName: "optionValue", publicName: "optionValue", isSignal: true, isRequired: false, transformFunction: null }, optionLabel: { classPropertyName: "optionLabel", publicName: "optionLabel", isSignal: true, isRequired: false, transformFunction: null }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, filterBy: { classPropertyName: "filterBy", publicName: "filterBy", isSignal: true, isRequired: false, transformFunction: null }, dataKey: { classPropertyName: "dataKey", publicName: "dataKey", isSignal: true, isRequired: false, transformFunction: null }, showClear: { classPropertyName: "showClear", publicName: "showClear", isSignal: true, isRequired: false, transformFunction: null }, display: { classPropertyName: "display", publicName: "display", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { onChange: "onChange" }, host: { properties: { "class": "this.styleClass" }, classAttribute: "grid gap-1" }, viewQueries: [{ propertyName: "multiSelect", first: true, predicate: ["multiSelect"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: "@if (label()) {\n  <label\n    (click)=\"multiSelect?.show()\"\n    [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\n    [for]=\"ngControl?.name || label()\"\n    >{{ label() }}</label\n  >\n}\n<p-multiSelect\n  #multiSelect\n  [ngModel]=\"value()\"\n  (ngModelChange)=\"onValueChange($event)\"\n  [options]=\"options()\"\n  [display]=\"display()\"\n  [optionLabel]=\"optionLabel()\"\n  [optionValue]=\"optionValue()\"\n  (onBlur)=\"onTouched()\"\n  [disabled]=\"disabled() || readonly()\"\n  [inputId]=\"ngControl?.name?.toString() || label()\"\n  [invalid]=\"isInvalid(ngControl?.control)\"\n  placeholder=\"{{ placeholder() ?? label() ?? '' }}\"\n  [filter]=\"filter()\"\n  [filterBy]=\"filterBy()\"\n  [dataKey]=\"dataKey()\"\n  styleClass=\"w-full\"\n  appendTo=\"body\"\n  [showClear]=\"showClear()\"\n></p-multiSelect>\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: MultiSelectModule }, { kind: "component", type: i2.MultiSelect, selector: "p-multiSelect, p-multiselect, p-multi-select", inputs: ["id", "ariaLabel", "styleClass", "panelStyle", "panelStyleClass", "inputId", "readonly", "group", "filter", "filterPlaceHolder", "filterLocale", "overlayVisible", "tabindex", "dataKey", "ariaLabelledBy", "displaySelectedLabel", "maxSelectedLabels", "selectionLimit", "selectedItemsLabel", "showToggleAll", "emptyFilterMessage", "emptyMessage", "resetFilterOnHide", "dropdownIcon", "chipIcon", "optionLabel", "optionValue", "optionDisabled", "optionGroupLabel", "optionGroupChildren", "showHeader", "filterBy", "scrollHeight", "lazy", "virtualScroll", "loading", "virtualScrollItemSize", "loadingIcon", "virtualScrollOptions", "overlayOptions", "ariaFilterLabel", "filterMatchMode", "tooltip", "tooltipPosition", "tooltipPositionStyle", "tooltipStyleClass", "autofocusFilter", "display", "autocomplete", "showClear", "autofocus", "placeholder", "options", "filterValue", "selectAll", "focusOnHover", "filterFields", "selectOnFocus", "autoOptionFocus", "highlightOnSelect", "size", "variant", "fluid", "appendTo", "motionOptions"], outputs: ["onChange", "onFilter", "onFocus", "onBlur", "onClick", "onClear", "onPanelShow", "onPanelHide", "onLazyLoad", "onRemove", "onSelectAllChange"] }, { 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: MultiSelectField, decorators: [{
            type: Component,
            args: [{ selector: 'mt-multi-select-field', standalone: true, imports: [FormsModule, MultiSelectModule, FieldValidation], changeDetection: ChangeDetectionStrategy.OnPush, host: {
                        class: 'grid gap-1',
                    }, template: "@if (label()) {\n  <label\n    (click)=\"multiSelect?.show()\"\n    [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\n    [for]=\"ngControl?.name || label()\"\n    >{{ label() }}</label\n  >\n}\n<p-multiSelect\n  #multiSelect\n  [ngModel]=\"value()\"\n  (ngModelChange)=\"onValueChange($event)\"\n  [options]=\"options()\"\n  [display]=\"display()\"\n  [optionLabel]=\"optionLabel()\"\n  [optionValue]=\"optionValue()\"\n  (onBlur)=\"onTouched()\"\n  [disabled]=\"disabled() || readonly()\"\n  [inputId]=\"ngControl?.name?.toString() || label()\"\n  [invalid]=\"isInvalid(ngControl?.control)\"\n  placeholder=\"{{ placeholder() ?? label() ?? '' }}\"\n  [filter]=\"filter()\"\n  [filterBy]=\"filterBy()\"\n  [dataKey]=\"dataKey()\"\n  styleClass=\"w-full\"\n  appendTo=\"body\"\n  [showClear]=\"showClear()\"\n></p-multiSelect>\n\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\n" }]
        }], ctorParameters: () => [], propDecorators: { multiSelect: [{
                type: ViewChild,
                args: ['multiSelect', { static: true }]
            }], field: [{ type: i0.Input, args: [{ isSignal: true, alias: "field", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], class: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], pInputs: [{ type: i0.Input, args: [{ isSignal: true, alias: "pInputs", required: false }] }], options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: false }] }], optionValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionValue", required: false }] }], optionLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionLabel", required: false }] }], filter: [{ type: i0.Input, args: [{ isSignal: true, alias: "filter", required: false }] }], filterBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterBy", required: false }] }], dataKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "dataKey", required: false }] }], showClear: [{ type: i0.Input, args: [{ isSignal: true, alias: "showClear", required: false }] }], display: [{ type: i0.Input, args: [{ isSignal: true, alias: "display", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], onChange: [{
                type: Output
            }], styleClass: [{
                type: HostBinding,
                args: ['class']
            }] } });

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

export { MultiSelectField };
//# sourceMappingURL=masterteam-components-multi-select-field.mjs.map
