import { useState, useEffect } from 'react';
import { fetch, apis } from '@/utils/request';

const fetchBrands = fetch(apis.brand.list)

export default function useBrands() {
  const [brands, setBrands] = useState([])

  useEffect(() => {
    const params = { pageSize: 500 }
    fetchBrands({ params }).then((res) => {
      const { records } = res
      setBrands(records || [])
    }).catch((err) => {
      console.error(err)
    })
  }, [])

  return [brands, setBrands]
}
