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;
};
import { html, LitElement } from 'lit';
import { property, state } from 'lit/decorators.js';
import { addThemingController } from '../../theming/theming-controller.js';
import { CalendarDay } from '../calendar/model.js';
import IgcChipComponent from '../chip/chip.js';
import { watch } from '../common/decorators/watch.js';
import { registerComponent } from '../common/definitions/register.js';
import { IgcDateRangePickerResourceStringsEN, } from '../common/i18n/date-range-picker.resources.js';
import { styles } from './predefined-ranges-area.base.css.js';
import { all } from './themes/ranges-themes.js';
import { styles as shared } from './themes/shared/predefined-ranges-area.common.css.js';
export default class IgcPredefinedRangesAreaComponent extends LitElement {
    static { this.tagName = 'igc-predefined-ranges-area'; }
    static { this.styles = [styles, shared]; }
    static register() {
        registerComponent(IgcPredefinedRangesAreaComponent, IgcChipComponent);
    }
    constructor() {
        super();
        this._predefinedRanges = [];
        this.usePredefinedRanges = false;
        this.customRanges = [];
        this.resourceStrings = IgcDateRangePickerResourceStringsEN;
        addThemingController(this, all);
    }
    _updatePredefinedRanges() {
        this._predefinedRanges = getPredefinedRanges(this.resourceStrings);
    }
    _handleRangeSelect(range) {
        this.dispatchEvent(new CustomEvent('igcRangeSelect', { detail: range }));
    }
    *_renderDateRanges() {
        const ranges = this.usePredefinedRanges
            ? [...this._predefinedRanges, ...this.customRanges]
            : this.customRanges;
        for (const { label, dateRange } of ranges) {
            yield html `
        <igc-chip @click=${() => this._handleRangeSelect(dateRange)}>
          ${label}
        </igc-chip>
      `;
        }
    }
    render() {
        return html `<div part="ranges">${this._renderDateRanges()}</div>`;
    }
}
__decorate([
    state()
], IgcPredefinedRangesAreaComponent.prototype, "_predefinedRanges", void 0);
__decorate([
    property({
        type: Boolean,
        reflect: true,
        attribute: 'use-predefined-ranges',
    })
], IgcPredefinedRangesAreaComponent.prototype, "usePredefinedRanges", void 0);
__decorate([
    property({ attribute: false })
], IgcPredefinedRangesAreaComponent.prototype, "customRanges", void 0);
__decorate([
    property({ attribute: false })
], IgcPredefinedRangesAreaComponent.prototype, "resourceStrings", void 0);
__decorate([
    watch('resourceStrings')
], IgcPredefinedRangesAreaComponent.prototype, "_updatePredefinedRanges", null);
function getPredefinedRanges(resourceStrings) {
    const today = CalendarDay.today;
    const ranges = [
        {
            key: 'last7Days',
            getDateRange: () => ({
                start: today.add('day', -7).native,
                end: today.native,
            }),
        },
        {
            key: 'currentMonth',
            getDateRange: () => ({
                start: today.set({ date: 1 }).native,
                end: today.set({ date: 1 }).add('month', 1).add('day', -1).native,
            }),
        },
        {
            key: 'last30Days',
            getDateRange: () => ({
                start: today.add('day', -29).native,
                end: today.native,
            }),
        },
        {
            key: 'yearToDate',
            getDateRange: () => ({
                start: today.set({ year: today.year, month: 0, date: 1 }).native,
                end: today.native,
            }),
        },
    ];
    return ranges.map((range) => ({
        label: resourceStrings[range.key] ||
            IgcDateRangePickerResourceStringsEN[range.key],
        dateRange: range.getDateRange(),
    }));
}
//# sourceMappingURL=predefined-ranges-area.js.map