import { AXP_MODULE_MANIFEST_PROVIDER, provideLazyProvider, AXP_DATASOURCE_DEFINITION_PROVIDER, AXPSystemActionType } from '@acorex/platform/core';
import { AXP_ENTITY_DEFINITION_LOADER, entityMasterCrudActions, entityMasterRecordActions, entityDetailsCrudActions, entityMasterDeleteAction, entityDetailsSimpleCondition, AXPEntityService } from '@acorex/platform/layout/entity';
import { AXP_MENU_PROVIDER, AXP_SEARCH_PROVIDER, createAllQueryView, AXPEntityCommandScope, AXPSearchCommandProvider } from '@acorex/platform/common';
import { AXP_PERMISSION_DEFINITION_PROVIDER } from '@acorex/platform/auth';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { NgModule, inject, Injector, Injectable } from '@angular/core';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { AXPCommonMenuKeys } from '@acorex/modules/common';
import { AXTranslationService } from '@acorex/core/translation';

const config = {
    i18n: 'calendar-management',
    module: 'CalendarManagement'
};
const RootConfig = {
    config,
    module: {
        name: config.module,
        title: `@${config.i18n}:module.title`,
        icon: 'fa-light fa-calendar',
    },
    entities: {
        calendar: {
            name: 'Calendar',
            title: `@${config.i18n}:calendars.entities.calendar.title`,
            titlePlural: `@${config.i18n}:calendars.entities.calendar.plural`,
            icon: 'fa-light fa-calendar',
        },
        calendarEvent: {
            name: 'CalendarEvent',
            title: `@${config.i18n}:calendar-events.entities.calendar-event.title`,
            titlePlural: `@${config.i18n}:calendar-events.entities.calendar-event.plural`,
            icon: 'fa-light fa-calendar-day',
        },
        calendarEventType: {
            name: 'CalendarEventType',
            title: `@${config.i18n}:calendar-event-types.entities.calendar-event-type.title`,
            titlePlural: `@${config.i18n}:calendar-event-types.entities.calendar-event-type.plural`,
            icon: 'fa-light fa-tag',
        },
    },
};

//#region ----   Imports   ----
//#endregion
//#region ----   Manifest Definition   ----
/**
 * Calendar Management Module Manifest.
 * Defines module metadata, features, and provider references.
 */
const CalendarManagementManifest = {
    name: RootConfig.module.name,
    version: '1.0.0',
    title: RootConfig.module.title,
    icon: RootConfig.module.icon,
    i18n: RootConfig.config.i18n,
    required: true,
    // Module dependencies (optional)
};
//#endregion

class AXMCalendarManagementModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMCalendarManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMCalendarManagementModule, imports: [CommonModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMCalendarManagementModule, providers: [
            // Module Manifest Provider
            {
                provide: AXP_MODULE_MANIFEST_PROVIDER,
                useValue: CalendarManagementManifest,
                multi: true,
            },
            // Provider references (now using tokens)
            provideLazyProvider(AXP_PERMISSION_DEFINITION_PROVIDER, () => Promise.resolve().then(function () { return permissionDefinition_provider; }).then(m => m.AXMCalendarManagementPermissionDefinitionProvider)),
            provideLazyProvider(AXP_MENU_PROVIDER, () => Promise.resolve().then(function () { return menu_provider; }).then(m => m.AXMCalendarManagementMenuProvider)),
            provideLazyProvider(AXP_ENTITY_DEFINITION_LOADER, () => Promise.resolve().then(function () { return entity_provider; }).then(m => m.AXMCalendarManagementEntityProvider)),
            provideLazyProvider(AXP_SEARCH_PROVIDER, () => Promise.resolve().then(function () { return search_provider; }).then(m => m.AXMCalendarManagementSearchCommandProvider)),
            // Lazy datasource provider: AXPDataSourceDefinitionProviderService resolves Promise providers (await Promise.resolve(raw)) before calling .items()
            provideLazyProvider(AXP_DATASOURCE_DEFINITION_PROVIDER, () => import('./acorex-modules-calendar-management-datasource.provider-C_iazC89.mjs').then(m => m.AXMCalendarManagementDataSourceProvider)),
        ], imports: [CommonModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMCalendarManagementModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        CommonModule,
                    ],
                    providers: [
                        // Module Manifest Provider
                        {
                            provide: AXP_MODULE_MANIFEST_PROVIDER,
                            useValue: CalendarManagementManifest,
                            multi: true,
                        },
                        // Provider references (now using tokens)
                        provideLazyProvider(AXP_PERMISSION_DEFINITION_PROVIDER, () => Promise.resolve().then(function () { return permissionDefinition_provider; }).then(m => m.AXMCalendarManagementPermissionDefinitionProvider)),
                        provideLazyProvider(AXP_MENU_PROVIDER, () => Promise.resolve().then(function () { return menu_provider; }).then(m => m.AXMCalendarManagementMenuProvider)),
                        provideLazyProvider(AXP_ENTITY_DEFINITION_LOADER, () => Promise.resolve().then(function () { return entity_provider; }).then(m => m.AXMCalendarManagementEntityProvider)),
                        provideLazyProvider(AXP_SEARCH_PROVIDER, () => Promise.resolve().then(function () { return search_provider; }).then(m => m.AXMCalendarManagementSearchCommandProvider)),
                        // Lazy datasource provider: AXPDataSourceDefinitionProviderService resolves Promise providers (await Promise.resolve(raw)) before calling .items()
                        provideLazyProvider(AXP_DATASOURCE_DEFINITION_PROVIDER, () => import('./acorex-modules-calendar-management-datasource.provider-C_iazC89.mjs').then(m => m.AXMCalendarManagementDataSourceProvider)),
                    ],
                }]
        }] });

