import { registerLocaleData } from '@angular/common';

// import and register locale manually
import localeEn from '@angular/common/locales/en';
import localeEN_150 from '@angular/common/locales/en-150';
import localeEN_AT from '@angular/common/locales/en-AT';
import localeEN_BE from '@angular/common/locales/en-BE';
import localeEN_CH from '@angular/common/locales/en-CH';
import localeEN_CY from '@angular/common/locales/en-CY';
import localeEN_DE from '@angular/common/locales/en-DE';
import localeEN_DK from '@angular/common/locales/en-DK';
import localeEN_FI from '@angular/common/locales/en-FI';
import localeEN_GG from '@angular/common/locales/en-GG';
import localeEN_GI from '@angular/common/locales/en-GI';
import localeEN_IE from '@angular/common/locales/en-IE';
import localeEN_IM from '@angular/common/locales/en-IM';
import localeEN_JE from '@angular/common/locales/en-JE';
import localeEN_MT from '@angular/common/locales/en-MT';
import localeEN_NL from '@angular/common/locales/en-NL';
import localeEN_SE from '@angular/common/locales/en-SE';
import localeEN_SI from '@angular/common/locales/en-SI';
import localeEnExtra from '@angular/common/locales/extra/en';
import localeEnExtra_150 from '@angular/common/locales/extra/en-150';
import localeEnExtra_AT from '@angular/common/locales/extra/en-AT';
import localeEnExtra_BE from '@angular/common/locales/extra/en-BE';
import localeEnExtra_CH from '@angular/common/locales/extra/en-CH';
import localeEnExtra_CY from '@angular/common/locales/extra/en-CY';
import localeEnExtra_DE from '@angular/common/locales/extra/en-DE';
import localeEnExtra_DK from '@angular/common/locales/extra/en-DK';
import localeEnExtra_FI from '@angular/common/locales/extra/en-FI';
import localeEnExtra_GG from '@angular/common/locales/extra/en-GG';
import localeEnExtra_GI from '@angular/common/locales/extra/en-GI';
import localeEnExtra_IE from '@angular/common/locales/extra/en-IE';
import localeEnExtra_IM from '@angular/common/locales/extra/en-IM';
import localeEnExtra_JE from '@angular/common/locales/extra/en-JE';
import localeEnExtra_MT from '@angular/common/locales/extra/en-MT';
import localeEnExtra_NL from '@angular/common/locales/extra/en-NL';
import localeEnExtra_SE from '@angular/common/locales/extra/en-SE';
import localeEnExtra_SI from '@angular/common/locales/extra/en-SI';
import localeFr from '@angular/common/locales/fr';
import localeFR_MC from '@angular/common/locales/fr-MC';
import localeFR_LU from '@angular/common/locales/fr-LU';
import localeFR_CH from '@angular/common/locales/fr-CH';
import localeFR_BE from '@angular/common/locales/fr-BE';
import localeFRExtra_BE from '@angular/common/locales/extra/fr-BE';
import localeFRExtra_CH from '@angular/common/locales/extra/fr-CH';
import localeFRExtra_LU from '@angular/common/locales/extra/fr-LU';
import localeFRExtra_MC from '@angular/common/locales/extra/fr-MC';
import localeFrExtra from '@angular/common/locales/extra/fr';

import { GlobalConfig, I18nConfig, LocaleServiceConfig } from '@eui/core';

import * as moment from 'moment';

/**
 * import and register locales (currently MWP uses only French and English)
 */
registerLocaleData(localeEn, 'en', localeEnExtra);
registerLocaleData(localeFr, 'fr', localeFrExtra);
registerLocaleData(localeEN_150, localeEnExtra_150);
registerLocaleData(localeEN_AT, localeEnExtra_AT);
registerLocaleData(localeEN_BE, localeEnExtra_BE);
registerLocaleData(localeEN_CH, localeEnExtra_CH);
registerLocaleData(localeEN_CY, localeEnExtra_CY);
registerLocaleData(localeEN_DE, localeEnExtra_DE);
registerLocaleData(localeEN_DK, localeEnExtra_DK);
registerLocaleData(localeEN_FI, localeEnExtra_FI);
registerLocaleData(localeEN_GG, localeEnExtra_GG);
registerLocaleData(localeEN_GI, localeEnExtra_GI);
registerLocaleData(localeEN_IE, localeEnExtra_IE);
registerLocaleData(localeEN_IM, localeEnExtra_IM);
registerLocaleData(localeEN_JE, localeEnExtra_JE);
registerLocaleData(localeEN_MT, localeEnExtra_MT);
registerLocaleData(localeEN_NL, localeEnExtra_NL);
registerLocaleData(localeEN_SE, localeEnExtra_SE);
registerLocaleData(localeEN_SI, localeEnExtra_SI);
registerLocaleData(localeFR_MC, localeFRExtra_MC);
registerLocaleData(localeFR_LU, localeFRExtra_LU);
registerLocaleData(localeFR_CH, localeFRExtra_CH);
registerLocaleData(localeFR_BE, localeFRExtra_BE);

