"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    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);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var core_1 = require("@angular/core");
var lodash_1 = require("lodash");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __object = typescript_angular_utilities_1.services.object;
var __array = typescript_angular_utilities_1.services.array;
var __guid = typescript_angular_utilities_1.services.guid;
var __time = typescript_angular_utilities_1.services.time;
var validationInput_1 = require("../validationInput");
var componentValidator_service_1 = require("../../../services/componentValidator/componentValidator.service");
var form_1 = require("../../form/form");
var input_1 = require("../input");
var AbsoluteTimeComponent = (function (_super) {
    __extends(AbsoluteTimeComponent, _super);
    function AbsoluteTimeComponent(rlForm, componentValidator, object, array, guid, timeUtility) {
        var _this = _super.call(this, rlForm, componentValidator, object, array, guid) || this;
        _this.minuteInterval = 15;
        _this.showTimes = false;
        _this.hourSelected = false;
        _this.minuteSelected = false;
        _this.inputType = 'time';
        _this.timeUtility = timeUtility;
        _this.control.valueChanges.subscribe(function (value) {
            _this.time = timeUtility.parseTime(value);
        });
        return _this;
    }
    Object.defineProperty(AbsoluteTimeComponent.prototype, "time", {
        get: function () {
            if (!(this.hourSelected || this.minuteSelected)) {
                return null;
            }
            return {
                hour: this.hour,
                minute: this.minute,
                period: this.period,
            };
        },
        set: function (value) {
            if (value == null) {
                this.hour = null;
                this.minute = null;
                this.period = __time.timePeriods.AM;
            }
            else {
                this.hour = value.hour;
                this.minute = value.minute;
                this.period = value.period;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AbsoluteTimeComponent.prototype, "displayTime", {
        get: function () {
            return this.timeUtility.formatTime(this.time, false);
        },
        enumerable: true,
        configurable: true
    });
    AbsoluteTimeComponent.prototype.ngOnInit = function () {
        _super.prototype.ngOnInit.call(this);
        this.allHours = lodash_1.range(1, 13);
        this.allMinutes = lodash_1.range(0, 60, this.minuteInterval);
        this.setSelections();
    };
    AbsoluteTimeComponent.prototype.toggleTimes = function () {
        if (this.showTimes) {
            this.closeTimes();
        }
        else {
            this.showTimes = true;
        }
    };
    AbsoluteTimeComponent.prototype.closeTimes = function () {
        this.showTimes = false;
        this.setSelections();
    };
    AbsoluteTimeComponent.prototype.togglePeriod = function () {
        this.period = this.timeUtility.inversePeriod(this.period);
        this.setValue(this.timeUtility.formatTime(this.time));
    };
    AbsoluteTimeComponent.prototype.selectHour = function (hour) {
        this.hour = hour;
        this.hourSelected = true;
        this.setValue(this.timeUtility.formatTime(this.time));
        if (this.minuteSelected) {
            this.showTimes = false;
        }
    };
    AbsoluteTimeComponent.prototype.deselectHour = function () {
        this.hourSelected = false;
    };
    AbsoluteTimeComponent.prototype.selectMinute = function (minute) {
        this.minute = minute;
        this.minuteSelected = true;
        this.setValue(this.timeUtility.formatTime(this.time));
        if (this.hourSelected) {
            this.showTimes = false;
        }
    };
    AbsoluteTimeComponent.prototype.deselectMinute = function () {
        this.minuteSelected = false;
    };
    AbsoluteTimeComponent.prototype.setSelections = function () {
        this.hourSelected = this.hour != null;
        this.minuteSelected = this.minute != null;
    };
    return AbsoluteTimeComponent;
}(validationInput_1.ValidatedInputComponent));
__decorate([
    core_1.Input(),
    __metadata("design:type", Number)
], AbsoluteTimeComponent.prototype, "minuteInterval", void 0);
AbsoluteTimeComponent = __decorate([
    core_1.Component({
        selector: 'rlAbsoluteTime',
        template: require('./absoluteTime.html'),
        inputs: validationInput_1.validationInputs,
        outputs: validationInput_1.baseOutputs,
        providers: [componentValidator_service_1.ComponentValidator],
        animations: input_1.baseAnimations,
    }),
    __param(0, core_1.Optional()),
    __metadata("design:paramtypes", [form_1.FormComponent,
        componentValidator_service_1.ComponentValidator, __object.ObjectUtility, __array.ArrayUtility, __guid.GuidService, __time.TimeUtility])
], AbsoluteTimeComponent);
exports.AbsoluteTimeComponent = AbsoluteTimeComponent;
//# sourceMappingURL=data:application/json;base64, 