const defaultHead = require(`@/assets/img/default-head.jpg`);
const phoneHead = require(`@/assets/img/phone-head.png`);

const getters = {
  nowDate(state) {
    return state.nowDate;
  },
  status(state) {
    return state.status;
  },
  type(state) {
    return state.type;
  },
  welcomeInfo(state) {
    return state.welcomeInfo;
  },
  channelInfo(state) {
    const info = JSON.parse(JSON.stringify(state.channelInfo || {}));
    if (!info.defaultUserAva) {
      info.defaultUserAva = defaultHead;
    }
    if (!info.chatAdminAvaUrl) {
      info.chatAdminAvaUrl = defaultHead;
    }
    info.defaultPhoneHeadAva = phoneHead;
    return info;
  },
  channelConfig(state) {
    return state.channelConfig;
  },
  encrypt(state) {
    return state.encrypt;
  },
  white(state) {
    return state.white;
  },
  menuList(state) {
    return state.menuList;
  },
  menuListPc(state) {
    return state.menuList.filter(obj => {
      return (
        obj.menuType === 'imagetext' ||
        obj.menuType === 'playlists' ||
        obj.menuType === 'report' ||
        obj.menuType === 'iframeLine'
      );
    });
  },
  advertTop(state) {
    return state.advertTop;
  },
  advertMiddle(state) {
    return state.advertMiddle;
  },
  advertText(state) {
    return state.advertText;
  },
  playerInfo(state) {
    return state.playerInfo;
  },
  userInfo(state) {
    const info = JSON.parse(JSON.stringify(state.userInfo || {}));
    if (info.id && !info.userHeadImg) {
      info.userHeadImg = phoneHead;
    }
    return info;
  },
  showRed(state) {
    return state.showRed;
  },
  showRedInfo(state) {
    return state.showRedInfo;
  },
  onlySeeRed(state) {
    return state.onlySeeRed;
  },
  jumpUrls(state) {
    if (process.client) {
      const info = state.channelInfo;
      const uin = info.uin;
      const id = info.id;
      const backUrl = encodeURIComponent(window.location.href);
      const origin =
        process.env.NODE_ENV === 'development'
          ? `http://${window.location.hostname}:3004`
          : window.location.origin;
      return {
        login_noback: `${origin}/my/login?uin=${uin}&backUrl=`,
        login: `${origin}/my/login?uin=${uin}&backUrl=${backUrl}`,
        login_binding: `${origin}/my/login/binding?uin=${uin}&backUrl=${backUrl}`,
        center: `${origin}/my/center?uin=${uin}&backUrl=${backUrl}`,
        center_wallet: `${origin}/my/center/wallet?uin=${uin}&backUrl=${backUrl}`,
        pay_redPacket: `${origin}/my/pay/redPacket?uin=${uin}&id=${id}&backUrl=${backUrl}`,
        auth_pay: `${origin}/my/auth/pay?uin=${uin}&id=${id}&backUrl=${backUrl}`,
        auth_password: `${origin}/my/auth/password?uin=${uin}&id=${id}&backUrl=${backUrl}`
      };
    }
  }
};
export default getters;
