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/components/ecocup/components/AddCustomerModal/index.tsx
var AddCustomerModal_exports = {};
__export(AddCustomerModal_exports, {
  default: () => AddCustomerModal_default
});
module.exports = __toCommonJS(AddCustomerModal_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_index = require("./index.less");
var import_hooks = require("../../hooks");
var AddCustomerModal = (props) => {
  const { visible, onCancel, onOk } = props;
  const [form] = import_antd.Form.useForm();
  const { post } = (0, import_hooks.useRequest)();
  const [loading, setLoading] = (0, import_react.useState)(false);
  const { goalShopId } = (0, import_hooks.useGetGoalShopInfo)();
  const _onCancel = () => {
    if (loading) return;
    onCancel == null ? void 0 : onCancel();
    form.resetFields();
  };
  const _onOk = async () => {
    if (loading) return;
    try {
      const values = await form.validateFields();
      const result = await addCustomer(values);
      if (!result) {
        return;
      }
      onOk == null ? void 0 : onOk(values);
      form.resetFields();
    } catch (error) {
      console.error(error);
    }
  };
  const addCustomer = async (values) => {
    const { first_name, last_name, phone, email, membership } = values;
    try {
      setLoading(true);
      const res = await post("/shop/wallet/eco/customer", {
        goal_shop_id: goalShopId,
        customer: {
          first_name,
          last_name,
          phone: phone == null ? void 0 : phone.phone,
          country_calling_code: phone == null ? void 0 : phone.countryCallingCode,
          email,
          register_channel: "shop"
        },
        tags: [membership]
      });
      if ((res == null ? void 0 : res.code) == 200) {
        (0, import_materials.PisellToast)({
          content: import_utils.locales.getText(
            "pisell2.text.ecocup.add-customer-modal.success"
          )
        });
        return true;
      }
      return false;
    } catch (error) {
      console.error(error);
      return false;
    } finally {
      setLoading(false);
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal,
    {
      open: visible,
      headerDivider: true,
      title: import_utils.locales.getText("pisell2.text.ecocup.add-customer-modal.title"),
      onCancel: _onCancel,
      onOk: _onOk,
      okText: import_utils.locales.getText("pisell2.text.ecocup.button.confirm"),
      cancelText: import_utils.locales.getText("pisell2.text.ecocup.button.cancel"),
      width: 680,
      centered: true,
      destroyOnClose: true,
      wrapClassName: "pisell2-ecocup-add-customer-modal",
      okButtonProps: { loading }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell2-ecocup-add-customer-modal-content" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form, { form, size: "large" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell2-ecocup-add-customer-modal-content-name-wrap" }, /* @__PURE__ */ import_react.default.createElement(
      import_materials.FormItemInput,
      {
        renderMode: "edit",
        label: import_utils.locales.getText(
          "pisell2.text.ecocup.add-customer-modal.first-name"
        ),
        placeholder: import_utils.locales.getText(
          "pisell2.text.ecocup.add-customer-modal.first-name-placeholder"
        ),
        name: "first_name",
        requiredobj: {
          required: true,
          message: import_utils.locales.getText(
            "pisell2.text.ecocup.add-customer-modal.first-name-required"
          )
        }
      }
    ), /* @__PURE__ */ import_react.default.createElement(
      import_materials.FormItemInput,
      {
        renderMode: "edit",
        label: import_utils.locales.getText(
          "pisell2.text.ecocup.add-customer-modal.last-name"
        ),
        placeholder: import_utils.locales.getText(
          "pisell2.text.ecocup.add-customer-modal.last-name-placeholder"
        ),
        name: "last_name",
        requiredobj: {
          required: true,
          message: import_utils.locales.getText(
            "pisell2.text.ecocup.add-customer-modal.last-name-required"
          )
        }
      }
    )), /* @__PURE__ */ import_react.default.createElement(
      import_materials.FormItemInput.Mobile,
      {
        renderMode: "edit",
        name: "phone",
        label: import_utils.locales.getText(
          "pisell2.text.ecocup.add-customer-modal.phone"
        ),
        placeholder: import_utils.locales.getText(
          "pisell2.text.ecocup.add-customer-modal.phone-placeholder"
        ),
        typeobj: {
          type: "phone",
          enabled: true,
          message: import_utils.locales.getText(
            "pisell2.text.ecocup.add-customer-modal.phone-error"
          )
        },
        requiredobj: {
          required: true,
          message: import_utils.locales.getText(
            "pisell2.text.ecocup.add-customer-modal.phone-required"
          )
        },
        returnFormat: "object"
      }
    ), /* @__PURE__ */ import_react.default.createElement(
      import_materials.FormItemInput,
      {
        renderMode: "edit",
        name: "email",
        label: import_utils.locales.getText(
          "pisell2.text.ecocup.add-customer-modal.email"
        ),
        placeholder: import_utils.locales.getText(
          "pisell2.text.ecocup.add-customer-modal.email-placeholder"
        ),
        requiredobj: {
          required: true,
          message: import_utils.locales.getText(
            "pisell2.text.ecocup.add-customer-modal.email-required"
          )
        }
      }
    ), /* @__PURE__ */ import_react.default.createElement(
      import_materials.FormItemSelect,
      {
        renderMode: "edit",
        name: "membership",
        label: import_utils.locales.getText(
          "pisell2.text.ecocup.add-customer-modal.membership"
        ),
        defaultValue: "regular",
        options: [
          { label: "Regular", value: "regular" },
          { label: "Business", value: "business" },
          { label: "Admin", value: "admin" }
        ]
      }
    )))
  );
};
var AddCustomerModal_default = AddCustomerModal;
