

    // FlowHunt Chatbot Widget - Dynamically generated for chatbot ID: 2e9b20b5-b981-4e4d-95b6-885c0fdcdf8a
    window.FHChatbot_2e9b20b5_b981_4e4d_95b6_885c0fdcdf8a = {
      // Chatbot configuration
      config: {
        chatbotId: '2e9b20b5-b981-4e4d-95b6-885c0fdcdf8a',
        workspaceId: '98906441-50f5-478a-8073-cac577106acd',
        headerTitle: 'Virtuální asistent Tomáš',
        urlSuffix: '#utm_source=chatbot',
        maxWindowWidth: '540px',
        
        inputPlaceholder: 'Zeptejte se na cokoli',
        
        cookieConsent: 'true',
        
        // Theme customizations
        theme: ' ',
        ratelimitErrorMessage: '',
        
        // Custom options
        customOptions: '{"chatBubbleBackground":"","chatBubbleIconColor":"","chatBubbleImageUrl":"https://i.postimg.cc/4Nr8vLSN/500x500-lexus-chat-4.png","chatBubbleSize":null,"chatPrimaryColor":"","chatTextColor":"","position":"bottom-right","textDirection":"auto","messagePlaceholderText":"Zeptejte se na cokoli","headerLogoImageUrl":"https://i.postimg.cc/ncVjRBFZ/Lexus-2D-S-BW-HR-RGB.jpg","headerText":"Lexus Chat","messagesHeaderLogoImageUrl":"https://i.postimg.cc/T2gJMVvp/2D-Hires-signage-B-RGB.jpg","avatarAssistantImageUrl":"https://i.postimg.cc/ncVjRBFZ/Lexus-2D-S-BW-HR-RGB.jpg","removeBranding":true,"popupMessages":null,"popupMessagesDelay":2000,"chatbotLanguage":"en"}',
        
        // Header options
        showHeader: '{"title":"Virtuální asistent Tomáš","description":""}',
      },
      
      // Method to override configuration options
      setConfig: function(overrideConfig) {
        if (overrideConfig && typeof overrideConfig === 'object') {
          // Merge the override config with the default config
          for (var key in overrideConfig) {
            if (overrideConfig.hasOwnProperty(key)) {
              // Special handling for customOptions which is a JSON string
              if (key === 'customOptions') {
                try {
                  // Parse existing customOptions
                  var existingOptions = this.config.customOptions ? JSON.parse(this.config.customOptions) : {};
                  
                  // Parse new customOptions
                  var newOptions = {};
                  if (typeof overrideConfig.customOptions === 'string') {
                    newOptions = JSON.parse(overrideConfig.customOptions);
                  } else if (typeof overrideConfig.customOptions === 'object') {
                    newOptions = overrideConfig.customOptions;
                  }
                  
                  // Merge the options
                  for (var optKey in newOptions) {
                    if (newOptions.hasOwnProperty(optKey)) {
                      existingOptions[optKey] = newOptions[optKey];
                    }
                  }
                  
                  // Stringify the merged result with proper escaping
                  this.config.customOptions = JSON.stringify(existingOptions)
                    .replace(/\\/g, "\\\\")
                    .replace(/"/g, '\\"')
                    .replace(/\n/g, "\\n")
                    .replace(/\r/g, "\\r")
                    .replace(/\t/g, "\\t");
                } catch (e) {
                  console.error('Error merging customOptions:', e);
                  this.config[key] = overrideConfig[key];
                }
              } else if (key === 'theme') {
                // Update top-level theme and sync into customOptions.theme so the
                // React widget picks it up on the next renderChatWidget() call
                this.config.theme = overrideConfig.theme;
                try {
                  var themeOpts = this.config.customOptions ? JSON.parse(this.config.customOptions) : {};
                  var themeVal = overrideConfig.theme;
                  if (themeVal === 'L') themeVal = 'light';
                  else if (themeVal === 'D') themeVal = 'dark';
                  themeOpts.theme = themeVal;
                  this.config.customOptions = JSON.stringify(themeOpts);
                } catch (e) {
                  console.error('Error syncing theme to customOptions:', e);
                }
              } else if (key === 'showHeader') {
                // Special handling for showHeader which is also a JSON string
                try {
                  var existingHeader = this.config.showHeader ? JSON.parse(this.config.showHeader) : {};
                  var newHeader = {};
                  
                  if (typeof overrideConfig.showHeader === 'string') {
                    newHeader = JSON.parse(overrideConfig.showHeader);
                  } else if (typeof overrideConfig.showHeader === 'object') {
                    newHeader = overrideConfig.showHeader;
                  }
                  
                  for (var headerKey in newHeader) {
                    if (newHeader.hasOwnProperty(headerKey)) {
                      existingHeader[headerKey] = newHeader[headerKey];
                    }
                  }
                  
                  this.config.showHeader = JSON.stringify(existingHeader)
                    .replace(/\\/g, "\\\\")
                    .replace(/"/g, '\\"')
                    .replace(/\n/g, "\\n")
                    .replace(/\r/g, "\\r")
                    .replace(/\t/g, "\\t");
                } catch (e) {
                  console.error('Error merging showHeader:', e);
                  this.config[key] = overrideConfig[key];
                }
              } else {
                // Normal assignment for other properties
                this.config[key] = overrideConfig[key];
              }
            }
          }
        }
        // Re-render the chatbot widget with the updated config if already initialised
        if (this.chatbotManager && typeof this.chatbotManager.renderChatWidget === 'function') {
          this.chatbotManager.renderChatWidget();
        }
        return this; // Allow chaining
      },
      

      // Initialize the chatbot and call the callback with the instance
      init: function(callback) {
        const self = this;

        // Moving init code to separate function so we can call it from fake chat bubble too
        // Loads the core chatbot widget script
        function createChatbot(callback, fakeButton) {
          const scriptChatbot = document.createElement('script');
          scriptChatbot.async = true;
          scriptChatbot.src = 'https://app.flowhunt.io/fh-chat-widget.js';
          scriptChatbot.onload = function() {
            if (window.FHChatbot) {
              // Initialize the chatbot and pass the instance to the callback
              const chatbotManager = FHChatbot.initChatbot(self.config);
              // Store reference so setConfig() can trigger re-renders after init
              self.chatbotManager = chatbotManager;
              if (callback && typeof callback === 'function') {
                callback(chatbotManager);
              }
              if(fakeButton) {
                const fakeChatButton = document.getElementById("fh-chatbot-button-" + self.config.chatbotId);
                fakeChatButton.remove();
              }
            }
          };
          document.head.appendChild(scriptChatbot);
        };

        // Creating fake chat button if chatbot is not embedded and chat button is not explicitly hidden
        if(!window.FHChatbot && true && self.config.showChatButton !== false) {
          self.config.openChatPanel = true;

          // If this chatbot was previously open (cookie persists across pages),
          // skip the fake button and load the full widget directly
          var openCookie = document.cookie.match(/fh-chatbotOpen=([^;]*)/);
          if (openCookie) {
            try {
              var openIds = JSON.parse(decodeURIComponent(openCookie[1]));
              if (Array.isArray(openIds) && openIds.indexOf(self.config.chatbotId) !== -1) {
                createChatbot(callback);
                return;
              }
            } catch(e) { /* ignore corrupted cookie */ }
          }

          const scriptButton = document.createElement('script');
          scriptButton.async = true;
          scriptButton.src = 'https://app.flowhunt.io/fh-chat-button.js';
          scriptButton.onload = function() {
            if (window.FHChatbotButton) {
              // Initialize the chatbot button and pass the instance to the callback
              const chatbotButton = FHChatbotButton.initChatbotButton(self.config.chatbotId, self.config.customOptions, () => createChatbot(callback, true));
              if (callback && typeof callback === 'function') {
                callback(chatbotButton);
              }
            }
          };
          document.head.appendChild(scriptButton);
          return;
        }
        // This loads normally if chatbot is not button, loads the external JS only if not already loaded
        if (!window.FHChatbot) {
          createChatbot(callback);
        }
      }
    };
  