import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { viewChild, contentChild, inject, ChangeDetectorRef, input, computed, booleanAttribute, model, output, effect, untracked, ChangeDetectionStrategy, Component } from '@angular/core';
import * as i2 from '@angular/forms';
import { Validators, NgForm, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
import * as i4 from '@angular/material/icon';
import { MatIconModule } from '@angular/material/icon';
import * as i3 from '@angular/material/input';
import { MatInputModule } from '@angular/material/input';
import * as i5 from '@angular/material/tooltip';
import { MatTooltipModule } from '@angular/material/tooltip';
import { provideMomentDatetimeAdapter } from '@ng-matero/extensions-moment-adapter';
import * as i6 from '@ng-matero/extensions/datetimepicker';
import { MtxDatetimepicker, MtxDatetimepickerModule } from '@ng-matero/extensions/datetimepicker';
import { SdView } from '@sd-angular/core/components/view';
import { SdViewDefDirective } from '@sd-angular/core/forms/directives';
import { SdLabel } from '@sd-angular/core/forms/label';
import { SD_FORM_CONFIGURATION, SdFormControl } from '@sd-angular/core/forms/models';
import { SdUtilities, DateUtilities } from '@sd-angular/core/utilities/extensions';
import moment from 'moment';
import { Subscription } from 'rxjs';
import * as uuid from 'uuid';

/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @angular-eslint/no-input-rename */
class SdDatetime {
    id = `I${uuid.v4()}`;
    // ==========================================
    // 1. SIGNAL QUERIES
    // ==========================================
    inputRef = viewChild('input');
    datetimePicker = viewChild(MtxDatetimepicker);
    sdLabelTemplate = contentChild('sdLabel');
    sdValueTemplate = contentChild('sdValue');
    sdViewDef = contentChild(SdViewDefDirective);
    // ==========================================
    // 2. INJECTS
    // ==========================================
    ref = inject(ChangeDetectorRef);
    formConfig = inject(SD_FORM_CONFIGURATION, { optional: true });
    // ==========================================
    // 3. SIGNAL INPUTS & MODEL
    // ==========================================
    autoIdInput = input(undefined, { alias: 'autoId' });
    autoId = computed(() => this.autoIdInput() ? `forms-datetime-${this.autoIdInput()}` : undefined);
    name = input(uuid.v4());
    size = input('md');
    // Chấp nhận mọi loại Form cha truyền xuống (FormGroup<{}>, FormGroup<any>, NgForm...)
    form = input();
    label = input();
    helperText = input();
    placeholder = input();
    hideInlineError = input(false, { transform: booleanAttribute });
    required = input(false, { transform: booleanAttribute });
    disabled = input(false, { transform: booleanAttribute });
    viewed = input(false, { transform: booleanAttribute });
    inlineError = input();
    hyperlink = input();
    appearanceInput = input(undefined, { alias: 'appearance' });
    appearance = computed(() => this.appearanceInput() ?? this.formConfig?.appearance ?? 'outline');
    // Xử lý thông minh Gom min/minDate và max/maxDate
    minInput = input(undefined, { alias: 'min' });
    minDateInput = input(undefined, { alias: 'minDate' });
    resolvedMin = computed(() => this.#parseDateBoundary(this.minInput() ?? this.minDateInput()));
    maxInput = input(undefined, { alias: 'max' });
    maxDateInput = input(undefined, { alias: 'maxDate' });
    resolvedMax = computed(() => this.#parseDateBoundary(this.maxInput() ?? this.maxDateInput()));
    valueModel = model(undefined, { alias: 'model' });
    // ==========================================
    // 4. SIGNAL OUTPUTS
    // ==========================================
    sdChange = output();
    sdFocus = output();
    // ==========================================
    // 5. INTERNAL STATE & STREAMS
    // ==========================================
    isMobileOrTablet = SdUtilities.isMobile();
    formControl = new SdFormControl();
    isFocused = false;
    isValid;
    #date;
    #subscription = new Subscription();
    constructor() {
        // EFFECT 1: Sync model thay đổi từ bên ngoài (String/Date -> Moment)
        effect(() => {
            let val = this.valueModel();
            untracked(() => {
                if (!DateUtilities.isDate(val)) {
                    val = null;
                }
                val = DateUtilities.toFormat(val, 'yyyy/MM/dd HH:mm');
                if (this.#date !== val) {
                    this.#date = val;
                    const dateObj = DateUtilities.isDate(this.#date)
                        ? moment(DateUtilities.toFormat(this.#date, 'yyyy/MM/dd HH:mm'), 'YYYY/MM/DD HH:mm')
                        : null;
                    this.formControl.setValue(dateObj, { emitEvent: false });
                }
            });
        });
        // EFFECT 2: Sync Disable
        effect(() => {
            if (this.disabled())
                this.formControl.disable({ emitEvent: false });
            else
                this.formControl.enable({ emitEvent: false });
        });
        // EFFECT 3: Update Validators
        effect(() => {
            const req = this.required();
            const inl = this.inlineError();
            untracked(() => {
                const validators = [];
                if (req)
                    validators.push(Validators.required);
                if (inl)
                    validators.push(this.customInlineErrorValidator());
                this.formControl.setValidators(validators.length ? validators : null);
                this.formControl.updateValueAndValidity({ emitEvent: false });
            });
        });
    }
    ngOnInit() {
        this.#subscription.add(this.formControl.sdChanges.subscribe(() => {
            this.ref.markForCheck();
        }));
        const formGroup = this.form() instanceof NgForm ? this.form().form : this.form();
        formGroup?.addControl(this.name(), this.formControl);
    }
    ngOnDestroy() {
        const formGroup = this.form() instanceof NgForm ? this.form().form : this.form();
        formGroup?.removeControl(this.name());
        this.#subscription.unsubscribe();
    }
    // Hàm private tái sử dụng cho parse Min/Max Datetime
    #parseDateBoundary(val) {
        if (val === 'TODAY')
            return new Date();
        if (val && DateUtilities.isDate(val))
            return new Date(val);
        return null;
    }
    customInlineErrorValidator() {
        return () => ({ inlineError: true });
    }
    onFocus = () => {
        this.isFocused = true;
        this.sdFocus.emit();
    };
    onBlur = () => {
        this.isFocused = false;
    };
    onClick = () => {
        if (this.sdViewDef()?.templateRef) {
            if (!this.formControl.disabled && !this.isFocused) {
                this.focus();
            }
        }
    };
    blur = () => {
        this.inputRef()?.nativeElement?.blur();
    };
    focus = () => {
        this.isFocused = true;
        setTimeout(() => {
            this.inputRef()?.nativeElement?.focus();
            this.datetimePicker()?.open();
        }, 100);
    };
    focusInputElement() {
        this.inputRef()?.nativeElement?.focus();
    }
    onKeyDown = (event) => {
        const key = event.keyCode || event.charCode;
        const isShift = key === 16;
        if (event.ctrlKey && (key === 67 || key === 86))
            return true;
        if (((key >= 48 && key <= 57) ||
            key === 8 ||
            key <= 37 ||
            key <= 39 ||
            (key >= 96 && key <= 105) ||
            key === 191 ||
            key === 186 ||
            key === 59) &&
            !isShift) {
            return true;
        }
        return false;
    };
    onConfirmInput = (event) => {
        const currentVal = event.target.value;
        const formControl = this.formControl;
        const regexToMinutes = /^([1-9]|([012][0-9])|(3[01]))\/([0]{0,1}[1-9]|1[012])\/\d\d\d\d [012]{0,1}[0-9]:[0-6][0-9]$/g;
        const regexToSecond = /^([1-9]|([012][0-9])|(3[01]))\/([0]{0,1}[1-9]|1[012])\/\d\d\d\d [012]{0,1}[0-9]:[0-6][0-9]:[0-6][0-9]$/g;
        if (currentVal && !(regexToMinutes.test(currentVal) || regexToSecond.test(currentVal))) {
            setTimeout(() => {
                formControl.markAsDirty();
                formControl.markAsTouched();
                formControl.setErrors({ ...formControl.errors, date: `Sai định dạng` });
            }, 0);
        }
        else {
            setTimeout(() => {
                formControl.setErrors({ ...formControl.errors, date: null });
                this.formControl.updateValueAndValidity();
            }, 0);
        }
    };
    onChange = (_) => {
        const event = _;
        // Giữ nguyên logic format cũ theo yêu cầu hệ thống
        const value = DateUtilities.toFormat(event.value?.toDate(), 'yyyy/MM/dd HH:mm:ss');
        this.inputRef()?.nativeElement?.focus();
        if (this.#date !== value) {
            this.valueModel.set(value);
            this.sdChange.emit(value);
        }
    };
    clear = ($event) => {
        $event?.stopPropagation();
        if (this.formControl.value) {
            this.formControl.setValue(null);
            this.valueModel.set(null);
            this.sdChange.emit(null);
        }
    };
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdDatetime, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.17", type: SdDatetime, isStandalone: true, selector: "sd-datetime", inputs: { autoIdInput: { classPropertyName: "autoIdInput", publicName: "autoId", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, form: { classPropertyName: "form", publicName: "form", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, helperText: { classPropertyName: "helperText", publicName: "helperText", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, hideInlineError: { classPropertyName: "hideInlineError", publicName: "hideInlineError", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, viewed: { classPropertyName: "viewed", publicName: "viewed", isSignal: true, isRequired: false, transformFunction: null }, inlineError: { classPropertyName: "inlineError", publicName: "inlineError", isSignal: true, isRequired: false, transformFunction: null }, hyperlink: { classPropertyName: "hyperlink", publicName: "hyperlink", isSignal: true, isRequired: false, transformFunction: null }, appearanceInput: { classPropertyName: "appearanceInput", publicName: "appearance", isSignal: true, isRequired: false, transformFunction: null }, minInput: { classPropertyName: "minInput", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, minDateInput: { classPropertyName: "minDateInput", publicName: "minDate", isSignal: true, isRequired: false, transformFunction: null }, maxInput: { classPropertyName: "maxInput", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, maxDateInput: { classPropertyName: "maxDateInput", publicName: "maxDate", isSignal: true, isRequired: false, transformFunction: null }, valueModel: { classPropertyName: "valueModel", publicName: "model", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueModel: "modelChange", sdChange: "sdChange", sdFocus: "sdFocus" }, providers: [
            provideMomentDatetimeAdapter({
                parse: {
                    dateInput: 'DD/MM/YYYY',
                    timeInput: 'HH:mm',
                    datetimeInput: 'DD/MM/YYYY HH:mm',
                },
                display: {
                    dateInput: 'DD/MM/YYYY',
                    monthInput: 'MMMM',
                    timeInput: 'HH:mm',
                    datetimeInput: 'DD/MM/YYYY HH:mm',
                    monthYearLabel: 'MMM YYYY',
                    dateA11yLabel: 'LL',
                    monthYearA11yLabel: 'MMMM YYYY',
                    popupHeaderDateLabel: 'MMM DD, ddd',
                },
            }),
        ], queries: [{ propertyName: "sdLabelTemplate", first: true, predicate: ["sdLabel"], descendants: true, isSignal: true }, { propertyName: "sdValueTemplate", first: true, predicate: ["sdValue"], descendants: true, isSignal: true }, { propertyName: "sdViewDef", first: true, predicate: SdViewDefDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "inputRef", first: true, predicate: ["input"], descendants: true, isSignal: true }, { propertyName: "datetimePicker", first: true, predicate: MtxDatetimepicker, descendants: true, isSignal: true }], ngImport: i0, template: "@let lbl = label();\r\n@let app = appearance();\r\n@let hideErr = hideInlineError();\r\n@let viewDef = sdViewDef();\r\n@let hText = helperText();\r\n@let req = required();\r\n@let inlErr = inlineError();\r\n\r\n@let minD = resolvedMin();\r\n@let maxD = resolvedMax();\r\n\r\n@if (viewed()) {\r\n  <sd-view\r\n    [label]=\"lbl\"\r\n    [labelTemplate]=\"sdLabelTemplate()\"\r\n    [value]=\"formControl.value\"\r\n    [display]=\"formControl.value | date: 'dd/MM/yyyy HH:mm'\"\r\n    [hyperlink]=\"hyperlink()\"\r\n    [valueTemplate]=\"sdValueTemplate()\">\r\n  </sd-view>\r\n} @else {\r\n  @if (!app) {\r\n    <ng-content select=\"[sdLabel]\">\r\n      @if (lbl) {\r\n        <sd-label [label]=\"lbl\" [required]=\"req\"></sd-label>\r\n      }\r\n    </ng-content>\r\n  }\r\n  \r\n  <div\r\n    class=\"d-flex align-items-center\"\r\n    [class.sd-view]=\"viewDef?.templateRef\"\r\n    [class.c-focused]=\"isFocused\"\r\n    [class.c-disabled]=\"formControl.disabled\"\r\n    (click)=\"onClick()\"\r\n    aria-hidden=\"true\">\r\n    \r\n    @if (viewDef?.templateRef && !isFocused && !datetimePicker()?.opened) {\r\n      <ng-container\r\n        *ngTemplateOutlet=\"\r\n          viewDef!.templateRef;\r\n          context: { value: formControl.value }\r\n        \">\r\n      </ng-container>\r\n    } @else {\r\n      <mat-form-field\r\n        class=\"c-form-field-datetime-input\"\r\n        [class.sd-md]=\"size() === 'md'\"\r\n        [class.sd-sm]=\"size() === 'sm'\"\r\n        [class.hide-inline-error]=\"hideErr\"\r\n        [appearance]=\"app || 'outline'\">\r\n        \r\n        @if (app && lbl) {\r\n          <mat-label style=\"display: inline-block\">\r\n            <div style=\"display: flex; align-items: center; gap: 4px\">\r\n              <span>{{ lbl }}</span>\r\n              @if (hText) {\r\n                <mat-icon [matTooltip]=\"hText\" matTooltipPosition=\"below\">info_outline</mat-icon>\r\n              }\r\n            </div>\r\n          </mat-label>\r\n        }\r\n        \r\n        <mtx-datetimepicker #datetimePicker [type]=\"'datetime'\" [mode]=\"'auto'\"></mtx-datetimepicker>\r\n        \r\n        <input\r\n          aria-hidden=\"true\"\r\n          [attr.data-autoId]=\"autoId()\"\r\n          [mtxDatetimepicker]=\"datetimePicker\"\r\n          [id]=\"id\"\r\n          (blur)=\"onConfirmInput($event)\"\r\n          (keyup.enter)=\"onConfirmInput($event)\"\r\n          (keydown)=\"onKeyDown($event)\"\r\n          (dateChange)=\"onChange($event)\"\r\n          [autocomplete]=\"id\"\r\n          autocorrect=\"off\"\r\n          [formControl]=\"formControl\"\r\n          [required]=\"req\"\r\n          [placeholder]=\"placeholder() || lbl || ''\"\r\n          [min]=\"minD\"\r\n          [max]=\"maxD\"\r\n          (focus)=\"onFocus()\"\r\n          (blur)=\"onBlur()\"\r\n          #input\r\n          matInput />\r\n          \r\n        <mtx-datetimepicker-toggle [for]=\"datetimePicker\" matSuffix></mtx-datetimepicker-toggle>\r\n        \r\n        @if (formControl.errors?.['required'] && formControl.touched) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Vui l\u00F2ng nh\u1EADp th\u00F4ng tin' }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['matDatepickerMin'] && formControl.touched && !isFocused) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Ng\u00E0y nh\u1ECF nh\u1EA5t' }}: <strong>{{ minD | date: 'dd/MM/yyyy HH:mm' }}</strong>\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['matDatepickerMax'] && formControl.touched && !isFocused) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Ng\u00E0y l\u1EDBn nh\u1EA5t' }}: <strong>{{ maxD | date: 'dd/MM/yyyy HH:mm' }}</strong>\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['matDatetimePickerParse'] && formControl.touched && !isFocused) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Parse error' }}: <strong>{{ formControl.errors?.['matDatetimePickerParse']?.text }}</strong>\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['customValidator'] && formControl.touched) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ formControl.errors?.['customValidator'] }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['date'] && formControl.touched) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ formControl.errors?.['date'] }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['inlineError'] && formControl.touched) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ inlErr }}\r\n            }\r\n          </mat-error>\r\n        }\r\n      </mat-form-field>\r\n    }\r\n  </div>\r\n}", styles: [".text-primary{color:var(--sd-primary)!important}.bg-primary{background:var(--sd-primary)!important}.border-primary{border-color:var(--sd-primary)!important}.text-primary-light{color:var(--sd-primary-light)!important}.bg-primary-light{background:var(--sd-primary-light)!important}.border-primary-light{border-color:var(--sd-primary-light)!important}.text-primary-dark{color:var(--sd-primary-dark)!important}.bg-primary-dark{background:var(--sd-primary-dark)!important}.border-primary-dark{border-color:var(--sd-primary-dark)!important}.text-info{color:var(--sd-info)!important}.bg-info{background:var(--sd-info)!important}.border-info{border-color:var(--sd-info)!important}.text-info-light{color:var(--sd-info-light)!important}.bg-info-light{background:var(--sd-info-light)!important}.border-info-light{border-color:var(--sd-info-light)!important}.text-info-dark{color:var(--sd-info-dark)!important}.bg-info-dark{background:var(--sd-info-dark)!important}.border-info-dark{border-color:var(--sd-info-dark)!important}.text-success{color:var(--sd-success)!important}.bg-success{background:var(--sd-success)!important}.border-success{border-color:var(--sd-success)!important}.text-success-light{color:var(--sd-success-light)!important}.bg-success-light{background:var(--sd-success-light)!important}.border-success-light{border-color:var(--sd-success-light)!important}.text-success-dark{color:var(--sd-success-dark)!important}.bg-success-dark{background:var(--sd-success-dark)!important}.border-success-dark{border-color:var(--sd-success-dark)!important}.text-warning{color:var(--sd-warning)!important}.bg-warning{background:var(--sd-warning)!important}.border-warning{border-color:var(--sd-warning)!important}.text-warning-light{color:var(--sd-warning-light)!important}.bg-warning-light{background:var(--sd-warning-light)!important}.border-warning-light{border-color:var(--sd-warning-light)!important}.text-warning-dark{color:var(--sd-warning-dark)!important}.bg-warning-dark{background:var(--sd-warning-dark)!important}.border-warning-dark{border-color:var(--sd-warning-dark)!important}.text-error{color:var(--sd-error)!important}.bg-error{background:var(--sd-error)!important}.border-error{border-color:var(--sd-error)!important}.text-error-light{color:var(--sd-error-light)!important}.bg-error-light{background:var(--sd-error-light)!important}.border-error-light{border-color:var(--sd-error-light)!important}.text-error-dark{color:var(--sd-error-dark)!important}.bg-error-dark{background:var(--sd-error-dark)!important}.border-error-dark{border-color:var(--sd-error-dark)!important}.text-secondary{color:var(--sd-secondary)!important}.bg-secondary{background:var(--sd-secondary)!important}.border-secondary{border-color:var(--sd-secondary)!important}.text-secondary-light{color:var(--sd-secondary-light)!important}.bg-secondary-light{background:var(--sd-secondary-light)!important}.border-secondary-light{border-color:var(--sd-secondary-light)!important}.text-secondary-dark{color:var(--sd-secondary-dark)!important}.bg-secondary-dark{background:var(--sd-secondary-dark)!important}.border-secondary-dark{border-color:var(--sd-secondary-dark)!important}.text-light{color:var(--sd-light)!important}.bg-light{background:var(--sd-light)!important}.border-light{border-color:var(--sd-light)!important}.text-dark{color:var(--sd-dark)!important}.bg-dark{background:var(--sd-dark)!important}.border-dark{border-color:var(--sd-dark)!important}.text-black500{color:var(--sd-black500)!important}.bg-black500{background:var(--sd-black500)!important}.border-black500{border-color:var(--sd-black500)!important}.text-black400{color:var(--sd-black400)!important}.bg-black400{background:var(--sd-black400)!important}.border-black400{border-color:var(--sd-black400)!important}.text-black300{color:var(--sd-black300)!important}.bg-black300{background:var(--sd-black300)!important}.border-black300{border-color:var(--sd-black300)!important}.text-black200{color:var(--sd-black200)!important}.bg-black200{background:var(--sd-black200)!important}.border-black200{border-color:var(--sd-black200)!important}.text-black100{color:var(--sd-black100)!important}.bg-black100{background:var(--sd-black100)!important}.border-black100{border-color:var(--sd-black100)!important}.text-white{color:#fff!important}.bg-white{background:#fff!important}.border-white{border-color:#fff!important}.text-black{color:#000!important}.bg-black{background:#000!important}.border-black{border-color:#000!important}:host{padding-top:5px;display:block}:host ::ng-deep .mat-mdc-form-field.mat-form-field-appearance-outline.mat-form-field-disabled .mat-mdc-text-field-wrapper{background:var(--sd-black100)}:host ::ng-deep .mat-mdc-form-field input.mat-mdc-input-element:disabled{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field .mat-mdc-placeholder-required{color:var(--sd-error)}.sd-view:not(.c-focused):not(.c-disabled):hover{background-color:#ebecf0}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: i1.DatePipe, name: "date" }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "ngmodule", type: MatInputModule }, { kind: "directive", type: i3.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "component", type: i3.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i3.MatLabel, selector: "mat-label" }, { kind: "directive", type: i3.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "directive", type: i3.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatTooltipModule }, { kind: "directive", type: i5.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "ngmodule", type: MtxDatetimepickerModule }, { kind: "component", type: i6.MtxDatetimepicker, selector: "mtx-datetimepicker", inputs: ["multiYearSelector", "twelvehour", "showWeekNumbers", "startView", "mode", "timeInterval", "preventSameDateTimeSelection", "calendarHeaderComponent", "panelClass", "opened", "color", "startAt", "type", "touchUi", "timeInput", "timeInputAutoFocus", "disabled", "xPosition", "yPosition", "restoreFocus"], outputs: ["selectedChanged", "opened", "closed", "viewChanged"], exportAs: ["mtxDatetimepicker"] }, { kind: "component", type: i6.MtxDatetimepickerToggle, selector: "mtx-datetimepicker-toggle", inputs: ["for", "tabIndex", "aria-label", "disabled", "disableRipple"], exportAs: ["mtxDatetimepickerToggle"] }, { kind: "directive", type: i6.MtxDatetimepickerInput, selector: "input[mtxDatetimepicker]", inputs: ["mtxDatetimepicker", "mtxDatetimepickerFilter", "value", "min", "max", "disabled"], outputs: ["dateChange", "dateInput"], exportAs: ["mtxDatetimepickerInput"] }, { kind: "component", type: SdLabel, selector: "sd-label", inputs: ["label", "description", "required", "helperText"] }, { kind: "component", type: SdView, selector: "sd-view", inputs: ["label", "value", "display", "hyperlink", "labelTemplate", "valueTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdDatetime, decorators: [{
            type: Component,
            args: [{ selector: 'sd-datetime', changeDetection: ChangeDetectionStrategy.OnPush, providers: [
                        provideMomentDatetimeAdapter({
                            parse: {
                                dateInput: 'DD/MM/YYYY',
                                timeInput: 'HH:mm',
                                datetimeInput: 'DD/MM/YYYY HH:mm',
                            },
                            display: {
                                dateInput: 'DD/MM/YYYY',
                                monthInput: 'MMMM',
                                timeInput: 'HH:mm',
                                datetimeInput: 'DD/MM/YYYY HH:mm',
                                monthYearLabel: 'MMM YYYY',
                                dateA11yLabel: 'LL',
                                monthYearA11yLabel: 'MMMM YYYY',
                                popupHeaderDateLabel: 'MMM DD, ddd',
                            },
                        }),
                    ], standalone: true, imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        MatInputModule,
                        MatIconModule,
                        MatTooltipModule,
                        MatFormFieldModule,
                        MtxDatetimepickerModule,
                        SdLabel,
                        SdView
                    ], template: "@let lbl = label();\r\n@let app = appearance();\r\n@let hideErr = hideInlineError();\r\n@let viewDef = sdViewDef();\r\n@let hText = helperText();\r\n@let req = required();\r\n@let inlErr = inlineError();\r\n\r\n@let minD = resolvedMin();\r\n@let maxD = resolvedMax();\r\n\r\n@if (viewed()) {\r\n  <sd-view\r\n    [label]=\"lbl\"\r\n    [labelTemplate]=\"sdLabelTemplate()\"\r\n    [value]=\"formControl.value\"\r\n    [display]=\"formControl.value | date: 'dd/MM/yyyy HH:mm'\"\r\n    [hyperlink]=\"hyperlink()\"\r\n    [valueTemplate]=\"sdValueTemplate()\">\r\n  </sd-view>\r\n} @else {\r\n  @if (!app) {\r\n    <ng-content select=\"[sdLabel]\">\r\n      @if (lbl) {\r\n        <sd-label [label]=\"lbl\" [required]=\"req\"></sd-label>\r\n      }\r\n    </ng-content>\r\n  }\r\n  \r\n  <div\r\n    class=\"d-flex align-items-center\"\r\n    [class.sd-view]=\"viewDef?.templateRef\"\r\n    [class.c-focused]=\"isFocused\"\r\n    [class.c-disabled]=\"formControl.disabled\"\r\n    (click)=\"onClick()\"\r\n    aria-hidden=\"true\">\r\n    \r\n    @if (viewDef?.templateRef && !isFocused && !datetimePicker()?.opened) {\r\n      <ng-container\r\n        *ngTemplateOutlet=\"\r\n          viewDef!.templateRef;\r\n          context: { value: formControl.value }\r\n        \">\r\n      </ng-container>\r\n    } @else {\r\n      <mat-form-field\r\n        class=\"c-form-field-datetime-input\"\r\n        [class.sd-md]=\"size() === 'md'\"\r\n        [class.sd-sm]=\"size() === 'sm'\"\r\n        [class.hide-inline-error]=\"hideErr\"\r\n        [appearance]=\"app || 'outline'\">\r\n        \r\n        @if (app && lbl) {\r\n          <mat-label style=\"display: inline-block\">\r\n            <div style=\"display: flex; align-items: center; gap: 4px\">\r\n              <span>{{ lbl }}</span>\r\n              @if (hText) {\r\n                <mat-icon [matTooltip]=\"hText\" matTooltipPosition=\"below\">info_outline</mat-icon>\r\n              }\r\n            </div>\r\n          </mat-label>\r\n        }\r\n        \r\n        <mtx-datetimepicker #datetimePicker [type]=\"'datetime'\" [mode]=\"'auto'\"></mtx-datetimepicker>\r\n        \r\n        <input\r\n          aria-hidden=\"true\"\r\n          [attr.data-autoId]=\"autoId()\"\r\n          [mtxDatetimepicker]=\"datetimePicker\"\r\n          [id]=\"id\"\r\n          (blur)=\"onConfirmInput($event)\"\r\n          (keyup.enter)=\"onConfirmInput($event)\"\r\n          (keydown)=\"onKeyDown($event)\"\r\n          (dateChange)=\"onChange($event)\"\r\n          [autocomplete]=\"id\"\r\n          autocorrect=\"off\"\r\n          [formControl]=\"formControl\"\r\n          [required]=\"req\"\r\n          [placeholder]=\"placeholder() || lbl || ''\"\r\n          [min]=\"minD\"\r\n          [max]=\"maxD\"\r\n          (focus)=\"onFocus()\"\r\n          (blur)=\"onBlur()\"\r\n          #input\r\n          matInput />\r\n          \r\n        <mtx-datetimepicker-toggle [for]=\"datetimePicker\" matSuffix></mtx-datetimepicker-toggle>\r\n        \r\n        @if (formControl.errors?.['required'] && formControl.touched) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Vui l\u00F2ng nh\u1EADp th\u00F4ng tin' }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['matDatepickerMin'] && formControl.touched && !isFocused) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Ng\u00E0y nh\u1ECF nh\u1EA5t' }}: <strong>{{ minD | date: 'dd/MM/yyyy HH:mm' }}</strong>\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['matDatepickerMax'] && formControl.touched && !isFocused) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Ng\u00E0y l\u1EDBn nh\u1EA5t' }}: <strong>{{ maxD | date: 'dd/MM/yyyy HH:mm' }}</strong>\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['matDatetimePickerParse'] && formControl.touched && !isFocused) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ 'Parse error' }}: <strong>{{ formControl.errors?.['matDatetimePickerParse']?.text }}</strong>\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['customValidator'] && formControl.touched) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ formControl.errors?.['customValidator'] }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['date'] && formControl.touched) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ formControl.errors?.['date'] }}\r\n            }\r\n          </mat-error>\r\n        }\r\n\r\n        @if (formControl.errors?.['inlineError'] && formControl.touched) {\r\n          <mat-error>\r\n            @if (!hideErr) {\r\n              {{ inlErr }}\r\n            }\r\n          </mat-error>\r\n        }\r\n      </mat-form-field>\r\n    }\r\n  </div>\r\n}", styles: [".text-primary{color:var(--sd-primary)!important}.bg-primary{background:var(--sd-primary)!important}.border-primary{border-color:var(--sd-primary)!important}.text-primary-light{color:var(--sd-primary-light)!important}.bg-primary-light{background:var(--sd-primary-light)!important}.border-primary-light{border-color:var(--sd-primary-light)!important}.text-primary-dark{color:var(--sd-primary-dark)!important}.bg-primary-dark{background:var(--sd-primary-dark)!important}.border-primary-dark{border-color:var(--sd-primary-dark)!important}.text-info{color:var(--sd-info)!important}.bg-info{background:var(--sd-info)!important}.border-info{border-color:var(--sd-info)!important}.text-info-light{color:var(--sd-info-light)!important}.bg-info-light{background:var(--sd-info-light)!important}.border-info-light{border-color:var(--sd-info-light)!important}.text-info-dark{color:var(--sd-info-dark)!important}.bg-info-dark{background:var(--sd-info-dark)!important}.border-info-dark{border-color:var(--sd-info-dark)!important}.text-success{color:var(--sd-success)!important}.bg-success{background:var(--sd-success)!important}.border-success{border-color:var(--sd-success)!important}.text-success-light{color:var(--sd-success-light)!important}.bg-success-light{background:var(--sd-success-light)!important}.border-success-light{border-color:var(--sd-success-light)!important}.text-success-dark{color:var(--sd-success-dark)!important}.bg-success-dark{background:var(--sd-success-dark)!important}.border-success-dark{border-color:var(--sd-success-dark)!important}.text-warning{color:var(--sd-warning)!important}.bg-warning{background:var(--sd-warning)!important}.border-warning{border-color:var(--sd-warning)!important}.text-warning-light{color:var(--sd-warning-light)!important}.bg-warning-light{background:var(--sd-warning-light)!important}.border-warning-light{border-color:var(--sd-warning-light)!important}.text-warning-dark{color:var(--sd-warning-dark)!important}.bg-warning-dark{background:var(--sd-warning-dark)!important}.border-warning-dark{border-color:var(--sd-warning-dark)!important}.text-error{color:var(--sd-error)!important}.bg-error{background:var(--sd-error)!important}.border-error{border-color:var(--sd-error)!important}.text-error-light{color:var(--sd-error-light)!important}.bg-error-light{background:var(--sd-error-light)!important}.border-error-light{border-color:var(--sd-error-light)!important}.text-error-dark{color:var(--sd-error-dark)!important}.bg-error-dark{background:var(--sd-error-dark)!important}.border-error-dark{border-color:var(--sd-error-dark)!important}.text-secondary{color:var(--sd-secondary)!important}.bg-secondary{background:var(--sd-secondary)!important}.border-secondary{border-color:var(--sd-secondary)!important}.text-secondary-light{color:var(--sd-secondary-light)!important}.bg-secondary-light{background:var(--sd-secondary-light)!important}.border-secondary-light{border-color:var(--sd-secondary-light)!important}.text-secondary-dark{color:var(--sd-secondary-dark)!important}.bg-secondary-dark{background:var(--sd-secondary-dark)!important}.border-secondary-dark{border-color:var(--sd-secondary-dark)!important}.text-light{color:var(--sd-light)!important}.bg-light{background:var(--sd-light)!important}.border-light{border-color:var(--sd-light)!important}.text-dark{color:var(--sd-dark)!important}.bg-dark{background:var(--sd-dark)!important}.border-dark{border-color:var(--sd-dark)!important}.text-black500{color:var(--sd-black500)!important}.bg-black500{background:var(--sd-black500)!important}.border-black500{border-color:var(--sd-black500)!important}.text-black400{color:var(--sd-black400)!important}.bg-black400{background:var(--sd-black400)!important}.border-black400{border-color:var(--sd-black400)!important}.text-black300{color:var(--sd-black300)!important}.bg-black300{background:var(--sd-black300)!important}.border-black300{border-color:var(--sd-black300)!important}.text-black200{color:var(--sd-black200)!important}.bg-black200{background:var(--sd-black200)!important}.border-black200{border-color:var(--sd-black200)!important}.text-black100{color:var(--sd-black100)!important}.bg-black100{background:var(--sd-black100)!important}.border-black100{border-color:var(--sd-black100)!important}.text-white{color:#fff!important}.bg-white{background:#fff!important}.border-white{border-color:#fff!important}.text-black{color:#000!important}.bg-black{background:#000!important}.border-black{border-color:#000!important}:host{padding-top:5px;display:block}:host ::ng-deep .mat-mdc-form-field.mat-form-field-appearance-outline.mat-form-field-disabled .mat-mdc-text-field-wrapper{background:var(--sd-black100)}:host ::ng-deep .mat-mdc-form-field input.mat-mdc-input-element:disabled{color:var(--sd-black400)!important}:host ::ng-deep .mat-mdc-form-field .mat-mdc-placeholder-required{color:var(--sd-error)}.sd-view:not(.c-focused):not(.c-disabled):hover{background-color:#ebecf0}\n"] }]
        }], ctorParameters: () => [] });

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

export { SdDatetime };
//# sourceMappingURL=sd-angular-core-forms-datetime.mjs.map
