export class InstanceStorage {
  constructor(prefix, logger) {
    this.data = {};
    // private getData = () => JSON.parse(window.sessionStorage.getItem(this.prefix) || '{}');
    this.getData = () => this.data;
    // private setData = (data: any) => window.sessionStorage.setItem(this.prefix, JSON.stringify(data));
    this.setData = (data) => this.data = data;
    this.prefix = prefix;
    this.logger = logger.new('InstanceStorage').setColor('sun');
  }
  save(key, value) {
    this.logger.debugGroup('save', { key, value, data: this.getData() });
    const data = this.getData();
    data[key] = value;
    this.setData(data);
  }
  get(key) {
    this.logger.debugGroup('get', { key, value: this.getData()[key], data: this.getData() });
    return this.getData()[key];
  }
  remove(key) {
    this.logger.debugGroup('remove', { key, data: this.getData() });
    const data = this.getData();
    delete data[key];
    this.setData(data);
  }
  clear() {
    this.logger.debugGroup('clear', { data: this.getData() });
    this.setData({});
  }
  getAll() {
    this.logger.debugGroup('getAll', { data: this.getData() });
    return this.getData();
  }
}
