1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/courseTimeZone-C-EM-zv4.js","assets/index-CEuwz0Wd.js","assets/index-DpXtj1XG.css"])))=>i.map(i=>d[i]); 2import{Z as t,a1 as d,U as e,a4 as p,a2 as c,bm as ge,b4 as ye,b5 as Ne,b6 as V,b7 as f,b8 as ve,b9 as m,ag as be,aF as we,aG as Ce,ba as _e,aI as Se,aJ as H,bn as Ae,bo as ke,aV as De,am as B,an as P,ao as W,ap as G,o as Le,a3 as h,aq as Te,ar as Ee,as as Me,at as ze,au as Ie,al as Ve,ax as N,ay as me}from"./index-CEuwz0Wd.js";const Fe=["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"],Re=()=>{const[ue,xe]=t.useState([]),[F,J]=t.useState(!0),[C,K]=t.useState(""),[n,_]=t.useState(null),[v,S]=t.useState(null),[A,j]=t.useState(!1),[u,k]=t.useState(null),[Q,$]=t.useState(""),[he,O]=t.useState(""),[pe,R]=t.useState(""),[D,X]=t.useState(""),[L,Y]=t.useState(""),[T,ee]=t.useState(""),[b,se]=t.useState(""),[E,ae]=t.useState(""),[Z,te]=t.useState(""),[U,ne]=t.useState(""),M=async()=>{J(!0);const{data:s,error:a}=await d.from("course_submissions").select("*").order("created_at",{ascending:!1});!a&&s&&xe(s),J(!1)};t.useEffect(()=>{M()},[]),t.useEffect(()=>{if(!n){O(""),R("");return}let s=!1;return(async()=>{try{const{data:a}=await d.functions.invoke("list-users"),x=(Array.isArray(a)?a:(a==null?void 0:a.users)||[]).find(l=>l.id===n.submitted_by);s||O((x==null?void 0:x.email)||"â")}catch{s||O("â")}if(n.tournament_id){const{data:a}=await d.from("tournaments").select("name").eq("id",n.tournament_id).maybeSingle();s||R((a==null?void 0:a.name)||"â")}else s||R("â")})(),()=>{s=!0}},[n]);const re=s=>{S(s),X(s.name),Y(s.street_address),ee(s.city),se(s.state),ae(s.zip_code),te(""),ne("")},fe=async()=>{var y,de,ce;if(!v)return;if(!D.trim()||!L.trim()||!T.trim()||!b||!E.trim()){N.error("Course Name, Address, City, State, and Zip are required.");return}j(!0);let s=Z?parseFloat(Z):null,a=U?parseFloat(U):null;if(s==null||a==null){const{geocodeAddress:o}=await me(async()=>{const{geocodeAddress:i}=await import("./geocode-CvLbPqoP.js");return{geocodeAddress:i}},[]),z=await o({street:L.trim(),city:T.trim(),state:b,zip:E.trim()});z&&(s=z.latitude,a=z.longitude)}const{detectCourseTimeZone:w}=await me(async()=>{const{detectCourseTimeZone:o}=await import("./courseTimeZone-C-EM-zv4.js");return{detectCourseTimeZone:o}},__vite__mapDeps([0,1,2])),x=w({latitude:s,longitude:a,state:b}).timeZone,{data:l,error:le}=await d.from("courses").insert({name:D.trim(),street_address:L.trim(),city:T.trim(),state:b,zip_code:E.trim(),latitude:s,longitude:a,time_zone:x}).select("id").single();if(le||!l){N.error("Failed to create course."),j(!1);return}const r=v.tournament_id;if(r){const{error:o}=await d.from("tournaments").update({course_id:l.id}).eq("id",r);o&&console.error("Failed to link tournament to new course:",o)}try{const{data:o}=await d.functions.invoke("list-users"),i=(Array.isArray(o)?o:(o==null?void 0:o.users)||[]).find(q=>q.id===v.submitted_by),I=i==null?void 0:i.email;if(I){const q=[(y=i==null?void 0:i.user_metadata)==null?void 0:y.first_name,(de=i==null?void 0:i.user_metadata)==null?void 0:de.last_name].filter(Boolean).join(" ").trim()||((ce=i==null?void 0:i.user_metadata)==null?void 0:ce.full_name)||I;await d.from("scheduled_emails").insert({to_email:I,trigger_action:"new_course_approved",variables:{user_name:q,user_email:I,course_name:D.trim()},scheduled_at:new Date().toISOString(),status:"pending"})}}catch(o){console.error("Failed to schedule new course approved email:",o)}const{error:g}=await d.from("course_submissions").delete().eq("id",v.id);g&&N.error("Course created but failed to remove submission."),N.success("Course approved and added to Course Management."),S(null),j(!1),M()},oe=s=>{k(s),$(""),_(null)},je=async()=>{var a,w,x;if(!u)return;j(!0);try{const{data:l}=await d.functions.invoke("list-users"),r=(Array.isArray(l)?l:(l==null?void 0:l.users)||[]).find(y=>y.id===u.submitted_by),g=r==null?void 0:r.email;if(g){const y=[(a=r==null?void 0:r.user_metadata)==null?void 0:a.first_name,(w=r==null?void 0:r.user_metadata)==null?void 0:w.last_name].filter(
2Boolean).join(" ").trim()||((x=r==null?void 0:r.user_metadata)==null?void 0:x.full_name)||g;await d.from("scheduled_emails").insert({to_email:g,trigger_action:"new_course_denied",variables:{user_name:y,user_email:g,course_name:u.name,rejection_reason:Q.trim()},scheduled_at:new Date().toISOString(),status:"pending"})}}catch(l){console.error("Failed to schedule new course denied email:",l)}const{error:s}=await d.from("course_submissions").delete().eq("id",u.id);if(s){N.error("Failed to deny submission."),j(!1);return}N.success("Course submission denied and removed."),k(null),j(!1),M()},ie=ue.filter(s=>s.name.toLowerCase().includes(C.toLowerCase())||s.city.toLowerCase().includes(C.toLowerCase())||s.state.toLowerCase().includes(C.toLowerCase()));return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-card border border-border rounded-xl p-6",children:[e.jsx("h2",{className:"text-lg font-heading font-semibold text-foreground mb-4",children:"Course Approvals"}),e.jsx("p",{className:"text-sm text-muted-foreground font-body mb-6",children:"Review and approve or deny pending course submissions."}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-6",children:[e.jsx(p,{placeholder:"Search by course name, city, or state...",value:C,onChange:s=>K(s.target.value),className:"max-w-md font-body"}),e.jsx(c,{size:"sm",onClick:()=>{},children:"Search"}),e.jsx(c,{variant:"outline",size:"sm",onClick:()=>K(""),children:"Clear"}),e.jsx(c,{variant:"outline",size:"sm",onClick:M,disabled:F,children:e.jsx(ge,{className:`h-3.5 w-3.5 ${F?"animate-spin":""}`})})]}),e.jsx("div",{className:"border border-border rounded-lg overflow-hidden",children:e.jsxs(ye,{children:[e.jsx(Ne,{children:e.jsxs(V,{children:[e.jsx(f,{className:"font-body",children:"Course Name"}),e.jsx(f,{className:"font-body",children:"Address"}),e.jsx(f,{className:"font-body",children:"City"}),e.jsx(f,{className:"font-body",children:"State"}),e.jsx(f,{className:"font-body",children:"Zip"}),e.jsx(f,{className:"font-body text-center",children:"Status"}),e.jsx(f,{className:"font-body w-[100px] text-center",children:"Actions"})]})}),e.jsx(ve,{children:F?e.jsx(V,{children:e.jsx(m,{colSpan:7,className:"py-16",children:e.jsx(be,{size:"lg",label:"Loading submissions..."})})}):ie.length===0?e.jsx(V,{children:e.jsx(m,{colSpan:7,className:"text-center text-muted-foreground font-body py-12",children:"No course submissions found."})}):ie.map(s=>e.jsxs(V,{children:[e.jsx(m,{className:"font-body",children:s.name}),e.jsx(m,{className:"font-body",children:s.street_address}),e.jsx(m,{className:"font-body",children:s.city}),e.jsx(m,{className:"font-body",children:s.state}),e.jsx(m,{className:"font-body",children:s.zip_code}),e.jsx(m,{className:"text-center",children:e.jsx("span",{className:`inline-block px-2 py-0.5 rounded-full text-xs font-body font-medium ${s.status==="approved"?"bg-green-100 text-green-800":s.status==="rejected"?"bg-red-100 text-red-800":"bg-yellow-100 text-yellow-800"}`,children:s.status.charAt(0).toUpperCase()+s.status.slice(1)})}),e.jsx(m,{className:"text-center",children:e.jsxs(we,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(c,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 bg-primary hover:bg-primary/90 text-primary-foreground",children:e.jsx(_e,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",className:"w-36 font-body",children:[e.jsxs(H,{onClick:()=>_(s),className:"cursor-pointer",children:[e.jsx(Ae,{className:"h-3.5 w-3.5 mr-2 text-muted-foreground"}),"View"]}
2),s.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsxs(H,{onClick:()=>re(s),className:"cursor-pointer",children:[e.jsx(ke,{className:"h-3.5 w-3.5 mr-2 text-muted-foreground"}),"Approve"]}),e.jsxs(H,{onClick:()=>oe(s),className:"cursor-pointer text-destructive focus:text-destructive",children:[e.jsx(De,{className:"h-3.5 w-3.5 mr-2"}),"Deny"]})]})]})]})})]},s.id))})]})})]}),e.jsx(B,{open:!!n,onOpenChange:s=>!s&&_(null),children:e.jsxs(P,{className:"sm:max-w-md",children:[e.jsx(W,{children:e.jsx(G,{className:"font-heading",children:"Course Submission Details"})}),n&&e.jsxs("div",{className:"space-y-3 font-body text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"User"}),e.jsx("span",{className:"text-foreground",children:he||"â¦"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Tournament"}),e.jsx("span",{className:"text-foreground",children:pe||"â¦"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Course Name"}),e.jsx("span",{className:"text-foreground",children:n.name})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Street Address"}),e.jsx("span",{className:"text-foreground",children:n.street_address})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"City"}),e.jsx("span",{className:"text-foreground",children:n.city})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"State"}),e.jsx("span",{className:"text-foreground",children:n.state})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Zip Code"}),e.jsx("span",{className:"text-foreground",children:n.zip_code})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Submitted"}),e.jsx("span",{className:"text-foreground",children:Le(new Date(n.created_at),"MMM d, yyyy h:mm a")})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Status"}),e.jsx("span",{className:"text-foreground capitalize",children:n.status})]}),n.status==="pending"&&e.jsxs("div",{className:"flex justify-end gap-2 pt-3 border-t border-border",children:[e.jsx(c,{size:"sm",variant:"outline",onClick:()=>oe(n),className:"font-body",children:"Deny"}),e.jsx(c,{size:"sm",onClick:()=>{_(null),re(n)},className:"font-body",children:"Approve"})]})]})]})}),e.jsx(B,{open:!!v,onOpenChange:s=>!s&&S(null),children:e.jsxs(P,{className:"sm:max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(W,{children:e.jsx(G,{className:"font-heading",children:"Approve Course Submission"})}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("div",{children:[e.jsx(h,{className:"font-body text-sm",children:"Course Name *"}),e.jsx(p,{className:"font-body mt-1",value:D,onChange:s=>X(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(h,{className:"font-body text-sm",children:"Street Address *"}),e.jsx(p,{className:"font-body mt-1",value:L,onChange:s=>Y(s.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(h,{className:"font-body text-sm",children:"City *"}),e.jsx(p,{className:"font-body mt-1",value:T,onChange:s=>ee(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(h,{className:"font-body text-sm",children:"State *"}),e.jsxs(Te,{value:b,onValueChange:se,children:[e.jsx(Ee,{className:"font-body mt-1",children:e.jsx(Me,{placeholder:"Select state"})}),e.jsx(ze,{children:Fe.map(s=>e.jsx(Ie,{value:s,children:s},s))})]})]})]}),e.jsxs("div",{children:[e.jsx(h,{className:"font-body text-sm",children:"Zip Code *"}),e.jsx(p,{className:"font-body mt-1",value:E,onChange:s=>ae(s.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(h,{className:"font-body text-sm",children:"Latitude"}),e.jsx(p,{className:"font-body mt-1",type:"text",inputMode:"decimal",value:Z,onChange:s=>te(s.target.value),placeholder:"e.g. 40.7128"})]}),e.jsxs("div",{children:[e.jsx(h,{className:"font-body text-sm",children:"Longitude"}),e.jsx(p,{className:"font-body mt-1",type:"text",inputMode:"decimal",value:U,onChange:s=>ne(s.target.value),placeholder:"e.g. -74.0060"})]})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx(c,{variant:"outline",onClick:()=>S(null),className:"font-body",children:"Cancel"}),e.jsx(c,{onClick:fe,disabled:A,className:"font-body",children:A?"Approving...":"Approve Course"})]})]})]})}),e.jsx(B,{open:!!u,onOpenChange:s=>!s&&k(null),children:e.jsxs(P,{className:"sm:max-w-md",children:[e.jsx(W,{children:e.jsx(G,{className:"font-heading",children:"Deny Course Submission"})}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("p",{className:"text-sm text-muted-foreground font-body",children:["Are you sure you want to deny ",e.jsx("strong",{className:"text-foreground",children:u==null?void 0:u.name}),"?"]}),e.jsxs("div",{children:[e.jsx(h,{className:"font-body text-sm",children:"Reason for Denial"}),e.jsx(Ve,{className:"font-body mt-1",value:Q,onChange:s=>$(s.target.value),placeholder:"Enter reason for denial (optional)",rows:3})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx(c,{variant:"outline",onClick:()=>k(null),className:"font-body",children:"Cancel"}),e.jsx(c,{variant:"destructive",onClick:je,disabled:A,className:"font-body",children:A?"Denying...":"Deny Submission"})]})]})]})})]})};export{Re 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.