{"version":3,"file":"Chat.C8ix3TyX.mjs","names":[],"sources":["https:/framerusercontent.com/modules/gA4jKwNSEvuDPxlh898b/C94tKt6uhIqpNsoKk6oX/Chat.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";export default function Chat(){const[messages,setMessages]=React.useState([]);const[input,setInput]=React.useState(\"\");const[loading,setLoading]=React.useState(false);const[error,setError]=React.useState(\"\");const[listening,setListening]=React.useState(false);async function sendMessage(){if(!input.trim())return;setError(\"\");setLoading(true);setMessages(prev=>[...prev,{role:\"user\",content:input}]);try{const res=await fetch(\"https://chat-juridiko.vercel.app/api/chat\",{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},body:JSON.stringify({message:input})});const data=await res.json();if(!res.ok)throw new Error(data?.error||\"N\\xe5got gick fel\");setMessages(prev=>[...prev,{role:\"assistant\",content:data.reply||\"Inget svar fr\\xe5n AI:n\"}]);}catch(e){setError(e.message);}finally{setInput(\"\");setLoading(false);}}function onKeyDown(e){if(e.key===\"Enter\"&&(e.metaKey||e.ctrlKey))sendMessage();}function toggleListening(){if(!(\"webkitSpeechRecognition\"in window||\"SpeechRecognition\"in window)){alert(\"Din webbl\\xe4sare st\\xf6djer inte r\\xf6st-till-text\");return;}const SpeechRecognition=window.SpeechRecognition||window.webkitSpeechRecognition;const recognition=new SpeechRecognition;recognition.lang=\"sv-SE\";recognition.continuous=false;recognition.interimResults=false;if(!listening){recognition.start();setListening(true);recognition.onresult=event=>{const transcript=event.results[0][0].transcript;setInput(prev=>prev?prev+\" \"+transcript:transcript);};recognition.onerror=err=>{console.error(\"Speech error\",err);setListening(false);};recognition.onend=()=>setListening(false);}else{recognition.stop();setListening(false);}}return /*#__PURE__*/_jsxs(\"div\",{style:styles.wrap,children:[/*#__PURE__*/_jsx(\"div\",{style:styles.header}),/*#__PURE__*/_jsxs(\"div\",{style:styles.inputContainer,children:[/*#__PURE__*/_jsx(\"textarea\",{rows:2,value:input,onChange:e=>setInput(e.target.value),onKeyDown:onKeyDown,placeholder:\"St\\xe4ll en juridisk fr\\xe5ga…\",style:styles.input}),/*#__PURE__*/_jsxs(\"div\",{style:styles.buttonContainer,children:[/*#__PURE__*/_jsx(\"button\",{onClick:toggleListening,style:{...styles.iconButton,background:listening?\"#e74c3c\":\"#2ec5b6\"},\"aria-label\":\"Mikrofon\",children:/*#__PURE__*/_jsx(\"svg\",{xmlns:\"http://www.w3.org/2000/svg\",viewBox:\"0 0 24 24\",fill:\"white\",width:\"20\",height:\"20\",children:/*#__PURE__*/_jsx(\"path\",{d:\"M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 14 0h-2zM11 18h2v3h-2v-3z\"})})}),/*#__PURE__*/_jsx(\"button\",{onClick:sendMessage,disabled:loading||!input.trim(),style:styles.button,children:loading?\"Skickar…\":\"Skicka\"})]})]}),/*#__PURE__*/_jsxs(\"div\",{style:styles.chat,children:[messages.map((m,i)=>/*#__PURE__*/_jsx(\"div\",{style:{...styles.bubble,...m.role===\"user\"?styles.user:styles.bot},children:m.content},i)),loading&&/*#__PURE__*/_jsx(\"div\",{style:styles.thinking,children:\"AI t\\xe4nker…\"})]}),error&&/*#__PURE__*/_jsxs(\"div\",{style:styles.error,children:[\"⚠️ \",error]})]});}const styles={wrap:{width:\"100%\",maxWidth:1080,margin:\"0 auto\",padding:\"40px 0px 60px 0px\"},thinking:{fontStyle:\"italic\",opacity:.7,padding:\"5px\"},inputContainer:{display:\"flex\",flexDirection:\"column\",gap:10,marginBottom:10},input:{flex:1,padding:10,borderRadius:20,border:\"2px solid #d9dce6\",outline:\"none\",fontSize:14,resize:\"vertical\",minHeight:44},buttonContainer:{display:\"flex\",gap:10,justifyContent:\"flex-end\"},button:{padding:\"10px 30px\",borderRadius:20,border:\"none\",background:\"#2ec5b6\",color:\"#1E3857\",fontWeight:600,cursor:\"pointer\",height:44,flex:1},iconButton:{borderRadius:20,height:44,border:\"none\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",color:\"#fff\",cursor:\"pointer\",flex:1,padding:\"0 20px\"},error:{marginTop:10,background:\"#fff5f5\",border:\"2px solid #ffffff\",color:\"#a32929\",borderRadius:20,padding:10},header:{fontSize:18,fontWeight:700,marginBottom:10},chat:{border:\"2px solid #e6e8ef\",background:\"#ffffff\",borderRadius:20,height:380,overflowY:\"auto\",padding:10,display:\"flex\",flexDirection:\"column\"},bubble:{padding:\"10px 10px\",borderRadius:20,marginBottom:10,maxWidth:\"85%\",whiteSpace:\"pre-wrap\",wordBreak:\"break-word\"},user:{background:\"#39C0BA\",alignSelf:\"flex-end\",marginLeft:\"auto\"},bot:{background:\"#f5f5f5\",alignSelf:\"flex-start\",marginRight:\"auto\"},\"@media (min-width: 768px)\":{inputContainer:{flexDirection:\"row\",alignItems:\"center\"},buttonContainer:{justifyContent:\"flex-start\"},button:{flex:\"none\",width:\"auto\"},iconButton:{flex:\"none\",width:\"auto\",padding:\"0 20px\"}}};\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Chat\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Chat.map"],"mappings":"0MAAqF,SAAwB,GAAM,CAAC,GAAK,CAAC,EAAS,EAAY,CAAA,EAAgB,EAAE,EAAO,CAAC,EAAM,EAAS,CAAA,EAAgB,IAAS,CAAC,EAAQ,EAAW,CAAA,EAAgB,IAAY,CAAC,EAAM,EAAS,CAAA,EAAgB,IAAS,CAAC,EAAU,EAAa,CAAA,EAAgB,IAAO,eAAe,GAAa,CAAK,KAAM,OAA4C,CAA9B,EAAS,IAAI,EAAW,IAAM,EAAY,GAAM,CAAC,GAAG,EAAK,CAAC,KAAK,OAAO,QAAQ,EAAM,CAAC,EAAE,GAAG,CAAC,IAAM,EAAI,MAAM,MAAM,4CAA4C,CA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