import { Button as e } from "../../../atomic/atoms/button/Button.js";
import { ErrorMessage as t } from "../../../atomic/atoms/error_message/ErrorMessage.js";
import { Modal as n } from "../../../atomic/atoms/modal/Modal.js";
import { body as r, footer as i } from "./confirmDialog.css.js";
import { useCallback as a, useState as o } from "react";
import { jsx as s, jsxs as c } from "react/jsx-runtime";
import { useTranslation as l } from "react-i18next";
//#region src/backoffice/molecules/confirm_dialog/ConfirmDialog.tsx
var u = ({ isOpen: u, title: d, children: f, confirmLabel: p, cancelLabel: m, confirmTone: h = "default", confirmVariant: g, isConfirmLoading: _ = !1, onClose: v, onConfirm: y, closeOnConfirm: b = !0 }) => {
	let { t: x } = l("ui", { useSuspense: !1 }), [S, C] = o(!1), [w, T] = o(null), E = p ?? x("common.actions.confirm", { defaultValue: "Confirm" }), D = m ?? x("common.actions.cancel", { defaultValue: "Cancel" }), O = a(() => {
		S || _ || (T(null), v());
	}, [
		S,
		_,
		v
	]), k = a(async () => {
		if (!(S || _)) {
			T(null), C(!0);
			try {
				await y(), b && v();
			} catch (e) {
				let t = x("common.errors.unexpected", { defaultValue: "An unexpected error occurred." });
				e instanceof Error && e.message.trim() !== "" && (t = e.message), T(t);
			} finally {
				C(!1);
			}
		}
	}, [
		b,
		_,
		S,
		v,
		y,
		x
	]), A = g ?? "primary";
	g == null && h === "danger" && (A = "danger");
	let j = S || _, M = /* @__PURE__ */ c("div", {
		className: i,
		children: [/* @__PURE__ */ s(e, {
			type: "button",
			variant: "secondary",
			onClick: O,
			disabled: j,
			"data-initial-focus": !0,
			children: D
		}), /* @__PURE__ */ s(e, {
			type: "button",
			variant: A,
			onClick: () => {
				k().catch(() => {});
			},
			isLoading: j,
			children: E
		})]
	}), N = null;
	return w != null && (N = /* @__PURE__ */ s(t, { children: w })), /* @__PURE__ */ s(n, {
		isOpen: u,
		onClose: O,
		title: d,
		footer: M,
		initialFocus: {
			mode: "selector",
			selector: "[data-initial-focus]"
		},
		children: /* @__PURE__ */ c("div", {
			className: r,
			children: [N, f]
		})
	});
};
//#endregion
export { u as ConfirmDialog, u as default };

//# sourceMappingURL=ConfirmDialog.js.map