import moment from 'moment-mini';
import lodash from 'lodash';
import i18n from '@/vue/i18n';
import { getKeyProductClone, getGptWriterUserPlanAllow } from './utils';

export const getters = {
  /** @param {StateUser} state */
  getToken(state) {
    return !!state.token;
  },

  /** @param {StateUser} state */
  getIsAuthed(state) {
    return !!(state.id && state.token);
  },

  /** @param {StateUser} state */
  getUserPlan(state) {
    return state.extensionPlan;
  },

  /** @param {StateUser} state */
  getTimeExpried(state) {
    return state.userData && state.userData.timeExpired
      ? moment(state.userData.timeExpired).format('DD/MM/YYYY').toString()
      : '';
  },

  /** @param {StateUser} state */
  getUsername(state) {
    return state.username;
  },

  /** @param {StateUser} state */
  getScoreClone(state) {
    return (platform) => {
      return lodash.get(state, getKeyProductClone(platform), 0);
    };
  },

  /** @param {StateUser} state */
  getPassword(state) {
    return state.password;
  },

  /** @param {StateUser} state */
  getUserData(state) {
    return state.userData;
  },

  /** @param {StateUser} state */
  getUserId(state) {
    return state.id;
  },

  /** @param {StateUser} state */
  getIsVipPlus(state) {
    return state.extensionPlan === 'VipPlus';
  },

  /** @param {StateUser} state */
  getIsPaidVip(state) {
    return ['Vip', 'VipPlus'].includes(state.extensionPlan);
  },

  /** @param {StateUser} state */
  getIsPaidPlan(state) {
    return state.extensionPlan !== 'Free';
  },

  /** @param {StateUser} state */
  getUsageGptWriter(state) {
    const allow = getGptWriterUserPlanAllow(state.extensionPlan);
    return {
      allow,
      text: !allow ? i18n.t('AI_GPT_FUNCTION_REQURIED_HIGH_PLAN') : '',
    };
  },
};
