1import{O as E,s as g,j as e,S as te,i as $,a as se,e as re,r as y,I as ae,B as oe,L as ie}from"./index-BY9D8-Pf.js";import{F as ne,u as le,a as de,b as ce,M as ue}from"./MemberLayout-CnENs_gX.js";import{S as me}from"./sparkles-B0mstdoD.js";import{V as he}from"./VideoCard-BWi3d0se.js";import{R as pe}from"./refresh-cw-BJuDwa4b.js";import{C as fe,a as ge}from"./card-D7FFP0kL.js";import{P as T}from"./play-DrdAHDjt.js";import{S as xe}from"./search-CF7ovopU.js";import{L as be}from"./lock-84E_hCb7.js";import"./supabase-CV4rtS2H.js";import"./collapsible-BoM0z06z.js";import"./index-D592S1_E.js";import"./send-BSNr4BA2.js";import"./folder-DvmQc-Xf.js";import"./trending-up-CZvPF79n.js";import"./credit-card-D1KD-Clg.js";import"./dialog-Dz16vSbe.js";import"./zap-Cv5mpNOE.js";import"./circle-check-big-CEJxj07w.js";import"./triangle-alert-EtXz_-5p.js";import"./AddToRoutineDialog-CWJhXJIm.js";import"./plus-tRtKOL-H.js";import"./list-plus-O02TW_1B.js";import"./clock-BmnXbIYz.js";function ye(){return E({queryKey:["daily-affirmation"],queryFn:async()=>{const{data:r,error:u}=await g.from("affirmations").select("*").eq("is_active",!0);if(u)throw u;if(!r||r.length===0)return{text:"Your practice today plants seeds for tomorrow's ease.",author:null};const d=new Date,m=new Date(d.getFullYear(),0,0),h=d.getTime()-m.getTime(),n=Math.floor(h/(1e3*60*60*24))%r.length;return r[n]},staleTime:1e3*60*60})}function je({userName:r,currentStreak:u=0}){const{data:d,isLoading:m}=ye();return e.jsxs("div",{className:"relative overflow-hidden rounded-2xl gradient-hero p-6 md:p-8 text-primary-foreground mb-8",children:[e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-white/10 rounded-full -translate-y-32 translate-x-32"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-48 h-48 bg-white/5 rounded-full translate-y-24 -translate-x-24"}),e.jsxs("div",{className:"relative z-10",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"font-heading text-2xl md:text-3xl font-bold mb-2",children:["Welcome back",r?`, ${r}`:"","!"]}),e.jsx("p",{className:"text-primary-foreground/80 mb-4",children:"Continue your somatic journey today."})]}),u>0&&e.jsxs("div",{className:"flex items-center gap-2 bg-white/20 rounded-full px-3 py-1.5",children:[e.jsx(ne,{className:"h-5 w-5 text-orange-300"}),e.jsxs("span",{className:"font-semibold",children:[u," day streak!"]})]})]}),e.jsxs("div",{className:"mt-4 p-4 bg-white/15 backdrop-blur-sm rounded-xl border border-white/20",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium mb-2 text-primary-foreground/90",children:[e.jsx(me,{className:"h-4 w-4"}),"Today's Affirmation"]}),m?e.jsx(te,{className:"h-6 w-full bg-white/20"}):e.jsxs("p",{className:"text-lg md:text-xl font-medium italic",children:['"',d==null?void 0:d.text,'"']}),(d==null?void 0:d.author)&&e.jsxs("p",{className:"text-sm text-primary-foreground/70 mt-2",children:["â ",d.author]})]})]})]})}function ve({items:r,onPlayVideo:u,onToggleFavorite:d,isFavorited:m,isInRoutine:h}){return r.length===0?null:e.jsxs("section",{id:"my-practice-section",className:"mb-10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"font-heading text-xl font-semibold flex items-center gap-2",children:[e.jsx(pe,{className:"h-5 w-5 text-primary"}),"Home: My Library"]}),e.jsx("p",{className:"text-sm text-muted-foreground hidden sm:block",children:"Pick up where you left off"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6",children:r.slice(0,3).map(i=>{var S;if(!i.videos)return null;const n=i.videos.duration_seconds?Math.round(i.progress_seconds/i.videos.duration_seconds*100):i.progress_seconds>0?10:0;return e.jsx(he,{id:i.videos.id,title:i.videos.title,description:i.videos.description,thumbnailUrl:i.videos.vimeo_thumbnail_url,durationSeconds:i.videos.duration_seconds,categoryName:((S=i.videos.video_categories)==null?void 0:S.name)||null,isFavorited:m(i.videos.id),isInRoutine:(h==null?void 0:h(i.videos.id))??!1,progressPercent:n,resumeSeconds:i.progress_seconds,onPlay:()=>u(i.videos.id,i.progress_seconds),onToggleFavorite:()=>d(i.videos.id)},i.id)})})]})}function we({title:r,slug:u,thumbnailUrl:d,videoCount:m=0,categoryName:h}){const i=$(),n=()=>{i(`/dashboard/module/${u}`)};return e.jsxs(fe,{className:"group cursor-pointer overflow-hidden transition-all hover:shadow-lg hover:scale-[1.02] border-border/50",onClick:n,children:[e.jsxs("div",{className:"relative aspect-video bg-muted overflow-hidden",children:[d?e.jsx("img",{src:d,alt:r,loading:"lazy",className:"w-full h-full object-cover transition-transform group-hover:scale-105"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center bg-gradient-to-br from-primary/20 to-primary/5",children:e.jsx(se,{className:"h-12 w-12 text-primary/50"})}),e.jsx("div",{className:"absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center",children:e.jsx("div",{className:"bg-primary text-primary-foreground rounded-full p-3",children:e.jsx(T,{className:"h-6 w-6",fill:"currentColor"})})}),m>0&&e.jsxs(re,{variant:"secondary",className:"absolute bottom-2 right-2 bg-black/75 text-white backdrop-blur-sm border-0",children:[m," ",m===1?"video":"videos"]})]}),e.jsxs(ge,{className:"p-4",children:[e.jsx("h3",{className:"font-medium text-foreground line-clamp-2 group-hover:text-primary transition-colors",children:r}),h&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:h})]})]})}function De(){var B,I;const[r,u]=y.useState(null),[d,m]=y.useState(null),[h,i]=y.useState(!0),[n,S]=y.useState(""),[H,K]=y.useState(null),N=$();y.useEffect(()=>{const{data:{subscription:t}}=g.auth.onAuthStateChange((o,l)=>{m(l),u((l==null?void 0:l.user)??null),i(!1)});return g.auth.getSession().then(({data:{session:o}})=>{m(o),u((o==null?void 0:o.user)??null),i(!1)}),()=>t.unsubscribe()},[]),y.useEffect(()=>{!h&&!r&&N("/auth")},[r,h,N]),y.useEffect(()=>{if(!r)return;(async()=>{const[o,l]=await Promise.all([g.from("subscriptions").select("status").eq("user_id",r.id).maybeSingle(),g.rpc("is_admin")]),a=o.data,c=l.data===!0;if(!a&&!c){N("/join-now");return}K((a==null?void 0:a.status)==="active")})()},[r,N]);const{data:k=[],isLoading:V}=E({queryKey:["module-pages-with-counts"],queryFn:async()=>
1{const[t,o]=await Promise.all([g.from("module_pages").select("id, title, slug, is_published, featured_image_url, folder_id, sort_order").eq("is_published",!0).order("sort_order"),g.from("module_page_sections").select("page_id, section_type, image_url")]);if(t.error)throw new Error(t.error.message);if(o.error)throw new Error(o.error.message);const l=o.data||[];return(t.data||[]).map(a=>{var L;const c=l.filter(w=>w.page_id===a.id),x=c.filter(w=>w.section_type==="video").length,v=a.featured_image_url||((L=c.find(w=>w.section_type==="image"))==null?void 0:L.image_url)||null;return{...a,videoCount:x,thumbnail:v}})},enabled:!!r}),{data:A=[]}=E({queryKey:["module-folders"],queryFn:async()=>{const{data:t,error:o}=await g.from("module_folders").select("*").order("sort_order",{ascending:!0});if(o)throw o;return t||[]},enabled:!!r}),{isFavorited:z,toggleFavorite:D}=le(r==null?void 0:r.id),{continueWatching:Q}=de(r==null?void 0:r.id),{isInRoutine:U}=ce(r==null?void 0:r.id),O=(t,o)=>{N(`/dashboard/video/${t}`)},F=y.useMemo(()=>{const o=[...k.filter(a=>!a.folder_id).map(a=>({type:"page",sort_order:a.sort_order??0,id:a.id,data:a})),...A.filter(a=>!a.parent_folder_id).map(a=>({type:"folder",sort_order:a.sort_order??0,id:a.id}))];o.sort((a,c)=>a.sort_order-c.sort_order);const l=[];for(const a of o)if(a.type==="page")l.push(a.data);else{const c=k.filter(x=>x.folder_id===a.id).sort((x,v)=>(x.sort_order??0)-(v.sort_order??0));l.push(...c)}return l},[k,A]),{data:R=[]}=E({queryKey:["search-videos-dashboard",n],queryFn:async()=>{const{data:t,error:o}=await g.rpc("search_videos",{search_query:n,max_results:12});if(o)throw o;const l=t||[];if(l.length===0)return l;const a=l.map(s=>s.id),{data:c}=await g.from("videos").select("id, vimeo_thumbnail_url, transcript").in("id",a),{data:x}=await g.from("module_page_sections").select("video_id, page_id, heading").in("video_id",a).eq("section_type","video"),v=new Map((c||[]).map(s=>[s.id,s.vimeo_thumbnail_url])),L=new Map((c||[]).map(s=>[s.id,s.transcript])),w=new Map((x||[]).filter(s=>s.heading).map(s=>[s.video_id,s.heading])),J=new Map((x||[]).map(s=>[s.video_id,s.page_id])),X=(s,p)=>{if(!s||!p)return 0;const _=s.toLowerCase(),C=p.toLowerCase().split(/\s+/).filter(f=>f.length>=3);let b=0;for(const f of C){let j=0;for(;(j=_.indexOf(f,j))!==-1;)b++,j+=f.length}return b},Z=(s,p)=>{if(!s||!p)return null;const _=s.toLowerCase(),C=p.toLowerCase().split(/\s+/).filter(M=>M.length>=3);let b=-1;for(const M of C){const q=_.indexOf(M);if(q!==-1){b=q;break}}if(b===-1)return null;const f=Math.max(0,b-50),j=Math.min(s.length,b+50),P=s.slice(f,j).trim();return`${f>0?"...":""}${P}${j<s.length?"...":""}`},Y=l.map(s=>{const p=J.get(s.id),_=p?k.find(ee=>ee.id===p):null,C=v.get(s.id)||(_==null?void 0:_.thumbnail)||null,b=n.toLowerCase(),f=w.get(s.id),j=s.title.toLowerCase().includes(b)||f&&f.toLowerCase().includes(b),P=L.get(s.id),M=X(P,n),q=j?null:Z(P,n);return{...s,thumbnail:C,transcriptSnippet:q,titleExactMatch:j,occurrences:M,displayTitle:f||s.title}});return Y.sort((s,p)=>s.titleExactMatch&&!p.titleExactMatch?-1:!s.titleExactMatch&&p.titleExactMatch?1:p.occurrences-s.occurrences),Y},enabled:!!r&&n.length>=2}),W=y.useMemo(()=>{if(!n)return F;const t=n.toLowerCase();return[...F].sort((o,l)=>{const a=o.title.toLowerCase(),c=l.title.toLowerCase(),x=a.startsWith(t)?0:a.includes(t)?1:2,v=c.startsWith(t)?0:c.includes(t)?1:2;return x-v})},[F,n]);if(h)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})});if(!r)return null;const G=((I=(B=r.user_metadata)==null?void 0:B.full_name)==null?void 0:I.split(" ")[0])||null;return e.jsxs(ue,{children:[e.jsx(je,{userName:G,currentStreak:0}),e.jsxs("div",{className:"relative mb-8",children:[e.jsx(xe,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{type:"search",placeholder:"Search modules...",value:n,onChange:t=>S(t.target.value),className:"pl-10"})]}),n.length>=2&&R.length>0&&e.jsxs("section",{className:"mb-8",children:[e.jsxs("h2",{className:"font-heading text-xl font-semibold mb-4",children:["Search Results (",R.length,")"]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6",children:R.map(t=>e.jsxs("div",{className:"group cursor-pointer rounded-xl border bg-card shadow-sm hover:shadow-lg transition-shadow overflow-hidden",onClick:()=>O(t.id),children:[e.jsxs("div",{className:"relative aspect-video bg-muted overflow-hidden",children:[t.thumbnail?e.jsx("img",{src:t.thumbnail,alt:t.title,loading:"lazy",className:"w-full h-full object-cover transition-transform group-hover:scale-105"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center bg-gradient-to-br from-primary/20 to-primary/5",children:e.jsx(T,{className:"h-12 w-12 text-primary/50"})}),e.jsx("div",{className:"absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center",children:e.jsx("div",{className:"bg-primary text-primary-foreground rounded-full p-3",children:e.jsx(T,{className:"h-6 w-6",fill:"currentColor"})})}),t.duration_seconds&&t.duration_seconds>0&&e.jsxs("div",{className:"absolute bottom-2 right-2 bg-black/70 text-white text-xs px-2 py-1 rounded",children:[Math.floor(t.duration_seconds/60),":",(t.duration_seconds%60).toString().padStart(2,"0")]})]}),e.jsxs("div",{className:"p-3",children:[e.jsx("p",{className:"font-medium text-sm line-clamp-2",children:t.displayTitle||t.title}),t.transcriptSnippet&&e.jsx("p",{className:"text-xs text-muted-foreground italic mt-1 line-clamp-2",children:t.transcriptSnippet}),t.category_name&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.category_name})]})]},t.id))})]}),n.length<2&&e.jsx(ve,{items:Q,onPlayVideo:O,onToggleFavorite:D,isFavorited:z,isInRoutine:U}),e.jsxs("section",{children:[e.jsx("h2",{className:"font-heading text-xl font-semibold mb-4",children:"All Modules"}),V?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 sm:gap-6",children:[...Array(8)].map((t,o)=>e.jsx("div",{className:"h-64 bg-muted animate-pulse rounded-xl"},o))}):W.length===0?!n&&H===!1?e.jsxs("div",{className:"text-center py-16 space-y-4",children:[e.jsx(be,{className:"h-16 w-16 mx-auto text-muted-foreground"}),e.jsx("h2",{className:"text-2xl font-bold",children:"Your Membership Has Expired"}),e.jsx("p",{className:"text-muted-foreground max-w-md mx-auto",children:"Rejoin today to unlock all modules, videos, somatic mindfulness programs, and your Heidi Hadley AI practice companion."}),e.jsx("div",{className:"flex justify-center gap-4 pt-2",children:e.jsx(oe,{asChild:!0,children:e.jsx(ie,{to:"/join-now",children:"Restart Membership"})})})]}):e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:n?"No modules found. Try adjusting your search.":"No modules available yet. Check back soon!"})}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6",children:W.map(t=>e.jsx(we,{id:t.id,title:t.title,slug:t.slug,thumbnailUrl:t.thumbnail,videoCount:t.videoCount},t.id))})]})]})}export{De as default}; 2//# sourceMappingURL=Dashboard-8XclvUvZ.js.map
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.