import Badge from '@mui/material/Badge'
import IconButton from '@mui/material/IconButton'
import Tooltip from '@mui/material/Tooltip'
import { ShoppingCart } from 'lucide-react'
import type { AuthUser } from '@/shared/model/auth'

type Props = {
  user: AuthUser | null
  cartCount: number
  onNavigate: (to: string) => void
}

export function CartBadge({ user, cartCount, onNavigate }: Props) {
  return (
    <Tooltip title={user ? 'Корзина' : 'Авторизуйтесь для совершения покупок'}>
      <IconButton
        color="inherit"
        sx={{ ml: 1 }}
        onClick={() => {
          if (!user) onNavigate('/auth')
          else onNavigate('/cart')
        }}
        aria-label="Корзина"
      >
        <Badge color="secondary" badgeContent={user ? cartCount : 0} invisible={!user || cartCount === 0}>
          <ShoppingCart />
        </Badge>
      </IconButton>
    </Tooltip>
  )
}
