import{o as L,r as n,H as xe,c as Oe,j as e,e as Ae,P as he,d as ze,a9 as _e,aa as Be,i as D,ab as Fe,a as z,ac as fe,ad as Ve,q as v,S as Ue,ae as q,v as C,af as H,p as ge,a8 as ie,x as k,y as S,ag as P,ah as M,T as Je,A as X,a7 as $e,C as je,D as ye,w as T,ai as ne,aj as Ke,u as qe,a1 as Ge,k as He,n as Xe,U as Ze,ak as E,s as w,I as ce,al as Ye,M as Qe,am as We,an as es,a6 as ss,B as ts}from"./index-oAPVDf-r.js";import{D as as,a as rs,b as is,c as ns,u as cs,S as O}from"./dropdown-menu-CBJEO_Gg.js";import{B as U}from"./badge-Qwi4CUXx.js";import{u as os,A as oe}from"./useIdentityVerification-CD3mPBIt.js";import{C as ls}from"./check-CG8zylH4.js";import{P as ds}from"./progress-Cql_vZKU.js";import{R as ms}from"./refresh-cw-DEBvxUr1.js";import{C as Ne}from"./clock-DRtqJZUo.js";import{T as us}from"./trending-up-Be0ZnpBQ.js";import{E as ps}from"./eye-G89nJUb2.js";import{L as xs}from"./leaf-DHbwTQEy.js";import{Z as hs}from"./zap-RaPdKGJZ.js";import{S as fs,a as gs,b as js,c as ys,d as Ns}from"./select-Bi-TzF3J.js";import{M as vs}from"./mail-BT0S3dBU.js";import{S as le}from"./shield-BWGzcrms.js";import{C as bs}from"./circle-alert-C1Hs9zwh.js";import{B as J}from"./building-2-w77rCUKE.js";import{C as de}from"./credit-card-CfUVKCDe.js";import{P as ws}from"./palette-xHAcW495.js";import{S as ks}from"./save-BwjzM02b.js";import"./index-DGH-oZ97.js";import"./chevron-right-B9rMgght.js";import"./circle-030W8joh.js";import"./chevron-down-QDDHZwZg.js";/** * @license lucide-react v0.462.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ss=L("BellOff",[["path",{d:"M8.7 3A6 6 0 0 1 18 8a21.3 21.3 0 0 0 .6 5",key:"o7mx20"}],["path",{d:"M17 17H3s3-2 3-9a4.67 4.67 0 0 1 .3-1.7",key:"16f1lm"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/** * @license lucide-react v0.462.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const me=L("Flame",[["path",{d:"M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z",key:"96xj49"}]]);/** * @license lucide-react v0.462.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Cs=L("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/** * @license lucide-react v0.462.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ve=L("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/** * @license lucide-react v0.462.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Is=L("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/** * @license lucide-react v0.462.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ps=L("Radar",[["path",{d:"M19.07 4.93A10 10 0 0 0 6.99 3.34",key:"z3du51"}],["path",{d:"M4 6h.01",key:"oypzma"}],["path",{d:"M2.29 9.62A10 10 0 1 0 21.31 8.35",key:"qzzz0"}],["path",{d:"M16.24 7.76A6 6 0 1 0 8.23 16.67",key:"1yjesh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M17.99 11.66A6 6 0 0 1 15.77 16.67",key:"1u2y91"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"m13.41 10.59 5.66-5.66",key:"mhq4k0"}]]);/** * @license lucide-react v0.462.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ms=L("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);var $="Switch",[Es]=Ae($),[Ds,Ts]=Es($),be=n.forwardRef((t,s)=>{const{__scopeSwitch:a,name:h,checked:c,defaultChecked:r,required:i,disabled:u,value:l="on",onCheckedChange:p,form:g,...f}=t,[d,x]=n.useState(null),o=xe(s,I=>x(I)),j=n.useRef(!1),y=d?g||!!d.closest("form"):!0,[N,R]=Oe({prop:c,defaultProp:r??!1,onChange:p,caller:$});return e.jsxs(Ds,{scope:a,checked:N,disabled:u,children:[e.jsx(he.button,{type:"button",role:"switch","aria-checked":N,"aria-required":i,"data-state":Ce(N),"data-disabled":u?"":void 0,disabled:u,value:l,...f,ref:o,onClick:ze(t.onClick,I=>{R(_=>!_),y&&(j.current=I.isPropagationStopped(),j.current||I.stopPropagation())})}),y&&e.jsx(Se,{control:d,bubbles:!j.current,name:h,value:l,checked:N,required:i,disabled:u,form:g,style:{transform:"translateX(-100%)"}})]})});be.displayName=$;var we="SwitchThumb",ke=n.forwardRef((t,s)=>{const{__scopeSwitch:a,...h}=t,c=Ts(we,a);return e.jsx(he.span,{"data-state":Ce(c.checked),"data-disabled":c.disabled?"":void 0,...h,ref:s})});ke.displayName=we;var Ls="SwitchBubbleInput",Se=n.forwardRef(({__scopeSwitch:t,control:s,checked:a,bubbles:h=!0,...c},r)=>{const i=n.useRef(null),u=xe(i,r),l=_e(a),p=Be(s);return n.useEffect(()=>{const g=i.current;if(!g)return;const f=window.HTMLInputElement.prototype,x=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==a&&x){const o=new Event("click",{bubbles:h});x.call(g,a),g.dispatchEvent(o)}},[l,a,h]),e.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:a,...c,tabIndex:-1,ref:u,style:{...c.style,...p,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Se.displayName=Ls;function Ce(t){return t?"checked":"unchecked"}var Ie=be,Rs=ke;const A=n.forwardRef(({className:t,...s},a)=>e.jsx(Ie,{className:D("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",t),...s,ref:a,children:e.jsx(Rs,{className:D("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));A.displayName=Ie.displayName;const Os=[{id:"light",icon:fe},{id:"dark",icon:ve},{id:"auto",icon:Ve}];function As(){const{theme:t,setTheme:s,resolvedTheme:a,lightLevel:h}=Fe(),{t:c}=z(),r=Math.round(h/60*100);return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid grid-cols-3 gap-2",children:Os.map(({id:i,icon:u})=>{const l=t===i;return e.jsxs("button",{onClick:()=>s(i),className:D("relative flex flex-col items-center gap-2 p-4 rounded-xl border-2 transition-all duration-200",l?"border-primary bg-primary/10":"border-border hover:border-primary/50 hover:bg-muted/50"),children:[l&&e.jsx(v.div,{layoutId:"theme-indicator",className:"absolute inset-0 rounded-xl bg-primary/5 border-2 border-primary",transition:{type:"spring",bounce:.2,duration:.4}}),e.jsx("div",{className:D("relative z-10 w-10 h-10 rounded-full flex items-center justify-center transition-colors",l?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:e.jsx(u,{className:"w-5 h-5"})}),e.jsxs("div",{className:"relative z-10 text-center",children:[e.jsx("p",{className:D("text-sm font-medium transition-colors",l?"text-primary":"text-foreground"),children:c(`themeSelector.${i}.label`)}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:c(`themeSelector.${i}.description`)})]})]},i)})}),t==="auto"&&e.jsxs(v.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-muted/50 text-sm",children:[e.jsx(Ue,{className:"w-4 h-4 text-primary flex-shrink-0"}),e.jsxs("span",{className:"text-muted-foreground",children:[c("themeSelector.currentMode")," ",e.jsx("span",{className:"text-foreground font-medium",children:c(a==="dark"?"themeSelector.darkMode":"themeSelector.lightMode")})]})]}),e.jsxs("div",{className:"px-3 py-3 rounded-lg bg-muted/30 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("span",{className:"text-muted-foreground flex items-center gap-1.5",children:[e.jsx(ve,{className:"w-3 h-3"}),c("themeSelector.lightLevelDark")]}),e.jsxs("span",{className:"text-foreground font-mono font-medium",children:[c("themeSelector.lightLevel")," ",h,"/60"]}),e.jsxs("span",{className:"text-muted-foreground flex items-center gap-1.5",children:[c("themeSelector.lightLevelLight"),e.jsx(fe,{className:"w-3 h-3"})]})]}),e.jsx("div",{className:"relative h-2 rounded-full overflow-hidden bg-gradient-to-r from-slate-800 via-slate-500 to-amber-100",children:e.jsx(v.div,{className:"absolute top-0 bottom-0 w-1 bg-primary shadow-lg shadow-primary/50",initial:{left:"0%"},animate:{left:`${r}%`},transition:{type:"spring",bounce:.3,duration:.6},style:{transform:"translateX(-50%)"}})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:c("themeSelector.autoDescription")})]})]})]})}function zs(){const{i18n:t}=z(),[s,a]=n.useState(!1),h=q.find(r=>r.code===t.language)||q[0],c=r=>{t.changeLanguage(r),a(!1)};return e.jsxs(as,{open:s,onOpenChange:a,children:[e.jsx(rs,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(H,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:h.name}),e.jsx("span",{className:"sm:hidden",children:h.flag})]})}),e.jsx(is,{align:"end",children:q.map(r=>e.jsxs(ns,{onClick:()=>c(r.code),className:"gap-2 cursor-pointer",children:[e.jsx("span",{children:r.flag}),e.jsx("span",{className:"flex-1",children:r.name}),t.language===r.code&&e.jsx(ls,{className:"w-4 h-4 text-primary"})]},r.code))})]})}const G="https://api.quixzoom.com/api/qz",_s=()=>{const{user:t}=ge(),[s,a]=n.useState(null),[h,c]=n.useState(null),[r,i]=n.useState(!0),[u,l]=n.useState(!1),p=n.useCallback(async()=>{if(!t){a(null),i(!1);return}const d=ie.getToken();if(!d){i(!1);return}try{(await fetch(`${G}/auth/wallet`,{headers:{Authorization:`Bearer ${d}`}})).ok}catch{}try{const x=await fetch(`${G}/missions/stats`,{headers:{Authorization:`Bearer ${d}`}});if(x.ok){const o=await x.json();o&&o.user_id&&a(o)}}catch{}i(!1)},[t]),g=n.useCallback(async()=>{if(!t)return null;l(!0);try{const d=ie.getToken();if(!d)return null;const x=await fetch(`${G}/missions/calculate-priority`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`}});if(!x.ok)throw new Error("Failed to calculate priority");const o=await x.json();return c({priorityScore:o.priorityScore,visibilityDelay:o.visibilityDelay,totalCompleted:o.stats.totalCompleted,totalClaimed:o.stats.totalClaimed,totalExpired:o.stats.totalExpired,approvalRate:o.stats.approvalRate,avgCompletionTime:o.stats.avgCompletionTime,streakDays:o.stats.streakDays,recentCompletions:o.stats.recentCompletions}),await p(),o}catch(d){return console.error("Error calculating score:",d),null}finally{l(!1)}},[t,p]);n.useEffect(()=>{p()},[p]);const f=n.useCallback(d=>d>=90?{name:"Elite",color:"text-yellow-400",icon:"🔥"}:d>=70?{name:"Pro",color:"text-purple-400",icon:"⚡"}:d>=50?{name:"Aktiv",color:"text-blue-400",icon:"📸"}:d>=30?{name:"Rookie",color:"text-green-400",icon:"🌱"}:{name:"Ny",color:"text-muted-foreground",icon:"👋"},[]);return{performance:s,stats:h,loading:r,calculating:u,calculateScore:g,fetchPerformance:p,getTier:f}},Bs=()=>{const{t}=z(),{performance:s,stats:a,loading:h,calculating:c,calculateScore:r,getTier:i}=_s();if(h)return e.jsx(k,{className:"bg-card/50 backdrop-blur-sm border-border/50",children:e.jsx(S,{className:"p-6",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-4 bg-muted rounded w-1/3"}),e.jsx("div",{className:"h-8 bg-muted rounded w-2/3"}),e.jsx("div",{className:"h-2 bg-muted rounded"})]})})});const u=(s==null?void 0:s.priority_score)||(a==null?void 0:a.priorityScore)||50,l=i(u),p=(s==null?void 0:s.visibility_delay_seconds)||(a==null?void 0:a.visibilityDelay)||60,g={Elite:e.jsx(me,{className:"h-5 w-5"}),Pro:e.jsx(hs,{className:"h-5 w-5"}),Active:e.jsx(je,{className:"h-5 w-5"}),Rookie:e.jsx(xs,{className:"h-5 w-5"}),New:e.jsx(ps,{className:"h-5 w-5"})},f=d=>({Elite:t("performance.tierElite"),Pro:t("performance.tierPro"),Aktiv:t("performance.tierActive"),Active:t("performance.tierActive"),Rookie:t("performance.tierRookie"),Ny:t("performance.tierNew"),New:t("performance.tierNew")})[d]||d;return e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3},children:e.jsxs(k,{className:"bg-gradient-to-br from-card via-card to-primary/5 border-border/50 overflow-hidden",children:[e.jsx(P,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(M,{className:"text-lg flex items-center gap-2",children:[e.jsx(Je,{className:"h-5 w-5 text-primary"}),t("performance.title")]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:r,disabled:c,className:"h-8",children:e.jsx(ms,{className:D("h-4 w-4",c&&"animate-spin")})})]})}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:D("p-2 rounded-full",u>=90?"bg-yellow-500/20":u>=70?"bg-purple-500/20":u>=50?"bg-blue-500/20":u>=30?"bg-green-500/20":"bg-muted"),children:e.jsx("span",{className:l.color,children:g[l.name]||g.Active})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("performance.level")}),e.jsxs("p",{className:D("font-bold text-lg",l.color),children:[l.icon," ",f(l.name)]})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("performance.score")}),e.jsx("p",{className:"font-bold text-2xl",children:Math.round(u)})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ds,{value:u,className:"h-2"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0"}),e.jsx("span",{children:"50"}),e.jsx("span",{children:"100"})]})]}),e.jsx("div",{className:D("p-3 rounded-lg",p===0?"bg-yellow-500/10 border border-yellow-500/20":p<=15?"bg-purple-500/10 border border-purple-500/20":p<=30?"bg-blue-500/10 border border-blue-500/20":"bg-muted/50 border border-border/50"),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:p===0?`⚡ ${t("performance.seeMissionsFirst")}`:p<=15?`⚡ ${t("performance.headStart",{seconds:p})}`:p<=30?t("performance.headStart",{seconds:p}):t("performance.delay",{seconds:p})})]})}),(a||s)&&e.jsxs("div",{className:"grid grid-cols-3 gap-2 pt-2",children:[e.jsxs("div",{className:"text-center p-2 bg-muted/30 rounded-lg",children:[e.jsx(X,{className:"h-4 w-4 mx-auto text-green-500 mb-1"}),e.jsx("p",{className:"text-lg font-bold",children:(a==null?void 0:a.totalCompleted)??(s==null?void 0:s.total_missions_completed)??0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("performance.completed")})]}),e.jsxs("div",{className:"text-center p-2 bg-muted/30 rounded-lg",children:[e.jsx(us,{className:"h-4 w-4 mx-auto text-primary mb-1"}),e.jsxs("p",{className:"text-lg font-bold",children:[(a==null?void 0:a.approvalRate)??Math.round((s==null?void 0:s.approval_rate)??0),"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("performance.approved")})]}),e.jsxs("div",{className:"text-center p-2 bg-muted/30 rounded-lg",children:[e.jsx(me,{className:"h-4 w-4 mx-auto text-orange-500 mb-1"}),e.jsx("p",{className:"text-lg font-bold",children:(a==null?void 0:a.streakDays)??(s==null?void 0:s.streak_days)??0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("performance.streak")})]})]}),((a==null?void 0:a.totalExpired)||0)>0&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-destructive/10 rounded-lg text-sm",children:[e.jsx($e,{className:"h-4 w-4 text-destructive"}),e.jsx("span",{className:"text-destructive",children:t("performance.expiredAffectScore",{count:a==null?void 0:a.totalExpired})})]})]})]})})},B=[{id:"JBFqnCBsd6RMkjVDRZzb",name:"George",descriptionKey:"voiceDescriptions.george"},{id:"EXAVITQu4vr4xnSDxMaL",name:"Sarah",descriptionKey:"voiceDescriptions.sarah"},{id:"TX3LPaxmHKxFdv7VOQHJ",name:"Liam",descriptionKey:"voiceDescriptions.liam"},{id:"XrExE9yKIg1WjnnlVkGX",name:"Matilda",descriptionKey:"voiceDescriptions.matilda"},{id:"onwK4e9ZLuTAKqWW03F9",name:"Daniel",descriptionKey:"voiceDescriptions.daniel"}];function Fs({value:t,onChange:s,disabled:a}){const{t:h,i18n:c}=z(),[r,i]=n.useState(!1),[u,l]=n.useState(null),p=B.find(f=>f.id===t)||B[0],g=async()=>{if(u){u.pause(),u.src="",l(null),i(!1);return}i(!0);try{const f=h("voiceSample",{name:p.name}),d=await fetch("https://tmmrlsaixtghdicmmpmp.supabase.co/functions/v1/elevenlabs-tts",{method:"POST",headers:{"Content-Type":"application/json",apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InRtbXJsc2FpeHRnaGRpY21tcG1wIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2Njk4ODQsImV4cCI6MjA4MzI0NTg4NH0.lKID0Mt0B-uyYWi57xldQJ56stbG7YopeOEy4ObKoMU",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InRtbXJsc2FpeHRnaGRpY21tcG1wIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2Njk4ODQsImV4cCI6MjA4MzI0NTg4NH0.lKID0Mt0B-uyYWi57xldQJ56stbG7YopeOEy4ObKoMU"},body:JSON.stringify({text:f,voiceId:p.id})});if(!d.ok)throw new Error("Failed to generate audio");const x=await d.blob(),o=URL.createObjectURL(x),j=new Audio(o);j.onended=()=>{i(!1),l(null),URL.revokeObjectURL(o)},j.onerror=()=>{i(!1),l(null),T.error(h("voicePreviewError"))},l(j),await j.play()}catch(f){console.error("Voice preview error:",f),T.error(h("voicePreviewError")),i(!1)}};return e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(fs,{value:t,onValueChange:s,disabled:a,children:[e.jsx(gs,{className:"flex-1",children:e.jsx(js,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ye,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:p.name}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:["- ",h(p.descriptionKey)]})]})})}),e.jsx(ys,{children:B.map(f=>e.jsx(Ns,{value:f.id,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:f.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:h(f.descriptionKey)})]})},f.id))})]}),e.jsx(C,{type:"button",variant:"outline",size:"icon",className:"shrink-0",onClick:g,disabled:a,title:h("voicePreviewButton"),children:r?e.jsx(Ms,{className:"h-4 w-4 fill-current"}):e.jsx(Is,{className:"h-4 w-4"})})]})}const Vs=({latitude:t,longitude:s,reachMeters:a})=>{const{t:h}=z(),c=n.useRef(null),r=n.useRef(null),[i,u]=n.useState(!1),[l,p]=n.useState(null),[g,f]=n.useState(null),d=n.useRef(a);n.useEffect(()=>{d.current=a},[a]),n.useEffect(()=>{(async()=>{try{const N=await Ke();N&&p(N)}catch(N){console.error("Failed to fetch Mapbox token:",N)}})()},[]);const x=t??59.3293,o=s??18.0686,j=n.useCallback(()=>{if(!r.current||!c.current)return;const y=r.current.getCenter(),N=d.current,R=y.lat+N/111320,I=r.current.project([y.lng,y.lat]),_=r.current.project([y.lng,R]),Z=Math.max(0,Math.abs(_.y-I.y));f({cx:I.x,cy:I.y,r:Z})},[]);return n.useEffect(()=>{if(!l||!c.current||r.current)return;ne.accessToken=l,r.current=new ne.Map({container:c.current,style:"mapbox://styles/mapbox/dark-v11",center:[o,x],zoom:pe(a),interactive:!1,attributionControl:!1,logoPosition:"bottom-right"});const y=c.current.querySelector(".mapboxgl-ctrl-logo");return y&&(y.style.display="none"),r.current.on("load",()=>{r.current&&(r.current.addSource("reach-circle",{type:"geojson",data:ue(x,o,a)}),r.current.addLayer({id:"reach-circle-fill",type:"fill",source:"reach-circle",paint:{"fill-color":"rgba(255, 255, 255, 0.15)","fill-opacity":1}}),r.current.addLayer({id:"reach-circle-outline",type:"line",source:"reach-circle",paint:{"line-color":"#E07850","line-width":6,"line-opacity":1}}),r.current.addSource("center-point",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[o,x]}}}),r.current.addLayer({id:"center-point",type:"circle",source:"center-point",paint:{"circle-radius":8,"circle-color":"hsl(185, 70%, 50%)","circle-stroke-width":3,"circle-stroke-color":"#ffffff"}}),u(!0),j(),r.current.on("move",j),r.current.on("zoom",j),r.current.on("resize",j))}),()=>{r.current&&(r.current.off("move",j),r.current.off("zoom",j),r.current.off("resize",j),r.current.remove(),r.current=null,u(!1))}},[l,x,o]),n.useEffect(()=>{if(!r.current||!i)return;const y=r.current.getSource("reach-circle");y&&y.setData(ue(x,o,a));const N=pe(a);r.current.flyTo({center:[o,x],zoom:N,duration:500}),j(),r.current.once("moveend",j)},[a,x,o,i,j]),n.useEffect(()=>{if(!r.current||!i)return;const y=r.current.getSource("center-point");y&&y.setData({type:"Feature",properties:{},geometry:{type:"Point",coordinates:[o,x]}})},[x,o,i]),l?e.jsxs("div",{className:"relative aspect-square rounded-xl overflow-hidden border border-border/50",children:[e.jsx("div",{ref:c,className:"absolute inset-0 [&_.mapboxgl-ctrl-logo]:!hidden [&_.mapboxgl-ctrl-attrib]:!hidden"}),g&&g.r>0&&e.jsx("svg",{className:"absolute inset-0 pointer-events-none",width:"100%",height:"100%","aria-hidden":"true",children:e.jsx("circle",{cx:g.cx,cy:g.cy,r:g.r,vectorEffect:"non-scaling-stroke",style:{fill:"hsl(var(--background) / 0.35)",stroke:"hsl(var(--destructive))",strokeWidth:4,opacity:.95}})}),e.jsx("div",{className:"absolute inset-0 pointer-events-none bg-gradient-to-t from-background/20 via-transparent to-background/20"})]}):e.jsx("div",{className:"aspect-square rounded-xl bg-muted/50 flex items-center justify-center",children:e.jsx("div",{className:"animate-pulse text-sm text-muted-foreground",children:h("map.loadingMap")})})};function ue(t,s,a){const c=[];for(let r=0;r<=64;r++){const i=r/64*2*Math.PI,u=a*Math.cos(i),p=a*Math.sin(i)/111320,g=u/(111320*Math.cos(t*Math.PI/180));c.push([s+g,t+p])}return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[c]}}}function pe(t){return t<=500?12.8:t<=1e3?11.8:t<=2e3?10.8:t<=3e3?10.3:t<=5e3?9.8:t<=7500?9.3:t<=1e4?8.8:t<=15e3?8.3:t<=2e4?7.8:t<=3e4?7.3:t<=4e4?6.8:t<=5e4?6.3:5.8}const ut=()=>{const t=qe(),{t:s}=z(),{user:a,signOut:h}=ge(),{wallet:c,isLoading:r}=cs(),{profile:i,isLoading:u,updateProfile:l}=Ge(),{error:p,requestPosition:g}=He(),{ordererProfile:f,isActiveOrderer:d,isPendingOrderer:x}=Xe(),{isVerified:o}=os(a==null?void 0:a.id),[j,y]=n.useState(""),[N,R]=n.useState(5e3),[I,_]=n.useState(""),[Z,Pe]=n.useState(!1),[Y,Q]=n.useState(!1),[W,ee]=n.useState(B[0].id),[F,V]=n.useState({newMissions:!0,claimUpdates:!0,rewards:!0,marketing:!1}),[se,te]=n.useState(!1),[K,ae]=n.useState(null),re=m=>{if(!m.trim())return null;if(m.length<2)return s("profile.nicknameMinChars");if(m.length>20)return s("profile.nicknameMaxChars");const b=[/sex/i,/fuck/i,/shit/i,/ass(?:hole)?/i,/dick/i,/cock/i,/pussy/i,/nazi/i,/hitler/i,/kuk/i,/fitta/i,/hora/i,/bög/i,/neger/i,/jävel/i,/skit/i,/fan(?:s)?$/i,/helvete/i,/död/i,/kill/i,/hate/i];for(const Re of b)if(Re.test(m))return s("profile.nicknameOffensive");return/^[\p{L}\p{N}\s\-_.*!?♥★☆⭐🎮🎯🎲💎🔥⚡🌟🏆]+$/u.test(m)?null:s("profile.nicknameInvalidChars")},Me=m=>{y(m),ae(re(m))};n.useEffect(()=>{i&&(y(i.display_name||""),R(i.reach_meters||5e3),_(i.phone_number||""),Pe(i.sms_notifications_enabled||!1),Q(i.self_accounting||!1),ee(i.voice_id||B[0].id))},[i]),n.useEffect(()=>{!a&&!u&&t("/auth")},[a,u,t]);const Ee=async()=>{const m=await g();if(m){const{error:b}=await l({latitude:m.latitude,longitude:m.longitude});b?T.error(s("profile.couldNotUpdateLocation")):T.success(s("profile.locationUpdated"))}},De=async()=>{const m=re(j);if(m){ae(m),T.error(m);return}te(!0);const{error:b}=await l({display_name:j.trim()||null,reach_meters:N,phone_number:I||null,self_accounting:Y,voice_id:W});te(!1),b?T.error(s("profile.couldNotSave")):T.success(s("profile.profileSaved"))},Te=async()=>{await h(),T.success(s("profile.loggedOut")),t("/")},Le=m=>m>=1e3?`${(m/1e3).toFixed(1)} ${s("common.km")}`:`${m} m`;return u?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx("div",{className:"animate-pulse text-muted-foreground",children:s("profile.loadingProfile")})}):e.jsxs("div",{className:"min-h-screen bg-background text-foreground pb-24",children:[e.jsxs("main",{className:"p-4 space-y-6 pt-[calc(env(safe-area-inset-top)+1.5rem)]",children:[e.jsxs(v.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{duration:.4},className:"relative overflow-hidden rounded-3xl bg-gradient-to-br from-primary/20 via-primary/10 to-accent/10 border border-primary/20 p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-40 h-40 bg-gradient-to-bl from-primary/30 to-transparent rounded-full blur-3xl"}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:s("profile.totalEarned")}),e.jsx("div",{className:"flex items-baseline gap-2",children:r?e.jsx("div",{className:"h-12 w-32 bg-muted/50 animate-pulse rounded-lg"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-5xl font-bold text-foreground tracking-tight",children:((c==null?void 0:c.total_earned)||0).toLocaleString("sv-SE")}),e.jsx("span",{className:"text-2xl font-medium text-muted-foreground",children:s("common.sek")})]})}),e.jsx("div",{className:"flex items-center gap-4 mt-4 text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-success animate-pulse"}),e.jsxs("span",{children:[s("profile.available"),": ",((c==null?void 0:c.balance)||0).toLocaleString("sv-SE")," ",s("common.sek")]})]})})]})]}),e.jsx(Bs,{}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3},children:e.jsxs(k,{className:"glass-card",children:[e.jsxs(P,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(Ze,{className:"w-5 h-5 text-primary"}),s("profile.accountInfo")]}),e.jsx(E,{children:s("profile.accountInfoDesc")})]}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(w,{htmlFor:"email",className:"flex items-center gap-2",children:[e.jsx(vs,{className:"w-4 h-4"}),s("profile.email")]}),e.jsx(ce,{id:"email",value:(a==null?void 0:a.email)||"",disabled:!0,className:"bg-muted/50"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"displayName",className:"flex items-center gap-2",children:s("profile.nickname")}),e.jsx(ce,{id:"displayName",value:j,onChange:m=>Me(m.target.value),placeholder:s("profile.nicknamePlaceholder"),maxLength:20,className:K?"border-destructive":""}),K?e.jsx("p",{className:"text-xs text-destructive",children:K}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("profile.nicknameHint")})]})]})]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.12},children:e.jsxs(k,{className:`glass-card ${o?"border-green-500/30":"border-amber-500/30"}`,children:[e.jsxs(P,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(le,{className:"w-5 h-5 text-primary"}),s("profile.identity","Identitetsverifiering"),o?e.jsxs(U,{variant:"default",className:"text-xs gap-1 bg-green-600 ml-auto",children:[e.jsx(X,{className:"w-3 h-3"}),s("profile.verified","Verifierad")]}):e.jsxs(U,{variant:"outline",className:"text-xs gap-1 text-amber-500 border-amber-500 ml-auto",children:[e.jsx(bs,{className:"w-3 h-3"}),s("profile.notVerified","Ej verifierad")]})]}),e.jsx(E,{children:o?s("profile.identityVerifiedDesc","Din identitet är verifierad. Du kan ta uppdrag."):s("profile.identityNotVerifiedDesc","Verifiera din identitet med pass eller nationellt ID för att kunna ta uppdrag.")})]}),!o&&e.jsx(S,{children:e.jsxs(C,{onClick:()=>t("/verify-identity"),className:"w-full",children:[e.jsx(le,{className:"w-4 h-4 mr-2"}),s("profile.verifyNow","Verifiera nu"),e.jsx(oe,{className:"w-4 h-4 ml-2"})]})})]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.13},children:e.jsxs(k,{className:`glass-card ${d?"border-green-500/30":"border-border"}`,children:[e.jsxs(P,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(J,{className:"w-5 h-5 text-primary"}),s("profile.orderer"),d&&e.jsxs(U,{variant:"default",className:"text-xs gap-1 bg-green-600 ml-auto",children:[e.jsx(X,{className:"w-3 h-3"}),s("profile.ordererActive")]}),x&&e.jsxs(U,{variant:"outline",className:"text-xs gap-1 text-amber-500 border-amber-500 ml-auto",children:[e.jsx(Ne,{className:"w-3 h-3"}),s("profile.ordererPending")]})]}),e.jsx(E,{children:d?s("profile.ordererAsOrg",{org:f==null?void 0:f.organization_name}):s(x?"profile.ordererApplicationPending":"profile.ordererDesc")})]}),e.jsxs(S,{className:"space-y-3",children:[d&&e.jsxs(e.Fragment,{children:[e.jsxs(C,{onClick:()=>t("/orderer/dashboard"),className:"w-full",children:[e.jsx(J,{className:"w-4 h-4 mr-2"}),s("profile.openOrdererDashboard")]}),e.jsxs(C,{variant:"outline",onClick:()=>t("/orderer/create-mission"),className:"w-full",children:[e.jsx(je,{className:"w-4 h-4 mr-2"}),s("profile.createNewMission")]})]}),f?e.jsxs(C,{variant:"outline",onClick:()=>t("/orderer/register"),className:"w-full",children:[e.jsx(J,{className:"w-4 h-4 mr-2"}),s("profile.viewOrdererProfile")]}):e.jsxs(C,{onClick:()=>t("/orderer/register"),className:"w-full",children:[e.jsx(J,{className:"w-4 h-4 mr-2"}),s("profile.becomeOrderer"),e.jsx(oe,{className:"w-4 h-4 ml-2"})]})]})]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.15},children:e.jsxs(k,{className:"glass-card",children:[e.jsxs(P,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-5 h-5 text-primary"}),s("profile.paymentMethod")]}),e.jsx(E,{children:"Koppla ditt Stripe-konto för att ta emot utbetalningar"})]}),e.jsx(S,{className:"space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"stripeConnect",className:"flex items-center gap-2",children:"Stripe Connect"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Utbetalningar hanteras via Stripe Connect. Koppla ditt konto i Stripe-dashboarden."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Utbetalningar sker automatiskt via Stripe Connect."})]})})]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.2},children:e.jsxs(k,{className:"glass-card",children:[e.jsxs(P,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(Ps,{className:"w-5 h-5 text-primary"}),s("profile.reachTitle")]}),e.jsx(E,{children:s("profile.reachDesc")})]}),e.jsxs(S,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("profile.reach")}),e.jsx("span",{className:"text-lg font-mono font-semibold text-primary",children:Le(N)})]}),e.jsx(Ye,{value:[N],onValueChange:m=>R(m[0]),min:500,max:5e4,step:500,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"500m"}),e.jsxs("span",{children:["50",s("common.km")]})]})]}),e.jsx(Vs,{latitude:(i==null?void 0:i.latitude)??null,longitude:(i==null?void 0:i.longitude)??null,reachMeters:N})]})]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.2},children:e.jsxs(k,{className:"glass-card",children:[e.jsxs(P,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(Qe,{className:"w-5 h-5 text-primary"}),s("profile.locationTitle")]}),e.jsx(E,{children:s("profile.locationDesc")})]}),e.jsxs(S,{className:"space-y-4",children:[i!=null&&i.latitude&&(i!=null&&i.longitude)?e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg font-mono text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("span",{className:"text-muted-foreground",children:[s("profile.lat"),":"]}),e.jsx("span",{children:i.latitude.toFixed(6)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("span",{className:"text-muted-foreground",children:[s("profile.long"),":"]}),e.jsx("span",{children:i.longitude.toFixed(6)})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:s("profile.noLocationSaved")}),e.jsxs(C,{onClick:Ee,variant:"outline",className:"w-full",children:[e.jsx(We,{className:"w-4 h-4 mr-2"}),s("profile.updateToCurrentLocation")]}),p&&e.jsx("p",{className:"text-sm text-destructive",children:p})]})]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.3},children:e.jsxs(k,{className:"glass-card",children:[e.jsxs(P,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(es,{className:"w-5 h-5 text-primary"}),s("profile.notificationsTitle")]}),e.jsx(E,{children:s("profile.notificationsDesc")})]}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(w,{children:s("profile.newMissions")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("profile.newMissionsDesc")})]}),e.jsx(A,{checked:F.newMissions,onCheckedChange:m=>V(b=>({...b,newMissions:m}))})]}),e.jsx(O,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(w,{children:s("profile.missionUpdates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("profile.missionUpdatesDesc")})]}),e.jsx(A,{checked:F.claimUpdates,onCheckedChange:m=>V(b=>({...b,claimUpdates:m}))})]}),e.jsx(O,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(w,{children:s("profile.rewards")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("profile.rewardsDesc")})]}),e.jsx(A,{checked:F.rewards,onCheckedChange:m=>V(b=>({...b,rewards:m}))})]}),e.jsx(O,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs(w,{className:"flex items-center gap-2",children:[s("profile.marketing"),e.jsx(Ss,{className:"w-3 h-3 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("profile.marketingDesc")})]}),e.jsx(A,{checked:F.marketing,onCheckedChange:m=>V(b=>({...b,marketing:m}))})]})]})]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.32},children:e.jsxs(k,{className:"glass-card",children:[e.jsxs(P,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-5 h-5 text-primary"}),s("profile.countryTax")]}),e.jsx(E,{children:s("profile.countryTaxDesc")})]}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg",children:"🇸🇪"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:s("profile.sweden")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("profile.basedOnGps")})]})]}),e.jsx(ss,{className:"w-5 h-5 text-primary"})]}),e.jsx(O,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs(w,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-4 h-4"}),s("profile.selfAccountingLabel")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("profile.selfAccountingDescription")})]}),e.jsx(A,{checked:Y,onCheckedChange:Q})]}),e.jsx("div",{className:"p-3 bg-green-500/10 border border-green-500/30 rounded-lg",children:e.jsxs("p",{className:"text-xs text-green-400",children:["✓ ",e.jsx("strong",{children:s("profile.weHandleTax")})," – ",s("profile.taxAutoDeducted")]})})]})]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.35},children:e.jsxs(k,{className:"glass-card",children:[e.jsxs(P,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(ws,{className:"w-5 h-5 text-primary"}),s("profile.appearanceTitle")]}),e.jsx(E,{children:s("profile.appearanceDesc")})]}),e.jsxs(S,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs(w,{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-4 h-4"}),s("profile.language")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("profile.languageDesc")}),e.jsx(zs,{})]}),e.jsx(O,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(w,{children:s("profile.theme")}),e.jsx(As,{})]}),e.jsx(O,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(w,{className:"flex items-center gap-2",children:[e.jsx(ye,{className:"w-4 h-4"}),s("profile.voiceGuide","Instruktionsröst")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("profile.voiceGuideDesc","Välj vilken röst som ska användas för navigering och fotoinstruktioner")}),e.jsx(Fs,{value:W,onChange:ee})]})]})]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.4},children:e.jsxs(C,{onClick:De,className:"w-full",size:"lg",disabled:se,children:[e.jsx(ks,{className:"w-4 h-4 mr-2"}),s(se?"profile.saving":"profile.saveChanges")]})}),e.jsx(v.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.5},children:e.jsxs(C,{onClick:Te,variant:"outline",className:"w-full text-destructive hover:text-destructive",children:[e.jsx(Cs,{className:"w-4 h-4 mr-2"}),s("profile.logOut")]})})]}),e.jsx(ts,{})]})};export{ut as default};