import * as i0 from '@angular/core';
import { forwardRef, Input, Component } from '@angular/core';
import { FormsModule, ReactiveFormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { A11yModule } from '@angular/cdk/a11y';
import { gettext } from '@c8y/ngx-components/gettext';
import * as i1 from '@ngx-translate/core';

const todayDate = new Date();
var TimeSpanInMs;
(function (TimeSpanInMs) {
    TimeSpanInMs[TimeSpanInMs["MINUTE"] = 60000] = "MINUTE";
    TimeSpanInMs[TimeSpanInMs["HOUR"] = 3600000] = "HOUR";
    TimeSpanInMs[TimeSpanInMs["DAY"] = 86400000] = "DAY";
    TimeSpanInMs[TimeSpanInMs["WEEK"] = 604800000] = "WEEK";
    TimeSpanInMs[TimeSpanInMs["MONTH"] = todayDate.valueOf() - new Date(todayDate.setMonth(todayDate.getMonth() - 1)).valueOf()] = "MONTH";
})(TimeSpanInMs || (TimeSpanInMs = {}));
const INTERVALS = [
    {
        id: 'minutes',
        title: gettext('Last minute'),
        timespanInMs: TimeSpanInMs.MINUTE
    },
    {
        id: 'hours',
        title: gettext('Last hour'),
        timespanInMs: TimeSpanInMs.HOUR
    },
    {
        id: 'days',
        title: gettext('Last day'),
        timespanInMs: TimeSpanInMs.DAY
    },
    {
        id: 'weeks',
        title: gettext('Last week'),
        timespanInMs: TimeSpanInMs.WEEK
    },
    {
        id: 'months',
        title: gettext('Last month'),
        timespanInMs: TimeSpanInMs.MONTH
    },
    { id: 'custom', title: gettext('Custom') }
];
const INTERVAL_TITLES = {
    minutes: gettext('Last minute'),
    hours: gettext('Last hour'),
    days: gettext('Last day'),
    weeks: gettext('Last week'),
    months: gettext('Last month'),
    custom: gettext('Custom')
};
const INTERVAL_VALUES = Object.keys(INTERVAL_TITLES).reduce((acc, key) => ({
    ...acc,
    [key]: key
}), {});

class IntervalPickerComponent {
    constructor(translate) {
        this.translate = translate;
        this.INTERVALS = INTERVALS;
        this.touched = false;
        this.disabled = false;
        this.translatedIntervals = [];
        // eslint-disable-next-line @typescript-eslint/no-empty-function
        this.onChange = _ => { };
        // eslint-disable-next-line @typescript-eslint/no-empty-function
        this.onTouched = () => { };
    }
    ngOnInit() {
        this.translatedIntervals = this.INTERVALS.map(interval => ({
            ...interval,
            title: this.translate.instant(interval.title)
        }));
    }
    writeValue(value) {
        this.value = value;
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(onTouched) {
        this.onTouched = onTouched;
    }
    markAsTouched() {
        if (!this.touched) {
            this.onTouched();
            this.touched = true;
        }
    }
    setDisabledState(disabled) {
        this.disabled = disabled;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IntervalPickerComponent, deps: [{ token: i1.TranslateService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.19", type: IntervalPickerComponent, isStandalone: true, selector: "c8y-interval-picker", inputs: { INTERVALS: "INTERVALS" }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: forwardRef(() => IntervalPickerComponent),
                multi: true
            }
        ], ngImport: i0, template: "@for (interval of translatedIntervals; track interval.id) {\n  <li\n    [ngClass]=\"{\n      active: interval.id === value\n    }\"\n  >\n    <button\n      type=\"button\"\n      [attr.data-cy]=\"'interval-picker--' + interval.id\"\n      (click)=\"onChange(interval.id)\"\n    >\n      <span\n        [ngClass]=\"{\n          'text-primary': interval.id === value\n        }\"\n      >\n        <span\n          c8yIcon=\"check\"\n          [ngStyle]=\"{ visibility: interval.id === value ? 'visible' : 'hidden' }\"\n        ></span>\n        {{ interval.title }}\n      </span>\n    </button>\n  </li>\n}\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "ngmodule", type: FormsModule }, { kind: "ngmodule", type: A11yModule }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "ngmodule", type: BsDropdownModule }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: IntervalPickerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-interval-picker', standalone: true, imports: [CommonModule, FormsModule, A11yModule, ReactiveFormsModule, BsDropdownModule], providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => IntervalPickerComponent),
                            multi: true
                        }
                    ], template: "@for (interval of translatedIntervals; track interval.id) {\n  <li\n    [ngClass]=\"{\n      active: interval.id === value\n    }\"\n  >\n    <button\n      type=\"button\"\n      [attr.data-cy]=\"'interval-picker--' + interval.id\"\n      (click)=\"onChange(interval.id)\"\n    >\n      <span\n        [ngClass]=\"{\n          'text-primary': interval.id === value\n        }\"\n      >\n        <span\n          c8yIcon=\"check\"\n          [ngStyle]=\"{ visibility: interval.id === value ? 'visible' : 'hidden' }\"\n        ></span>\n        {{ interval.title }}\n      </span>\n    </button>\n  </li>\n}\n" }]
        }], ctorParameters: () => [{ type: i1.TranslateService }], propDecorators: { INTERVALS: [{
                type: Input
            }] } });

/**
 * Generated bundle index. Do not edit.
 */

export { INTERVALS, INTERVAL_TITLES, INTERVAL_VALUES, IntervalPickerComponent, TimeSpanInMs };
//# sourceMappingURL=c8y-ngx-components-interval-picker.mjs.map
