import { computed } from "vue";
import { useStore } from "vuex";
import { useRoute, useRouter } from "vue-router";
/**
 * 获取用户会员到期时间
 */
export const useExpireTime = () => {
  const store = useStore();
  const expireTime = computed(() => store.getters.getUserData.expireTime);
  return {
    expireTime,
  };
};

export const useOpenIdIsZhangbing = () => {
  const store = useStore();
  const openid = computed(() => store.getters.getUserData.openid);
  const isZhangbing = openid.value === "ovKTX50v7OAEPI_ERofpUvrNQCJU";
  return {
    isZhangbing,
  };
};

export const useSound = () => {};

/**
 * 路由转发汇总class模式书写,需要注意this指向
 * @returns
 */
export class RouterBus {
  router;
  route;
  constructor() {
    this.router = useRouter();
    this.route = useRoute();
  }
  /**
   * 会员购买页
   */
  goBuyVip = () => {
    this.router.push("/buyVip");
  };
  /**
   * 分成提现页
   */
  goCashOut = () => {
    this.router.push("/cashOut");
  };
  /**
   * 我的下级页
   */
  goMyBranch = () => {
    this.router.push("/myBranch");
  };
  /**
   * 模拟考试页
   */
  goMockTest = () => {
    this.router.push({ path: "/mockTest", query: this.route.query });
  };
}

// function deepClone<T>(target: T, hash = new Map()): T {
//   //地址存在则说明存在循环引用,直接返回新构造的引用地址
//   if (hash.has(target)) return hash.get(target);
//   //按类型处理数据
//   switch (Object.prototype.toString.apply(target).slice(8, -1)) {
//     case "Object": {
//       const result: T = Object.assign({}, target);
//       hash.set(target, result);
//       for (let key in target) {
//         result[key] = deepClone(target[key], hash);
//       }
//       return result;
//     }
//     case "Array": {
//       const result: T = Object.assign([], target);
//       hash.set(target, result);
//       for (let key in target) {
//         result[key] = deepClone(target[key], hash);
//       }
//       return result;
//     }
//     case "Map": {
//       const result = new Map();
//       hash.set(target, result);
//       target.forEach((value, key) => {
//         let v: any, k: any;
//         hash.set(value, v);
//         hash.set(key, k);
//       });
//       return result;
//     }
//     default:
//       return target;
//   }
// }

// let a = { a: 1, b: { a: 1 }, c: [{}, 2, 3] };
// a.b = a;
// a.c[1] = a;
// let b = deepClone(a);
// a.c[2] = 10;
// a.a = 22;
// console.log({ a, b });
