import { Overlay, OverlayPositionBuilder } from '@angular/cdk/overlay';
import { DOCUMENT } from '@angular/common';
import { ChangeDetectionStrategy, Component, ComponentFactoryResolver, Inject, Input, Optional, } from '@angular/core';
import { RTriggerStrategyBuilderService } from '../../../cdk/overlay/overlay-trigger';
import { RCalendarTimeModelService, RDateService, } from '../../extra/calendar-kit';
import { RCalendarWithTimeComponent } from './calendar-with-time.component';
import { RBasePickerComponent } from './datepicker.component';
import { R_DATE_SERVICE_OPTIONS } from './datepicker.directive';
export class RDateTimePickerComponent extends RBasePickerComponent {
    constructor(document, positionBuilder, triggerStrategyBuilder, overlay, cfr, dateService, dateServiceOptions, calendarWithTimeModelService) {
        super(document, positionBuilder, triggerStrategyBuilder, overlay, cfr, dateService, dateServiceOptions);
        this.calendarWithTimeModelService = calendarWithTimeModelService;
        this.pickerClass = RCalendarWithTimeComponent;
    }
    get value() {
        return this.picker ? this.picker.date : undefined;
    }
    set value(date) {
        if (!this.picker) {
            this.queue = date;
            return;
        }
        if (date) {
            this.visibleDate = date;
            this.picker.visibleDate = date;
            this.picker.date = date;
            this.picker.cd.markForCheck();
        }
    }
    get twelveHoursFormat() {
        return this._twelveHoursFormat;
    }
    set twelveHoursFormat(value) {
        this._twelveHoursFormat = !!value;
    }
    get withSeconds() {
        return this._withSeconds;
    }
    set withSeconds(value) {
        this._withSeconds = !!value;
    }
    get singleColumn() {
        return this._singleColumn;
    }
    set singleColumn(value) {
        this._singleColumn = !!value;
    }
    ngOnInit() {
        this.format = this.format || this.buildTimeFormat();
    }
    patchWithInputs() {
        this.picker.singleColumn = this.singleColumn;
        this.picker.twelveHoursFormat = this.twelveHoursFormat;
        this.picker.withSeconds = this.withSeconds;
        this.picker.step = this.step;
        this.picker.title = this.title;
        this.picker.applyButtonText = this.applyButtonText;
        this.picker.currentTimeButtonText = this.currentTimeButtonText;
        if (this.twelveHoursFormat) {
            this.picker.timeFormat = this.dateService.getTwelveHoursFormat();
        }
        else {
            this.picker.timeFormat = this.withSeconds
                ? this.dateService.getTwentyFourHoursFormatWithSeconds()
                : this.dateService.getTwentyFourHoursFormat();
        }
        super.patchWithInputs();
        this.picker.cd.markForCheck();
    }
    get pickerValueChange() {
        return this.picker.dateChange;
    }
    writeQueue() {
        if (this.queue) {
            const date = this.queue;
            this.queue = null;
            this.value = date;
        }
    }
    buildTimeFormat() {
        if (this.singleColumn) {
            return this.calendarWithTimeModelService.buildDateFormat(this.twelveHoursFormat);
        }
        else {
            return this.calendarWithTimeModelService.buildDateFormat(this.twelveHoursFormat, this.withSeconds);
        }
    }
}
RDateTimePickerComponent.decorators = [
    { type: Component, args: [{
                selector: 'r-date-timepicker',
                template: '',
                changeDetection: ChangeDetectionStrategy.OnPush
            },] }
];
RDateTimePickerComponent.ctorParameters = () => [
    { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
    { type: OverlayPositionBuilder },
    { type: RTriggerStrategyBuilderService },
    { type: Overlay },
    { type: ComponentFactoryResolver },
    { type: RDateService },
    { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [R_DATE_SERVICE_OPTIONS,] }] },
    { type: RCalendarTimeModelService }
];
RDateTimePickerComponent.propDecorators = {
    step: [{ type: Input }],
    title: [{ type: Input }],
    applyButtonText: [{ type: Input }],
    currentTimeButtonText: [{ type: Input }],
    twelveHoursFormat: [{ type: Input }],
    withSeconds: [{ type: Input }],
    singleColumn: [{ type: Input }]
};
//# sourceMappingURL=date-timepicker.component.js.map