import { AXDataSource } from '@acorex/cdk/common';
import { AXTranslationService } from '@acorex/core/translation';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { inject } from '@angular/core';

//#region ----   Imports   ----
//#endregion
const WEEK_DAY_IDS = [
    'sunday',
    'monday',
    'tuesday',
    'wednesday',
    'thursday',
    'friday',
    'saturday',
];
const WEEK_DAYS_I18N_PREFIX = '@calendar-management:calendars.week-days';
//#region ----   Week Days Data Source Definition   ----
/**
 * Week days data source definition.
 * Provides days of the week with i18n titles for use in weekend and first-day-of-week fields.
 */
class AXMWeekDaysDataSourceDefinition {
    constructor() {
        this.translate = inject(AXTranslationService);
    }
    async items() {
        const list = await Promise.all(WEEK_DAY_IDS.map(async (id) => ({
            id,
            title: await this.translate.translateAsync(`${WEEK_DAYS_I18N_PREFIX}.${id}`),
        })));
        return [
            {
                name: 'week-days',
                title: 'Week Days',
                source: () => new AXDataSource({
                    key: 'id',
                    load: async () => ({
                        items: list,
                        total: list.length,
                    }),
                    byKey: async (key) => list.find((item) => item.id === key),
                    pageSize: 20,
                }),
                columns: [
                    {
                        name: 'id',
                        title: 'ID',
                        datatype: 'string',
                        type: AXPWidgetsCatalog.text,
                    },
                    {
                        name: 'title',
                        title: 'Title',
                        datatype: 'string',
                        type: AXPWidgetsCatalog.text,
                    },
                ],
                filters: [
                    {
                        field: 'title',
                        title: 'Title',
                        operator: { type: 'equal' },
                        widget: { type: AXPWidgetsCatalog.text },
                        filterType: { advance: true, inline: true },
                    },
                ],
                textField: { name: 'title', title: 'Title' },
                valueField: { name: 'id', title: 'ID' },
            },
        ];
    }
}
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Data Source Provider   ----
/**
 * Calendar Management Data Source Provider.
 * Provides all datasource definitions for the Calendar Management module.
 */
class AXMCalendarManagementDataSourceProvider {
    constructor() {
        this.weekDays = new AXMWeekDaysDataSourceDefinition();
    }
    async items() {
        const items = await Promise.all([this.weekDays.items()]);
        return items.flat();
    }
}
//#endregion

export { AXMCalendarManagementDataSourceProvider };
//# sourceMappingURL=acorex-modules-calendar-management-datasource.provider-C_iazC89.mjs.map
