1import{j as e}from"./ui-vendor-7ksmbWQe.js";import{r as n,u as W,i as ae}from"./react-vendor-LSUMIZ7H.js";import{r as X}from"./RewardAmount-3TSaSN1_.js";import{l as ee,B as S,X as re,P as Y,m as K,j as T,C as v,e as N,n as le,o as ie,u as oe,k as ne,p as L,D as ce,a as V,b as O,f as de,T as me,g as ue,q as Q}from"./index-DWFe9eMF.js";import{T as Z}from"./TranslatedContent-CYfKKLR5.js";import{c as pe}from"./accuracyUtils-DZ1EPLhq.js";import{u as G}from"./i18n-vendor-Cq4PMOpV.js";import{I as xe}from"./image-DFSrbkYV.js";import{C as fe}from"./circle-check-big-BRFBDULZ.js";import{U as ge}from"./upload-D80f99Bq.js";import{A as he,a as je}from"./alert-DW7avT1o.js";import{a as ve}from"./quillCopySnippet-BeIN0RjG.js";import{c as Ne}from"./networkFee-DfHLXRzC.js";import{D as be}from"./dollar-sign-CtNe3tg5.js";import{U as ke}from"./users-2RT-GKgj.js";import"./isEqual-90ER81th.js";async function we(x,f=1280,s=.75){return new Promise((y,i)=>{const j=new FileReader;j.onload=w=>{const l=new window.Image;l.onload=()=>{const m=document.createElement("canvas");let c=l.width,b=l.height;c>f&&(b=b*f/c,c=f),m.width=c,m.height=b;const d=m.getContext("2d");if(!d){i(new Error("Failed to get canvas context"));return}d.drawImage(l,0,0,c,b),y(m.toDataURL("image/jpeg",s))},l.onerror=()=>i(new Error("Failed to load image")),l.src=w.target?.result},j.onerror=()=>i(new Error("Failed to read file")),j.readAsDataURL(x)})}function Pe({taskId:x,label:f,placeholder:s,value:y,onChange:i,disabled:j,required:w=!0,onUploadingChange:l}){const[m,c]=n.useState(!1),[b,d]=n.useState(null),[U,u]=n.useState(0),[C,_]=n.useState(!1),P=n.useRef(null),{toast:k}=ee(),{t:p}=G();n.useEffect(()=>{l?.(m)},[m,l]);const I=async A=>{const g=A.target.files?.[0];if(g){if(!g.type.startsWith("image/")){k({title:p("toasts.invalidFile"),description:p("toasts.invalidFileDesc"),variant:"destructive"});return}if(g.size>10*1024*1024){k({title:p("toasts.fileTooLarge"),description:p("toasts.fileTooLargeDesc"),variant:"destructive"});return}c(!0),u(10),_(!1);try{u(20);const D=await we(g);d(D),u(40);const $=await T.uploadProofImage(x,D);u(100),_(!0),i($.url),k({title:p("toasts.imageUploaded"),description:p("toasts.imageUploadedDesc")})}
1catch(D){console.error("Upload error:",D),d(null),u(0),k({title:p("toasts.uploadFailed"),description:D.message||p("toasts.uploadFailedDesc"),variant:"destructive"})}finally{c(!1)}}},F=()=>{d(null),u(0),_(!1),i(""),P.current&&(P.current.value="")},R=y||b;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4 text-primary"}),f,w&&e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx("input",{ref:P,type:"file",accept:"image/*",onChange:I,className:"hidden",disabled:j||m}),R?e.jsxs("div",{className:"relative rounded-lg overflow-hidden border bg-muted",children:[e.jsx("img",{src:R,alt:"Proof",className:"w-full max-h-48 object-contain"}),!j&&!m&&e.jsx(S,{type:"button",size:"icon",variant:"destructive",className:"absolute top-2 right-2 h-8 w-8",onClick:F,children:e.jsx(re,{className:"h-4 w-4"})}),m&&e.jsxs("div",{className:"absolute inset-0 bg-background/80 flex flex-col items-center justify-center gap-2 p-4",children:[e.jsx(Y,{size:24,speed:1.6}),e.jsx(K,{value:U,className:"w-full max-w-32"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("proofUpload.uploading")})]}),C&&!m&&e.jsx("div",{className:"absolute top-2 left-2 bg-success text-success-foreground rounded-full p-1",children:e.jsx(fe,{className:"h-4 w-4"})})]}):e.jsx("div",{onClick:()=>!j&&!m&&P.current?.click(),className:` 2 border-2 border-dashed rounded-lg p-6 text-center cursor-pointer 3 transition-colors hover:border-primary/50 hover:bg-muted/50 4 ${j||m?"opacity-50 cursor-not-allowed":""} 5 ${w?"border-primary/30":""} 6 `,children:m?e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Y,{size:32,speed:1.6}),e.jsx(K,{value:U,className:"w-full max-w-32"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p("proofUpload.compressingUploading")})]}):e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(ge,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("proofUpload.clickToSelect",{size:10})})]})})]})}function De(){const{t:x}=G(),f=W();return e.jsx(v,{className:"border-warning/50 bg-warning/5",children:e.jsxs(N,{className:"py-12 text-center space-y-4",children:[e.jsx("div",{className:"mx-auto w-16 h-16 rounded-full bg-warning/10 flex items-center justify-center",children:e.jsx(le,{className:"h-8 w-8 text-warning"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-1",children:x("profileCompletion.requiredTitle","Complete Your Profile First")}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-sm mx-auto",children:x("profileCompletion.requiredDescription","You need to complete your profile (name, country, and phone number) before you can access tasks.")})]}),e.jsxs(S,{onClick:()=>f("/complete-profile"),className:"gap-2",children:[e.jsx(ie,{className:"h-4 w-4"}),x("profileCompletion.updateNow","Update Now")]})]})})}function qe(){const{taskId:x}=ae(),f=W(),{t:s,i18n:y}=G(),{toast:i}=ee(),{isProfileIncomplete:j}=oe(),{data:w}=ne(),[l,m]=n.useState(null),[c,b]=n.useState(null),[d,U]=n.useState(null),[u,C]=n.useState({}),[_,P]=n.useState(!0),[k,p]=n.useState(!1),[I,F]=n.useState(!1),[R,A]=n.useState(null),[g,D]=n.useState(0);n.useEffect(()=>{const t=r=>{if(g>0)return r.preventDefault(),r.returnValue="",r.returnValue};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[g]);const $=n.useCallback(t=>{D(r=>t?r+1:Math.max(0,r-1))},[]),z=n.useCallback(()=>{if(!c||d)return null;const t=new Date(c.expires_at),r=new Date,a=t.getTime()-r.getTime();if(a<=0)return s("taskDetailPage.expired");const o=Math.floor(a/6e4),h=Math.floor(a%6e4/1e3);return`${o}:${h.toString().padStart(2,"0")}`},[c,d,s]);n.useEffect(()=>{B()},[x]),n.useEffect(()=>{if(!c||d)return;const t=setInterval(()=>{const r=z();A(r),r===s("taskDetailPage.expired")&&(i({title:s("toasts.timeExpired"),description:s("toasts.timeExpiredDesc"),variant:"destructive"}),f("/tasks"))},1e3);return A(z()),()=>clearInterval(t)},[c,d,z,f,i,s]);const B=async()=>{try{const t=await T.getTask(x);if(!t){m(null),P(!1);return}const r=await T.getProfile(),a=(r?.tasks_completed||0)+(r?.tasks_pen
6ding||0),o=pe(r?.tasks_completed||0,a);if(t.minimum_accuracy>0&&o<t.minimum_accuracy){i({title:s("toasts.accessDenied"),description:s("toasts.accessDeniedDesc",{accuracy:t.minimum_accuracy,current:o.toFixed(1)}),variant:"destructive"}),f("/tasks");return}m(t),b(t.lock||null),U(t.proof||null)}catch(t){i({title:s("toasts.error"),description:t.message,variant:"destructive"})}finally{P(!1)}},se=async()=>{F(!0);try{const t=await T.acceptTask(x);i({title:s("toasts.success"),description:t.message}),await B()}catch(t){console.error("Accept task error:",t),i({title:s("toasts.error"),description:t.message||s("toasts.failedAcceptTask"),variant:"destructive"})}finally{F(!1)}},te=async()=>{const t=l?.proof_requirements||[];if(t.length>0){const r=t.filter((a,o)=>(a.type==="image"||a.required!==!1)&&!u[`proof_${o}`]?.trim());if(r.length>0){i({title:s("toasts.missingProofs"),description:s("toasts.missingProofsDesc",{fields:r.map(a=>a.label).join(", ")}),variant:"destructive"});return}}else if(!u.proof_0?.trim()){i({title:s("toasts.error"),description:s("toasts.provideProof"),variant:"destructive"});return}if(g>0){i({title:s("toasts.uploadInProgress"),description:s("toasts.uploadInProgressDesc"),variant:"destructive"});return}p(!0);try{const r=t.length>0?t.map((o,h)=>({label:o.label,value:u[`proof_${h}`]||""})):[{label:"Proof",value:u.proof_0||""}],a=await T.submitProof(x,JSON.stringify(r));i({title:s("toasts.success"),description:a.message}),await B()}catch(r){i({title:s("toasts.error"),description:r.message,variant:"destructive"})}finally{p(!1)}};if(_)return e.jsx("div",{className:"min-h-screen bg-background pb-20 md:pb-6 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Y,{size:48,speed:1.6,className:"mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:s("taskDetailPage.loadingTask")})]})});if(!l)return e.jsx("div",{className:"min-h-screen bg-background pb-20 md:pb-6 flex items-center justify-center",children:e.jsx(v,{className:"max-w-md mx-4",children:e.jsxs(N,{className:"pt-6 text-center",children:[e.jsx(L,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-bold mb-2",children:s("taskDetailPage.notFound")}),e.jsx("p",{className:"text-muted-foreground mb-4",children:s("taskDetailPage.notFoundDesc")}),e.jsx(S,{onClick:()=>f("/tasks"),children:s("taskDetailPage.backToTasks")})]})})});const M=l?.proof_requirements||[];return e.jsxs("div",{className:"min-h-screen bg-background pb-20 md:pb-6",children:[e.jsx(ce,{payableBalance:0,pendingBalance:0}),e.jsx("main",{className:"container mx-auto px-4 pt-24 md:pt-6 pb-8 space-y-6",children:j?e.jsx(De,{}):e.jsxs(e.Fragment,{children:[e.jsx(Z,{texts:{title:l.title||"",description:l.description||"",instructions:l.instructions||""},targetLanguage:y.language,children:(t,r)=>e.jsxs(e.Fragment,{children:[e.jsxs(v,{children:[e.jsx(V,{children:e.jsx(O,{children:t.title})}),e.jsxs(N,{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground",children:t.description}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 pt-4 border-t",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-success/10",children:e.jsx(be,{className:"h-4 w-4 text-success"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("taskDetailPage.baseReward")}),(()=>{const a=X(l);return e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsxs("p",{className:"font-semibold text-success",children:["â¥",Math.floor(a.effective)]}),a.boost>0&&e.jsxs("p",{className:"text-xs line-through text-muted-foreground",children:["â¥",Math.floor(a.original)]})]})})(),(()=>{const a=X(l),{net:o,waived:h}=Ne(a.original,{threshold:w?.network_fee_waiver_threshold,rate:w?.network_fee_rate}),E=o+a.boost;return e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s("taskDetailPage.youGet",{amount:Math.floor(E)}),h?` · ${s("taskDetailPage.noNetworkFee",{defaultValue:"no network fee"})}`:""]})})()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-warning/10",children:e.jsx(de,{className:"h-4 w-4 text-warning"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("taskDetailPage.timeLimit")}),e.jsxs("p",{className:"font-semibold",children:[l.lock_duration_minutes,"m"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-info/10",children:e.jsx(ke,{className:"h-4 w-4 text-info"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("taskDetailPage.slots")}),e.jsxs("p",{className:"font-semibold",children:[l.claimed,"/",l.max_claims]})]})]})]})]})]}),t.instructions&&e.jsxs(v,{children:[e.jsx(V,{children:e.jsx(O,{className:"text-lg",children:s("taskDetailPage.instructions")})}),e.jsx(N,{children:e.jsx("div",{className:"rich-text-content text-sm",ref:
6a=>{if(!a)return;const o=ve(a,()=>i({title:s("common.copiedToClipboard")}),()=>i({title:s("common.error"),variant:"destructive"})),h=a.__copySnippetCleanup;h?.(),a.__copySnippetCleanup=o},dangerouslySetInnerHTML:{__html:t.instructions}})})]})]})}),c&&!d&&e.jsx(v,{className:"border-warning bg-warning/5",children:e.jsx(N,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(me,{className:"h-8 w-8 text-warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold",children:s("taskDetailPage.taskAccepted")}),e.jsx("p",{className:"text-2xl font-bold text-warning",children:R||s("taskDetailPage.calculating")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("taskDetailPage.timeRemaining")})]})]})})}),g>0&&e.jsxs(he,{children:[e.jsx(L,{className:"h-4 w-4"}),e.jsx(je,{children:s("proofUpload.uploadingImages",{count:g})})]}),d&&e.jsx(v,{className:"border-success bg-success/5",children:e.jsx(N,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ue,{className:"h-8 w-8 text-success"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold",children:s("taskDetailPage.proofSubmitted")}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s("taskDetailPage.status")," ",e.jsx("span",{className:"capitalize font-medium",children:d.status})]})]})]})})}),c&&!d&&(()=>{const t={};return M.forEach((r,a)=>{r.label&&(t[`label_${a}`]=r.label),r.placeholder&&(t[`placeholder_${a}`]=r.placeholder)}),e.jsxs(v,{children:[e.jsx(V,{children:e.jsx(O,{children:s("taskDetailPage.submitProof")})}),e.jsxs(N,{className:"space-y-4",children:[M.length>0?e.jsx(Z,{texts:t,targetLanguage:y.language,children:r=>e.jsx("div",{className:"space-y-4",children:M.map((a,o)=>{const h=a.type==="image"||a.required!==!1,E=r[`label_${o}`]||a.label,J=r[`placeholder_${o}`]||a.placeholder;return e.jsx("div",{className:"space-y-2",children:a.type==="image"?e.jsx(Pe,{taskId:x,label:E,placeholder:J,value:u[`proof_${o}`]||"",onChange:q=>C(H=>({...H,[`proof_${o}`]:q})),disabled:k,required:!0,onUploadingChange:$}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"text-sm font-medium",children:[E,h&&e.jsx("span",{className:"text-destructive ml-1",children:"*"}),!h&&e.jsxs("span",{className:"text-muted-foreground ml-1 text-xs",children:["(",s("proofUpload.optional"),")"]})]}),e.jsx(Q,{placeholder:J,value:u[`proof_${o}`]||"",onChange:q=>C(H=>({...H,[`proof_${o}`]:q.target.value})),rows:2})]})},o)})})}):e.jsx(Q,{placeholder:s("taskDetailPage.defaultProofPlaceholder"),value:u.proof_0||"",onChange:r=>C(a=>({...a,proof_0:r.target.value})),rows:4}),e.jsx(S,{onClick:te,disabled:k||g>0,className:"w-full",children:k?s("taskDetailPage.submitting"):g>0?s("taskDetailPage.waitForUploads"):s("taskDetailPage.submitProof")})]})]})})(),!c&&!d&&l.status==="active"&&l.claimed<l.max_claims&&e.jsx(S,{onClick:se,disabled:I,className:"w-full",size:"lg",children:s(I?"taskDetailPage.accepting":"taskDetailPage.acceptTask")}),!c&&!d&&l.status!=="active"&&l.status!=="paused"&&e.jsx(v,{className:"border-destructive bg-destructive/5",children:e.jsxs(N,{className:"pt-6 text-center",children:[e.jsx(L,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),e.jsx("h3",{className:"font-semibold mb-2",children:s("taskDetailPage.taskUnavailable")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("taskDetailPage.noLongerAvailable")})]})}),!c&&!d&&(l.status==="active"||l.status==="paused")&&l.claimed>=l.max_claims&&e.jsx(v,{className:"border-destructive bg-destructive/5",children:e.jsxs(N,{className:"pt-6 text-center",children:[e.jsx(L,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),e.jsx("h3",{className:"font-semibold mb-2",children:s("taskDetailPage.noSlots")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("taskDetailPage.allSlotsTaken")})]})})]})})]})}export{qe as default};
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.