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 { actions as r, container as i, header as a, pre as o, title as s, truncated as c } from "./backofficeJsonViewer.css.js";
import { useCallback as l, useMemo 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/molecules/backoffice_json_viewer/BackofficeJsonViewer.tsx
var h = ({ value: h, title: g, className: _, maxHeight: v, truncate: y = !1, truncateLabel: b, expandLabel: x, copyLabel: S, copiedLabel: C }) => {
	let { t: w } = m("ui"), [T, E] = d(y), [D, O] = d(!1), k = g ?? w("backoffice.jsonViewer.title"), A = b ?? w("backoffice.jsonViewer.collapse"), j = x ?? w("backoffice.jsonViewer.expand"), M = S ?? w("backoffice.jsonViewer.copy"), N = C ?? w("backoffice.jsonViewer.copied"), P = u(() => {
		try {
			return JSON.stringify(h, null, 2);
		} catch {
			return JSON.stringify({ error: w("backoffice.jsonViewer.serializationError") });
		}
	}, [w, h]), F = l(async () => {
		let e = !1;
		try {
			typeof navigator < "u" && (await navigator.clipboard.writeText(P), e = !0);
		} catch {
			e = !1;
		}
		e ||= n(P), e && (O(!0), window.setTimeout(() => {
			O(!1);
		}, 1400));
	}, [P]), I = u(() => {
		if (v != null) return { maxHeight: v };
	}, [v]), L = M;
	D && (L = N);
	let R = A;
	return T && (R = j), /* @__PURE__ */ p("div", {
		className: e(i, _),
		children: [/* @__PURE__ */ p("div", {
			className: a,
			children: [/* @__PURE__ */ f("span", {
				className: s,
				children: k
			}), /* @__PURE__ */ p("div", {
				className: r,
				children: [/* @__PURE__ */ f(t, {
					type: "button",
					variant: "secondary",
					size: "small",
					onClick: () => {
						F().catch(() => {});
					},
					children: L
				}), /* @__PURE__ */ f(t, {
					type: "button",
					variant: "secondary",
					size: "small",
					onClick: () => {
						E((e) => !e);
					},
					children: R
				})]
			})]
		}), /* @__PURE__ */ f("pre", {
			className: e(o, { [c]: T }),
			style: I,
			children: P
		})]
	});
};
//#endregion
export { h as BackofficeJsonViewer, h as default };

//# sourceMappingURL=BackofficeJsonViewer.js.map