async function calendarEventTypeFactory(injector) {
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.calendarEventType.name,
        title: RootConfig.entities.calendarEventType.title,
        icon: RootConfig.entities.calendarEventType.icon,
        formats: {
            individual: RootConfig.entities.calendarEventType.title,
            plural: RootConfig.entities.calendarEventType.titlePlural,
            searchResult: {
                title: '{{ title }}',
                description: '{{ description }}',
            },
        },
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            { name: 'color' },
            { name: 'icon' },
            { name: 'default' },
            { name: 'archive' },
        ],
        //#region ----   Property Groups   ----
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
            {
                id: 'appearance',
                title: '@general:terms.interface.appearance',
            },
            {
                id: 'settings',
                title: '@general:terms.interface.settings',
            },
        ],
        //#endregion
        //#region ----   Properties   ----
        properties: [
            // Basic Information
            {
                name: 'title',
                title: '@general:terms.common.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: 'Enter event type title',
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
            {
                name: 'description',
                title: '@general:terms.common.description',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.largeText,
                        options: {
                            rows: 3,
                            placeholder: 'Enter event type description',
                        },
                    },
                },
            },
            {
                name: 'order',
                title: '@general:terms.classification.order',
                groupId: 'settings',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                        options: {
                            minValue: 0,
                            maxValue: 9999,
                        },
                    },
                },
            },
        ],
        //#endregion
        //#region ----   Table Columns   ----
        columns: [
            { name: 'title' },
        ],
        //#endregion
        //#region ----   Interface Layouts   ----
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'appearance' },
                        { id: 'settings' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        // Appearance
                        // Settings
                        { name: 'order', layout: { positions: { lg: { colSpan: 4, order: 8 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'appearance' },
                        { id: 'settings' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        // Appearance
                        // Settings
                        { name: 'order', layout: { positions: { lg: { colSpan: 4, order: 8 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        { id: 'basic-info' },
                        { id: 'appearance' },
                        { id: 'settings' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        // Appearance
                        // Settings
                        { name: 'order', layout: { positions: { lg: { colSpan: 4, order: 8 } } } },
                    ],
                    actions: [
                        ...entityMasterRecordActions()
                    ],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions(),
                    ],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'order', dir: 'asc' }]
                        }),
                    ],
                },
            },
        },
        //#endregion
    };
    return entityDef;
}

var calendarEventType_entity = /*#__PURE__*/Object.freeze({
    __proto__: null,
    calendarEventTypeFactory: calendarEventTypeFactory
});

