import { FLAGS, useFeatureIsOn } from '@komi-app/flags-sdk'

export const useDigitalProductFeatures = (options?: {
  checkTier?: boolean
}) => {
  const { checkTier = false } = options || {}

  const topTierFeature = useFeatureIsOn(FLAGS.TIER_CREATOR_TOP)
  const isTopTier = checkTier ? topTierFeature : false

  const isFreeDownloadOn = useFeatureIsOn(FLAGS.FREE_DOWNLOADS_TALENT)
  const isPaidDownloadOn =
    useFeatureIsOn(FLAGS.PAID_DIGITAL_PRODUCT) && !isTopTier
  const isOneToOneEnabled =
    useFeatureIsOn(FLAGS.ONE_TO_ONE_SESSION_PRODUCT) && isPaidDownloadOn
  const isCourseEnabled =
    useFeatureIsOn(FLAGS.COURSE_PRODUCT) && isPaidDownloadOn

  const useNewForms = isOneToOneEnabled || isCourseEnabled

  return {
    isFreeDownloadOn,
    isPaidDownloadOn,
    isOneToOneEnabled,
    isCourseEnabled,
    useNewForms
  }
}
