var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/contactInfoModal/index.tsx
var contactInfoModal_exports = {};
__export(contactInfoModal_exports, {
  default: () => contactInfoModal_default
});
module.exports = __toCommonJS(contactInfoModal_exports);
var import_materials = require("@pisell/materials");
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_locales = __toESM(require("./locales"));
var import_index = require("./index.less");
var import_ContactInfoContent = __toESM(require("./ContactInfoContent"));
var ContactInfoModalContent = (props) => {
  var _a, _b;
  const {
    open,
    title,
    onCancel,
    onSave,
    onDelete,
    isShowDelete,
    dataSource,
    config
  } = props;
  const context = (0, import_useEngineContext.default)();
  import_utils.locales.init(
    import_locales.default,
    ((_b = (_a = context.appHelper.utils) == null ? void 0 : _a.storage) == null ? void 0 : _b.get("umi_locale")) || "en"
  );
  const [form] = import_antd.Form.useForm();
  (0, import_react.useEffect)(() => {
    form.resetFields();
    if (dataSource) {
      const { first_name, last_name, email } = dataSource || {};
      const { country_calling_code, phone, country_code } = (dataSource == null ? void 0 : dataSource.phone) || {};
      let countryCallingCode = "";
      if (country_calling_code) {
        countryCallingCode = (country_calling_code == null ? void 0 : country_calling_code.startsWith("+")) ? country_calling_code : `+${country_calling_code}`;
      }
      form.setFieldsValue({
        first_name,
        last_name,
        phone: {
          phone,
          countryCallingCode,
          countryCode: country_code
        },
        email
      });
    } else {
      form.resetFields();
    }
  }, [dataSource, form]);
  const isEmpty = (0, import_react.useMemo)(() => {
    var _a2;
    return !(dataSource == null ? void 0 : dataSource.first_name) && !(dataSource == null ? void 0 : dataSource.last_name) && !((_a2 = dataSource == null ? void 0 : dataSource.phone) == null ? void 0 : _a2.phone) && !(dataSource == null ? void 0 : dataSource.email);
  }, [dataSource]);
  const handleCancel = (e) => {
    var _a2, _b2;
    (_a2 = e == null ? void 0 : e.preventDefault) == null ? void 0 : _a2.call(e);
    (_b2 = e == null ? void 0 : e.stopPropagation) == null ? void 0 : _b2.call(e);
    onCancel();
  };
  const handleDelete = (e) => {
    var _a2, _b2;
    (_a2 = e == null ? void 0 : e.preventDefault) == null ? void 0 : _a2.call(e);
    (_b2 = e == null ? void 0 : e.stopPropagation) == null ? void 0 : _b2.call(e);
    onDelete();
  };
  const handleSave = async (e) => {
    var _a2, _b2, _c, _d, _e;
    (_a2 = e == null ? void 0 : e.preventDefault) == null ? void 0 : _a2.call(e);
    (_b2 = e == null ? void 0 : e.stopPropagation) == null ? void 0 : _b2.call(e);
    try {
      const values = await form.validateFields();
      console.log("values", values);
      onSave({
        first_name: (values == null ? void 0 : values.first_name) || "",
        last_name: (values == null ? void 0 : values.last_name) || "",
        display_name: (values == null ? void 0 : values.first_name) || (values == null ? void 0 : values.last_name) ? `${(values == null ? void 0 : values.first_name) || ""} ${(values == null ? void 0 : values.last_name) || ""}` : "",
        phone: {
          phone: ((_c = values == null ? void 0 : values.phone) == null ? void 0 : _c.phone) || "",
          country_calling_code: ((_d = values == null ? void 0 : values.phone) == null ? void 0 : _d.countryCallingCode) || "",
          country_code: ((_e = values == null ? void 0 : values.phone) == null ? void 0 : _e.countryCode) || ""
        },
        email: (values == null ? void 0 : values.email) || ""
      });
    } catch (error) {
      console.error("handleSave failed:", error);
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal,
    {
      open,
      onCancel: handleCancel,
      title: title || import_utils.locales.getText("pisell2.text.contact-info.modal.title"),
      footer: /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-contact-info-modal-footer" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { type: "default", block: true, onClick: handleCancel }, import_utils.locales.getText("pisell2.text.button.cancel")), isShowDelete && !isEmpty ? /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { type: "default", block: true, danger: true, onClick: handleDelete }, import_utils.locales.getText("pisell2.text.button.delete")) : null, /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { type: "primary", block: true, onClick: handleSave }, import_utils.locales.getText("pisell2.text.button.save"))),
      destroyOnClose: true,
      mobileModalHeight: "auto"
    },
    /* @__PURE__ */ import_react.default.createElement(import_ContactInfoContent.default, { form, config })
  );
};
var ContactInfoModal = (props) => {
  const { open } = props;
  return open ? /* @__PURE__ */ import_react.default.createElement(ContactInfoModalContent, { ...props }) : null;
};
var contactInfoModal_default = ContactInfoModal;
