import { State } from "./_type";
import { IUser } from "#/api";

/**
 * TODO: 待优化
 * json字符串格式化
 */
String.prototype.parse = function<T>(this: string): T | null {
  let result: T | null = null;
  if (this) result = JSON.parse(this);
  return result;
};

const store = localStorage;

const state: State = {
  store: store,
  pageTitle: "精准投放后台",
  roles: [],
  routes: [],
  addRoutes: [],
  user: store.getItem("user")?.parse<IUser>() ?? {},
  officials: [],
  platforms: [],
  selectTime:[],
  setTemStepOne:{},
  collapsed:
    store.getItem("collapsed") && store.getItem("collapsed") === "true"
      ? true
      : false,
};

export default state;
