import {
    defineStore
} from 'pinia';
import {
    ElMessage
} from 'element-plus'

import req from "../request"


export const useAdminStore = defineStore('adminStore', {
    state: () => ({
        adminInfo: {},
        adminAccount: [{
            loginId: "test1234",
            loginPwd: "test1234"
        }]
    }),
    getters: {
        async getAdminInfo() {
            return this.getAdminInfo
        }
    },
    actions: {
        addAdminAccount(loginInfo) {
            this.adminAccount.push({
                loginId: loginInfo.loginId,
                loginPwd: loginInfo.loginPwd,
            })
            ElMessage({
                message: "注册快递员账号成功",
                type: "success"
            })

        },
        loginAdmin(loginInfo) {
            let hasAccount = false
            this.adminAccount.forEach((item, index) => {
                if (item.loginId === loginInfo.loginId && item.loginPwd === loginInfo.loginPwd) {
                    this.adminInfo = this.adminAccount[index]
                    hasAccount = true;
                }
            })
            localStorage.setItem("isAdmin", true)
            return hasAccount
        }
    }
});