import {Button} from '@/components/ui/button'
import {type ProfileDetail} from '@/stores/profile'

// the friendship call-to-action for the profile header; hidden for the
// viewer's own profile and existing friends
export function FriendButton({
  status,
  busy,
  onAddFriend,
}: {
  status: ProfileDetail['friendshipStatus']
  busy: boolean
  onAddFriend: () => void
}) {
  // self/friends have no cta; blocked is handled by the profile header's
  // dedicated unblock affordance
  if (
    status === 'self' ||
    status === 'friends' ||
    status === 'blocked'
  )
    return null

  if (status === 'pending_outgoing')
    return (
      <Button
        label="Requested"
        color="secondary"
        size="small"
        disabled
      />
    )

  const label =
    status === 'pending_incoming' ? 'Accept request' : 'Add friend'

  return (
    <Button
      label={busy ? 'Sending…' : label}
      color="primary"
      size="small"
      disabled={busy}
      onPress={onAddFriend}
    />
  )
}
