(()=>{"use strict";var e={2890:(e,t,r)=>{var a=r(5320),n=r(960),o=r(252),s=r(6318),i=r(3706),l=r(1017),c=r(2365),d=r(1581),u=r(401),f=r(2304),g=r(2346),h=(r(1060),r(2105),r(5767)),p=r(9580);const m=f.default.create({container:{flex:1,padding:10},module:{padding:15,borderRadius:5,marginBottom:10},title:{fontWeight:"bold",fontSize:16},text:{fontSize:14,marginTop:5}}),x=({data:e})=>{const t=[],r=/\{([^}]+)\}/g;let a;for(;null!==(a=r.exec(e));){const e=a[1].split(","),r=e[0].trim(),n=parseInt(e[1].trim(),10),o=e.length>2?e.slice(2).join(",").trim():"";t.push({questionNumber:r,score:n,reason:o})}return(0,p.jsx)(g.default,{style:m.container,children:t.map(((e,t)=>{return(0,p.jsxs)(o.default,{style:[m.module,{backgroundColor:(r=e.score,2===r?"green":1===r?"yellow":0===r?"red":"white")}],children:[(0,p.jsxs)(s.default,{style:m.title,children:["Question ",e.questionNumber]}),(0,p.jsx)(s.default,{style:m.text,children:2===e.score?"Correct":e.reason})]},t);var r}))})};var y=r(2380),j=r.n(y);const b=async e=>new Promise(((t,r)=>{fetch(e).then((e=>e.blob())).then((e=>{const a=URL.createObjectURL(e),n=new window.Image;n.onload=()=>{const e=document.createElement("canvas");e.width=n.width,e.height=n.height;const o=e.getContext("2d");if(!o)return URL.revokeObjectURL(a),r(new Error("Unable to get canvas context"));o.drawImage(n,0,0);let s=.9,i=e.toDataURL("image/jpeg",s),l=i.split(",")[1],c=3*l.length/4;for(;c>1048576&&s>.1;)s-=.1,i=e.toDataURL("image/jpeg",s),l=i.split(",")[1],c=3*l.length/4;URL.revokeObjectURL(a),t({uri:i})},n.onerror=e=>{URL.revokeObjectURL(a),console.error("Error loading image for conversion:",e),r(new Error("Failed to load image for conversion"))},n.src=a})).catch((e=>{console.error("Error fetching image blob:",e),r(e)}))}));const v=f.default.create({container:{padding:20,alignItems:"center",justifyContent:"center",flexGrow:1},input:{height:40,borderWidth:1,marginBottom:10,padding:5,width:"100%"},image:{width:300,height:300,marginVertical:20},loader:{marginVertical:20},textContainer:{marginTop:20,padding:10,backgroundColor:"#eee",borderRadius:5,width:"100%"},textTitle:{fontWeight:"bold",marginBottom:10},title:{fontSize:24,marginBottom:20}});(0,a.default)((function(){const[e,t]=(0,n.useState)(!1),[r,a]=(0,n.useState)(""),[f,m]=(0,n.useState)(!1),[y,w]=(0,n.useState)(null),[S,C]=(0,n.useState)(""),[E,O]=(0,n.useState)(""),[T,L]=(0,n.useState)(null),[P,R]=(0,n.useState)(""),[U,k]=(0,n.useState)(!1),[B,I]=(0,n.useState)(""),[N,$]=(0,n.useState)(!1),A="/api",_=()=>{"hawvyv-rokxY8-tapdak"===r?t(!0):c.default.alert("Beta Release","Incorrect beta release password.")};return e?(0,p.jsx)(g.default,{contentContainerStyle:v.container,children:f?(0,p.jsxs)(o.default,{style:v.container,children:[(0,p.jsxs)(s.default,{style:{marginBottom:10},children:["Welcome, ",S,"!"]}),(0,p.jsx)(l.default,{title:"Logout",onPress:()=>{w(null),m(!1),c.default.alert("Logout","Logged out successfully.")}}),(0,p.jsx)("br",{}),(0,p.jsx)(p.Fragment,{children:(0,p.jsx)("input",{type:"file",accept:"image/*",onChange:async e=>{const t=e.target.files&&e.target.files[0];if(!t)return;let r=t;if("image/heic"===t.type||"image/heif"===t.type||t.name.match(/\.(heic|heif)$/i))try{const e=await j()({blob:t,toType:"image/jpeg",quality:.2}),a=Array.isArray(e)?e[0]:e;r=new File([a],t.name.replace(/\.(heic|heif)$/i,".jpg"),{type:"image/jpeg"})}catch(n){return console.error("Error converting HEIC file:",n),void c.default.alert("Conversion Error","Could not convert HEIC image to JPEG.")}const a=URL.createObjectURL(r);try{const e=await b(a);L(e.uri),R(""),I("")}catch(n){console.error("Error compressing image:",n),c.default.alert("Compression Error","Could not compress image.")}}})}),!1,T&&(0,p.jsx)(d.default,{source:{uri:T},style:v.image}),T&&(0,p.jsx)(l.default,{title:"Extract Text",onPress:async()=>{if(T){k(!0);try{const e="jpg",t=await fetch(T),r=await t.blob();let a=new FormData;a.append("file",r,`photo.${e}`);const n=await h.default.post(`${A}/textract/extract`,a,{headers:{"Content-Type":"multipart/form-data"}});R(n.data.text)}catch(e){console.error("Upload Error:",e),alert("Error extracting text from image")}finally{k(!1)}}}}),U&&(0,p.jsx)(u.default,{style:v.loader,size:"large"}),""!==P&&(0,p.jsxs)(o.default,{style:v.textContainer,children:[(0,p.jsx)(s.default,{style:v.textTitle,children:"Extracted Text:"}),(0,p.jsx)(s.default,{children:P}),(0,p.jsx)(l.default,{title:N?"Sending...":"Send to ChatGPT",onPress:async()=>{if(P.trim()){$(!0);try{const e=await fetch(`${A}/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:P})}),t=await e.json(),r=t.choices&&t.choices[0].message.content;I(r||"No response from AI.")}catch(e){console.error("Error fetching chat response:",e),I("Error fetching chat response.")}finally{$(!1)}}else c.default.alert("Error","No extracted text to send.")},disabled:N})]}),""!==B&&(0,p.jsxs)(o.default,{style:v.textContainer,children:[(0,p.jsx)(s.default,{style:v.textTitle,children:"ChatGPT Response:"}),(0,p.jsx)(s.default,{children:B}),(0,p.jsx)(x,{data:B})]})]}):(0,p.jsxs)(o.default,{style:{padding:20},children:[(0,p.jsx)(s.default,{children:"Username:"}),(0,p.jsx)(i.default,{value:S,onChangeText:C,autoCapitalize:"none",style:v.input}),(0,p.jsx)(s.default,{children:"Password:"}),(0,p.jsx)(i.default,{value:E,onChangeText:O,secureTextEntry:!0,style:v.input}),(0,p.jsx)(l.default,{title:"Signup",onPress:async()=>{try{await fetch(`${A}/auth/signup`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:S,password:E})});c.default.alert("Signup","Signup successful! Now you can log in.")}catch(e){console.error(e),c.default.alert("Signup Error","An error occurred during signup.")}}}),(0,p.jsx)(o.default,{style:{marginVertical:10}}),(0,p.jsx)(l.default,{title:"Login",onPress:async()=>{try{const e=await fetch(`${A}/auth/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:S,password:E})}),t=await e.json();t.access_token?(w(t.access_token),m(!0),c.default.alert("Login","Login successful!")):c.default.alert("Login Failed","Invalid credentials.")}catch(e){console.error(e),c.default.alert("Login Error","An error occurred during login.")}}})]})}):(0,p.jsxs)(g.default,{contentContainerStyle:v.container,children:[(0,p.jsx)(s.default,{style:v.title,children:"Beta Release Access"}),(0,p.jsx)(s.default,{children:"Please enter the beta release password to continue:"}),(0,p.jsx)(i.default,{value:r,onChangeText:a,secureTextEntry:!0,style:v.input,placeholder:"Beta Password"}),(0,p.jsx)(l.default,{title:"Enter Beta",onPress:_})]})}))}},t={};function r(a){var n=t[a];if(void 0!==n)return n.exports;var o=t[a]={exports:{}};return e[a].call(o.exports,o,o.exports,r),o.exports}r.m=e,(()=>{var e=[];r.O=(t,a,n,o)=>{if(!a){var s=1/0;for(d=0;d=o)&&Object.keys(r.O).every((e=>r.O[e](a[l])))?a.splice(l--,1):(i=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[a,n,o]}})(),r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e={792:0};r.O.j=t=>0===e[t];var t=(t,a)=>{var n,o,[s,i,l]=a,c=0;if(s.some((t=>0!==e[t]))){for(n in i)r.o(i,n)&&(r.m[n]=i[n]);if(l)var d=l(r)}for(t&&t(a);cr(2890)));a=r.O(a)})(); //# sourceMappingURL=main.dd88ab12.js.map