import type { ReactNode } from "react"
import { getLocale, getTranslations } from "next-intl/server"
import { formatLongDate } from "@/shared/lib/utils"
import { getGreetingKey } from "@/modules/dashboard/lib/dashboard-utils"

/**
 * 仪表盘问候语头部（共享组件）
 *
 * 教师与学生仪表盘头部 90% 重复，统一抽象为此组件。
 * 通过 `actions` slot 注入角色专属快捷操作。
 */
export async function DashboardGreetingHeader({
  userName,
  actions,
}: {
  userName: string
  actions?: ReactNode
}) {
  const t = await getTranslations("dashboard")
  const locale = await getLocale()
  const today = formatLongDate(new Date(), locale)
  const greetingKey = getGreetingKey(new Date())

  return (
    <div className="flex flex-col justify-between space-y-4 md:flex-row md:items-center md:space-y-0">
      <div>
        <h2 className="text-2xl font-bold tracking-tight">
          {userName ? `${t(`greeting.${greetingKey}`)}，${userName}` : t(`greeting.${greetingKey}`)}
        </h2>
        <p className="text-muted-foreground">{t("greeting.todayIs", { date: today })}</p>
      </div>
      {actions}
    </div>
  )
}
