const O = {
  debug: !1,
  allowFullscreen: !0,
  alwaysShowWelcomeMessages: !1
}, R = (e, t) => {
  const a = `${e ?? ""}`.trim();
  return t === !0 ? a !== "false" : a === "true";
}, Y = (e) => {
  try {
    const t = new URL(e), a = t.pathname.split("/").filter((o) => !!o)[1];
    let r = O.debug;
    t.searchParams.has("debug") && (r = R(t.searchParams.get("debug"), r));
    let s = O.allowFullscreen;
    t.searchParams.has("allowFullscreen") && (s = R(
      t.searchParams.get("allowFullscreen"),
      s
    ));
    let n = O.alwaysShowWelcomeMessages;
    return t.searchParams.has("alwaysShowWelcomeMessages") && (n = R(
      t.searchParams.get("alwaysShowWelcomeMessages"),
      n
    )), {
      widgetId: a,
      debug: r,
      allowFullscreen: s,
      alwaysShowWelcomeMessages: n
    };
  } catch {
    return null;
  }
};
var y = /* @__PURE__ */ ((e) => (e.SEND_QUESTION = "SEND_QUESTION", e.CLEAR_MESSAGES = "CLEAR_MESSAGES", e.UPDATE_STYLES = "UPDATE_STYLES", e.UPDATE_IMAGES = "UPDATE_IMAGES", e.UPDATE_FULLSCREEN = "UPDATE_FULLSCREEN", e.UPDATE_PARENT_URL = "UPDATE_PARENT_URL", e.SHOW_CATEGORIES_MESSAGES = "SHOW_CATEGORIES_MESSAGES", e.SHOW_FEEDBACK_PAGE = "SHOW_FEEDBACK_PAGE", e.GO_TO_DATA_RETRIEVAL_PAGE = "GO_TO_DATA_RETRIEVAL_PAGE", e.SHAREPOINT_REQUEST_ACCESS_TOKEN_RECEIVED = "SHAREPOINT_REQUEST_ACCESS_TOKEN_RECEIVED", e.SHAREPOINT_SET_ACCESS_TOKEN = "SHAREPOINT_SET_ACCESS_TOKEN", e))(y || {});
Object.values(y);
const Q = (e, t, a) => {
  try {
    const r = {
      type: e,
      data: t,
      target: "iframe"
    };
    a.postMessage(r, "*");
  } catch {
  }
};
var C = /* @__PURE__ */ ((e) => (e.OPEN_CHAT = "OPEN_CHAT", e.CLOSE_CHAT = "CLOSE_CHAT", e.TOGGLE_CHAT = "TOGGLE_CHAT", e))(C || {});
const Z = Object.values(C), G = (e, t) => {
  try {
    if (typeof e != "object" || e === null)
      return !1;
    const { type: a, data: r, target: s, clientId: n } = e;
    return s === "script" && Z.includes(a) && n === t && typeof r == "object" && r !== null;
  } catch {
    return !1;
  }
}, T = (e, t, a) => {
  try {
    return G(e, a) ? e.type === t : !1;
  } catch {
    return !1;
  }
}, M = (e, t, a, r) => {
  try {
    const s = {
      type: e,
      data: t,
      target: "script",
      clientId: a
    };
    r.postMessage(s, "*");
  } catch {
  }
};
var _ = /* @__PURE__ */ ((e) => (e.CHAT_READY = "CHAT_READY", e.CHAT_FAILED = "CHAT_FAILED", e.STYLES_UPDATED = "STYLES_UPDATED", e.QUESTION_ASKED = "QUESTION_ASKED", e.QUESTION_ANSWERED = "QUESTION_ANSWERED", e.ANSWER_REACTED = "ANSWER_REACTED", e.MESSAGES_CLEARED = "MESSAGES_CLEARED", e.CONTACT_ADMIN_CLICKED = "CONTACT_ADMIN_CLICKED", e.CLOSE_IFRAME_CLICKED = "CLOSE_IFRAME_CLICKED", e.SHOW_FEEDBACK_PAGE = "SHOW_FEEDBACK_PAGE", e.SEARCH_PAGE_ACTIVE = "SEARCH_PAGE_ACTIVE", e.SOURCE_PREVIEW_OPENED = "SOURCE_PREVIEW_OPENED", e.SOURCE_PREVIEW_CLOSED = "SOURCE_PREVIEW_CLOSED", e.SHAREPOINT_REQUEST_ACCESS_TOKEN = "SHAREPOINT_REQUEST_ACCESS_TOKEN", e))(_ || {});
const q = Object.values(_), z = (e, t) => {
  try {
    if (typeof e != "object" || e === null)
      return !1;
    const { type: a, data: r, source: s, clientId: n } = e;
    return s === "iframe" && q.includes(a) && n === t && typeof r == "object" && r !== null;
  } catch {
    return !1;
  }
}, b = (e, t, a) => {
  try {
    return z(e, a) ? e.type === t : !1;
  } catch {
    return !1;
  }
}, h = (e) => `myreach-widget-${e}`, X = h("style"), i = h("wrapper"), S = h("iframe"), w = h("iframe-parent"), u = h("toggler"), V = h("toggler-button"), g = h("popup-message-wrapper"), J = h("popup-message"), L = h("open-image"), A = h("toggler-open-wrapper"), $ = h("toggler-close-wrapper"), W = "data-client-id", c = (e, t) => {
  e.setAttribute(W, t);
}, l = (e, t) => document.querySelector(
  `#${e}[${W}="${t}"]`
), f = (e, t, a) => {
  try {
    const r = l(S, e), s = r == null ? void 0 : r.contentWindow;
    s && Q(t, a, s);
  } catch {
  }
}, ee = (e) => {
  try {
    const t = window.location.href;
    new URL(t).protocol.startsWith("http") && f(e, y.UPDATE_PARENT_URL, { parentUrl: t });
  } catch {
  }
}, p = {
  "theme-primary": {
    cssVar: "--myreach-widget-theme-primary-color",
    getterFn: (e) => e.primary,
    defaultValues: {
      light: "rgb(72, 161, 238)",
      dark: "rgb(72, 161, 238)"
    }
  },
  "theme-primary-hover": {
    cssVar: "--myreach-widget-theme-primary-hover-color",
    getterFn: (e) => e.primaryHover,
    defaultValues: {
      light: "rgb(48, 107, 159)",
      dark: "rgb(48, 107, 159)"
    }
  },
  "fonts-over-primary": {
    cssVar: "--myreach-widget-fonts-over-primary-color",
    getterFn: (e) => e.textOverPrimary,
    defaultValues: {
      light: "rgb(255, 255, 255)",
      dark: "rgb(255, 255, 255)"
    }
  },
  "background-main": {
    cssVar: "--myreach-widget-background-main-color",
    defaultValues: {
      light: "rgb(255, 255, 255)",
      dark: "rgb(10, 10, 16)"
    }
  },
  "background-alt": {
    cssVar: "--myreach-widget-background-alt-color",
    defaultValues: {
      light: "rgb(244, 245, 247)",
      dark: "rgb(28, 28, 34)"
    }
  },
  "fonts-main": {
    cssVar: "--myreach-widget-fonts-main-color",
    defaultValues: {
      light: "rgb(27, 42, 74)",
      dark: "rgb(227, 227, 227)"
    }
  },
  "fonts-alt": {
    cssVar: "--myreach-widget-fonts-alt-color",
    defaultValues: {
      light: "rgb(139, 146, 162)",
      dark: "rgb(139, 146, 162)"
    }
  },
  "border-main": {
    cssVar: "--myreach-widget-border-main-color",
    defaultValues: {
      light: "rgb(226, 226, 226)",
      dark: "rgb(45, 46, 49)"
    }
  },
  "warn-color": {
    cssVar: "--myreach-widget-warn-color",
    defaultValues: {
      light: "rgb(208, 2, 27)",
      dark: "rgb(208, 2, 27)"
    }
  }
}, x = Object.values(p), D = "data-myreach-theme", k = "screen and (max-width: 767px)", te = (e, t, a) => {
  var r;
  try {
    const s = document.documentElement;
    s.setAttribute(D, `${a}`.toLowerCase());
    for (const n of x) {
      const o = ((r = n.getterFn) == null ? void 0 : r.call(n, t)) ?? null;
      o ? s.style.setProperty(
        `${n.cssVar}-${e}-given`,
        `rgb(${o.join(",")})`
      ) : s.style.removeProperty(`${n.cssVar}-${e}-given`);
    }
  } catch {
  }
}, ae = (e) => {
  const t = `${p["theme-primary"].cssVar}-${e}`, a = `${p["theme-primary-hover"].cssVar}-${e}`, r = `${p["fonts-over-primary"].cssVar}-${e}`, s = `${p["background-main"].cssVar}-${e}`, n = `${p["fonts-main"].cssVar}-${e}`, o = `${p["border-main"].cssVar}-${e}`, E = `${p["warn-color"].cssVar}-${e}`;
  return `
:root {
    ${x.map((d) => `
        ${d.cssVar}-${e}: var(${d.cssVar}-${e}-given, ${d.defaultValues.light});
        `).join(`
`)}

	--_myreach-button-size-small: var(--myreach-button-size-small, var(--myreach-button-size, 40px));
	--_myreach-button-size-medium: var(--myreach-button-size-medium, var(--myreach-button-size, 48px));
	--_myreach-button-size-large: var(--myreach-button-size-large, var(--myreach-button-size, 56px));
	
	--_myreach-icon-size-small: var(--myreach-icon-size-small, var(--myreach-icon-size, 24px));
	--_myreach-icon-size-medium: var(--myreach-icon-size-medium, var(--myreach-icon-size, 32px));
	--_myreach-icon-size-large: var(--myreach-icon-size-large, var(--myreach-icon-size, 40px));
	

	--_myreach-button-size: var(--_myreach-button-size-small);
	--_myreach-icon-size: var(--_myreach-icon-size-small);
    --_myreach-vertical-gap: var(--myreach-vertical-gap, 20px);
    --_myreach-horizontal-gap: var(--myreach-horizontal-gap, 20px);
	--_myreach-iframe-radius: var(--myreach-iframe-radius, 16px);
	--_myreach-min-font-size: var(--myreach-min-font-size, 14px);
}

:root[${D}="dark"] {
	${x.map((d) => `
		${d.cssVar}-${e}: var(${d.cssVar}-${e}-given, ${d.defaultValues.dark});
		`).join(`
`)}
}

@media (prefers-color-scheme: dark) {
	:root[${D}="auto"] {
		${x.map((d) => `
			${d.cssVar}-${e}: var(${d.cssVar}-${e}-given, ${d.defaultValues.dark});
			`).join(`
`)}
	}
}

#${i} {
    position: fixed;
    bottom: var(--_myreach-vertical-gap);
    right: var(--_myreach-horizontal-gap);
    z-index: 100;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;

    max-height: calc(100% - var(--_myreach-vertical-gap) - 8px);
    max-width: calc(100% - var(--_myreach-horizontal-gap) - 8px);

    display: none;

    pointer-events: none;

	transition: all 300ms;
}

#${i}.at-left {
    right: unset;
    left: var(--myreach-horizontal-gap, 20px);

    align-items: flex-start;
}

#${i}.ready {
    display: flex;
}

#${i}.previewing #${w},
#${i}.previewing #${S} {
	width: 1080px;
	height: 720px;
}

#${w},
#${S} {
    width: 400px;
    height: 640px;
	max-height: 100%;
	max-width: 100%;

	transition: all 300ms;

    flex: 0 1 auto;
    border-radius: var(--_myreach-iframe-radius);
    overflow: hidden;
    border: none;

	transform: translateY(0px);
}

#${w} {
    box-shadow:
        2px 6px 28px 0px rgba(12, 30, 70, 0.12),
        0px 0px 16px 0px rgba(17, 42, 96, 0.06),
        0px 0px 6px 0px rgba(13, 34, 80, 0.04),
        0px 0px 4px 0px rgba(9, 22, 70, 0.02),
        0px 0px 2px 0px rgba(0, 0, 0, 0.02)
        ;

    visibility: hidden;
}

#${S} {
	pointer-events: all;
	clip-path: inset(0 round var(--_myreach-iframe-radius));
}

#${i}.open #${w} {
    visibility: visible;
}

#${u} {
	position: relative;

	margin-top: 4px;

    flex: 0 0 auto;

	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	justify-content: flex-end;
}

#${u}[data-button-size="MEDIUM"] {
	--_myreach-button-size: var(--_myreach-button-size-medium);
	--_myreach-icon-size: var(--_myreach-icon-size-medium);
}

#${u}[data-button-size="LARGE"] {
	--_myreach-button-size: var(--_myreach-button-size-large);
	--_myreach-icon-size: var(--_myreach-icon-size-large);
}

#${V} {
	width: var(--_myreach-button-size);
	height: var(--_myreach-button-size);

	border-radius: 50%;

	background-color: var(${t});
	color: var(${r});
	border: none;

	display: flex;
	align-items: center;
	justify-content: center;

	padding: 0;
	overflow: hidden;

	cursor: pointer;
	pointer-events: all;
}

@media (hover: hover) {
    #${V}:hover {
        background-color: var(${a});
    }
        
    #${g} { 
        > p:hover {
            > button {
                display: flex;
                align-items: center;
            }
            
            > button:hover {
                > svg {
                    fill: var(${E});
                }
            }
        }    
    }
}

#${g} {
	display: none;

	position: absolute;
    top: 0;
    right: 0;
    transform: translateY(calc(-100% - 8px));

	width: 100%;

	pointer-events: all;

	flex-direction: column;
	align-items: flex-end;
	justify-content: flex-end;
	gap: 8px;

	> p {
        position: relative;
		margin: 0;
		padding: 12px 16px;
		border: 1px solid var(${o});
		white-space: nowrap;

		border-radius: 12px;
		border-bottom-right-radius: 0;

		background: var(${s});
		color: var(${n});

		white-space: break-spaces;

		font-size: max(var(--_myreach-min-font-size), calc((14 / 16) * 1rem));
        
        &.open {
            display: flex;
        }

        &:not(.open) {
            display: none;
        }

        > button {
            display: none;
            cursor: pointer;
            position: absolute;
            right: -8px;
            top: -8px;
            padding: 4px;
            border-radius: 50%;
            border-style: none;
            background-color: var(${o});
			color: var(${n});

            > svg {
                width: 16px;
                height: 16px;
                min-width: unset;
                min-height: unset;
            }
        }
	}
}

#${i}.at-left {
	#${u} {
		align-items: flex-start;
	}

	#${g} {
		left: 0;
		right: unset;
		align-items: flex-start;
		
		> p {
			border-bottom-right-radius: 12px;
			border-bottom-left-radius: 0;
		}
	}
}

#${i}.message-ready:not(.interacted) #${g},
#${i}.message-ready.always-show-welcome-messages:not(.open) #${g} {
    display: flex;
}

#${A} {
    display: none;
}


#${A},
#${$} {
	width: 100%;
	height: 100%;

	flex: 0 0 100%;
	
	align-items: center;
	justify-content: center;
}

#${A} {
	display: flex;
}

#${$} {
	display: none;
}

#${i}.open #${$} {
    display: flex;
}

#${i}.open #${A} {
    display: none;
}

#${u} #${L} {
	display: none;

	width: 100%;
	height: 100%;
}

#${i}.with-image #${L} {
	display: block;
}

#${i}.with-image #${A} svg {
	display: none;
}

#${u} svg {
    fill: currentColor;

    min-width: var(--_myreach-icon-size);
    width: var(--_myreach-icon-size);
    min-height: var(--_myreach-icon-size);
    height: var(--_myreach-icon-size);
}


@media ${k} {
	#${i}.allow-fullscreen {
		#${w} {
			width: 100%;
			flex: 1 1 auto;
			border-radius: 0px;
			box-shadow: none;
		}

		#${S} {
			width: 100%;
			height: 100%;

			border-radius: 0px;
		}
	}

	#${i}.allow-fullscreen.open {
		width: 100%;
		height: 100%;

		max-width: unset;
		max-height: unset;

		bottom: 0px;
		right: 0px;

		background-color: var(${s});
	}

	#${i}.allow-fullscreen.open.at-left {
		left: 0px;
	}

	#${i}.allow-fullscreen.open #${u} {
		display: none;
	}
    
    #${g} {
        > p {
            > button {
                display: flex;
            }
        }
    }
}
`;
}, re = (e, t) => {
  const a = document.createElement("style");
  return a.id = X, c(a, e), a.textContent = ae(e), t.appendChild(a), a;
}, K = (e, t) => {
  const a = (r) => {
    z(r.data, e) && t(r.data);
  };
  return window.addEventListener("message", a), () => {
    window.removeEventListener("message", a);
  };
}, se = "myreach-icon", j = `
<path fill-rule="evenodd" clip-rule="evenodd" d="M18.5303 5.46967C18.8232 5.76256 18.8232 6.23744 18.5303 6.53033L6.53033 18.5303C6.23744 18.8232 5.76256 18.8232 5.46967 18.5303C5.17678 18.2374 5.17678 17.7625 5.46967 17.4696L17.4696 5.46967C17.7625 5.17678 18.2374 5.17678 18.5303 5.46967Z"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.46967 5.46967C5.76256 5.17678 6.23744 5.17678 6.53033 5.46967L18.5303 17.4696C18.8232 17.7625 18.8232 18.2374 18.5303 18.5303C18.2374 18.8232 17.7625 18.8232 17.4696 18.5303L5.46967 6.53033C5.17678 6.23744 5.17678 5.76256 5.46967 5.46967Z"/>
`, oe = `
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.70717 3.80873C4.65425 2.86165 5.97956 2.35156 7.5 2.35156L16.5 2.35156C18.0204 2.35156 19.3457 2.86165 20.2928 3.80873C21.2399 4.75582 21.75 6.08113 21.75 7.60156V13.0016C21.75 14.5221 21.2399 15.8474 20.2928 16.7944C19.3457 17.7415 18.0204 18.2516 16.5 18.2516H13.1642L9.3651 21.3079C9.34767 21.3219 9.32963 21.3352 9.31101 21.3476C8.22193 22.0736 7 21.3246 7 20.0016V18.2516C5.7943 18.1105 4.49491 17.5822 3.70717 16.7944C2.76009 15.8474 2.25 14.5221 2.25 13.0016L2.25 7.60156C2.25 6.08113 2.76009 4.75582 3.70717 3.80873ZM11.3609 5.0018L11.38 5.00159C12.1182 5.00159 12.9945 5.18361 13.7133 5.68832C14.4717 6.22091 15 7.08031 15 8.25938C15 9.36843 14.618 10.1274 14.0541 10.6381C13.6533 11.0011 13.1325 11.2314 12.882 11.3421C12.8313 11.3646 12.7916 11.3821 12.7663 11.3948C12.5539 11.5017 12.4349 11.6054 12.3677 11.6988C12.3094 11.78 12.255 11.9007 12.255 12.1211C12.255 12.6074 11.8633 13.0016 11.38 13.0016C10.8968 13.0016 10.505 12.6074 10.505 12.1211C10.505 11.5642 10.6565 11.0747 10.9498 10.6667C11.2343 10.271 11.6128 10.0064 11.9837 9.8198C12.1174 9.75252 12.2308 9.70135 12.3309 9.65616C12.5549 9.55506 12.7126 9.4839 12.8834 9.3292C13.0486 9.17957 13.25 8.91129 13.25 8.25938C13.25 7.6775 13.0191 7.34824 12.7118 7.13242C12.367 6.89032 11.8751 6.76422 11.3897 6.76256C10.4229 6.78785 9.75 7.4349 9.75 8.25938C9.75 8.74566 9.35825 9.13986 8.875 9.13986C8.39175 9.13986 8 8.74566 8 8.25938C8 6.26901 9.65604 5.03922 11.3609 5.0018ZM11.4355 14.0016C10.8857 14.0016 10.44 14.4493 10.44 15.0016C10.44 15.5539 10.8857 16.0016 11.4355 16.0016H11.4445C11.9943 16.0016 12.44 15.5539 12.44 15.0016C12.44 14.4493 11.9943 14.0016 11.4445 14.0016H11.4355Z"/>
`, N = (e) => {
  const t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  return t.classList.add(se), t.setAttribute("viewBox", "0 0 24 24"), t.innerHTML = e, t;
}, ne = (e, t) => {
  const a = document.createElement("div");
  a.id = u, c(a, e);
  const r = document.createElement("div");
  r.id = g, c(r, e), a.appendChild(r);
  const s = document.createElement("button");
  s.id = V, c(s, e);
  const n = document.createElement("div");
  n.id = A, c(n, e);
  const o = document.createElement("img");
  o.id = L, c(o, e);
  const E = N(oe);
  n.appendChild(o), n.appendChild(E), s.appendChild(n);
  const d = document.createElement("div");
  d.id = $, c(d, e);
  const B = N(j);
  d.appendChild(B), s.appendChild(d), a.appendChild(s);
  let v = !1;
  return s.onclick = () => {
    v ? (f(e, y.SHOW_FEEDBACK_PAGE, { showFeedbackPage: !0 }), v = !1) : (f(e, y.SHOW_FEEDBACK_PAGE, { showFeedbackPage: !1 }), F(e));
  }, o.onload = () => {
    const m = l(i, e);
    m == null || m.classList.add("image-loaded");
  }, o.onerror = () => {
    const m = l(i, e);
    m == null || m.classList.add("image-failed");
  }, K(e, (m) => {
    m.type === _.SHOW_FEEDBACK_PAGE && (v = m.data.showFeedbackPage);
  }), t.appendChild(a), a;
}, ie = (e, t) => {
  if (!t)
    return;
  l(u, e).setAttribute("data-button-size", t);
}, de = (e, t) => {
  const a = l(i, e);
  if (!t) {
    a.classList.remove("with-image");
    return;
  }
  a.classList.add("with-image");
  const r = l(L, e);
  r.src = t;
}, le = (e, t) => {
  if (t.length === 0)
    return;
  const a = l(g, e);
  a && (Array.from(a.childNodes).forEach((s) => s.remove()), t.forEach((s, n) => {
    const o = document.createElement("p");
    o.id = `${J}-${n}`, c(o, e), o.textContent = s, o == null || o.classList.add("open");
    const E = document.createElement("button"), d = N(j);
    E.appendChild(d), E.onclick = () => {
      me(o.id, e);
    }, o.appendChild(E), a.appendChild(o);
  }));
  const r = l(i, e);
  r == null || r.classList.add("message-ready");
}, ce = (e) => {
  const t = l(i, e);
  t == null || t.classList.add("open"), t == null || t.classList.add("interacted");
}, he = (e) => {
  const t = l(i, e);
  t == null || t.classList.remove("open"), t == null || t.classList.add("interacted");
}, F = (e) => {
  const t = l(i, e);
  t == null || t.classList.toggle("open"), t == null || t.classList.add("interacted");
}, me = (e, t) => {
  const a = l(e, t);
  a == null || a.classList.remove("open");
}, I = /* @__PURE__ */ new Map(), U = (e, t) => {
  const a = l(i, e);
  if (a.classList.add("ready"), t.data.widget.pageLocationAtBottomLeft ? a.classList.add("at-left") : a.classList.remove("at-left"), !t.data.widget.tooltipMessagesDisabled) {
    const r = I.get(e);
    clearTimeout(r);
    const s = t.data.widget.tooltipMessages.length > 0 ? t.data.widget.tooltipMessages : t.data.defaults.tooltipMessages, n = window.setTimeout(() => {
      le(e, s);
    }, 1e3);
    I.set(e, n);
  }
  te(e, t.data.widget.colors, t.data.widget.theme), de(e, t.data.widget.header.iconSrc || null), ie(e, t.data.widget.buttonSize), ee(e);
}, ue = (e) => {
  l(i, e).classList.remove("open");
}, H = (e, t) => {
  const a = l(i, e), r = "previewing";
  t ? a.classList.add(r) : a.classList.remove(r);
}, Ee = (e, t, a) => {
  const r = document.createElement("div");
  r.id = w, c(r, e);
  const s = document.createElement("iframe");
  s.id = S;
  const n = new URL(import.meta.url);
  return n.pathname = `/widget/${e}`, t.debug && n.searchParams.set("debug", "true"), s.setAttribute("allow", "fullscreen"), s.setAttribute("allowfullscreen", "true"), s.src = n.href, s.width = "420px", s.height = "640px", c(s, e), r.appendChild(s), a.appendChild(r), r;
}, pe = (e) => {
  const t = l(i, e.widgetId);
  if (t)
    return t;
  re(e.widgetId, document.head);
  const a = document.createElement("div");
  a.id = i, e.debug && a.classList.add("debugmode"), e.allowFullscreen && a.classList.add("allow-fullscreen"), e.alwaysShowWelcomeMessages && a.classList.add("always-show-welcome-messages"), c(a, e.widgetId), Ee(e.widgetId, e, a), ne(e.widgetId, a);
  const r = (o) => {
    e.allowFullscreen && f(e.widgetId, y.UPDATE_FULLSCREEN, { isFullscreen: o });
  }, s = window.matchMedia(k);
  s.addEventListener("change", (o) => {
    r(o.matches);
  });
  const n = (o) => {
    try {
      if (z(o.data, e.widgetId)) {
        b(
          o.data,
          _.CHAT_READY,
          e.widgetId
        ) ? (U(e.widgetId, o.data), r(s.matches)) : b(
          o.data,
          _.CLOSE_IFRAME_CLICKED,
          e.widgetId
        ) ? ue(e.widgetId) : b(
          o.data,
          _.STYLES_UPDATED,
          e.widgetId
        ) ? U(e.widgetId, o.data) : b(
          o.data,
          _.SOURCE_PREVIEW_OPENED,
          e.widgetId
        ) ? H(e.widgetId, !0) : b(
          o.data,
          _.SOURCE_PREVIEW_CLOSED,
          e.widgetId
        ) && H(e.widgetId, !1);
        return;
      } else if (G(o.data, e.widgetId)) {
        T(o.data, C.OPEN_CHAT, e.widgetId) ? ce(e.widgetId) : T(
          o.data,
          C.CLOSE_CHAT,
          e.widgetId
        ) ? he(e.widgetId) : T(
          o.data,
          C.TOGGLE_CHAT,
          e.widgetId
        ) && F(e.widgetId);
        return;
      }
    } catch {
    }
  };
  return window.addEventListener("message", n), document.body.appendChild(a), a;
}, ge = (e) => {
  M(C.OPEN_CHAT, {}, e, window);
}, _e = (e) => {
  M(C.CLOSE_CHAT, {}, e, window);
}, Ce = (e) => {
  M(C.TOGGLE_CHAT, {}, e, window);
}, we = {
  openChat: ge,
  closeChat: _e,
  toggleChat: Ce
};
window.myreachEmbeddedChat = {
  createChat: pe,
  sendEvent: f,
  controlChat: we,
  eventListener: K
};
const P = Y(import.meta.url);
if (P && P.widgetId)
  try {
    window.myreachEmbeddedChat.createChat(P);
  } catch {
  }
window.dispatchEvent(new CustomEvent("myreach-embedded-chat-ready"));