/**
 * Within the MyWP environment, the 'L' and 'l' date formats have been modified to align with each other
 * and to adhere to the CLDR-based date formats utilized by Angular.
 * For instance, the 'shortDate' format now corresponds to 'DD/MM/YY' instead of the default
 * Moment.js format of 'DD/MM/YYYY'.
 */
const longDateFormat = {
    /** LTS: Specifies the format for displaying time with seconds. */
    LT: 'HH:mm',
    /** LT: Specifies the format for displaying time without seconds. */
    LTS: 'HH:mm:ss',
    /**
     * This format typically produces a localized short date format that is more complete,
     * often including the full month name and day of the month without any abbreviations.
     * e.g. moment().format('L'); // Output: 09/03/2024
     */
    /** L: Specifies the format for displaying the date in short format. */
    L: 'DD/MM/YY',
    /** LL: Specifies the format for displaying the date in long format. */
    LL: 'D MMMM YYYY',
    /** LLL: Specifies the format for displaying the date and time. */
    LLL: 'D MMMM YYYY HH:mm',
    /** LLLL: Specifies the format for displaying the full date and time with the day of the week. */
    LLLL: 'dddd, D MMMM YYYY HH:mm',
    /**
     * This format usually renders a localized short date format that is even shorter,
     * potentially using abbreviations for the month and/or day of the month.
     * e.g. moment().format('l'); // Output: 9/3/2024
     */
    /** l: Specifies the format for displaying the date in short format. */
    l: 'DD/MM/YY',
    /** ll: Specifies the format for displaying the date in long format. */
    ll: 'D MMMM YYYY',
    /** lll: Specifies the format for displaying the date and time. */
    lll: 'D MMMM YYYY HH:mm',
    /** llll: Specifies the format for displaying the full date and time with the day of the week. */
    llll: 'dddd, D MMMM YYYY HH:mm',
}

const longDateFormat_Common = {
    LT: 'HH:mm',
    LTS: 'HH:mm:ss',
    L: 'DD/MM/YYYY',
    LL: 'D MMMM YYYY',
    LLL: 'D MMMM YYYY HH:mm',
    LLLL: 'dddd, D MMMM YYYY HH:mm',
    l: 'DD/MM/YYYY',
    ll: 'D MMMM YYYY',
    lll: 'D MMMM YYYY HH:mm',
    llll: 'dddd, D MMMM YYYY HH:mm',
}

moment.defineLocale('en-at', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-be', { parentLocale: 'en', longDateFormat });
moment.defineLocale('en-ch', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-cy', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-de', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-dk', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-fi', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-gg', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-gi', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-im', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-je', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-mt', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-nl', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('en-se', {
    parentLocale: 'en',
    longDateFormat: {
        /** LTS: Specifies the format for displaying time with seconds. */
        LT: 'HH:mm',
        /** LT: Specifies the format for displaying time without seconds. */
        LTS: 'HH:mm:ss',
        /** L: Specifies the format for displaying the date in short format. */
        L: 'Y-MM-DD',
        /** LL: Specifies the format for displaying the date in long format. */
        LL: 'D MMMM YYYY',
        /** LLL: Specifies the format for displaying the date and time. */
        LLL: 'D MMMM YYYY HH:mm',
        /** LLLL: Specifies the format for displaying the full date and time with the day of the week. */
        LLLL: 'dddd, D MMMM YYYY HH:mm',
        /** l: Specifies the format for displaying the date in short format. */
        l: 'Y-MM-DD',
        /** ll: Specifies the format for displaying the date in long format. */
        ll: 'D MMMM YYYY',
        /** lll: Specifies the format for displaying the date and time. */
        lll: 'D MMMM YYYY HH:mm',
        /** llll: Specifies the format for displaying the full date and time with the day of the week. */
        llll: 'dddd, D MMMM YYYY HH:mm',
    }
});
moment.defineLocale('en-si', { parentLocale: 'en', longDateFormat_Common });
moment.defineLocale('fr-be', { parentLocale: 'fr', longDateFormat });
moment.defineLocale('fr-lu', { parentLocale: 'fr', longDateFormat });
moment.defineLocale('fr-mc', { parentLocale: 'fr', longDateFormat });

/**
 * Internationalization Configuration
 */
const i18nConfig: I18nConfig = {
    i18nLoader: {
        i18nFolders: ['elements/@remote.name@/bundles/assets/i18n-compiled'],
    },
    i18nService: {
        languages: ['en', 'fr'],
        defaultLanguage: 'en',
    },
};

/**
 * Locale Configuration
 */
const localeConfig: LocaleServiceConfig = {
    id: 'en',
    available: ['en', 'fr'],
    bindWithTranslate: true,
    affectGlobalLocale: true,
};

/**
 * Global Configuration
 */
export const GLOBAL: GlobalConfig = {
    /* URL that needs to be used in the appRouting of the MWP */
    baseUrl: '@base.url@',
    /* Element tag name that needs to be unique - make sure it doesn't collide with any other MWP element */
    elementName: '@element.name@',
    /* in case you are using NgRx give it a unique name (mostly for debugging) */
    storeName: '@store.name@',
    i18n: i18nConfig,
    locale: localeConfig,
    eui: {
        assetsBaseUrl: 'assets/elements/@remote.name@/bundles/assets',
    },
};
