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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { UserBaseForm } from './vm/security/users/user-base-form';
import { UIAlert } from './ui/shared/ui-alert';
import { CommunicationHubClient } from './services/signalr/communication-hub-client';
import { BreezeSyncHubClient } from './services/signalr/breeze-sync-hub-client';
import { SecurityHubClient } from './services/signalr/security-hub-client';
import { UIBadge } from './attributes/ui-badge';
import { UINotificationList } from './ui/chat/ui-notification-list';
import { UINotification } from './ui/chat/ui-notification';
import { Avatar } from './ui/history/avatar';
import { AppRouter } from 'aurelia-router';
import { UIEntityHistory } from './ui/history/ui-entity-history';
import { UIFilesComponents } from './ui/files/ui-files';
import { computedFrom, Container, FrameworkConfiguration } from "aurelia-framework";
import { PLATFORM } from 'aurelia-pal';
import { Config } from "./config";
import "./locales/common-fr.json";
import "./locales/common-nl.json";
import "./locales/common-en.json";
import { BreezeModel } from "./data/breeze-model";
import { ValueConverters } from './value-converters/value-converters';
import { MenuComponents } from "./ui/menu/ui-navbar";
import { Page } from "./ui/page/ui-page";
import { UISvgIcon } from "./ui/icons/ui-svg-icon";
import { UIIcon } from './ui/icons/ui-icon';
import { UIFlag } from './ui/icons/ui-flag';
import * as AttributeHelpers from './attributes/ui-helpers';
import { UITooltip } from './attributes/ui-tooltip';
import { UIContextmenu } from './attributes/ui-contextmenu';
import { UIInputmaskCustomAttribute } from './attributes/ui-inputmask';
import { Forms } from './ui/forms/ui-forms';
import { Panels } from './ui/panels/ui-panels';
import { Menus } from './ui/menu/ui-menus';
import { Shared } from './ui/shared/ui-shared';
import { registerValidators, UIValidationRenderer } from "./ui/forms/ui-validation";
import { BreezeValidator } from './breeze-validator';
import * as breeze from 'breeze-client';
import { EventAggregator } from 'aurelia-event-aggregator';
import { Backend, TCustomAttribute } from 'aurelia-i18n';
import moment from 'moment';
import { HttpClient } from 'aurelia-fetch-client';
import { ValidationController } from 'aurelia-validation';
import { DateUtils } from './utils/date-utils';
import { UIChat } from './ui/chat/ui-chat';
import { UINotificationAlert } from './ui/chat/ui-notification-alert';
import { UISegmentedControl } from './ui/forms/ui-segmented-control';
import { UISegmentedOption } from './ui/forms/ui-segmented-control-option';
import { UIPagination } from './resources/elements/ui-pagination';
import { UITab } from './ui/tab-panel/ui-tab';
import { UITabbarStart } from './ui/tab-panel/ui-tab-start';
import { UITabbarEnd } from './ui/tab-panel/ui-tab-end';
import { UIInfiniteScrollCustomAttribute } from './attributes/ui-infinite-scroll';
import { Auth0Service, AuthService, DWAuthService } from './security/index';
import { UIThemeObserverAttribute } from './attributes/ui-theme-observer';
import { PredicateUtils } from './data/predicate-utils';
import { RemoteFileStorage } from './services/file-storage-service';
import { LanguageCode } from './constants/constants';
export var UIResources;
(function (UIResources) {
    UIResources["Buttons"] = "buttons";
})(UIResources || (UIResources = {}));
export var UIFrameworkConfig = (function () {
    function UIFrameworkConfig(auConfig, loadResources) {
        var _this = this;
        this.auConfig = auConfig;
        this.resources = [
            "base-app",
            "config",
            "breeze-validator",
            "breeze-model",
            "data-context",
            "entity-manager",
            "repository"
        ];
        this.DefaultLang = LanguageCode.FR;
        this.ApplicationConfigImplementation = null;
        this.BreezeModelImplementation = null;
        this.AuthServiceImplemententation = null;
        this.FileStorageServiceImplemententation = null;
        this.HttpClientConfiguration = null;
        loadResources(function () { return _this.loadResources(); });
    }
    Object.defineProperty(UIFrameworkConfig.prototype, "AuConfig", {
        get: function () {
            return this.auConfig;
        },
        enumerable: false,
        configurable: true
    });
    UIFrameworkConfig.prototype.setDefaultLang = function (lang) {
        this.DefaultLang = lang;
        return this;
    };
    UIFrameworkConfig.prototype.setApplicationConfigImplementation = function (configModule) {
        this.ApplicationConfigImplementation = configModule;
        return this;
    };
    UIFrameworkConfig.prototype.setBreezeModelImplementation = function (breezeModelModule) {
        this.BreezeModelImplementation = breezeModelModule;
        return this;
    };
    UIFrameworkConfig.prototype.setAuthServiceImplementation = function (authserviceModule) {
        this.AuthServiceImplemententation = authserviceModule;
        return this;
    };
    UIFrameworkConfig.prototype.setFileStorageServiceImplementation = function (fileStorageService) {
        if (fileStorageService != null) {
            this.FileStorageServiceImplemententation = fileStorageService;
        }
        else {
            this.FileStorageServiceImplemententation = RemoteFileStorage.DWService;
        }
        return this;
    };
    UIFrameworkConfig.prototype.setHttpClientConfiguration = function (configurationFn) {
        this.HttpClientConfiguration = configurationFn;
        return this;
    };
    UIFrameworkConfig.prototype.autoDetectAuthServiceImplementation = function (authConfig) {
        var authserviceModule = null;
        if ((authConfig.originalDomain != null && authConfig.originalDomain.endsWith('.auth0.com'))
            || authConfig.domain.endsWith('.auth0.com')) {
            authserviceModule = Auth0Service;
        }
        else {
            authserviceModule = DWAuthService;
        }
        return this.setAuthServiceImplementation(authserviceModule);
    };
    UIFrameworkConfig.prototype.checkPrerequisites = function () {
        if (this.ApplicationConfigImplementation == null)
            throw "You must provide an implementation of Config abstract class";
        if (this.AuthServiceImplemententation == null)
            throw "You must provide an implementation of AuthService abstract class";
        if (this.BreezeModelImplementation == null)
            throw "You must provide an implementation of BreezeModel abstract class";
    };
    UIFrameworkConfig.prototype.useStandardResources = function () {
    };
    UIFrameworkConfig.prototype.useResource = function (resource) {
        this.resources.push(resource);
        return this;
    };
    UIFrameworkConfig.prototype.loadResources = function () {
        var attributes = Object.keys(AttributeHelpers).map(function (k) {
            if (AttributeHelpers[k] instanceof Function)
                return AttributeHelpers[k];
            else
                return null;
        });
        this.auConfig.globalResources(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([
            PLATFORM.moduleName('./resources/converters/date-format-value-converter'),
            PLATFORM.moduleName('./resources/converters/get-value-converter'),
            PLATFORM.moduleName('./resources/converters/french-number-converter'),
            PLATFORM.moduleName('./resources/elements/custom-paging'),
            PLATFORM.moduleName('./resources/elements/custom-ag-grid'),
            PLATFORM.moduleName('./resources/elements/grid-header-bar'),
            PLATFORM.moduleName('./resources/elements/tiny-mce'),
            PLATFORM.moduleName('./resources/elements/flow-uploader'),
            PLATFORM.moduleName('./resources/elements/loading-indicator'),
            PLATFORM.moduleName('./resources/elements/previewers/file-previewer'),
            PLATFORM.moduleName('./resources/elements/summary-filters/summary-filter'),
            PLATFORM.moduleName('./resources/attributes/select2-attribute'),
            PLATFORM.moduleName('./resources/attributes/place-autocomplete'),
            PLATFORM.moduleName('./ag-grid/agGridAurelia'),
            PLATFORM.moduleName('./ag-grid/agGridColumn'),
            PLATFORM.moduleName('./ag-grid/agTemplate'),
            PLATFORM.moduleName('./ui/viewport/ui-viewport'),
            PLATFORM.moduleName('./ui/viewport/ui-router-view'),
            PLATFORM.moduleName('./ui/viewport/ui-tab-router-view/ui-tab-router-view'),
            PLATFORM.moduleName('./ui/viewport/ui-viewport-footer'),
            PLATFORM.moduleName('./ui/viewport/ui-viewport-header'),
            PLATFORM.moduleName('./ui/viewport/ui-viewport-leftpart'),
            PLATFORM.moduleName('./ui/menu/ui-appbar'),
            PLATFORM.moduleName('./ui/data/tree/tree-node'),
            PLATFORM.moduleName('./ui/data/tree/ui-tree-panel'),
            PLATFORM.moduleName('./ui/pictures/ui-lightbox'),
            PLATFORM.moduleName('./ui/calendar/ui-date-picker'),
            PLATFORM.moduleName('./ui/calendar/ui-range-picker'),
            PLATFORM.moduleName('./ui/calendar/ui-scheduler'),
            PLATFORM.moduleName('./ui/buttons/ui-button'),
            PLATFORM.moduleName('./ui/buttons/ui-button-group'),
            PLATFORM.moduleName('./ui/buttons/ui-tag'),
            PLATFORM.moduleName('./ui/shared/ui-drop'),
            PLATFORM.moduleName('./ui/data/ui-tag-select'),
            PLATFORM.moduleName('./ui/data/ui-tag-list-check'),
            PLATFORM.moduleName('./ui/data/grid/ui-column'),
            PLATFORM.moduleName('./ui/data/grid/ui-table'),
            PLATFORM.moduleName('./ui/data/grid/ui-table-action'),
            PLATFORM.moduleName('./ui/data/ui-table-pagination/ui-table-pagination'),
            PLATFORM.moduleName('./ui/data/ui-tag-check'),
            PLATFORM.moduleName('./ui/anchor-tab/ui-anchor-tab'),
            PLATFORM.moduleName('./ui/metadata/metadata-detail'),
            PLATFORM.moduleName('./modules/dialogs/floating-box-view.html'),
            PLATFORM.moduleName('./ui/page/ui-dialog-header'),
            PLATFORM.moduleName('./ui/tab-panel/ui-tab-panel'),
            PLATFORM.moduleName('./resources/elements/step-timeline/step-timeline'),
            PLATFORM.moduleName('./resources/global-loader/global-loader')
        ], __read(Panels), false), __read(Page), false), __read(Shared), false), __read(MenuComponents), false), __read(ValueConverters), false), [
            UISvgIcon, UIIcon, UIFlag
        ], false), __read(Forms), false), __read(attributes.filter(function (f) { return f != null; })), false), [
            UITooltip,
            UIBadge,
            UIContextmenu,
            UIInputmaskCustomAttribute,
            UIEntityHistory,
            Avatar,
            UIChat,
            UINotification,
            UINotificationList,
            UINotificationAlert,
            UISegmentedOption,
            UISegmentedControl,
            UIPagination
        ], false), __read(UIFilesComponents), false), __read(Menus), false), [
            UITab,
            UITabbarStart,
            UITabbarEnd,
            UIInfiniteScrollCustomAttribute,
            UIAlert,
            UserBaseForm,
            UIThemeObserverAttribute
        ], false));
        return Promise.resolve();
    };
    __decorate([
        computedFrom("auConfig"),
        __metadata("design:type", FrameworkConfiguration),
        __metadata("design:paramtypes", [])
    ], UIFrameworkConfig.prototype, "AuConfig", null);
    return UIFrameworkConfig;
}());
export function configure(auConfig, configCallback) {
    Container.instance = auConfig.container;
    var loadResources = function () { return Promise.resolve(); };
    var config = new UIFrameworkConfig(auConfig, function (fn) {
        loadResources = fn;
    });
    if (isFunction(configCallback)) {
        configCallback(config);
    }
    else {
        config.useStandardResources();
    }
    configureDefaultPlugins(config);
    configureHttpClient(config.HttpClientConfiguration);
    config.checkPrerequisites();
    auConfig.singleton(Config, config.ApplicationConfigImplementation);
    auConfig.singleton(BreezeModel, config.BreezeModelImplementation);
    auConfig.singleton(AuthService, config.AuthServiceImplemententation);
    auConfig.singleton(RemoteFileStorage.Service, config.FileStorageServiceImplemententation);
    auConfig.singleton(CommunicationHubClient);
    auConfig.singleton(BreezeSyncHubClient);
    auConfig.singleton(SecurityHubClient);
    auConfig.singleton(DateUtils);
    auConfig.singleton(PredicateUtils);
    return loadResources();
}
export * from './exports';
var TranslationAttribute;
(function (TranslationAttribute) {
    TranslationAttribute["Lower"] = "lower";
    TranslationAttribute["Proper"] = "proper";
    TranslationAttribute["Upper"] = "upper";
    TranslationAttribute["UpperFirst"] = "upperFirst";
    TranslationAttribute["LowerFirst"] = "lowerFirst";
})(TranslationAttribute || (TranslationAttribute = {}));
;
function configureDefaultPlugins(frameworkConfig) {
    return frameworkConfig.AuConfig
        .plugin(PLATFORM.moduleName('aurelia-validation'), function (config) {
        config.customValidator(BreezeValidator);
    })
        .plugin(PLATFORM.moduleName('aurelia-breeze'), function () {
        breeze.config.initializeAdapterInstances({ dataService: 'webApi', uriBuilder: 'json' });
    })
        .plugin(PLATFORM.moduleName('aurelia-i18n'), function (instance) {
        var aliases = ['t'];
        TCustomAttribute.configureAliases(aliases);
        instance.i18next.use(Backend.with(frameworkConfig.AuConfig.aurelia.loader));
        instance.i18next.use({
            type: 'postProcessor',
            name: 'handleReferences',
            process: function (value, key, options, translator) {
                var _a;
                (_a = options._refLoopDetection) !== null && _a !== void 0 ? _a : (options._refLoopDetection = []);
                if (options._refLoopDetection.find(function (x) { return x == key; })) {
                    console.warn("Translation reference loop detected on key ".concat(key, ": ").concat(options._refLoopDetection.join(', ')));
                    return key;
                }
                options._refLoopDetection.push(key);
                var trAttrRegex = /\$(?<attr>.+?)\((?<referencedKey>.+?)\)/g;
                var result = value === null || value === void 0 ? void 0 : value.replace(trAttrRegex, function (match, attr, referencedKey) {
                    var e_1, _a;
                    var tr = translator.translate(referencedKey, options);
                    switch (attr) {
                        case TranslationAttribute.Lower: return tr.toLowerCase();
                        case TranslationAttribute.Proper:
                            var words = tr.split(" ");
                            try {
                                for (var words_1 = __values(words), words_1_1 = words_1.next(); !words_1_1.done; words_1_1 = words_1.next()) {
                                    var word = words_1_1.value;
                                    word = word.charAt(0).toUpperCase() + word.slice(1);
                                }
                            }
                            catch (e_1_1) { e_1 = { error: e_1_1 }; }
                            finally {
                                try {
                                    if (words_1_1 && !words_1_1.done && (_a = words_1.return)) _a.call(words_1);
                                }
                                finally { if (e_1) throw e_1.error; }
                            }
                            return words.join(" ");
                        case TranslationAttribute.Upper: return tr.toUpperCase();
                        case TranslationAttribute.UpperFirst: return tr.charAt(0).toUpperCase() + tr.slice(1);
                        case TranslationAttribute.LowerFirst: return tr.charAt(0).toLowerCase() + tr.slice(1);
                        default:
                            console.warn("Unknown attribute detected : $".concat(attr, "(").concat(referencedKey, ")"));
                            return key;
                    }
                });
                options._refLoopDetection.pop();
                return result;
            }
        });
        var options = instance.i18next.options;
        if (false == isArray(options.postProcess)) {
            if (isString(options.postProcess)) {
                options.postProcess = [options.postProcess];
            }
            else {
                options.postProcess = [];
            }
        }
        options.postProcess.push('handleReferences');
        return instance.setup({
            backend: {
                loadPath: function (lngs, namespaces) {
                    if (namespaces.length > 0 && namespaces[0] === 'common')
                        return 'digiwall-lib/dist/native-modules/locales/{{ns}}-{{lng}}.json';
                    return './locales/{{ns}}-{{lng}}.json';
                }
            },
            lng: frameworkConfig.DefaultLang,
            attributes: aliases,
            fallbackLng: 'fr',
            debug: false,
            ns: ['translation', 'common'],
            defaultNS: 'translation',
            fallbackNS: 'common'
        }).then(function () {
            var router = Container.instance.get(AppRouter);
            router.transformTitle = function (title) { return instance.tr(title); };
            var eventAggregator = Container.instance.get(EventAggregator);
            eventAggregator.subscribe('i18n:locale:changed', function () {
                router.updateTitle();
            });
            moment.locale(frameworkConfig.DefaultLang);
        });
    })
        .plugin(PLATFORM.moduleName('aurelia-animator-css'))
        .plugin(PLATFORM.moduleName('aurelia-image-resizer'))
        .plugin(PLATFORM.moduleName('aurelia-ui-virtualization'))
        .postTask(function () {
        var val = Container.instance.get(ValidationController);
        val.addRenderer(new UIValidationRenderer());
        registerValidators(Container.instance);
    });
}
function configureHttpClient(configFn) {
    var httpClient = Container.instance.get(HttpClient);
    httpClient.configure(function (config) {
        config
            .withDefaults({
            credentials: 'same-origin'
        });
    });
    if (configFn != null) {
        httpClient.configure(configFn);
    }
}

//# sourceMappingURL=index.js.map
