import { useUiTranslation as e } from "../../../../i18n/useUiTranslation.js";
import { MarkdownCopySuccessSvg as t } from "../../../../icons/markdown/MarkdownCopySuccessSvg.js";
import { MarkdownCopySvg as n } from "../../../../icons/markdown/MarkdownCopySvg.js";
import { copyButton as r, icon as i, label as a } from "./MarkdownCodeCopyButton.css.js";
import { useCallback as o, useEffect as s, useRef as c, useState as l } from "react";
import { jsx as u, jsxs as d } from "react/jsx-runtime";
//#region src/atomic/molecules/markdown/components/MarkdownCodeCopyButton.tsx
var f = ({ code: f }) => {
	let { t: p } = e(), [m, h] = l(!1), g = c(null);
	s(() => () => {
		g.current != null && window.clearTimeout(g.current);
	}, []);
	let _ = o(async () => {
		try {
			let e;
			if (typeof navigator < "u" && (e = navigator.clipboard), e != null && typeof e.writeText == "function") await e.writeText(f);
			else {
				let e = document.createElement("textarea");
				e.value = f, e.setAttribute("readonly", ""), e.style.position = "absolute", e.style.left = "-9999px", document.body.appendChild(e), e.select(), document.execCommand("copy"), document.body.removeChild(e);
			}
			h(!0), g.current != null && window.clearTimeout(g.current), g.current = window.setTimeout(() => {
				h(!1), g.current = null;
			}, 2e3);
		} catch {}
	}, [f]), v = p("markdown.code.copyTitle");
	m && (v = p("markdown.code.copiedTitle"));
	let y = /* @__PURE__ */ u(n, { className: i });
	m && (y = /* @__PURE__ */ u(t, { className: i }));
	let b = p("markdown.code.copy");
	return m && (b = p("markdown.code.copied")), /* @__PURE__ */ d("button", {
		className: r,
		onClick: () => {
			_().catch(() => {});
		},
		title: v,
		type: "button",
		children: [y, /* @__PURE__ */ u("span", {
			className: a,
			children: b
		})]
	});
};
//#endregion
export { f as MarkdownCodeCopyButton };

//# sourceMappingURL=MarkdownCodeCopyButton.js.map