import { LatLng } from 'leaflet'

import { Trashbox, isTrashboxResponse } from '../../api/trashbox/types'
import useFetch, { UseFetchReturn } from '../useFetch'

import { Category } from '../../assets/category'
import { composeTrashboxURL, processTrashbox } from '../../api/trashbox'

const useTrashboxes = (position: LatLng, category: Category): UseFetchReturn<Trashbox[]> => (
    useFetch(
        composeTrashboxURL(position, category),
        'GET',
        true,
        isTrashboxResponse,
        processTrashbox,
        [],
    )
)

export default useTrashboxes
