1var $=Object.defineProperty;var b=(n,t,s)=>t in n?$(n,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[t]=s;var S=(n,t,s)=>b(n,typeof t!="symbol"?t+"":t,s);import{u as I,a as C,b as U,r as p,j as e,X as D,M as q,I as j,c as O,y,d as T}from"./index-BLsutjms.js";import{C as F,B,g as H,S as Q,H as z}from"./BadgesSection-HImMK9zw.js";import{C as M,L as G,H as J,T as V,G as X,B as Y,S as K,F as W}from"./SidebarMenu-2AycbA8-.js";import{p as Z,D as E,a as ee}from"./proccessMissions-DiwG-yPv.js";import{u as te,a as se,E as ae,G as R,S as k}from"./useGiveawayStatus-Xc2usPxW.js";import{u as ne}from"./useRequireAuth-c4YQpGqG.js";import{S as re}from"./StreakButton-D1MUMr5Q.js";import{H as P}from"./HomeUserNextBadge-zTZgDCnf.js";import"./GoalCardSkeleton-C8OYITKs.js";function oe(){const{logout:n}=I(),t=C(),s=U(),[o,i]=p.useState(!1),l="w-5 h-5",a="w-6 h-6",r=()=>new URLSearchParams(s.search).get("email")||"",u=(c,m)=>e.jsx(c,{className:a,fill:m?"currentColor":"none"}),h=[{name:"Home",path:"/streak",icon:c=>u(J,c)},{name:"Missões",path:"/streak/missions",icon:c=>u(V,c)},{name:"Indicar",path:"/indicar",icon:c=>u(X,c)},{name:"Cupons",path:"/cupons",icon:c=>u(Y,c)}],d=c=>{const m=r();t(m?`${c}?email=${encodeURIComponent(m)}`:c),i(!1)},g=c=>{const m=s.pathname;return c==="/streak"?m==="/streak":m===c||m.startsWith(`${c}/`)},w=c=>{c.preventDefault();const m=r();m?window.location.href=`https://app.thenewscc.com.br/support?newsletter=thenews&email=${encodeURIComponent(m)}`:window.location.href="https://app.thenewscc.com.br/support?newsletter=thenews",i(!1)},x=c=>{c.preventDefault(),n();const m=new URLSearchParams(window.location.search),L=`${window.location.origin}${window.location.pathname}`;m.set("origin",L),window.location.href=`https://auth.thenewscc.com.br/login?${m.toString()}`},f=c=>{c.preventDefault(),i(!o)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex xl:hidden w-full px-4 justify-between items-center md:p-4 relative z-30 bg-gray-soft-lp-bg",children:[e.jsx("button",{onClick:f,className:"flex gap-2 text-gray-400 hover:text-yellow-400 cursor-pointer transition-colors",children:o?e.jsx(D,{className:l}):e.jsx(q,{className:l})}),e.jsx("img",{src:j.newLogos.theNews,className:"h-10 md:h-12",alt:"the news Logo"})]}),o&&e.jsx("div",{className:"fixed inset-0 bg-gray-soft-lp-bg z-20 pt-16 px-6 overflow-y-auto",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex flex-col gap-2 flex-1",children:h.map(c=>{const m=g(c.path);return e.jsxs("button",{onClick:()=>d(c.path),className:`transition duration-300 flex items-center justify-start cursor-pointer gap-3 w-full p-2 rounded-lg ${m?"text-yellow-400":"text-gray-400 hover:bg-gray-100"}`,children:[e.jsx("div",{className:`${m?"text-yellow-400":"text-gray-400"}`,children:c.icon(m)}),e.jsx("h2",{className:"text-xl font-medium lowercase",children:c.name})]},c.path)})}),e.jsxs("div",{className:"pb-8 space-y-2",children:[e.jsxs("button",{onClick:w,className:"flex gap-3 text-gray-400 hover:text-yellow-400 cursor-pointer p-2 rounded-lg hover:bg-gray-100 w-full transition-colors",children:[e.jsx(M,{className:a}),e.jsx("p",{className:"text-xl lowercase",children:"Suporte"})]}),e.jsxs("button",{onClick:x,className:"flex gap-3 text-gray-400 hover:text-yellow-400 cursor-pointer p-2 rounded-lg hover:bg-gray-100 w-full transition-colors",children:[e.jsx(G,{className:a}),e.jsx("p",{className:"text-xl lowercase",children:"Sair"})]})]})]})})]})}function ie(){return e.jsxs("div",{className:"w-full flex flex-col items-center gap-4",children:[e.jsx("div",{className:"h-6 w-64 bg-gray-200 rounded-full animate-pulse"}),e.jsx("div",{className:"h-40 w-40 bg-gray-200 rounded-full animate-pulse"}),e.jsx("div",{className:"w-full max-w-md",children:e.jsx("div",{className:"h-10 bg-gray-200 rounded-lg animate-pulse"})})]})}function ce(){return e.jsx("div",{className:"flex gap-5 mt-4",children:[1,2].map((n,t)=>e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsx("div",{className:"h-6 w-6 bg-gray-200 rounded-full animate-pulse"}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"h-6 w-20 bg-gray-200 rounded-full animate-pulse"}),e.jsx("div",{className:"h-4 w-16 bg-gray-200 rounded-full animate-pulse"})]})]}),t===0&&e.jsx("span",{className:"border-r-2 h-6 ml-5"})]},t))})}function _(){return e.jsxs("div",{className:"w-full flex flex-col items-center gap-4",children:[e.jsx("div",{className:"h-6 w-64 bg-gray-200 rounded-full animate-pulse"}),e.jsx("div",{className:"h-40 w-40 bg-gray-200 rounded-full animate-pulse"}),e.jsx("div",{className:"w-full max-w-md",children:e.jsx("div",{className:"h-10 bg-gray-200 rounded-lg animate-pulse"})})]})}const le="https://worker.thenewscc.com";function ue(){return{logError:async t=>{try{const s=await fetch(`${le}/streaks/error`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return s.ok||console.error("Failed to log error to server"),await s.json()}catch(s){console.error("Error while logging error:",s)}}}}function de({error:n,userEmail:t}){const s=C(),[o,i]=p.useState(5),{logError:l}=ue();return p.useEffect(()=>{const a=setInterval(()=>{i(r=>{if(r<=1){clearInterval(a);const u=new URLSearchParams(window.location.search),h=`${window.location.origin}${window.location.pathname}`;return u.set("origin",h),window.location.href=`https://auth.thenewscc.com.br/login?${u.toString()}`,0}return r-1})},1e3);return()=>clearInterval(a)},[s]),p.useEffect(()=>{l({error:n,userId:t}),console.error(n)},[n,l]),e.jsx("div",{className:"w-full h-full min-h-dvh bg-gray-soft-lp-bg flex flex-col items-center",children:e.jsxs("div",{className:"md:max-w-2xl flex flex-col items-center gap-4 justify-between h-full min-h-dvh pt-10 px-4 pb-10",children:[e.jsx("img",{src:j.newLogos.theNews,alt:"",className:"w-30 xl:w-50"}),e.jsx("div",{children:e.jsxs("div",{className:"p-6 flex flex-col gap-6 items-center justify-center",children:[e.jsxs("div",{className:"w-full text-gray gap-3 xl:gap-4 flex flex-col items-center justify-center text-center",children:[e.jsx("h1",{className:"text-3xl xl:text-6xl leading-4 xl:leading-8 font-medium lowercase",children:"Oops!"}),e.jsx("p",{className:"text-lg xl:text-2xl leading-5 xl:leading-8 lowercase",children:"Algo deu errado com sua sessão"}),e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx("p",{className:"text-lg xl:text-xl leading-4 text-yellow lowercase",children:"Você será redirecionado em"}),e.jsx("span",{className:"w-8 text-center font-bold text-lg xl:text-xl leading-4 text-yellow",children:o}),e.jsx("p",{className:"text-lg xl:text-xl leading-4 text-yellow lowercase",children:"segundos..."})]})]}),e.jsxs("div",{className:"flex flex-col w-full gap-3 max-w-lg items-center justify-center",children:[e.jsx(re,{title:"ir para login agora",onClick:()=>{const a=new URLSearchParams(window.location.search),r=`${window.location.origin}${window.location.pathname}`;a.set("origin",r),window.location.href=`https://auth.thenewscc.com.br/login?${a.toString()}`}}),e.jsxs("p",{className:"text-base xl:text-lg text-center text-gray-400 lowercase",children:["Ou ",e.jsx("a",{onClick:()=>window.location.reload(),className:"underline cursor-pointer",children:"tente novamente"})]})]})]})}),e.jsxs("p",{className:"text-sm text-center leading-3 text-gray-400 px-4 lowercase",children:["Se o problema persistir, entre em contato com o ",e.jsx("a",{href:"https://app.thenewscc.com.br/support?newsletter=thenews",className:"ml-1 underline",children:"suporte"})]})]})})}const me="https://worker.thenewscc.com/streaks/read",N="streak_pending_reads",v=3,A=1e3,he=7*24*60*60*1e3,xe="leitura registrada com sucesso";class ge{constructor(){S(this,"syncQueue",new Map);S(this,"isProcessing",new Map)}async syncStreakData(t,s){var o,i,l;if(this.isProcessing.get(t)){const a=this.syncQueue.get(t)||[];s&&a.push(s),this.syncQueue.set(t,a);return}this.isProcessing.set(t,!0),(o=s==null?void 0:s.onStart)==null||o.call(s);try{this.drainPendingReads().catch(u=>
1console.warn("Sync: falha ao drenar fila pendente:",u));const a=new URLSearchParams(window.location.search),r=await this.callReadAPI(a);if(r.success){const u={wasNewlyRegistered:!!r.wasNewlyRegistered,message:r.message};this.updateCaches(r.data,t),window.dispatchEvent(new CustomEvent("streak-sync",{detail:{email:t,data:r.data,...u}})),await new Promise(d=>setTimeout(d,200)),(i=s==null?void 0:s.onComplete)==null||i.call(s,r.data,u),(this.syncQueue.get(t)||[]).forEach(d=>{var g;return(g=d.onComplete)==null?void 0:g.call(d,r.data,u)}),this.syncQueue.delete(t)}else throw new Error(r.error||"Falha na sincronização")}catch(a){const r=a instanceof Error?a:new Error("Sync failed");(l=s==null?void 0:s.onError)==null||l.call(s,r),(this.syncQueue.get(t)||[]).forEach(h=>{var d;return(d=h.onError)==null?void 0:d.call(h,r)}),this.syncQueue.delete(t)}finally{this.isProcessing.set(t,!1)}}async callReadAPI(t){const s=localStorage.getItem("auth_token");if(!s){const x=new URLSearchParams(window.location.search),f=`${window.location.origin}${window.location.pathname}`;return x.set("origin",f),window.location.href=`https://auth.thenewscc.com.br/login?${x.toString()}`,{success:!1,error:"No token found"}}const o={},i=t.get("id"),l=t.get("utm_source"),a=t.get("utm_medium"),r=t.get("utm_channel"),u=t.get("utm_campaign");i&&(o.postId=i),l&&(o.utm_source=l),a&&(o.utm_medium=a),r&&(o.utm_channel=r),u&&(o.utm_campaign=u);const h=await this.executeReadFetch(o,s);if(h.status===401){localStorage.removeItem("auth_token");const x=new URLSearchParams(window.location.search),f=`${window.location.origin}${window.location.pathname}`;return x.set("origin",f),window.location.href=`https://auth.thenewscc.com.br/login?${x.toString()}`,{success:!1,error:"Unauthorized"}}if(h.kind==="http-error")return{success:!1,error:h.message||"API request failed"};if(h.kind==="retryable-failure")return this.enqueuePendingRead(o),{success:!1,error:h.message||"Network/server error"};const d=h.payload,g=typeof(d==null?void 0:d.message)=="string"?d.message:void 0,w=!!g&&g.toLowerCase().includes(xe);return{success:!0,data:d==null?void 0:d.data,message:g,wasNewlyRegistered:w}}async executeReadFetch(t,s){let o,i;for(let l=0;l<=v;l++)try{const a=await fetch(me,{method:"POST",keepalive:!0,headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify(t)});if(a.ok)return{kind:"success",payload:await a.json().catch(()=>null),status:a.status};o=a.status;const r=await a.json().catch(()=>null);if(i=r==null?void 0:r.message,a.status>=400&&a.status<500)return{kind:"http-error",status:a.status,message:i};if(l<v){await this.delay(A*(l+1));continue}}catch(a){if(i=a instanceof Error?a.message:"Network error",l<v){await this.delay(A*(l+1));continue}}return{kind:"retryable-failure",status:o,message:i}}delay(t){return new Promise(s=>setTimeout(s,t))}getPendingReads(){try{const t=localStorage.getItem(N);if(!t)return[];const s=JSON.parse(t);if(!Array.isArray(s))return[];const o=Date.now();return s.filter(i=>i&&typeof i.queuedAt=="number"&&o-i.queuedAt<he)}catch{return[]}}setPendingReads(t){try{t.length===0?localStorage.removeItem(N):localStorage.setItem(N,JSON.stringify(t))}catch(s){console.error("Failed to persist pending reads:",s)}}enqueuePendingRead(t){if(!t.postId&&!t.utm_source&&!t.utm_medium&&!t.utm_channel&&!t.utm_campaign)return;const s=this.getPendingReads();s.push({...t,queuedAt:Date.now()}),this.setPendingReads(s),console.warn("Sync: leitura enfileirada para retry futuro",t)}async drainPendingReads(){const t=localStorage.getItem("auth_token");if(!t)return;const s=this.getPendingReads();if(s.length===0)return;console.log(`Sync: drenando ${s.length} leitura(s) pendente(s)`);const o=[];for(const i of s){const{queuedAt:l,...a}=i,r=await this.executeReadFetch(a,t);r.kind!=="success"&&r.kind!=="http-error"&&o.push(i)}this.setPendingReads(o)}updateCaches(t,s){try{localStorage.setItem("streak_data_cache",JSON.stringify({email:s,data:{currentStreak:t.currentStreak,maxStreak:t.maxStreak,weekdays:t.weekdays,url:t.url},timestamp:Date.now()})),t.readingDates&&localStorage.setItem("reading_dates_cache",JSON.stringify({data:{readingDates:t.readingDates},timestamp:Date.now()}))}catch(o){console.error("Failed to update caches:",o)}}isEmailSyncing(t){return this.isProcessing.get(t)||!1}}const fe=new ge;function we({children:n,onSyncComplete:t}){const[s]=O(),{isAuthenticated:o,user:i}=I(),[l,a]=p.useState(!1),[r,u]=p.useState(!1);return p.useEffect(()=>{const h=s.get("read")==="true",d=s.get("email");if(h&&d&&!r){a(!0);const g=async()=>{const w=d||(i==null?void 0:i.email);w?(console.log("StreakDataSync: Iniciando sincronização única"),await fe.syncStreakData(w,{onComplete:(x,f)=>{console.log("StreakDataSync: Sincronização concluÃda!",f),u(!0),a(!1),t==null||t(),f!=null&&f.wasNewly
1Registered?y.success("Leitura registrada com sucesso!",{position:"top-right",autoClose:3e3}):y.info("Você já está em dia!",{position:"top-right",autoClose:3e3})},onError:x=>{console.error("StreakDataSync: Erro na sincronização:",x),u(!0),a(!1),y.error("Erro ao registrar leitura. Tente novamente.",{position:"top-right",autoClose:3e3})}})):(console.warn("StreakDataSync: Email não encontrado"),u(!0),a(!1))};if(!o&&!d){let w=0;const x=10;(async()=>{for(;!o&&w<x;)await new Promise(c=>setTimeout(c,100)),w++;g()})()}else g()}},[s,o,i,r,t]),l?e.jsx("div",{className:"w-full min-h-screen bg-gray-soft-lp-bg flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4"}),e.jsx("p",{className:"text-gray-600",children:"Registrando sua leitura..."})]})}):e.jsx(e.Fragment,{children:n})}function pe({showCalendar:n}){return e.jsx("div",{id:"streakMain",className:"w-full flex flex-col items-center gap-4",children:n?e.jsx(F,{}):null})}function Ae(){ne();const{streakData:n,loading:t,error:s,email:o}=te(),{isActive:i}=se(),l=(n==null?void 0:n.maxStreak)||0;p.useEffect(()=>{T.trackPageView({page_name:"streak_home_page",page_url:window.location.href})},[]);const{nextGoal:a,completedMissions:r}=Z(l);return s&&s===ae.INVALID_EMAIL?e.jsx(de,{error:s,userEmail:o||""}):e.jsx(we,{children:e.jsxs("div",{id:"streakHome",className:"w-full min-h-screen bg-gray-soft-lp-bg flex flex-col xl:flex-row xl:justify-center items-center",children:[e.jsx(K,{}),e.jsx(oe,{}),e.jsxs("div",{className:"xl:hidden md:max-w-3xl justify-center w-full pt-4 px-4 pb-14 flex flex-col gap-4 items-center",children:[i&&e.jsx(R,{}),!i&&e.jsx("a",{href:"https://link.thenewscc.com/redirect?url=VQl6BCSkrfcw&id={{resource_id}}",target:"_blank",children:e.jsx("img",{src:j.lojinha.mobile,alt:"Lojinha",className:"w-full rounded-md h-auto"})}),e.jsx(pe,{showCalendar:!0,currentStreak:(n==null?void 0:n.currentStreak)||0,nextGoal:(a==null?void 0:a.daysToMaintain)||0}),e.jsx(k,{streakData:n}),e.jsx(B,{variant:"compact",loading:t,completedMissions:r}),e.jsx(E,{}),e.jsx(P,{maxStreak:(n==null?void 0:n.maxStreak)||0}),e.jsxs("a",{href:"https://app.thenewscc.com.br/support?newsletter=thenews",className:"flex gap-1 text-gray-400",children:[e.jsx(M,{className:"h-4"}),e.jsxs("p",{className:"text-sm lowercase",children:["Precisa de ajuda? ",e.jsx("span",{className:"underline",children:"Entre em contato com o suporte"})]})]})]}),e.jsx("div",{className:"ml-[250px] hidden xl:flex xl:flex-col pb-20 w-full justify-center items-center",children:e.jsxs("div",{className:"max-w-6xl flex gap-12 pt-10 w-full",children:[e.jsxs("div",{className:"w-2/3 flex flex-col gap-6",children:[e.jsx("h1",{className:"text-xl md:text-2xl mb-2 text-gray font-medium text-center lowercase",children:H((n==null?void 0:n.currentStreak)||0)}),!i&&e.jsx("a",{href:"https://link.thenewscc.com/redirect?url=VQl6BCSkrfcw&id={{resource_id}}",target:"_blank",children:e.jsx("img",{src:j.lojinha.desktop,alt:"Lojinha",className:"w-full rounded-md h-auto"})}),t?e.jsx(ie,{}):e.jsx(Q,{showCalendar:!0,nextGoal:(a==null?void 0:a.daysToMaintain)||0}),t?e.jsx(_,{}):e.jsx(z,{})]}),e.jsxs("div",{className:"w-1/3 flex flex-col gap-6",children:[t?e.jsx(ce,{}):e.jsx(k,{streakData:n}),i&&e.jsx(R,{}),t?e.jsx(_,{}):e.jsx(P,{maxStreak:(n==null?void 0:n.maxStreak)||0}),t?e.jsx(ee,{}):e.jsx(E,{})]})]})}),e.jsx("div",{className:"xl:hidden",children:e.jsx(W,{})})]})})}export{Ae as StreakHomePage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.