import { jsx as c } from "@emotion/react/jsx-runtime";
import { useFormContext as I, useFormState as w } from "react-hook-form";
import { useModuleDictionary as F } from "@m4l/core";
import { useCallback as f, useEffect as T } from "react";
import { useModal as M } from "../../../../hooks/useModal/index.js";
import { useWindowToolsMF as N } from "../../../WindowBase/hooks/useWindowToolsMF/index.js";
import { clsx as k } from "clsx";
import { classActoinFormCancelRoot as A } from "./constanst.js";
import { DICTIONARY as r } from "../../dictionary.js";
import { WindowConfirm as L } from "../../../WindowConfirm/WindowConfirm.js";
import { ButtonRootStyled as R } from "./slots/ActionFormCancelSlots.js";
function W(C) {
  const {
    className: d,
    onClose: e,
    linkToCloseWindow: i = !1,
    "data-testid": u
  } = C, { getLabel: o } = F(), { openModal: s } = M(), { close: a, setFnQueryClose: l } = N(), { control: p } = I(), { isDirty: m } = w({
    control: p
  }), t = f(() => {
    a(!1), e?.();
  }, [a, e]), n = f(() => {
    m ? s({
      window: /* @__PURE__ */ c(
        L,
        {
          variant: "warning",
          title: o(r.CONFIRM_QUIT_TITLE),
          msg: o(r.CONFIRM_QUIT_MSG),
          onClickIntro: t
        }
      ),
      variant: "warning"
    }) : t();
  }, [m, s, o, t]);
  return T(() => {
    i && l(n);
  }, [n, l, i]), /* @__PURE__ */ c(
    R,
    {
      ownerState: {},
      variant: "outlined",
      onClick: n,
      className: k(A, d),
      label: o(r.LABEL_CANCEL),
      "data-testid": u
    }
  );
}
export {
  W as ActionFormCancel
};
