import { BsDatepickerDirective, BsLocaleService } from 'ngx-bootstrap/datepicker';
import { Component, EventEmitter, Inject, Input, Optional, Output, ViewChild } from '@angular/core';
import { NG_ASYNC_VALIDATORS, NG_VALIDATORS, NG_VALUE_ACCESSOR, NgModel } from '@angular/forms';
import { DomSanitizer } from '@angular/platform-browser';
import { ElementBase } from '../../base/element-base';
import { INPUT_FORMS_CONFIG } from '../../input-forms-config.constants';
import * as i0 from "@angular/core";
import * as i1 from "ngx-bootstrap/datepicker";
import * as i2 from "@angular/platform-browser";
import * as i3 from "@angular/common";
import * as i4 from "@angular/forms";
import * as i5 from "ngx-bootstrap/tooltip";
import * as i6 from "../input-validations/input-validations.component";
let identifier = 0;
export class InputDateComponent extends ElementBase {
    constructor(validators, asyncValidators, config, localeService, domSanitizer) {
        super(validators, asyncValidators, config);
        this.config = config;
        this.localeService = localeService;
        this.domSanitizer = domSanitizer;
        this.placeholder = '';
        this.format = 'MM/dd/yyyy';
        this.showInputGroup = true;
        this.placement = 'bottom';
        this.theme = 'theme-dark-blue';
        this.onChange = new EventEmitter();
        this.locale = 'en-gb';
        this.bsConfig = {
            containerClass: this.theme,
            customTodayClass: 'today',
        };
        this.identifier = `input-date-${identifier++}`;
        if (config.date) {
            Object.assign(this, config.date);
        }
    }
    ngOnInit() {
        this.localeService.use(this.locale);
        this.datepicker.setConfig();
        if (!this.inputGroupText) {
            this.inputGroupText = this.domSanitizer.bypassSecurityTrustHtml("<i class='fa fa-calendar' aria-hidden='true'></i>");
        }
        setTimeout(() => {
            this.handleInitialValue();
        });
    }
    ngDoCheck() {
        this.handleInitialValue();
    }
    onValueChange(value) {
        this.onChange.emit(value);
    }
    handleInitialValue() {
        if (this.value && (typeof this.value == "string" || this.value instanceof String)) {
            let data = new Date(this.value);
            data.setHours(0);
            data.setMinutes(0);
            data.setSeconds(0);
            data.setMilliseconds(0);
            this.writeValue(data);
        }
    }
}
InputDateComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: InputDateComponent, deps: [{ token: NG_VALIDATORS, optional: true }, { token: NG_ASYNC_VALIDATORS, optional: true }, { token: INPUT_FORMS_CONFIG }, { token: i1.BsLocaleService }, { token: i2.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component });
InputDateComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: InputDateComponent, selector: "input-date", inputs: { placeholder: "placeholder", minDate: "minDate", maxDate: "maxDate", format: "format", showInputGroup: "showInputGroup", inputGroupText: "inputGroupText", placement: "placement", theme: "theme" }, outputs: { onChange: "onChange" }, providers: [{
            provide: NG_VALUE_ACCESSOR,
            useExisting: InputDateComponent,
            multi: true
        }], viewQueries: [{ propertyName: "datepicker", first: true, predicate: ["dp"], descendants: true, static: true }, { propertyName: "model", first: true, predicate: NgModel, descendants: true, static: true }], usesInheritance: true, ngImport: i0, template: "<label *ngIf=\"label\" [attr.for]=\"identifier\">\n  {{label}}\n  <span class=\"required-symbol\" *ngIf=\"isRequired\"> *</span>\n  <i class=\"fa fa-question-circle ml-2\" tooltip=\"{{help}}\" container=\"body\" *ngIf=\"help\"></i>\n</label>\n\n<div class=\"input-group\">\n  <div class=\"input-group-prepend\" *ngIf=\"showInputGroup\">\n    <span class=\"input-group-text\" [innerHtml]=\"inputGroupText\"></span>\n  </div>\n\n  <input type=\"text\" class=\"form-control\" [id]=\"identifier\" #dp=\"bsDatepicker\"\n    bsDatepicker\n    autocomplete=\"off\"\n    [minDate]=\"minDate\"\n    [maxDate]=\"maxDate\"\n    [placement]=\"placement\"\n    [placeholder]=\"placeholder\"\n    [disabled]=\"disabled\" \n    [bsConfig]=\"bsConfig\"\n    [(ngModel)]=\"value\"\n    (bsValueChange)=\"onValueChange($event)\"\n    [ngClass]=\"{\n      'is-valid': showValidations && !disabled && touched && !(invalid | async),\n      'is-invalid': showValidations && !disabled && touched && (invalid | async)\n    }\">\n</div>\n\n<small class=\"text-muted\" *ngIf=\"description\">{{description}}</small>\n\n<input-validations\n  *ngIf=\"showValidations && !disabled && touched && (invalid | async)\"\n  [messages]=\"failures | async\">\n</input-validations>\n", dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i4.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: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i1.BsDatepickerDirective, selector: "[bsDatepicker]", inputs: ["placement", "triggers", "outsideClick", "container", "outsideEsc", "isOpen", "bsValue", "bsConfig", "isDisabled", "minDate", "maxDate", "minMode", "daysDisabled", "datesDisabled", "datesEnabled", "dateCustomClasses"], outputs: ["bsValueChange", "onShown", "onHidden"], exportAs: ["bsDatepicker"] }, { kind: "directive", type: i1.BsDatepickerInputDirective, selector: "input[bsDatepicker]" }, { kind: "directive", type: i5.TooltipDirective, selector: "[tooltip], [tooltipHtml]", inputs: ["containerClass", "tooltipAnimation", "tooltipFadeDuration", "isOpen", "tooltipHtml", "tooltip", "tooltipPlacement", "placement", "tooltipIsOpen", "tooltipEnable", "isDisabled", "tooltipAppendToBody", "container", "tooltipClass", "tooltipContext", "tooltipPopupDelay", "delay", "tooltipTrigger", "triggers", "adaptivePosition"], outputs: ["tooltipChange", "tooltipStateChanged", "onShown", "onHidden"], exportAs: ["bs-tooltip"] }, { kind: "component", type: i6.InputValidationsComponent, selector: "input-validations", inputs: ["messages"] }, { kind: "pipe", type: i3.AsyncPipe, name: "async" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: InputDateComponent, decorators: [{
            type: Component,
            args: [{ selector: 'input-date', providers: [{
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: InputDateComponent,
                            multi: true
                        }], template: "<label *ngIf=\"label\" [attr.for]=\"identifier\">\n  {{label}}\n  <span class=\"required-symbol\" *ngIf=\"isRequired\"> *</span>\n  <i class=\"fa fa-question-circle ml-2\" tooltip=\"{{help}}\" container=\"body\" *ngIf=\"help\"></i>\n</label>\n\n<div class=\"input-group\">\n  <div class=\"input-group-prepend\" *ngIf=\"showInputGroup\">\n    <span class=\"input-group-text\" [innerHtml]=\"inputGroupText\"></span>\n  </div>\n\n  <input type=\"text\" class=\"form-control\" [id]=\"identifier\" #dp=\"bsDatepicker\"\n    bsDatepicker\n    autocomplete=\"off\"\n    [minDate]=\"minDate\"\n    [maxDate]=\"maxDate\"\n    [placement]=\"placement\"\n    [placeholder]=\"placeholder\"\n    [disabled]=\"disabled\" \n    [bsConfig]=\"bsConfig\"\n    [(ngModel)]=\"value\"\n    (bsValueChange)=\"onValueChange($event)\"\n    [ngClass]=\"{\n      'is-valid': showValidations && !disabled && touched && !(invalid | async),\n      'is-invalid': showValidations && !disabled && touched && (invalid | async)\n    }\">\n</div>\n\n<small class=\"text-muted\" *ngIf=\"description\">{{description}}</small>\n\n<input-validations\n  *ngIf=\"showValidations && !disabled && touched && (invalid | async)\"\n  [messages]=\"failures | async\">\n</input-validations>\n" }]
        }], ctorParameters: function () { return [{ type: undefined, decorators: [{
                    type: Optional
                }, {
                    type: Inject,
                    args: [NG_VALIDATORS]
                }] }, { type: undefined, decorators: [{
                    type: Optional
                }, {
                    type: Inject,
                    args: [NG_ASYNC_VALIDATORS]
                }] }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [INPUT_FORMS_CONFIG]
                }] }, { type: i1.BsLocaleService }, { type: i2.DomSanitizer }]; }, propDecorators: { placeholder: [{
                type: Input
            }], minDate: [{
                type: Input
            }], maxDate: [{
                type: Input
            }], format: [{
                type: Input
            }], showInputGroup: [{
                type: Input
            }], inputGroupText: [{
                type: Input
            }], placement: [{
                type: Input
            }], theme: [{
                type: Input
            }], onChange: [{
                type: Output
            }], datepicker: [{
                type: ViewChild,
                args: ['dp', { static: true }]
            }], model: [{
                type: ViewChild,
                args: [NgModel, { static: true }]
            }] } });
//# sourceMappingURL=data:application/json;base64, 