import { trpc } from '@/lib/trpc'
import { useMembersFilterStore } from '@/store/members.store'

export function useMembersList() {
  const search = useMembersFilterStore((s) => s.search)
  const nurAusbildungsbetriebe = useMembersFilterStore((s) => s.nurAusbildungsbetriebe)

  const { data, isLoading, refetch, isFetching } = trpc.members.list.useQuery({
    search: search || undefined,
    status: 'aktiv',
    ausbildungsbetrieb: nurAusbildungsbetriebe || undefined,
  })

  return {
    data: data ?? [],
    isLoading,
    refetch,
    isRefetching: isFetching,
  }
}

export function useMemberDetail(id: string) {
  const { data, isLoading } = trpc.members.byId.useQuery({ id })
  return { data: data ?? null, isLoading }
}
