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 { Tooltip } from '@masterteam/components/tooltip';
import * as i2 from 'primeng/datepicker';
import { DatePickerModule } from 'primeng/datepicker';
import { isInvalid } from '@masterteam/components';
import { Icon } from '@masterteam/icons';

class DateField {
    calendar;
    field = input(true, ...(ngDevMode ? [{ debugName: "field" }] : /* istanbul ignore next */ []));
    hint = input(...(ngDevMode ? [undefined, { debugName: "hint" }] : /* istanbul ignore next */ []));
    label = input(...(ngDevMode ? [undefined, { debugName: "label" }] : /* istanbul ignore next */ []));
    placeholder = input(...(ngDevMode ? [undefined, { debugName: "placeholder" }] : /* istanbul ignore next */ []));
    class = input('', ...(ngDevMode ? [{ debugName: "class" }] : /* istanbul ignore next */ []));
    readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : /* istanbul ignore next */ []));
    showIcon = input(true, ...(ngDevMode ? [{ debugName: "showIcon" }] : /* istanbul ignore next */ []));
    showClear = input(false, ...(ngDevMode ? [{ debugName: "showClear" }] : /* istanbul ignore next */ []));
    showTime = input(false, ...(ngDevMode ? [{ debugName: "showTime" }] : /* istanbul ignore next */ []));
    pInputs = input(...(ngDevMode ? [undefined, { debugName: "pInputs" }] : /* istanbul ignore next */ []));
    required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
    rtl = signal(document.documentElement.dir === 'rtl', ...(ngDevMode ? [{ debugName: "rtl" }] : /* istanbul ignore next */ []));
    styleClass;
    requiredValidator = Validators.required;
    value = signal(null, ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
    disabled = signal(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
    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) {
        if (value == null || value === '') {
            this.value.set(null);
            return;
        }
        if (typeof value === 'string') {
            const parsed = new Date(value);
            this.value.set(isNaN(parsed.getTime()) ? null : parsed);
            return;
        }
        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.2.8", ngImport: i0, type: DateField, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: DateField, isStandalone: true, selector: "mt-date-field", inputs: { field: { classPropertyName: "field", publicName: "field", isSignal: true, isRequired: false, transformFunction: null }, hint: { classPropertyName: "hint", publicName: "hint", 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() || hint()) {\r\n  <div class=\"flex items-center gap-1\">\r\n    @if (label()) {\r\n      <label\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 (hint()) {\r\n      <span\r\n        class=\"inline-flex text-surface-400\"\r\n        [mtTooltip]=\"hint()\"\r\n        tooltipPosition=\"top\"\r\n      >\r\n        <mt-icon icon=\"general.help-circle\" />\r\n      </span>\r\n    }\r\n  </div>\r\n}\r\n<p-datepicker\r\n  #calendar\r\n  [ngModel]=\"value()\"\r\n  (ngModelChange)=\"onValueChange($event)\"\r\n  (onBlur)=\"onTouched()\"\r\n  [disabled]=\"disabled() || readonly()\"\r\n  [inputId]=\"ngControl?.name ? ngControl?.name?.toString() : label()\"\r\n  [invalid]=\"isInvalid(ngControl?.control)\"\r\n  [baseZIndex]=\"1051\"\r\n  placeholder=\"{{ placeholder() ?? label() ?? '' }}\"\r\n  inputStyleClass=\"w-full\"\r\n  [showIcon]=\"showIcon()\"\r\n  [showClear]=\"showClear()\"\r\n  [showTime]=\"showTime()\"\r\n  dateFormat=\"dd/mm/yy\"\r\n  appendTo=\"body\"\r\n>\r\n  <ng-template #previousicon>\r\n    <mt-icon\r\n      [icon]=\"rtl() ? 'arrow.chevron-right' : 'arrow.chevron-left'\"\r\n      class=\"text-2xl\"\r\n    />\r\n  </ng-template>\r\n  <ng-template #nexticon>\r\n    <mt-icon\r\n      [icon]=\"rtl() ? 'arrow.chevron-left' : 'arrow.chevron-right'\"\r\n      class=\"text-2xl\"\r\n    />\r\n  </ng-template>\r\n</p-datepicker>\r\n\r\n<!-- <mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation> -->\r\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: "directive", type: Tooltip, selector: "[mtTooltip]" }, { kind: "component", type: Icon, selector: "mt-icon", inputs: ["icon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: DateField, decorators: [{
            type: Component,
            args: [{ selector: 'mt-date-field', standalone: true, imports: [FormsModule, DatePickerModule, Tooltip, Icon], changeDetection: ChangeDetectionStrategy.OnPush, host: {
                        class: 'grid gap-1',
                    }, template: "@if (label() || hint()) {\r\n  <div class=\"flex items-center gap-1\">\r\n    @if (label()) {\r\n      <label\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 (hint()) {\r\n      <span\r\n        class=\"inline-flex text-surface-400\"\r\n        [mtTooltip]=\"hint()\"\r\n        tooltipPosition=\"top\"\r\n      >\r\n        <mt-icon icon=\"general.help-circle\" />\r\n      </span>\r\n    }\r\n  </div>\r\n}\r\n<p-datepicker\r\n  #calendar\r\n  [ngModel]=\"value()\"\r\n  (ngModelChange)=\"onValueChange($event)\"\r\n  (onBlur)=\"onTouched()\"\r\n  [disabled]=\"disabled() || readonly()\"\r\n  [inputId]=\"ngControl?.name ? ngControl?.name?.toString() : label()\"\r\n  [invalid]=\"isInvalid(ngControl?.control)\"\r\n  [baseZIndex]=\"1051\"\r\n  placeholder=\"{{ placeholder() ?? label() ?? '' }}\"\r\n  inputStyleClass=\"w-full\"\r\n  [showIcon]=\"showIcon()\"\r\n  [showClear]=\"showClear()\"\r\n  [showTime]=\"showTime()\"\r\n  dateFormat=\"dd/mm/yy\"\r\n  appendTo=\"body\"\r\n>\r\n  <ng-template #previousicon>\r\n    <mt-icon\r\n      [icon]=\"rtl() ? 'arrow.chevron-right' : 'arrow.chevron-left'\"\r\n      class=\"text-2xl\"\r\n    />\r\n  </ng-template>\r\n  <ng-template #nexticon>\r\n    <mt-icon\r\n      [icon]=\"rtl() ? 'arrow.chevron-left' : 'arrow.chevron-right'\"\r\n      class=\"text-2xl\"\r\n    />\r\n  </ng-template>\r\n</p-datepicker>\r\n\r\n<!-- <mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation> -->\r\n" }]
        }], ctorParameters: () => [], propDecorators: { calendar: [{
                type: ViewChild,
                args: ['calendar', { static: true }]
            }], field: [{ type: i0.Input, args: [{ isSignal: true, alias: "field", required: false }] }], hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", 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
