1import{c as E,o as b,a as w,p as S,k as c,V as p}from"./index-IxvR3ybE.js";const C=()=>{const{toast:a}=E(),i=b(),{currentUser:r}=w(),l=()=>{try{const e=localStorage.getItem("unlocked-events");return e?JSON.parse(e):[]}catch{return[]}},m=e=>{try{localStorage.setItem("unlocked-events",JSON.stringify(e))}catch(o){console.error("Failed to save unlocked events to localStorage:",o)}},{data:t=[],isLoading:g,refetch:d}=S({queryKey:["unlocked-events"],queryFn:async()=>{if(!(r!=null&&r.id))return l();const{data:e,error:o}=await c.from("event_access_codes").select("event_id").eq("unlocked_by_user_id",r.id);if(o)throw console.error("Error fetching unlocked events:",o),o;return console.log("Fetched unlocked events from referral codes:",e),e.map(f=>f.event_id)},staleTime:0,refetchOnWindowFocus:!0}),u=p({mutationFn:async({accessCode:e,eventId:o})=>{if(console.log("Submitting referral code:",{accessCode:e,eventId:o,userId:(r==null?void 0:r.id)||"anonymous"}),!e||e.trim()!=="#Kconect09099")throw new Error("Invalid referral code. Please enter the correct code.");if(!(r!=null&&r.id)){const k=l();if(!k.includes(o)){const h=[...k,o];m(h)}return{success:!0,message:o==="admin-unlock"?"Unlimited event creation unlocked!":"Event features unlocked successfully!"}}const{data:y,error:n}=await c.from("event_access_codes").select("id").eq("event_id",o).eq("access_code",e).eq("unlocked_by_user_id",r.id).maybeSingle();if(n)throw console.error("Error checking existing code:",n),n;if(y)return{success:!0,message:o==="admin-unlock"?"Unlimited event creation already unlocked!":"Event features already unlocked!"};const{data:_,error:s}=await c.from("event_access_codes").insert([{event_id:o,access_code:e,unlocked_by_user_id:r.id}]).select().single();if(s)throw console.error("Error recording referral code:",s),s;return{success:!0,message:o==="admin-unlock"?"Unlimited event creation unlocked!":"Event features unlocked successfully!",data:_}},onSuccess:async e=>{console.log("Referral code submission successful:",e),await i.invalidateQueries({queryKey:["unlocked-events"]}),await i.invalidateQueries({queryKey:["event-payments"]}),await d(),a({title:"Success",description:e.message})},onError:e=>{console.error("Submit referral code error:",e),a({title:"Error",description:`Failed to unlock event: ${e.message}`,variant:"destructive"})}}),v=e=>{const o=t.includes(e);return console.log("Checking if event is unlocked by referral code:",{eventId:e,unlockedEvents:t,isUnlocked:o}),o};return{unlockedEvents:t,isLoadingUnlocked:g,refetchUnlocked:d,submitReferralCode:u.mutate,isSubmittingCode:u.isPending,isEventUnlockedByCode:v}};export{C as u};
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.