// 用于新建镜像
export const mirrorNameKey = 'mirror-name';
// 模型部署
export const modelDeploymentInfoKey = 'model-deployment-info';
// 编辑器 url
export const editorUrlKey = 'editor-url';

export const getSessionStorageItem = (key: string, isObject: boolean = false) => {
  const jsonStr = sessionStorage.getItem(key);
  if (!isObject) {
    return jsonStr;
  }
  if (jsonStr) {
    try {
      return JSON.parse(jsonStr);
    } catch (error) {
      return undefined;
    }
  }
  return undefined;
};

export const setSessionStorageItem = (key: string, state?: any, isObject: boolean = false) => {
  if (state) {
    sessionStorage.setItem(key, isObject ? JSON.stringify(state) : state);
  }
};

export const removeSessionStorageItem = (key: string) => {
  sessionStorage.removeItem(key);
};

// 获取之后就删除，多用于上一个页面传递数据到下一个页面
export const getSessionItemThenRemove = (key: string, isObject: boolean = false) => {
  const res = getSessionStorageItem(key, isObject);
  sessionStorage.removeItem(key);
  return res;
};
