(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[398],{9773:function(e,t,s){Promise.resolve().then(s.bind(s,9691))},9376:function(e,t,s){"use strict";var r=s(5475);s.o(r,"useRouter")&&s.d(t,{useRouter:function(){return r.useRouter}})},257:function(e,t,s){"use strict";var r,a;e.exports=(null==(r=s.g.process)?void 0:r.env)&&"object"==typeof(null==(a=s.g.process)?void 0:a.env)?s.g.process:s(4227)},4227:function(e){!function(){var t={229:function(e){var t,s,r,a=e.exports={};function n(){throw Error("setTimeout has not been defined")}function l(){throw Error("clearTimeout has not been defined")}function i(e){if(t===setTimeout)return setTimeout(e,0);if((t===n||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(s){try{return t.call(null,e,0)}catch(s){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:n}catch(e){t=n}try{s="function"==typeof clearTimeout?clearTimeout:l}catch(e){s=l}}();var o=[],c=!1,d=-1;function u(){c&&r&&(c=!1,r.length?o=r.concat(o):d=-1,o.length&&m())}function m(){if(!c){var e=i(u);c=!0;for(var t=o.length;t;){for(r=o,o=[];++d1)for(var s=1;s{v(),localStorage.getItem("token")||b.push("/login")},[]);let N=async()=>{t(!0),h("");try{let{Html5Qrcode:e}=await Promise.all([s.e(52),s.e(791)]).then(s.bind(s,791)),r=new e("scanner-view");y.current=r,await r.start({facingMode:"environment"},{fps:10,qrbox:{width:250,height:150}},e=>{r.stop().catch(()=>{}),t(!1),k(e)},()=>{})}catch(e){t(!1),h("N\xe3o foi poss\xedvel acessar a c\xe2mera. Use o c\xf3digo manual.")}},k=async e=>{m(!0),h(""),p(null);try{let t=await l.h.scan(e);p(t)}catch(e){h(e.message)}finally{m(!1)}},w=e=>"good"===e?"text-green-400":"warning"===e?"text-yellow-400":"text-red-400",D=e=>"good"===e?"\uD83D\uDFE2":"warning"===e?"\uD83D\uDFE1":"\uD83D\uDD34";if(f){var S,T,C,E;let e=(E=f.score)>=71?"#10B981":E>=51?"#EAB308":E>=31?"#F97316":"#EF4444";return(0,r.jsxs)("div",{className:"min-h-screen bg-dark px-4 py-6 max-w-lg mx-auto",children:[(0,r.jsx)("button",{onClick:()=>p(null),className:"text-gray-400 mb-4 hover:text-white",children:"← Voltar"}),(0,r.jsxs)("div",{className:"text-center mb-8",children:[(0,r.jsx)("h2",{className:"text-lg font-semibold mb-1",children:f.product_name||"Produto"}),f.brand&&(0,r.jsx)("p",{className:"text-gray-500 text-sm",children:f.brand}),(0,r.jsxs)("div",{className:"relative w-40 h-40 mx-auto mt-6",children:[(0,r.jsxs)("svg",{viewBox:"0 0 120 120",className:"w-full h-full -rotate-90",children:[(0,r.jsx)("circle",{cx:"60",cy:"60",r:"52",fill:"none",stroke:"#374151",strokeWidth:"10"}),(0,r.jsx)("circle",{cx:"60",cy:"60",r:"52",fill:"none",stroke:e,strokeWidth:"10",strokeDasharray:"".concat(3.267*f.score," 326.7"),strokeLinecap:"round",className:"transition-all duration-1000"})]}),(0,r.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[(0,r.jsx)("span",{className:"text-4xl font-black",style:{color:e},children:f.score}),(0,r.jsx)("span",{className:"text-gray-500 text-sm",children:"/100"})]})]})]}),(0,r.jsx)("div",{className:"bg-dark-light rounded-2xl p-4 mb-4",children:(0,r.jsx)("p",{className:"text-gray-300 text-sm leading-relaxed",children:f.summary})}),(null===(S=f.positives)||void 0===S?void 0:S.length)>0&&(0,r.jsxs)("div",{className:"mb-4",children:[(0,r.jsx)("h3",{className:"font-semibold text-green-400 mb-2",children:"✅ Positivos"}),f.positives.map((e,t)=>(0,r.jsxs)("p",{className:"text-gray-300 text-sm ml-4 mb-1",children:["• ",e]},t))]}),(null===(T=f.negatives)||void 0===T?void 0:T.length)>0&&(0,r.jsxs)("div",{className:"mb-4",children:[(0,r.jsx)("h3",{className:"font-semibold text-red-400 mb-2",children:"❌ Negativos"}),f.negatives.map((e,t)=>(0,r.jsxs)("p",{className:"text-gray-300 text-sm ml-4 mb-1",children:["• ",e]},t))]}),(null===(C=f.ingredients)||void 0===C?void 0:C.length)>0&&(0,r.jsxs)("div",{className:"mb-6",children:[(0,r.jsx)("h3",{className:"font-semibold mb-3",children:"\uD83D\uDCCB Ingredientes"}),(0,r.jsx)("div",{className:"space-y-2",children:f.ingredients.map((e,t)=>(0,r.jsxs)("div",{className:"bg-dark-light rounded-xl p-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,r.jsx)("span",{children:D(e.classification)}),(0,r.jsxs)("span",{className:"font-medium text-sm ".concat(w(e.classification)),children:[e.name,e.popular_name&&e.popular_name!==e.name?" (".concat(e.popular_name,")"):""]})]}),(0,r.jsx)("p",{className:"text-gray-400 text-xs ml-6",children:e.explanation}),(0,r.jsx)("p",{className:"text-gray-500 text-xs ml-6 italic",children:e.reason})]},t))})]}),(0,r.jsxs)("div",{className:"flex gap-3",children:[(0,r.jsx)("button",{onClick:()=>{navigator.share&&navigator.share({title:"Aletheia: ".concat(f.product_name),text:"Score: ".concat(f.score,"/100 - ").concat(f.summary),url:window.location.href})},className:"flex-1 bg-primary text-dark font-bold py-3 rounded-xl",children:"\uD83D\uDCE4 Compartilhar"}),(0,r.jsx)("button",{onClick:()=>p(null),className:"flex-1 bg-dark-light text-white font-bold py-3 rounded-xl",children:"\uD83D\uDCF7 Novo Scan"})]})]})}return(0,r.jsxs)("div",{className:"min-h-screen bg-dark px-4 py-6 max-w-lg mx-auto",children:[(0,r.jsxs)("nav",{className:"flex items-center justify-between mb-8",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xl",children:"\uD83D\uDC41️"}),(0,r.jsx)("span",{className:"font-bold tracking-wider text-primary",children:"ALETHEIA"})]}),(0,r.jsxs)("div",{className:"flex gap-3",children:[(0,r.jsx)(o.default,{href:"/history",className:"text-gray-400 text-sm hover:text-white",children:"Hist\xf3rico"}),(0,r.jsx)(o.default,{href:"/premium",className:"text-primary text-sm font-semibold",children:"Premium"})]})]}),(0,r.jsxs)("div",{className:"text-center mb-8",children:[(0,r.jsx)("h1",{className:"text-2xl font-bold mb-2",children:"Escanear Produto"}),(0,r.jsx)("p",{className:"text-gray-400 text-sm",children:"Aponte a c\xe2mera para o c\xf3digo de barras"})]}),x&&(0,r.jsx)("div",{className:"bg-red-500/10 text-red-400 text-sm p-3 rounded-xl mb-4",children:x}),u&&(0,r.jsxs)("div",{className:"text-center py-20",children:[(0,r.jsx)("div",{className:"animate-spin text-4xl mb-4",children:"\uD83D\uDC41️"}),(0,r.jsx)("p",{className:"text-gray-400",children:"Analisando produto..."})]}),!u&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"mb-6",children:e?(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{id:"scanner-view",ref:j,className:"rounded-2xl overflow-hidden mb-4"}),(0,r.jsx)("button",{onClick:()=>{var e;null===(e=y.current)||void 0===e||e.stop().catch(()=>{}),t(!1)},className:"w-full bg-red-500/20 text-red-400 py-3 rounded-xl font-semibold",children:"Parar Scanner"})]}):(0,r.jsx)("button",{onClick:N,className:"w-full bg-primary text-dark py-6 rounded-2xl font-bold text-xl hover:bg-primary-dark transition transform hover:scale-[1.02] active:scale-95",children:"\uD83D\uDCF7 Escanear C\xf3digo de Barras"})}),(0,r.jsxs)("div",{className:"relative mb-6",children:[(0,r.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,r.jsx)("div",{className:"w-full border-t border-gray-700"})}),(0,r.jsx)("div",{className:"relative flex justify-center",children:(0,r.jsx)("span",{className:"bg-dark px-4 text-gray-500 text-sm",children:"ou digite o c\xf3digo"})})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)("input",{type:"text",placeholder:"Ex: 7891000100103",value:c,onChange:e=>d(e.target.value),className:"flex-1 bg-dark-light rounded-xl px-4 py-3 text-white placeholder-gray-500 outline-none focus:ring-2 focus:ring-primary"}),(0,r.jsx)("button",{onClick:()=>c&&k(c),disabled:!c,className:"bg-primary text-dark px-6 py-3 rounded-xl font-bold disabled:opacity-50",children:"Buscar"})]}),(0,r.jsxs)("div",{className:"mt-8",children:[(0,r.jsx)("p",{className:"text-gray-500 text-sm mb-3",children:"\uD83E\uDDEA Teste com produtos demo:"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:[{name:"Coca-Cola",code:"7891000100103"},{name:"Nescau",code:"7891000053508"},{name:"Miojo",code:"7891000305232"},{name:"Aveia",code:"7891000362006"},{name:"Oreo",code:"7622300830236"}].map(e=>(0,r.jsx)("button",{onClick:()=>k(e.code),className:"bg-dark-light text-gray-300 px-3 py-1.5 rounded-lg text-xs hover:bg-gray-600 transition",children:e.name},e.code))})]})]})]})}},1837:function(e,t,s){"use strict";s.d(t,{h:function(){return n}});let r=s(257).env.NEXT_PUBLIC_API_URL||"http://localhost:8090";async function a(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=localStorage.getItem("token"),a={"Content-Type":"application/json",...t.headers||{}};s&&(a.Authorization="Bearer ".concat(s));let n=await fetch("".concat(r).concat(e),{...t,headers:a});if(!n.ok)throw Error((await n.json().catch(()=>({detail:"Erro de rede"}))).detail||"HTTP ".concat(n.status));return n.json()}let n={register:e=>a("/api/auth/register",{method:"POST",body:JSON.stringify(e)}),login:e=>a("/api/auth/login",{method:"POST",body:JSON.stringify(e)}),me:()=>a("/api/auth/me"),scan:e=>a("/api/scan",{method:"POST",body:JSON.stringify({barcode:e})}),history:()=>a("/api/history")}},1768:function(e,t,s){"use strict";let r;s.d(t,{t:function(){return c}});var a=s(2265);let n=e=>{let t;let s=new Set,r=(e,r)=>{let a="function"==typeof e?e(t):e;if(!Object.is(a,t)){let e=t;t=(null!=r?r:"object"!=typeof a||null===a)?a:Object.assign({},t,a),s.forEach(s=>s(t,e))}},a=()=>t,n={setState:r,getState:a,getInitialState:()=>l,subscribe:e=>(s.add(e),()=>s.delete(e))},l=t=e(r,a,n);return n},l=e=>e?n(e):n,i=e=>e,o=e=>{let t=l(e),s=e=>(function(e,t=i){let s=a.useSyncExternalStore(e.subscribe,a.useCallback(()=>t(e.getState()),[e,t]),a.useCallback(()=>t(e.getInitialState()),[e,t]));return a.useDebugValue(s),s})(t,e);return Object.assign(s,t),s},c=(r=e=>({user:null,token:null,setAuth:(t,s)=>{localStorage.setItem("token",t),localStorage.setItem("user",JSON.stringify(s)),e({token:t,user:s})},logout:()=>{localStorage.removeItem("token"),localStorage.removeItem("user"),e({token:null,user:null})},hydrate:()=>{let t=localStorage.getItem("token"),s=localStorage.getItem("user");t&&s&&e({token:t,user:JSON.parse(s)})}}))?o(r):o}},function(e){e.O(0,[648,971,117,744],function(){return e(e.s=9773)}),_N_E=e.O()}]);