(() => { const getConfig = function () { const fourteenLoadedEventName = "FOURTEEN_INLINE_LOADED"; const fourteenOrigin = "https://widget.14.ai"; const iframe = document.createElement("iframe"); iframe.allow = "clipboard-write"; let didLoad = false; let isEmbedReady = false; let onReadyCallbacks = []; let onNotificationsChangeCallback = null; const sendMessage = (message) => { if (didLoad) { iframe.contentWindow.postMessage(message, fourteenOrigin); } else { window.addEventListener( fourteenLoadedEventName, () => { iframe.contentWindow.postMessage(message, fourteenOrigin); }, { once: true } ); } }; return { init: function (containerId) { const load = () => { const container = typeof containerId === 'string' ? document.getElementById(containerId) || document.querySelector(containerId) : containerId; if (!container) { console.error('[14.ai] Container element not found:', containerId); return; } iframe.src = "https://widget.14.ai/HNvcUmnTZyGUpjXT?mode=inline"; iframe.id = "HNvcUmnTZyGUpjXT-inline"; iframe.style.border = "0"; iframe.style.padding = "0"; iframe.style.margin = "0"; iframe.style.width = "100%"; iframe.style.height = "100%"; iframe.style.outline = "none"; iframe.style.display = "block"; iframe.style.background = "white"; iframe.style.borderRadius = "inherit"; iframe.addEventListener("load", () => { didLoad = true; window.dispatchEvent(new CustomEvent(fourteenLoadedEventName)); }); container.appendChild(iframe); window.addEventListener("message", (event) => { const eventType = event.data?.type; switch (eventType) { case "FOURTEEN_EMBED_NOTIFICATIONS_CHANGE_HNvcUmnTZyGUpjXT": { onNotificationsChangeCallback?.(event.data.numNotifications); break; } case "FOURTEEN_EMBED_READY_HNvcUmnTZyGUpjXT": { isEmbedReady = true; onReadyCallbacks.forEach((callback) => callback()); onReadyCallbacks = []; sendMessage({ type: 'FOURTEEN_SET_SOURCE', url: window.location.href }); break; } case "FOURTEEN_EMBED_UNREADY_HNvcUmnTZyGUpjXT": { isEmbedReady = false; break; } default: { break; } } }); }; if (document.readyState === "complete") { load(); } else { document.addEventListener("readystatechange", () => { if (document.readyState === "complete") { load(); } }); } }, setMetadata: (metadata) => { sendMessage({ metadata }); }, setUser: (emailOrObject, name) => { if (typeof emailOrObject === 'string') { sendMessage({ type: 'FOURTEEN_SET_USER', user: { email: emailOrObject, name } }); } else { sendMessage({ type: 'FOURTEEN_SET_USER', user: emailOrObject }); } }, setUserSecure: (encrypted) => { sendMessage({ type: 'FOURTEEN_SET_USER_SECURE', user: { encrypted } }); }, logout: () => { sendMessage({ type: 'FOURTEEN_LOGOUT_USER' }); }, onNotificationsChange: (callback) => { onNotificationsChangeCallback = callback; }, onReady: (callback) => { if (isEmbedReady) { callback(); } else { onReadyCallbacks.push(callback); } } }; }; // Unique instance for inline embed window.fourteenInline_HNvcUmnTZyGUpjXT = window.fourteenInline_HNvcUmnTZyGUpjXT || getConfig(); // If this is the first inline instance, also assign it to the global window.fourteenInline if (!window.fourteenInline) { window.fourteenInline = window.fourteenInline_HNvcUmnTZyGUpjXT; } })();