import { jsxs as F, jsx as o } from "react/jsx-runtime";
import { IconNames as M } from "./index-IconNames.js";
import { Text as k, TextTypes as y, FontWeights as B } from "./index-Text.js";
import { useState as I, useEffect as O } from "react";
import { Modal as N } from "./index-Modal.js";
import { ModalBody as q } from "./index-ModalBody.js";
import { ModalFooter as C } from "./index-ModalFooter.js";
import { ModalHeader as G } from "./index-ModalHeader.js";
import a from "./index-EditModal.module.scss.js";
const D = (f) => {
  const {
    title: p,
    titleReplacements: h,
    children: u,
    positiveBtnText: v = "Save",
    showPositiveBtnIcon: g,
    showFooterTopBorder: x,
    saveCallback: i,
    cancelCallback: l,
    savable: b,
    close: e,
    closeOnSave: s = !0,
    closeOnError: n = !1,
    savingInProgress: r,
    testId: T,
    width: w = "672px",
    requestGotError: t = !1
  } = f, [d, c] = I(!1);
  O(() => {
    d && s && !r && (c(!1), t ? n && e({
      isOk: !0,
      data: {
        requestGotError: t
      }
    }) : s && e({
      isOk: !0,
      data: {
        requestGotError: t
      }
    }));
  }, [e, n, s, d, t, r]);
  const E = () => {
    c(!0), i && i();
  }, m = () => {
    l && l(), e({
      isOk: !1
    });
  };
  return F(N, {
    width: w,
    className: a.modal,
    testId: T,
    children: [o(G, {
      closeFn: m,
      children: o(k, {
        replacements: h,
        fontWeight: B.bold,
        type: y.heading4,
        className: a.headerText,
        children: p
      })
    }), o(q, {
      className: a.body,
      children: u
    }), o(C, {
      showTopBorder: x,
      buttonsPosition: "between",
      positive: {
        cta: E,
        text: v,
        icon: g ? M.save : void 0,
        isLoading: r,
        disabled: !b
      },
      negative: {
        cta: m,
        text: "Cancel"
      }
    })]
  });
};
export {
  D as EditModal
};
