import { defineStore, storeToRefs } from 'pinia'
import { useUserStore } from './user'
import { getParentBindChildApi } from '@/api'
import { ref } from 'vue'

export const useChildStore = defineStore('child', () => {
  const children = ref([] as any)
  const { userInfo } = storeToRefs(useUserStore())

  async function getChildren() {
    children.value =
      (
        await getParentBindChildApi({
          parentId: userInfo.value?.id,
        })
      )?.rows || []
    return children.value
  }
  return { children, getChildren }
})
