var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Component, Input, Output } from "@angular/core";
import { ValueField } from "../value-field";
import * as momentImported from "moment";
var moment = momentImported;
var DateFieldComponent = /** @class */ (function () {
    function DateFieldComponent() {
    }
    __decorate([
        Input("field"),
        Output("field"),
        __metadata("design:type", DateField)
    ], DateFieldComponent.prototype, "field", void 0);
    DateFieldComponent = __decorate([
        Component({
            selector: "path-datefield",
            templateUrl: "date-field.component.html"
        })
    ], DateFieldComponent);
    return DateFieldComponent;
}());
export { DateFieldComponent };
var DateField = /** @class */ (function (_super) {
    __extends(DateField, _super);
    function DateField(form, translationService) {
        var _this = _super.call(this, form, translationService) || this;
        _this.form = form;
        _this.translationService = translationService;
        _this._initialValueSet = false;
        _this._dateInputFormat = translationService.getUserDateFormat();
        return _this;
    }
    Object.defineProperty(DateField.prototype, "datePickerValue", {
        get: function () {
            return this._datePickerValue;
        },
        set: function (value) {
            this._datePickerValue = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(DateField.prototype, "initialValueSet", {
        get: function () {
            return this._initialValueSet;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(DateField.prototype, "datePickerInitialValue", {
        get: function () {
            return this._datePickerInitialValue;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(DateField.prototype, "dateInputFormat", {
        get: function () {
            return this._dateInputFormat;
        },
        enumerable: false,
        configurable: true
    });
    DateField.prototype.setValue = function (value) {
        if (typeof value === "string") {
            value = moment(value).toDate();
        }
        if (value != null && Object.prototype.toString.call(value) === "[object Date]") {
            // it is a date
            if (isNaN(value.getTime())) {
                value = null;
            }
            else {
                // cut off local timezone
                value = new Date(value.toDateString() + " 00:00:00 GMT");
            }
        }
        else {
            value = null;
        }
        // update ui
        this._datePickerValue = value;
        _super.prototype.setValue.call(this, value);
        if (!this._initialValueSet) {
            this._datePickerInitialValue = value;
            this._initialValueSet = true;
        }
    };
    DateField.prototype.updateValueFromGui = function (value) {
        if (value != null && isNaN(value.getDate())) {
            value = null;
        }
        if (value != null) {
            this.setValue(value);
            this._datePickerValue = this.value;
        }
    };
    return DateField;
}(ValueField));
export { DateField };
//# sourceMappingURL=date-field.component.js.map