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/checkout/components/SendPaymentLinkModal/index.tsx
var SendPaymentLinkModal_exports = {};
__export(SendPaymentLinkModal_exports, {
  default: () => SendPaymentLinkModal_default
});
module.exports = __toCommonJS(SendPaymentLinkModal_exports);
var import_react = require("react");
var import_antd = require("antd");
var import_index = require("./index.less");
var import_react2 = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_usePrefix = __toESM(require("../../../../hooks/usePrefix"));
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("../../locales"));
var import_hooks = require("../../../../hooks");
var import_useToast = __toESM(require("../../../../hooks/useToast"));
var import_utils2 = require("../../../booking/utils");
function SendPaymentLinkModal({
  balanceAmount = "$15.1",
  customerEmail = "customer@email.com",
  customerName = "",
  onClose,
  sendPaymentLink,
  customerId
}) {
  var _a, _b, _c, _d, _e, _f, _g;
  const prefix = (0, import_usePrefix.default)();
  const context = (0, import_hooks.useEngineContext)();
  import_utils.locales.init(
    import_locales.default,
    ((_e = (_d = (_c = (_b = (_a = context.appHelper.utils) == null ? void 0 : _a.getApp) == null ? void 0 : _b.call(_a)) == null ? void 0 : _c.locales) == null ? void 0 : _d.getLocale) == null ? void 0 : _e.call(_d)) || ((_g = (_f = context.appHelper.utils) == null ? void 0 : _f.storage) == null ? void 0 : _g.get("umi_locale")) || "en"
  );
  const Toast = (0, import_useToast.default)();
  const getText = (key, fallback) => {
    return import_utils.locales.getText(key) || fallback;
  };
  const formatCustomerName = (customerName2) => {
    if ((0, import_utils2.isWalkIn)(customerId)) {
      return "";
    }
    const formatTemplate = getText("pisell2.checkout.send-payment-link.customer-name-format");
    if (typeof formatTemplate === "function") {
      return formatTemplate(customerName2);
    }
    return `${customerName2}'s `;
  };
  const validateEmail = (email) => {
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    return emailRegex.test(email);
  };
  const [emailAddress, setEmailAddress] = (0, import_react.useState)(customerEmail || "");
  (0, import_react.useEffect)(() => {
    setEmailAddress(customerEmail || "");
  }, [customerEmail]);
  const handleSendLink = () => {
    console.log("Send link clicked");
    console.log("Email to send:", emailAddress);
    console.log("Amount to send:", balanceAmount);
    if (!emailAddress || emailAddress.trim() === "") {
      Toast.fail(getText("pisell2.checkout.send-payment-link.email-required"));
      return;
    }
    if (!validateEmail(emailAddress.trim())) {
      Toast.fail(getText("pisell2.checkout.send-payment-link.email-invalid"));
      return;
    }
    sendPaymentLink({
      emails: [emailAddress.trim()],
      amount: balanceAmount
    });
    onClose == null ? void 0 : onClose();
  };
  const modalContent = /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("send-payment-link-modal") }, /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("modal-content") }, /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("main-content") }, /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("illustration-container") }, /* @__PURE__ */ import_react2.default.createElement(
    "img",
    {
      src: prefix + "/send_payment_link.png",
      className: (0, import_classnames.default)("illustration")
    }
  )), /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("form-container") }, /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("email-options-container") }, /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("email-section") }, /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("section-label") }, formatCustomerName(customerName), getText("pisell2.checkout.send-payment-link.email-address", "Email Address")), /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("email-option") }, /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("email-input-container") }, /* @__PURE__ */ import_react2.default.createElement("div", { className: `${(0, import_classnames.default)("email-input")} ${(0, import_classnames.default)("email-input-selected")}` }, /* @__PURE__ */ import_react2.default.createElement(
    "input",
    {
      type: "email",
      value: emailAddress,
      onChange: (e) => setEmailAddress(e.target.value),
      placeholder: getText("pisell2.checkout.send-payment-link.email-placeholder", "Enter email address"),
      className: (0, import_classnames.default)("email-text-input")
    }
  )))))), /* @__PURE__ */ import_react2.default.createElement("div", { className: (0, import_classnames.default)("footer") }, /* @__PURE__ */ import_react2.default.createElement(
    "button",
    {
      className: (0, import_classnames.default)("send-button"),
      onClick: handleSendLink
    },
    getText(
      "pisell2.checkout.send-payment-link.send-button",
      "Send Link"
    )
  ))))));
  return /* @__PURE__ */ import_react2.default.createElement(
    import_antd.Modal,
    {
      title: getText(
        "pisell2.checkout.send-payment-link.modal-title",
        "Send Payment Link"
      ),
      width: 680,
      footer: null,
      centered: true,
      wrapClassName: "send-payment-link-modal-wrapper",
      open: true,
      onCancel: onClose
    },
    modalContent
  );
}
var SendPaymentLinkModal_default = SendPaymentLinkModal;
