import { LogService, AsyncStorageService, BaseModuleEffects, initialBaseAppState, baseAppReducers, initialBaseUserState, baseUserReducers, baseReducers, initialBaseState, DEFAULT_BASE_CONFIG, getBaseRootProviders, BASE_NAME_TOKEN, getBaseChildProviders, baseInitApp, APP_CONFIG_TOKEN, BaseModule } from '@eui/base';
export * from '@eui/base';
export { DEFAULT_BASE_APP_CONFIG as DEFAULT_APP_CONFIG, DEFAULT_BASE_ENVIRONMENT_CONFIG as DEFAULT_ENVIRONMENT_CONFIG, DEFAULT_BASE_GLOBAL_CONFIG as DEFAULT_GLOBAL_CONFIG, DEFAULT_BASE_CONFIG as DEFAULT_IONIC_CONFIG, baseInitApp as initApp, basePreInitApp as preInitApp } from '@eui/base';
import { __extends, __spread } from 'tslib';
import { ɵɵinject, ɵɵdefineInjectable, ɵsetClassMetadata, Injectable, Optional, APP_INITIALIZER, Injector, ɵɵdefineNgModule, ɵɵdefineInjector, ɵɵsetNgModuleScope, NgModule, SkipSelf } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { EffectsModule, EffectsRootModule } from '@ngrx/effects';
import { from } from 'rxjs';
import { take, tap } from 'rxjs/operators';
import { Storage } from '@ionic/storage';

/**
 * ionic storage service, using the @ionic/storage library
 * https://ionicframework.com/docs/building/storage
 */
var IonicStorageService = /** @class */ (function (_super) {
    __extends(IonicStorageService, _super);
    function IonicStorageService(storage, log) {
        var _this = _super.call(this) || this;
        _this.storage = storage;
        _this.log = log;
        return _this;
    }
    /**
     * the name of the storage service
     */
    IonicStorageService.prototype.name = function () {
        return IonicStorageService.NAME;
    };
    /**
     * reflects the readiness of the storage
     * @returns one time emission Observable<void>
     */
    IonicStorageService.prototype.ready = function () {
        var _this = this;
        return from(this.storage.ready())
            .pipe(take(1), tap(function () {
        }, function (err) {
            if (_this.log) {
                _this.log.error(_this.name(), 'ready', err);
            }
        }));
    };
    /**
     * retrieve an object from storage
     * @param key the associated key
     * @returns one time emission Observable of value
     */
    IonicStorageService.prototype.get = function (key) {
        var _this = this;
        return from(this.storage.get(key))
            .pipe(take(1), tap(function () {
        }, function (err) {
            if (_this.log) {
                _this.log.error(_this.name(), 'get', err);
            }
        }));
    };
    /**
     * sets an object in storage
     * @param key the associated key
     * @param value the value to set
     * @returns one time emission Observable
     */
    IonicStorageService.prototype.set = function (key, value) {
        var _this = this;
        return from(this.storage.set(key, value))
            .pipe(take(1), tap(function () {
        }, function (err) {
            if (_this.log) {
                _this.log.error(_this.name(), 'set', err);
            }
        }));
    };
    /**
     * removes an object from storage
     * @param key the associated key
     * @returns one time emission Observable
     */
    IonicStorageService.prototype.remove = function (key) {
        var _this = this;
        return from(this.storage.remove(key))
            .pipe(take(1), tap(function () {
        }, function (err) {
            if (_this.log) {
                _this.log.error(_this.name(), 'remove', err);
            }
        }));
    };
    IonicStorageService.NAME = 'IonicStorageService';
    /** @nocollapse */ IonicStorageService.ɵfac = function IonicStorageService_Factory(t) { return new (t || IonicStorageService)(ɵɵinject(Storage), ɵɵinject(LogService, 8)); };
    /** @nocollapse */ IonicStorageService.ɵprov = ɵɵdefineInjectable({ token: IonicStorageService, factory: IonicStorageService.ɵfac });
    return IonicStorageService;
}(AsyncStorageService));
/*@__PURE__*/ (function () { ɵsetClassMetadata(IonicStorageService, [{
        type: Injectable
    }], function () { return [{ type: Storage }, { type: LogService, decorators: [{
                type: Optional
            }] }]; }, null); })();

