import { ref } from 'vue'

export const usePagination = (defaultPagination) => {
  const mergedDefault = { page: 1, perPage: 10, ...defaultPagination }
  const pagination = ref({ ...mergedDefault })

  const setPagination = (newPagination) => {
    pagination.value = { ...pagination.value, ...newPagination }
  }

  const setPage = (page) => setPagination({ page })

  const reset = () => {
    pagination.value = { ...mergedDefault }
  }

  return {
    pagination,
    setPagination,
    setPage,
    reset,
  }
}

export default usePagination
