1import{j as e,k as p,v as k,g as y,r as v,i as z,o as I,p as T,q as P,l as O,m as A,D as E,a as L,B as c,b as U,d as V,e as q,R as F,L as h,t as C}from"./index-Bj3g7Z6n.js";import{S as H}from"./SEOMetaTags-CXUV2KLP.js";import{u as $,a as J,b as W,c as X}from"./useChallenges-DiseUZH3.js";import{h as f,u as Y}from"./useInspirationBoards-C9XRfd-_.js";import{S as G,a as K,b as Q,c as R,d as Z}from"./select-B3ESPlDy.js";import{C as D}from"./circle-x-BBQgKn7Q.js";import{T as w}from"./trophy-DTUaGO1r.js";import{U as ee}from"./users-CwEKp0xP.js";import{C as se}from"./calendar-days-CcDxg4Rg.js";import{f as S}from"./format-B7hN-bk8.js";import"./index-dP3aIPNJ.js";import"./chevron-down-B1MXwv-_.js";import"./chevron-up--nB-FXHv.js";import"./en-US-ClfMaaVW.js";import"./differenceInCalendarDays-DauCbfGV.js";import"./normalizeDates-DzYoqby6.js";const te=({board:s,minItemsRequired:i})=>{const{data:a=0}=f(s.id),r=a>=i;return e.jsxs("div",{className:"flex items-center justify-between w-full py-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium",children:s.title}),s.description&&e.jsx("div",{className:"text-xs text-muted-foreground line-clamp-1",children:s.description})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-2",children:[e.jsxs(p,{variant:r?"default":"secondary",className:"text-xs",children:[a," items"]}),r?e.jsx(k,{className:"h-4 w-4 text-green-600"}):e.jsx(D,{className:"h-4 w-4 text-red-600"})]})]})},ae=({board:s,minItemsRequired:i})=>{const{data:a=0}=f(s.id);return a<i?null:e.jsx(Z,{value:s.id,children:e.jsx(te,{board:s,minItemsRequired:i})},s.id)},ie=({boards:s,selectedBoard:i,onValueChange:a,minItemsRequired:r,disabled:d=!1})=>!s||s.length===0?e.jsxs("div",{className:"text-center py-4 text-muted-foreground",children:[e.jsx(D,{className:"h-8 w-8 mx-auto mb-2"}),e.jsx("p",{className:"text-sm",children:"No boards available"}),e.jsxs("p",{className:"text-xs",children:["Create a board with at least ",r," items first"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs(G,{value:i,onValueChange:a,disabled:d,children:[e.jsx(K,{children:e.jsx(Q,{placeholder:"Select a board to submit"})}),e.jsx(R,{children:s.map(t=>e.jsx(ae,{board:t,minItemsRequired:r},t.id))})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:e.jsxs("p",{children:["Only boards with at least ",r," items are shown."]})})]}),ve=()=>{y();const{data:s,isLoading:i}=$();if(i)return e.jsx("div",{className:"container mx-auto px-4 py-8",children:e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx("div",{className:"text-center",children:e.jsx("div",{className:"animate-pulse",children:"Loading challenges..."})})})});const a=(s==null?void 0:s.filter(t=>{const n=new Date,l=new Date(t.start_date),o=new Date(t.end_date);return l<=n&&n<=o&&t.is_active}))||[],r=(s==null?void 0:s.filter(t=>{const n=new Date;return new Date(t.start_date)>n&&t.is_active}))||[],d=(s==null?void 0:s.filter(t=>{const n=new Date;return new Date(t.end_date)<n&&t.is_active}))||[];return e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsx(H,{title:"Board Challenges - Create & Win",description:"Join our board challenges and showcase your creativity. Create inspiring boards and win amazing prizes!",noIndex:!0}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"text-4xl font-bold mb-4",children:"Board Challenges"}),e.jsx("p",{className:"text-xl text-muted-foreground",children:"Create inspiring boards and compete for amazing prizes"})]}),e.jsxs("div",{className:"space-y-8",children:[a.length>0&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx(w,{className:"h-6 w-6 text-primary"}),e.jsx("h2",{className:"text-2xl font-semibold",children:"Active Challenges"})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:a.map(t=>e.jsx(j,{challenge:t,isActive:!0},t.id))})]}),r.length>0&&e.jsxs("section",{children:[e.jsx("h2",{className:"text-2xl font-semibold mb-6",children:"Upcoming Challenges"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:r.map(t=>e.jsx(j,{challenge:t,isActive:!1},t.id))})]}),d.length>0&&e.jsxs("section",{children:[e.jsx("h2",{className:"text-2xl font-semibold mb-6",children:"Past Challenges"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:d.map(t=>e.jsx(j,{challenge:t,isActive:!1},t.id))})]}),(s==null?void 0:s.length)===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(w,{className:"h-16 w-16 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-xl font-semibold mb-2",children:"No Challenges Yet"}),e.jsx("p",{className:"text-muted-foreground",children:"Check back soon for exciting board challenges!"})]})]})]})},j=({challenge:s,isActive:i})=>{var N;const{user:a}=y(),{data:r}=J(s.id),{data:d}=W(s.id),[t,n]=v.useState(!1),[l,o]=v.useState(""),{data:_}=Y(a==null?void 0:a.id),{data:g=0}=f(l),m=X(),x=s.min_items_required||15,u=l&&g>=x,B=async()=>
1{if(!(!l||!a||!u))try{await m.mutateAsync({challengeId:s.id,boardId:l}),C.success("Board submitted successfully!"),n(!1),o("")}catch(M){console.error("Submission error:",M),C.error("Failed to submit board. Please try again.")}},b=(r==null?void 0:r.length)||0;return e.jsxs(z,{className:"h-full flex flex-col",children:[e.jsxs(I,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(p,{variant:i?"default":"secondary",children:i?"Active":"Inactive"}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[e.jsx(ee,{className:"h-4 w-4"}),b]})]}),e.jsx(T,{className:"text-xl",children:s.title}),s.description&&e.jsx(P,{children:s.description})]}),e.jsxs(O,{className:"flex-1 space-y-4",children:[s.prize_details&&e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-sm mb-1",children:"Prize"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s.prize_details})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(se,{className:"h-4 w-4"}),S(new Date(s.start_date),"MMM d")," - ",S(new Date(s.end_date),"MMM d, yyyy")]}),e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"Min. items required:"})," ",s.min_items_required||15]}),s.budget_limit&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"Budget limit:"})," £",s.budget_limit]})]}),e.jsxs(A,{className:"flex flex-col gap-2",children:[i&&a&&!d&&e.jsxs(E,{open:t,onOpenChange:n,children:[e.jsx(L,{asChild:!0,children:e.jsx(c,{className:"w-full",children:"Submit Board"})}),e.jsxs(U,{children:[e.jsxs(V,{children:[e.jsxs(q,{children:["Submit to ",s.title]}),e.jsxs(F,{children:["Select one of your boards to submit. Make sure it has at least ",s.min_items_required||15," items!"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(ie,{boards:_||[],selectedBoard:l,onValueChange:o,minItemsRequired:x,disabled:m.isPending}),l&&!u&&e.jsxs("div",{className:"p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700",children:["This board has ",g," items but needs at least ",x," items to be eligible for submission."]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{onClick:B,disabled:!u||m.isPending,className:"flex-1",children:m.isPending?"Submitting...":"Submit Board"}),e.jsx(c,{variant:"outline",onClick:()=>n(!1),children:"Cancel"})]})]})]})]}),d&&e.jsxs("div",{className:"text-center",children:[e.jsx(p,{variant:"secondary",children:"Already Submitted"}),e.jsx(h,{to:`/wishlist/${(N=d.inspiration_boards)==null?void 0:N.slug}`,className:"block mt-2",children:e.jsx(c,{variant:"outline",size:"sm",className:"w-full",children:"View Submission"})})]}),!a&&i&&e.jsx(h,{to:"/signin",children:e.jsx(c,{variant:"outline",className:"w-full",children:"Sign in to Participate"})}),b>0&&e.jsx(h,{to:`/challenges/${s.id}/submissions`,children:e.jsx(c,{variant:"outline",size:"sm",className:"w-full",children:"View Submissions"})})]})]})};export{ve 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.