import { useMemo } from 'react'

import type { PlaylistOption } from 'features/MatchPage/types'
import type { MatchInfo } from 'requests/getMatchInfo'

import { buildChapters } from '../helpers'

type Args = {
  profile: MatchInfo,
  selectedPlaylist?: PlaylistOption,
  url: string,
}

export const useChapters = ({
  profile,
  selectedPlaylist,
  url,
}: Args) => {
  const chapters = useMemo(
    () => buildChapters({
      profile,
      selectedPlaylist,
      url,
    }),
    [
      profile,
      selectedPlaylist,
      url,
    ],
  )

  return { chapters }
}
