/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/*!*****************************************************!*\
  !*** ./js/event-providers/mailchimp.js + 1 modules ***!
  \*****************************************************/

;// ./js/event-providers/utils.js
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
/**
 * Utilities for conversion tracking event providers.
 *
 * Site Kit by Google, Copyright 2025 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// PII types for classification.
const PII_TYPE = {
  EMAIL: 'email',
  PHONE: 'phone',
  NAME: 'name'
};

// Indicators for identifying PII fields.
const PII_INDICATORS = {
  [PII_TYPE.EMAIL]: ['email', 'e-mail', 'mail', 'email address'],
  [PII_TYPE.PHONE]: ['phone', 'tel', 'mobile', 'cell', 'telephone', 'phone number'],
  [PII_TYPE.NAME]: ['name', 'full-name', 'full name', 'full_name', 'fullname', 'first-name', 'first name', 'first_name', 'firstname', 'last-name', 'last name', 'last_name', 'lastname', 'given-name', 'given name', 'given_name', 'givenname', 'family-name', 'family name', 'family_name', 'familyname', 'fname', 'lname', 'first', 'last', 'your-name', 'your name']
};
const PHONE_MIN_DIGIT_COUNT = 7;

/**
 * Normalizes a value for use in conversion tracking.
 *
 * @since 1.161.0
 *
 * @param {string} value The value to normalize.
 * @return {string} The normalized value.
 */
function normalizeValue(value) {
  if (!value || typeof value !== 'string') {
    return '';
  }
  return value.trim().toLowerCase();
}

/**
 * Normalizes a label by removing common form suffixes and prefixes.
 *
 * @since 1.162.0
 *
 * @param {string} label The label to normalize.
 * @return {string} The normalized label.
 */
function normalizeLabel(label) {
  if (!label || typeof label !== 'string') {
    return '';
  }
  return label.trim().toLowerCase()
  // Remove common required field indicators
  .replace(/\s*\*+\s*$/, '') // "Name *" → "Name"
  .replace(/\s*\(required\)\s*$/i, '') // "Name (Required)" → "Name"
  .replace(/\s*:\s*$/, '') // "Name:" → "Name"
  .trim();
}

/**
 * Normalizes an email address for conversion tracking.
 *
 * @since 1.161.0
 *
 * @param {string} email The email address to normalize.
 * @return {string} The normalized email address.
 */
function normalizeEmail(email) {
  const normalizedEmail = normalizeValue(email);
  const atIndex = normalizedEmail.lastIndexOf('@');

  // If there is no '@' in the email, return it as is.
  if (atIndex === -1) {
    return normalizedEmail;
  }
  const domain = normalizedEmail.slice(atIndex + 1);

  // Check if it is a 'gmail.com' or 'googlemail.com' address.
  if (['gmail.com', 'googlemail.com'].includes(domain)) {
    const prefix = normalizedEmail.slice(0, atIndex);

    // Remove dots from the prefix.
    const normalizedPrefix = prefix.replace(/\./g, '');
    return "".concat(normalizedPrefix, "@").concat(domain);
  }
  return normalizedEmail;
}

/**
 * Determines if a string has a phone-like pattern.
 *
 * @since 1.162.0
 *
 * @param {string} value The string to validate.
 * @return {boolean} Whether the string passed has a phone-like pattern or not.
 */
function hasPhoneLikePattern(value) {
  const digits = value.replace(/\D/g, '');
  if (digits.length < PHONE_MIN_DIGIT_COUNT || digits.length < value.length / 2) {
    return false;
  }

  // Ensure the string only contains digits and phone-like separators, such as spaces, dashes, parentheses, plus signs, and dots.
  return /^[\s\-()+.\d]*$/.test(value);
}

/**
 * Normalizes a phone number for conversion tracking.
 *
 * @since 1.161.0
 *
 * @param {string} phone The phone number to normalize.
 * @return {string} The normalized phone number.
 */
function normalizePhone(phone) {
  const normalizedPhone = normalizeValue(phone);

  // Remove all non-numeric characters.
  const digits = normalizedPhone.replace(/\D/g, '');

  // If the phone number starts with a '+' sign, keep it.
  if (normalizedPhone.startsWith('+')) {
    return "+".concat(digits);
  }
  return digits;
}

/**
 * Checks if a value is likely an email address.
 *
 * @since 1.161.0
 *
 * @param {string} value The value to check.
 * @return {boolean} True if the value is likely an email address, false otherwise.
 */
function isLikelyEmail(value) {
  if (!value) {
    return false;
  }
  const normalizedEmail = normalizeEmail(value);
  const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return emailPattern.test(normalizedEmail);
}

/**
 * Checks if a value is likely a phone number.
 *
 * @since 1.161.0
 *
 * @param {string} value The value to check.
 * @return {boolean} True if the value is likely a phone number, false otherwise.
 */
