import * as i0 from '@angular/core';
import { input, signal, inject, effect, HostBinding, ViewChild, ChangeDetectionStrategy, Component } from '@angular/core';
import * as i1 from '@angular/forms';
import { Validators, NgControl, FormsModule } from '@angular/forms';
import * as i2 from 'primeng/datepicker';
import { DatePickerModule } from 'primeng/datepicker';
import { FieldValidation } from '@masterteam/components/field-validation';
import { isInvalid } from '@masterteam/components';
import { Icon } from '@masterteam/icons';

class DateField {
    calendar;
    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" }] : []));
    showIcon = input(true, ...(ngDevMode ? [{ debugName: "showIcon" }] : []));
    showClear = input(false, ...(ngDevMode ? [{ debugName: "showClear" }] : []));
    showTime = input(false, ...(ngDevMode ? [{ debugName: "showTime" }] : []));
    pInputs = input(...(ngDevMode ? [undefined, { debugName: "pInputs" }] : []));
    required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : []));
    rtl = signal(document.documentElement.dir === 'rtl', ...(ngDevMode ? [{ debugName: "rtl" }] : []));
    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();
            }
        });
    }
    applyInputsToCalendar() {
        Object.assign(this.calendar, this.pInputs());
    }
    ngOnInit() {
        this.styleClass = this.class();
        if (this.pInputs()) {
            this.applyInputsToCalendar();
        }
    }
    onValueChange(value) {
        this.onModelChange(value);
        this.value.set(value);
    }
    ngOnChanges(changes) {
        if (changes['pInputs']) {
            this.applyInputsToCalendar();
        }
    }
    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: DateField, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: DateField, isStandalone: true, selector: "mt-date-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 }, showIcon: { classPropertyName: "showIcon", publicName: "showIcon", isSignal: true, isRequired: false, transformFunction: null }, showClear: { classPropertyName: "showClear", publicName: "showClear", isSignal: true, isRequired: false, transformFunction: null }, showTime: { classPropertyName: "showTime", publicName: "showTime", 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 } }, host: { properties: { "class": "this.styleClass" }, classAttribute: "grid gap-1" }, viewQueries: [{ propertyName: "calendar", first: true, predicate: ["calendar"], 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    >{{ label() }}</label\n  >\n}\n<p-datepicker\n  #calendar\n  [ngModel]=\"value()\"\n  (ngModelChange)=\"onValueChange($event)\"\n  (onBlur)=\"onTouched()\"\n  [disabled]=\"disabled() || readonly()\"\n  [inputId]=\"ngControl?.name ? ngControl?.name?.toString() : label()\"\n  [invalid]=\"isInvalid(ngControl?.control)\"\n  [baseZIndex]=\"1051\"\n  placeholder=\"{{ placeholder() ?? label() ?? '' }}\"\n  styleClass=\"w-full\"\n  [showIcon]=\"showIcon()\"\n  [showClear]=\"showClear()\"\n  [showTime]=\"showTime()\"\n  appendTo=\"body\"\n>\n  <ng-template #previousicon>\n    <mt-icon\n      [icon]=\"rtl() ? 'arrow.chevron-right' : 'arrow.chevron-left'\"\n      class=\"text-2xl\"\n    />\n  </ng-template>\n  <ng-template #nexticon>\n    <mt-icon\n      [icon]=\"rtl() ? 'arrow.chevron-left' : 'arrow.chevron-right'\"\n      class=\"text-2xl\"\n    />\n  </ng-template>\n</p-datepicker>\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: DatePickerModule }, { kind: "component", type: i2.DatePicker, selector: "p-datePicker, p-datepicker, p-date-picker", inputs: ["iconDisplay", "styleClass", "inputStyle", "inputId", "inputStyleClass", "placeholder", "ariaLabelledBy", "ariaLabel", "iconAriaLabel", "dateFormat", "multipleSeparator", "rangeSeparator", "inline", "showOtherMonths", "selectOtherMonths", "showIcon", "icon", "readonlyInput", "shortYearCutoff", "hourFormat", "timeOnly", "stepHour", "stepMinute", "stepSecond", "showSeconds", "showOnFocus", "showWeek", "startWeekFromFirstDayOfYear", "showClear", "dataType", "selectionMode", "maxDateCount", "showButtonBar", "todayButtonStyleClass", "clearButtonStyleClass", "autofocus", "autoZIndex", "baseZIndex", "panelStyleClass", "panelStyle", "keepInvalid", "hideOnDateTimeSelect", "touchUI", "timeSeparator", "focusTrap", "showTransitionOptions", "hideTransitionOptions", "tabindex", "minDate", "maxDate", "disabledDates", "disabledDays", "showTime", "responsiveOptions", "numberOfMonths", "firstDayOfWeek", "view", "defaultDate", "appendTo", "motionOptions"], outputs: ["onFocus", "onBlur", "onClose", "onSelect", "onClear", "onInput", "onTodayClick", "onClearClick", "onMonthChange", "onYearChange", "onClickOutside", "onShow"] }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched"] }, { kind: "component", type: Icon, selector: "mt-icon", inputs: ["icon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: DateField, decorators: [{
            type: Component,
            args: [{ selector: 'mt-date-field', standalone: true, imports: [FormsModule, DatePickerModule, FieldValidation, Icon], 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    >{{ label() }}</label\n  >\n}\n<p-datepicker\n  #calendar\n  [ngModel]=\"value()\"\n  (ngModelChange)=\"onValueChange($event)\"\n  (onBlur)=\"onTouched()\"\n  [disabled]=\"disabled() || readonly()\"\n  [inputId]=\"ngControl?.name ? ngControl?.name?.toString() : label()\"\n  [invalid]=\"isInvalid(ngControl?.control)\"\n  [baseZIndex]=\"1051\"\n  placeholder=\"{{ placeholder() ?? label() ?? '' }}\"\n  styleClass=\"w-full\"\n  [showIcon]=\"showIcon()\"\n  [showClear]=\"showClear()\"\n  [showTime]=\"showTime()\"\n  appendTo=\"body\"\n>\n  <ng-template #previousicon>\n    <mt-icon\n      [icon]=\"rtl() ? 'arrow.chevron-right' : 'arrow.chevron-left'\"\n      class=\"text-2xl\"\n    />\n  </ng-template>\n  <ng-template #nexticon>\n    <mt-icon\n      [icon]=\"rtl() ? 'arrow.chevron-left' : 'arrow.chevron-right'\"\n      class=\"text-2xl\"\n    />\n  </ng-template>\n</p-datepicker>\n\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\n" }]
        }], ctorParameters: () => [], propDecorators: { calendar: [{
                type: ViewChild,
                args: ['calendar', { 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 }] }], showIcon: [{ type: i0.Input, args: [{ isSignal: true, alias: "showIcon", required: false }] }], showClear: [{ type: i0.Input, args: [{ isSignal: true, alias: "showClear", required: false }] }], showTime: [{ type: i0.Input, args: [{ isSignal: true, alias: "showTime", required: false }] }], pInputs: [{ type: i0.Input, args: [{ isSignal: true, alias: "pInputs", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], styleClass: [{
                type: HostBinding,
                args: ['class']
            }] } });

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

export { DateField };
//# sourceMappingURL=masterteam-components-date-field.mjs.map
