"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const storage_1 = require("../../../../../client/util/web/storage");
const MethodNotImplementedError_1 = require("../../../../../exception/MethodNotImplementedError");
const Primitive_1 = require("../../../../../Primitive");
const _ids_1 = require("../../../../_ids");
class SessionStorage extends Primitive_1.Primitive {
    constructor(system) {
        super({
            i: [],
            o: [],
        }, {}, system, _ids_1.ID_SESSION_STORAGE);
        this._checkAPI = () => {
            if (!sessionStorage) {
                throw new Error('session Storage API not implemented');
            }
        };
    }
    read() {
        return __awaiter(this, void 0, void 0, function* () {
            this._checkAPI();
            const obj = (0, storage_1.getAllSessionStorage)();
            return obj;
        });
    }
    write(data) {
        return __awaiter(this, void 0, void 0, function* () {
            this._checkAPI();
            throw new MethodNotImplementedError_1.MethodNotImplementedError();
        });
    }
    get(name) {
        return __awaiter(this, void 0, void 0, function* () {
            this._checkAPI();
            const value = sessionStorage.getItem(name);
            if (value === null) {
                throw new Error('item not found');
            }
            else {
                return value;
            }
        });
    }
    set(name, data) {
        return __awaiter(this, void 0, void 0, function* () {
            this._checkAPI();
            localStorage.setItem(name, data);
        });
    }
    delete(name) {
        return __awaiter(this, void 0, void 0, function* () {
            this._checkAPI();
            sessionStorage.removeItem(name);
        });
    }
    deepSet(path, data) {
        throw new MethodNotImplementedError_1.MethodNotImplementedError();
    }
    deepGet(path) {
        throw new MethodNotImplementedError_1.MethodNotImplementedError();
    }
    deepDelete(path) {
        throw new MethodNotImplementedError_1.MethodNotImplementedError();
    }
    subscribe(path, key, listener) {
        throw new MethodNotImplementedError_1.MethodNotImplementedError();
    }
    keys() {
        return __awaiter(this, void 0, void 0, function* () {
            const keys = (0, storage_1.getStorageKeys)(sessionStorage);
            return keys;
        });
    }
    hasKey(name) {
        return __awaiter(this, void 0, void 0, function* () {
            const has = (0, storage_1.storageHasKey)(sessionStorage, name);
            return has;
        });
    }
}
exports.default = SessionStorage;
//# sourceMappingURL=index.js.map