export const fetchCourseSubtitleUrl = async (course: resp.gen.CourseGenItem) => {
  const loginState = useLoginState()

  try {
    const subtitleRecord = await useFetchWrapped<
      {
        page?: number
        perpage?: number
        task_id: string
      } & AuthedRequest,
      BaseResponse<PagedData<resp.gen.CourseSubtitleCreate>>
    >('App.Digital_VideoSubtitle.GetList', {
      token: loginState.token!,
      user_id: loginState.user.id,
      task_id: course.task_id,
      page: 1,
      perpage: 1,
    })

    if (subtitleRecord.data.items.length !== 1) {
      return course.subtitle_url
    }

    return subtitleRecord.data.items[0].url
  } catch (err) {
    return course.subtitle_url
  }
}