async function calendarEventFactory(injector) {
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.calendarEvent.name,
        title: RootConfig.entities.calendarEvent.title,
        icon: RootConfig.entities.calendarEvent.icon,
        formats: {
            individual: RootConfig.entities.calendarEvent.title,
            plural: RootConfig.entities.calendarEvent.titlePlural,
            searchResult: {
                title: '{{ title }} - {{ date }}',
                description: '{{ calendar.title }} - {{ type }}',
            },
        },
        //#region ----   Property Groups   ----
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
            {
                id: 'date',
                title: '@general:terms.datetime.date',
            },
            {
                id: 'appearance',
                title: '@general:terms.interface.appearance',
            },
            {
                id: 'settings',
                title: '@general:terms.interface.settings',
            },
        ],
        //#endregion
        //#region ----   Properties   ----
        properties: [
            // Basic Information
            {
                name: 'calendarId',
                title: '@calendar-management:calendar-events.entities.calendar-event.fields.calendar.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.calendar.name}`,
                            expose: [
                                { source: 'id', target: 'calendar.id' },
                                { source: 'title', target: 'calendar.title' },
                            ],
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
            {
                name: 'title',
                title: '@general:terms.common.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: 'Enter event title',
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
            {
                name: 'description',
                title: '@general:terms.common.description',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.largeText,
                        options: {
                            rows: 3,
                            placeholder: 'Enter event description',
                        },
                    },
                },
            },
            {
                name: 'typeId',
                title: '@calendar-management:calendar-events.entities.calendar-event.fields.type.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            look: 'select',
                            entity: `${RootConfig.module.name}.${RootConfig.entities.calendarEventType.name}`,
                            expose: [
                                { source: 'id', target: 'type.id' },
                                { source: 'title', target: 'type.title' },
                                { source: 'color', target: 'type.color' },
                                { source: 'icon', target: 'type.icon' },
                            ],
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
            // Date & Time
            {
                name: 'date',
                title: '@general:terms.datetime.date',
                groupId: 'date',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                        options: {
                            showTime: false,
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
            // Recurrence
            {
                name: 'isRecurring',
                title: '@calendar-management:calendar-events.entities.calendar-event.fields.is-recurring.title',
                groupId: 'date',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'boolean',
                    defaultValue: false,
                    interface: {
                        type: AXPWidgetsCatalog.toggle,
                    },
                },
            },
            {
                name: 'recurrenceRule',
                title: '@calendar-management:calendar-events.entities.calendar-event.fields.recurrence-rule.title',
                groupId: 'date',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.largeText,
                        options: {
                            rows: 3,
                            placeholder: 'FREQ=YEARLY;BYMONTH=3;BYMONTHDAY=21',
                            visibility: '{{ context.eval("isRecurring") ?? false }}'
                        },
                    },
                },
            },
            {
                name: 'order',
                title: '@general:terms.classification.order',
                groupId: 'settings',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                        options: {
                            minValue: 0,
                            maxValue: 9999,
                        },
                    },
                },
            },
        ],
        //#endregion
        //#region ----   Table Columns   ----
        columns: [
            { name: 'title' },
            { name: 'typeId', options: { dataPath: 'type.title' } },
            { name: 'date' },
            { name: 'isRecurring' },
        ],
        //#endregion
        //#region ----   Interface Layouts   ----
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'date' },
                        { id: 'settings' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'typeId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Date 
                        { name: 'date', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'isRecurring', layout: { positions: { lg: { colSpan: 6, order: 9 } } } },
                        { name: 'recurrenceRule', layout: { positions: { lg: { colSpan: 12, order: 10 } } } },
                        // Settings
                        { name: 'order', layout: { positions: { lg: { colSpan: 6, order: 13 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'date' },
                        { id: 'settings' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'typeId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Date 
                        { name: 'date', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'isRecurring', layout: { positions: { lg: { colSpan: 6, order: 9 } } } },
                        { name: 'recurrenceRule', layout: { positions: { lg: { colSpan: 12, order: 10 } } } },
                        // Settings
                        { name: 'order', layout: { positions: { lg: { colSpan: 6, order: 13 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        { id: 'basic-info' },
                        { id: 'date' },
                        { id: 'settings' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'typeId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Date 
                        { name: 'date', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'isRecurring', layout: { positions: { lg: { colSpan: 6, order: 9 } } } },
                        { name: 'recurrenceRule', layout: { positions: { lg: { colSpan: 12, order: 10 } } } },
                        // Settings
                        { name: 'order', layout: { positions: { lg: { colSpan: 6, order: 13 } } } },
                    ],
                    actions: [
                        {
                            title: '@general:actions.edit.title',
                            command: 'quick-modify-entity',
                            priority: 'primary',
                            type: 'update',
                            scope: AXPEntityCommandScope.Individual,
                        },
                        {
                            title: '@general:actions.delete.title',
                            command: 'delete-entity',
                            priority: 'secondary',
                            type: 'delete',
                            scope: AXPEntityCommandScope.Individual,
                        },
                    ],
                },
                list: {
                    actions: [
                        ...entityDetailsCrudActions('calendarId')
                    ],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'date', dir: 'asc' }]
                        }),
                    ],
                },
            },
        },
        //#endregion
    };
    return entityDef;
}

