"use client"

import { Brush, Flame, Trophy } from "lucide-react"
import Link from "@/components/common/versioned-link"
import { firstName, useUserProfile } from "@/hooks/use-user-profile"
import { StreakStateDto } from "@/lib/dto/practice.dto"
import { faNumber } from "@/lib/helpers/format.helper"
import NotificationBell from "@/components/notification/notification-bell.component"
import { cn } from "@/lib/utils"
import { jalaliDay } from "@/lib/helpers/date.helper"

const todayLabel = () => jalaliDay()

export default function HomeTopBar({ streak }: { streak?: StreakStateDto | null }) {
  const profile = useUserProfile()
  const name = firstName(profile)

  return (
    <header className="sticky top-0 z-20 shrink-0 h-16 px-4 flex items-center bg-background/95 backdrop-blur border-b border-line/60">
      <Link
        href="/profile"
        aria-label="پروفایل"
        className="w-11 h-11 rounded-full bg-sienna-soft text-sienna-dark grid place-items-center text-title-3 font-extrabold shrink-0"
      >
        {name ? name.charAt(0) : <Brush className="w-5 h-5" aria-hidden="true" />}
      </Link>

      <div className="flex-1 min-w-0 mr-3">
        <p className="text-caption text-ink-soft truncate">{todayLabel()}</p>
        <p className="text-title-3 font-extrabold truncate">{name ? `سلام ${name}!` : "سلام!"}</p>
      </div>

      {streak ? (
        <div className="flex items-center gap-1.5 shrink-0">
          <Link
            href="/practice"
            aria-label={`${faNumber(streak.current)} روز پیاپی`}
            className={cn(
              "h-8 px-2.5 rounded-full flex items-center gap-1 text-caption font-extrabold",
              streak.practised_today ? "bg-gradient-to-l from-sienna to-ochre text-canvas" : "bg-paper-2 text-ink-soft"
            )}
          >
            <Flame className="w-4 h-4" aria-hidden="true" />
            {faNumber(streak.current)}
          </Link>
          <Link href="/practice" aria-label={`${faNumber(streak.xp?.week)} امتیاز این هفته`} className="h-8 px-2.5 rounded-full flex items-center gap-1 text-caption font-extrabold bg-ultra-soft text-ultra">
            <Trophy className="w-4 h-4" aria-hidden="true" />
            <span dir="ltr">{faNumber(streak.xp?.week)} XP</span>
          </Link>
        </div>
      ) : (
        <span className="font-brand text-title-1 text-ink leading-[1.9] shrink-0" aria-label="رنگوک">رنگوک</span>
      )}

      <span className="mr-1.5">
        <NotificationBell />
      </span>
    </header>
  )
}
