(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{1057:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>g});var r=a(5155),o=a(9137),s=a.n(o),c=a(2115),n=a(6766),l=a(1013),i=a(3568),d=a(8240),m=a(4823);let b=function(e){let{content:t}=e;console.log("Rendering markdown with content length:",t.length);let a=(0,c.useMemo)(()=>{let e=t;if(!/^(\|\s.*\s\|\s*\n)(\|\s*[-:]+[-|\s:]*\s*\|\s*\n)((?:\|\s.*\s\|\s*\n)+)/gm.test(t)){let a=t.split("\n"),r=-1,o=-1,s=!1;for(let e=0;er)){let t=a[r].split("|").filter(Boolean).length;if(r+1===o||!a[r+1].includes("|-")&&!a[r+1].includes("|:")){let s="| "+Array(t).fill("---").join(" | ")+" |";a.splice(r+1,0,s),o++,e++}}}s&&(o=a.length-1),e=a.join("\n")}return e},[t]);return(0,r.jsxs)("div",{className:"jsx-972fca43577d4c7c markdown-chat",children:[(0,r.jsx)(s(),{id:"972fca43577d4c7c",children:'.markdown-chat{font-size:.875rem;line-height:1.6}.markdown-chat h1{font-size:1.35rem;font-weight:bold;margin-top:1.25rem;margin-bottom:.75rem}.markdown-chat h2{font-size:1.2rem;font-weight:bold;margin-top:1.25rem;margin-bottom:.75rem}.markdown-chat h3{font-size:1.05rem;font-weight:bold;margin-top:1rem;margin-bottom:.5rem}.markdown-chat p{margin-bottom:.75rem}.markdown-chat ul,.markdown-chat ol{padding-left:1.5rem;margin-bottom:.75rem}.markdown-chat ul{list-style-type:disc}.markdown-chat ol{list-style-type:decimal}.markdown-chat li{margin-bottom:.25rem}.markdown-chat code{background-color:rgba(0,0,0,.05);padding:.125rem .25rem;-webkit-border-radius:.25rem;-moz-border-radius:.25rem;border-radius:.25rem;font-family:monospace;color:#06c}.markdown-chat pre{background-color:rgba(0,0,0,.03);padding:.75rem;-webkit-border-radius:.375rem;-moz-border-radius:.375rem;border-radius:.375rem;overflow-x:auto;margin-bottom:.75rem}.markdown-chat pre code{background-color:transparent;padding:0;color:inherit;display:block}.markdown-chat a{color:#06c;text-decoration:none}.markdown-chat a:hover{text-decoration:underline}.markdown-chat blockquote{border-left:4px solid#e0e0e0;padding-left:.75rem;font-style:italic;color:rgba(0,0,0,.6);margin-bottom:.75rem}.markdown-chat table{border-collapse:collapse;width:100%;margin-bottom:1rem;font-size:.875rem}.markdown-chat .table-wrapper{overflow-x:auto;display:block;margin-bottom:1rem}.markdown-chat table th,.markdown-chat table td{border:1px solid#e0e0e0;padding:.5rem .75rem;text-align:left;min-width:6rem;vertical-align:top;word-break:normal}.markdown-chat table th[align="center"],.markdown-chat table td[align="center"]{text-align:center}.markdown-chat table th[align="right"],.markdown-chat table td[align="right"]{text-align:right}.markdown-chat table th{background-color:rgba(0,0,0,.05);font-weight:600;color:rgba(0,0,0,.8)}.markdown-chat table tr:nth-child(even){background-color:rgba(0,0,0,.02)}.markdown-chat table tr:hover{background-color:rgba(0,0,0,.04)}'}),(0,r.jsx)(d.oz,{remarkPlugins:[m.A],components:{table:e=>(0,r.jsx)("div",{className:"jsx-972fca43577d4c7c table-wrapper",children:(0,r.jsx)("table",{...e,className:"jsx-972fca43577d4c7c "+(e&&null!=e.className&&e.className||"")})})},children:a})]})},f="HNUE Assistant",h="/api/chat",u="hnue_current_conversation",p=["Th\xf4ng tin tuyển sinh đại học","C\xe1c ng\xe0nh đ\xe0o tạo tại HNUE","Tuyển sinh vừa học vừa l\xe0m","Th\xf4ng tin bồi dưỡng cấp chứng chỉ","Đ\xe0o tạo sau đại học","Cơ hội việc l\xe0m sau tốt nghiệp"];function g(){let[e,t]=(0,c.useState)([{type:"bot",content:"Ch\xe0o bạn! \uD83D\uDC4B M\xecnh l\xe0 trợ l\xfd ảo hỗ trợ gi\xe1o dục của trường Đại học Sư phạm H\xe0 Nội. Bạn đang cần t\xecm hiểu th\xf4ng tin g\xec? \uD83D\uDE0A",timestamp:new Date,role:"assistant"}]),[a,o]=(0,c.useState)(""),[d,m]=(0,c.useState)(!1),[g,x]=(0,c.useState)(void 0),w=(0,c.useRef)(null),y=(0,c.useRef)(null),k=(0,c.useRef)(null);(0,c.useEffect)(()=>{let e=localStorage.getItem(u);if(e)try{let a=JSON.parse(e);if(a.messages&&a.messages.length>0){let e=a.messages.map(e=>({...e,timestamp:new Date(e.timestamp)}));t(e),a.conversationId&&x(a.conversationId)}}catch(e){}},[]),(0,c.useEffect)(()=>{if(e.length>0){let t=e.map(e=>({...e,timestamp:e.timestamp.toISOString()}));localStorage.setItem(u,JSON.stringify({messages:t,conversationId:g}))}},[e,g]);let j=()=>{var e;null==(e=w.current)||e.scrollIntoView({behavior:"smooth"})};(0,c.useEffect)(()=>{console.log("Messages updated:",e),j()},[e]),(0,c.useEffect)(()=>{if(y.current){y.current.style.height="auto";let e=Math.min(y.current.scrollHeight,120);y.current.style.height="".concat(e,"px"),y.current.style.overflowY=y.current.scrollHeight>120?"auto":"hidden"}},[a]);let v=()=>e.filter(e=>"user"===e.type||"bot"===e.type).map(e=>({role:"user"===e.type?"user":"assistant",content:e.content})),N=async e=>{if(e.preventDefault(),!a.trim()||d)return;let r=a.trim();o(""),t(e=>[...e,{type:"user",content:r,timestamp:new Date,role:"user"}]),m(!0);let s="",c=!1,n=!1;try{let e=v(),a=await fetch(h,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:r,conversationId:g,history:e})});if(!a.ok)throw Error("HTTP error! status: ".concat(a.status));if(!a.body)throw Error("No response body");let o=a.body.getReader(),l=new TextDecoder;for(;;){let{done:e,value:a}=await o.read();if(e){console.log("Stream complete");break}let r=l.decode(a,{stream:!0});for(let e of(console.log("Raw chunk:",r),r.split("\n")))if(e.trim())if(e.startsWith("data: "))try{let a=e.slice(6),r=JSON.parse(a);if(console.log("Parsed data:",r),"conversation"===r.type){x(r.id);continue}if("error"===r.type){i.Ay.error(r.message||"An error occurred"),t(e=>[...e,{type:"bot",content:r.message||"Đ\xe3 xảy ra lỗi. Vui l\xf2ng thử lại sau.",timestamp:new Date,role:"assistant"}]),n=!0;break}if("chunk"===r.type){let e=r.content||"";if(s+=e,i.Ay.success('Received chunk: "'.concat(e.substring(0,15)).concat(e.length>15?"...":"",'"'),{id:"chunk-toast",duration:1e3}),c)t(e=>{let t=e.length-1;return t>=0&&"bot"===e[t].type?e.map((e,a)=>a===t?(console.log("Updating message at index ".concat(a,":"),{old:e.content,new:s}),{...e,content:s}):e):e});else{c=!0;let a={type:"bot",content:e,timestamp:new Date,role:"assistant"};t(e=>[...e,a])}}if("end"===r.type){if(console.log("End event received",r),i.Ay.success("End event received",{id:"end-toast",duration:2e3}),r.fullResponse)if(s=r.fullResponse,c)t(e=>{let t=e.length-1;return t>=0&&"bot"===e[t].type?e.map((e,a)=>a===t?(console.log("Updating message at index ".concat(a,":"),{old:e.content,new:s}),{...e,content:s}):e):e});else{c=!0;let e={type:"bot",content:s,timestamp:new Date,role:"assistant"};t(t=>[...t,e])}n=!0;break}}catch(t){console.error("Error parsing JSON:",t,"Raw line:",e)}else console.log("Unexpected line format:",e);if(n)break}}catch(e){console.error("Stream processing error:",e),i.Ay.error("Lỗi kết nối đến m\xe1y chủ"),t(e=>[...e,{type:"bot",content:"Xin lỗi, đ\xe3 xảy ra lỗi kết nối. Vui l\xf2ng thử lại sau.",timestamp:new Date,role:"assistant"}])}finally{var l;if(c&&s)t(e=>{let t=e.length-1;return t>=0&&"bot"===e[t].type?e.map((e,a)=>a===t?(console.log("Updating message at index ".concat(a,":"),{old:e.content,new:s}),{...e,content:s}):e):e});else if(s&&!c){let e={type:"bot",content:s,timestamp:new Date,role:"assistant"};t(t=>[...t,e])}m(!1),null==(l=y.current)||l.focus()}},S=e=>e.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),E=e=>{if(d)return;o(e),t(t=>[...t,{type:"user",content:e,timestamp:new Date,role:"user"}]),o(""),m(!0);let a="",r=!1,s=!1;(async()=>{try{let o=v(),c=await fetch(h,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e,conversationId:g,history:o})});if(!c.ok)throw Error("HTTP error! status: ".concat(c.status));if(!c.body)throw Error("No response body");let n=c.body.getReader(),l=new TextDecoder;for(;;){let{done:e,value:o}=await n.read();if(e){console.log("Stream complete");break}let c=l.decode(o,{stream:!0});for(let e of(console.log("Raw chunk:",c),c.split("\n")))if(e.trim())if(e.startsWith("data: "))try{let o=e.slice(6),c=JSON.parse(o);if(console.log("Parsed data:",c),"conversation"===c.type){x(c.id);continue}if("error"===c.type){i.Ay.error(c.message||"An error occurred"),t(e=>[...e,{type:"bot",content:c.message||"Đ\xe3 xảy ra lỗi. Vui l\xf2ng thử lại sau.",timestamp:new Date,role:"assistant"}]),s=!0;break}if("chunk"===c.type){let e=c.content||"";if(a+=e,i.Ay.success('Received chunk: "'.concat(e.substring(0,15)).concat(e.length>15?"...":"",'"'),{id:"chunk-toast",duration:1e3}),r)t(e=>{let t=e.length-1;return t>=0&&"bot"===e[t].type?e.map((e,r)=>r===t?(console.log("Updating message at index ".concat(r,":"),{old:e.content,new:a}),{...e,content:a}):e):e});else{r=!0;let a={type:"bot",content:e,timestamp:new Date,role:"assistant"};t(e=>[...e,a])}}if("end"===c.type){if(console.log("End event received",c),i.Ay.success("End event received",{id:"end-toast",duration:2e3}),c.fullResponse)if(a=c.fullResponse,r)t(e=>{let t=e.length-1;return t>=0&&"bot"===e[t].type?e.map((e,r)=>r===t?(console.log("Updating message at index ".concat(r,":"),{old:e.content,new:a}),{...e,content:a}):e):e});else{r=!0;let e={type:"bot",content:a,timestamp:new Date,role:"assistant"};t(t=>[...t,e])}s=!0;break}}catch(t){console.error("Error parsing JSON:",t,"Raw line:",e)}else console.log("Unexpected line format:",e);if(s)break}}catch(e){console.error("Stream processing error:",e),i.Ay.error("Lỗi kết nối đến m\xe1y chủ"),t(e=>[...e,{type:"bot",content:"Xin lỗi, đ\xe3 xảy ra lỗi kết nối. Vui l\xf2ng thử lại sau.",timestamp:new Date,role:"assistant"}])}finally{var o;if(r&&a)t(e=>{let t=e.length-1;return t>=0&&"bot"===e[t].type?e.map((e,r)=>r===t?(console.log("Updating message at index ".concat(r,":"),{old:e.content,new:a}),{...e,content:a}):e):e});else if(a&&!r){let e={type:"bot",content:a,timestamp:new Date,role:"assistant"};t(t=>[...t,e])}m(!1),null==(o=y.current)||o.focus()}})()};return(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 flex flex-col h-screen bg-gray-50",children:[(0,r.jsxs)("header",{className:"jsx-aeaf8c193c9bc4f1 bg-[#003d7c] shadow-md py-3 px-6 flex justify-between items-center sticky top-0 z-10",children:[(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 flex items-center space-x-3",children:[(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 relative h-10 w-10 overflow-hidden rounded-full bg-white p-1",children:(0,r.jsx)(n.default,{src:"/hnue_logo.png",alt:"HNUE Logo",fill:!0,sizes:"40px",style:{objectFit:"contain"},priority:!0})}),(0,r.jsx)("h1",{className:"jsx-aeaf8c193c9bc4f1 text-xl font-semibold text-white",children:f})]}),(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 flex items-center space-x-2",children:(0,r.jsxs)("button",{onClick:()=>{localStorage.removeItem(u),x(void 0),t([{type:"bot",content:"Xin ch\xe0o! M\xecnh l\xe0 trợ l\xfd ảo của trường Đại học Sư phạm H\xe0 Nội. Bạn c\xf3 thể hỏi m\xecnh bất kỳ điều g\xec li\xean quan đến học tập, chương tr\xecnh đ\xe0o tạo hoặc c\xe1c hoạt động của trường. \uD83D\uDE0A",timestamp:new Date,role:"assistant"}])},className:"jsx-aeaf8c193c9bc4f1 bg-white text-[#003d7c] hover:bg-blue-50 px-4 py-2 rounded-full text-sm font-medium transition-colors duration-200 flex items-center space-x-1",children:[(0,r.jsx)(l.QwN,{className:"text-lg"}),(0,r.jsx)("span",{className:"jsx-aeaf8c193c9bc4f1",children:"Cuộc tr\xf2 chuyện mới"})]})})]}),(0,r.jsxs)("div",{ref:k,className:"jsx-aeaf8c193c9bc4f1 flex-1 p-4 md:p-6 overflow-y-auto",children:[g&&(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 text-xs text-center text-gray-500 mb-4",children:["ID cuộc tr\xf2 chuyện: ",g.substring(0,8),"..."]}),(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 max-w-4xl mx-auto",children:[e.map((e,t)=>(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 "+"mb-6 flex ".concat("user"===e.type?"justify-end":"justify-start"),children:["bot"===e.type&&(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 flex items-center justify-center w-10 h-10 rounded-full bg-[#e6f3ff] border border-[#cce5ff] mr-3 mb-auto overflow-hidden",children:(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 relative h-7 w-7",children:(0,r.jsx)(n.default,{src:"/hnue_logo.png",alt:"HNUE Logo",fill:!0,sizes:"28px",style:{objectFit:"contain"}})})}),(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 flex flex-col max-w-[75%]",children:["bot"===e.type&&(0,r.jsx)("span",{className:"jsx-aeaf8c193c9bc4f1 text-xs text-gray-600 ml-1 mb-1 font-medium",children:f}),(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 "+"rounded-2xl px-4 py-3 ".concat("user"===e.type?"bg-[#003d7c] text-white rounded-tr-none":"bg-white text-gray-800 rounded-tl-none shadow-sm border border-[#e6f3ff]"),children:"bot"===e.type?(0,r.jsx)(b,{content:e.content},"".concat(t,"-").concat(e.content.length)):(0,r.jsx)("p",{className:"jsx-aeaf8c193c9bc4f1 text-sm whitespace-pre-wrap break-words",children:e.content})}),(0,r.jsx)("p",{className:"jsx-aeaf8c193c9bc4f1 "+"text-xs mt-1 text-gray-500 ".concat("user"===e.type?"text-right mr-1":"ml-1"),children:S(e.timestamp)})]})]},t)),d&&(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 flex justify-start mb-6",children:[(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 flex items-center justify-center w-10 h-10 rounded-full bg-[#e6f3ff] border border-[#cce5ff] mr-3 overflow-hidden",children:(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 relative h-7 w-7",children:(0,r.jsx)(n.default,{src:"/hnue_logo.png",alt:"HNUE Logo",fill:!0,sizes:"28px",style:{objectFit:"contain"}})})}),(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 bg-white rounded-2xl px-5 py-4 shadow-sm border border-[#e6f3ff] rounded-tl-none",children:(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 flex space-x-2",children:[(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 w-2 h-2 rounded-full bg-[#003d7c] animate-pulse"}),(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 w-2 h-2 rounded-full bg-[#003d7c] animate-pulse delay-75"}),(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 w-2 h-2 rounded-full bg-[#003d7c] animate-pulse delay-150"})]})})]}),(0,r.jsx)("div",{ref:w,className:"jsx-aeaf8c193c9bc4f1"})]})]}),(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 bg-white sticky bottom-0 left-0 right-0 z-10 shadow-md",children:[(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 px-4 md:px-6 py-2",children:(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 max-w-4xl mx-auto",children:(0,r.jsx)("div",{style:{WebkitOverflowScrolling:"touch"},className:"jsx-aeaf8c193c9bc4f1 flex gap-2 overflow-x-auto pb-2 scrollbar-thin scrollbar-thumb-gray-300 scrollbar-track-transparent",children:p.map((e,t)=>(0,r.jsx)("button",{onClick:()=>E(e),disabled:d,className:"jsx-aeaf8c193c9bc4f1 flex-shrink-0 bg-blue-50 hover:bg-blue-100 text-[#003d7c] px-4 py-2 rounded-full text-sm font-medium transition-colors duration-200 border border-blue-200 hover:border-blue-300 disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap",children:e},t))})})}),(0,r.jsx)("form",{onSubmit:N,className:"jsx-aeaf8c193c9bc4f1 pb-4 md:pb-6",children:(0,r.jsxs)("div",{className:"jsx-aeaf8c193c9bc4f1 max-w-4xl mx-auto flex gap-3 items-center",children:[(0,r.jsx)("div",{className:"jsx-aeaf8c193c9bc4f1 relative flex-1",children:(0,r.jsx)("textarea",{ref:y,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),N(e))},placeholder:"Nhập c\xe2u hỏi của bạn...",style:{minHeight:"48px",maxHeight:"120px"},disabled:d,rows:1,className:"jsx-aeaf8c193c9bc4f1 w-full pl-4 pr-12 py-3 rounded-xl border border-gray-300 focus:border-[#003d7c] focus:ring focus:ring-blue-200 focus:ring-opacity-50 resize-none text-gray-800"})}),(0,r.jsx)("button",{type:"submit",disabled:d||!a.trim(),className:"jsx-aeaf8c193c9bc4f1 bg-[#003d7c] text-white p-3 rounded-xl hover:bg-[#00285a] disabled:opacity-50 disabled:cursor-not-allowed transition-colors duration-200 flex items-center justify-center h-[48px] min-w-[48px]",children:(0,r.jsx)(l.$_z,{})})]})})]}),(0,r.jsx)(s(),{id:"aeaf8c193c9bc4f1",children:'textarea::-webkit-scrollbar,div::-webkit-scrollbar{width:6px;height:6px}textarea::-webkit-scrollbar-track,div::-webkit-scrollbar-track{background:#f1f1f1;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}textarea::-webkit-scrollbar-thumb,div::-webkit-scrollbar-thumb{background-color:#c1c1c1;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}textarea::-webkit-scrollbar-thumb:hover,div::-webkit-scrollbar-thumb:hover{background-color:#a1a1a1}body{font-family:var(--font-roboto),"Segoe UI",-apple-system,BlinkMacSystemFont,sans-serif}.scrollbar-thin{scrollbar-width:thin;scrollbar-color:#c1c1c1 transparent}.scrollbar-thin::-webkit-scrollbar{width:6px;height:6px}.scrollbar-thin::-webkit-scrollbar-track{background:transparent}.scrollbar-thin::-webkit-scrollbar-thumb{background-color:#c1c1c1;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.scrollbar-thin::-webkit-scrollbar-thumb:hover{background-color:#a1a1a1}.scrollbar-thumb-gray-300::-webkit-scrollbar-thumb{background-color:#d1d5db}.scrollbar-track-transparent::-webkit-scrollbar-track{background:transparent}.overflow-x-auto{-webkit-overflow-scrolling:touch;scroll-behavior:smooth}'})]})}},4356:(e,t,a)=>{Promise.resolve().then(a.bind(a,1057))}},e=>{var t=t=>e(e.s=t);e.O(0,[512,519,608,441,684,358],()=>t(4356)),_N_E=e.O()}]);