import { cx as e } from "../../../theme/tools.js";
import { Button as t } from "../../../atomic/atoms/button/Button.js";
import { copyWithExecCommand as n } from "../../shared/copyWithExecCommand.js";
import { feedback as r, root as i, value as a, valueNoTruncate as o } from "./copyableText.css.js";
import { useCallback as s, useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
import { jsx as f, jsxs as p } from "react/jsx-runtime";
import { useTranslation as m } from "react-i18next";
//#region src/backoffice/atoms/copyable_text/CopyableText.tsx
var h = ({ value: h, copyValue: g, className: _, truncate: v = !0, copyLabel: y, copiedLabel: b }) => {
	let { t: x } = m("ui", { useSuspense: !1 }), [S, C] = d(!1), w = u(null), T = y ?? x("backoffice.copyableText.copy", { defaultValue: "Copy" }), E = b ?? x("backoffice.copyableText.copied", { defaultValue: "Copied" }), D = g ?? h, O = l(() => {
		let t = null;
		return v || (t = o), e(a, t, _);
	}, [_, v]), k = s(() => {
		w.current != null && (window.clearTimeout(w.current), w.current = null);
	}, []);
	c(() => () => {
		k();
	}, [k]);
	let A = s(async () => {
		k();
		let e = !1;
		try {
			if (typeof navigator < "u") {
				let { clipboard: t } = navigator;
				await t.writeText(D), e = !0;
			}
		} catch {
			e = !1;
		}
		e ||= n(D), e && (C(!0), w.current = window.setTimeout(() => {
			C(!1), w.current = null;
		}, 1400));
	}, [k, D]), j = () => {
		A().catch(() => {});
	}, M = null;
	return S && (M = /* @__PURE__ */ f("span", {
		className: r,
		role: "status",
		"aria-live": "polite",
		children: E
	})), /* @__PURE__ */ p("span", {
		className: i,
		children: [
			/* @__PURE__ */ f("span", {
				className: O,
				title: h,
				children: h
			}),
			/* @__PURE__ */ f(t, {
				type: "button",
				variant: "secondary",
				size: "small",
				onClick: j,
				children: T
			}),
			M
		]
	});
};
//#endregion
export { h as CopyableText, h as default };

//# sourceMappingURL=CopyableText.js.map