import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output, Optional } from '@angular/core';
import { NgControl } from '@angular/forms';
import * as _ from 'lodash';
/**
 * Angular 2 wrapper around Semantic UI Input Element.
 * @see http://semantic-ui.com/elements/input.html
 */
var InputDate = (function () {
    function InputDate(control, _elementRef) {
        this._elementRef = _elementRef;
        this.placeholder = '';
        this.type = '';
        this.value = '';
        this.disabled = false;
        this.focused = false;
        this.tabIndex = null;
        this.required = false;
        this.blur = new EventEmitter();
        if (control) {
            control.valueAccessor = this;
        }
        if (!InputDate.DEFAULT_VALUE) {
            InputDate.DEFAULT_VALUE = InputDate._defaultValue();
        }
    }
    InputDate._defaultValue = function () {
        var d = new Date();
        d.setHours(0);
        d.setMinutes(0);
        d.setSeconds(0);
        d.setMilliseconds(0);
        d.setMonth(d.getMonth() + 1);
        d.setDate(1);
        var r = d.toISOString();
        r = r.substring(0, r.indexOf('T') + 1);
        r = r + '00:00:00';
        return r;
    };
    InputDate.prototype.ngOnChanges = function (change) {
        if (change.focused) {
            var f = change.focused.currentValue === true || change.focused.currentValue === 'true';
            if (f) {
                var el = this._elementRef.nativeElement;
                el.children[0].children[0].focus();
            }
        }
    };
    InputDate.prototype.onBlur = function (value) {
        this.onTouched();
        this.blur.emit(value);
    };
    InputDate.prototype.writeValue = function (value) {
        this._modelValue = _.isEmpty(value) ? InputDate.DEFAULT_VALUE : value;
        this._elementRef.nativeElement.firstElementChild.firstElementChild.setAttribute('value', this._modelValue);
    };
    InputDate.prototype.registerOnChange = function (fn) {
        this.onChange = fn;
    };
    InputDate.prototype.registerOnTouched = function (fn) {
        this.onTouched = fn;
    };
    return InputDate;
}());
export { InputDate };
InputDate.decorators = [
    { type: Component, args: [{
                changeDetection: ChangeDetectionStrategy.OnPush,
                host: { 'role': 'text' },
                selector: 'cw-input-date',
                template: "<div flex layout=\"row\" layout-wrap class=\"ui fluid input\"  [ngClass]=\"{disabled: disabled, icon: icon, required: required}\">\n    <input flex\n           type=\"datetime-local\"\n           [value]=\"_modelValue\"\n           [disabled]=\"disabled\"\n           tabindex=\"{{tabIndex || ''}}\"\n           placeholder=\"{{placeholder}}\"\n           (blur)=\"onBlur($event)\"\n           (change)=\"$event.stopPropagation()\"\n           (input)=\"onChange($event.target.value)\" />\n    <i [ngClass]=\"icon\" *ngIf=\"icon\"></i>\n</div>\n  ",
            },] },
];
/** @nocollapse */
InputDate.ctorParameters = function () { return [
    { type: NgControl, decorators: [{ type: Optional },] },
    { type: ElementRef, },
]; };
InputDate.propDecorators = {
    'placeholder': [{ type: Input },],
    'type': [{ type: Input },],
    'value': [{ type: Input },],
    'icon': [{ type: Input },],
    'disabled': [{ type: Input },],
    'focused': [{ type: Input },],
    'tabIndex': [{ type: Input },],
    'required': [{ type: Input },],
    'blur': [{ type: Output },],
};
//# sourceMappingURL=input-date.js.map