import { useMemo } from 'react'

import sumBy from 'lodash/sumBy'

import type { Chapters } from '../types'

export const useDuration = (chapters: Chapters) => (
  useMemo(() => sumBy(chapters, 'duration'), [chapters])
)