function isLikelyPhone(value) {
  if (!value) {
    return false;
  }
  if (!hasPhoneLikePattern(value)) {
    return false;
  }
  const normalizedPhone = normalizePhone(value);
  const phonePattern = /^\+?\d{7,}$/;
  if (!phonePattern.test(normalizedPhone)) {
    return false;
  }

  // Reduce false positives: reject plain numeric strings without formatting or international prefix.
  // Allow formatted numbers (e.g., '123-456-7890', '(555) 123-4567') and international format (e.g., '+1234567890').
  const hasFormatting = /[\s\-()+.]/.test(value);
  const hasInternationalPrefix = value.trim().startsWith('+');

  // If it's a plain numeric string (no formatting and no + prefix), reject it to avoid false positives.
  if (!hasFormatting && !hasInternationalPrefix) {
    return false;
  }
  return true;
}

/**
 * Classifies a field as PII based on its metadata.
 *
 * @since 1.161.0
 *
 * @param {Object} fieldMeta The metadata of the field to classify.
 * @return {Object|null} An object containing the PII type and value, or null if not classified.
 */
function classifyPII(fieldMeta) {
  let _ref = fieldMeta || {},
    type = _ref.type,
    name = _ref.name,
    value = _ref.value,
    label = _ref.label;
  type = normalizeValue(type);
  name = normalizeValue(name);
  value = normalizeValue(value);
  label = normalizeLabel(label);

  // First check explicit field types (most reliable).
  switch (type) {
    case 'email':
      return {
        type: PII_TYPE.EMAIL,
        value: normalizeEmail(value)
      };
    case 'tel':
      return {
        type: PII_TYPE.PHONE,
        value: normalizePhone(value)
      };
  }

  // Then check email patterns (emails are more distinctive than phone patterns).
  if (isLikelyEmail(value)) {
    return {
      type: PII_TYPE.EMAIL,
      value: normalizeEmail(value)
    };
  }

  // Then check field name/label indicators for all PII types (context-based detection).
  if (PII_INDICATORS[PII_TYPE.EMAIL].includes(name) || PII_INDICATORS[PII_TYPE.EMAIL].includes(label)) {
    return {
      type: PII_TYPE.EMAIL,
      value: normalizeEmail(value)
    };
  }
  if (PII_INDICATORS[PII_TYPE.PHONE].includes(name) || PII_INDICATORS[PII_TYPE.PHONE].includes(label)) {
    return {
      type: PII_TYPE.PHONE,
      value: normalizePhone(value)
    };
  }
  if (PII_INDICATORS[PII_TYPE.NAME].includes(name) || PII_INDICATORS[PII_TYPE.NAME].includes(label)) {
    return {
      type: PII_TYPE.NAME,
      value: normalizeValue(value)
    };
  }

  // Finally, use pattern matching as fallback (most prone to false positives).
  if (isLikelyPhone(value)) {
    return {
      type: PII_TYPE.PHONE,
      value: normalizePhone(value)
    };
  }
  return null;
}

/**
 * Extracts and formats name fields for Google Tag's user_data address object.
 *
 * @since 1.162.0
 *
 * @param {Array<Object>} fields An array of detected PII fields.
 * @return {Object|undefined} An object containing normalized first_name and optionally last_name, or undefined if no names found.
 */
function getAddress(fields) {
  const names = fields.filter(_ref2 => {
    let type = _ref2.type;
    return type === PII_TYPE.NAME;
  }).map(_ref3 => {
    let value = _ref3.value;
    return normalizeValue(value);
  }).filter(Boolean);
  if (!names.length) {
    return undefined;
  }
  const _ref4 = names.length === 1 ? names[0].split(' ') : names,
    _ref5 = _toArray(_ref4),
    firstName = _ref5[0],
    lastNames = _arrayLikeToArray(_ref5).slice(1);
  return _objectSpread({
    first_name: firstName
  }, (lastNames === null || lastNames === void 0 ? void 0 : lastNames.length) > 0 ? {
    last_name: lastNames.join(' ')
  } : {});
}

/**
 * Extracts the email address from detected PII fields.
 *
 * @since 1.162.0
 *
 * @param {Array<Object>} fields An array of detected PII fields.
 * @return {string|undefined} The email address if found, undefined otherwise.
 */
function getEmail(fields) {
  var _fields$find;
  return (_fields$find = fields.find(_ref6 => {
    let type = _ref6.type;
    return type === PII_TYPE.EMAIL;
  })) === null || _fields$find === void 0 ? void 0 : _fields$find.value;
}

/**
 * Extracts the phone number from detected PII fields.
 *
 * @since 1.162.0
 *
 * @param {Array<Object>} fields An array of detected PII fields.
 * @return {string|undefined} The phone number if found, undefined otherwise.
 */