var calendarEvent_entity = /*#__PURE__*/Object.freeze({
    __proto__: null,
    calendarEventFactory: calendarEventFactory
});

async function calendarFactory(injector) {
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.calendar.name,
        title: RootConfig.entities.calendar.title,
        icon: RootConfig.entities.calendar.icon,
        formats: {
            individual: RootConfig.entities.calendar.title,
            plural: RootConfig.entities.calendar.titlePlural,
            searchResult: {
                title: '{{ title }}',
                description: '{{ calendarType.title }}',
            },
        },
        plugins: [
            { name: 'archive' },
            { name: 'color' },
            { name: 'icon' },
        ],
        //#region ----   Related Entities   ----
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.calendarEvent.name}`,
                title: RootConfig.entities.calendarEvent.titlePlural,
                columns: ['date', 'typeId', 'title', 'isRecurring'],
                conditions: [entityDetailsSimpleCondition('calendarId')],
                actions: [...entityDetailsCrudActions('calendarId')],
            },
        ],
        //#endregion
        //#region ----   Property Groups   ----
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
            // {
            //   id: 'inheritance',
            //   title: '@calendar-management:calendars.entities.calendar.groups.inheritance',
            // },
            {
                id: 'week-config',
                title: '@calendar-management:calendars.entities.calendar.groups.week-configuration',
            },
            // {
            //   id: 'working-hours',
            //   title: '@calendar-management:calendars.entities.calendar.groups.working-hours',
            // },
        ],
        //#endregion
        //#region ----   Properties   ----
        properties: [
            // Basic Information
            {
                name: 'title',
                title: '@general:terms.common.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: 'Enter calendar title',
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
            {
                name: 'description',
                title: '@general:terms.common.description',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.largeText,
                        options: {
                            rows: 3,
                            placeholder: 'Enter calendar description',
                        },
                    },
                },
            },
            {
                name: 'calendarTypeId',
                title: '@calendar-management:calendars.entities.calendar.fields.calendar-type.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            valueField: 'value',
                            textField: 'text',
                            multiple: false,
                            dataSource: [
                                { value: 'gregorian', text: 'Gregorian' },
                                { value: 'solar-hijri', text: 'Solar Hijri' },
                            ],
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
            // Inheritance
            {
                name: 'parentId',
                title: '@calendar-management:calendars.entities.calendar.fields.parent-calendar.title',
                groupId: 'inheritance',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            look: 'select',
                            entity: `${RootConfig.module.name}.${RootConfig.entities.calendar.name}`,
                            expose: [
                                { source: 'id', target: 'parent.id' },
                                { source: 'title', target: 'parent.title' },
                            ],
                        },
                    },
                },
            },
            // Week Configuration
            {
                name: 'weekends',
                title: '@calendar-management:calendars.entities.calendar.fields.weekend-pattern.title',
                groupId: 'week-config',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.selectionList,
                        options: {
                            dataSource: 'week-days',
                            valueField: 'id',
                            textField: 'title',
                            multiple: true,
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
            {
                name: 'firstDayOfWeek',
                title: '@calendar-management:calendars.entities.calendar.fields.first-day-of-week.title',
                groupId: 'week-config',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            dataSource: 'week-days',
                            valueField: 'id',
                            textField: 'title',
                            multiple: false,
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
            // // Working Hours
            // {
            //     name: 'workingHours',
            //     title: '@calendar-management:calendars.entities.calendar.fields.working-hours-config.title',
            //     groupId: 'working-hours',
            //     options: {
            //         sort: { enabled: false },
            //         filter: {
            //             advance: { enabled: false },
            //             inline: { enabled: false },
            //         },
            //     },
            //     schema: {
            //         dataType: 'string',
            //         interface: {
            //             type: AXPWidgetsCatalog.flexLayout,
            //             options: {
            //                 rows: 5,
            //                 placeholder: 'JSON configuration for working hours',
            //             },
            //             children:[
            //                 {
            //                 }
            //             ]
            //         },
            //     },
            // },
        ],
        //#endregion
        //#region ----   Table Columns   ----
        columns: [
            { name: 'title' },
            { name: 'calendarTypeId', options: { dataPath: 'calendarType.title' } },
        ],
        //#region ----   Interface Layouts   ----
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'inheritance' },
                        { id: 'week-config' },
                    ],
                    properties: [
                        // Basic Info — title and type 6+6
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    md: { colSpan: 6, order: 2 },
                                    lg: { colSpan: 6, order: 2 },
                                },
                            },
                        },
                        {
                            name: 'calendarTypeId',
                            layout: {
                                positions: {
                                    md: { colSpan: 6, order: 3 },
                                    lg: { colSpan: 6, order: 3 },
                                },
                            },
                        },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Inheritance
                        { name: 'parentId', layout: { positions: { lg: { colSpan: 12, order: 5 } } } },
                        // Week Config
                        { name: 'weekends', layout: { positions: { lg: { colSpan: 12, order: 8 } } } },
                        { name: 'firstDayOfWeek', layout: { positions: { lg: { colSpan: 12, order: 9 } } } },
                        // Working Hours
                        //{ name: 'workingHours', layout: { positions: { lg: { colSpan: 12, order: 9 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'inheritance' },
                        { id: 'week-config' },
                        { id: 'working-hours' },
                    ],
                    properties: [
                        // Basic Info — title and type 6+6
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    md: { colSpan: 6, order: 2 },
                                    lg: { colSpan: 6, order: 2 },
                                },
                            },
                        },
                        {
                            name: 'calendarTypeId',
                            layout: {
                                positions: {
                                    md: { colSpan: 6, order: 3 },
                                    lg: { colSpan: 6, order: 3 },
                                },
                            },
                        },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Inheritance
                        { name: 'parentId', layout: { positions: { lg: { colSpan: 12, order: 5 } } } },
                        // Week Config
                        { name: 'weekends', layout: { positions: { lg: { colSpan: 12, order: 8 } } } },
                        { name: 'firstDayOfWeek', layout: { positions: { lg: { colSpan: 12, order: 9 } } } },
                        // Working Hours
                        //{ name: 'workingHours', layout: { positions: { lg: { colSpan: 12, order: 9 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        { id: 'basic-info' },
                        { id: 'inheritance' },
                        { id: 'week-config' },
                        { id: 'working-hours' },
                    ],
                    properties: [
                        // Basic Info — title and type 6+6
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    md: { colSpan: 6, order: 2 },
                                    lg: { colSpan: 6, order: 2 },
                                },
                            },
                        },
                        {
                            name: 'calendarTypeId',
                            layout: {
                                positions: {
                                    md: { colSpan: 6, order: 3 },
                                    lg: { colSpan: 6, order: 3 },
                                },
                            },
                            dataPath: 'calendarType.title',
                        },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Inheritance
                        { name: 'parentId', layout: { positions: { lg: { colSpan: 12, order: 5 } } } },
                        // Week Config
                        { name: 'weekends', layout: { positions: { lg: { colSpan: 12, order: 8 } } } },
                        { name: 'firstDayOfWeek', layout: { positions: { lg: { colSpan: 12, order: 9 } } } },
                        // Working Hours
                        //{ name: 'workingHours', layout: { positions: { lg: { colSpan: 12, order: 9 } } } },
                    ],
                    actions: [
                        entityMasterDeleteAction()
                    ],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions()
                    ],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'title', dir: 'asc' }]
                        }),
                    ],
                },
            },
        },
        //#endregion    
    };
    return entityDef;
}

var calendar_entity = /*#__PURE__*/Object.freeze({
    __proto__: null,
    calendarFactory: calendarFactory
});

class AXMCalendarManagementEntityProvider {
    constructor() {
        this.injector = inject(Injector);
    }
    preload() {
        const module = RootConfig.module.name;
        return Array.from(Object.values(RootConfig.entities)).map((entity) => ({
            module: module,
            entity: entity.name,
        }));
    }
    async get(moduleName, entityName) {
        if (moduleName == RootConfig.module.name) {
            switch (entityName) {
                case RootConfig.entities.calendar.name:
                    return (await Promise.resolve().then(function () { return calendar_entity; })).calendarFactory(this.injector);
                case RootConfig.entities.calendarEvent.name:
                    return (await Promise.resolve().then(function () { return calendarEvent_entity; })).calendarEventFactory(this.injector);
                case RootConfig.entities.calendarEventType.name:
                    return (await Promise.resolve().then(function () { return calendarEventType_entity; })).calendarEventTypeFactory(this.injector);
            }
        }
        return null;
    }
    async list() {
        const m = RootConfig.module.name;
        return Promise.resolve(Object.values(RootConfig.entities).map((e) => ({ name: e.name, module: m })));
    }
}

var entity_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMCalendarManagementEntityProvider: AXMCalendarManagementEntityProvider
});

const AXPCalendarManagementMenuKeys = {
    Root: 'CalendarManagement:Menu',
    Calendars: 'CalendarManagement:Menu:Calendars',
    CalendarEventTypes: 'CalendarManagement:Menu:CalendarEventTypes',
};

//#region ----   Imports   ----
//#endregion
//#region ----   Menu Provider   ----
class AXMCalendarManagementMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const module = RootConfig.module;
        context.find(AXPCommonMenuKeys.Configuration).addItems([
            {
                name: AXPCalendarManagementMenuKeys.Root,
                priority: 8920,
                text: '@calendar-management:module.menus.foundation-group.title',
                icon: module.icon,
                policy: {
                    features: [module.name],
                },
                children: [
                    {
                        name: AXPCalendarManagementMenuKeys.Calendars,
                        text: '@calendar-management:calendars.entities.calendar.plural',
                        path: this.entityService.createPath(module.name, RootConfig.entities.calendar.name),
                        icon: RootConfig.entities.calendar.icon,
                        priority: 1,
                    },
                    {
                        name: AXPCalendarManagementMenuKeys.CalendarEventTypes,
                        text: '@calendar-management:calendar-event-types.entities.calendar-event-type.plural',
                        path: this.entityService.createPath(module.name, RootConfig.entities.calendarEventType.name),
                        icon: RootConfig.entities.calendarEventType.icon,
                        priority: 2,
                    },
                ],
            },
        ]);
    }
}
//#endregion

var menu_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMCalendarManagementMenuProvider: AXMCalendarManagementMenuProvider
});

//#region ----   Imports   ----
//#endregion
//#region ----   Permission Keys   ----
const moduleKey = RootConfig.module.name;
const AXMPermissionsKeys = {
    CalendarManagement: {
        Management: `${moduleKey}:${AXPSystemActionType.Manage}`,
        Calendar: {
            Management: `${moduleKey}:Calendar:${AXPSystemActionType.Manage}`,
            View: `${moduleKey}:Calendar:${AXPSystemActionType.View}`,
            Create: `${moduleKey}:Calendar:${AXPSystemActionType.Create}`,
            Update: `${moduleKey}:Calendar:${AXPSystemActionType.Update}`,
            Delete: `${moduleKey}:Calendar:${AXPSystemActionType.Delete}`,
            Admin: `${moduleKey}:Calendar:Admin`,
        },
        CalendarEventType: {
            Management: `${moduleKey}:CalendarEventType:${AXPSystemActionType.Manage}`,
            View: `${moduleKey}:CalendarEventType:${AXPSystemActionType.View}`,
            Create: `${moduleKey}:CalendarEventType:${AXPSystemActionType.Create}`,
            Update: `${moduleKey}:CalendarEventType:${AXPSystemActionType.Update}`,
            Delete: `${moduleKey}:CalendarEventType:${AXPSystemActionType.Delete}`,
        },
    },
};
//#endregion

class AXMCalendarManagementPermissionDefinitionProvider {
    constructor() {
        this.translateService = inject(AXTranslationService);
    }
    async define(context) {
        const keys = AXMPermissionsKeys.CalendarManagement;
        const moduleTitle = await this.translateService.translateAsync('@calendar-management:module.title');
        const calendarTrans = async (action) => await this.translateService.translateAsync(`@calendar-management:calendars.permissions.calendar.actions.${action}.title`);
        const eventTypeTrans = async (action) => await this.translateService.translateAsync(`@calendar-management:calendar-event-types.permissions.calendar-event-type.actions.${action}.title`);
        context.addGroup(RootConfig.module.name, moduleTitle)
            // Calendar Management
            .addPermission(keys.Calendar.Management, await calendarTrans('manage'))
            .addChild(keys.Calendar.View, await calendarTrans('view'))
            .addChild(keys.Calendar.Create, await calendarTrans('create'))
            .addChild(keys.Calendar.Update, await calendarTrans('update'))
            .addChild(keys.Calendar.Delete, await calendarTrans('delete'))
            .endPermission()
            // Calendar Event Type Management
            .addPermission(keys.CalendarEventType.Management, await eventTypeTrans('manage'))
            .addChild(keys.CalendarEventType.View, await eventTypeTrans('view'))
            .addChild(keys.CalendarEventType.Create, await eventTypeTrans('create'))
            .addChild(keys.CalendarEventType.Update, await eventTypeTrans('update'))
            .addChild(keys.CalendarEventType.Delete, await eventTypeTrans('delete'))
            .endPermission()
            // Administrative Permissions
            .addPermission(keys.Calendar.Admin, await calendarTrans('admin'))
            .endPermission()
            .endGroup();
    }
}

var permissionDefinition_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMCalendarManagementPermissionDefinitionProvider: AXMCalendarManagementPermissionDefinitionProvider
});

class AXMCalendarManagementSearchCommandProvider extends AXPSearchCommandProvider {
    constructor() {
        super(...arguments);
        this.commands = [];
    }
}

var search_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMCalendarManagementSearchCommandProvider: AXMCalendarManagementSearchCommandProvider
});

class AXMCalendarManagementService {
    constructor() {
        this.entityService = inject(AXPEntityService);
        //#region ----   Data Accessors   ----
        this.calendarEventDataAccessor = this.entityService
            .withEntity(RootConfig.module.name, RootConfig.entities.calendarEvent.name)
            .data();
        this.calendarDataAccessor = this.entityService
            .withEntity(RootConfig.module.name, RootConfig.entities.calendar.name)
            .data();
    }
    //#endregion
    //#region ----   Methods   ----
    async getCalendars() {
        const calendars = await this.calendarDataAccessor.query({
            skip: 0,
            take: 9999,
            filter: {
                logic: 'and',
                filters: [
                    { field: 'isArchived', operator: { type: 'equal', negative: true }, value: true },
                ],
            },
        });
        return calendars.items.map((eventType) => ({
            id: eventType.id,
            title: eventType.title,
        }));
    }
    async getEvents(range, calendarIds) {
        //TODO: check calendars state to be active
        const filters = [
            { field: 'date', operator: { type: 'lte' }, value: range.end },
            { field: 'date', operator: { type: 'gte' }, value: range.from },
        ];
        // If no calendar IDs provided or empty array, return no events (user must explicitly select calendars)
        if (!calendarIds || calendarIds.length === 0) {
            return [];
        }
        filters.push({ field: 'calendarId', operator: { type: 'in' }, value: calendarIds });
        const events = await this.calendarEventDataAccessor.query({
            skip: 0,
            take: 9999,
            filter: {
                logic: 'and',
                filters,
            },
        });
        return events.items.map((event) => ({
            date: event.date,
            title: event.title,
            description: event.description,
            type: {
                color: event.type?.color,
                icon: event.type?.icon,
                isHoliday: event.type?.isHoliday,
            },
        }));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMCalendarManagementService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMCalendarManagementService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMCalendarManagementService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }] });

// Main Module

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

export { AXMCalendarManagementEntityProvider, AXMCalendarManagementMenuProvider, AXMCalendarManagementModule, AXMCalendarManagementPermissionDefinitionProvider, AXMCalendarManagementSearchCommandProvider, AXMCalendarManagementService, AXMPermissionsKeys, RootConfig, calendarEventFactory, calendarEventTypeFactory, calendarFactory };
//# sourceMappingURL=acorex-modules-calendar-management.mjs.map
