import { N as f, a6 as v, j as r, u as R, a as p, a7 as E, h as S, M as k, n as M, s as g } from "./index-c65ca4a4.mjs";
import { R as h } from "./RecommendationReasonForm-b6fdb352.mjs";
import "./Form-f4ced0f0.mjs";
import "./TextArea-65b41e1e.mjs";
const x = ({ recommendation: e, animate: o }) => {
  const t = R(), { updateRoute: a } = p(), { mutateAsync: l } = E(), { formState: n, updateForm: m, handleSave: c, saveState: s, errors: u } = S({
    initialState: {
      ...e
    },
    onSave: async () => {
      await l(n), t.remove(), a("recommendations");
    },
    onValidate: () => {
      const d = {};
      return n.title || (d.title = "Title is required"), d;
    }
  });
  let i = "Save";
  return s === "saving" ? i = "Saving..." : s === "saved" && (i = "Saved"), /* @__PURE__ */ r.jsx(
    k,
    {
      afterClose: () => {
        a("recommendations");
      },
      animate: o ?? !0,
      backDropClick: !1,
      cancelLabel: "Cancel",
      okColor: "black",
      okLabel: i,
      size: "sm",
      testId: "edit-recommendation-modal",
      title: "Edit recommendation",
      onOk: async () => {
        s !== "saving" && (M.remove(), await c({ force: !0 }) || g({
          type: "pageError",
          message: "One or more fields have errors, please doublecheck you filled all mandatory fields"
        }));
      },
      children: /* @__PURE__ */ r.jsx(h, { errors: u, formState: n, updateForm: m })
    }
  );
}, y = ({ params: e }) => {
  const { data: { recommendations: o } = {} } = v(), t = o == null ? void 0 : o.find(({ id: a }) => a === (e == null ? void 0 : e.id));
  return t ? /* @__PURE__ */ r.jsx(x, { recommendation: t }) : null;
}, F = f.create(y);
export {
  F as default
};
//# sourceMappingURL=EditRecommendationModal-c30de48b.mjs.map
