"use strict";(globalThis.webpackChunk_newfold_labs_wp_module_help_center=globalThis.webpackChunk_newfold_labs_wp_module_help_center||[]).push([[409],{409(e,t,n){n.d(t,{default:()=>x});var o=n(28),s=n(875),r=n(567),a=n(723);function l(e){const t=e&&String(e).trim()?`"${String(e).trim()}"`:"this",n=function(e){if("string"!=typeof e)return"#";const t=e.trim();return t.startsWith("http://")||t.startsWith("https://")?t:"#"}(window?.nfdHelpCenter?.resourceLink||"#"),o=(0,a.sprintf)(/* translators: %s: the user's search query (or the word "this" if empty) */ /* translators: %s: the user's search query (or the word "this" if empty) */
(0,a.__)("Sorry, I don't have any information on %s yet.","wp-module-help-center"),t),s=(0,a.__)("Here are a few things to try:","wp-module-help-center"),r=(0,a.__)("Resource center","wp-module-help-center"),l=(0,a.sprintf)(/* translators: %s: link to the Resource center */ /* translators: %s: link to the Resource center */
(0,a.__)("Search our %s for a related article or video.","wp-module-help-center"),'<a href="'+i(n)+'" target="_blank" rel="noopener noreferrer">'+i(r)+"</a>"),c=(0,a.__)("Rephrase your question — short, clear prompts work best.","wp-module-help-center"),p=(0,a.sprintf)(/* translators: %s: clickable phone number */ /* translators: %s: clickable phone number */
(0,a.__)("Talk to a person — call %s or chat live with one of our agents.","wp-module-help-center"),'<a href="tel:8884014678">'+i("888-401-4678")+"</a>");return["<p>"+i(o)+"</p>","<p><strong>"+i(s)+"</strong></p>","<ul>","<li>"+l+"</li>","<li>"+i(c)+"</li>","<li>"+p+"</li>","</ul>"].join("")}function i(e){return"string"!=typeof e?"":e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}var c=n(87),p=n(69),d=n(989),u=n(738),h=n(319),g=n(450),m=n(884),f=n(960),_=n(703),w=n(593);const v=Object.freeze({hasWooCommerce:!1});var y=n(790);const C=e=>(0,y.jsx)(h.A,{icon:e,size:16}),S="contextual-action",b=[{id:"write-post",icon:C(g.A),text:(0,a.__)("Write a blog post","wp-module-help-center"),action:(0,a.__)("Help me write a new blog post for my site.","wp-module-help-center")},{id:"edit-page",icon:C(m.A),text:(0,a.__)("Edit a page","wp-module-help-center"),action:(0,a.__)("I want to edit one of the pages on my site.","wp-module-help-center")},{id:"add-product",icon:C(f.A),text:(0,a.__)("Add a product","wp-module-help-center"),action:(0,a.__)("Add a new product to my store.","wp-module-help-center"),slot:S,requires:e=>e.hasWooCommerce},{id:"customize-site",icon:C(_.A),text:(0,a.__)("Customize site","wp-module-help-center"),action:(0,a.__)("Help me customize my site's appearance.","wp-module-help-center"),slot:S},{id:"site-settings",icon:C(w.A),text:(0,a.__)("Update site settings","wp-module-help-center"),action:(0,a.__)("Help me update my site settings.","wp-module-help-center")}],I=(e,t)=>{let n=null,o=null;for(const s of e)"function"==typeof s.requires?!n&&s.requires(t)&&(n=s):o||(o=s);return n||o||null},x=()=>{const[e]=(()=>{const[e,t]=(0,c.useState)(()=>p.Sp.getHelpVisible());return(0,c.useEffect)(()=>{const e=()=>{t(p.Sp.getHelpVisible())};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}},[]),[e,t]})(),{hasLaunchedFromTooltip:t}=(0,d.X)(),{onClose:n}=(0,r.b_)(),i=(0,c.useRef)(!1),[h,g]=(0,c.useState)(!1),[m,f]=(0,c.useState)(0),[_,w]=(0,c.useState)(null);(0,c.useEffect)(()=>{const e=(0,o.getChatHistoryStorageKeys)("help_center");try{if(!localStorage.getItem(e.history)){const t=localStorage.getItem(e.archive);if(t){const n=JSON.parse(t),o=Array.isArray(n)&&n[0];if(o?.messages?.length>0&&o?.archivedAt){const t=18e5,n=new Date(o.archivedAt).getTime();if(Date.now()-n<=t){const t=o.messages.map(e=>({...e,timestamp:e.timestamp instanceof Date?e.timestamp.toISOString():e.timestamp}));localStorage.setItem(e.history,JSON.stringify(t)),null!==o.conversationId&&void 0!==o.conversationId&&localStorage.setItem(e.conversationId,String(o.conversationId)),null!==o.sessionId&&void 0!==o.sessionId&&localStorage.setItem(e.sessionId,String(o.sessionId))}}}}}catch(e){}},[]);const{messages:C,sendMessage:S,retryFailedMessage:x,sendSystemMessage:A,isTyping:j,status:k,conversationId:q,clearApprovalRequest:R,clearTyping:H,updateMessage:M,stopRequest:N,clearChatHistory:E,loadConversation:T,getSessionId:L,error:W,connectionState:O,isConnecting:U,manualRetry:D,isOffline:F,nextRetryAt:z}=(0,o.useNfdAgentsWebSocket)({configEndpoint:"undefined"!=typeof window&&window.nfdHelpCenter?.restUrl?window.nfdHelpCenter.restUrl+"/nfd-agents/chat/v1/config":"/nfd-agents/chat/v1/config",consumer:"help_center",autoConnect:e,consumerType:"help_center",autoLoadHistory:!0,getConnectionFailedFallbackMessage:l});(0,c.useEffect)(()=>{C.length>0&&(0,o.archiveConversation)(C,L(),q,"help_center")},[C,L,q]),(0,c.useEffect)(()=>{const e=()=>{C.length>0&&(0,o.archiveConversation)(C,L(),q,"help_center")};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[C,L,q]);const B=(0,c.useCallback)(e=>{const t=e.messages||e;T(t,e.conversationId??null,e.sessionId??null)},[T]),P=(0,c.useCallback)(()=>{M&&M(e=>"approval_request"===e.type&&e.approvalRequest,e=>({...e,type:"assistant",content:(0,a.__)("Action approved and executed.","wp-module-help-center"),approvalRequest:null})),R()},[R,M]),J=(0,c.useCallback)(()=>{M&&M(e=>"approval_request"===e.type&&e.approvalRequest,e=>{const t=e.approvalRequest?.tool_name||"action";return{...e,type:"assistant",content:(0,a.sprintf)(/* translators: %s: the name of the action or tool that was cancelled */ /* translators: %s: the name of the action or tool that was cancelled */
(0,a.__)('Action "%s" was cancelled.',"wp-module-help-center"),t),approvalRequest:null}}),R()},[R,M]),V=(0,c.useCallback)(()=>{i.current=!1,C.length>0&&(0,o.archiveConversation)(C,L(),q,"help_center"),E(),f(e=>e+1)},[C,L,q,E]),$=(0,c.useCallback)(()=>{i.current=!1,(0,o.removeConversationFromArchive)(q,L(),"help_center"),E(),f(e=>e+1)},[q,L,E]),K=(0,c.useCallback)(e=>{e&&(e.conversationId&&e.conversationId===q||e.sessionId&&e.sessionId===L())&&(i.current=!1,E(),f(e=>e+1))},[q,L,E]),X=(0,c.useMemo)(()=>(()=>{const e=(()=>{const e="undefined"!=typeof window&&window.nfdHelpCenter&&window.nfdHelpCenter.environment||{};return{...v,...e}})(),t=new Map;for(const e of b)e.slot&&(t.has(e.slot)||t.set(e.slot,[]),t.get(e.slot).push(e));const n=new Map;for(const[o,s]of t){const t=I(s,e);t&&n.set(o,t)}const o=new Set,s=[];for(const t of b){if(t.slot){if(o.has(t.slot))continue;if(n.get(t.slot)!==t)continue;o.add(t.slot)}else if("function"==typeof t.requires&&!t.requires(e))continue;const{requires:r,slot:a,...l}=t;s.push(l)}return s})(),[]),G=(0,c.useMemo)(()=>{for(let e=C.length-1;e>=0;e-=1){const t=C[e];if(("user"===t.type||"user"===t.role)&&t.content)return String(t.content)}return""},[C]),Q=[...C],Y=0===Q.length&&!i.current;(0,c.useEffect)(()=>{Q.length>0&&(i.current=!0)},[Q.length]);const Z=C.length>0,ee=C.length>0;let te;return te=Y?(0,y.jsx)("div",{className:"nfd-help-center-chat__welcome-wrapper",children:(0,y.jsx)(o.WelcomeScreen,{onSendMessage:S,title:(0,a.__)("Hi, I'm BLU, your AI assistant.","wp-module-help-center"),subtitle:(0,a.__)("I can help you create and edit posts and pages, update content, and manage your WordPress site.","wp-module-help-center"),showSuggestions:!0,suggestions:X})}):(0,y.jsxs)("div",{className:"nfd-help-center-chat__messages-wrapper",children:[C.length>0&&(0,y.jsx)("div",{className:"nfd-help-center-chat__messages-header",children:(0,y.jsx)("button",{onClick:$,className:"nfd-help-center-chat__clear-chat-button","aria-label":(0,a.__)("Clear chat","wp-module-help-center"),children:(0,a.__)("Clear Chat","wp-module-help-center")})}),(0,y.jsx)(o.ChatMessages,{messages:Q,isLoading:ee&&j,status:k,error:W,onRetry:!ee||"failed"!==O&&"rate_limited"!==O?void 0:D,connectionFailed:ee&&("failed"===O||"rate_limited"===O),isConnectingOrReconnecting:ee&&("connecting"===O||"reconnecting"===O),connectionState:O,nextRetryAt:z,isOffline:F,onApprove:P,onReject:J,onSendMessage:S,onSendSystemMessage:A,conversationId:q,onClearTyping:H,brandId:null,onEditUserMessage:w,onRetryUserMessage:x})]}),(0,y.jsxs)("div",{className:"nfd-help-center-chat nfd-ai-chat-container","data-brand":"bluehost",children:[(0,y.jsx)("div",{className:"nfd-help-center-chat__header-wrapper",children:(0,y.jsx)(o.ChatHeader,{title:(0,a.__)("Blu Chat","wp-module-help-center"),onNewChat:V,newChatDisabled:Y||ee&&("failed"===O||"connecting"===O||"reconnecting"===O),onClose:n,extraActions:(0,y.jsx)(o.ChatHistoryDropdown,{consumer:"help_center",open:h,onOpenChange:e=>{g(e),e&&f(e=>e+1)},onSelectConversation:e=>{B(e),g(!1)},onConversationDeleted:K,refreshTrigger:m,disabled:!1})})}),te,(0,y.jsx)("div",{className:"nfd-help-center-chat__input-area",children:(0,y.jsx)("div",{className:"nfd-help-center-chat__input-wrapper",children:(0,y.jsx)(o.ChatInput,{onSendMessage:S,onStopRequest:N,showStopButton:j,disabled:j||F||ee&&("failed"===O||"connecting"===O||"reconnecting"===O),placeholder:(0,a.__)("Ask me anything about WordPress…","wp-module-help-center"),showTopBorder:!1,prefill:_,onPrefillConsumed:()=>w(null),lastUserMessage:G})})}),(0,u.$)(t)&&(0,y.jsx)("div",{className:"nfd-help-center-chat__footer-wrapper"+(Z?" nfd-help-center-chat__footer-wrapper--collapsed":""),"aria-hidden":Z,children:(0,y.jsx)(s.A,{})})]})}}}]);