"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
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 __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
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.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.configure = exports.UIFrameworkConfig = exports.UIResources = void 0;
var user_base_form_1 = require("./vm/security/users/user-base-form");
var ui_alert_1 = require("./ui/shared/ui-alert");
var communication_hub_client_1 = require("./services/signalr/communication-hub-client");
var breeze_sync_hub_client_1 = require("./services/signalr/breeze-sync-hub-client");
var security_hub_client_1 = require("./services/signalr/security-hub-client");
var ui_badge_1 = require("./attributes/ui-badge");
var ui_notification_list_1 = require("./ui/chat/ui-notification-list");
var ui_notification_1 = require("./ui/chat/ui-notification");
var avatar_1 = require("./ui/history/avatar");
var aurelia_router_1 = require("aurelia-router");
var ui_entity_history_1 = require("./ui/history/ui-entity-history");
var ui_files_1 = require("./ui/files/ui-files");
var aurelia_framework_1 = require("aurelia-framework");
var aurelia_pal_1 = require("aurelia-pal");
var config_1 = require("./config");
require("./locales/common-fr.json");
require("./locales/common-nl.json");
require("./locales/common-en.json");
var breeze_model_1 = require("./data/breeze-model");
var value_converters_1 = require("./value-converters/value-converters");
var ui_navbar_1 = require("./ui/menu/ui-navbar");
var ui_page_1 = require("./ui/page/ui-page");
var ui_svg_icon_1 = require("./ui/icons/ui-svg-icon");
var ui_icon_1 = require("./ui/icons/ui-icon");
var ui_flag_1 = require("./ui/icons/ui-flag");
var AttributeHelpers = __importStar(require("./attributes/ui-helpers"));
var ui_tooltip_1 = require("./attributes/ui-tooltip");
var ui_contextmenu_1 = require("./attributes/ui-contextmenu");
var ui_inputmask_1 = require("./attributes/ui-inputmask");
var ui_forms_1 = require("./ui/forms/ui-forms");
var ui_panels_1 = require("./ui/panels/ui-panels");
var ui_menus_1 = require("./ui/menu/ui-menus");
var ui_shared_1 = require("./ui/shared/ui-shared");
var ui_validation_1 = require("./ui/forms/ui-validation");
var breeze_validator_1 = require("./breeze-validator");
var breeze = __importStar(require("breeze-client"));
var aurelia_event_aggregator_1 = require("aurelia-event-aggregator");
var aurelia_i18n_1 = require("aurelia-i18n");
var moment_1 = __importDefault(require("moment"));
var aurelia_fetch_client_1 = require("aurelia-fetch-client");
var aurelia_validation_1 = require("aurelia-validation");
var date_utils_1 = require("./utils/date-utils");
var ui_chat_1 = require("./ui/chat/ui-chat");
var ui_notification_alert_1 = require("./ui/chat/ui-notification-alert");
var ui_segmented_control_1 = require("./ui/forms/ui-segmented-control");
var ui_segmented_control_option_1 = require("./ui/forms/ui-segmented-control-option");
var ui_pagination_1 = require("./resources/elements/ui-pagination");
var ui_tab_1 = require("./ui/tab-panel/ui-tab");
var ui_tab_start_1 = require("./ui/tab-panel/ui-tab-start");
var ui_tab_end_1 = require("./ui/tab-panel/ui-tab-end");
var ui_infinite_scroll_1 = require("./attributes/ui-infinite-scroll");
var index_1 = require("./security/index");
var ui_theme_observer_1 = require("./attributes/ui-theme-observer");
var predicate_utils_1 = require("./data/predicate-utils");
var file_storage_service_1 = require("./services/file-storage-service");
var constants_1 = require("./constants/constants");
var UIResources;
(function (UIResources) {
    UIResources["Buttons"] = "buttons";
})(UIResources = exports.UIResources || (exports.UIResources = {}));
var UIFrameworkConfig = exports.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 = constants_1.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 = file_storage_service_1.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 = index_1.Auth0Service;
        }
        else {
            authserviceModule = index_1.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([
            aurelia_pal_1.PLATFORM.moduleName('./resources/converters/date-format-value-converter'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/converters/get-value-converter'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/converters/french-number-converter'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/elements/custom-paging'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/elements/custom-ag-grid'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/elements/grid-header-bar'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/elements/tiny-mce'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/elements/flow-uploader'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/elements/loading-indicator'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/elements/previewers/file-previewer'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/elements/summary-filters/summary-filter'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/attributes/select2-attribute'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/attributes/place-autocomplete'),
            aurelia_pal_1.PLATFORM.moduleName('./ag-grid/agGridAurelia'),
            aurelia_pal_1.PLATFORM.moduleName('./ag-grid/agGridColumn'),
            aurelia_pal_1.PLATFORM.moduleName('./ag-grid/agTemplate'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/viewport/ui-viewport'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/viewport/ui-router-view'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/viewport/ui-tab-router-view/ui-tab-router-view'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/viewport/ui-viewport-footer'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/viewport/ui-viewport-header'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/viewport/ui-viewport-leftpart'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/menu/ui-appbar'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/data/tree/tree-node'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/data/tree/ui-tree-panel'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/pictures/ui-lightbox'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/calendar/ui-date-picker'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/calendar/ui-range-picker'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/calendar/ui-scheduler'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/buttons/ui-button'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/buttons/ui-button-group'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/buttons/ui-tag'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/shared/ui-drop'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/data/ui-tag-select'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/data/ui-tag-list-check'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/data/grid/ui-column'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/data/grid/ui-table'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/data/grid/ui-table-action'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/data/ui-table-pagination/ui-table-pagination'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/data/ui-tag-check'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/anchor-tab/ui-anchor-tab'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/metadata/metadata-detail'),
            aurelia_pal_1.PLATFORM.moduleName('./modules/dialogs/floating-box-view.html'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/page/ui-dialog-header'),
            aurelia_pal_1.PLATFORM.moduleName('./ui/tab-panel/ui-tab-panel'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/elements/step-timeline/step-timeline'),
            aurelia_pal_1.PLATFORM.moduleName('./resources/global-loader/global-loader')
        ], __read(ui_panels_1.Panels), false), __read(ui_page_1.Page), false), __read(ui_shared_1.Shared), false), __read(ui_navbar_1.MenuComponents), false), __read(value_converters_1.ValueConverters), false), [
            ui_svg_icon_1.UISvgIcon, ui_icon_1.UIIcon, ui_flag_1.UIFlag
        ], false), __read(ui_forms_1.Forms), false), __read(attributes.filter(function (f) { return f != null; })), false), [
            ui_tooltip_1.UITooltip,
            ui_badge_1.UIBadge,
            ui_contextmenu_1.UIContextmenu,
            ui_inputmask_1.UIInputmaskCustomAttribute,
            ui_entity_history_1.UIEntityHistory,
            avatar_1.Avatar,
            ui_chat_1.UIChat,
            ui_notification_1.UINotification,
            ui_notification_list_1.UINotificationList,
            ui_notification_alert_1.UINotificationAlert,
            ui_segmented_control_option_1.UISegmentedOption,
            ui_segmented_control_1.UISegmentedControl,
            ui_pagination_1.UIPagination
        ], false), __read(ui_files_1.UIFilesComponents), false), __read(ui_menus_1.Menus), false), [
            ui_tab_1.UITab,
            ui_tab_start_1.UITabbarStart,
            ui_tab_end_1.UITabbarEnd,
            ui_infinite_scroll_1.UIInfiniteScrollCustomAttribute,
            ui_alert_1.UIAlert,
            user_base_form_1.UserBaseForm,
            ui_theme_observer_1.UIThemeObserverAttribute
        ], false));
        return Promise.resolve();
    };
    __decorate([
        (0, aurelia_framework_1.computedFrom)("auConfig"),
        __metadata("design:type", aurelia_framework_1.FrameworkConfiguration),
        __metadata("design:paramtypes", [])
    ], UIFrameworkConfig.prototype, "AuConfig", null);
    return UIFrameworkConfig;
}());
function configure(auConfig, configCallback) {
    aurelia_framework_1.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_1.Config, config.ApplicationConfigImplementation);
    auConfig.singleton(breeze_model_1.BreezeModel, config.BreezeModelImplementation);
    auConfig.singleton(index_1.AuthService, config.AuthServiceImplemententation);
    auConfig.singleton(file_storage_service_1.RemoteFileStorage.Service, config.FileStorageServiceImplemententation);
    auConfig.singleton(communication_hub_client_1.CommunicationHubClient);
    auConfig.singleton(breeze_sync_hub_client_1.BreezeSyncHubClient);
    auConfig.singleton(security_hub_client_1.SecurityHubClient);
    auConfig.singleton(date_utils_1.DateUtils);
    auConfig.singleton(predicate_utils_1.PredicateUtils);
    return loadResources();
}
exports.configure = configure;
__exportStar(require("./exports"), 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(aurelia_pal_1.PLATFORM.moduleName('aurelia-validation'), function (config) {
        config.customValidator(breeze_validator_1.BreezeValidator);
    })
        .plugin(aurelia_pal_1.PLATFORM.moduleName('aurelia-breeze'), function () {
        breeze.config.initializeAdapterInstances({ dataService: 'webApi', uriBuilder: 'json' });
    })
        .plugin(aurelia_pal_1.PLATFORM.moduleName('aurelia-i18n'), function (instance) {
        var aliases = ['t'];
        aurelia_i18n_1.TCustomAttribute.configureAliases(aliases);
        instance.i18next.use(aurelia_i18n_1.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 = aurelia_framework_1.Container.instance.get(aurelia_router_1.AppRouter);
            router.transformTitle = function (title) { return instance.tr(title); };
            var eventAggregator = aurelia_framework_1.Container.instance.get(aurelia_event_aggregator_1.EventAggregator);
            eventAggregator.subscribe('i18n:locale:changed', function () {
                router.updateTitle();
            });
            moment_1.default.locale(frameworkConfig.DefaultLang);
        });
    })
        .plugin(aurelia_pal_1.PLATFORM.moduleName('aurelia-animator-css'))
        .plugin(aurelia_pal_1.PLATFORM.moduleName('aurelia-image-resizer'))
        .plugin(aurelia_pal_1.PLATFORM.moduleName('aurelia-ui-virtualization'))
        .postTask(function () {
        var val = aurelia_framework_1.Container.instance.get(aurelia_validation_1.ValidationController);
        val.addRenderer(new ui_validation_1.UIValidationRenderer());
        (0, ui_validation_1.registerValidators)(aurelia_framework_1.Container.instance);
    });
}
function configureHttpClient(configFn) {
    var httpClient = aurelia_framework_1.Container.instance.get(aurelia_fetch_client_1.HttpClient);
    httpClient.configure(function (config) {
        config
            .withDefaults({
            credentials: 'same-origin'
        });
    });
    if (configFn != null) {
        httpClient.configure(configFn);
    }
}

//# sourceMappingURL=index.js.map
