2025-12-08 14:26:01 +09:00
|
|
|
"use client"
|
|
|
|
|
|
|
|
|
|
import { Coffee, X } from "lucide-react"
|
2025-12-08 20:26:51 +09:00
|
|
|
import Link from "next/link"
|
2025-12-08 14:26:01 +09:00
|
|
|
import type React from "react"
|
|
|
|
|
import { FaGithub } from "react-icons/fa"
|
2025-12-20 20:18:54 +05:30
|
|
|
import { useDictionary } from "@/hooks/use-dictionary"
|
|
|
|
|
import { formatMessage } from "@/lib/i18n/utils"
|
2025-12-08 14:26:01 +09:00
|
|
|
|
|
|
|
|
interface QuotaLimitToastProps {
|
2025-12-08 18:56:34 +09:00
|
|
|
type?: "request" | "token"
|
2025-12-08 14:26:01 +09:00
|
|
|
used: number
|
|
|
|
|
limit: number
|
|
|
|
|
onDismiss: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function QuotaLimitToast({
|
2025-12-08 18:56:34 +09:00
|
|
|
type = "request",
|
2025-12-08 14:26:01 +09:00
|
|
|
used,
|
|
|
|
|
limit,
|
|
|
|
|
onDismiss,
|
|
|
|
|
}: QuotaLimitToastProps) {
|
2025-12-20 20:18:54 +05:30
|
|
|
const dict = useDictionary()
|
2025-12-08 18:56:34 +09:00
|
|
|
const isTokenLimit = type === "token"
|
|
|
|
|
const formatNumber = (n: number) =>
|
|
|
|
|
n >= 1000 ? `${(n / 1000).toFixed(1)}k` : n.toString()
|
2025-12-20 20:18:54 +05:30
|
|
|
|
2025-12-08 14:26:01 +09:00
|
|
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
|
|
|
if (e.key === "Escape") {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
onDismiss()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
role="alert"
|
|
|
|
|
aria-live="polite"
|
|
|
|
|
tabIndex={0}
|
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
|
className="relative w-[400px] overflow-hidden rounded-xl border border-border/50 bg-card p-5 shadow-soft animate-message-in"
|
|
|
|
|
>
|
|
|
|
|
{/* Close button */}
|
|
|
|
|
<button
|
|
|
|
|
onClick={onDismiss}
|
|
|
|
|
className="absolute right-3 top-3 p-1.5 rounded-full text-muted-foreground/60 hover:text-foreground hover:bg-muted transition-colors"
|
|
|
|
|
aria-label="Dismiss"
|
|
|
|
|
>
|
|
|
|
|
<X className="w-4 h-4" />
|
|
|
|
|
</button>
|
|
|
|
|
{/* Title row with icon */}
|
|
|
|
|
<div className="flex items-center gap-2.5 mb-3 pr-6">
|
|
|
|
|
<div className="flex-shrink-0 w-8 h-8 rounded-lg bg-accent flex items-center justify-center">
|
|
|
|
|
<Coffee
|
|
|
|
|
className="w-4 h-4 text-accent-foreground"
|
|
|
|
|
strokeWidth={2}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<h3 className="font-semibold text-foreground text-sm">
|
2025-12-08 18:56:34 +09:00
|
|
|
{isTokenLimit
|
2025-12-20 20:18:54 +05:30
|
|
|
? dict.quota.tokenLimit
|
|
|
|
|
: dict.quota.dailyLimit}
|
2025-12-08 14:26:01 +09:00
|
|
|
</h3>
|
|
|
|
|
<span className="px-2 py-0.5 text-xs font-medium rounded-md bg-muted text-muted-foreground">
|
2025-12-20 20:18:54 +05:30
|
|
|
{formatMessage(dict.quota.usedOf, {
|
|
|
|
|
used: formatNumber(used),
|
|
|
|
|
limit: formatNumber(limit),
|
|
|
|
|
})}
|
2025-12-08 14:26:01 +09:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{/* Message */}
|
|
|
|
|
<div className="text-sm text-muted-foreground leading-relaxed mb-4 space-y-2">
|
|
|
|
|
<p>
|
2025-12-20 20:18:54 +05:30
|
|
|
{isTokenLimit
|
|
|
|
|
? dict.quota.messageToken
|
|
|
|
|
: dict.quota.messageApi}
|
2025-12-08 14:26:01 +09:00
|
|
|
</p>
|
2025-12-20 20:18:54 +05:30
|
|
|
<p dangerouslySetInnerHTML={{ __html: dict.quota.tip }} />
|
|
|
|
|
<p>{dict.quota.reset}</p>
|
|
|
|
|
</div>{" "}
|
2025-12-08 14:26:01 +09:00
|
|
|
{/* Action buttons */}
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<a
|
|
|
|
|
href="https://github.com/DayuanJiang/next-ai-draw-io"
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-lg bg-primary text-primary-foreground hover:bg-primary/90 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<FaGithub className="w-3.5 h-3.5" />
|
2025-12-20 20:18:54 +05:30
|
|
|
{dict.quota.selfHost}
|
2025-12-08 14:26:01 +09:00
|
|
|
</a>
|
|
|
|
|
<a
|
|
|
|
|
href="https://github.com/sponsors/DayuanJiang"
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-lg border border-border text-foreground hover:bg-muted transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<Coffee className="w-3.5 h-3.5" />
|
2025-12-20 20:18:54 +05:30
|
|
|
{dict.quota.sponsor}
|
2025-12-08 14:26:01 +09:00
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|