import { MutationTree } from 'vuex'
import { UserState } from './state'
import { UserMutationTypes } from './mutation-types'
import Cookies from 'js-cookie'
import Keys from '@/constant/key'
import { setProjectId } from '@/utils/cookies'

export type Mutations<S = UserState> = {
  [UserMutationTypes.SET_TOKEN](state: S, token: string): void
  [UserMutationTypes.SET_USER_NAME](state: S, userName: string): void
  [UserMutationTypes.SET_USER_ID](state: S, userId: string): void
  [UserMutationTypes.SET_USER_PHONE](state: S, userPhone: number): void
  [UserMutationTypes.SET_PROJECT_ID](state: S, projectId: string): void
  [UserMutationTypes.SET_COMPANY_ID](state: S, companyId: string): void
  [UserMutationTypes.SET_USER_MAC](state: S, companyId: string): void,
  [UserMutationTypes.SET_REMOTECONTROL](state: S, remoteControl: boolean): void
}

export const mutations: MutationTree<UserState> & Mutations = {
  [UserMutationTypes.SET_TOKEN](state: UserState, token: string) {
    state.token = token
  },
  [UserMutationTypes.SET_USER_MAC](state: UserState, mac: string) {
    state.mac = mac
  },

  [UserMutationTypes.SET_USER_NAME](state: UserState, userName: string) {
    state.userName = userName
  },

  [UserMutationTypes.SET_USER_ID](state: UserState, userId: string) {
    state.userId = userId
  },
  [UserMutationTypes.SET_USER_PHONE](state: UserState, userPhone: number) {
    state.userPhone = userPhone
  },
  [UserMutationTypes.SET_PROJECT_ID](state: UserState, projectId: string) {
    // Cookies.set(Keys.projectId, projectId)
    setProjectId(projectId)
    // debugger
    state.projectId = projectId
  },
  [UserMutationTypes.SET_COMPANY_ID](state: UserState, companyId: string) {
    state.companyId = companyId
  },
  [UserMutationTypes.SET_REMOTECONTROL](state: UserState, remoteControl: boolean) {
    state.remoteControl = remoteControl
  }

}
