import axios from '../plugins/axios'
import { defineStore } from 'pinia'

export const useAdminsStore = defineStore('admins', {

    state: () => ({
        items: [],
        fetching: true,
        total: 0,
        token: null,
        permissions: []
    }),
    getters: {
        isLoggedIn: (state) => !!state.token
    },
    actions:{
        async login(number) {
            const { status, data, error } = await axios.post('/auth/login', {
                phone: number.value,
                type: 1
            })
              console.log('state',data);
            if (status == 200) {
                // this.token = data.accessToken
                // this.permissions = data.permissions
              //  console.log(data);
                
                return { status, data, error }
            }

        },   async sendOtp(number, code) {
            const { status, data, error } = await axios.post('/auth/login-step-two', {
                phone: number.value,
                code: code.value
            })

            console.log(data);
            if (status == 200) {
                console.log('first', this.token);
                 this.token = data.token
                // this.permissions = data.permissions
                console.log('two', this.token);
                return { status, data, error }
            }

        },
    }


})