import { Injectable } from '@angular/core';
import { RDateService } from '../../extra/calendar-kit';
import { RDateTimePickerComponent } from './date-timepicker.component';
import { RDatepickerAdapter } from './datepicker.directive';
import { RDatepickerComponent, RRangepickerComponent } from './datepicker.component';
export class RDateAdapterService extends RDatepickerAdapter {
    constructor(dateService) {
        super();
        this.dateService = dateService;
        this.picker = RDatepickerComponent;
    }
    parse(date, format) {
        return this.dateService.parse(date, format);
    }
    format(date, format) {
        return this.dateService.format(date, format);
    }
    isValid(date, format) {
        return this.dateService.isValidDateString(date, format);
    }
}
RDateAdapterService.decorators = [
    { type: Injectable }
];
RDateAdapterService.ctorParameters = () => [
    { type: RDateService }
];
export class RRangeAdapterService extends RDatepickerAdapter {
    constructor(dateService) {
        super();
        this.dateService = dateService;
        this.picker = RRangepickerComponent;
    }
    parse(range, format) {
        const [start, end] = range.split('-').map(subDate => subDate.trim());
        return {
            start: this.dateService.parse(start, format),
            end: this.dateService.parse(end, format),
        };
    }
    format(range, format) {
        if (!range) {
            return '';
        }
        const start = this.dateService.format(range.start, format);
        const isStartValid = this.dateService.isValidDateString(start, format);
        if (!isStartValid) {
            return '';
        }
        const end = this.dateService.format(range.end, format);
        const isEndValid = this.dateService.isValidDateString(end, format);
        if (isEndValid) {
            return `${start} - ${end}`;
        }
        else {
            return start;
        }
    }
    isValid(range, format) {
        const [start, end] = range.split('-').map(subDate => subDate.trim());
        return this.dateService.isValidDateString(start, format) && this.dateService.isValidDateString(end, format);
    }
}
RRangeAdapterService.decorators = [
    { type: Injectable }
];
RRangeAdapterService.ctorParameters = () => [
    { type: RDateService }
];
export class RDateTimeAdapterService extends RDatepickerAdapter {
    constructor(dateService) {
        super();
        this.dateService = dateService;
        this.picker = RDateTimePickerComponent;
    }
    parse(date, format) {
        return this.dateService.parse(date, format);
    }
    format(date, format) {
        return this.dateService.format(date, format);
    }
    isValid(date, format) {
        return this.dateService.isValidDateString(date, format);
    }
}
RDateTimeAdapterService.decorators = [
    { type: Injectable }
];
RDateTimeAdapterService.ctorParameters = () => [
    { type: RDateService }
];
//# sourceMappingURL=datepicker-adapter.js.map