/*! ratio-ui · design system for knowledge sharing · https://github.com/losol/ratio-ui · (c) 2026 Losol AS · MPL-2.0 */
"use client";
import { Mail } from "../../icons/index.js";
import { useEffect, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region src/core/ObfuscatedEmail/ObfuscatedEmail.tsx
/**
* ObfuscatedEmail component that hides email addresses from spam bots
* while maintaining accessibility for real users.
*
* The email is encoded and only decoded client-side with JavaScript,
* making it harder for bots to scrape.
*
* @example
* ```tsx
* <ObfuscatedEmail email="hello@example.com" subject="Contact inquiry" />
* ```
*/
var ObfuscatedEmail = ({ email, className = "", linkClassName = "hover:underline", subject }) => {
	const [decodedEmail, setDecodedEmail] = useState("");
	const [mounted, setMounted] = useState(false);
	useEffect(() => {
		setMounted(true);
		try {
			const decoded = atob(btoa(email));
			setDecodedEmail(decoded);
		} catch {
			setDecodedEmail(email);
		}
	}, [email]);
	if (!mounted || !decodedEmail) return /* @__PURE__ */ jsx("span", {
		className,
		children: /* @__PURE__ */ jsxs("span", {
			className: "inline-flex items-center gap-1",
			children: [/* @__PURE__ */ jsx(Mail, {
				className: "h-4 w-4",
				"aria-hidden": "true"
			}), /* @__PURE__ */ jsx("span", {
				className: "text-(--text-subtle)",
				children: "Email loading..."
			})]
		})
	});
	const mailtoHref = subject ? `mailto:${decodedEmail}?subject=${encodeURIComponent(subject)}` : `mailto:${decodedEmail}`;
	const [localPart, domain] = decodedEmail.split("@");
	return /* @__PURE__ */ jsx("span", {
		className,
		children: /* @__PURE__ */ jsxs("a", {
			href: mailtoHref,
			className: linkClassName,
			onClick: (e) => {
				e.preventDefault();
				window.location.href = mailtoHref;
			},
			children: [
				/* @__PURE__ */ jsx("span", { children: localPart }),
				/* @__PURE__ */ jsx("span", {
					"aria-hidden": "true",
					children: "@"
				}),
				/* @__PURE__ */ jsx("span", {
					className: "sr-only",
					children: "@"
				}),
				/* @__PURE__ */ jsx("span", { children: domain })
			]
		})
	});
};
//#endregion
export { ObfuscatedEmail };

//# sourceMappingURL=ObfuscatedEmail.js.map