import { jsx as C } from "@emotion/react/jsx-runtime";
import { useFormContext as f, useFormState as d } from "react-hook-form";
import { useModuleDictionary as u } from "@m4l/core";
import { useCallback as p } from "react";
import { useWindowCloseGuard as I } from "../../../../hooks/useWindowCloseGuard/index.js";
import { clsx as T } from "clsx";
import { classActoinFormCancelRoot as A } from "./constanst.js";
import { DICTIONARY as t } from "../../dictionary.js";
import { ButtonRootStyled as F } from "./slots/ActionFormCancelSlots.js";
function w(r) {
  const {
    className: s,
    onClose: e,
    linkToCloseWindow: n = !1,
    "data-testid": i
  } = r, { getLabel: o } = u(), { control: a } = f(), { isDirty: l } = d({
    control: a
  }), m = p(() => {
    e?.();
  }, [e]), { requestClose: c } = I({
    confirmMessage: o(t.CONFIRM_QUIT_MSG),
    confirmTitle: o(t.CONFIRM_QUIT_TITLE),
    isDirty: l,
    linkToCloseWindow: n,
    onAfterClose: m
  });
  return /* @__PURE__ */ C(
    F,
    {
      ownerState: {},
      variant: "outlined",
      onClick: () => c(),
      className: T(A, s),
      label: o(t.LABEL_CANCEL),
      "data-testid": i
    }
  );
}
export {
  w as ActionFormCancel
};
