import { Component, Input, Output, EventEmitter } from '@angular/core';
import { UntypedFormControl } from '@angular/forms';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/material/datepicker";
import * as i3 from "@angular/material/form-field";
import * as i4 from "@angular/material/icon";
import * as i5 from "@angular/material/input";
import * as i6 from "@angular/material/tooltip";
import * as i7 from "@angular/forms";
export class DatepickerComponent {
    constructor() {
        this.label = null;
        this.disabled = false;
        this.startDate = new Date();
        this.editable = false;
        this.selectedDate = null;
        this.frmControl = new UntypedFormControl(null);
        this.required = false;
        this.readonly = false;
        this.appearance = null;
        this.selectedChange = new EventEmitter();
        this.hasRequiredField = (abstractControl) => {
            if (abstractControl == null) {
                return false;
            }
            if (abstractControl.validator) {
                const validator = abstractControl.validator({});
                if (validator && validator['required']) {
                    return true;
                }
            }
            if (abstractControl['controls']) {
                for (const controlName in abstractControl['controls']) {
                    if (abstractControl['controls'][controlName]) {
                        if (this.hasRequiredField(abstractControl['controls'][controlName])) {
                            return true;
                        }
                    }
                }
            }
            return false;
        };
        this.selectedValue = null;
    }
    ngOnInit() {
        this.origValue = this.frmControl.value;
        console.log(this.origValue);
    }
    save() {
        if (this.editableCallback) {
            this.editableCallback();
            this.origValue = this.frmControl.value;
        }
    }
    cancel() {
        this.frmControl.patchValue(this.origValue);
        this.selectedValue = this.origValue;
    }
    ngOnChanges() {
        if (this.selectedDate) {
            this.selectedValue = this.selectedDate;
        }
        else if (this.frmControl.value) {
            this.selectedValue = this.frmControl.value;
            this.origValue = this.frmControl.value;
        }
    }
}
DatepickerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: DatepickerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
DatepickerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.0", type: DatepickerComponent, selector: "eagna-datepicker", inputs: { label: "label", disabled: "disabled", startDate: "startDate", editable: "editable", editableCallback: "editableCallback", selectedDate: "selectedDate", frmControl: "frmControl", required: "required", readonly: "readonly", appearance: "appearance" }, outputs: { selectedChange: "selectedChange" }, usesOnChanges: true, ngImport: i0, template: "<mat-form-field [appearance]=\"appearance\" color=\"primary\">\r\n    <mat-label *ngIf=\"label != null\">{{label}}</mat-label>\r\n    <input matInput [matDatepicker]=\"picker\" [formControl]=\"frmControl\" placeholder=\"dd/mm/yyy\" autocomplete=\"off\"\r\n        [required]=\"hasRequiredField(frmControl)\">\r\n    <mat-icon *ngIf=\"editable == true && this.frmControl.value != this.origValue\" class=\"font-success cursor-pointer inline\" matTooltip=\"save\" (click)=\"save()\">save</mat-icon>\r\n    <mat-icon *ngIf=\"editable == true && this.frmControl.value != this.origValue\" class=\"font-danger cursor-pointer inline\" matTooltip=\"cancel\"\r\n        (click)=\"cancel()\">cancel</mat-icon>\r\n    <mat-datepicker-toggle matSuffix [for]=\"picker\"></mat-datepicker-toggle>\r\n    <mat-datepicker #picker [startAt]=\"startDate\" [disabled]=\"disabled\"></mat-datepicker>\r\n</mat-form-field>", styles: [""], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.MatDatepicker, selector: "mat-datepicker", exportAs: ["matDatepicker"] }, { kind: "directive", type: i2.MatDatepickerInput, selector: "input[matDatepicker]", inputs: ["matDatepicker", "min", "max", "matDatepickerFilter"], exportAs: ["matDatepickerInput"] }, { kind: "component", type: i2.MatDatepickerToggle, selector: "mat-datepicker-toggle", inputs: ["for", "tabIndex", "aria-label", "disabled", "disableRipple"], exportAs: ["matDatepickerToggle"] }, { kind: "component", type: i3.MatFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i3.MatLabel, selector: "mat-label" }, { kind: "directive", type: i3.MatSuffix, selector: "[matSuffix]" }, { kind: "component", type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: i5.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "directive", type: i6.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { kind: "directive", type: i7.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: i7.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i7.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i7.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: DatepickerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'eagna-datepicker', template: "<mat-form-field [appearance]=\"appearance\" color=\"primary\">\r\n    <mat-label *ngIf=\"label != null\">{{label}}</mat-label>\r\n    <input matInput [matDatepicker]=\"picker\" [formControl]=\"frmControl\" placeholder=\"dd/mm/yyy\" autocomplete=\"off\"\r\n        [required]=\"hasRequiredField(frmControl)\">\r\n    <mat-icon *ngIf=\"editable == true && this.frmControl.value != this.origValue\" class=\"font-success cursor-pointer inline\" matTooltip=\"save\" (click)=\"save()\">save</mat-icon>\r\n    <mat-icon *ngIf=\"editable == true && this.frmControl.value != this.origValue\" class=\"font-danger cursor-pointer inline\" matTooltip=\"cancel\"\r\n        (click)=\"cancel()\">cancel</mat-icon>\r\n    <mat-datepicker-toggle matSuffix [for]=\"picker\"></mat-datepicker-toggle>\r\n    <mat-datepicker #picker [startAt]=\"startDate\" [disabled]=\"disabled\"></mat-datepicker>\r\n</mat-form-field>" }]
        }], ctorParameters: function () { return []; }, propDecorators: { label: [{
                type: Input
            }], disabled: [{
                type: Input
            }], startDate: [{
                type: Input
            }], editable: [{
                type: Input
            }], editableCallback: [{
                type: Input
            }], selectedDate: [{
                type: Input
            }], frmControl: [{
                type: Input
            }], required: [{
                type: Input
            }], readonly: [{
                type: Input
            }], appearance: [{
                type: Input
            }], selectedChange: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 