'use client'

import React from 'react'

import { Button } from '@/components/ui/button'

type AffiliateUnlockButtonProps = {
  url?: string | null
  label?: string | null
  onUnlock?: () => void
}

export const AffiliateUnlockButton: React.FC<AffiliateUnlockButtonProps> = ({
  url,
  label,
  onUnlock,
}) => {
  if (!url) return null

  const handleClick = () => {
    window.open(url, '_blank', 'noopener,noreferrer')
    onUnlock?.()
  }

  return (
    <Button onClick={handleClick} size="lg">
      {label || 'Mở khóa chương'}
    </Button>
  )
}
