import { useState } from "react"
import Taro from '@tarojs/taro'
import { login } from '@/services/person'

export default () => {
  const [person, setPerson] = useState()
  const [peronRoles, setPersonRoles] = useState([])

  const personLogin = (params) => {
    login(params).then((res) => {
      const { person : taPerson, personRoleList, sessionKey } = res;
      setPerson(taPerson);
      setPersonRoles(personRoleList);
      Taro.setStorage({ key: 'sessionKey', data: sessionKey })
    })
  }

  return [person, peronRoles, setPerson, personLogin]
}
