import type { MouseEventHandler } from 'react'
import { Link } from 'react-router'

import type { TUser } from '~/apis/news/get-user'

type TGetPremiumAttribute = {
  isPremium?: boolean
  slug: string
  onClick: MouseEventHandler<HTMLElement>
  userData?: TUser['data']
}

export const getPremiumAttribute = (parameters: TGetPremiumAttribute) => {
  const { isPremium, slug, onClick, userData } = parameters
  if (isPremium && (!userData || userData?.subscribe_plan_code === 'basic')) {
    return {
      onClick,
      to: '',
    }
  }

  return {
    as: Link,
    to: `/detail/${slug}`,
  }
}
