import { AsyncStorageService, LogService, BaseModuleEffects, initialBaseAppState, baseAppReducers, initialBaseUserState, baseUserReducers, baseReducers, initialBaseState, DEFAULT_BASE_CONFIG, getBaseRootProviders, BASE_NAME_TOKEN, getBaseChildProviders, BaseModule, baseInitApp, APP_CONFIG_TOKEN } 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 { ɵɵ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
 */
class IonicStorageService extends AsyncStorageService {
    constructor(storage, log) {
        super();
        this.storage = storage;
        this.log = log;
    }
    /**
     * the name of the storage service
     */
    name() {
        return IonicStorageService.NAME;
    }
    /**
     * reflects the readiness of the storage
     * @returns one time emission Observable<void>
     */
    ready() {
        return from(this.storage.ready())
            .pipe(take(1), tap(() => {
        }, 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
     */
    get(key) {
        return from(this.storage.get(key))
            .pipe(take(1), tap(() => {
        }, 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
     */
    set(key, value) {
        return from(this.storage.set(key, value))
            .pipe(take(1), tap(() => {
        }, 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
     */
    remove(key) {
        return from(this.storage.remove(key))
            .pipe(take(1), tap(() => {
        }, 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 });
/*@__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 = {}));

const IonicModuleEffects = [...BaseModuleEffects];

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

const actionToReducerMap = {};
const ionicAppReducers = (state = initialIonicAppState, action) => {
    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);
};

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

const actionToReducerMap$1 = {};
const ionicUserReducers = (state = initialIonicUserState, action) => {
    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);
};

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

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

function getRootProviders(ionicConfig = DEFAULT_BASE_CONFIG) {
    return [
        ...getBaseRootProviders(ionicConfig),
        // ionic config
        { provide: BASE_NAME_TOKEN, useValue: 'eui-ionic' },
        // storage services
        IonicStorageService,
        { provide: AsyncStorageService, useExisting: IonicStorageService },
    ];
}
function getChildProviders(moduleName) {
    return [
        ...getBaseChildProviders(moduleName),
    ];
}
class IonicModule extends BaseModule {
    constructor(parentModule, injector) {
        super(parentModule, injector);
    }
    static forRoot(ionicConfig = DEFAULT_BASE_CONFIG) {
        return {
            ngModule: IonicModule,
            providers: [
                ...getRootProviders(ionicConfig),
                // ionic app initializer
                { provide: APP_INITIALIZER, useFactory: baseInitApp, multi: true, deps: [APP_CONFIG_TOKEN, Injector] },
            ],
        };
    }
    static forChild(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),
        ]] });
(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
