"use client";

export default function QrCodeCard({ path, label }: { path: string; label?: string }) {
  const src = `/api/qr?path=${encodeURIComponent(path)}`;

  return (
    <div className="card p-4 text-center inline-block">
      <img src={src} alt={`QR code for ${path}`} className="w-32 h-32 mx-auto rounded-md bg-white p-1" />
      <p className="text-xs text-neutral-500 mt-2 max-w-[9rem] truncate mx-auto">{label || path}</p>
      <a href={src} download={`qr-${path.replace(/\//g, "-").replace(/^-/, "") || "page"}.png`} className="btn-secondary inline-block px-3 py-1.5 text-xs mt-2">
        ⬇ Download QR
      </a>
    </div>
  );
}