function getPhoneNumber(fields) {
  var _fields$find2;
  return (_fields$find2 = fields.find(_ref7 => {
    let type = _ref7.type;
    return type === PII_TYPE.PHONE;
  })) === null || _fields$find2 === void 0 ? void 0 : _fields$find2.value;
}

/**
 * Extracts and classifies user data from a WPForms form submission.
 *
 * @since 1.162.0
 *
 * @param {Array<Object>} fields An array of detected PII fields.
 * @return {Object|undefined} A user_data object containing detected PII (address, email, phone_number), or undefined if no PII found.
 */
function getUserData(fields) {
  const userDataFields = [['address', getAddress(fields)], ['email', getEmail(fields)], ['phone_number', getPhoneNumber(fields)]].filter(_ref8 => {
    let _ref9 = _slicedToArray(_ref8, 2),
      value = _ref9[1];
    return value;
  });
  if (userDataFields.length === 0) {
    return undefined;
  }
  return Object.fromEntries(userDataFields);
}
;// ./js/event-providers/mailchimp.js
function mailchimp_slicedToArray(r, e) { return mailchimp_arrayWithHoles(r) || mailchimp_iterableToArrayLimit(r, e) || mailchimp_unsupportedIterableToArray(r, e) || mailchimp_nonIterableRest(); }
function mailchimp_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function mailchimp_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return mailchimp_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? mailchimp_arrayLikeToArray(r, a) : void 0; } }
function mailchimp_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function mailchimp_iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function mailchimp_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function mailchimp_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function mailchimp_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? mailchimp_ownKeys(Object(t), !0).forEach(function (r) { mailchimp_defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : mailchimp_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function mailchimp_defineProperty(e, r, t) { return (r = mailchimp_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function mailchimp_toPropertyKey(t) { var i = mailchimp_toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function mailchimp_toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
 * Site Kit by Google, Copyright 2024 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Internal dependencies
 */

(mc4wp => {
  if (!mc4wp) {
    return;
  }
  mc4wp.forms.on('subscribed', (mc4wpForm, data) => {
    var _global$_googlesiteki, _global$_googlesiteki2, _global$_googlesiteki3;
    const gtagUserDataEnabled = (_global$_googlesiteki = globalThis._googlesitekit) === null || _global$_googlesiteki === void 0 ? void 0 : _global$_googlesiteki.gtagUserData;
    const userData = gtagUserDataEnabled ? getUserDataFromForm(mc4wpForm.element, data) : null;
    (_global$_googlesiteki2 = globalThis._googlesitekit) === null || _global$_googlesiteki2 === void 0 || (_global$_googlesiteki3 = _global$_googlesiteki2.gtagEvent) === null || _global$_googlesiteki3 === void 0 || _global$_googlesiteki3.call(_global$_googlesiteki2, 'submit_lead_form', mailchimp_objectSpread({
      event_category: 'mailchimp',
      googlesitekit_event_provider: 'mailchimp',
      googlesitekit_form_id: String(mc4wpForm.id)
    }, userData ? {
      user_data: userData
    } : {}));
  });
})(globalThis.mc4wp);

/**
 * Extracts and classifies user data from a Mailchimp form submission.
 *
 * @since 1.164.0
 *
 * @param {HTMLFormElement} form The submitted form element.
 * @param {Object}          data The submitted form's data.
 * @return {Object|undefined} A user_data object containing detected PII (address, email, phone_number), or undefined if no PII found.
 */
function getUserDataFromForm(form, data) {
  // eslint-disable-next-line sitekit/acronym-case
  if (!form || !(form instanceof HTMLFormElement)) {
    return undefined;
  }
  const detectedFields = Object.entries(data).map(_ref => {
    var _form$querySelector;
    let _ref2 = mailchimp_slicedToArray(_ref, 2),
      name = _ref2[0],
      value = _ref2[1];
    // Mailchimp joins the individual name fields into a single field "NAME",
    // but still provides the individual values in the data object.
    // We only rely on "NAME" when neither "FNAME" nor "LNAME" are available.
    if (name === 'NAME' && ('FNAME' in data || 'LNAME' in data)) {
      return null;
    }
    const input = form.querySelector("[name='".concat(name, "']"));
    const type = input === null || input === void 0 ? void 0 : input.type;
    const label = input !== null && input !== void 0 && input.id ? (_form$querySelector = form.querySelector("label[for='".concat(input === null || input === void 0 ? void 0 : input.id, "']"))) === null || _form$querySelector === void 0 ? void 0 : _form$querySelector.textContent : undefined;
    return classifyPII({
      type,
      label,
      name,
      value
    });
  }).filter(Boolean);
  return getUserData(detectedFields);
}
/******/ })()
;
//# sourceMappingURL=googlesitekit-events-provider-mailchimp.js.map