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AAe,KAAK,MAAM,EAAa,eAExD,MAAM,EAAgB,SAAS,cAAc,OAS7C,OARA,EAAc,aAAa,QAAS,qDACpC,EAAc,UAAY,kBACrB,WAAW,YAAa,EAAa,aAAa,OAClD,WAAW,cAAe,EAAa,aAAa,SACpD,WAAW,sBAAuB,EAAa,aAAa,iBAC5D,WAAW,gBAAiB,6FAEjC,EAAc,cAAc,oCAAoC,MAAM,gBAAkB,KAAK,aACtF,CACX,CAEA,MAAM,uBAAyB,oWAazB,yBAA2B,sMAO3B,kBAAoB,+uBAepB,mCAAqC","file":"/gh/addy-ai/customer-inquiry-bot@master/js/widget.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /gh/addy-ai/customer-inquiry-bot@master/js/widget.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const scriptTag = document.currentScript;\nconst queryString = window.location.search;\nconst urlParams = new URLSearchParams(queryString);\n// Get the data from the parent\nlet data = {};\nlet interactiveMode = false;\nlet widgetId = null;\nlet previousQuestionsAndAnswers = [];\nlet interactiveSectionState = [];\nlet currentQuestionIndex = 0;\nlet lastKnownQuestionUIState = {};\nlet previousWidgetIframeHeight = null;\nlet progressSnapshots = [];\n\nlet TOTAL_EXPECTED_QUESTIONS = 15;\nconst USE_MOCK_DATA = false;\nlet mockData = {\n    leadFunnelWidgetsConfig: {\n        heroSection: {\n            title: \"John Doe\",\n            description: \"Horizon Mortgage\",\n            image: \"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=150&h=150&fit=crop&crop=face\"\n        },\n        social: {\n            facebook: {\n                url: \"https://facebook.com/\",\n                icon: \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/facebook.svg\"\n            },\n            instagram: {\n                url: \"https://instagram.com/\",\n                icon: \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/instagram.svg\"\n            },\n            youtube: {\n                url: \"https://youtube.com/\",\n                icon: \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/youtube.svg\"\n            }\n        }\n    },\n};\n\nlet backendAPI;\n\nwindow.addEventListener(\"load\", async function () {\n    data = await getChatBotData();\n    if (!data) {\n        console.error(\"Error: No data found\");\n        return;\n    };\n    // console.log(\"Data\", data);\n    let env = scriptTag.getAttribute(\"env\") || \"development\";\n    const mode = scriptTag.getAttribute(\"mode\") || \"widget\";\n    \n    // Set the data object\n    data.env = env;\n    data.mode = mode;\n    data.primaryColor = data?.leadFunnelWidgetsConfig?.primaryColor || data?.primaryColor || \"#745DDE\";\n    \n    // Initialize leadFunnelWidgetsConfig for home mode if not present\n    if (mode === \"home\") {\n        if (!data.leadFunnelWidgetsConfig) {\n            data.leadFunnelWidgetsConfig = {};\n        }\n        \n        // Use mock data for testing if enabled\n        if (USE_MOCK_DATA) {\n            data.leadFunnelWidgetsConfig.heroSection = mockData.leadFunnelWidgetsConfig.heroSection;\n            data.leadFunnelWidgetsConfig.social = mockData.leadFunnelWidgetsConfig.social;\n        }\n    }\n    \n    // Set the CSS variable for primary color\n    document.documentElement.style.setProperty('--primary-color', data.primaryColor);\n    \n    backendAPI = data.env == \"development\" ? \"https://backend-dev-111911035666.us-central1.run.app\" : \"https://backend-prod-zquodzeuva-uc.a.run.app\"\n\n    if (data.env == \"test-local\") {\n        backendAPI = \"http://localhost:8080\";\n    }\n\n    // Render home mode specific sections\n    if (mode === \"home\") {\n        renderHeroSection(data.leadFunnelWidgetsConfig?.heroSection || mockData.leadFunnelWidgetsConfig.heroSection);\n        renderSocialIcons(data.leadFunnelWidgetsConfig?.social || mockData.leadFunnelWidgetsConfig.social);\n    }\n\n    // Get the widget ids to create from the scriptTag and the widget ids in the data\n    const widgetIdsToRender = scriptTag.getAttribute(\"widgets\")?.split(\",\") || [];\n    const agentPublicId = scriptTag.id;\n    initializeWidgets(widgetIdsToRender, agentPublicId);\n    listenForInteractiveResponse();\n\n    // Expose global function to programmatically trigger widgets\n    window.addyTriggerWidget = function(targetWidgetId) {\n        // Validate inputs\n        if (!targetWidgetId || typeof targetWidgetId !== 'string') {\n            console.error('[Addy Widget] Invalid widget ID provided');\n            return false;\n        }\n\n        // Check if widget is in the configured list to render\n        if (!widgetIdsToRender.includes(targetWidgetId)) {\n            console.error(`[Addy Widget] Widget \"${targetWidgetId}\" is not configured for this agent. Available widgets: ${widgetIdsToRender.join(', ')}`);\n            return false;\n        }\n\n        // Find the widget from the loaded data\n        const widget = data.leadFunnelWidgets.find(w => w.id === targetWidgetId);\n        if (!widget) {\n            console.error(`[Addy Widget] Widget \"${targetWidgetId}\" not found in agent configuration`);\n            return false;\n        }\n\n        // Set the interactive mode and widget id\n        interactiveMode = true;\n        widgetId = targetWidgetId;\n\n        // Add icon image if not present\n        if (!widget.iconImage) {\n            widget.iconImage = iconImageLookup[targetWidgetId] || \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/home.svg\";\n        }\n\n        // Trigger the widget view\n        createAgentView(widget);\n        \n        console.log(`[Addy Widget] Successfully triggered widget: ${targetWidgetId}`);\n        return true;\n    };\n\n    // Log available widgets for developers\n    console.log('[Addy Widget] Loaded successfully. Available widgets:', widgetIdsToRender);\n    console.log('[Addy Widget] Trigger widgets programmatically using: window.addyTriggerWidget(\"widget-id\")');\n});\n\nconst iconImageLookup = {\n    \"refinance\": \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/reload.svg\",\n    \"buy-home\": \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/home.svg\",\n    \"rates\": \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/chart.svg\",\n}\n\nasync function getChatBotData() {\n    let env = scriptTag?.getAttribute(\"env\") || \"development\";\n    let backend = url = window.location.host === ''\n        ? \"https://us-central1-hey-addy-chatgpt.cloudfunctions.net/businessInference/infer/bot-info-public\"\n        : \"https://us-central1-hey-addy-chatgpt.cloudfunctions.net/businessInference/infer/bot-info-public\"\n    if (env == \"development\") {\n        backend = \"https://us-central1-addy-ai-dev.cloudfunctions.net/businessInference/infer/bot-info-public\";\n    }\n    if (env == \"test\") {\n        backend = \"http://127.0.0.1:5003/addy-ai-dev/us-central1/businessInference/infer/bot-info-public\";\n    }\n    if (env == \"test-local\") {\n        backend = \"http://localhost:8080/embeddingsInference/infer/bot-info-public\";\n    }\n    // backend =\n    //   \"http://127.0.0.1:5003/addy-ai-dev/us-central1/businessInference/infer/bot-info-public\";\n    const publicId = scriptTag.id;\n    const host = window.location.host;\n    const data = await fetch(`${backend}/?publicId=${publicId}&host=${host}`, {\n        method: \"GET\",\n        headers: {\n            \"Content-Type\": \"application/json\"\n        }\n    })\n    .then((response) => response.json())\n    .then(data => { \n        if (!data.success) throw new Error(\"Error: No data found\");\n        const dataWithWidgets = {\n            ...data?.data?.config,\n            leadFunnelWidgets: data?.data?.leadFunnelWidgets,\n            leadFunnelWidgetsConfig: data?.data?.leadFunnelWidgetsConfig,\n        }\n        return dataWithWidgets;\n    })\n    .catch((error) => {\n        console.error(\"Error\", error);\n        return undefined;\n    });\n    \n    if (!data) return undefined;\n    data.primaryColor ||= \"#745DDE\";\n    data.primaryColorName ||= \"Purple\";\n    data.publicId = scriptTag.id;\n    data.host = window.location.host;\n    data.env = env;\n    return data;\n}\n\nfunction renderHeroSection(heroData) {\n    if (!heroData) return;\n    \n    const heroContainer = document.querySelector('.addy-widget-hero-container');\n    if (!heroContainer) return;\n    \n    heroContainer.innerHTML = `\n        <div class=\"addy-hero-content\">\n            ${heroData.image ? `<img src=\"${heroData.image}\" alt=\"${heroData.title || ''}\" class=\"addy-hero-image\" />` : ''}\n            <div class=\"addy-hero-content-text\">\n                ${heroData.title ? `<h1 class=\"addy-hero-title\">${heroData.title}</h1>` : ''}\n                ${heroData.description ? `<p class=\"addy-hero-description\">${heroData.description}</p>` : ''}\n            </div>\n        </div>\n    `;\n    \n    // Set the hero section background to primary color\n    heroContainer.style.backgroundColor = data.primaryColor;\n}\n\nfunction renderSocialIcons(socialData) {\n    if (!socialData) return;\n    \n    const iconsContainer = document.querySelector('.addy-widget-icons-container');\n    if (!iconsContainer) return;\n    \n    let socialHTML = '<div class=\"addy-social-icons\">';\n    \n    Object.keys(socialData).forEach(platform => {\n        const social = socialData[platform];\n        if (social.url) {\n            socialHTML += `\n                <a href=\"${social.url}\" target=\"_blank\" class=\"addy-social-link\">\n                    ${social.icon ? `<img src=\"${social.icon}\" alt=\"${platform}\" class=\"addy-social-icon\" />` : ''}\n                    <span class=\"addy-social-label\">${platform.charAt(0).toUpperCase() + platform.slice(1)}</span>\n                </a>\n            `;\n        }\n    });\n    \n    socialHTML += '</div>';\n    iconsContainer.innerHTML = socialHTML;\n}\n\nfunction initializeWidgets(widgetIdsToRender, agentPublicId) {\n    const styleSheetLink = scriptTag.getAttribute(\"env\") &&\n        scriptTag.getAttribute(\"env\").includes(\"local\") ?\n        \"css/style.css\" :\n        \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/css/style.min.css\";\n    \n    // Inject CSS into current document (for widget cards)\n    if (!document.head.querySelector(`link[href=\"${styleSheetLink}\"]`)) {\n        const linkElement = document.createElement(\"link\");\n        linkElement.setAttribute(\"rel\", \"stylesheet\");\n        linkElement.setAttribute(\"href\", styleSheetLink);\n        document.head.appendChild(linkElement);\n    }\n    \n    // Try to inject CSS into parent document (for full-screen overlays)\n    // Wrap in try-catch to handle cross-origin restrictions\n    try {\n        if (!window.parent.document.head.querySelector(`link[href=\"${styleSheetLink}\"]`)) {\n            const parentLinkElement = document.createElement(\"link\");\n            parentLinkElement.setAttribute(\"rel\", \"stylesheet\");\n            parentLinkElement.setAttribute(\"href\", styleSheetLink);\n            window.parent.document.head.appendChild(parentLinkElement);\n        }\n    } catch (error) {\n        // Cross-origin restriction - parent injection failed, but current document has CSS\n        console.log('[Addy Widget] Parent CSS injection skipped (cross-origin)');\n    }\n    // Only render the widgets that are in the widgetIdsToRender array\n    data.leadFunnelWidgets.forEach(widget => {\n        if (!widgetIdsToRender.includes(widget.id)) {\n            return;\n        }\n        console.log(\"Widget id to render\", widget.id);\n        const widgetCard = createWidgetCard({...widget,\n            iconImage: iconImageLookup[widget.id] || \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/home.svg\"\n        });\n        // Find all elements where addy-widget-id = agentPublicId  && widgets == scriptTag.widgets\n        let widgetCardContainers = document.body.querySelectorAll(`[addy-widget-id=\"${agentPublicId}\"][widgets=\"${scriptTag.getAttribute(\"widgets\")}\"]`);\n        // find the parent of this script tag\n        const scriptTagParent = scriptTag?.parentElement;\n        // If widget card containers is empty, then add script tag parent to the widget card containers\n        if (widgetCardContainers.length === 0 && scriptTagParent) {\n            widgetCardContainers = [scriptTagParent];\n        }\n        // console.log(\"Widget card containers\", widgetCardContainers);\n        widgetCardContainers.forEach(container => {\n            container.appendChild(widgetCard);\n            // Update the style to be horizontal flex, justify content center, align items center\n            container.setAttribute(\"class\", \"addy-widget-card-container\");\n        });\n        // Add event listener to the button\n        widgetCard.querySelector(\"button\").addEventListener(\"click\", () => {\n            interactiveMode = true;\n            widgetId = widget.id;\n            createAgentView(widget);\n        });\n    });\n}\n\nfunction startFullScreenInteractiveMode(agentView) {\n    // Create an overlay, add to window.parent.document.body z-index,\n    // and then append the agent view to the overlay\n    const overlay = document.createElement(\"div\");\n    overlay.setAttribute(\"class\", \"addy-agent-view-overlay\");\n    window.parent.document.body.appendChild(overlay);\n\n    // Append the agent view to the overlay\n    overlay.appendChild(agentView);\n}\n\nfunction endFullScreenInteractiveMode() {\n    // I feel like this could be useful one day\n}\n\nfunction createWidgetCard(widget) {\n    let widgetCard = document.createElement(\"div\");\n    widgetCard.setAttribute(\"class\", \"addy-widget-card-parent\");\n\n    // Create a copy of the template\n    let template = widgetCardHTMLTemplate.replaceAll(\"{{primaryColor}}\", data.primaryColor);\n\n    // Replace all occurrences of {{key}} with the corresponding value\n    Object.keys(widget).forEach(key => {\n        const regex = new RegExp(`{{${key}}}`, 'g');\n        template = template.replace(regex, widget[key]);\n    });\n\n    widgetCard.innerHTML = template;\n\n    // Add extra buttons (Calendly link and custom links)\n    const extraButtonsContainer = widgetCard.querySelector('.addy-widget-extra-buttons');\n    const primaryColor = data.leadFunnelWidgetsConfig?.primaryColor || data.primaryColor;\n\n    // Style the container inline (since CSS may not be updated on CDN)\n    if (extraButtonsContainer) {\n        extraButtonsContainer.style.display = 'flex';\n        extraButtonsContainer.style.flexDirection = 'column';\n        extraButtonsContainer.style.gap = '8px';\n        extraButtonsContainer.style.width = '100%';\n        extraButtonsContainer.style.marginTop = '8px';\n    }\n\n    // Helper function to apply button styles inline (so it works even before CSS is updated on CDN)\n    const applyButtonStyles = (btn, bgColor) => {\n        btn.style.display = 'block';\n        btn.style.width = '100%';\n        btn.style.padding = '0.75rem 1.5rem';\n        btn.style.borderRadius = '9999px';\n        btn.style.backgroundColor = bgColor;\n        btn.style.color = 'white';\n        btn.style.textAlign = 'center';\n        btn.style.textDecoration = 'none';\n        btn.style.fontSize = '1rem';\n        btn.style.fontWeight = '500';\n        btn.style.cursor = 'pointer';\n        btn.style.boxSizing = 'border-box';\n        btn.style.transition = 'transform 0.3s ease';\n    };\n\n    // Helper function to ensure URL has a protocol (prevents relative URL issues)\n    const ensureAbsoluteUrl = (url) => {\n        if (!url) return url;\n        // If URL doesn't start with http:// or https://, prepend https://\n        if (!/^https?:\\/\\//i.test(url)) {\n            return 'https://' + url;\n        }\n        return url;\n    };\n\n    // Add Calendly \"Book a Call\" button (only if calendlyLink has actual content)\n    const calendlyLink = data.leadFunnelWidgetsConfig?.calendlyLink?.trim();\n    if (calendlyLink) {\n        const calendlyBtn = document.createElement('a');\n        calendlyBtn.href = ensureAbsoluteUrl(calendlyLink);\n        calendlyBtn.target = '_blank';\n        calendlyBtn.className = 'addy-widget-secondary-btn';\n        applyButtonStyles(calendlyBtn, primaryColor);\n        calendlyBtn.textContent = 'Book a Call';\n        extraButtonsContainer.appendChild(calendlyBtn);\n    }\n\n    // Add custom links (only if both label and url have actual content)\n    const customLinks = data.leadFunnelWidgetsConfig?.customLinks || [];\n    customLinks.forEach(link => {\n        const label = link.label?.trim();\n        const url = link.url?.trim();\n        if (label && url) {\n            const linkBtn = document.createElement('a');\n            linkBtn.href = ensureAbsoluteUrl(url);\n            linkBtn.target = '_blank';\n            linkBtn.className = 'addy-widget-secondary-btn';\n            applyButtonStyles(linkBtn, primaryColor);\n            linkBtn.textContent = label;\n            extraButtonsContainer.appendChild(linkBtn);\n        }\n    });\n\n    return widgetCard;\n}\n\nfunction closeTheView() {\n    // Get agent view\n    const agentView = window.parent.document.body.querySelector(\".addy-agent-view\");\n    if (agentView) {\n        // If current question is rateQuote, ask the user if they really want to exit, yes or no\n        const currentQuestion = interactiveSectionState[currentQuestionIndex];\n        if (currentQuestion && currentQuestion.type == \"rateQuote\") {\n            const confirmExit = confirm(\"Are you sure you want to exit the quote?\");\n            if (!confirmExit) {\n                return;\n            } else {\n                // User wants to exit, reset the whole question flow\n                previousQuestionsAndAnswers = [];\n                currentQuestionIndex = 0;\n                interactiveSectionState = [];\n            }\n        }\n        // Remove the overlay\n        const overlay = window.parent.document.body.querySelector(\".addy-agent-view-overlay\");\n        if (overlay) {\n            overlay.remove();\n        }\n        agentView.remove();\n        endFullScreenInteractiveMode();\n    }\n}\n\nasync function createAgentView(widget) {\n    // Create a full screen overlay with a close button at the top right\n    // The overlay should be scrollable and have the class \"addy-custom-scroll\"\n    let agentView = document.createElement(\"div\");\n    agentView.setAttribute(\"class\", \"addy-agent-view\");\n    \n    // Add fullscreen class if widget has fullScreenMode set to true\n    if (widget.fullScreenMode === true) {\n        agentView.classList.add(\"addy-agent-view-fullscreen\");\n    }\n    \n    agentView.innerHTML = `\n        <div class=\"addy-agent-view-header-container\">\n            <button class=\"addy-close-button\">\n                <img src=\"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/close.svg\" />\n            </button>\n        </div>\n    `;\n    // Create a header which will have a progress bar and then right below will\n    // be a back button to go back to the previous question.\n    // Back button should be disabled if the user is on the first question.\n    let header = document.createElement(\"div\");\n    header.setAttribute(\"class\", \"addy-agent-view-header\");\n    header.innerHTML = `\n        <div class=\"addy-agent-view-progress-bar\">\n            <div class=\"addy-agent-view-progress-bar-fill\" style=\"background-color: ${data.primaryColor};\"></div>\n        </div>\n        <div class=\"addy-agent-view-header-back-button-container\">\n            <button class=\"addy-back-button\">\n                <img width=\"22\" height=\"22\" src=\"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/back.svg\" />\n            </button>\n            <!-- Three dots loader -->\n            <div class=\"addy-three-dots-loader\">\n                <div class=\"dot-pulse\"></div>\n            </div>\n            <p class=\"addy-agent-view-header-progress-text\">0%</p>\n        </div>\n    `;\n    let agentViewContent = document.createElement(\"div\");\n    agentViewContent.setAttribute(\"class\", \"addy-agent-view-content\");\n\n    agentViewContent.appendChild(header);\n\n    agentView.appendChild(agentViewContent);\n    // Get close button and create the action to close the agent view\n    let closeButton = agentView.querySelector(\".addy-close-button\");\n    closeButton.addEventListener(\"click\", () => {\n        closeTheView();\n    });\n    \n    // Add back button click listener\n    let backButton = agentView.querySelector(\".addy-back-button\");\n    backButton.addEventListener(\"click\", handleBackButtonClick);\n\n    // document.body.appendChild(agentView);\n    startFullScreenInteractiveMode(agentView);\n\n    // Reset the current question index\n    currentQuestionIndex = 0;\n    interactiveSectionState = [];\n    progressSnapshots = [];\n\n    // Create the content\n    getNextQuestion();\n    \n    // Ensure progress/back button hidden initially\n    const agentViewDom = window.parent.document.body.querySelector(\".addy-agent-view\");\n    if (agentViewDom) {\n        const progressText = agentViewDom.querySelector(\".addy-agent-view-header-progress-text\");\n        const progressWrapper = agentViewDom.querySelector(\".addy-agent-view-progress-bar\");\n        const backButton = agentViewDom.querySelector(\".addy-back-button\");\n        if (progressText) {\n            progressText.style.display = \"none\";\n            progressText.textContent = \"0%\";\n        }\n        if (progressWrapper) {\n            progressWrapper.style.display = \"none\";\n        }\n        if (backButton) {\n            backButton.style.display = \"none\";\n        }\n    }\n}\n\n\n\nfunction handleBackButtonClick() {\n    console.log(\"[Back] Current question index:\", currentQuestionIndex, \"TOTAL:\", TOTAL_EXPECTED_QUESTIONS);\n    // currentQuestionIndex matches data-question-index of current view\n    // Can't go back if we're on the first question (index 1)\n    if (currentQuestionIndex <= 1) return;\n\n    // DOM element index for previous question (currentQuestionIndex - 1)\n    const previousDOMIndex = currentQuestionIndex - 1;\n    \n    console.log(\"[Back] Looking for previous question element at DOM index\", previousDOMIndex);\n    const previousQuestionElement = window.parent.document.querySelector(`.addy-agent-form-section[data-question-index=\"${previousDOMIndex}\"]`);\n    \n    if (previousQuestionElement) {\n        // Hide all question elements\n        window.parent.document.querySelectorAll('.addy-agent-form-section').forEach(el => {\n            el.style.display = 'none';\n        });\n        \n        // Show the previous question element\n        previousQuestionElement.style.display = 'flex';\n\n        // Update currentQuestionIndex to reflect the new position\n        currentQuestionIndex = previousDOMIndex;\n\n        // Apply stored progress snapshot for this question\n        applyProgressSnapshot(currentQuestionIndex);\n\n        const progressWrapper = window.parent.document.querySelector(\".addy-agent-view-progress-bar\");\n        const progressText = window.parent.document.querySelector(\".addy-agent-view-header-progress-text\");\n        if (currentQuestionIndex <= 1) {\n            window.parent.document.querySelector(\".addy-back-button\").style.display = \"none\";\n            if (progressWrapper) {\n                progressWrapper.style.display = \"none\";\n            }\n            if (progressText) {\n                progressText.style.display = \"none\";\n            }\n        } else {\n            window.parent.document.querySelector(\".addy-back-button\").style.display = \"block\";\n            if (progressWrapper) {\n                progressWrapper.style.display = \"block\";\n            }\n            if (progressText) {\n                progressText.style.display = \"block\";\n            }\n        }\n    } else {\n        console.log(\"[Back] No previous question element found at DOM index\", previousDOMIndex);\n    }\n}\n\nfunction handleNextQuestion(nextQuestion, options = {}) {\n    const { isCached = false } = options;\n    \n    // Parse nextQuestion question data as JSON if it's a string\n    if (nextQuestion?.nextQuestion && typeof nextQuestion.nextQuestion == \"string\") {\n        nextQuestion.nextQuestion = JSON.parse(nextQuestion.nextQuestion);\n    }\n    if (nextQuestion.type == \"endOfFlow\") {\n        // Remove the current question element\n        if (window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-agent-form-section\")) {\n            window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-agent-form-section\").remove();\n        }\n        // Get the last \".addy-agent-form-section\" element and hide it\n        const lastQuestionElement = window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-agent-form-section:last-child\");\n        if (lastQuestionElement) {\n            lastQuestionElement.style.display = \"none\";\n        }\n        // Create success screen\n        const successScreen = createSuccessScreen(nextQuestion);\n        // Close button on click listener\n        successScreen.querySelector(\".addy-interactive-primary-button\").addEventListener(\"click\", () => {\n            closeTheView();\n        });\n        \n        window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-agent-view-content\").appendChild(successScreen);\n        return;\n    }    \n    // Store the question state at the current index (before incrementing)\n    interactiveSectionState[currentQuestionIndex] = nextQuestion;\n    // Increment to get the DOM index for this question\n    currentQuestionIndex++;\n    \n    // Check if we already have a question element at this index (must check in parent document!)\n    let nextQuestionElement = window.parent.document.querySelector(`.addy-agent-form-section[data-question-index=\"${currentQuestionIndex}\"]`);\n    let isNewElement = false;\n\n    if (!nextQuestionElement) {\n        // Create new question element if it doesn't exist\n        isNewElement = true;\n        nextQuestionElement = createNextQuestionElement(nextQuestion);\n        nextQuestionElement.setAttribute('data-question-index', currentQuestionIndex);\n        // \"addy-agent-view\" is now in the window.parent.document.body\n        window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-agent-view-content\").appendChild(nextQuestionElement);\n    }\n    \n    // Hide all question elements\n    window.parent.document.querySelectorAll('.addy-agent-form-section').forEach(el => {\n        el.style.display = 'none';\n    });\n    \n    // Show the current question element\n    nextQuestionElement.style.display = 'flex';\n\n    // Adjust the iframe height to fit the content\n    const iframe = nextQuestionElement.querySelector(\".addy-interactive-iframe\");\n    updateIframeHeightToItsContent(iframe, nextQuestion);\n\n    // Only add event listener for NEW elements to avoid duplicate handlers\n    if (isNewElement) {\n        addNextButtonOnClickListener(nextQuestionElement, nextQuestion);\n    }\n\n    // Only update TOTAL_EXPECTED_QUESTIONS on FRESH API calls, not cached navigation\n    // This prevents percentage jumps when navigating back and forth\n    if (!isCached) {\n        let numberOfQuestionsLeft = nextQuestion.nextQuestion?.numberOfQuestionsLeft;\n        if (numberOfQuestionsLeft !== undefined && numberOfQuestionsLeft !== null) {\n            TOTAL_EXPECTED_QUESTIONS = numberOfQuestionsLeft + currentQuestionIndex;\n        }\n        console.log(\"[Forward] Fresh API - Updated TOTAL:\", TOTAL_EXPECTED_QUESTIONS);\n    }\n    \n    console.log(\"[Forward] Question index:\", currentQuestionIndex, \"TOTAL:\", TOTAL_EXPECTED_QUESTIONS, \"Cached:\", isCached);\n\n    // Capture and apply progress snapshot for this question\n    const progressFraction = TOTAL_EXPECTED_QUESTIONS > 0 ? currentQuestionIndex / TOTAL_EXPECTED_QUESTIONS : 0;\n    const progressPercent = Math.min(100, Math.max(0, Math.round(progressFraction * 100)));\n    const progressWidth = Math.min(100, Math.max(0, progressFraction * 100));\n    progressSnapshots[currentQuestionIndex] = { percent: progressPercent, width: progressWidth };\n    updateProgressIndicators(progressWidth, progressPercent);\n\n    // If the previousQuestionsAndAnswers array is < 2, don't show the back button\n    if (previousQuestionsAndAnswers.length < 1) {\n        window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-back-button\").style.display = \"none\";\n        window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-agent-view-header-progress-text\").style.display = \"none\";\n        window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-agent-view-progress-bar\").style.display = \"none\";\n    } else {\n        window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-back-button\").style.display = \"block\";\n        window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-agent-view-header-progress-text\").style.display = \"block\";\n        window.parent.document.body.querySelector(\".addy-agent-view\").querySelector(\".addy-agent-view-progress-bar\").style.display = \"block\";\n    }\n}\n\nfunction updateProgressIndicators(progressWidth, progressPercent) {\n    const agentView = window.parent.document.body.querySelector(\".addy-agent-view\");\n    if (!agentView) {\n        return;\n    }\n    const progressBar = agentView.querySelector(\".addy-agent-view-progress-bar-fill\");\n    const progressText = agentView.querySelector(\".addy-agent-view-header-progress-text\");\n    const progressWrapper = agentView.querySelector(\".addy-agent-view-progress-bar\");\n\n    if (progressBar) {\n        progressBar.style.width = `${progressWidth}%`;\n        progressBar.style.backgroundColor = data.primaryColor;\n    }\n    if (progressText) {\n        progressText.textContent = `${progressPercent}%`;\n        progressText.style.display = \"block\";\n    }\n    if (progressWrapper) {\n        progressWrapper.style.display = \"block\";\n    }\n}\n\nfunction applyProgressSnapshot(domIndex) {\n    if (domIndex === undefined || domIndex === null) {\n        return;\n    }\n    const snapshot = progressSnapshots[domIndex];\n    if (snapshot) {\n        updateProgressIndicators(snapshot.width, snapshot.percent);\n        return;\n    }\n    const fraction = TOTAL_EXPECTED_QUESTIONS > 0 ? domIndex / TOTAL_EXPECTED_QUESTIONS : 0;\n    const percent = Math.min(100, Math.max(0, Math.round(fraction * 100)));\n    updateProgressIndicators(Math.min(100, Math.max(0, fraction * 100)), percent);\n}\n\nfunction addNextButtonOnClickListener(nextQuestionElement, nextQuestion) {\n    const nextButton = nextQuestionElement.querySelector(\".addy-interactive-primary-button\");\n\n    if (nextButton) {\n        // Mark button as having listener to prevent duplicates\n        if (nextButton.hasAttribute('data-listener-added')) {\n            return;\n        }\n        nextButton.setAttribute('data-listener-added', 'true');\n        \n        if (nextQuestion.type == \"rateQuote\") {\n            // Change next button text to \"Continue full application\"\n            nextButton.innerHTML = nextQuestion.nextQuestion.buttonText;\n            // Get the simple paragraph and insert right before the next button\n            const simpleParagraph = createSimpleParagraph(nextQuestion.nextQuestion.continuePrompt);\n            nextQuestionElement.insertBefore(simpleParagraph, nextButton);\n        }\n        nextButton.addEventListener(\"click\", () => {\n            if (nextQuestion.type == \"rateQuote\") {\n                // Redirect to the redirectUrl in new tab\n                window.open(nextQuestion.nextQuestion.redirectUrl, \"_blank\");\n            } else {\n                getNextQuestion();\n            }\n        });\n    }\n}\n\nfunction createSimpleParagraph(text) {\n    const paragraph = document.createElement(\"p\");\n    paragraph.innerHTML = text;\n    paragraph.setAttribute(\"class\", \"addy-simple-paragraph\");\n    return paragraph;\n}\n\nfunction updateIframeHeightToItsContent(iframe, interactiveData) {\n    if (!iframe) {\n        return;\n    };\n    iframe.addEventListener('load', async () => {\n        let additionalHeight = interactiveData?.type == \"textInput\" ? 20 : 20;\n        if (interactiveData?.type == \"rateQuote\") {\n            additionalHeight = 5;\n        }\n        \n        let contentHeight = iframe.contentWindow.document.body.scrollHeight + additionalHeight;\n        iframe.style.height = `${contentHeight}px`;\n    });\n}\n\nfunction createNextQuestionElement(nextQuestion) {\n    let nextQuestionElement = document.createElement(\"div\");\n    nextQuestionElement.setAttribute(\"class\", \"addy-agent-form-section\");\n    \n    let questionData = nextQuestion?.nextQuestion;\n    if (!questionData) {\n        throw new Error(\"No question data found\");\n    }\n    // If questionData is a string, parse it\n    if (typeof questionData == \"string\") {\n        questionData = JSON.parse(questionData);\n    }\n    // Question data found, create \n    // This is interactive mode\n    let innerHTML = nextQuestionHTMLTemplate\n        .replaceAll(\"{{question}}\", questionData.question);\n\n    nextQuestionElement.innerHTML = innerHTML;\n\n    // Create the iframe to load the answer capture ui\n    let iframe = document.createElement(\"iframe\");\n    iframe.setAttribute(\"class\", \"addy-interactive-iframe\");\n    // set border to none\n    iframe.style.border = \"none\";\n    iframe.setAttribute(\"srcdoc\", nextQuestion.uiComponent);\n    nextQuestionElement.appendChild(iframe);\n\n    // If the next question type is communicationPreferencesWithConsentCheckbox, then append the privacy policy and terms of service link\n    if (nextQuestion.type == \"communicationPreferencesWithConsentCheckbox\") {\n        const privacyPolicyAndTermsOfService = document.createElement(\"div\");\n        privacyPolicyAndTermsOfService.innerHTML = privacyPolicyAndTermsOfServiceHTML\n            .replaceAll(\"{{privacyPolicyURL}}\", data.privacyPolicyURL || \"https://addy.so/privacypolicy\")\n            .replaceAll(\"{{termsOfServiceURL}}\", data.termsOfServiceURL || \"https://addy.so/termsofservice\");\n        nextQuestionElement.appendChild(privacyPolicyAndTermsOfService);\n    }\n\n    // Create a button if needed\n    if (nextQuestion.type != \"selector\") {\n        let nextButton = document.createElement(\"button\");\n        nextButton.setAttribute(\"class\", \"addy-interactive-primary-button\");\n        nextButton.innerHTML = \"Next\";\n        nextButton.style.backgroundColor = data.primaryColor;\n        nextButton.style.marginBottom = \"10px\";\n        nextButton.style.marginTop = \"20px\";\n        nextQuestionElement.appendChild(nextButton);\n    }\n\n    return nextQuestionElement;\n}\n\nfunction listenForInteractiveResponse() {\n    // Add the listener to the parent window\n    window.parent.addEventListener(\"message\", (event) => {\n        if (event.data.answerSelected) {\n            const question = event.data.answerSelected.question;\n            const answer = event.data.answerSelected.answer;\n            if (!(question && answer)) {\n                console.error(\"No question or answer found\");\n                return;\n            }\n            \n            // The current question's data index is currentQuestionIndex - 1\n            // (since currentQuestionIndex is the DOM index which starts at 1)\n            const currentDataIndex = currentQuestionIndex - 1;\n            \n            // Guard against edge case where no question is displayed yet\n            if (currentDataIndex < 0) {\n                console.error(\"[Answer] Invalid state: currentDataIndex is\", currentDataIndex);\n                return;\n            }\n            \n            console.log(\"[Answer] Question:\", question, \"at dataIndex:\", currentDataIndex, \"DOM index:\", currentQuestionIndex);\n            \n            // Check if answer changed by comparing with stored answer at current position\n            let answerChanged = false;\n            if (previousQuestionsAndAnswers[currentDataIndex]) {\n                if (previousQuestionsAndAnswers[currentDataIndex].answer !== answer) {\n                    answerChanged = true;\n                    console.log(\"[Answer] Answer CHANGED from:\", previousQuestionsAndAnswers[currentDataIndex].answer, \"to:\", answer);\n                }\n                previousQuestionsAndAnswers[currentDataIndex] = { question, answer };\n            } else {\n                // New question at this index\n                previousQuestionsAndAnswers[currentDataIndex] = { question, answer };\n            }\n            \n            // Save the last known question UI state\n            lastKnownQuestionUIState[question] = event.data.answerSelected.uiState;\n\n            // If the answer changed, clear cached states for subsequent questions\n            if (answerChanged) {\n                console.log(\"[AnswerChange] Clearing cache from dataIndex\", currentDataIndex + 1, \"onwards\");\n                \n                // Clear all cached states AFTER the current question\n                // Keep indices 0 through currentDataIndex\n                interactiveSectionState = interactiveSectionState.slice(0, currentDataIndex + 1);\n                \n                // Truncate previousQuestionsAndAnswers to match\n                previousQuestionsAndAnswers = previousQuestionsAndAnswers.slice(0, currentDataIndex + 1);\n                \n                // Trim stored progress snapshots as well\n                progressSnapshots = progressSnapshots.slice(0, currentQuestionIndex + 1);\n                \n                // Remove DOM elements for questions after the current one\n                // DOM index > currentQuestionIndex means it's after the current question\n                const allQuestionElements = window.parent.document.querySelectorAll('.addy-agent-form-section');\n                allQuestionElements.forEach(el => {\n                    const elIndex = parseInt(el.getAttribute('data-question-index'));\n                    if (elIndex > currentQuestionIndex) {\n                        console.log(\"[AnswerChange] Removing DOM element at index\", elIndex);\n                        el.remove();\n                    }\n                });\n                \n                console.log(\"[AnswerChange] Cache size after clear:\", interactiveSectionState.length);\n            }\n            \n            // For selector type, get next question immediately\n            // For other types, wait for the next button click\n            if (event.data.answerSelected.type == \"selector\") {\n                getNextQuestion();\n            }\n        }\n    });\n}\n\nasync function sleep(ms) {\n    return new Promise(resolve => setTimeout(resolve, ms));\n}\n\nasync function getNextQuestion() {\n    // Have a little delay for better user experience\n    await sleep(300);\n    \n    console.log(\"[GetNext] Current index:\", currentQuestionIndex, \"Checking cache at index:\", currentQuestionIndex);\n    \n    // If we have a previously answered question at the current index, use that instead of making a new API call\n    if (interactiveSectionState[currentQuestionIndex]) {\n        console.log(\"[GetNext] Using CACHED data for next question\");\n        handleNextQuestion(interactiveSectionState[currentQuestionIndex], { isCached: true });\n        return;\n    }\n\n    console.log(\"[GetNext] No cache, making API call\");\n    showLoader();\n    const nextQuestionResponse = await makeAPICallForNextQuestion();\n    if (nextQuestionResponse?.nextQuestion) {\n        hideLoader();\n        handleNextQuestion(nextQuestionResponse, { isCached: false });\n    }\n}\n\nfunction showLoader() {\n    // Show the three dots loader\n    const threeDotsLoader = window.parent.document.body.querySelector(\".addy-three-dots-loader\");\n    if (threeDotsLoader) {\n        threeDotsLoader.style.display = \"flex\";\n    }\n    // Hide agent form section\n    const agentFormSections = window.parent.document.body.querySelectorAll(\".addy-agent-form-section\");\n    if (agentFormSections) {\n        agentFormSections.forEach(section => {\n            section.style.visibility = \"hidden\";\n        });\n    }\n}\n\nfunction hideLoader() {\n    // Hide the three dots loader\n    const threeDotsLoader = window.parent.document.body.querySelector(\".addy-three-dots-loader\");\n    if (threeDotsLoader) {\n        threeDotsLoader.style.display = \"none\";\n    }\n    // Show agent form section\n    const agentFormSections = window.parent.document.body.querySelectorAll(\".addy-agent-form-section\");\n    if (agentFormSections) {\n        agentFormSections.forEach(section => {\n            section.style.visibility = \"visible\";\n        });\n    }\n}\n\nasync function makeAPICallForNextQuestion() {\n    const payload = {\n        uid: \"chatbot-website\",\n        agentPublicId: data.publicId,\n        previousQuestionsAndAnswers: previousQuestionsAndAnswers,\n        widgetId: widgetId,\n    };\n    const requestOptions = {\n        method: \"POST\",\n        headers: { \"Content-Type\": \"application/json\" },\n        body: JSON.stringify(payload),\n    };\n    const response = await fetch(backendAPI + \"/api/loan-pricing-agent/get-next-question\", requestOptions)\n        .then(response => {\n            if (!response.ok) {\n                if (response.status === 500) {\n                    alert(\"Sorry something went wrong, please check your answer and try again.\");\n                    return;\n                }\n                throw new Error(`HTTP error! status: ${response.status}`);\n            }\n            return response.json();\n        })\n        .then(data => {\n            return data;\n        })\n        .catch(error => {\n            console.error(\"Error making API call for next question\", error);\n        });\n    return response;\n}\n\nfunction createSuccessScreen(nextQuestion) {\n    // Parse next question as JSON\n    if (typeof nextQuestion.nextQuestion == \"string\") {\n        nextQuestion.nextQuestion = JSON.parse(nextQuestion.nextQuestion);\n    }\n    const successScreen = document.createElement(\"div\");\n    successScreen.setAttribute(\"class\", \"addy-agent-form-section addy-agent-success-screen\");\n    successScreen.innerHTML = successScreenHTML\n        .replaceAll(\"{{title}}\", nextQuestion.nextQuestion.title)\n        .replaceAll(\"{{message}}\", nextQuestion.nextQuestion.message)\n        .replaceAll(\"{{closeButtonText}}\", nextQuestion.nextQuestion.closeButtonText)\n        .replaceAll(\"{{checkIcon}}\", \"https://cdn.jsdelivr.net/gh/addy-ai/customer-inquiry-bot@latest/img/icons/check_green.svg\");\n    // Update the close button primary color\n    successScreen.querySelector(\".addy-interactive-primary-button\").style.backgroundColor = data.primaryColor;\n    return successScreen;\n}\n\nconst widgetCardHTMLTemplate = `\n<div class=\"addy-widget-card\">\n    <div class=\"addy-widget-card-header\">\n      <img src=\"{{iconImage}}\" />\n      <h2>{{name}}</h2>\n    </div>\n\n    <p>{{description}}</p>\n    <button class=\"addy-widget-primary-btn\" style=\"background-color: {{primaryColor}};\">{{buttonText}}</button>\n    <div class=\"addy-widget-extra-buttons\"></div>\n  </div>\n`\n\nconst nextQuestionHTMLTemplate = `\n    <div class=\"addy-agent-form-section-header\">\n        <!-- <img src=\"{{chatbotAvatarURL}}\" /> -->\n        <h2 class=\"addy-agent-form-section-question\">{{question}}</h2>\n    </div>\n`\n\nconst successScreenHTML = `\n    <div class=\"addy-agent-form-section-header\" style=\"display: flex; flex-direction: column; align-items: center;\">\n        <div class=\"addy-agent-form-section-header-avatar-container\" style=\"display: flex; gap: 15px; align-items: start; flex-direction: column; align-items: center;\">\n            <img width=\"30\" height=\"30\" src=\"{{checkIcon}}\" />\n            <h2 class=\"addy-agent-form-section-question\" style=\"text-align: center; margin-top: 0px;\">{{title}}</h2>\n        </div>\n\n        <p style=\"margin-bottom: 30px; margin-top: 0px; text-align: center; max-width: 80%;\">{{message}}</p>\n\n        <button class=\"addy-interactive-primary-button\" style=\"max-width: 80%;\">\n            {{closeButtonText}}\n        </button>\n    </div>\n`;\n\nconst privacyPolicyAndTermsOfServiceHTML = `\n    <div style=\"display: flex; flex-direction: row; align-items: center; gap: 10px;\">\n        <a style=\"font-size: 13px;\" href=\"{{privacyPolicyURL}}\" target=\"_blank\">Privacy Policy</a>\n        <a style=\"font-size: 13px;\" href=\"{{termsOfServiceURL}}\" target=\"_blank\">Terms of Service</a>\n    </div>\n`\n"]}