settings = $settings; } public function maybe_enqueue_widget(): void { if (is_admin()) { return; } if ($this->settings->get('auto_insert') === '1') { $this->enqueue(); } } public function enqueue(): void { $options = $this->settings->get_all(); if ($this->enqueued || $options['connected'] !== '1' || $options['embed_enabled'] !== '1' || empty($options['assistant_slug'])) { return; } $this->enqueued = true; $config = array( 'assistant_slug' => $options['assistant_slug'], 'api_domain' => $this->settings->service_url('api'), 'frontend_domain' => $this->settings->service_url('widget'), 'position' => $options['position'], 'accent_color' => $options['accent_color'], ); wp_enqueue_script($this->script_handle, $config['frontend_domain'] . '/embed.min.js', array(), AIVA_LITE_VERSION, true); wp_add_inline_script($this->script_handle, 'window.embeddedChatbotConfig = ' . wp_json_encode($config, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) . ';', 'before'); // The hosted runtime reads the public configuration. No site credential is emitted. add_filter('script_loader_tag', array($this, 'add_embed_data_attributes'), 10, 3); wp_enqueue_style('aiva-lite-widget', AIVA_LITE_PLUGIN_URL . 'assets/css/widget.css', array(), AIVA_LITE_VERSION); wp_add_inline_style('aiva-lite-widget', '#aii-embed-container .chatbot-bubble{background-color:' . sanitize_hex_color($options['accent_color']) . '!important;}'); if ($options['position'] === 'bottom-left') { wp_add_inline_style('aiva-lite-widget', '#aii-embed-container .chatbot-container{right:auto!important;left:24px!important;}#aii-embed-container .chatbot-bubble-container{justify-content:flex-start;}#aii-embed-container .chatbot-message-container{align-items:flex-start;}@media(min-width:769px){#aii-embed-container .chatbot-window{right:auto;left:0;}}'); } } public function add_embed_data_attributes(string $tag, string $handle, string $src): string { if ($handle !== $this->script_handle) { return $tag; } $attrs = array('data-assistant-slug' => $this->settings->get('assistant_slug'), 'data-api-domain' => $this->settings->service_url('api'), 'data-frontend-domain' => $this->settings->service_url('widget')); $html = ''; foreach ($attrs as $key => $value) { $html .= ' ' . esc_attr($key) . '="' . esc_attr($value) . '"'; } return str_replace('