function hasContactNameIssue(action) {
  if (action.actionType === "link_contact") {
    const contactName = action.payload.contactName || "";
    return contactName.trim().length === 0;
  }
  if (action.actionType !== "create_contact") return false;
  const type = action.payload.type || "person";
  if (type !== "person") return false;
  const name = action.payload.name || "";
  const { cleanedName } = stripTitleFromName(name);
  return cleanedName.trim().split(/\s+/).length < 2;
}
const TITLE_TOKENS = /* @__PURE__ */ new Set([
  "mr",
  "mrs",
  "ms",
  "miss",
  "dr",
  "prof",
  "sir",
  "lady",
  "lord",
  "mgr",
  "in\u017C",
  "lic",
  "hab",
  "herr",
  "frau",
  "sr",
  "sra",
  "srta",
  "ing",
  "dott",
  "arch"
]);
function stripTitleFromName(name) {
  const parts = name.trim().split(/\s+/).filter((p) => p.length > 0);
  if (parts.length < 2) return { cleanedName: name.trim(), title: null };
  const firstToken = parts[0].replace(/\.$/, "").toLowerCase();
  if (TITLE_TOKENS.has(firstToken)) {
    return { cleanedName: parts.slice(1).join(" "), title: parts[0] };
  }
  return { cleanedName: name.trim(), title: null };
}
function splitPersonName(name, email) {
  const { cleanedName } = stripTitleFromName(name);
  const trimmed = cleanedName.trim();
  const parts = trimmed.split(/\s+/).filter((item) => item.length > 0);
  if (parts.length >= 2) {
    return {
      firstName: parts[0],
      lastName: parts.slice(1).join(" ")
    };
  }
  if (email) {
    const localPart = email.split("@")[0] || "";
    const emailParts = localPart.split(/[._-]/).filter((p) => p.length > 0);
    if (emailParts.length >= 2) {
      return {
        firstName: emailParts[0].charAt(0).toUpperCase() + emailParts[0].slice(1).toLowerCase(),
        lastName: emailParts.slice(1).map((p) => p.charAt(0).toUpperCase() + p.slice(1).toLowerCase()).join(" ")
      };
    }
  }
  return {
    firstName: parts[0] || trimmed,
    lastName: ""
  };
}
export {
  hasContactNameIssue,
  splitPersonName,
  stripTitleFromName
};
//# sourceMappingURL=contactValidation.js.map