var IonicAppActionTypes;
(function (IonicAppActionTypes) {
})(IonicAppActionTypes || (IonicAppActionTypes = {}));

var IonicUserActionTypes;
(function (IonicUserActionTypes) {
})(IonicUserActionTypes || (IonicUserActionTypes = {}));

var IonicModuleEffects = __spread(BaseModuleEffects);

var initialIonicAppState = Object.assign({}, initialBaseAppState, {});

var actionToReducerMap = {};
var ionicAppReducers = function (state, action) {
    if (state === void 0) { state = initialIonicAppState; }
    if (actionToReducerMap[action.type]) {
        return actionToReducerMap[action.type](state, action);
    }
    // if the action type is not in the map, call the base reducers method
    return baseAppReducers(state, action);
};

var initialIonicUserState = Object.assign({}, initialBaseUserState, {});

var actionToReducerMap$1 = {};
var ionicUserReducers = function (state, action) {
    if (state === void 0) { state = initialIonicUserState; }
    if (actionToReducerMap$1[action.type]) {
        return actionToReducerMap$1[action.type](state, action);
    }
    // if the action type is not in the map, call the base reducers method
    return baseUserReducers(state, action);
};

var ionicReducers = Object.assign({}, baseReducers, {
    app: ionicAppReducers,
    user: ionicUserReducers,
});

var initialIonicState = Object.assign({}, initialBaseState, {
    app: initialIonicAppState,
    user: initialIonicUserState,
});

function getRootProviders(ionicConfig) {
    if (ionicConfig === void 0) { ionicConfig = DEFAULT_BASE_CONFIG; }
    return __spread(getBaseRootProviders(ionicConfig), [
        // ionic config
        { provide: BASE_NAME_TOKEN, useValue: 'eui-ionic' },
        // storage services
        IonicStorageService,
        { provide: AsyncStorageService, useExisting: IonicStorageService },
    ]);
}
function getChildProviders(moduleName) {
    return __spread(getBaseChildProviders(moduleName));
}
var IonicModule = /** @class */ (function (_super) {
    __extends(IonicModule, _super);
    function IonicModule(parentModule, injector) {
        return _super.call(this, parentModule, injector) || this;
    }
    IonicModule.forRoot = function (ionicConfig) {
        if (ionicConfig === void 0) { ionicConfig = DEFAULT_BASE_CONFIG; }
        return {
            ngModule: IonicModule,
            providers: __spread(getRootProviders(ionicConfig), [
                // ionic app initializer
                { provide: APP_INITIALIZER, useFactory: baseInitApp, multi: true, deps: [APP_CONFIG_TOKEN, Injector] },
            ]),
        };
    };
    IonicModule.forChild = function (moduleName) {
        return {
            ngModule: IonicModule,
            providers: getChildProviders(moduleName),
        };
    };
    /** @nocollapse */ IonicModule.ɵmod = ɵɵdefineNgModule({ type: IonicModule });
    /** @nocollapse */ IonicModule.ɵinj = ɵɵdefineInjector({ factory: function IonicModule_Factory(t) { return new (t || IonicModule)(ɵɵinject(IonicModule, 12), ɵɵinject(Injector)); }, imports: [[
                HttpClientModule,
                EffectsModule.forRoot(IonicModuleEffects),
            ]] });
    return IonicModule;
}(BaseModule));
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵɵsetNgModuleScope(IonicModule, { imports: [HttpClientModule, EffectsRootModule] }); })();
/*@__PURE__*/ (function () { ɵsetClassMetadata(IonicModule, [{
        type: NgModule,
        args: [{
                imports: [
                    HttpClientModule,
                    EffectsModule.forRoot(IonicModuleEffects),
                ],
            }]
    }], function () { return [{ type: IonicModule, decorators: [{
                type: Optional
            }, {
                type: SkipSelf
            }] }, { type: Injector }]; }, null); })();

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

export { IonicAppActionTypes, IonicModule, IonicModuleEffects, IonicStorageService, IonicUserActionTypes, getChildProviders, getRootProviders, initialIonicAppState as initialAppState, initialIonicState, initialIonicUserState as initialUserState, ionicAppReducers, ionicUserReducers, ionicReducers as reducers };
//# sourceMappingURL=eui-ionic.js.map
