"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/layouts/page-layout/copilot"],{2619:(e,s,t)=>{t.r(s),t.d(s,{default:()=>o});var a=t(296),r=t(2620),l=t(90),n=t(295);const c=l.Locale.getTranslate("components.copilot"),o=e=>(0,n.jsx)(a.Drawer,{"data-type":"copilot-drawer",className:"ext-copilot-assistant-drawer",title:(0,n.jsx)(c,{content:"drawer.title"}),placement:"right",size:"sm",...e,children:(0,n.jsx)(r.default,{})})},2620:(e,s,t)=>{t.r(s),t.d(s,{default:()=>p});var a=t(295),r=t(296),l=t(725),n=t(90),c=t(729),o=t.n(c),i=t(598),d=t(683);const u=n.Locale.getTranslate("components.copilot"),p=()=>{const e=(0,r.useTranslate)("components.copilot"),[s,t]=(0,i.useSearchParams)(),n=s.get("copilot"),[c,p]=(0,d.useLocalStorage)("copilot-answers",[]),[h,m]=(0,a.useState)(""),g=(0,a.useRef)(null),f=(0,a.useRef)(null),[x,{loading:j,error:v}]=(0,l.useLazyQuery)(o());(0,a.useEffect)(()=>{g.current&&(g.current.scrollTop=g.current.scrollHeight)},[c,j]),(0,a.useEffect)(()=>{j||f.current?.focus()},[j]);const k=async(e=h)=>{const s=e.trim();if(!s||j)return;const t=[...c,{role:"user",content:s,id:c.length}];p(t),m("");const a=await x({variables:{question:s}}),r=a?.data?.copilotChat.answer,l=[...t,{role:"assistant",content:r?.message??void 0,error:r?.error??void 0,id:t.length}];p(l),f.current?.focus()},w=(0,a.useRef)(k);w.current=k,(0,a.useEffect)(()=>{n&&(w.current(n),t(e=>(e.set("copilot",""),e),{replace:!0}))},[n,t]);return(0,a.jsxs)("div",{className:"plesk-copilot-chat-container",children:[(0,a.jsxs)("div",{className:"plesk-copilot-chat-messages",ref:g,children:[c.map(e=>(0,a.jsx)("div",{className:"plesk-copilot-msg-row "+("user"===e.role?"right":"left"),children:"assistant"===e.role?(0,a.jsx)("div",{className:"plesk-copilot-assistant-card",children:(0,a.jsx)("div",{className:"assistant-content",children:e.error?(0,a.jsx)(r.StatusMessage,{intent:"danger",children:e.error}):(0,a.jsx)(r.Markdown,{children:e.content??""})})}):(0,a.jsx)("div",{className:"user-chip",children:(0,a.jsx)("span",{children:e.content})})},e.id)),j&&(0,a.jsx)("div",{className:"msg-row left",children:(0,a.jsx)("div",{className:"assistant-card",children:(0,a.jsx)("div",{className:"assistant-content",children:(0,a.jsx)(r.ContentLoader,{className:"plesk-copilot-loading-indicator",text:(0,a.jsx)(u,{content:"loader.text"})})})})}),v&&(0,a.jsx)("div",{className:"msg-row left",style:{marginTop:8},children:(0,a.jsx)(r.StatusMessage,{intent:"danger",children:v.message})})]}),(0,a.jsx)("form",{onSubmit:e=>{e.preventDefault(),k()},className:"plesk-copilot-chat-input-row",children:(0,a.jsx)(r.Input,{value:h,placeholder:String(e("chat-input.placeholder")),disabled:j,onChange:e=>m(e.target.value),size:"fill",className:"plesk-copilot-chat-input",innerRef:f})})]})}}}]);
//# sourceMappingURL=copilot.js.map?37d30f840e4110451cfa