import { AXFormatService } from '@acorex/core/format';
import { AXTranslationService } from '@acorex/core/translation';
import { objectKeyValueTransforms } from '@acorex/platform/core';
import { AXMLocaleManagementService, AXPRegionalSetting } from './acorex-modules-locale-management.mjs';
import { AXPWidgetsList } from '@acorex/modules/common';

class AXMRegionalSettingProvider {
    constructor(injector) {
        this.injector = injector;
        this.regionalService = this.injector.get(AXMLocaleManagementService);
        this.translateService = this.injector.get(AXTranslationService);
        this.formatService = this.injector.get(AXFormatService);
    }
    async provide(context) {
        const trans = async (key) => await this.translateService.translateAsync(`@regional:settings.regional.${key}`);
        const profiles = await this.regionalService.getLocaleProfiles();
        const defaultProfile = profiles.find((p) => p.code === 'en-US');
        context
            .addGroup('regional-settings', await trans('title'), await trans('description'), 'fa-light fa-earth-americas')
            // Date & Time Section
            .addSection('date-time', await trans('datetime.title'), await trans('datetime.description'))
            .addSetting({
            key: AXPRegionalSetting.TimeZone,
            title: await trans('datetime.timezone.title'),
            scope: 'T',
            isInherited: true,
            defaultValue: await this.regionalService.getBrowserTimeZoneCode(),
            valueTransforms: objectKeyValueTransforms('code'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'code',
                    dataSource: 'timezones',
                },
            },
            description: await trans('datetime.timezone.description'),
        })
            .endSection()
            // Region Section
            .addSection('region', await trans('region.title'), await trans('region.description'))
            .addSetting({
            key: AXPRegionalSetting.LocaleProfile,
            title: await trans('region.format.title'),
            scope: 'U',
            isInherited: true,
            defaultValue: defaultProfile.code,
            valueTransforms: objectKeyValueTransforms('code'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'code',
                    dataSource: profiles,
                },
            },
            description: await trans('region.format.description'),
        })
            .addSetting({
            key: AXPRegionalSetting.Language,
            title: await trans('region.language.title'),
            scope: 'U',
            isInherited: true,
            defaultValue: await this.translateService.getDefaultLang(),
            valueTransforms: objectKeyValueTransforms('code'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'code',
                    dataSource: 'locales',
                },
                triggers: [
                    {
                        event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                        action: `{{ widget.setValue(context.eval('${AXPRegionalSetting.LocaleProfile}')) }}`,
                    },
                ],
            },
            description: await trans('region.language.description'),
        })
            .addSetting({
            key: AXPRegionalSetting.Calendar,
            title: await trans('region.calendar.title'),
            scope: 'U',
            isInherited: true,
            defaultValue: defaultProfile.calendar.system,
            valueTransforms: objectKeyValueTransforms('value'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'value',
                    textField: 'text',
                    dataSource: [
                        {
                            text: await trans('region.calendar.options.gregorian'),
                            value: 'gregorian',
                        },
                        {
                            text: await trans('region.calendar.options.hijri'),
                            value: 'solar-hijri',
                        },
                    ],
                },
                triggers: [
                    {
                        event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                        action: [
                            `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').calendar.system) }}`,
                        ],
                    },
                ],
            },
            description: await trans('region.calendar.description'),
        })
            .addSetting({
            key: AXPRegionalSetting.FirstDayOfWeek,
            title: await trans('region.firstday.title'),
            scope: 'T',
            isInherited: false,
            defaultValue: defaultProfile.calendar.week.startsOn,
            valueTransforms: objectKeyValueTransforms('value'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'value',
                    textField: 'text',
                    dataSource: [
                        {
                            text: await trans('region.firstday.options.saturday'),
                            value: 6,
                        },
                        {
                            text: await trans('region.firstday.options.sunday'),
                            value: 0,
                        },
                        {
                            text: await trans('region.firstday.options.monday'),
                            value: 1,
                        },
                    ],
                    triggers: [
                        {
                            event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                            action: [
                                `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').calendar.week.startsOn) }}`,
                            ],
                        },
                    ],
                },
            },
            description: await trans('region.firstday.description'),
        })
            .addSetting({
            key: AXPRegionalSetting.WeekendDays,
            title: await trans('region.workdays.title'),
            scope: 'T',
            isInherited: false,
            defaultValue: defaultProfile.calendar.week.weekends,
            widget: {
                type: AXPWidgetsList.Editors.SelectionList,
                options: {
                    multiple: true,
                    valueField: 'value',
                    textField: 'text',
                    dataSource: [
                        { text: await trans('region.workdays.options.monday'), value: 1 },
                        { text: await trans('region.workdays.options.tuesday'), value: 2 },
                        { text: await trans('region.workdays.options.wednesday'), value: 3 },
                        { text: await trans('region.workdays.options.thursday'), value: 4 },
                        { text: await trans('region.workdays.options.friday'), value: 5 },
                        { text: await trans('region.workdays.options.saturday'), value: 6 },
                        { text: await trans('region.workdays.options.sunday'), value: 0 },
                    ],
                },
                triggers: [
                    {
                        event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                        action: [
                            `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').calendar.week.weekends) }}`,
                        ],
                    },
                ],
            },
            description: await trans('region.workdays.description'),
        })
            // .addSetting({
            //   key: AXPRegionalSetting.ShortDate,
            //   title: await trans('region.shortdate.title'),
            //   scope: 'U',
            //   isInherited: true,
            //   defaultValue: defaultProfile.formats.date.medium,
            //   valueTransforms: objectKeyValueTransforms('value'),
            //   widget: {
            //     type: AXPWidgetsList.Editors.SelectBox,
            //     options: {
            //       valueField: 'value',
            //       textField: 'text',
            //       dataSource: await Promise.all(
            //         profiles.map(async (c) => ({
            //           text: `${c.formats.date.medium} (${await this.formatService.format(new Date(), 'datetime', { format: c.formats.date.medium })})`,
            //           value: c.formats.date.medium,
            //         })),
            //       ),
            //     },
            //     triggers: [
            //       {
            //         event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
            //         action: [
            //           `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').formats.date.short) }}`,
            //         ],
            //       },
            //     ],
            //   },
            //   description: await trans('region.shortdate.description'),
            // })
            // .addSetting({
            //   key: AXPRegionalSetting.LongDate,
            //   title: await trans('region.longdate.title'),
            //   scope: 'U',
            //   isInherited: true,
            //   defaultValue: defaultProfile.formats.date.long,
            //   valueTransforms: objectKeyValueTransforms('value'),
            //   widget: {
            //     type: AXPWidgetsList.Editors.SelectBox,
            //     options: {
            //       valueField: 'value',
            //       textField: 'text',
            //       dataSource: await Promise.all(
            //         profiles.map(async (c) => ({
            //           text: `${c.formats.date.long} (${await this.formatService.format(new Date(), 'datetime', { format: c.formats.date.long })})`,
            //           value: c.formats.date.long,
            //         })),
            //       ),
            //     },
            //     triggers: [
            //       {
            //         event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
            //         action: [
            //           `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').formats.date.long) }}`,
            //         ],
            //       },
            //     ],
            //   },
            //   description: await trans('region.longdate.description'),
            // })
            // .addSetting({
            //   key: AXPRegionalSetting.ShortTime,
            //   title: await trans('region.shorttime.title'),
            //   scope: 'U',
            //   isInherited: true,
            //   defaultValue: defaultProfile.formats.time.short,
            //   valueTransforms: objectKeyValueTransforms('value'),
            //   widget: {
            //     type: AXPWidgetsList.Editors.SelectBox,
            //     options: {
            //       valueField: 'value',
            //       textField: 'text',
            //       dataSource: await Promise.all(
            //         profiles.map(async (c) => ({
            //           text: `${c.formats.time.short} (${await this.formatService.format(new Date(), 'datetime', { format: c.formats.time.short })})`,
            //           value: c.formats.time.short,
            //         })),
            //       ),
            //     },
            //     triggers: [
            //       {
            //         event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
            //         action: [
            //           `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').formats.time.short) }}`,
            //         ],
            //       },
            //     ],
            //   },
            //   description: await trans('region.shorttime.description'),
            // })
            // .addSetting({
            //   key: AXPRegionalSetting.LongTime,
            //   title: await trans('region.longtime.title'),
            //   scope: 'U',
            //   isInherited: true,
            //   defaultValue: defaultProfile.formats.time.long,
            //   valueTransforms: objectKeyValueTransforms('value'),
            //   widget: {
            //     type: AXPWidgetsList.Editors.SelectBox,
            //     options: {
            //       valueField: 'value',
            //       textField: 'text',
            //       dataSource: await Promise.all(
            //         profiles.map(async (c) => ({
            //           text: `${c.formats.time.long} (${await this.formatService.format(new Date(), 'datetime', { format: c.formats.time.long })})`,
            //           value: c.formats.time.long,
            //         })),
            //       ),
            //     },
            //     triggers: [
            //       {
            //         event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
            //         action: [
            //           `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').formats.time.long) }}`,
            //         ],
            //       },
            //     ],
            //   },
            //   description: await trans('region.longtime.description'),
            // })
            .endSection()
            // Unit Settings Section
            .addSection('units', await trans('units.title'), await trans('units.description'))
            .addSetting({
            key: AXPRegionalSetting.TemperatureUnits,
            title: await trans('units.temperature.title'),
            scope: 'U',
            isInherited: true,
            defaultValue: defaultProfile.units.temperature,
            valueTransforms: objectKeyValueTransforms('value'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'value',
                    textField: 'text',
                    dataSource: await Promise.all(profiles.map(async (c) => ({
                        text: await trans(`units.temperature.options.${c.units.temperature}`),
                        value: c.units.temperature,
                    }))),
                },
                triggers: [
                    {
                        event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                        action: [
                            `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').units.temperature) }}`,
                        ],
                    },
                ],
            },
            description: await trans('units.temperature.description'),
        })
            .addSetting({
            key: AXPRegionalSetting.DistanceUnits,
            title: await trans('units.distance.title'),
            scope: 'U',
            isInherited: true,
            defaultValue: defaultProfile.units.distance,
            valueTransforms: objectKeyValueTransforms('value'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'value',
                    textField: 'text',
                    dataSource: await Promise.all(profiles.map(async (c) => ({
                        text: await trans(`units.distance.options.${c.units.distance}`),
                        value: c.units.distance,
                    }))),
                },
                triggers: [
                    {
                        event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                        action: [
                            `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').units.distance) }}`,
                        ],
                    },
                ],
            },
            description: await trans('units.distance.description'),
        })
            .addSetting({
            key: AXPRegionalSetting.WeightUnits,
            title: await trans('units.weight.title'),
            scope: 'U',
            isInherited: true,
            defaultValue: defaultProfile.units.weight,
            valueTransforms: objectKeyValueTransforms('value'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'value',
                    textField: 'text',
                    dataSource: await Promise.all(profiles.map(async (c) => ({
                        text: await trans(`units.weight.options.${c.units.weight}`),
                        value: c.units.weight,
                    }))),
                },
                triggers: [
                    {
                        event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                        action: [
                            `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').units.weight) }}`,
                        ],
                    },
                ],
            },
            description: await trans('units.weight.description'),
        })
            .addSetting({
            key: AXPRegionalSetting.VolumeUnits,
            title: await trans('units.volume.title'),
            scope: 'U',
            isInherited: true,
            defaultValue: defaultProfile.units.volume,
            valueTransforms: objectKeyValueTransforms('value'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'value',
                    textField: 'text',
                    dataSource: [
                        { text: await trans('units.volume.options.liters'), value: 'liters' },
                        { text: await trans('units.volume.options.gallons'), value: 'gallons' },
                    ],
                },
                triggers: [
                    {
                        event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                        action: [
                            `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').units.volume) }}`,
                        ],
                    },
                ],
            },
            description: await trans('units.volume.description'),
        })
            .addSetting({
            key: AXPRegionalSetting.SpeedUnits,
            title: await trans('units.speed.title'),
            scope: 'U',
            isInherited: true,
            defaultValue: defaultProfile.units.speed,
            valueTransforms: objectKeyValueTransforms('value'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'value',
                    textField: 'text',
                    dataSource: await Promise.all(profiles.map(async (c) => ({
                        text: await trans(`units.speed.options.${c.units.speed}`),
                        value: c.units.speed,
                    }))),
                },
                triggers: [
                    {
                        event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                        action: [
                            `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').units.speed) }}`,
                        ],
                    },
                ],
            },
            description: await trans('units.speed.description'),
        })
            .addSetting({
            key: AXPRegionalSetting.AreaUnits,
            title: await trans('units.area.title'),
            scope: 'U',
            isInherited: true,
            defaultValue: defaultProfile.units.area,
            valueTransforms: objectKeyValueTransforms('value'),
            widget: {
                type: AXPWidgetsList.Editors.SelectBox,
                options: {
                    valueField: 'value',
                    textField: 'text',
                    dataSource: await Promise.all(profiles.map(async (c) => ({
                        text: await trans(`units.area.options.${c.units.area}`),
                        value: c.units.area,
                    }))),
                },
                triggers: [
                    {
                        event: `{{ events.context('${AXPRegionalSetting.LocaleProfile}') }}`,
                        action: [
                            `{{ widget.setValue(widget.find('${AXPRegionalSetting.LocaleProfile}').output('item').units.area) }}`,
                        ],
                    },
                ],
            },
            description: await trans('units.area.description'),
        })
            .endSection()
            .endGroup();
    }
}

export { AXMRegionalSettingProvider };
//# sourceMappingURL=acorex-modules-locale-management-settings.provider-Cy0NOzzw.mjs.map
