/**
 * Copyright 2024 Phenix Real Time Solutions, Inc. Confidential and Proprietary. All Rights Reserved.
 */
import IUserDataStore from './IUserDataStore';

export default class LocalStorageUserStore implements IUserDataStore {
  public async get(key: string, defaultValue: string): Promise<string> {
    return window.localStorage.getItem(key) || defaultValue;
  }

  public async set(key: string, value: string): Promise<void> {
    return window.localStorage.setItem(key, value);
  }

  public static browserSupported(): boolean {
    try {
      if (!window.localStorage) {
        return false;
      }

      const name = '__enableability_test__';

      localStorage.setItem(name, 'Evaluating whether local storage is enabled and accessible');
      localStorage.removeItem(name);

      return true;
    } catch (ignoredEx) {
      return false;
    }
  }
}
