import { LoginForm } from '@/interface/user'
import router from '@/router'
import { request } from '@/utils/request'
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    token: '',
  }),
  actions: {
    async login(data: LoginForm) {
      const { token } = await request<{ token: string }>({
        url: '/backendApi/login/cashRegisterDoLogin',
        method: 'POST',
        data,
        noAuth: true,
      })
      this.token = token
    },
  },
  getters: {
    getToken: ({ token }) => token,
  },
})
