1import{a2 as Ke,r as c,g as Nt,j as e,e as q,C as me,aM as Kt,d as G,w as Me,an as Zs,H as ea,D as Gt,x as Jt,y as Xt,z as Qt,aq as He,I as je,ar as ta,as as sa,at as aa,au as ra,aN as na,av as oa,h as L,s as I,b as ke,S as We,o as ft,i as Ye,aO as Mt,aP as ia,Y as Fe,aQ as It,k as Ot,l as Zt,aR as la,aS as ca,aT as da,a0 as ua,X as ht,aU as St,aV as S,aW as es,aX as ts,aY as _t,aZ as Ct,a_ as kt,a$ as qt,b0 as ma,b1 as Ae,b2 as Ge,b3 as Ie,b4 as fa,b5 as ha,b6 as ss,b7 as xa,b8 as pa,b9 as ga,E as as,ba as rs,bb as ba,c as wa,q as ya,bc as va,aI as ja,bd as ns,aC as xt,K as Na,ab as Sa,be as _a,aK as rt,ak as os,bf as Ca,m as Ue,bg as ka,bh as Ra,az as Rt,aB as Ta,bi as Pa,aE as Da,bj as Ea,bk as Lt,a8 as pt,P as gt,a9 as Aa,bl as Ma,bm as Ia,bn as Oa,V as qa,a1 as $t,bo as La,bp as $a,R as za,al as Ba,L as Ha,Z as Fa,bq as zt,aw as Ua,f as Va}from"./index-Cu7LKwbt.js";import{P as Wa,a as Ya,b as Ka,u as Ga,S as Ja}from"./popover-B1J7JRGC.js";import{u as Xa}from"./useAppBadge-BKjIx8hh.js";import{B as ot}from"./bell-BipC5Ggg.js";import{A as Qa}from"./award-gpWEs34o.js";import{f as Za}from"./formatDistanceToNow-DcvlajSs.js";import{A as er}from"./AchievementMedal-CT4y5oFY.js";import{L as is}from"./log-out-BsrLC1WC.js";import{P as nt}from"./pencil-CVmaqCaO.js";import{P as tr}from"./plus-CKCFis_R.js";import{S as Ce}from"./switch-D5Prkwof.js";import{T as sr}from"./type-ReCRRP_p.js";import{M as ar}from"./monitor-Z8jOUyDl.js";import{K as rr}from"./key-round-SPKxkmsU.js";import{F as nr}from"./file-text-DKoAsm5w.js";import{A as or}from"./arrow-left-DUI0NmPa.js";import{S as ir}from"./settings-C5A3712a.js";import"./constructNow-Bkwo4L2g.js";import"./en-US-CIDmvCya.js";import"./endOfMonth-q24iNOYN.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const lr=Ke("Accessibility",[["circle",{cx:"16",cy:"4",r:"1",key:"1grugj"}],["path",{d:"m18 19 1-7-6 1",key:"r0i19z"}],["path",{d:"m5 8 3-3 5.5 3-2.36 3.5",key:"9ptxx2"}],["path",{d:"M4.24 14.5a5 5 0 0 0 6.88 6",key:"10kmtu"}],["path",{d:"M13.76 17.5a5 5 0 0 0-6.88-6",key:"2qq6rc"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const cr=Ke("Camera",[["path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z",key:"1tc9qg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const dr=Ke("DoorOpen",[["path",{d:"M13 4h3a2 2 0 0 1 2 2v14",key:"hrm0s9"}],["path",{d:"M2 20h3",key:"1gaodv"}],["path",{d:"M13 20h9",key:"s90cdi"}],["path",{d:"M10 12v.01",key:"vx6srw"}],["path",{d:"M13 4.562v16.157a1 1 0 0 1-1.242.97L5 20V5.562a2 2 0 0 1 1.515-1.94l4-1A2 2 0 0 1 13 4.561Z",key:"199qr4"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const ur=Ke("Inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]);/** 22 * @license lucide-react v0.462.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const Bt=Ke("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]),mr=t=>{switch(t){case"achievement":return e.jsx(Qa,{className:"h-4 w-4 text-yellow-500"});case"milestone":return e.jsx(ea,{className:"h-4 w-4 text-green-500"});case"streak":return e.jsx(Zs,{className:"h-4 w-4 text-orange-500"});case"community":return e.jsx(Me,{className:"h-4 w-4 text-blue-500"});default:return e.jsx(ot,{className:"h-4 w-4"})}},fr=()=>{const[t,s]=c.useState(!1),a=Nt(),{notifications:n,unreadCount:r,markAsRead:o,markAllAsRead:l,clearAll:u}=Xa();return e.jsxs(Wa,{open:t,onOpenChange:s,children:[e.jsx(Ya,{asChild:!0,children:e.jsxs(q,{variant:"ghost",size:"icon",className:"relative rounded-full h-9 w-9","aria-label":"Notifications",children:[e.jsx(ot,{className:"h-4 w-4"}),r>0&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 h-4 w-4 roun
26ded-full bg-accent text-accent-foreground text-[10px] font-bold flex items-center justify-center",children:r>9?"9+":r})]})}),e.jsxs(Ka,{className:"w-80 p-0 rounded-2xl border border-border/50 shadow-xl",align:"end",children:[e.jsxs("div",{className:"p-3 flex items-center justify-between border-b border-border/50",children:[e.jsx("h3",{className:"font-display font-bold text-sm",children:"Notifications"}),e.jsxs("div",{className:"flex gap-1",children:[r>0&&e.jsxs(q,{variant:"ghost",size:"sm",className:"h-7 text-xs rounded-full",onClick:l,children:[e.jsx(me,{className:"h-3 w-3 mr-1"})," Read All"]}),n.length>0&&e.jsx(q,{variant:"ghost",size:"sm",className:"h-7 text-xs text-destructive hover:text-destructive rounded-full",onClick:u,children:e.jsx(Kt,{className:"h-3 w-3"})}),n.length>0&&e.jsxs(q,{variant:"ghost",size:"sm",className:"h-7 text-xs rounded-full gap-1",onClick:()=>{s(!1),a("/notifications")},children:[e.jsx(ur,{className:"h-3 w-3"})," View All"]})]})]}),e.jsx("div",{className:"max-h-80 overflow-y-auto",children:n.length===0?e.jsxs("div",{className:"p-6 text-center text-muted-foreground",children:[e.jsx(ot,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No notifications yet"})]}):n.map(d=>e.jsxs("button",{onClick:()=>o(d.id),className:G("w-full text-left p-3 border-b border-border/30 hover:bg-secondary/50 transition-colors flex gap-3",!d.read&&"bg-primary/5"),children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:mr(d.type)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h4",{className:G("text-sm truncate",!d.read&&"font-semibold"),children:d.title}),!d.read&&e.jsx("span",{className:"h-2 w-2 rounded-full bg-primary flex-shrink-0 mt-1.5"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-2",children:d.message}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:Za(new Date(d.createdAt),{addSuffix:!0})})]})]},d.id))})]})]})},hr=({open:t,onOpenChange:s,userId:a,currentUsername:n,currentCountry:r,currentPhoneNumber:o,onSaved:l})=>{const[u,d]=c.useState((n==null?void 0:n.split("@")[0])||""),[g,y]=c.useState(r||""),[m,f]=c.useState(o||""),[b,R]=c.useState(!1),v=async()=>{const j=u.trim();if(!j){L.error("Username cannot be empty");return}if(j.length>30){L.error("Username must be 30 characters or less");return}R(!0);try{const{error:w}=await I.from("profiles").update({username:j,country:g||null,phone_number:m.trim()||null}).eq("user_id",a);if(w)throw w;l(j,g||null,m.trim()||null),L.success("Profile updated!"),s(!1)}catch(w){L.error(w.message||"Failed to update profile")}finally{R(!1)}};return e.jsx(Gt,{open:t,onOpenChange:s,children:e.jsxs(Jt,{className:"sm:max-w-sm",children:[e.jsx(Xt,{children:e.jsx(Qt,{className:"font-display",children:"Edit Profile"})}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(He,{htmlFor:"username",children:"Username"}),e.jsx(je,{id:"username",value:u,onChange:j=>d(j.target.value),maxLength:30,placeholder:"Your display name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(He,{htmlFor:"country",children:"Country"}),e.jsxs(ta,{value:g,onValueChange:y,children:[e.jsx(sa,{id:"country",children:e.jsx(aa,{placeholder:"Select country"})}),e.jsx(ra,{children:na.map(j=>e.jsxs(oa,{value:j.code,children:[j.flag," ",j.name]},j.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(He,{htmlFor:"phone",children:"Phone Number"}),e.jsx(je,{id:"phone",type:"tel",value:m,onChange:j=>f(j.target.value),placeholder:"+1 234 567 8900",maxLength:20}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"So friends can find you from their contacts"})]}),e.jsx(q,{onClick:v,disabled:b,className:"w-full",children:b?"Saving...":"Save Changes"})]})]})})},xr=()=>{const{user:t}=ke(),[s,a]=c.useState(""),[n,r]=c.useState([]),[o,l]=c.useState([]),[u,d]=c.useState(null),[g,y]=c.useState(!0);c.useEffect(()=>{m(),t&&f()},[t]);const m=async()=>{y(!0);const{data:x}=await I.from("youth_groups").select("id, name, church_name").order("name");x&&r(x),y(!1)},f=async()=>
26{if(!t)return;const{data:x}=await I.from("profiles").select("youth_group_id").eq("user_id",t.id).single();x&&d(x.youth_group_id);const{data:i}=await I.from("youth_group_join_requests").select("youth_group_id, status").eq("user_id",t.id);i&&l(i)},b=async x=>{if(!t){L.error("Please sign in first");return}const{error:i}=await I.from("youth_group_join_requests").insert({youth_group_id:x,user_id:t.id});if(i){i.message.includes("duplicate")?L.error("You've already requested to join this group"):L.error(i.message);return}L.success("Request sent! Your youth leader will approve you."),f()},R=x=>{if(u===x)return"member";const i=o.find(h=>h.youth_group_id===x);return(i==null?void 0:i.status)||null},v=s.trim(),j=v.length>=2,w=j?n.filter(x=>x.name.toLowerCase().includes(v.toLowerCase())||x.church_name&&x.church_name.toLowerCase().includes(v.toLowerCase())):[];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-lg font-display font-bold",children:"Find Your Youth Group"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Type your church or ministry name to find it, then request to join."})]}),e.jsxs("div",{className:"relative",children:[e.jsx(We,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(je,{value:s,onChange:x=>a(x.target.value),placeholder:"Type your church or ministry name...",className:"pl-10 rounded-xl"})]}),g?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"gradient-spinner w-8 h-8"})}):j?w.length===0?e.jsxs("div",{className:"text-center py-8 space-y-2",children:[e.jsx(ft,{className:"h-10 w-10 text-muted-foreground mx-auto"}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:['No groups found matching "',v,'"']})]}):e.jsx("div",{className:"space-y-2",children:w.map(x=>{const i=R(x.id);return e.jsxs("div",{className:"flex items-center gap-3 p-4 rounded-xl bg-card border border-border/50",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-purple-500/20 flex items-center justify-center shrink-0",children:e.jsx(ft,{className:"h-5 w-5 text-purple-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm truncate",children:x.name}),x.church_name&&e.jsx("p",{className:"text-muted-foreground text-xs truncate",children:x.church_name})]}),i==="member"?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-500 font-medium",children:[e.jsx(me,{className:"h-3.5 w-3.5"})," Joined"]}):i==="pending"?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-500 font-medium",children:[e.jsx(Ye,{className:"h-3.5 w-3.5"})," Pending"]}):i==="approved"?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-500 font-medium",children:[e.jsx(me,{className:"h-3.5 w-3.5"})," Approved"]}):i==="rejected"?e.jsx("span",{className:"text-xs text-muted-foreground",children:"Declined"}):e.jsxs(q,{size:"sm",onClick:()=>b(x.id),className:"rounded-full text-xs bg-purple-600 hover:bg-purple-700",children:[e.jsx(Me,{className:"h-3.5 w-3.5 mr-1"})," Join"]})]},x.id)})}):e.jsxs("div",{className:"text-center py-8 space-y-2",children:[e.jsx(We,{className:"h-10 w-10 text-muted-foreground mx-auto"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Start typing to find your youth group"})]})]})},pr=()=>{const{user:t}=ke(),[s,a]=c.useState(""),[n,r]=c.useState([]),[o,l]=c.useState([]),[u,d]=c.useState(null),[g,y]=c.useState(!0);c.useEffect(()=>{m(),t&&f()},[t]);const m=async()=>{y(!0);const{data:x}=await I.from("schools").select("id, name, school_name").order("school_name");x&&r(x),y(!1)},f=async()=>{if(!t)return;const{data:x}=await I.from("profiles").select("school_id").eq("user_id",t.id).single();x&&d(x.school_id);const{data:i}=await I.from("school_join_requests").select("school_id, status").eq("user_id",t.id);i&&l(i)},b=async x=>{if(!t){L.error("Please sign in first");return}const{error:i}=await I.from("school_join_requests").insert({school_id:x,user_id:t.id});if(i){i.message.includes("duplicate")?L.error("You've already requested to join this school"):L.error(i.message);return}L.success("Request sent! Your school admin will approve you."),f()},R=x=>
26{if(u===x)return"member";const i=o.find(h=>h.school_id===x);return(i==null?void 0:i.status)||null},v=s.trim(),j=v.length>=2,w=j?n.filter(x=>x.school_name.toLowerCase().includes(v.toLowerCase())||x.name.toLowerCase().includes(v.toLowerCase())):[];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-lg font-display font-bold",children:"Find Your School"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Type your school name to find it, then request to join."})]}),e.jsxs("div",{className:"relative",children:[e.jsx(We,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(je,{value:s,onChange:x=>a(x.target.value),placeholder:"Type your school name...",className:"pl-10 rounded-xl"})]}),g?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"gradient-spinner w-8 h-8"})}):j?w.length===0?e.jsxs("div",{className:"text-center py-8 space-y-2",children:[e.jsx(Mt,{className:"h-10 w-10 text-muted-foreground mx-auto"}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:['No schools found matching "',v,'"']})]}):e.jsx("div",{className:"space-y-2",children:w.map(x=>{const i=R(x.id);return e.jsxs("div",{className:"flex items-center gap-3 p-4 rounded-xl bg-card border border-border/50",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-blue-500/20 flex items-center justify-center shrink-0",children:e.jsx(Mt,{className:"h-5 w-5 text-blue-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm truncate",children:x.school_name}),x.name!==x.school_name&&e.jsx("p",{className:"text-muted-foreground text-xs truncate",children:x.name})]}),i==="member"?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-500 font-medium",children:[e.jsx(me,{className:"h-3.5 w-3.5"})," Joined"]}):i==="pending"?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-500 font-medium",children:[e.jsx(Ye,{className:"h-3.5 w-3.5"})," Pending"]}):i==="approved"?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-500 font-medium",children:[e.jsx(me,{className:"h-3.5 w-3.5"})," Approved"]}):i==="waitlisted"?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-500 font-medium",children:[e.jsx(Ye,{className:"h-3.5 w-3.5"})," Waitlisted"]}):i==="rejected"?e.jsx("span",{className:"text-xs text-muted-foreground",children:"Declined"}):e.jsxs(q,{size:"sm",onClick:()=>b(x.id),className:"rounded-full text-xs bg-blue-600 hover:bg-blue-700",children:[e.jsx(Me,{className:"h-3.5 w-3.5 mr-1"})," Join"]})]},x.id)})}):e.jsxs("div",{className:"text-center py-8 space-y-2",children:[e.jsx(We,{className:"h-10 w-10 text-muted-foreground mx-auto"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Start typing to find your school"})]})]})},gr=()=>{const{user:t}=ke(),{myTribe:s,myRole:a,members:n,joinRequests:r,myRejectedRequests:o,loading:l,createTribe:u,renameTribe:d,requestJoin:g,approveRequest:y,rejectRequest:m,dismissRejectedRequest:f,leaveTribe:b,removeMember:R}=ia(),[v,j]=c.useState(""),[w,x]=c.useState(!1),[i,h]=c.useState(""),[C,z]=c.useState([]),[k,E]=c.useState(!1),[O,B]=c.useState([]),[p,D]=c.useState(!1),[$,W]=c.useState(!1),[U,Q]=c.useState(""),[V,Z]=c.useState(!1),ie=async()=>{if(!v.trim()||v.trim().length<2){L.error("Tribe name must be at least 2 characters");return}x(!0),await u(v.trim()),j(""),D(!1),x(!1)},fe=async()=>{if(!U.trim()||U.trim().length<2){L.error("Tribe name must be at least 2 characters");return}Z(!0),await d(U.trim()),Q(""),W(!1),Z(!1)},Re=async()=>{if(!i.trim())return;E(!0);const{data:N}=await I.from("tribes").select("id, name, status").ilike("name",`%${i}%`).eq("status","approved").limit(10);if(N){const J=N.map(oe=>oe.id),{data:ae}=await I.from("tribe_members").select("tribe_id").in("tribe_id",J),le={};ae==null||ae.forEach(oe=>{le[oe.tribe_id]=(le[oe.tribe_id]||0)+1}),z(N.map(oe=>({...oe,member_count:le[oe.id]||0})))}if(t){const{data:J}=await I.from("tribe_join_requests").select("tribe_id, status").eq("user_id",t.id);B((J==null?void 0:J.filter(ae=>ae.status==="pending").map(ae=>ae.tribe_id))||[])}E(!1)},he=async N=>{await g(N),B(J=>[...J,N])};return l?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"gradient-spinner w-8 h-8"})}
26):s?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-2xl bg-card border border-border/50 p-5 shadow-sm",style:{borderTopColor:"hsl(270, 60%, 55%)",borderTopWidth:"2px"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center",style:{background:"hsl(270, 60%, 55%, 0.15)"},children:e.jsx(Fe,{className:"h-6 w-6",style:{color:"hsl(270, 60%, 55%)"}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-display font-bold text-base",children:s.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.status==="pending"?e.jsx("span",{className:"text-yellow-500 font-medium",children:"â³ Awaiting admin approval"}):s.status==="rejected"?e.jsx("span",{className:"text-destructive font-medium",children:"â Name rejected â please rename"}):e.jsxs(e.Fragment,{children:[n.length," member",n.length!==1?"s":""," â¢"," ",a==="leader"?"ð Leader":"Member"]})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(q,{variant:"ghost",size:"sm",onClick:b,className:"text-destructive hover:text-destructive hover:bg-destructive/10 rounded-full text-xs",children:[e.jsx(is,{className:"h-3.5 w-3.5 mr-1"}),a==="leader"?"Disband":"Leave"]})})]}),a==="leader"&&s.status==="rejected"&&e.jsxs("div",{className:"mb-4 rounded-xl bg-destructive/5 border border-destructive/20 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(It,{className:"h-4 w-4 text-destructive"}),e.jsx("span",{className:"text-xs font-semibold text-destructive",children:"Name rejected by admin"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose a new name and resubmit for approval."}),$?e.jsxs("div",{className:"space-y-2",children:[e.jsx(je,{value:U,onChange:N=>Q(N.target.value),placeholder:"New tribe name...",maxLength:30,className:"rounded-xl text-sm"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{onClick:fe,disabled:V||!U.trim(),size:"sm",className:"flex-1 rounded-full text-white",style:{background:"hsl(270, 60%, 55%)"},children:V?"Submitting...":"Resubmit"}),e.jsx(q,{variant:"outline",size:"sm",onClick:()=>W(!1),className:"rounded-full",children:"Cancel"})]})]}):e.jsxs(q,{size:"sm",onClick:()=>{Q(s.name),W(!0)},className:"rounded-full text-xs gap-1.5 text-white",style:{background:"hsl(270, 60%, 55%)"},children:[e.jsx(nt,{className:"h-3 w-3"})," Rename Tribe"]})]}),a==="leader"&&s.status==="approved"&&e.jsxs("div",{className:"mb-4 rounded-xl bg-primary/5 border border-primary/20 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ot,{className:"h-4 w-4",style:{color:"hsl(270, 60%, 55%)"}}),e.jsx("span",{className:"text-xs font-semibold",children:"Invite friends to your tribe"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Share this link â friends can request to join in one tap!"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{readOnly:!0,value:`${window.location.origin}/tribe/join/${s.id}`,className:"flex-1 text-xs rounded-full bg-background border border-border px-3 py-1.5 outline-none",onFocus:N=>N.target.select()}),e.jsx(q,{size:"icon",variant:"outline",className:"rounded-full shrink-0 h-8 w-8",onClick:async()=>{const N=`${window.location.origin}/tribe/join/${s.id}`;if(navigator.share)try{await navigator.share({title:`Join ${s.name} on Biblez!`,text:`Join my tribe "${s.name}" on Biblez!`,url:N})}catch{}else await navigator.clipboard.writeText(N),L.success("Tribe invite link copied!")},children:navigator.share?e.jsx(Ot,{className:"h-3.5 w-3.5"}):e.jsx(Zt,{className:"h-3.5 w-3.5"})})]})]}),e.jsx("div",{className:"space-y-2",children:n.map(N=>{var le;const J=((le=N.username)==null?void 0:le.split("@")[0])||"Member",ae=J.slice(0,2).toUpperCase();return e.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-xl",children:[e.jsxs(la,{className:"h-8 w-8",children:[e.jsx(ca,{src:N.avatar_url||void 0}),e.jsx(da,{className:"text-[10px] font-bold bg-purple-500/15 text-purple-600",children:ae})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-sm font-semibold truncate",children:J})}),N.role==="leader"&&e.jsx(ua,{className:"h-4 w-4 text-yellow-500"}),a==="leader"&&N.role!=="leader"&&N.user_id!==(t==null?void 0:t.id)&&e.jsx(q,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>R(N.id),children:e.jsx(ht,{className:"h-3.5 w-3.5"})})]},N.id)})})]}),a==="leader"&&r.length>0&&e.jsxs("div",{className:"rounded-2xl bg-card border border-border/50 p-4 shadow-sm",children:[e.jsxs("h4",{className:"font-display font-bold text-sm mb-3",children:[e.jsx(Ye,{className:"h-4 w-4 inline mr-1.5 text-yellow-500"}),"Pending Requests (",r.length,")"]}),e.jsx("div",{className:"space-y-2",children:r.map(N=>{var J;return e.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-xl bg-secondary/50",children:[e.jsx("p",{className:"flex-1 text-sm font-semibold truncate",children:((J=N.username)==null?void 0:J.split("@")[0])||"User"}),e.jsxs(q,{size:"sm",className:"h-7 rounded-full text-xs bg-green-600 hover:bg-green-700 text-white",onClick:()=>
26y(N.id),children:[e.jsx(me,{className:"h-3 w-3 mr-1"})," Approve"]}),e.jsx(q,{size:"sm",variant:"outline",className:"h-7 rounded-full text-xs",onClick:()=>m(N.id),children:e.jsx(ht,{className:"h-3 w-3"})})]},N.id)})})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-lg font-display font-bold flex items-center gap-2",children:[e.jsx(Fe,{className:"h-5 w-5",style:{color:"hsl(270, 60%, 55%)"}}),"Tribes"]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Create your own tribe or search and request to join one. You must be friends with the tribe leader to join."})]}),o.length>0&&e.jsx("div",{className:"space-y-2",children:o.map(N=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-destructive/5 border border-destructive/20",children:[e.jsx(It,{className:"h-4 w-4 text-destructive shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold",children:"Join request declined"}),e.jsxs("p",{className:"text-xs text-muted-foreground truncate",children:[N.username||"A tribe"," declined your request"]})]}),e.jsx(q,{size:"sm",variant:"ghost",className:"h-7 rounded-full text-xs",onClick:()=>f(N.id),children:"Dismiss"})]},N.id))}),p?e.jsxs("div",{className:"rounded-2xl bg-card border border-border/50 p-4 shadow-sm space-y-3",children:[e.jsx("p",{className:"text-sm font-semibold",children:"Name your tribe"}),e.jsx(je,{value:v,onChange:N=>j(N.target.value),placeholder:"e.g. Tribe of Judah",maxLength:30,className:"rounded-xl"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{onClick:ie,disabled:w||!v.trim(),className:"flex-1 rounded-full text-white",style:{background:"hsl(270, 60%, 55%)"},children:w?"Creating...":"Create Tribe"}),e.jsx(q,{variant:"outline",onClick:()=>D(!1),className:"rounded-full",children:"Cancel"})]})]}):e.jsxs(q,{onClick:()=>D(!0),className:"w-full rounded-xl gap-2 text-white",style:{background:"hsl(270, 60%, 55%)"},children:[e.jsx(tr,{className:"h-4 w-4"})," Create a Tribe"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(We,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(je,{value:i,onChange:N=>h(N.target.value),onKeyDown:N=>N.key==="Enter"&&Re(),placeholder:"Search tribes...",className:"pl-10 rounded-xl"})]}),i&&e.jsx(q,{variant:"outline",size:"sm",onClick:Re,disabled:k,className:"rounded-full text-xs",children:k?"Searching...":"Search"}),C.length>0&&e.jsx("div",{className:"space-y-2",children:C.map(N=>{const J=O.includes(N.id);return e.jsxs("div",{className:"flex items-center gap-3 p-4 rounded-xl bg-card border border-border/50",children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center shrink-0",style:{background:"hsl(270, 60%, 55%, 0.15)"},children:e.jsx(Fe,{className:"h-5 w-5",style:{color:"hsl(270, 60%, 55%)"}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm truncate",children:N.name}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[N.member_count," member",N.member_count!==1?"s":""]})]}),J?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-500 font-medium",children:[e.jsx(Ye,{className:"h-3.5 w-3.5"})," Pending"]}):e.jsxs(q,{size:"sm",onClick:()=>he(N.id),className:"rounded-full text-xs text-white",style:{background:"hsl(270, 60%, 55%)"},children:[e.jsx(Me,{className:"h-3.5 w-3.5 mr-1"})," Join"]})]},N.id)})})]})]})};function br(t){if(typeof document>"u")return;let s=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css",s.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t))}const ls=S.createContext({drawerRef:{current:null},overlayRef:{current:null},onPress:()=>{},onRelease:()=>{},onDrag:()=>{},onNestedDrag:()=>{},onNestedOpenChange:()=>{},onNestedRelease:()=>{},openProp:void 0,dismissible:!1,isOpen:!1,isDragging:!1,keyboardIsOpen:{current:!1},snapPointsOffset:null,snapPoints:null,handleOnly:!1,modal:!1,shouldFade:!1,activeSnapPoint:null,onOpenChange:()=>{},setActiveSnapPoint:()=>{},closeDrawer:()=>{}
26,direction:"bottom",shouldScaleBackground:!1,setBackgroundColorOnScale:!0,noBodyStyles:!1,container:null,autoFocus:!1}),Je=()=>{const t=S.useContext(ls);if(!t)throw new Error("useDrawerContext must be used within a Drawer.Root");return t};br(`[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,100%,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,-100%,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(-100%,0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(100%,0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not( 27[data-state=closed] 28){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}
28to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,100%,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,100%,0)}}@keyframes slideFromTop{from{transform:translate3d(0,-100%,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,-100%,0)}}@keyframes slideFromLeft{from{transform:translate3d(-100%,0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(-100%,0,0)}}@keyframes slideFromRight{from{transform:translate3d(100%,0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(100%,0,0)}}`);const wr=24,yr=typeof window<"u"?c.useLayoutEffect:c.useEffect;function Ht(...t){return(...s)=>{for(let a of t)typeof a=="function"&&a(...s)}}function vr(){return Tt(/^Mac/)}function jr(){return Tt(/^iPhone/)}function Ft(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Nr(){return Tt(/^iPad/)||vr()&&navigator.maxTouchPoints>1}function cs(){return jr()||Nr()}function Tt(t){return typeof window<"u"&&window.navigator!=null?t.test(window.navigator.platform):void 0}const ct=typeof document<"u"&&window.visualViewport;function Ut(t){let s=window.getComputedStyle(t);return/(auto|scroll)/.test(s.overflow+s.overflowX+s.overflowY)}function ds(t){for(Ut(t)&&(t=t.parentElement);t&&!Ut(t);)t=t.parentElement;return t||document.scrollingElement||document.documentElement}const Sr=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);let tt=0,dt;function _r(t={}){let{isDisabled:s}=t;yr(()=>{if(!s)return tt++,tt===1&&cs()&&(dt=Cr()),()=>{tt--,tt===0&&(dt==null||dt())}},[s])}function Cr(){let t,s=0,a=m=>{t=ds(m.target),!(t===document.documentElement&&t===document.body)&&(s=m.changedTouches[0].pageY)},n=m=>{if(!t||t===document.documentElement||t===document.body){m.preventDefault();return}let f=m.changedTouches[0].pageY,b=t.scrollTop,R=t.scrollHeight-t.clientHeight;R!==0&&((b<=0&&f>s||b>=R&&f<s)&&m.preventDefault(),s=f)},r=m=>{let f=m.target;bt(f)&&f!==document.activeElement&&(m.preventDefault(),f.style.transform="translateY(-2000px)",f.focus(),requestAnimationFrame(()=>{f.style.transform=""}))},o=m=>{let f=m.target;bt(f)&&(f.style.transform="translateY(-2000px)",requestAnimationFrame(()=>{f.style.transform="",ct&&(ct.height<window.innerHeight?requestAnimationFrame(()=>{Vt(f)}):ct.addEventListener("resize",()=>Vt(f),{once:!0}))}))},l=()=>{window.scrollTo(0,0)},u=window.pageXOffset,d=window.pageYOffset,g=Ht(kr(document.documentElement,"paddingRight",`${window.innerWidth-document.documentElement.clientWidth}px`));window.scrollTo(0,0);let y=Ht(ze(document,"touchstart",a,{passive:!1,capture:!0}),ze(document,"touchmove",n,{passive:!1,capture:!0}),ze(document,"touchend",r,{passive:!1,capture:!0}),ze(document,"focus",o,!0),ze(window,"scroll",l));return()=>{g(),y(),window.scrollTo(u,d)}}function kr(t,s,a){let n=t.style[s];return t.style[s]=a,()=>{t.style[s]=n}}function ze(t,s,a,n){return t.addEventListener(s,a,n),()=>{t.removeEventListener(s,a,n)}}function Vt(t){let s=document.scrollingElement||document.documentElement;for(;t&&t!==s;){let a=ds(t);if(a!==document.documentElement&&a!==document.body&&a!==t){let n=a.getBoundingClientRect().top,r=t.getBoundingClientRect().top,o=t.getBoundingClientRect().bottom;const l=a.getBoundingClientRect().bottom+wr;o>l&&(a.scrollTop+=r-n)}t=a.parentElement}}function bt(t){return t instanceof HTMLInputElement&&!Sr.has(t.type)||t instanceof HTMLTextAreaElement||t instanceof HTMLElement&&t.isContentEditable}function Rr(t,s){typeof t=="function"?t(s):t!=null&&(t.current=s)}function Tr(...t){return s=>t.forEach(a=>Rr(a,s))}function us(...t){return c.useCallback(Tr(...t),t)}const ms=new WeakMap;function te(t,s,a=!1){if(!t||!(t instanceof HTMLElement))return;let n={};Object.entries(s).forEach(([r,o])=>{if(r.startsWith("--")){t.style.setProperty(r,o);return}n[r]=t.style[r],t.style[r]=o}),!a&&ms.set(t,n)}function Pr(t,s){if(!t||!(t instanceof HTMLElement))return;let a=ms.get(t);a&&(t.style[s]=a[s])}const se=t=>{switch(t){case"top":case"bottom":return!0;case"left":case"right":return!1;default:return t}};function st(t,s){if(!t)return null;const a=window.getComputedStyle(t),n=a.transform||a.webkitTransform||a.mozTransform;let r=n.match(/^matrix3d\((.+)\)$/);return r?parseFloat(r[1].split(", ")[se(s)?13:12]):(r=n.match(/^matrix\((.+)\)$/),r?parseFloat(r[1].split(", ")[se(s)?5:4]):null)}function Dr(t){return 8*(Math.log(t+1)-2)}function ut(t,s){if(!t)return()=>{};const a=t.style.cssText;return Object.assign(t.style,s),()=>{t.style.cssText=a}}function Er(...t){return(...s)=>{for(const a of t)typeof a=="function"&&a(...s)}}const X={DURATION:.5,EASE:[.32,.72,0,1]},fs=.4,Ar=.25,Mr=100,hs=8,_e=16,wt=26,mt="vaul-dragging";function xs(t){const s=S.useRef(t);return S.useEffect(()=>{s.current=t}),S.useMemo(()=>(...a)=>s.current==null?void 0:s.current.call(s,...a),[])}function Ir({defaultProp:t,onChange:s}){const a=S.useState(t),[n]=a,r=S.useRef(n),o=xs(s);return S.useEffect(()=>{r.current!==n&&(o(n),r.current=n)},[n,r,o]),a}function ps({prop:t,defaultProp:s,onChange:a=()=>{}}){const[n,r]=Ir({defaultProp:s,onChange:a}),o=t!==void 0,l=o?t:n,u=xs(a),d=S.useCallback(g=>{if(o){const m=typeof g=="function"?g(t):g;m!==t&&u(m)}else r(g)},[o,t,r,u]);return[l,d]}function Or({activeSnapPointProp:t,setActiveSnapPointProp:s,snapPoints:a,drawerRef:n,overlayRef:r,fadeFromIndex:o,onSnapPointChange:l,direction:u="bottom",container:d,snapToSequentialPoint:g}){const[y,m]=ps({prop:t,defaultProp:a==null?void 0:a[0],onChange:s}),[f,b]=S.useState(typeof window<"u"?{innerWidth:window.innerWidth,innerHeight:window.innerHeight}:void 0);S.useEffect(()=>{function k(){b({innerWidth:window.innerWidth,innerHeight:window.innerHeight})}return window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const R=S.useMemo(()=>y===(a==null?void 0:a[a.length-1])||null,[a,y]),v=S.useMemo(()=>a==null?void 0:a.findIndex(k=>k===y),[a,y]),j=a&&a.length>0&&(o||o===0)&&!Number.isNaN(o)&&a[o]===y||!a,w=S.useMemo(()=>{const k=d?{width:d.getBoundingClientRect().width,height:d.getBoundingClientRect().height}:typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0};var E;return(E=a==null?void 0:a.map(O=>{const B=typeof O=="string";let p=0;if(B&&(p=parseInt(O,10)),se(u)){const $=B?p:f?O*k.height:0;return f?u==="bottom"?k.height-$:-k.height+$:$}const D=B?p:f?O*k.width:0;return f?u==="right"?k.width-D:-k.width+D:D}))!=null?E:[]},[a,f,d]),x=S.useMemo(()=>v!==null?w==null?void 0:w[v]:null,[w,v]),i=S.useCallback(k=>{var E;const O=(E=w==null?void 0:w.findIndex(B=>B===k))!=null?E:null;l(O),te(n.current,{transition:`transform ${X.DURATION}s cubic-bezier(${X.EASE.join(",")})`,transform:se(u)?`translate3d(0, ${k}px, 0)`:`translate3d(${k}px, 0, 0)`}),w&&O!==w.length-1&&O!==o&&O<o?te(r.current,{transition:`opacity ${X.DURATION}s cubic-bezier(${X.EASE.join(",")})`,opacity:"0"}):te(r.current,{transition:`opacity ${X.DURATION}s cubic-bezier(${X.EASE.join(",")})`,opacity:"1"}),m(a==null?void 0:a[Math.max(O,0)])},[n.current,a,w,o,r,m]);S.useEffect(()=>{if(y||t){var k;const E=(k=a==null?void 0:a.findIndex(O=>O===t||O===y))!=null?k:-1;w&&E!==-1&&typeof w[E]=="number"&&i(w[E])}},[y,t,a,w,i]);function h({draggedDistance:k,closeDrawer:E,velocity:O,dismissible:B}){if(o===void 0)return;const p=u==="bottom"||u==="right"?(x??0)-k:(x??0)+k,D=v===o-1,$=v===0,W=k>0;if(D&&te(r.current,{transition:`opacity ${X.DURATION}s cubic-bezier(${X.EASE.join(",")})`}),!g&&O>2&&!W){B?E():i(w[0]);return}if(!g&&O>2&&W&&w&&a){i(w[a.length-1]);return}const U=w==null?void 0:w.reduce((V,Z)=>typeof V!="number"||typeof Z!="number"?V:Math.abs(Z-p)<Math.abs(V-p)?Z:V),Q=se(u)?window.innerHeight:window.innerWidth;if(O>fs&&Math.abs(k)<Q*.4){const V=W?1:-1;if(V>0&&R){i(w[a.length-1]);return}if($&&V<0&&B&&E(),v===null)return;i(w[v+V]);return}i(U)}function C({draggedDistance:k}){if(x===null)return;const E=u==="bottom"||u==="right"?x-k:x+k;(u==="bottom"||u==="right")&&E<w[w.length-1]||(u==="top"||u==="left")&&E>w[w.length-1]||te(n.current,{transform:se(u)?`translate3d(0, ${E}px, 0)`:`translate3d(${E}px, 0, 0)`})}
28function z(k,E){if(!a||typeof v!="number"||!w||o===void 0)return null;const O=v===o-1;if(v>=o&&E)return 0;if(O&&!E)return 1;if(!j&&!O)return null;const p=O?v+1:v-1,D=O?w[p]-w[p-1]:w[p+1]-w[p],$=k/Math.abs(D);return O?1-$:$}return{isLastSnapPoint:R,activeSnapPoint:y,shouldFade:j,getPercentageDragged:z,setActiveSnapPoint:m,activeSnapPointIndex:v,onRelease:h,onDrag:C,snapPointsOffset:w}}const qr=()=>()=>{};function Lr(){const{direction:t,isOpen:s,shouldScaleBackground:a,setBackgroundColorOnScale:n,noBodyStyles:r}=Je(),o=S.useRef(null),l=c.useMemo(()=>document.body.style.backgroundColor,[]);function u(){return(window.innerWidth-wt)/window.innerWidth}S.useEffect(()=>{if(s&&a){o.current&&clearTimeout(o.current);const d=document.querySelector("[data-vaul-drawer-wrapper]")||document.querySelector("[vaul-drawer-wrapper]");if(!d)return;Er(n&&!r?ut(document.body,{background:"black"}):qr,ut(d,{transformOrigin:se(t)?"top":"left",transitionProperty:"transform, border-radius",transitionDuration:`${X.DURATION}s`,transitionTimingFunction:`cubic-bezier(${X.EASE.join(",")})`}));const g=ut(d,{borderRadius:`${hs}px`,overflow:"hidden",...se(t)?{transform:`scale(${u()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`}:{transform:`scale(${u()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`}});return()=>{g(),o.current=window.setTimeout(()=>{l?document.body.style.background=l:document.body.style.removeProperty("background")},X.DURATION*1e3)}}},[s,a,l])}let Be=null;function $r({isOpen:t,modal:s,nested:a,hasBeenOpened:n,preventScrollRestoration:r,noBodyStyles:o}){const[l,u]=S.useState(()=>typeof window<"u"?window.location.href:""),d=S.useRef(0),g=S.useCallback(()=>{if(Ft()&&Be===null&&t&&!o){Be={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,height:document.body.style.height,right:"unset"};const{scrollX:m,innerHeight:f}=window;document.body.style.setProperty("position","fixed","important"),Object.assign(document.body.style,{top:`${-d.current}px`,left:`${-m}px`,right:"0px",height:"auto"}),window.setTimeout(()=>window.requestAnimationFrame(()=>{const b=f-window.innerHeight;b&&d.current>=f&&(document.body.style.top=`${-(d.current+b)}px`)}),300)}},[t]),y=S.useCallback(()=>{if(Ft()&&Be!==null&&!o){const m=-parseInt(document.body.style.top,10),f=-parseInt(document.body.style.left,10);Object.assign(document.body.style,Be),window.requestAnimationFrame(()=>{if(r&&l!==window.location.href){u(window.location.href);return}window.scrollTo(f,m)}),Be=null}},[l]);return S.useEffect(()=>{function m(){d.current=window.scrollY}return m(),window.addEventListener("scroll",m),()=>{window.removeEventListener("scroll",m)}},[]),S.useEffect(()=>{a||!n||(t?(!window.matchMedia("(display-mode: standalone)").matches&&g(),s||window.setTimeout(()=>{y()},500)):y())},[t,n,l,s,a,g,y]),{restorePositionSetting:y}}function zr({open:t,onOpenChange:s,children:a,onDrag:n,onRelease:r,snapPoints:o,shouldScaleBackground:l=!1,setBackgroundColorOnScale:u=!0,closeThreshold:d=Ar,scrollLockTimeout:g=Mr,dismissible:y=!0,handleOnly:m=!1,fadeFromIndex:f=o&&o.length-1,activeSnapPoint:b,setActiveSnapPoint:R,fixed:v,modal:j=!0,onClose:w,nested:x,noBodyStyles:i,direction:h="bottom",defaultOpen:C=!1,disablePreventScroll:z=!0,snapToSequentialPoint:k=!1,preventScrollRestoration:E=!1,repositionInputs:O=!0,onAnimationEnd:B,container:p,autoFocus:D=!1}){var $,W;const[U=!1,Q]=ps({defaultProp:C,prop:t,onChange:T=>{s==null||s(T),!T&&!x&&Ne(),setTimeout(()=>{B==null||B(T)},X.DURATION*1e3),T&&!j&&typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),T||(document.body.style.pointerEvents="auto")}}),[V,Z]=S.useState(!1),[ie,fe]=S.useState(!1),[Re,he]=S.useState(!1),N=S.useRef(null),J=S.useRef(null),ae=S.useRef(null),le=S.useRef(null),oe=S.useRef(null),we=S.useRef(!1),qe=S.useRef(null),Le=S.useRef(0),xe=S.useRef(!1),Xe=S.useRef(0),P=S.useRef(null),Te=S.useRef((($=P.current)==null?void 0:$.getBoundingClientRect().height)||0),Qe=S.useRef(((W=P.current)==null?void 0:W.getBoundingClientRect().width)||0),Pe=S.useRef(0),lt=S.useCallback(T=>
28{o&&T===ee.length-1&&(J.current=new Date)},[]),{activeSnapPoint:Ze,activeSnapPointIndex:_,setActiveSnapPoint:A,onRelease:M,snapPointsOffset:ee,onDrag:De,shouldFade:ye,getPercentageDragged:Ee}=Or({snapPoints:o,activeSnapPointProp:b,setActiveSnapPointProp:R,drawerRef:P,fadeFromIndex:f,overlayRef:N,onSnapPointChange:lt,direction:h,container:p,snapToSequentialPoint:k});_r({isDisabled:!U||ie||!j||Re||!V||!O||!z});const{restorePositionSetting:Ne}=$r({isOpen:U,modal:j,nested:x,hasBeenOpened:V,preventScrollRestoration:E,noBodyStyles:i});function pe(){return(window.innerWidth-wt)/window.innerWidth}function re(T){var H,Y;!y&&!o||P.current&&!P.current.contains(T.target)||(Te.current=((H=P.current)==null?void 0:H.getBoundingClientRect().height)||0,Qe.current=((Y=P.current)==null?void 0:Y.getBoundingClientRect().width)||0,fe(!0),ae.current=new Date,cs()&&window.addEventListener("touchend",()=>we.current=!1,{once:!0}),T.target.setPointerCapture(T.pointerId),Le.current=se(h)?T.pageY:T.pageX)}function Dt(T,H){var Y,K;let F=T;const de=(Y=window.getSelection())==null?void 0:Y.toString(),ne=P.current?st(P.current,h):null,ce=new Date;if(F.hasAttribute("data-vaul-no-drag")||F.closest("[data-vaul-no-drag]"))return!1;if(h==="right"||h==="left")return!0;if(J.current&&ce.getTime()-J.current.getTime()<500)return!1;if(ne!==null&&(h==="bottom"?ne>0:ne<0))return!0;if(de&&de.length>0)return!1;if(ce.getTime()-((K=oe.current)==null?void 0:K.getTime())<g&&ne===0||H)return oe.current=ce,!1;for(;F;){if(F.scrollHeight>F.clientHeight){if(F.scrollTop!==0)return oe.current=new Date,!1;if(F.getAttribute("role")==="dialog")return!0}F=F.parentNode}return!0}function Ys(T){if(P.current&&ie){const H=h==="bottom"||h==="right"?1:-1,Y=(Le.current-(se(h)?T.pageY:T.pageX))*H,K=Y>0,F=o&&!y&&!K;if(F&&_===0)return;const de=Math.abs(Y),ne=document.querySelector("[data-vaul-drawer-wrapper]"),ce=h==="bottom"||h==="top"?Te.current:Qe.current;let ue=de/ce;const Se=Ee(de,K);if(Se!==null&&(ue=Se),F&&ue>=1||!we.current&&!Dt(T.target,K))return;if(P.current.classList.add(mt),we.current=!0,te(P.current,{transition:"none"}),te(N.current,{transition:"none"}),o&&De({draggedDistance:Y}),K&&!o){const ge=Dr(Y),et=Math.min(ge*-1,0)*H;te(P.current,{transform:se(h)?`translate3d(0, ${et}px, 0)`:`translate3d(${et}px, 0, 0)`});return}const ve=1-ue;if((ye||f&&_===f-1)&&(n==null||n(T,ue),te(N.current,{opacity:`${ve}`,transition:"none"},!0)),ne&&N.current&&l){const ge=Math.min(pe()+ue*(1-pe()),1),et=8-ue*8,At=Math.max(0,14-ue*14);te(ne,{borderRadius:`${et}px`,transform:se(h)?`scale(${ge}) translate3d(0, ${At}px, 0)`:`scale(${ge}) translate3d(${At}px, 0, 0)`,transition:"none"},!0)}if(!o){const ge=de*H;te(P.current,{transform:se(h)?`translate3d(0, ${ge}px, 0)`:`translate3d(${ge}px, 0, 0)`})}}}S.useEffect(()=>{var T;function H(){if(!P.current||!O)return;const Y=document.activeElement;if(bt(Y)||xe.current){var K;const F=((K=window.visualViewport)==null?void 0:K.height)||0,de=window.innerHeight;let ne=de-F;const ce=P.current.getBoundingClientRect().height||0,ue=ce>de*.8;Pe.current||(Pe.current=ce);const Se=P.current.getBoundingClientRect().top;if(Math.abs(Xe.current-ne)>60&&(xe.current=!xe.current),o&&o.length>0&&ee&&_){const ve=ee[_]||0;ne+=ve}if(Xe.current=ne,ce>F||xe.current){const ve=P.current.getBoundingClientRect().height;let ge=ve;ve>F&&(ge=F-(ue?Se:wt)),v?P.current.style.height=`${ve-Math.max(ne,0)}px`:P.current.style.height=`${Math.max(ge,F-Se)}px`}else P.current.style.height=`${Pe.current}px`;o&&o.length>0&&!xe.current?P.current.style.bottom="0px":P.current.style.bottom=`${Math.max(ne,0)}px`}}return(T=window.visualViewport)==null||T.addEventListener("resize",H),()=>{var Y;return(Y=window.visualViewport)==null?void 0:Y.removeEventListener("resize",H)}},[_,o,ee]);function $e(T){Ks(),w==null||w(),T||Q(!1),setTimeout(()=>{o&&A(o[0])},X.DURATION*1e3)}function Et(){if(!P.current)return;const T=document.querySelector("[data-vaul-drawer-wrapper]"),H=st(P.current,h);
28te(P.current,{transform:"translate3d(0, 0, 0)",transition:`transform ${X.DURATION}s cubic-bezier(${X.EASE.join(",")})`}),te(N.current,{transition:`opacity ${X.DURATION}s cubic-bezier(${X.EASE.join(",")})`,opacity:"1"}),l&&H&&H>0&&U&&te(T,{borderRadius:`${hs}px`,overflow:"hidden",...se(h)?{transform:`scale(${pe()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,transformOrigin:"top"}:{transform:`scale(${pe()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,transformOrigin:"left"},transitionProperty:"transform, border-radius",transitionDuration:`${X.DURATION}s`,transitionTimingFunction:`cubic-bezier(${X.EASE.join(",")})`},!0)}function Ks(){!ie||!P.current||(P.current.classList.remove(mt),we.current=!1,fe(!1),le.current=new Date)}function Gs(T){if(!ie||!P.current)return;P.current.classList.remove(mt),we.current=!1,fe(!1),le.current=new Date;const H=st(P.current,h);if(!Dt(T.target,!1)||!H||Number.isNaN(H)||ae.current===null)return;const Y=le.current.getTime()-ae.current.getTime(),K=Le.current-(se(h)?T.pageY:T.pageX),F=Math.abs(K)/Y;if(F>.05&&(he(!0),setTimeout(()=>{he(!1)},200)),o){M({draggedDistance:K*(h==="bottom"||h==="right"?1:-1),closeDrawer:$e,velocity:F,dismissible:y}),r==null||r(T,!0);return}if(h==="bottom"||h==="right"?K>0:K<0){Et(),r==null||r(T,!0);return}if(F>fs){$e(),r==null||r(T,!1);return}var de;const ne=Math.min((de=P.current.getBoundingClientRect().height)!=null?de:0,window.innerHeight);var ce;const ue=Math.min((ce=P.current.getBoundingClientRect().width)!=null?ce:0,window.innerWidth),Se=h==="left"||h==="right";if(Math.abs(H)>=(Se?ue:ne)*d){$e(),r==null||r(T,!1);return}r==null||r(T,!0),Et()}S.useEffect(()=>(U&&(te(document.documentElement,{scrollBehavior:"auto"}),J.current=new Date),()=>{Pr(document.documentElement,"scrollBehavior")}),[U]);function Js(T){const H=T?(window.innerWidth-_e)/window.innerWidth:1,Y=T?-_e:0;qe.current&&window.clearTimeout(qe.current),te(P.current,{transition:`transform ${X.DURATION}s cubic-bezier(${X.EASE.join(",")})`,transform:`scale(${H}) translate3d(0, ${Y}px, 0)`}),!T&&P.current&&(qe.current=setTimeout(()=>{const K=st(P.current,h);
28te(P.current,{transition:"none",transform:se(h)?`translate3d(0, ${K}px, 0)`:`translate3d(${K}px, 0, 0)`})},500))}function Xs(T,H){if(H<0)return;const Y=(window.innerWidth-_e)/window.innerWidth,K=Y+H*(1-Y),F=-_e+H*_e;te(P.current,{transform:se(h)?`scale(${K}) translate3d(0, ${F}px, 0)`:`scale(${K}) translate3d(${F}px, 0, 0)`,transition:"none"})}function Qs(T,H){const Y=se(h)?window.innerHeight:window.innerWidth,K=H?(Y-_e)/Y:1,F=H?-_e:0;H&&te(P.current,{transition:`transform ${X.DURATION}s cubic-bezier(${X.EASE.join(",")})`,transform:se(h)?`scale(${K}) translate3d(0, ${F}px, 0)`:`scale(${K}) translate3d(${F}px, 0, 0)`})}return S.createElement(es,{defaultOpen:C,onOpenChange:T=>{!y&&!T||(T?Z(!0):$e(!0),Q(T))},open:U},S.createElement(ls.Provider,{value:{activeSnapPoint:Ze,snapPoints:o,setActiveSnapPoint:A,drawerRef:P,overlayRef:N,onOpenChange:s,onPress:re,onRelease:Gs,onDrag:Ys,dismissible:y,handleOnly:m,isOpen:U,isDragging:ie,shouldFade:ye,closeDrawer:$e,onNestedDrag:Xs,onNestedOpenChange:Js,onNestedRelease:Qs,keyboardIsOpen:xe,modal:j,snapPointsOffset:ee,direction:h,shouldScaleBackground:l,setBackgroundColorOnScale:u,noBodyStyles:i,container:p,autoFocus:D}},a))}const gs=S.forwardRef(function({...t},s){const{overlayRef:a,snapPoints:n,onRelease:r,shouldFade:o,isOpen:l,modal:u}=Je(),d=us(s,a),g=n&&n.length>0;return u?S.createElement(Ct,{onMouseUp:r,ref:d,"data-vaul-overlay":"","data-vaul-snap-points":l&&g?"true":"false","data-vaul-snap-points-overlay":l&&o?"true":"false",...t}):(typeof window<"u"&&window.requestAnimationFrame(()=>{document.body.style.pointerEvents="auto"}),null)});gs.displayName="Drawer.Overlay";const bs=S.forwardRef(function({onPointerDownOutside:t,style:s,onOpenAutoFocus:a,...n},r){const{drawerRef:o,onPress:l,onRelease:u,onDrag:d,keyboardIsOpen:g,
28snapPointsOffset:y,modal:m,isOpen:f,direction:b,snapPoints:R,container:v,handleOnly:j,autoFocus:w}=Je(),[x,i]=S.useState(!1),h=us(r,o),C=S.useRef(null),z=S.useRef(null),k=S.useRef(!1),E=R&&R.length>0;Lr();const O=(p,D,$=0)=>{if(k.current)return!0;const W=Math.abs(p.y),U=Math.abs(p.x),Q=U>W,V=["bottom","right"].includes(D)?1:-1;if(D==="left"||D==="right"){if(!(p.x*V<0)&&U>=0&&U<=$)return Q}else if(!(p.y*V<0)&&W>=0&&W<=$)return!Q;return k.current=!0,!0};S.useEffect(()=>{E&&window.requestAnimationFrame(()=>{i(!0)})},[]);function B(p){C.current=null,k.current=!1,u(p)}return S.createElement(_t,{"data-vaul-drawer-direction":b,"data-vaul-drawer":"","data-vaul-delayed-snap-points":x?"true":"false","data-vaul-snap-points":f&&E?"true":"false","data-vaul-custom-container":v?"true":"false",...n,ref:h,style:y&&y.length>0?{"--snap-point-height":`${y[0]}px`,...s}:s,onPointerDown:p=>{j||(n.onPointerDown==null||n.onPointerDown.call(n,p),C.current={x:p.pageX,y:p.pageY},l(p))},onOpenAutoFocus:p=>{a==null||a(p),w||p.preventDefault()},onPointerDownOutside:p=>{if(t==null||t(p),!m||p.defaultPrevented){p.preventDefault();return}g.current&&(g.current=!1)},onFocusOutside:p=>{if(!m){p.preventDefault();return}},onPointerMove:p=>{if(z.current=p,j||(n.onPointerMove==null||n.onPointerMove.call(n,p),!C.current))return;const D=p.pageY-C.current.y,$=p.pageX-C.current.x,W=p.pointerType==="touch"?10:2;O({x:$,y:D},b,W)?d(p):(Math.abs($)>W||Math.abs(D)>W)&&(C.current=null)},onPointerUp:p=>{n.onPointerUp==null||n.onPointerUp.call(n,p),C.current=null,k.current=!1,u(p)},onPointerOut:p=>{n.onPointerOut==null||n.onPointerOut.call(n,p),B(z.current)},onContextMenu:p=>{n.onContextMenu==null||n.onContextMenu.call(n,p),B(z.current)}})});bs.displayName="Drawer.Content";const Br=250,Hr=120,Fr=S.forwardRef(function({preventCycle:t=!1,children:s,...a},n){const{closeDrawer:r,isDragging:o,snapPoints:l,activeSnapPoint:u,setActiveSnapPoint:d,dismissible:g,handleOnly:y,isOpen:m,onPress:f,onDrag:b}=Je(),R=S.useRef(null),v=S.useRef(!1);function j(){if(v.current){i();return}window.setTimeout(()=>{w()},Hr)}function w(){if(o||t||v.current){i();return}if(i(),(!l||l.length===0)&&g){r();return}if(u===l[l.length-1]&&g){r();return}const C=l.findIndex(k=>k===u);if(C===-1)return;const z=l[C+1];d(z)}function x(){R.current=window.setTimeout(()=>{v.current=!0},Br)}function i(){window.clearTimeout(R.current),v.current=!1}return S.createElement("div",{onClick:j,onPointerCancel:i,onPointerDown:h=>{y&&f(h),x()},onPointerMove:h=>{y&&b(h)},ref:n,"data-vaul-drawer-visible":m?"true":"false","data-vaul-handle":"","aria-hidden":"true",...a},S.createElement("span",{"data-vaul-handle-hitarea":"","aria-hidden":"true"},s))});Fr.displayName="Drawer.Handle";function Ur(t){const s=Je(),{container:a=s.container,...n}=t;return S.createElement(ts,{container:a,...n})}const be={Root:zr,Content:bs,Overlay:gs,Portal:Ur,Title:St,Description:kt},ws=({shouldScaleBackground:t=!0,...s})=>e.jsx(be.Root,{shouldScaleBackground:t,...s});ws.displayName="Drawer";const Vr=be.Portal,ys=c.forwardRef(({className:t,...s},a)=>e.jsx(be.Overlay,{ref:a,className:G("fixed inset-0 z-50 bg-black/80",t),...s}));ys.displayName=be.Overlay.displayName;const vs=c.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(Vr,{children:[e.jsx(ys,{}),e.jsxs(be.Content,{ref:n,className:G("fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",t),...a,children:[e.jsx("div",{className:"mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted"}),s]})]}));vs.displayName="DrawerContent";const js=({className:t,...s})=>e.jsx("div",{className:G("grid gap-1.5 p-4 text-center sm:text-left",t),...s});js.displayName="DrawerHeader";const Ns=c.forwardRef(({className:t,...s},a)=>e.jsx(be.Title,{ref:a,className:G("text-lg font-semibold leading-none tracking-tight",t),...s}));Ns.displayName=be.Title.displayName;const Wr=c.forwardRef(({className:t,...s},a)=>e.jsx(be.Description,{ref:a,className:G("text-sm text-muted-foreground",t),...s}));Wr.displayName=be.Description.displayName;const Yr=({open:t,onOpenChange:s})=>{const[a,n]=c.useState(""),[r,o]=c.useState(""),[l,u]=c.useState(!1),[d,g]=c.useState({}),y=()=>{const f={};return a.length<8&&(f.newPassword="Password must be at least 8 characters"),a!==r&&(f.confirmPassword="Passwords do not match"),g(f),Object.keys(f).length===0},m=async()=>
28{if(y()){u(!0);try{const{error:f}=await I.auth.updateUser({password:a});if(f)throw f;L.success("Password updated!"),n(""),o(""),g({}),s(!1)}catch(f){L.error(f.message||"Failed to update password")}finally{u(!1)}}};return e.jsx(Gt,{open:t,onOpenChange:s,children:e.jsxs(Jt,{className:"sm:max-w-sm",children:[e.jsx(Xt,{children:e.jsx(Qt,{className:"font-display",children:"Change Password"})}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(He,{htmlFor:"new-password",children:"New Password"}),e.jsx(qt,{id:"new-password",value:a,onChange:f=>{n(f.target.value),g(b=>({...b,newPassword:void 0}))},placeholder:"Enter new password"}),d.newPassword&&e.jsx("p",{className:"text-xs text-destructive",children:d.newPassword})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(He,{htmlFor:"confirm-password",children:"Confirm Password"}),e.jsx(qt,{id:"confirm-password",value:r,onChange:f=>{o(f.target.value),g(b=>({...b,confirmPassword:void 0}))},placeholder:"Confirm new password"}),d.confirmPassword&&e.jsx("p",{className:"text-xs text-destructive",children:d.confirmPassword})]}),e.jsx(q,{onClick:m,disabled:l,className:"w-full",children:l?"Updating...":"Update Password"})]})]})})};var Ss=["PageUp","PageDown"],_s=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Cs={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Oe="Slider",[yt,Kr,Gr]=fa(Oe),[ks]=pa(Oe,[Gr]),[Jr,it]=ks(Oe),Rs=c.forwardRef((t,s)=>{const{name:a,min:n=0,max:r=100,step:o=1,orientation:l="horizontal",disabled:u=!1,minStepsBetweenThumbs:d=0,defaultValue:g=[n],value:y,onValueChange:m=()=>{},onValueCommit:f=()=>{},inverted:b=!1,form:R,...v}=t,j=c.useRef(new Set),w=c.useRef(0),i=l==="horizontal"?Xr:Qr,[h=[],C]=ma({prop:y,defaultProp:g,onChange:p=>{var $;($=[...j.current][w.current])==null||$.focus(),m(p)}}),z=c.useRef(h);function k(p){const D=an(h,p);B(p,D)}function E(p){B(p,w.current)}function O(){const p=z.current[w.current];h[w.current]!==p&&f(h)}function B(p,D,{commit:$}={commit:!1}){const W=ln(o),U=cn(Math.round((p-n)/o)*o+n,W),Q=ss(U,[n,r]);C((V=[])=>{const Z=tn(V,Q,D);if(on(Z,d*o)){w.current=Z.indexOf(Q);const ie=String(Z)!==String(V);return ie&&$&&f(Z),ie?Z:V}else return V})}return e.jsx(Jr,{scope:t.__scopeSlider,name:a,disabled:u,min:n,max:r,valueIndexToChangeRef:w,thumbs:j.current,values:h,orientation:l,form:R,children:e.jsx(yt.Provider,{scope:t.__scopeSlider,children:e.jsx(yt.Slot,{scope:t.__scopeSlider,children:e.jsx(i,{"aria-disabled":u,"data-disabled":u?"":void 0,...v,ref:s,onPointerDown:Ae(v.onPointerDown,()=>{u||(z.current=h)}),min:n,max:r,inverted:b,onSlideStart:u?void 0:k,onSlideMove:u?void 0:E,onSlideEnd:u?void 0:O,onHomeKeyDown:()=>!u&&B(n,0,{commit:!0}),onEndKeyDown:()=>!u&&B(r,h.length-1,{commit:!0}),onStepKeyDown:({event:p,direction:D})=>{if(!u){const U=Ss.includes(p.key)||p.shiftKey&&_s.includes(p.key)?10:1,Q=w.current,V=h[Q],Z=o*U*D;B(V+Z,Q,{commit:!0})}}})})})})});Rs.displayName=Oe;var[Ts,Ps]=ks(Oe,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Xr=c.forwardRef((t,s)=>{const{min:a,max:n,dir:r,inverted:o,onSlideStart:l,onSlideMove:u,onSlideEnd:d,onStepKeyDown:g,...y}=t,[m,f]=c.useState(null),b=Ie(s,i=>f(i)),R=c.useRef(void 0),v=ha(r),j=v==="ltr",w=j&&!o||!j&&o;function x(i){const h=R.current||m.getBoundingClientRect(),C=[0,h.width],k=Pt(C,w?[a,n]:[n,a]);return R.current=h,k(i-h.left)}return e.jsx(Ts,{scope:t.__scopeSlider,startEdge:w?"left":"right",endEdge:w?"right":"left",direction:w?1:-1,size:"width",children:e.jsx(Ds,{dir:v,"data-orientation":"horizontal",...y,ref:b,style:{...y.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:i=>{const h=x(i.clientX);l==null||l(h)},onSlideMove:i=>{const h=x(i.clientX);u==null||u(h)},onSlideEnd:()=>{R.current=void 0,d==null||d()},onStepKeyDown:i=>{const C=Cs[w?"from-left":"from-right"].includes(i.key);g==null||g({event:i,direction:C?-1:1})}})})}),Qr=c.forwardRef((t,s)=>{const{min:a,max:n,inverted:r,onSlideStart:o,onSlideMove:l,onSlideEnd:u,onStepKeyDown:d,...g}=t,y=c.useRef(null),m=Ie(s,y),f=c.useRef(void 0),b=!r;function R(v){const j=f.current||y.current.getBoundingClientRect(),w=[0,j.height],i=Pt(w,b?[n,a]:[a,n]);return f.current=j,i(v-j.top)}return e.jsx(Ts,{scope:t.__scopeSlider,startEdge:b?"bottom":"top",endEdge:b?"top":"bottom",size:"height",direction:b?1:-1,children:e.jsx(Ds,{"data-orientation":"vertical",...g,ref:m,style:{...g.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:v=>{const j=R(v.clientY);o==null||o(j)},onSlideMove:v=>{const j=R(v.clientY);l==null||l(j)},onSlideEnd:()=>{f.current=void 0,u==null||u()},onStepKeyDown:v=>{const w=Cs[b?"from-bottom":"from-top"].includes(v.key);d==null||d({event:v,direction:w?-1:1})}})})}),Ds=c.forwardRef((t,s)=>{const{__scopeSlider:a,onSlideStart:n,onSlideMove:r,onSlideEnd:o,onHomeKeyDown:l,onEndKeyDown:u,onStepKeyDown:d,...g}=t,y=it(Oe,a);return e.jsx(Ge.span,{...g,ref:s,onKeyDown:Ae(t.onKeyDown,m=>{m.key==="Home"?(l(m),m.preventDefault()):m.key==="End"?(u(m),m.preventDefault()):Ss.concat(_s).includes(m.key)&&
28(d(m),m.preventDefault())}),onPointerDown:Ae(t.onPointerDown,m=>{const f=m.target;f.setPointerCapture(m.pointerId),m.preventDefault(),y.thumbs.has(f)?f.focus():n(m)}),onPointerMove:Ae(t.onPointerMove,m=>{m.target.hasPointerCapture(m.pointerId)&&r(m)}),onPointerUp:Ae(t.onPointerUp,m=>{const f=m.target;f.hasPointerCapture(m.pointerId)&&(f.releasePointerCapture(m.pointerId),o(m))})})}),Es="SliderTrack",As=c.forwardRef((t,s)=>{const{__scopeSlider:a,...n}=t,r=it(Es,a);return e.jsx(Ge.span,{"data-disabled":r.disabled?"":void 0,"data-orientation":r.orientation,...n,ref:s})});As.displayName=Es;var vt="SliderRange",Ms=c.forwardRef((t,s)=>{const{__scopeSlider:a,...n}=t,r=it(vt,a),o=Ps(vt,a),l=c.useRef(null),u=Ie(s,l),d=r.values.length,g=r.values.map(f=>qs(f,r.min,r.max)),y=d>1?Math.min(...g):0,m=100-Math.max(...g);return e.jsx(Ge.span,{"data-orientation":r.orientation,"data-disabled":r.disabled?"":void 0,...n,ref:u,style:{...t.style,[o.startEdge]:y+"%",[o.endEdge]:m+"%"}})});Ms.displayName=vt;var jt="SliderThumb",Is=c.forwardRef((t,s)=>{const a=Kr(t.__scopeSlider),[n,r]=c.useState(null),o=Ie(s,u=>r(u)),l=c.useMemo(()=>n?a().findIndex(u=>u.ref.current===n):-1,[a,n]);return e.jsx(Zr,{...t,ref:o,index:l})}),Zr=c.forwardRef((t,s)=>{const{__scopeSlider:a,index:n,name:r,...o}=t,l=it(jt,a),u=Ps(jt,a),[d,g]=c.useState(null),y=Ie(s,x=>g(x)),m=d?l.form||!!d.closest("form"):!0,f=xa(d),b=l.values[n],R=b===void 0?0:qs(b,l.min,l.max),v=sn(n,l.values.length),j=f==null?void 0:f[u.size],w=j?rn(j,R,u.direction):0;return c.useEffect(()=>{if(d)return l.thumbs.add(d),()=>{l.thumbs.delete(d)}},[d,l.thumbs]),e.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[u.startEdge]:`calc(${R}% + ${w}px)`},children:[e.jsx(yt.ItemSlot,{scope:t.__scopeSlider,children:e.jsx(Ge.span,{role:"slider","aria-label":t["aria-label"]||v,"aria-valuemin":l.min,"aria-valuenow":b,"aria-valuemax":l.max,"aria-orientation":l.orientation,"data-orientation":l.orientation,"data-disabled":l.disabled?"":void 0,tabIndex:l.disabled?void 0:0,...o,ref:y,style:b===void 0?{display:"none"}:t.style,onFocus:Ae(t.onFocus,()=>{l.valueIndexToChangeRef.current=n})})}),m&&e.jsx(Os,{name:r??(l.name?l.name+(l.values.length>1?"[]":""):void 0),form:l.form,value:b},n)]})});Is.displayName=jt;var en="RadioBubbleInput",Os=c.forwardRef(({__scopeSlider:t,value:s,...a},n)=>{const r=c.useRef(null),o=Ie(r,n),l=ga(s);return c.useEffect(()=>{const u=r.current;if(!u)return;const d=window.HTMLInputElement.prototype,y=Object.getOwnPropertyDescriptor(d,"value").set;if(l!==s&&y){const m=new Event("input",{bubbles:!0});y.call(u,s),u.dispatchEvent(m)}},[l,s]),e.jsx(Ge.input,{style:{display:"none"},...a,ref:o,defaultValue:s})});Os.displayName=en;function tn(t=[],s,a){const n=[...t];return n[a]=s,n.sort((r,o)=>r-o)}function qs(t,s,a){const o=100/(a-s)*(t-s);return ss(o,[0,100])}function sn(t,s){return s>2?`Value ${t+1} of ${s}`:s===2?["Minimum","Maximum"][t]:void 0}function an(t,s){if(t.length===1)return 0;const a=t.map(r=>Math.abs(r-s)),n=Math.min(...a);return a.indexOf(n)}function rn(t,s,a){const n=t/2,o=Pt([0,50],[0,n]);return(n-o(s)*a)*a}function nn(t){return t.slice(0,-1).map((s,a)=>t[a+1]-s)}function on(t,s){if(s>0){const a=nn(t);return Math.min(...a)>=s}return!0}function Pt(t,s){return a=>{if(t[0]===t[1]||s[0]===s[1])return s[0];const n=(s[1]-s[0])/(t[1]-t[0]);return s[0]+n*(a-t[0])}}function ln(t){return(String(t).split(".")[1]||"").length}function cn(t,s){const a=Math.pow(10,s);return Math.round(t*a)/a}var Ls=Rs,dn=As,un=Ms,mn=Is;const $s=c.forwardRef(({className:t,...s},a)=>e.jsxs(Ls,{ref:a,className:G("relative flex w-full touch-none select-none items-center",t),...s,children:[e.jsx(dn,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:e.jsx(un,{className:"absolute h-full bg-primary"})}),e.jsx(mn,{className:"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"})]}));$s.displayName=Ls.displayName;const zs="biblez-a11y",Ve={fontScale:1,highContrast:!1,reduceMotion:!1};function Bs(){try{const t=localStorage.getItem(zs);return t?{...Ve,...JSON.parse(t)}:Ve}catch{return Ve}}function Wt(t){localStorage.setItem(zs,JSON.stringify(t)),Hs(t)}function Hs(t){const s=document.documentElement;s.style.fontSize=`${t.fontScale*100}%`,s.classList.toggle("high-contrast",t.highContrast),s.classList.toggle("reduce-motion",t.reduceMotion)}typeof window<"u"&&Hs(Bs());const fn=()=>{const[t,s]=c.useState(Bs),a=(n,r)=>{const o={...t,[n]:r};s(o),Wt(o)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(sr,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"text-sm font-semibold",children:"Text Size"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"A"}),e.jsx($s,{value:[t.fontScale*100],min:100,max:150,step:25,onValueChange:([n])=>a("fontScale",n/100),className:"flex-1","aria-label":"Font size slider"}),e.jsx("span",{className:"text-lg font-bold text-muted-foreground",children:"A"})]}),e.jsxs("div",{className:"flex justify-between mt-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{children:"Normal"}),e.jsx("span",{children:"125%"}),e.jsx("span",{children:"150%"})]})]}),e.jsx("div",{className:"rounded-xl border border-border/50 p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(as,{className:"h-4 w-4 text-primary"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",children:"High Contrast"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Increase text and border contrast"})]})]}),e.jsx(Ce,{checked:t.highContrast,onCheckedChange:n=>a("highContrast",n),"aria-label":"Toggle high contrast mode"})]})}),e.jsx("div",{className:"rounded-xl border border-border/50 p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{className:"h-4 w-4 text-primary"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",children:"Reduce Motion"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Minimize animations throughout the app"})]})]}),e.jsx(Ce,{checked:t.reduceMotion,onCheckedChange:n=>a("reduceMotion",n),"aria-label":"Toggle reduce motion"})]})}),e.jsx(q,{variant:"ghost",size:"sm",className:"w-full text-xs text-muted-foreground",onClick:()=>{s(Ve),Wt(Ve)},children:"Reset to defaults"})]})},hn=({open:t,onOpenChange:s})=>{const{user:a}=ke(),{signOut:n}=ke(),r=Nt(),{theme:o,setTheme:l}=ba(),{isAdmin:u}=wa(),{isIncognito:d,toggleIncognito:g}=ya(),{isDesktopMode:y,toggleDesktopMode:m}=va(),{theme:f,setTheme:b}=ja(),[R,v]=c.useState(!0),[j,w]=c.useState(!1),[x,i]=c.useState(null);c.useEffect(()=>{!t||!a||I.from("profiles").select("earning_enabled, youth_group_id").eq("user_id",a.id).maybeSingle().then(async({data:p})=>{p&&v(p.earning_enabled??!0);const D=p==null?void 0:p.youth_group_id;if(D){const{data:$}=await I.from("youth_groups").select("id, name").eq("id",D).maybeSingle();$&&i($)}else i(null)})},[t,a]);const h=c.useCallback(async p=>{if(!a)return;v(p);const{error:D}=await I.from("profiles").update({earning_enabled:p}).eq("user_id",a.id);D?(v(!p),L.error("Failed to update setting")):L.success(p?"ZCoin earning enabled":"ZCoin earning disabled")},[a]),C="biblez_last_theme",z=typeof window<"u"&&localStorage.getItem(C)||null;f!=="default"&&localStorage.setItem(C,f);const k={"burning-bush":"ð¥ Burning Bush","living-water":"ð§ Living Water","psalm-23":"ð¿ Psalm 23","royal-purple":"ð Royal Purple"},E=f!=="default",O=E?f:z,B=async()=>{await n(),r("/auth")};return e.jsxs(e.Fragment,{children:[e.jsx(ws,{open:t,onOpenChange:s,children:e.jsxs(vs,{className:"max-w-lg mx-auto",children:[e.jsx(js,{className:"text-left",children:e.jsx(Ns,{className:"font-display text-base",children:"Settings"})}),e.jsxs("div",{className:"px-4 pb-24 space-y-1 overflow-y-auto max-h-[70vh]",children:[e.jsxs("div",{className:"flex items-center justify-between py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ar,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Desktop Mode"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Wider layout for laptops & desktops"})]})]}),e.jsx(Ce,{checked:y,onCheckedChange:m})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(rs,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Dark Mode"})]}),e.jsx(Ce,{checked:o==="dark",onCheckedChange:p=>l(p?"dark":"light")})]}),O?e.jsxs("div",{className:"flex items-center justify-between py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Bt,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:k[O]||"Theme"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Toggle your equipped theme on/off"})]})]}),e.jsx(Ce,{checked:E,onCheckedChange:p=>{b(p&&z?z:"default")}})]}):e.jsxs("button",{onClick:()=>{s(!1),r("/shop")},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors text-left",children:[e.jsx(Bt,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"App Theme"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Browse themes in the ZStore"})]})]}),e.jsxs("button",{onClick:()=>{s(!1),r("/notification-preferences")},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors text-left",children:[e.jsx(ot,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Notifications"})]}),e.jsxs("button",{onClick:()=>w(!0),className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors text-left",children:[e.jsx(rr,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Change Password"})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ns,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Incognito Mode"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Hide your online status from friends"})]})]}),e.jsx(Ce,{checked:d,onCheckedChange:g})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xt,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Earn ZCoins"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Turn off to read & track without earning"})]})]}),e.jsx(Ce,{checked:R,onCheckedChange:h})]}),e.jsxs("button",{onClick:()=>{s(!1),r("/downloads")},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors text-left",children:[e.jsx(Na,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Offline Downloads"})]}),u&&e.jsxs("button",{onClick:()=>{s(!1),r("/admin/moderation")},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors text-left",children:[e.jsx(Fe,{className:"h-4.5 w-4.5 text-destructive"}),e.jsx("span",{className:"text-sm font-medium text-destructive",children:"Admin Dashboard"})]}),e.jsxs("button",{onClick:()=>{s(!1),r("/manage-subscription")},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors text-left",children:[e.jsx(Sa,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Manage Subscription"})]}),e.jsxs("button",{onClick:()=>{s(!1),r("/support")},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors text-left",children:[e.jsx(_a,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Help & Support"})]}),e.jsxs("button",{onClick:()=>{s(!1),r("/privacy")},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors text-left",children:[e.jsx(Fe,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Privacy Policy"})]}),e.jsxs("button",{onClick:()=>{s(!1),r("/terms")},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-muted/50 transition-colors text-left",children:[e.jsx(nr,{className:"h-4.5 w-4.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Terms of Service"})]}),e.jsxs("button",{onClick:()=>{s(!1),r("/delete-account")},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-destructive/10 transition-colors text-left",children:[e.jsx(Kt,{className:"h-4.5 w-4.5 text-destructive"}),e.jsx("span",{className:"text-sm font-medium text-destructive",children:"Delete Account"})]}),x&&e.jsxs("button",{onClick:async()=>
28{if(!window.confirm(`Leave ${x.name}? You can rejoin later with the group's invite code.`))return;const{error:p}=await I.rpc("leave_youth_group",{_group_id:x.id});if(p){L.error(p.message||"Failed to leave");return}L.success(`You've left ${x.name}.`),i(null),s(!1)},className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-destructive/10 transition-colors text-left",children:[e.jsx(dr,{className:"h-4.5 w-4.5 text-destructive"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-destructive block",children:"Leave Group"}),e.jsx("span",{className:"text-[11px] text-muted-foreground truncate block",children:x.name})]})]}),e.jsxs("div",{className:"border-t border-border/30 pt-3 mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[e.jsx(lr,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Accessibility"})]}),e.jsx(fn,{})]}),e.jsxs("button",{onClick:B,className:"flex items-center gap-3 w-full py-3 px-3 rounded-xl hover:bg-destructive/10 transition-colors text-left mt-2",children:[e.jsx(is,{className:"h-4.5 w-4.5 text-destructive"}),e.jsx("span",{className:"text-sm font-medium text-destructive",children:"Sign Out"})]})]})]})}),e.jsx(Yr,{open:j,onOpenChange:w})]})},xn=({badgeName:t,size:s=16,className:a})=>{const n=rt[t];return n?e.jsx("span",{title:t,className:G("inline-flex items-center justify-center shrink-0 rounded-full overflow-hidden ring-1 ring-shop-accent/30",a),style:{width:s,height:s},children:e.jsx("img",{src:n,alt:t,className:"w-full h-full object-cover"})}):null};function pn({userId:t}){const[s,a]=c.useState(null),[n,r]=c.useState(!0);c.useEffect(()=>{o()},[t]);const o=async()=>{var u;r(!0);try{const{data:d}=await I.from("trivia_sessions").select("score, total_questions, category, coins_awarded").eq("user_id",t),{data:g}=await I.from("trivia_challenges").select("winner_id, challenger_id, challenged_id, status").eq("status","completed"),y=(g||[]).filter(i=>i.challenger_id===t||i.challenged_id===t),m=(d||[]).length,f=(d||[]).filter(i=>i.score===i.total_questions).length,b=(d||[]).reduce((i,h)=>i+(h.score||0),0),R=(d||[]).reduce((i,h)=>i+(h.total_questions||0),0),v={};(d||[]).forEach(i=>{v[i.category]=(v[i.category]||0)+1});const j=((u=Object.entries(v).sort((i,h)=>h[1]-i[1])[0])==null?void 0:u[0])||null,w=y.filter(i=>i.winner_id===t).length,x=y.filter(i=>i.winner_id&&i.winner_id!==t).length;a({gamesPlayed:m,perfectScores:f,totalCorrect:b,totalQuestions:R,favoriteCategory:j,challengesWon:w,challengesLost:x})}catch(d){console.error("Failed to fetch trivia stats:",d)}finally{r(!1)}};if(n||!s||s.gamesPlayed===0)return null;const l=s.totalQuestions>0?Math.round(s.totalCorrect/s.totalQuestions*100):0;return e.jsxs("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(os,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"font-display font-bold text-sm",children:"Trivia Stats"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"rounded-xl bg-secondary/50 p-3 text-center",children:[e.jsx("p",{className:"text-xl font-display font-bold",children:s.gamesPlayed}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-semibold uppercase",children:"Games"})]}),e.jsxs("div",{className:"rounded-xl bg-secondary/50 p-3 text-center",children:[e.jsxs("p",{className:"text-xl font-display font-bold",children:[l,"%"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-semibold uppercase",children:"Accuracy"})]}),e.jsxs("div",{className:"rounded-xl bg-secondary/50 p-3 text-center",children:[e.jsx("p",{className:"text-xl font-display font-bold text-yellow-500",children:s.perfectScores}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-semibold uppercase",children:"Perfect 10s"})]}),e.jsxs("div",{className:"rounded-xl bg-secondary/50 p-3 text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5",children:[e.jsx("span",{className:"text-xl font-display font-bold text-green-500",children:s.challengesWon}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"/"}),e.jsx("span",{className:"text-xl font-display font-bold text-red-500",children:s.challengesLost})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-semibold uppercase",children:"W/L"})]})]}),s.favoriteCategory&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(Ca,{className:"h-3 w-3"}),"Favorite: ",e.jsx("span",{className:"font-semibold text-foreground capitalize",children:s.favoriteCategory})]})]})}function gn({userId:t}){const[s,a]=c.useState([]),[n,r]=c.useState({wins:0,losses:0,draws:0}),[o,l]=c.useState({wins:0,losses:0,draws:0}),[u,d]=c.useState(!0);if(c.useEffect(()=>{(async()=>{try{const{data:f}=await I.from("game_results").select("game_type, result, is_challenge").eq("user_id",t);if(!f||f.length===0){d(!1);return}const b={};let R=0,v=0,j=0,w=0,x=0,i=0;for(const h of f){const C=h.game_type;b[C]||(b[C]={game_type:C,wins:0,losses:0,draws:0}),h.result==="win"?(b[C].wins++,w++,h.is_challenge&&R++):h.result==="loss"?(b[C].losses++,x++,h.is_challenge&&v++):(b[C].draws++,i++,h.is_challenge&&j++)}a(Object.values(b).sort((h,C)=>C.wins+C.losses+C.draws-(h.wins+h.losses+h.draws))),r({wins:R,losses:v,draws:j}),l({wins:w,losses:x,draws:i})}catch{}finally{d(!1)}})()},[t]),u||o.wins+o.losses+o.draws===0)return null;const g=o.wins+o.losses+o.draws,y=g>0?Math.round(o.wins/g*100):0;return e.jsxs(Ue.div,{initial:{opacity:0,y:12}
28,animate:{opacity:1,y:0},transition:{duration:.4,ease:[.16,1,.3,1]},className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",style:{borderTopColor:"hsl(210, 80%, 55%)",borderTopWidth:"2px"},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(os,{className:"h-4 w-4",style:{color:"hsl(210, 80%, 55%)"}}),e.jsx("h3",{className:"font-display font-bold text-sm",style:{color:"hsl(210, 80%, 55%)"},children:"Game Record"})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-2 mb-4",children:[e.jsx(at,{label:"Wins",value:o.wins,color:"text-green-500"}),e.jsx(at,{label:"Losses",value:o.losses,color:"text-red-500"}),e.jsx(at,{label:"Draws",value:o.draws,color:"text-muted-foreground"}),e.jsx(at,{label:"Win %",value:`${y}%`,color:"text-primary"})]}),n.wins+n.losses+n.draws>0&&e.jsxs("div",{className:"rounded-xl bg-secondary/50 p-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(ka,{className:"h-3.5 w-3.5 text-amber-500"}),e.jsx("p",{className:"text-xs font-bold text-foreground",children:"Challenge Record"})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[e.jsxs("span",{className:"text-green-500 font-bold",children:[n.wins,"W"]}),e.jsxs("span",{className:"text-red-500 font-bold",children:[n.losses,"L"]}),e.jsxs("span",{className:"text-muted-foreground font-bold",children:[n.draws,"D"]})]})]}),e.jsx("div",{className:"space-y-2",children:s.slice(0,6).map(m=>{const f=m.wins+m.losses+m.draws,b=f>0?Math.round(m.wins/f*100):0,R=Ra[m.game_type]||m.game_type;return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground truncate flex-1",children:R}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-green-500 font-semibold",children:[m.wins,"W"]}),e.jsxs("span",{className:"text-red-500 font-semibold",children:[m.losses,"L"]}),e.jsxs("span",{className:G("font-bold w-9 text-right",b>=50?"text-green-500":"text-red-500"),children:[b,"%"]})]})]},m.game_type)})})]})}function at({label:t,value:s,color:a}){return e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:G("text-lg font-display font-bold",a),children:s}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-semibold uppercase tracking-wider",children:t})]})}const bn=({onEquip:t})=>{const{user:s}=ke(),{config:a,ownedItems:n,purchaseItem:r,refetch:o}=Rt(),[l,u]=c.useState([]),[d,g]=c.useState(!0),[y,m]=c.useState("wings"),[f,b]=c.useState(0),[R,v]=c.useState(null);c.useEffect(()=>{(async()=>{const[{data:h},{data:C}]=await Promise.all([I.from("avatar_items").select("*").eq("item_type","accessory").eq("is_active",!0).order("sort_order"),s?I.from("clubcoin_transactions").select("amount").eq("user_id",s.id):{data:[]}]);h&&u(h),b((C||[]).reduce((z,k)=>z+k.amount,0)),g(!1)})()},[s]);const j=l.filter(i=>i.category===y),w=async i=>{v(i.id);const h=await r(i);h.success?(L.success(`⨠${i.name} acquired!`),b(C=>C-i.price_zcoins),await o()):L.error(h.error||"Purchase failed"),v(null)},x=async i=>{if(a.equipped_skin_id&&Ea.has(a.equipped_skin_id)){L.error("Accessories can't be used with this skin");return}const h=a.equipped_accessory_ids.includes(i.item_key),C=h?a.equipped_accessory_ids.filter(z=>z!==i.item_key):[...a.equipped_accessory_ids,i.item_key];await I.from("user_avatar_config").upsert({user_id:s.id,base_type:a.base_type,equipped_skin_id:a.equipped_skin_id,equipped_accessory_ids:C,updated_at:new Date().toISOString()},{onConflict:"user_id"}),await o(),L.success(h?`${i.name} unequipped`:`${i.name} equipped!`),t==null||t()};return d?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between px-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"Your ZCoins"}),e.jsxs("div",{className:"flex items-center gap-1 text-sm font-bold text-amber-500",children:[e.jsx(xt,{className:"h-4 w-4"}
28),f.toLocaleString()]})]}),e.jsx("div",{className:"flex gap-1.5 overflow-x-auto pb-1 -mx-1 px-1 scrollbar-hide",children:Ta.map(i=>e.jsxs("button",{onClick:()=>m(i.key),className:G("flex items-center gap-1 px-3 py-1.5 rounded-full text-xs font-semibold whitespace-nowrap transition-all border",y===i.key?"bg-primary text-primary-foreground border-primary shadow-sm":"bg-card text-muted-foreground border-border/50 hover:border-primary/30"),children:[e.jsx("span",{children:i.emoji}),i.label]},i.key))}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:e.jsx(Pa,{mode:"popLayout",children:j.map(i=>{const h=n.includes(i.id),C=a.equipped_accessory_ids.includes(i.item_key),z=Da[i.item_key];return e.jsxs(Ue.div,{layout:!0,initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},className:G("relative rounded-2xl border-2 p-3 bg-card transition-all",C?"border-primary shadow-md shadow-primary/10":"border-border/40"),children:[e.jsx("div",{className:G("absolute top-2 left-2 px-1.5 py-0.5 rounded-md text-[10px] font-bold uppercase",i.rarity==="legendary"&&"bg-amber-500/20 text-amber-500",i.rarity==="epic"&&"bg-purple-500/20 text-purple-500",i.rarity==="rare"&&"bg-blue-500/20 text-blue-500",i.rarity==="common"&&"bg-muted text-muted-foreground"),children:i.rarity}),C&&e.jsx("div",{className:"absolute top-2 right-2 w-5 h-5 rounded-full bg-primary flex items-center justify-center",children:e.jsx(me,{className:"w-3 h-3 text-primary-foreground"})}),e.jsx("div",{className:"flex justify-center py-2",children:e.jsx("img",{src:z,alt:i.name,className:"w-20 h-20 object-contain",style:{imageRendering:"auto"}})}),e.jsx("p",{className:"text-xs font-bold text-center truncate",children:i.name}),e.jsx("p",{className:"text-[10px] text-muted-foreground text-center line-clamp-2 mt-0.5 min-h-[24px]",children:i.description}),e.jsx("div",{className:"mt-2",children:h?e.jsx(q,{size:"sm",variant:C?"outline":"default",className:"w-full h-7 text-xs rounded-lg font-bold gap-1",onClick:()=>x(i),children:C?"Unequip":"Equip"}):e.jsx(q,{size:"sm",className:"w-full h-7 text-xs rounded-lg font-bold gap-1",disabled:R===i.id||f<i.price_zcoins,onClick:()=>w(i),children:R===i.id?e.jsx("span",{className:"animate-spin h-3 w-3 border border-current border-t-transparent rounded-full"}):e.jsxs(e.Fragment,{children:[e.jsx(xt,{className:"h-3 w-3"}),i.price_zcoins]})})})]},i.id)})})}),j.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground text-sm",children:"No items in this category yet"})]})},wn=({onClose:t})=>{const{config:s,setBaseType:a,loading:n}=Rt(),[r,o]=c.useState(s.base_type),[l,u]=c.useState(!1),[d,g]=c.useState("base"),y=Lt.filter(b=>b.gender==="boy"),m=Lt.filter(b=>b.gender==="girl"),f=async()=>{u(!0),await a(r),u(!1),t==null||t()};return n?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>g("base"),className:G("flex-1 py-2 rounded-xl text-xs font-bold transition-all border-2",d==="base"?"bg-primary text-primary-foreground border-primary":"bg-card text-muted-foreground border-border/50"),children:"⨠Base Avatar"}),e.jsxs("button",{onClick:()=>g("accessories"),className:G("flex-1 py-2 rounded-xl text-xs font-bold transition-all border-2 flex items-center justify-center gap-1",d==="accessories"?"bg-primary text-primary-foreground border-primary":"bg-card text-muted-foreground border-border/50"),children:[e.jsx(pt,{className:"h-3 w-3"}),"Accessories"]})]}),d==="base"?e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx(Ue.div,{initial:{scale:.8,opacity:0}
28,animate:{scale:1,opacity:1},transition:{type:"spring",stiffness:300,damping:20},children:e.jsx(gt,{baseType:r,size:"xl",className:"border-primary/40 shadow-lg shadow-primary/10"})},r)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Boy"}),e.jsx("div",{className:"grid grid-cols-4 gap-2",children:y.map(b=>e.jsxs("button",{onClick:()=>o(b.key),className:G("relative rounded-xl p-1 border-2 transition-all",r===b.key?"border-primary bg-primary/10 scale-105":"border-border/40 hover:border-primary/30"),children:[e.jsx("img",{src:b.src,alt:b.label,className:"w-full aspect-square object-contain rounded-lg",style:{imageRendering:"pixelated"}}),r===b.key&&e.jsx(Ue.div,{initial:{scale:0},animate:{scale:1},className:"absolute -top-1 -right-1 w-5 h-5 rounded-full bg-primary flex items-center justify-center",children:e.jsx(me,{className:"w-3 h-3 text-primary-foreground"})})]},b.key))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Girl"}),e.jsx("div",{className:"grid grid-cols-4 gap-2",children:m.map(b=>e.jsxs("button",{onClick:()=>o(b.key),className:G("relative rounded-xl p-1 border-2 transition-all",r===b.key?"border-primary bg-primary/10 scale-105":"border-border/40 hover:border-primary/30"),children:[e.jsx("img",{src:b.src,alt:b.label,className:"w-full aspect-square object-contain rounded-lg",style:{imageRendering:"pixelated"}}),r===b.key&&e.jsx(Ue.div,{initial:{scale:0},animate:{scale:1},className:"absolute -top-1 -right-1 w-5 h-5 rounded-full bg-primary flex items-center justify-center",children:e.jsx(me,{className:"w-3 h-3 text-primary-foreground"})})]},b.key))})]}),e.jsxs(q,{onClick:f,disabled:l||r===s.base_type,className:"w-full rounded-full font-bold gap-2",children:[e.jsx(Aa,{className:"h-4 w-4"}),l?"Saving...":"Set Avatar"]})]}):e.jsx(bn,{})]})},yn=es,vn=ts,Fs=c.forwardRef(({className:t,...s},a)=>e.jsx(Ct,{className:G("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...s,ref:a}));Fs.displayName=Ct.displayName;const jn=Ia("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Us=c.forwardRef(({side:t="right",className:s,children:a,...n},r)=>e.jsxs(vn,{children:[e.jsx(Fs,{}),e.jsxs(_t,{ref:r,className:G(jn({side:t}),s),...n,children:[a,e.jsxs(Ma,{className:"absolute right-4 top-4 roun
28ded-sm opacity-70 ring-offset-background transition-opacity data-[state=open]:bg-secondary hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[e.jsx(ht,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Us.displayName=_t.displayName;const Vs=({className:t,...s})=>e.jsx("div",{className:G("flex flex-col space-y-2 text-center sm:text-left",t),...s});Vs.displayName="SheetHeader";const Ws=c.forwardRef(({className:t,...s},a)=>e.jsx(St,{ref:a,className:G("text-lg font-semibold text-foreground",t),...s}));Ws.displayName=St.displayName;const Nn=c.forwardRef(({className:t,...s},a)=>e.jsx(kt,{ref:a,className:G("text-sm text-muted-foreground",t),...s}));Nn.displayName=kt.displayName;const Yt=Va.reduce((t,s)=>t+s.chapters,0);function Sn({item:t,imgSrc:s,details:a}){const[n,r]=c.useState(!1),[o,l]=c.useState(null),u=(d,g)=>{navigator.clipboard.writeText(d).then(()=>{l(g),L.success(`${g} copied!`),setTimeout(()=>l(null),2e3)})};return e.jsxs("div",{className:"rounded-xl border border-border/50 bg-secondary/30 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3",children:[s&&e.jsx("img",{src:s,alt:t.name,className:"w-12 h-12 rounded-lg object-cover flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-display font-bold truncate",children:t.name}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Purchased â"})]}),a&&e.jsxs(q,{variant:"ghost",size:"sm",className:"h-8 gap-1 text-xs rounded-lg",onClick:()=>r(!n),children:[n?e.jsx(ns,{className:"h-3.5 w-3.5"}):e.jsx(as,{className:"h-3.5 w-3.5"}),n?"Hide":"Show"]})]}),a&&n&&e.jsxs("div",{className:"border-t border-border/30 p-3 space-y-2",children:[e.jsx("div",{className:"rounded-lg bg-card/80 border border-border/40 p-2.5 space-y-1.5",children:a.fields.map(d=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[d.label,": ",e.jsx("span",{className:"font-mono font-bold text-foreground",children:d.value})]}),e.jsx("button",{onClick:()=>u(d.value,d.label),className:"text-[10px] text-primary hover:text-primary/80 flex items-center gap-0.5",children:o===d.label?e.jsx(me,{className:"h-3 w-3"}):e.jsx(Zt,{className:"h-3 w-3"})})]},d.label))}),e.jsx("p",{className:"text-xs font-bold text-foreground",children:a.instructions.title}),e.jsx("ol",{className:"list-decimal list-inside space-y-1 text-[11px] text-muted-foreground",children:a.instructions.steps.map((d,g)=>e.jsx("li",{children:d},g))})]})]})}function _n({item:t,imgSrc:s}){const[a,n]=c.useState(null),[r,o]=c.useState(!1),l=async()=>{if(!r){o(!0);try{const{data:u,error:d}=await I.rpc("get_purchased_card_details",{_item_id:t.id}),g=u;if(d||!(g!=null&&g.success))return;const y=/starbucks/i.test(g.brand||"")?"Security Code":"PIN";n({fields:[{label:"Card Number",value:g.card_number},{label:y,value:g.card_pin}],instructions:g.instructions||{title:"ð± How to redeem:",steps:["Open the app","Enter the card number + PIN"]}})}catch(u){console.error("Failed to fetch card details:",u)}}};return c.useEffect(()=>{l()},[]),e.jsx(Sn,{item:t,imgSrc:s,details:a})}const Wn=()=>{var Ze;const{userId:t}=Oa(),s=Nt(),{user:a,loading:n}=ke(),r=!t||t===(a==null?void 0:a.id),o=t||(a==null?void 0:a.id),[l,u]=c.useState(null),[d,g]=c.useState([]),[y,m]=c.useState(0),[f,b]=c.useState(!1),[R,v]=c.useState(!1),[j,w]=c.useState({currentStreak:0,longestStreak:0}),[x,i]=c.useState(!1),[h,C]=c.useState(!1),[z,k]=c.useState(!1),[E,O]=c.useState(null),[B,p]=c.useState(null),[D,$]=c.useState(null),[W,U]=c.useState(""),[Q,V]=c.useState(!1),[Z,ie]=c.useState(!1),fe=c.useRef(null),[Re,he]=c.useState(!1),{config:N}=Rt(),{items:J,allItems:ae,purchases:le,equippedBadge:oe,equipBadge:we}=Ga(),qe=qa();c.useEffect(()=>{if(!o)return;(async()=>{var ye,Ee,Ne,pe;const[A,M,ee,De]=await Promise.all([r?I.from("profiles").select("*").eq("user_id",o).maybeSingle():I.from("profiles_public").select("user_id, username, avatar_url, country, created_at, equipped_shop_badge, profile_picture_type, avatar_base_type, avatar_skin_id, avatar_accessory_ids").eq("user_id",o).maybeSingle(),I.from("achievements").select("*").eq("user_id",o).order("earned_at",{ascending:!1}),I.from("reading_progress").select("user_id").eq("user_id",o),I.from("club_memberships").select("is_active").eq("user_id",o).maybeSingle()]);if(A.data&&u(A.data),M.data&&g(M.data),m(((ye=ee.data)==null?void 0:ye.length)||0),b(((Ee=De.data)==null?void 0:Ee.is_active)===!0),r&&((Ne=A.data)!=null&&Ne.youth_group_id)){const{data:re}=await I.from("youth_groups").select("name, church_name").eq("id",A.data.youth_group_id).maybeSingle();re&&O(re)}if(r&&((pe=A.data)!=null&&pe.school_id)){const{data:re}=await I.from("schools").select("name, school_name").eq("id",A.data.school_id).maybeSingle();re&&p(re)}if(!r&&a){const{data:re}=await I.rpc("is_friend_with",{_user_id:o});k(!!re)}if(r){const{data:re}=await I.from("parent_children").select("id").eq("linked_child_user_id",o).maybeSingle();ie(!!re)}})()},[o]);const Le=async _=>{var M;const A=(M=_.target.files)==null?void 0:M[0];if(!(!A||!a)){if(A.size>2*1024*1024){L.error("Image must be under 2MB");return}v(!0);try{const ee=A.name.split(".").pop(),De=`${a.id}/avatar.${ee}`,{error:ye}=await I.storage.from("avatars").upload(De,A,{upsert:!0});if(ye)throw ye;const{data:{publicUrl:Ee}}=I.storage.from("avatars").getPublicUrl(De),Ne=`${Ee}?t=${Date.now()}`,{error:pe}=await I.from("profiles").update({avatar_url:Ne,profile_picture_type:"photo"}).eq("user_id",a.id);if(pe)throw pe;u(re=>re&&{...re,avatar_url:Ne,profile_picture_type:"photo"}),L.success("Profile picture updated!")}catch(ee){L.error(ee.message||"Failed to upload")}finally{v(!1)}}};if(n)return e.jsx($t,{variant:"profile"});if(!o)return e.jsxs("div",{className:"min-h-screen bg-background flex items-center justify-center flex-col gap-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"Please sign in to view your profile."}),e.jsx(q,{onClick:()=>s("/auth"),children:"Sign In"})]});if(!l)return e.jsx($t,{variant:"profile"});const xe=((Ze=l.username)==null?void 0:Ze.split("@")[0])||"Reader";xe.slice(0,2).toUpperCase();const Xe=new Date(l.created_at).toLocaleDateString("en-US",{month:"long",year:"numeric"}),P=(y/Yt*100).toFixed(1),Te=r?qe:j,Qe=le.map(_=>_.item_id),Pe=J.filter(_=>_.category==="badge"&&Qe.includes(_.id)),lt=async _=>{if(_){const A=J.find(ee=>ee.name===_),M=(A==null?void 0:A.image_url)||(A?rt[A.name]:null)||null;$({name:_,image:M}),we(_,!0)}else we(null)};return e.jsxs("div",{className:"min-h-screen bg-background pb-24",children:[e.jsx("input",{ref:fe,type:"file",accept:"image/*",className:"hidden",onChange:Le}),e.jsx(Ja,{show:!!D,badgeName:(D==null?void 0:D.name)||null,badgeImage:D==null?void 0:D.image,onDone:()=>$(null)}),e.jsx("div",{className:"sticky top-0 z-20 bg-background/80 backdrop-blur-md border-b border-border/30",children:e.jsxs("div",{className:"flex items-center justify-between px-4 h-12 max-w-lg mx-auto",children:[e.jsx(q,{variant:"ghost",size:"icon",onClick:()=>s(-1),className:"h-9 w-9 rounded-full",children:e.jsx(or,{className:"h-5 w-5"})}),e.jsx("h1",{className:"font-display font-bold text-base",children:xe}),e.jsxs("div",{className:"flex items-center gap-1",children:[r&&e.jsx(q,{variant:"ghost",size:"icon",onClick:()=>C(!0),className:"h-9 w-9 rounded-full",children:e.jsx(ir,{className:"h-5 w-5"})}),r&&e.jsx(fr,{}),!r&&e.jsx("div",{className:"w-9"})]})]})}),e.jsxs("div",{className:"container mx-auto px-4 max-w-lg pt-6",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[l.profile_picture_type==="photo"&&l.avatar_url?e.jsx("div",{className:G("w-20 h-20 rounded-xl overflow-hidden border-2 border-border/50 shadow-lg",r&&"curs
28or-pointer hover:border-primary/50 transition-colors"),onClick:r?()=>{var _;return(_=fe.current)==null?void 0:_.click()}:void 0,children:e.jsx("img",{src:l.avatar_url,alt:"Profile",className:"w-full h-full object-cover"})}):e.jsx(gt,{baseType:r?N.base_type:l.avatar_base_type||"boy-medium",skinKey:r?N.equipped_skin_id:l.avatar_skin_id||null,accessoryKeys:r?N.equipped_accessory_ids:l.avatar_accessory_ids||[],size:"lg",className:"border-2 border-border/50 shadow-lg",onClick:r?()=>he(!0):void 0}),r&&e.jsx("button",{onClick:()=>{var _;l.profile_picture_type==="photo"?(_=fe.current)==null||_.click():he(!0)},className:"absolute -bottom-1 -right-1 h-7 w-7 rounded-full bg-primary text-primary-foreground flex items-center justify-center shadow-md border-2 border-background hover:opacity-90 transition-opacity",children:l.profile_picture_type==="photo"?e.jsx(cr,{className:"h-3.5 w-3.5"}):e.jsx(nt,{className:"h-3.5 w-3.5"})}),r&&e.jsx("button",{onClick:async()=>{var A;const _=l.profile_picture_type==="photo"?"avatar":"photo";if(_==="photo"&&!l.avatar_url){(A=fe.current)==null||A.click();return}await I.from("profiles").update({profile_picture_type:_}).eq("user_id",a.id),u(M=>M&&{...M,profile_picture_type:_}),L.success(_==="photo"?"Switched to photo":"Switched to avatar")},className:"absolute -bottom-1 -left-1 h-7 w-7 rounded-full bg-muted text-foreground flex items-center justify-center shadow-md border-2 border-background hover:bg-muted/80 transition-colors",title:l.profile_picture_type==="photo"?"Switch to avatar":"Switch to photo",children:l.profile_picture_type==="photo"?e.jsx(La,{className:"h-3.5 w-3.5"}):e.jsx($a,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-display font-bold",children:y}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-semibold uppercase tracking-wider",children:"Chapters"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-display font-bold",children:Te.currentStreak}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-semibold uppercase tracking-wider",children:"Streak"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-display font-bold",children:d.length}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-semibold uppercase tracking-wider",children:"Badges"})]})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-display font-bold text-sm",children:xe}),e.jsx(za,{chaptersRead:y,size:16}),(r||z)&&l.equipped_shop_badge&&e.jsx(xn,{badgeName:l.equipped_shop_badge,size:16}),f&&e.jsx("span",{className:"text-base",title:"Bible Club Member",children:"ð³ï¸"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[e.jsx(Ba,{className:"h-3 w-3 inline mr-1"}),"Member since ",Xe]}),r&&e.jsxs(q,{variant:"outline",size:"sm",className:"mt-3 w-full gap-1.5 rounded-xl",onClick:()=>i(!0),children:[e.jsx(nt,{className:"h-3.5 w-3.5"})," Edit Profile"]})]}),e.jsxs("div",{className:"mt-6 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",style:{borderTopColor:"hsl(152, 68%, 54%)",borderTopWidth:"2px"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"font-display font-bold text-sm",style:{color:"hsl(152, 68%, 54%)"},children:"Bible Progress"}),Ha(y)&&e.jsx(Fa,{chaptersRead:y,size:"sm"})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs mb-2",children:[e.jsxs("span",{className:"text-muted-foreground",children:[y," / ",Yt," chapters"]}),e.jsxs("span",{className:"font-semibold text-primary",children:[P,"%"]})]}),e.jsx("div",{className:"h-2.5 bg-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-gradient-brand transition-all duration-700",style:{width:`${Math.min(parseFloat(P),100)}%`}})})]}),e.jsxs("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",style:{borderTopColor:"hsl(45, 93%, 58%)",borderTopWidth:"2px"},children:[e.jsx("h3",{className:"font-display font-bold text-sm mb-3",style:{color:"hsl(45, 93%, 58%)"},children:"Reading Streaks"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-display font-bold",style:{color:"hsl(24, 95%, 58%)"},children:Te.currentStreak}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Current streak"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-display font-bold",style:{color:"hsl(0, 72%, 58%)"},children:Te.longestStreak}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Longest streak"})]})]})]}),r&&!B&&e.jsx("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",style:{borderTopColor:"hsl(217, 91%, 60%)",borderTopWidth:"2px"},children:e.jsx(pr,{})}),r&&!E&&e.jsx("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",children:e.jsx(xr,{})}),r&&e.jsxs("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",style:{borderTopColor:"hsl(280, 68%, 60%)",borderTopWidth:"2px"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"font-display font-bold text-sm",style:{color:"hsl(280, 68%, 60%)"},children:"My Avatar"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(q,{variant:"outline",size:"sm",className:"h-7 text-xs rounded-lg gap-1",onClick:()=>s("/prayer-closet"),children:[e.jsx(pt,{className:"h-3 w-3"}),"Prayer Closet"]}),e.jsxs(q,{variant:"outline",size:"sm",className:"h-7 text-xs rounded-lg gap-1",onClick:()=>he(!0),children:[e.jsx(nt,{className:"h-3 w-3"}),"Customize"]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(gt,{baseType:N.base_type,skinKey:N.equipped_skin_id,accessoryKeys:N.equipped_accessory_ids,size:"lg",className:"border-primary/30"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold",children:N.equipped_skin_id&&zt[N.equipped_skin_id]?zt[N.equipped_skin_id]:N.base_type.replace("-"," â ").replace(/\b\w/g,_=>_.toUpperCase())}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:N.equipped_accessory_ids.length>0?`${N.equipped_accessory_ids.length} accessories equipped â¨`:N.equipped_skin_id?"Skin equipped â¨":"No items equipped"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Tap Customize to change your avatar or browse accessories"})]})]})]}),d.length>0&&(r||z)&&e.jsxs("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",style:{borderTopColor:"hsl(24, 95%, 58%)",borderTopWidth:"2px"},children:[e.jsx("h3",{className:"font-display font-bold text-sm mb-4",style:{color:"hsl(24, 95%, 58%)"},children:"Achievements"}),e.jsx("div",{className:"grid grid-cols-4 gap-3",children:d.map(_=>e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsx(er,{type:_.achievement_type,book:_.book,size:"sm"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1 truncate w-full",children:_.book||"Bible"})]},_.id))})]}),d.length>0&&!r&&!z&&e.jsx("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm text-center",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"ð Badges are only visible to friends"})}),r&&Pe.length>0&&e.jsxs("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(pt,{className:"h-4 w-4 text-shop-accent"}),e.jsx("h3",{className:"font-display font-bold text-sm",children:"My Shop Badges"})]}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:Pe.map(_=>{const A=oe===_.name,M=_.image_url||rt[_.name];return e.jsxs("div",{className:`relative flex flex-col items-center gap-2 rounded-xl p-3 border transition-all ${A?"border-shop-accent/50 bg-shop-accent/10 shadow-sm":"border-border/30 bg-background/50"}`,children:[A&&e.jsx("div",{className:"absolute top-1.5 right-1.5 h-4 w-4 roun
28ded-full bg-shop-accent flex items-center justify-center",children:e.jsx(me,{className:"h-2.5 w-2.5 text-white"})}),M&&e.jsx("img",{src:M,alt:_.name,className:"w-14 h-14 object-contain rounded-lg"}),e.jsx("p",{className:"text-[10px] font-semibold text-center leading-tight line-clamp-2",children:_.name.replace(" Badge","")}),e.jsx(q,{variant:A?"outline":"default",size:"sm",className:`w-full h-7 text-[10px] rounded-lg ${A?"":"bg-shop-accent hover:bg-shop-accent/90 text-white"}`,onClick:()=>lt(A?null:_.name),children:A?"Unequip":"Equip"})]},_.id)})})]}),r&&(()=>{const _=le.map(M=>M.item_id),A=ae.filter(M=>(M.category==="store_discount"||M.tier>=2)&&M.category!=="badge"&&_.includes(M.id));return A.length===0?null:e.jsxs("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Ua,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"font-display font-bold text-sm",children:"My Purchases"})]}),e.jsx("div",{className:"space-y-3",children:A.map(M=>{const ee=M.image_url||rt[M.name];return e.jsx(_n,{item:M,imgSrc:ee},M.id)})})]})})(),e.jsx(pn,{userId:o}),e.jsx(gn,{userId:o}),r&&E&&e.jsx("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-purple-500/20 flex items-center justify-center shrink-0",children:e.jsx(ft,{className:"h-5 w-5 text-purple-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-display font-bold text-sm truncate",children:E.name}),E.church_name&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:E.church_name})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground bg-muted px-2 py-0.5 rounded-full",children:"ð Only you"})]})}),r&&!Z&&e.jsxs("div",{className:"mt-4 rounded-2xl bg-card border border-border/50 p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Me,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"text-sm font-bold",children:"Link Parent Account"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"If your parent has a Biblez Parentz account, enter the code they shared with you to link your accounts."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(je,{value:W,onChange:_=>U(_.target.value.toUpperCase()),placeholder:"Enter 6-digit code",maxLength:6,className:"rounded-xl font-mono tracking-widest text-center uppercase"}),e.jsx("button",{disabled:W.length<6||Q,onClick:async()=>{V(!0);try{const{data:_,error:A}=await I.rpc("claim_parent_link_code",{_code:W}),M=_;if(A)throw new Error(A.message);M!=null&&M.success?(L.success(`Linked to ${M.parent_name||"your parent"}! ð`),ie(!0),U("")):L.error((M==null?void 0:M.error)||"Failed to link")}catch(_){L.error(_.message||"Failed to link")}V(!1)},className:"px-4 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold whitespace-nowrap disabled:opacity-50",children:Q?"...":"Link"})]})]}),r&&Z&&e.jsxs("div",{className:"mt-4 rounded-2xl bg-primary/5 border border-primary/20 p-4 flex items-center gap-3",children:[e.jsx(Me,{className:"h-5 w-5 text-primary flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Parent Account Linked â
"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your parent can see your reading progress"})]})]}),r&&e.jsx("div",{className:"mt-4",children:e.jsx(gr,{})})]}),r&&l&&e.jsx(hr,{open:x,onOpenChange:i,userId:o,currentUsername:l.username,currentCountry:l.country,currentPhoneNumber:l.phone_number,onSaved:(_,A,M)=>{u(ee=>ee&&{...ee,username:_,country:A,phone_number:M})}}),r&&e.jsx(hn,{open:h,onOpenChange:C}),e.jsx(yn,{open:Re,onOpenChange:he,children:e.jsxs(Us,{side:"bottom",className:"rounded-t-3xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Vs,{children:e.jsx(Ws,{className:"font-display",children:"Choose Your Avatar"})}),e.jsx("div",{className:"pt-4 pb-8",children:e.jsx(wn,{onClose:()=>he(!1)})})]})})]})};export{Wn 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.