import {SocialState} from '@/types/views/social.interface';
import {GetterTree, MutationTree, ActionTree} from 'vuex';

const state: SocialState = {
    author: '三毛',
    isfund: false,
    serviceChargeData: [
        {
            monthly: '月付：100元/月',
            seasonal: '季付：270元/季',
            halfYearly: '半年付：480元/半年',
            yearly: '年付：600元/年',
        },
        {
            monthly: '月付：150元/月',
            seasonal: '季付：405元/季',
            halfYearly: '半年付：720元/半年',
            yearly: '年付：900元/年',
        }
    ],
};

// 强制使用getter获取state
const getters: GetterTree<SocialState, any> = {
    author: (state: SocialState) => state.author,
    serviceChargeData: (state: SocialState) => state.serviceChargeData,
    service: (state: SocialState) => {
        return state.isfund ? state.serviceChargeData[1] : state.serviceChargeData[0];
    }
};

// 更改state
const mutations: MutationTree<SocialState> = {
    // 更新state都用该方法
    update(state: SocialState, data: SocialState) {
        for (const key in data) {
            if (!data.hasOwnProperty(key)) {
                return;
            }
            // @ts-ignore
            state[key] = data[key];
        }
    }
};

const actions: ActionTree<SocialState, any> = {
    updateAsyn({commit, state: SocialState}, data: SocialState) {
        commit('update', data);
    },
    // GET_DATA_ASYN({ commit, state: LoginState }) {
    //   Social.getData()
    // }
};

export default {
    state,
    getters,
    mutations,
    actions
};

