1import{r as n,j as e}from"./vendor-react-CjtdLP_L.js";import{b as Fe,u as ee,a as oe}from"./vendor-query-Dm6IpjeQ.js";import{a as z}from"./queryClient-CAqhRfHG.js";import{N as ss}from"./Navigation-BihYueM1.js";import{B as F}from"./button-CgHkADzY.js";import{A as Y,a as X,b as Z}from"./avatar-DYj0JdzG.js";import{B as O}from"./badge-C1_E7bcS.js";import{T as ns}from"./textarea-DFjcW1kC.js";import{I as Ve,u as vt,i as V}from"./AuthModal-XlKB8C9v.js";import{u as ke,a4 as jt,a5 as wt}from"./useAuth-BOD9I5M3.js";import{Q as Fs,ae as ve,a as Le,aR as Ls,j as Nt,r as Te,X as Ee,S as He,bO as zs,E as St,W as Ct,by as kt,M as ps,D as Re,ak as bs,b1 as ys,ab as vs,a9 as Ae,cQ as Tt,bL as Mt,_ as $t,b2 as Dt,m as It,bh as Rt,c$ as Pt,Z as Et}from"./vendor-icons-CEtKkbCp.js";import{D as At,a as Ft,b as Lt,c as zt}from"./dialog-BmoBvzwc.js";import{S as js,a as ws,b as Ns,c as Ss,d as re}from"./select-ypFJox8d.js";import{a as Ut}from"./LLMPickerContext-Dj7DD5fu.js";import{g as Us}from"./index-Bl7FDrSo.js";import{b as Kt,a as Ce,P as ze,f as Me,g as Ot}from"./index-DYd1AhEw.js";import{c as qt,a as Qt,u as Bt}from"./index-Bnm5UW7A.js";import{u as _t}from"./index-D8gd2y9N.js";import{a as W}from"./utils-09jiQjc0.js";import"./card-LCaJb0qG.js";import{a as Cs}from"./skill-attribution-B63CkjKI.js";import{b as Vt}from"./index-DpJDnEHE.js";import{C as Ht}from"./chip-BYlQls2d.js";import{f as Gt,a as ks,d as Wt,L as Ts,c as ie}from"./ledger-CR3N8AXT.js";import{a as Yt,r as Xt,S as Zt}from"./prompt-score-zynwKfto.js";import{D as Ms,a as $s,b as Ds,c as ye,d as Is}from"./dropdown-menu-YjUv8fUk.js";import{R as Rs}from"./run-in-platforms-67ql1g33.js";import{f as Jt}from"./format-display-title-B__cDUCD.js";import{g as ea}from"./platform-invocation-CU8J6FvP.js";import{a as sa}from"./useCart-DLHLpeLn.js";import{i as _e,l as Pe}from"./workspace-account-requests-DGgpqxXh.js";import{F as ta}from"./FeedbackButtons-BOKVBqd6.js";import{S as aa,p as ra}from"./refetch-policy-CrUT6q8I.js";import{I as na}from"./InstallGuideDialog-CJ4M2Lfs.js";import{S as Ps}from"./SecurityBadge-DiBKZkIi.js";import{u as ia}from"./vendor-i18n-B-dTb0jX.js";import{s as Es,f as je}from"./format-DEcNUuFA.js";import{c as Ks}from"./constructNow-DQZKXz2R.js";import{t as oa,c as la}from"./en-US-DaTnBiBt.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./auth-return-to-JRaTzEJL.js";import"./index-CaH9w3gZ.js";import"./consent-D3s5Yi52.js";import"./index-CXo7hDKg.js";import"./index-CFQO6bFv.js";import"./workspace-context-CmD3Vyun.js";import"./Logo-Dtk25poC.js";import"./BeaconMark-BfuppPGY.js";import"./app-chrome-Chb-SQcU.js";import"./beacon-access-LXtv0J6t.js";import"./index-CTrG49eW.js";import"./workspace-route-transition-Dap2JeOj.js";import"./vendor-motion-DcfotHwo.js";import"./index-DC01emjG.js";import"./WorkspacePreferences-CMsTGmr9.js";import"./vendor-react-icons-C3u-PHNU.js";import"./supabase--Raqy1d_.js";import"./index-DMBtqBCC.js";import"./index-CfHttwlL.js";import"./api-error-message-C03AM46c.js";import"./index-NncAJq6c.js";import"./SarvamIcon-De_a9IwZ.js";import"./beacon-request-Bo3SWsEZ.js";import"./tabs-DakQl-cT.js";import"./types-CGFT8RdL.js";import"./segmented-control-m_cU49-u.js";import"./index-DVJy0sr4.js";import"./security-references-CGtyBTnB.js";function ca(t,s){const a=oa(t);return isNaN(s)?la(t,NaN):(a.setDate(a.getDate()+s),a)}function Os(t,s){const a=Es(t),r=Es(s);return+a==+r}function is(t){return Os(t,Ks(t))}function da(t,s){return ca(t,-1)}function os(t){return Os(t,da(Ks(t)))}function ma({onCancel:t,onConversationCreated:s}){const{user:a}=ke(),r=Fe(),[o,d]=n.useState(null),[x,g]=n.useState(""),[b,j]=n.useState(""),[p,y]=n.useState(""),w=n.useRef(null),M=n.useRef(null);n.useEffect(()=>{const c=setTimeout(()=>{y(x)},300);return()=>clearTimeout(c)},[x]),n.useEffect(()=>{w.current?.focus()},[]),n.useEffect(()=>{o&&M.current?.focus()},[o]);const{data:$=[],isLoading:S}=ee({queryKey:["/api/users/messaging-search",p],queryFn:async()=>(await z(`/api/users/messaging-search?q=${encodeURIComponent(p)}`,"GET")).json(),enabled:p.length>=1}),{data:m=[]}=ee({queryKey:["/api/messages/recent-contacts"],queryFn:async()=>(await z("/api/messages/recent-contacts","GET")).json(),enabled:!p.trim()}),{data:f=[]}=ee({queryKey:["/api/creators"],queryFn:async()=>(await z("/api/creators","GET")).json(),enabled:!p.trim()}),C=oe({mutationFn:async({recipientId:c,content:P})=>{const U=await(await z("/api/messages/conversations","POST",{participantIds:[c]})).json();return P.trim()&&await z("/api/messages","POST",{conversationId:U.conversation.id,content:P.trim(),messageType:"text"}),U},onSuccess:c=>{r.invalidateQueries({queryKey:["/api/messages/conversations"]}),s(c.conversation.id)}}),T=c=>c.firstName&&c.lastName?`${c.firstName} ${c.lastName}`:c.username||c.firstName||c.lastName||"User",k=c=>`${c.firstName?.[0]||""}${c.lastName?.[0]||""}`.toUpperCase()||c.username?.[0]?.toUpperCase()||"?",q=()=>{o&&b.trim()&&C.mutate({recipientId:o.id,content:b.trim()})},B=c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),q())},H=(p.trim()?$:[...m||[],...f||[]]).filter((c,P,L)=>c.id!==a?.id&&L.findIndex(U=>U.id===c.id)===P);return e.jsxs("div",{className:"h-full flex flex-col bg-gradient-to-b from-orange-50/30 to-white",children:[e.jsx("div",{className:"px-6 py-4 border-b border-orange-200/50 bg-gradient-to-r from-white to-orange-50/50",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(F,{variant:"ghost",size:"sm",onClick:t,className:"h-9 w-9 p-0 rounded-full hover:bg-orange-100 text-orange-600",children:e.jsx(Fs,{className:"w-4 h-4"})}),e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:"New Message"})]}),e.jsxs("div",{className:"text-sm text-gray-500 flex items-center space-x-1",children:[e.jsx(ve,{className:"w-4 h-4"}),e.jsx("span",{children:"Start a conversation"})]})]})}),o?e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"px-6 py-4 border-b border-gray-100 bg-gradient-to-r from-white to-orange-50/30",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsxs(Y,{className:"w-10 h-10 border-2 border-orange-300",children:[e.jsx(X,{src:o.profileImageUrl}),e.jsx(Z,{className:"bg-gradient-to-br from-orange-100 to-orange-200 text-orange-700 font-semibold",children:k(o)})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("span",{className:"font-semibold text-gray-900",children:T(o)}),o.isCreator&&e.jsx(O,{variant:"secondary",className:"text-xs bg-orange-100 text-orange-700 border-orange-200",children:"Creator"}),o.isVerifiedCreator&&e.jsx("div",{className:"w-4 h-4 bg-orange-600 rounded-full flex items-center justify-center",children:e.jsx(Te,{className:"w-2 h-2 text-white"})})]}),e.jsxs("p",{className:"text-sm text-gray-600",children:["@",o.username]})]})]}),e.jsx(F,{variant:"ghost",size:"sm",onClick:()=>d(null),className:"h-8 w-8 p-0 rounded-full hover:bg-orange-100 text-gray-500",children:e.jsx(Ee,{className:"w-4 h-4"})})]})}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"flex-1 p-6",children:e.jsx(ns,{ref:M,placeholder:`Message ${T(o)}...`,value:b,onChange:c=>j(c.target.value),onKeyDown:B,rows:8,className:"w-full resize-none border-orange-200 focus:border-[var(--public-focus-color)] focu
1s:ring-[var(--public-focus-color)] text-base"})}),e.jsx("div",{className:"px-6 py-4 border-t border-gray-100 bg-white",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm text-gray-500",children:"Press Enter to send, Shift+Enter for new line"}),e.jsx(F,{onClick:q,disabled:!b.trim()||C.isPending,className:"bg-gradient-to-r from-orange-600 to-orange-700 hover:from-orange-700 hover:to-orange-800 text-white font-semibold px-6 rounded-xl shadow-lg hover:shadow-xl transition-all duration-200",children:C.isPending?e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}),e.jsx("span",{children:"Sending..."})]}):e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(He,{className:"w-4 h-4"}),e.jsx("span",{children:"Send"})]})})]})})]})]}):e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"p-6 border-b border-gray-100",children:e.jsxs("div",{className:"relative",children:[e.jsx(Le,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-gray-400"}),e.jsx(Ve,{ref:w,placeholder:"Search by name or username...",value:x,onChange:c=>g(c.target.value),className:"pl-10 h-12 text-base border-orange-200 focus:border-[var(--public-focus-color)] focus:ring-[var(--public-focus-color)] bg-white/80"})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:S?e.jsx("div",{className:"p-6 space-y-4",children:[...Array(5)].map((c,P)=>e.jsxs("div",{className:"flex items-center space-x-4 p-4 animate-pulse",children:[e.jsx("div",{className:"w-12 h-12 bg-gray-200 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"h-4 bg-gray-200 rounded w-3/4 mb-2"}),e.jsx("div",{className:"h-3 bg-gray-200 rounded w-1/2"})]})]},P))}):H.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full p-8 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-gradient-to-br from-orange-100 to-orange-200 rounded-full flex items-center justify-center mb-4",children:e.jsx(Ls,{className:"w-8 h-8 text-orange-600"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:p?"No users found":"No users available"}),e.jsx("p",{className:"text-gray-600",children:p?"Try a different search term":"Recent contacts and creators will appear here"})]}):e.jsxs("div",{className:"p-4 space-y-2",children:[!p&&m.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-600 mb-2 px-2 flex items-center",children:[e.jsx(Nt,{className:"w-4 h-4 mr-2"}),"Recent"]}),m.slice(0,3).map(c=>e.jsx(As,{user:c,onClick:()=>d(c),getUserDisplayName:T,getUserInitials:k},`recent-${c.id}`))]}),e.jsxs("div",{children:[!p&&e.jsxs("h3",{className:"text-sm font-semibold text-gray-600 mb-2 px-2 flex items-center",children:[e.jsx(ve,{className:"w-4 h-4 mr-2"}),"All Users"]}),H.map(c=>e.jsx(As,{user:c,onClick:()=>d(c),getUserDisplayName:T,getUserInitials:k},c.id))]})]})})]})]})}function As({user:t,onClick:s,getUserDisplayName:a,getUserInitials:r}){return e.jsxs("div",{onClick:s,className:"flex items-center space-x-4 p-3 rounded-xl cursor-pointer hover:bg-white hover:shadow-sm transition-all duration-200 group",children:[e.jsxs(Y,{className:"w-12 h-12 border-2 border-orange-200 group-hover:border-orange-300 transition-colors",children:[e.jsx(X,{src:t.profileImageUrl}),e.jsx(Z,{className:"bg-gradient-to-br from-orange-100 to-orange-200 text-orange-700 font-semibold",children:r(t)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("span",{className:"font-semibold text-gray-900 truncate",children:a(t)}),t.isCreator&&e.jsx(O,{variant:"secondary",className:"text-xs bg-orange-100 text-orange-700 border-orange-200",children:"Creator"}),t.isVerifiedCreator&&e.jsx("div",{className:"w-4 h-4 bg-orange-600 rounded-full flex items-center justify-center flex-shrink-0",children:e.jsx(Te,{className:"w-2 h-2 text-white"})})]}),e.jsx("div",{className:"flex items-center space-x-2 text-sm text-gray-600",children:e.jsxs("span",{className:"truncate",children:["@",t.username]})}),t.bio&&e.jsx("p",{className:"text-xs text-gray-500 truncate mt-1",children:t.bio})]})]})}function ua({onSearch:t,placeholder:s="Search prompts...",initialValue:a="",className:r="",disabled:o=!1}){const[d,x]=n.useState(a),g=n.useCallback(j=>{x(j),t(j)},[t]),b=n.useCallback(()=>{x(""),t("")},[t]);return e.jsxs("div",{className:`relative flex-1 min-w-0 ${r}`,children:[e.jsx(Le,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4 z-10"}),e.jsx(Ve,{type:"text",placeholder:s,value:d,onChange:j=>g(j.target.value),disabled:o,className:"w-full h-9 pl-10 pr-9 text-sm text-gray-100 placeholder-gray-400 bg-gray-800 border border-gray-600 rounded-lg shadow-sm transition-all duration-200 focus:border-gray-500 focus:ring-1 focus:ring-gray-500 hover:border-gray-500 disabled:opacity-50 disabled:cursor-not-allowed","data-testid":"compact-search-input"}),d&&!o&&e.jsx("button",{onClick:b,className:"absolute right-2.5 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-300 transition-colors duration-200 p-0.5 rounded-full hover:bg-gray-700","data-testid":"compact-clear-search","aria-label":"Clear search",children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})}function xa({onSortChange:t,onPriceFilter:s,sortBy:a="smart",priceFilter:r="all",showSortFilter:o=!0,showPriceFilter:d=!0,className:x="",disabled:g=!1}){const b=n.useCallback(p=>{t?.(p)},[t]),j=n.useCallback(p=>{s?.(p)},[s]);return!o&&!d?null:e.jsxs("div",{className:`flex gap-2 ${x}`,children:[o&&e.jsxs(js,{value:a,onValueChange:b,disabled:g,children:[e.jsx(ws,{className:"flex-1 h-8 text-xs bg-gray-800 border border-gray-600 rounded-md text-gray-100 hover:border-gray-500 focus:border-gray-500 focus:ring-1 focus:ring-gray-500 transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed","data-testid":"compact-sort-filter",children:e.jsx(Ns,{placeholder:"Smart"})}),e.jsxs(Ss,{className:"bg-gray-800 border border-gray-600 rounded-lg shadow-lg",children:[e.jsx(re,{value:"smart",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"Smart"}),e.jsx(re,{value:"newest",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"Newest"}),e.jsx(re,{value:"alphabetical",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"A-Z"}),e.jsx(re,{value:"rating",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"Top Rated"}),e.jsx(re,{value:"popular",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"Popular"}),e.jsx(re,{value:"price-low",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"Price: Low"}),e.jsx(re,{value:"price-high",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"Price: High"})]})]}),d&&e.jsxs(js,{value:r,onValueChange:j,disabled:g,children:[e.jsx(ws,{className:"flex-1 h-8 text-xs bg-gray-800 border border-gray-600 rounded-md text-gray-100 hover:border-gray-500 focus:border-gray-500 focus:ring-1 focus:ring-gray-500 transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed","data-testid":"compact-price-filter",children:e.jsx(Ns,{placeholder:"All"})}),e.jsxs(Ss,{className:"bg-gray-800 border border-gray-600 rounded-lg shadow-lg",children:[e.jsx(re,{value:"all",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"All"}),e.jsx(re,{value:"free",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"Free"}),e.jsx(re,{value:"premium",className:"text-gray-100 hover:bg-gray-700 focus:bg-gray-700 text-xs",children:"Premium"})]})]})]})}function ha({onSearch:t,onSortChange:s,onPriceFilter:a,placeholder:r="Search prompts...",initialValue:o="",showSortFilter:d=!0,showPriceFilter:x=!0,className:g="",disabled:b=!1}){const[j,p]=n.useState("smart"),[y,w]=n.useState("all"),M=n.useCallback(S=>{p(S),s?.(S)},[s]),$=n.useCallback(S=>{w(S),a?.(S)},[a]);return e.jsx("div",{className:`w-full ${g}`,"data-testid":"mobile-search-container",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ua,{onSearch:t,placeholder:r,initialValue:o,disabled:b}),(d||x)&&e.jsx(xa,{onSortChange:M,onPriceFilter:$,sortBy:j,priceFilter:y,showSortFilter:d,showPriceFilter:x,disabled:b})]})})}var qs=["PageUp","PageDown"],Qs=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Bs={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},$e="Slider",[ts,ga,fa]=qt($e),[_s]=Ot($e,[fa]),[pa,Ge]=_s($e),Vs=n.forwardRef((t,s)=>{const{name:a,min:r=0,max:o=100,step:d=1,orientation:x="horizontal",disabled:g=!1,minStepsBetweenThumbs:b=0,defaultValue:j=[r],value:p,onValueChange:y=()=>{},onValueCommit:w=()=>{},inverted:M=!1,form:$,...S}=t,m=n.useRef(new Set),f=n.useRef(0),T=x==="horizontal"?ba:ya,[k=[],q]=Kt({prop:p,defaultProp:j,onChange:L=>{[...m.current][f.current]?.focus(),y(L)}}),B=n.useRef(k);function J(L){const U=Sa(k,L);P(L,U)}function H(L){P(L,f.current)}function c(){const L=B.current[f.current];k[f.current]!==L&&w(k)}function P(L,U,{commit:l}={commit:!1}){const N=Ma(d),D=$a(Math.round((L-r)/d)*d+r,N),E=Us(D,[r,o]);q((A=[])=>{const K=wa(A,E,U);if(Ta(K,b*d)){f.current=K.indexOf(E);const le=String(K)!==String(A);return le&&l&&w(K),le?K:A}else return A})}return e.jsx(pa,{scope:t.__scopeSlider,name:a,disabled:g,min:r,max:o,valueIndexToChangeRef:f,thumbs:m.current,values:k,orientation:x,form:$,children:e.jsx(ts.Provider,{scope:t.__scopeSlider,children:e.jsx(ts.Slot,{scope:t.__scopeSlider,children:e.jsx(T,{"aria-disabled":g,"data-disabled":g?"":void 0,...S,ref:s,onPointerDown:Ce(S.onPointerDown,()=>{g||(B.current=k)}),min:r,max:o,inverted:M,onSlideStart:g?void 0:J,onSlideMove:g?void 0:H,onSlideEnd:g?void 0:c,onHomeKeyDown:()=>!g&&P(r,0,{commit:!0}),onEndKeyDown:()=>!g&&P(o,k.length-1,{commit:!0}),onStepKeyDown:({event:L,direction:U})=>{if(!g){const D=qs.includes(L.key)||L.shiftKey&&Qs.includes(L.key)?10:1,E=f.current,A=k[E],K=d*D*U;P(A+K,E,{commit:!0})}}})})})})});Vs.displayName=$e;var[Hs,Gs]=_s($e,{startEdge:"left",endEdge:"right",size:"width",direction:1}),ba=n.forwardRef((t,s)=>{const{min:a,max:r,dir:o,inverted:d,onSlideStart:x,onSlideMove:g,onSlideEnd:b,onStepKeyDown:j,...p}=t,[y,w]=n.useState(null),M=Me(s,T=>w(T)),$=n.useRef(void 0),S=Qt(o),m=S==="ltr",f=m&&!d||!m&&d;function C(T){const k=$.current||y.getBoundingClientRect(),q=[0,k.width],J=ls(q,f?[a,r]:[r,a]);return $.current=k,J(T-k.left)}return e.jsx(Hs,{scope:t.__scopeSlider,startEdge:f?"left":"right",endEdge:f?"right":"left",direction:f?1:-1,size:"width",children:e.jsx(Ws,{dir:S,"data-orientation":"horizontal",...p,ref:M,style:{...p.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:T=>{const k=C(T.clientX);x?.(k)},onSlideMove:T=>{const k=C(T.clientX);g?.(k)},onSlideEnd:()=>{$.current=void 0,b?.()},onStepKeyDown:T=>{const q=Bs[f?"from-left":"from-right"].includes(T.key);j?.({event:T,direction:q?-1:1})}})})}),ya=n.forwardRef((t,s)=>{const{min:a,max:r,inverted:o,onSlideStart:d,onSlideMove:x,onSlideEnd:g,onStepKeyDown:b,...j}=t,p=n.useRef(null),y=Me(s,p),w=n.useRef(void 0),M=!o;function $(S){const m=w.current||p.current.getBoundingClientRect(),f=[0,m.height],T=ls(f,M?[r,a]:[a,r]);return w.current=m,T(S-m.top)}return e.jsx(Hs,{scope:t.__scopeSlider,startEdge:M?"bottom":"top",endEdge:M?"top":"bottom",size:"height",direction:M?1:-1,children:e.jsx(Ws,{"data-orientation":"vertical",...j,ref:y,style:{...j.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:S=>{const m=$(S.clientY);d?.(m)},onSlideMove:S=>{const m=$(S.clientY);x?.(m)},onSlideEnd:()=>{w.current=void 0,g?.()},onStepKeyDown:S=>{const f=Bs[M?"from-bottom":"from-top"].includes(S.key);b?.({event:S,direction:f?-1:1})}})})}),Ws=n.forwardRef((t,s)=>{const{__scopeSlider:a,onSlideStart:r,onSlideMove:o,onSlideEnd:d,onHomeKeyDown:x,onEndKeyDown:g,onStepKeyDown:b,...j}=t,p=Ge($e,a);return e.jsx(ze.span,{...j,ref:s,onKeyDown:Ce(t.onKeyDown,y=>{y.key==="Home"?(x(y),y.preventDefault()):y.key==="End"?(g(y),y.preventDefault()):qs.concat(Qs).includes(y.key)&&(b(y),y.preventDefault())}),onPointerDown:Ce(t.onPointerDown,y=>{const w=y.target;w.setPointerCapture(y.pointerId),y.preventDefault(),p.thumbs.has(w)?w.focus():r(y)}),onPointerMove:Ce(t.onPointerMove,y=>{y.target.hasPointerCapture(y.pointerId)&&o(y)}),onPointerUp:Ce(t.onPointerUp,y=>{const w=y.target;w.hasPointerCapture(y.pointerId)&&(w.releasePointerCapture(y.pointerId),d(y))})})}),Ys="SliderTrack",Xs=n.forwardRef((t,s)=>{const{__scopeSlider:a,...r}=t,o=Ge(Ys,a);return e.jsx(ze.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:s})});Xs.displayName=Ys;var as="SliderRange",Zs=n.forwardRef((t,s)=>{const{__scopeSlider:a,...r}
1=t,o=Ge(as,a),d=Gs(as,a),x=n.useRef(null),g=Me(s,x),b=o.values.length,j=o.values.map(w=>st(w,o.min,o.max)),p=b>1?Math.min(...j):0,y=100-Math.max(...j);return e.jsx(ze.span,{"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,...r,ref:g,style:{...t.style,[d.startEdge]:p+"%",[d.endEdge]:y+"%"}})});Zs.displayName=as;var rs="SliderThumb",Js=n.forwardRef((t,s)=>{const a=ga(t.__scopeSlider),[r,o]=n.useState(null),d=Me(s,g=>o(g)),x=n.useMemo(()=>r?a().findIndex(g=>g.ref.current===r):-1,[a,r]);return e.jsx(va,{...t,ref:d,index:x})}),va=n.forwardRef((t,s)=>{const{__scopeSlider:a,index:r,name:o,...d}=t,x=Ge(rs,a),g=Gs(rs,a),[b,j]=n.useState(null),p=Me(s,C=>j(C)),y=b?x.form||!!b.closest("form"):!0,w=Bt(b),M=x.values[r],$=M===void 0?0:st(M,x.min,x.max),S=Na(r,x.values.length),m=w?.[g.size],f=m?Ca(m,$,g.direction):0;return n.useEffect(()=>{if(b)return x.thumbs.add(b),()=>{x.thumbs.delete(b)}},[b,x.thumbs]),e.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[g.startEdge]:`calc(${$}% + ${f}px)`},children:[e.jsx(ts.ItemSlot,{scope:t.__scopeSlider,children:e.jsx(ze.span,{role:"slider","aria-label":t["aria-label"]||S,"aria-valuemin":x.min,"aria-valuenow":M,"aria-valuemax":x.max,"aria-orientation":x.orientation,"data-orientation":x.orientation,"data-disabled":x.disabled?"":void 0,tabIndex:x.disabled?void 0:0,...d,ref:p,style:M===void 0?{display:"none"}:t.style,onFocus:Ce(t.onFocus,()=>{x.valueIndexToChangeRef.current=r})})}),y&&e.jsx(et,{name:o??(x.name?x.name+(x.values.length>1?"[]":""):void 0),form:x.form,value:M},r)]})});Js.displayName=rs;var ja="RadioBubbleInput",et=n.forwardRef(({__scopeSlider:t,value:s,...a},r)=>{const o=n.useRef(null),d=Me(o,r),x=_t(s);return n.useEffect(()=>{const g=o.current;if(!g)return;const b=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(b,"value").set;if(x!==s&&p){const y=new Event("input",{bubbles:!0});p.call(g,s),g.dispatchEvent(y)}},[x,s]),e.jsx(ze.input,{style:{display:"none"},...a,ref:d,defaultValue:s})});et.displayName=ja;function wa(t=[],s,a){const r=[...t];return r[a]=s,r.sort((o,d)=>o-d)}function st(t,s,a){const d=100/(a-s)*(t-s);return Us(d,[0,100])}function Na(t,s){return s>2?`Value ${t+1} of ${s}`:s===2?["Minimum","Maximum"][t]:void 0}function Sa(t,s){if(t.length===1)return 0;const a=t.map(o=>Math.abs(o-s)),r=Math.min(...a);return a.indexOf(r)}function Ca(t,s,a){const r=t/2,d=ls([0,50],[0,r]);return(r-d(s)*a)*a}function ka(t){return t.slice(0,-1).map((s,a)=>t[a+1]-s)}function Ta(t,s){if(s>0){const a=ka(t);return Math.min(...a)>=s}return!0}function ls(t,s){return a=>{if(t[0]===t[1]||s[0]===s[1])return s[0];const r=(s[1]-s[0])/(t[1]-t[0]);return s[0]+r*(a-t[0])}}function Ma(t){return(String(t).split(".")[1]||"").length}function $a(t,s){const a=Math.pow(10,s);return Math.round(t*a)/a}var tt=Vs,Da=Xs,Ia=Zs,Ra=Js;const Pa=n.forwardRef(({className:t,...s},a)=>e.jsxs(tt,{ref:a,className:W("relative flex w-full touch-none select-none items-center",t),...s,children:[e.jsx(Da,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:e.jsx(Ia,{className:"absolute h-full bg-primary"})}),e.jsx(Ra,{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-[var(--public-focus-color)] focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"})]}));Pa.displayName=tt.displayName;n.createContext(null);const Ea="z-30";n.memo(function({prompt:s,onView:a,onCopy:r,onPlay:o,onDelete:d,onCreatorClick:x,className:g="",isPurchased:b=!1,isPublished:j=!1,isSavedTile:p=!1,showCartActions:y=!0,viewMode:w="standard",tileSize:M="md",index:$=999,isNewestPrompt:S=!1,shareBadge:m,isSavedToVault:f=!1,onHide:C,shareId:T,isHidden:k=!1,isImported:q=!1,isFavorite:B=!1,onFavorite:J,folderId:H,folderName:c,onMoveToFolder:P,hasTeamsSubscription:L=!1,qualityRequestId:U}){const{t:l}=ia(),{toast:N}=vt(),D=s.generationSource==="skill"||s.generationSource==="skill_hub",E=D&&s.userId==="prompeteer-system",A=n.useMemo(()=>D?Yt(s.metadata):null,[D,s.metadata]),K=A?.verdict==="passed"?"approved":A?.verdict==="blocked"?"rejected":A?"flagged":null,le=K==="approved"?"assurance":K==="rejected"?"danger":"highlight",{addToCart:Ue,removeFromCart:ne,isInCart:we}=sa(),se=n.useRef(null),ce=we(s.id),[Ke,Oe]=n.useState(!1),[We,De]=n.useState(!1),[me,Ie]=n.useState(""),[ue,xe]=n.useState(B);n.useEffect(()=>{xe(B)},[B]);const he=n.useMemo(()=>{const u=parseFloat(s.price);return u===0?l("promptCard.free","Free"):`$${u.toFixed(2)}`},[s.price]);n.useMemo(()=>_e(s.creator)||"Anonymous",[s.creator]);const te=S,ge=n.useMemo(()=>Jt(s.title),[s.title]),i=n.useMemo(()=>{const u=s.platformId;if(!u)return null;try{return ea(u)||u}catch{return u}},[s.platformId]),h=n.useMemo(()=>Gt(Xt(s)?.value),[s]),v=ks(s.updatedAt||s.createdAt),I=ks(s.createdAt),R=Wt(s.usageCount),ae=s.category||l("promptCard.ledger.general","General"),_=i||(D?l("promptCard.skill","Skill"):l("promptCard.prompt","Prompt")),G=n.useCallback(()=>{a?.()},[a]),Ne=n.useCallback(u=>{u.stopPropagation();const Q=s.promptText||s.description||s.title||"",be=D?Cs(Q,s.metadata):Q;navigator.clipboard.writeText(be).then(()=>{jt(s.id,"prompt_drive"),Oe(!0),setTimeout(()=>Oe(!1),1500),N({title:"â
"+l("promptCard.copied"),description:"Content copied to clipboard",duration:1500})}).catch(()=>{N({variant:"destructive",title:l("promptCard.copyFailed"),description:l("promptCard.unableToCopy"),duration:2e3})}),r&&r()},[r,s.promptText,s.description,s.title,s.id,s.metadata,D,N]),{isOpen:at}=Ut(s.id),rt=n.useRef(null),[Se,qe]=n.useState(!1),[fe,Ye]=n.useState(!1),[nt,cs]=n.useState(!1),[it,Xe]=n.useState(!1),Ze=n.useRef(!1),ot=n.useCallback(()=>{fe||(Ze.current=!0,qe(!0))},[fe]),lt=n.useCallback(async()=>
1{if(d&&!fe){Ye(!0);try{await d(),qe(!1)}catch(u){console.error("Delete error:",u),N({variant:"destructive",title:l("promptCard.deleteFailed"),description:"Unable to delete. Please try again.",duration:2e3})}finally{Ye(!1)}}},[d,fe,N]),ds=n.useRef(null);n.useEffect(()=>{if(!Se)return;const u=window.setTimeout(()=>ds.current?.focus(),0);return()=>window.clearTimeout(u)},[Se]),n.useEffect(()=>{if(!Se)return;const u=Q=>{Q.key==="Escape"&&qe(!1)};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[Se]);const ct=n.useCallback(()=>{qe(!1),Ye(!1)},[]),[,dt]=Vt(),mt=n.useCallback(async u=>{const Q=Rs.find(de=>de.id===u);if(!Q)return;const be=s.promptText||s.description||"";try{be&&await navigator.clipboard.writeText(be);try{localStorage.setItem("prompeteer-last-top-app",Q.name)}catch{}wt?.(s.id,Q.id),window.open(Q.url,"_blank","noopener,noreferrer")}catch(de){N({title:"Could not open platform",description:String(de?.message||de),variant:"destructive"})}},[s.promptText,s.description,s.id,N]);n.useCallback(u=>{u.stopPropagation(),x?.()},[x]);const ut=n.useCallback(u=>{u.stopPropagation(),ce?(ne(s.id),N({title:"Removed from Cart",description:`${s.title} has been removed from your cart`})):(Ue(s),N({title:"Added to Cart",description:`${s.title} has been added to your cart`}))},[ce,s,Ue,ne,N]),xt=n.useCallback(u=>{u.stopPropagation(),cs(!0)},[]),ht=n.useCallback(u=>{u.stopPropagation();const Q=Cs(s.promptText||"",s.metadata),de=`${s.title?.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"skill"}.skill.md`,yt=new Blob([Q],{type:"text/markdown"}),fs=URL.createObjectURL(yt),es=document.createElement("a");es.href=fs,es.download=de,es.click(),URL.revokeObjectURL(fs),N({title:"Skill downloaded",description:de}),Ie(de),De(!0)},[s.promptText,s.title,s.metadata,N]),Qe=p&&L&&(m?!0:!E),Je=!!(d&&p),pe="min-h-11 cursor-pointer sm:min-h-9",gt=C||P||Qe||Je?e.jsxs(Ms,{children:[e.jsx($s,{asChild:!0,children:e.jsx(F,{variant:"ghost",size:"icon-sm",onClick:u=>u.stopPropagation(),"data-testid":`kebab-menu-${s.id}`,"aria-label":l("promptCard.moreOptions"),children:e.jsx(zs,{"aria-hidden":"true"})})}),e.jsxs(Ds,{align:"end",className:"min-w-[180px]",onClick:u=>u.stopPropagation(),onCloseAutoFocus:u=>{Ze.current&&(Ze.current=!1,u.preventDefault())},children:[C&&e.jsx(ye,{onClick:u=>{u.stopPropagation(),C()},className:pe,"data-testid":`menu-item-${k?"unhide":"hide"}-${s.id}`,children:k?e.jsxs(e.Fragment,{children:[e.jsx(St,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),l("promptCard.unhide")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),l("promptCard.hide")]})}),P&&e.jsx(ye,{onClick:u=>{u.stopPropagation(),P()},className:pe,"data-testid":`menu-item-${H?"remove-from-folder":"add-to-folder"}-${s.id}`,children:H?e.jsxs(e.Fragment,{children:[e.jsx(kt,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),l("promptCard.removeFromFolder")]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),l("promptCard.addToFolder")]})}),Qe&&m&&e.jsxs(ye,{onClick:u=>{u.stopPropagation(),Xe(!0)},className:pe,"data-testid":`menu-item-share-to-team-${s.id}`,children:[e.jsx(Re,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),l("promptCard.shareToTeam")]}),Qe&&!m&&e.jsxs(ye,{onClick:u=>{u.stopPropagation(),Xe(!0)},className:pe,"data-testid":`menu-item-share-to-team-secondary-${s.id}`,children:[e.jsx(Re,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),l("promptCard.shareToTeam")]}),Je&&e.jsxs(e.Fragment,{children:[(C||P||Qe)&&e.jsx(Is,{}),e.jsxs(ye,{onClick:u=>u.stopPropagation(),onSelect:ot,disabled:fe,className:W(pe,"text-[var(--public-danger)] focus:text-[var(--public-danger)]"),"data-testid":`button-delete-${s.id}`,"aria-label":l("promptCard.delete"),children:[e.jsx(bs,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),l("promptCard.delete")]})]})]})]}):null,ms=A?`Prompeteer Secure Scan: ${A.score??"not scored"} of 100`:"",us=A?`Prompeteer Secure Scan score ${A.score??"not scored"} of 100`:"",xs=K==="approved"?l("promptCard.scanPassed","Passed"):K==="rejected"?l("promptCard.scanBlocked","Blocked"):K==="flagged"?l("promptCard.scanFlagged","Flagged"):null,ft=A&&K?e.jsxs(O,{variant:le,size:"xs",className:"min-w-0 max-w-[64px] shrink-0","data-testid":`promptdrive-secure-scan-score-compact-${s.id}`,title:ms,"aria-label":us,children:[e.jsx(Ps,{status:K,size:"sm",showLabel:!1,variant:"icon-only"}),A.score!=null&&e.jsx("span",{className:"min-w-0 truncate",children:Math.round(A.score)})]}):null,pt=A&&K&&xs?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1","data-testid":`promptdrive-secure-scan-score-${s.id}`,title:ms,"aria-label":us,children:[e.jsx(Ps,{status:K,size:"sm",showLabel:!1,variant:"icon-only"}),e.jsxs("span",{className:"truncate",children:[xs,A.score!=null?` · ${Math.round(A.score)}`:""]})]}):null,bt=K==="approved"?"assurance":K==="rejected"?"danger":"highlight",hs=e.jsx(F,{variant:"ghost",size:"icon-sm",onClick:xt,"data-testid":"button-card-collaborate","aria-label":l("promptCard.collaborate","Collaborate"),title:l("promptCard.collaborate","Collaborate"),className:"text-[var(--public-second)] hover:text-[var(--public-second-hover)]",children:e.jsx(Re,{"aria-hidden":"true"})}),gs=e.jsx(aa,{isOpen:nt,onClose:()=>cs(!1),promptId:s.id,promptTitle:s.title,qualityRequestId:U??void 0}),Be="block min-w-0 max-w-full shrink truncate py-0 leading-5";return w==="compact"?e.jsxs("div",{ref:se,className:W(V.card,V.cardLift,V.focus,"group relative flex cursor-pointer items-start gap-3 overflow-hidden p-3",k&&"opacity-60",g),onClick:G,onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),G())},tabIndex:0,role:"button","aria-label":`View prompt: ${s.title}`,"data-testid":`compact-prompt-card-${s.id}`,children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1.5",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[D?e.jsx(O,{job:"category",size:"xs",className:Be,"data-testid":`type-chip-skill-compact-${s.id}`,children:ae}):e.jsx(O,{job:"status",size:"xs",className:Be,"data-testid":`category-badge-compact-${s.id}`,children:ae}),e.jsx("span",{className:W(V.meta,"min-w-0 shrink-[3] truncate text-[var(--public-ink-2)]"),"data-testid":`type-chip-prompt-compact-${s.id}`,title:_,children:_}),ft,m&&e.jsxs(O,{job:m.type==="team"?"status":"category",size:"xs",className:"min-w-0 shrink-0","data-testid":`share-badge-${s.id}`,children:[m.type==="team"?e.jsx(Re,{className:"h-2.5 w-2.5 shrink-0","aria-hidden":"true"}):e.jsx(ys,{className:"h-2.5 w-2.5 shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"max-w-[60px] truncate",children:m.text.replace("Shared by ","")})]}),f&&m&&e.jsx(O,{job:"verification",size:"xs","data-testid":`saved-to-vault-badge-compact-${s.id}`,title:l("promptCard.savedToVault"),children:e.jsx(vs,{className:"h-2.5 w-2.5","aria-hidden":"true"})}),te&&e.jsx(O,{job:"status",emphasis:h?"default":"strong",size:"xs","data-testid":`new-badge-compact-${s.id}`,children:l("promptCard.newBadge")}),q&&!te&&e.jsx(O,{job:"count",size:"xs","data-testid":`badge-imported-tile-compact-${s.id}`,"aria-hidden":"true",children:e.jsx(Ae,{className:"h-2.5 w-2.5","aria-hidden":"true"})})]}),e.jsx("h3",{className:W(V.h3,"line-clamp-2 text-[15px] sm:text-[15px]"),"data-testid":`title-compact-${s.id}`,title:s.title,children:ge}),e.jsxs(Ts,{variant:"inline","data-testid":`ledger-compact-${s.id}`,children:[e.jsx(ie,{label:l("promptCard.ledger.updated","Updated"),children:v}),e.jsx(ie,{label:l("promptCard.ledger.uses","Uses"),children:R}),!D&&e.jsx(ie,{label:l("promptCard.ledger.score","Score"),tone:"accent",suffix:"/100",valueProps:{"data-testid":`score-chip-compact-${s.id}`},children:h})]}),e.jsx("div",{onClick:u=>u.stopPropagation(),children:e.jsx(ta,{promptId:s.id,promptText:s.promptText||s.description,platformId:"general",qualityRequestId:U??void 0,variant:"tile",createdAt:s.createdAt})})]}),e.jsx("div",{className:"flex shrink-0 items-center",children:hs}),gs]}):e.jsxs("div",{ref:se,className:W(V.card,V.cardLift,V.focus,"group relative flex h-full cursor-pointer flex-col overflow-hidden p-4",k&&"opacity-60",Se&&Ea,g),onClick:G,onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),G())},tabIndex:0,role:"button","aria-label":`View prompt: ${s.title}`,"data-testid":`prompt-card-${s.id}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[D?e.jsx(O,{job:"category",size:"xs",className:Be,"data-testid":`type-chip-skill-${s.id}`,children:ae}):e.jsx(O,{job:"status",size:"xs",className:Be,"data-testid":`category-badge-${s.id}`,children:ae}),e.jsx("span",{className:W(V.meta,"min-w-0 shrink-[3] truncate text-[var(--public-ink-2)]"),"data-testid":`type-chip-prompt-${s.id}`,title:_,children:_})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[te&&e.jsx(O,{job:"status",emphasis:h?"default":"strong",size:"xs","data-testid":`new-badge-${s.id}`,children:l("promptCard.newBadge")}),q&&!te&&e.jsx(O,{job:"count",size:"xs","data-testid":`badge-imported-tile-${s.id}`,"aria-hidden":"true",children:e.jsx(Ae,{className:"h-2.5 w-2.5","aria-hidden":"true"})}),k&&e.jsx(O,{job:"status",size:"xs","data-testid":`hidden-badge-${s.id}`,children:l("promptCard.hidden")}),(!p||b||j)&&!D&&!m&&e.jsx(O,{job:"count",size:"xs","data-testid":`price-badge-${s.id}`,children:he}),y&&!b&&!j&&e.jsx(F,{variant:"ghost",size:"icon-sm",onClick:ut,"data-testid":`button-cart-${s.id}`,"aria-label":ce?"Removed from Cart":"Added to Cart",children:ce?e.jsx(Tt,{"aria-hidden":"true"}):e.jsx(Mt,{"aria-hidden":"true"})}
1),!at&>]})]}),m&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[e.jsxs(O,{job:m.type==="team"?"status":"category",size:"xs",className:"min-w-0","data-testid":`shared-by-badge-${s.id}`,children:[m.type==="team"?e.jsx(Re,{className:"h-2.5 w-2.5 shrink-0","aria-hidden":"true"}):e.jsx(ys,{className:"h-2.5 w-2.5 shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"max-w-[120px] truncate",children:m.text.replace("Shared by ","")})]}),f&&e.jsx(O,{job:"verification",size:"xs","data-testid":`saved-to-vault-badge-${s.id}`,title:l("promptCard.savedToVault"),children:e.jsx(vs,{className:"h-2.5 w-2.5","aria-hidden":"true"})})]}),e.jsx("h3",{className:W(V.h3,"mt-3 line-clamp-2 min-h-[2.5em] text-[16px] sm:text-[17px]"),"data-testid":`title-${s.id}`,title:s.title,children:ge}),e.jsx("div",{role:"presentation",className:W(V.rule,"mt-3")}),e.jsxs(Ts,{className:"mt-3 max-sm:grid-cols-2","data-testid":`ledger-${s.id}`,children:[e.jsx(ie,{label:l("promptCard.ledger.updated","Updated"),children:v}),e.jsx(ie,{label:l("promptCard.ledger.uses","Uses"),children:R}),D?e.jsx(ie,{label:l("promptCard.ledger.scan","Scan"),tone:bt,children:pt}):e.jsx(ie,{label:l("promptCard.ledger.score","Score"),tone:"accent",suffix:"/100",valueProps:{"data-testid":`score-chip-${s.id}`,"aria-label":h?`${h} of 100`:void 0},children:h}),D?e.jsx(ie,{label:l("promptCard.ledger.format","Format"),children:"SKILL.md"}):e.jsx(ie,{label:l("promptCard.ledger.created","Created"),children:I})]}),e.jsxs("div",{className:"mt-auto flex flex-wrap items-center justify-between gap-x-2 gap-y-1 border-t border-[var(--public-hairline)] pt-3",children:[e.jsx("div",{className:"flex min-w-0 items-center",children:c?e.jsx(Ht,{size:"sm",mono:!0,icon:e.jsx(ps,{className:"h-3.5 w-3.5","aria-hidden":"true"}),className:"max-w-full",children:c}):null}),e.jsxs("div",{className:"-mr-1.5 flex min-w-0 flex-wrap items-center justify-end sm:-mr-2",children:[e.jsx(F,{variant:"ghost",size:"icon-sm",onClick:Ne,disabled:!b&&!j&&!p,"data-testid":`button-copy-${s.id}`,"aria-label":l(Ke?"promptCard.copied":"promptCard.copy"),title:l("promptCard.copy"),children:Ke?e.jsx(Te,{className:"text-[var(--public-assurance)]","aria-hidden":"true"}):e.jsx($t,{"aria-hidden":"true"})}),hs,D?e.jsx(F,{variant:"ghost",size:"icon-sm",onClick:ht,"data-testid":`button-download-skill-${s.id}`,"aria-label":l("promptCard.download","Download"),title:l("promptCard.download","Download"),children:e.jsx(Dt,{"aria-hidden":"true"})}):e.jsxs(Ms,{children:[e.jsx($s,{asChild:!0,children:e.jsx(F,{ref:rt,variant:"ghost",size:"icon-sm",onClick:u=>u.stopPropagation(),disabled:!b&&!j&&!p,"data-testid":`button-run-in-prompt-${s.id}`,"aria-label":l("promptCard.runIn"),title:l("promptCard.runIn"),children:e.jsx(It,{"aria-hidden":"true"})})}),e.jsxs(Ds,{align:"end",className:"min-w-[200px]","data-testid":`run-in-menu-${s.id}`,onClick:u=>u.stopPropagation(),children:[Rs.map(u=>{const Q=u.Icon;return e.jsxs(ye,{"data-testid":`run-in-item-${s.id}-${u.id}`,onClick:be=>be.stopPropagation(),onSelect:()=>mt(u.id),className:pe,children:[e.jsx(Q,{className:"mr-2 h-3.5 w-3.5 shrink-0 text-[var(--public-ink-2)]","aria-hidden":"true"}),e.jsx("span",{className:"flex-1",children:u.name})]},u.id)}),e.jsx(Is,{}),e.jsx(ye,{"data-testid":`run-in-more-${s.id}`,onClick:u=>u.stopPropagation(),onSelect:()=>dt("/settings?tab=personalization"),className:W(pe,"text-[var(--public-ink-3)]"),children:l("agent.panel.runInMore","More platformsâ¦")})]})]}),J&&p&&e.jsx(F,{variant:"ghost",size:"icon-sm",onClick:u=>{u.stopPropagation(),u.preventDefault(),xe(!ue);try{J()}catch(Q){console.error("onFavorite error:",Q)}},"data-testid":`button-favorite-${s.id}`,"aria-label":l(ue?"promptCard.removeFromFavorites":"promptCard.addToFavorites"),"aria-pressed":ue,children:e.jsx(Rt,{className:W(ue&&"fill-[var(--public-ink)] text-[var(--public-ink)]"),"aria-hidden":"true"})})]})]}),Je&&Se&&e.jsxs("div",{className:"absolute inset-0 z-40 flex flex-col items-center justify-center gap-3 rounded-[var(--public-radius-surface)] bg-[var(--public-ground)] px-5 text-center",onClick:u=>{u.stopPropagation(),u.preventDefault()},role:"alertdialog","aria-modal":"true","aria-labelledby":`delete-confirm-title-${s.id}`,"aria-describedby":`delete-confirm-desc-${s.id}`,"data-testid":`delete-confirmation-overlay-${s.id}`,children:[e.jsx("span",{className:W(V.tile,"rounded-full text-[var(--public-danger)]"),children:e.jsx(bs,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("p",{id:`delete-confirm-title-${s.id}`,className:W(V.small,"text-[var(--public-ink)]"),children:l("promptCard.deleteQuestion")}),e.jsx("p",{id:`delete-confirm-desc-${s.id}`,className:V.meta,children:l("teams.cannotBeUndone")})]}),e.jsxs("div",{className:"grid w-full max-w-[240px] grid-cols-2 gap-2 pt-0.5",children:[e.jsx(F,{ref:ds,variant:"outline",size:"sm",onClick:u=>{u.stopPropagation(),u.preventDefault(),ct()},disabled:fe,"data-testid":"delete-cancel","aria-label":l("promptCard.cancel"),children:l("promptCard.cancel")}),e.jsx(F,{variant:"destructive",size:"sm",onClick:u=>{u.stopPropagation(),u.preventDefault(),lt()},loading:fe,loadingLabel:l("promptCard.delete"),"data-testid":"delete-confirm","aria-label":l("promptCard.delete"),children:l("promptCard.delete")})]})]}),gs,e.jsx(Zt,{isOpen:it,onClose:()=>Xe(!1),vaultItemId:s.id,promptTitle:s.title,promptContent:s.promptText,promptDescription:s.description,promptCategory:s.category,hasTeamsSubscription:L}),e.jsx(na,{open:We,onOpenChange:De,skillTitle:s.title,filename:me})]})},(t,s)=>{if(t.isPurchased!==s.isPurchased||t.isPublished!==s.isPublished||t.isSavedTile!==s.isSavedTile||t.showCartActions!==s.showCartActions||t.viewMode!==s.viewMode||t.tileSize!==s.tileSize||t.index!==s.index||t.isNewestPrompt!==s.isNewestPrompt||t.isSavedToVault!==s.isSavedToVault||t.isHidden!==s.isHidden||t.isImported!==s.isImported||t.className!==s.className||t.shareId!==s.shareId||t.folderId!==s.folderId||t.folderName!==s.folderName||t.hasTeam
1sSubscription!==s.hasTeamsSubscription||t.qualityRequestId!==s.qualityRequestId||t.isFavorite!==s.isFavorite)return!1;const a=t.prompt,r=s.prompt;return!(a.id!==r.id||a.title!==r.title||a.category!==r.category||a.platformId!==r.platformId||a.generationSource!==r.generationSource||a.price!==r.price||a.metadata!==r.metadata||a.promptIQAnalytics!==r.promptIQAnalytics||a.promptIQScore!==r.promptIQScore||a.usageCount!==r.usageCount||a.updatedAt!==r.updatedAt||a.createdAt!==r.createdAt)});class Aa{constructor(){this.baseUrl="/api/search",this.isInitialized=!0,console.log("ð SearchService: Enterprise server-side search initialized")}async searchMarketplace(s="",a={}){try{console.log("ð SearchService: Marketplace search via server API",{query:s,filters:a});const r=new URLSearchParams;s&&r.set("query",s.trim()),a.page!==void 0&&r.set("page",a.page.toString()),a.hitsPerPage&&r.set("hitsPerPage",a.hitsPerPage.toString()),a.category&&a.category!=="all"&&r.set("category",a.category),a.priceFilter&&a.priceFilter!=="all"&&r.set("priceFilter",a.priceFilter),a.rating&&r.set("rating",a.rating.toString()),a.tags&&a.tags.length>0&&r.set("tags",a.tags.join(",")),a.sortBy&&r.set("sortBy",a.sortBy);const o=await fetch(`${this.baseUrl}/marketplace?${r}`,{credentials:"include"});if(!o.ok)throw new Error(`Marketplace search failed: ${o.status} ${o.statusText}`);const d=await o.json();return console.log("â
SearchService: Marketplace search completed",{query:s,hits:d.totalHits||d.nbHits}),this.normalizeResponse(d)}catch(r){throw console.error("â SearchService: Marketplace search failed:",r),r}}async searchVault(s="",a={}){try{console.log("ð SearchService: Vault search via server API",{query:s,filters:a});const r=new URLSearchParams;s&&r.set("query",s.trim()),a.page!==void 0&&r.set("page",a.page.toString()),a.hitsPerPage&&r.set("hitsPerPage",a.hitsPerPage.toString()),a.category&&a.category!=="all"&&r.set("category",a.category),a.tags&&a.tags.length>0&&r.set("tags",a.tags.join(",")),a.sortBy&&r.set("sortBy",a.sortBy);const o=await fetch(`${this.baseUrl}/vault?${r}`,{credentials:"include"});if(!o.ok)throw new Error(`Vault search failed: ${o.status} ${o.statusText}`);const d=await o.json();return console.log("â
SearchService: Vault search completed",{query:s,hits:d.totalHits||d.nbHits}),this.normalizeResponse(d)}catch(r){throw console.error("â SearchService: Vault search failed:",r),r}}async searchCombined(s="",a={}){try{console.log("ð SearchService: Combined search via server API",{query:s,filters:a});const r=new URLSearchParams;s&&r.set("query",s.trim()),a.page!==void 0&&r.set("page",a.page.toString()),a.hitsPerPage&&r.set("hitsPerPage",a.hitsPerPage.toString()),a.category&&a.category!=="all"&&r.set("category",a.category),a.priceFilter&&a.priceFilter!=="all"&&r.set("priceFilter",a.priceFilter),a.rating&&r.set("rating",a.rating.toString()),a.tags&&a.tags.length>0&&r.set("tags",a.tags.join(",")),a.sortBy&&r.set("sortBy",a.sortBy);const o=await fetch(`${this.baseUrl}/combined?${r}`,{credentials:"include"});if(!o.ok)throw new Error(`Combined search failed: ${o.status} ${o.statusText}`);const d=await o.json();return console.log("â
SearchService: Combined search completed",{query:s,marketplaceHits:d.marketplace?.totalHits||d.marketplace?.nbHits,vaultHits:d.vault?.totalHits||d.vault?.nbHits}),{marketplace:this.normalizeResponse(d.marketplace),vault:this.normalizeResponse(d.vault)}}catch(r){throw console.error("â SearchService: Combined search failed:",r),r}}async search(s,a={},r="marketplace",o){return r==="private"?this.searchVault(s,a):this.searchMarketplace(s,a)}normalizeResponse(s){return{hits:s.hits||[],totalHits:s.totalHits||s.nbHits||0,totalPages:s.totalPages||s.nbPages||0,currentPage:s.currentPage||s.page||0,facets:s.facets||{},processingTimeMS:s.processingTimeMS||0}}async getAutocomplete(s,a="marketplace",r){try{const o=a==="private"?"vault":"marketplace",d=new URLSearchParams;d.set("query",s),d.set("hitsPerPage","5"),d.set("autocomplete","true");const x=await fetch(`${this.baseUrl}/${o}?${d}`,{credentials:"include"});if(!x.ok)throw new Error(`Autocomplete failed: ${x.status}`);return(await x.json()).hits?.map(b=>({title:b.title,category:b.category,objectID:b.objectID||b.id}
1))||[]}catch(o){return console.error("â SearchService: Autocomplete failed:",o),[]}}async getFacets(s="marketplace",a){try{const r=s==="private"?"vault":"marketplace",o=new URLSearchParams;o.set("facetsOnly","true");const d=await fetch(`${this.baseUrl}/${r}?${o}`,{credentials:"include"});if(!d.ok)throw new Error(`Facets failed: ${d.status}`);return(await d.json()).facets||{}}catch(r){return console.error("â SearchService: Facets failed:",r),{}}}}new Aa;function Fa(){const{user:t}=ke(),s=Fe(),a=n.useRef(null),r=n.useRef(null),o=n.useRef(null),d=n.useRef(),x=n.useRef(new Set),[g,b]=n.useState(null),[j,p]=n.useState(""),[y,w]=n.useState(""),[M,$]=n.useState(null),[S,m]=n.useState(!1),[f,C]=n.useState("newest"),[T,k]=n.useState(!1),[q,B]=n.useState({}),[J,H]=n.useState(new Set),[c,P]=n.useState(""),L=n.useCallback(async i=>{if(!x.current.has(i)){x.current.add(i);try{Promise.resolve().then(()=>{s.prefetchQuery({queryKey:["/api/messages",i,f],queryFn:async()=>await z(`/api/messages/${i}?sortBy=${f}&limit=50`,"GET"),staleTime:300*1e3})})}catch{}}},[s,f]),U=n.useCallback(i=>{b(i),w(""),P(""),i&&t?.id&&(s.setQueryData(["/api/messages/conversations"],h=>h?.conversations?{conversations:h.conversations.map(I=>I.id===i?{...I,unreadCount:0}:I)}:h),z(`/api/messages/conversations/${i}/read`,"PUT").catch(()=>{})),requestAnimationFrame(()=>{a.current&&a.current.focus()})},[t?.id,s]);n.useEffect(()=>{t&&(async()=>{try{await z("/api/messages/mark-all-read","PUT"),s.setQueryData(["/api/messages/unread-count"],{count:0}),s.setQueryData(["/api/messages/conversations"],h=>h?.conversations?{conversations:h.conversations.map(v=>({...v,unreadCount:0}))}:h),s.invalidateQueries({queryKey:["/api/messages/unread-count"]}),s.invalidateQueries({queryKey:["/api/messages/conversations"]})}catch(h){console.error("Error marking messages as read:",h)}})()},[t?.id]);const{data:l,isLoading:N,isFetching:D}=ee({queryKey:["/api/messages/conversations",y],queryFn:async()=>{const i=y?`/api/messages/conversations?search=${encodeURIComponent(y)}`:"/api/messages/conversations";return await z(i,"GET")},enabled:!!t,staleTime:y?0:120*1e3,gcTime:600*1e3,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnMount:"always",retry:1,retryDelay:100,placeholderData:i=>i,networkMode:"online"}),E=n.useMemo(()=>l?.conversations||[],[l]),A=n.useCallback((i,h)=>{w(i)},[]);n.useCallback(()=>{w("")},[]);const{data:K,isLoading:le,isFetching:Ue}=ee({queryKey:["/api/messages",g,f],queryFn:async()=>g?await z(`/api/messages/${g}?sortBy=${f}&limit=30`,"GET"):{messages:[]},enabled:!!g,staleTime:5*1e3,gcTime:600*1e3,refetchInterval:g?ra(3e3):!1,refetchOnWindowFocus:!1,refetchOnMount:!0,retry:1,retryDelay:50,placeholderData:i=>i,networkMode:"online"}),ne=n.useMemo(()=>K?.messages||[],[K]),we=oe({mutationFn:async i=>z(`/api/messages/conversations/${i}`,"DELETE"),onSuccess:()=>{s.invalidateQueries({queryKey:["/api/messages/conversations"]}),s.invalidateQueries({queryKey:["/api/messages/unread-count"]}),b(null),$(null)}}),se=oe({mutationFn:async({conversationId:i,content:h})=>z("/api/messages","POST",{conversationId:i,content:h,messageType:"text"}),onMutate:async({conversationId:i,content:h})=>{await s.cancelQueries({queryKey:["/api/messages",i,f]});const v=s.getQueryData(["/api/messages",i,f]),I={id:`temp-${Date.now()}`,conversationId:i,senderId:t?.id||"",content:h,messageType:"text",createdAt:new Date().toISOString(),isRead:!1,sender:{id:t?.id||"",username:t?.username||"",firstName:t?.firstName||"",lastName:t?.lastName||"",profileImageUrl:t?.profileImageUrl||null,isCreator:t?.isCreator||!1}};return s.setQueryData(["/api/messages",i,f],R=>({messages:[...R?.messages||[],I]})),p(""),{previousMessages:v}},onError:(i,h,v)=>{v?.previousMessages&&s.setQueryData(["/api/messages",g,f],v.previousMessages),p(h.content)},onSettled:()=>{s.invalidateQueries({queryKey:["/api/messages",g,f]}),s.invalidateQueries({queryKey:["/api/messages/conversations"]})}});oe({mutationFn:async i=>z(`/api/messages/${i}`,"DELETE"),onSuccess:()=>{s.invalidateQueries({queryKey:["/api/messages/conversations"]}),s.invalidateQueries({queryKey:["/api/messages",g,f]}
1)}}),oe({mutationFn:async i=>z(`/api/messages/conversations/${i}/read`,"PUT"),onSuccess:(i,h)=>{s.setQueryData(["/api/messages/conversations"],v=>v?.conversations?{conversations:v.conversations.map(R=>R.id===h?{...R,unreadCount:0}:R)}:v),s.invalidateQueries({queryKey:["/api/messages/unread-count"]})}}),oe({mutationFn:async({participantId:i,subject:h,content:v})=>{const R=await(await z("/api/messages/conversations","POST",{participantIds:[i]})).json();return v.trim()&&await z("/api/messages","POST",{conversationId:R.conversation.id,content:h?`Subject: ${h} 2 3${v}`:v,messageType:"text"}),{...R,isExisting:R.isExisting||!1}},onSuccess:i=>{m(!1),b(i.conversation.id),s.invalidateQueries({queryKey:["/api/messages/conversations"]}),i.isExisting&&s.invalidateQueries({queryKey:["/api/messages",i.conversation.id]})}});const ce=n.useCallback(()=>{!j.trim()||!g||se.isPending||se.mutate({conversationId:g,content:j.trim()})},[j,g,se]),Ke=n.useCallback(i=>{p(i),d.current&&clearTimeout(d.current),k(!!i.trim()),d.current=setTimeout(()=>{k(!1)},2e3)},[]),Oe=n.useCallback(i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),ce())},[ce]),We=i=>{const h=new Date(i);return is(h)?je(h,"h:mm a"):os(h)?"Yesterday":je(h,"MMM d")},De=i=>i.participants?.find(h=>h.userId!==t?.id)?.user,me=i=>i?`${i.firstName||""} ${i.lastName||""}`.trim():"",Ie=i=>{if(!i)return"?";const h=i.firstName?.charAt(0)||"",v=i.lastName?.charAt(0)||"";return`${h}${v}`||i.email?.charAt(0)||"?"},ue=n.useCallback(i=>l?.conversations?l.conversations.find(h=>h.participants?.find(I=>I.userId!==t?.id)?.userId===i):null,[l?.conversations,t]);n.useCallback(async(i,h)=>{const v=ue(i);if(v)return b(v.id),v.id;try{const R=await(await z("/api/messages/conversations","POST",{participantIds:[i]})).json();return h&&h.trim()&&await z("/api/messages","POST",{conversationId:R.conversation.id,content:h.trim(),messageType:"text"}),b(R.conversation.id),s.invalidateQueries({queryKey:["/api/messages/conversations"]}),R.conversation.id}catch(I){return console.error("Error starting conversation:",I),null}},[ue,s]);const xe=E?.find(i=>i.id===g),he=xe?De(xe):null,te=E||[],ge=n.useMemo(()=>(ne||[]).filter(h=>!c||c.trim()===""?!0:h.content.toLowerCase().includes(c.toLowerCase())).sort((h,v)=>{const I=new Date(h.createdAt).getTime(),R=new Date(v.createdAt).getTime();return I-R}),[ne,c]);return n.useEffect(()=>{if(E&&E.length>0&&!g){const i=[...E].sort((h,v)=>{const I=h.lastMessage?.createdAt||h.updatedAt,R=v.lastMessage?.createdAt||v.updatedAt;return new Date(R).getTime()-new Date(I).getTime()});b(i[0].id)}},[E,g]),n.useEffect(()=>{if(ne.length>0&&r.current){const i=ne[ne.length-1];i.id!==o.current&&(r.current.scrollIntoView({behavior:"smooth"}),o.current=i.id)}},[ne]),n.useEffect(()=>{g&&(P(""),a.current&&setTimeout(()=>{a.current?.focus()},100))},[g]),t?e.jsxs("div",{className:"min-h-screen bg-[var(--public-ground)]",children:[e.jsx(ss,{}),e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[e.jsx("div",{className:"bg-white rounded-2xl shadow-xl overflow-hidden border border-gray-200",style:{height:"calc(100vh - 12rem)"},children:e.jsxs("div",{className:"flex h-full",children:[e.jsxs("div",{className:"w-96 border-r border-[var(--public-hairline)] flex flex-col bg-[var(--public-ground)]",children:[e.jsxs("div",{className:"px-8 py-6 bg-white border-b border-gray-200 shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Messages"}),e.jsx(F,{onClick:()=>m(!0),variant:"ghost",size:"sm",className:"rounded-full p-3 transition-all duration-200 hover:scale-105",children:e.jsx(Ae,{className:"w-6 h-6"})})]}),e.jsx(ha,{onSearch:A,placeholder:"Search conversations...",initialValue:y,showSortFilter:!1,showPriceFilter:!1,className:"w-full"}),y&&e.jsx("div",{className:"mt-3 px-3 py-2 bg-blue-50 border border-blue-200 rounded-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Le,{className:"w-4 h-4 text-blue-600"}),e.jsx("span",{className:"text-sm font-medium text-blue-800",children:D?"Searching...":te.length===0?"N
3o results found":`${te.length} result${te.length===1?"":"s"} for "${y}"`})]}),D&&e.jsx("div",{className:"w-4 h-4 border-2 border-blue-300 border-t-blue-600 rounded-full animate-spin"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-3",children:N?e.jsx("div",{className:"space-y-3 py-4",children:[...Array(6)].map((i,h)=>e.jsxs("div",{className:"flex items-center space-x-4 p-4 rounded-xl animate-pulse bg-white/50",children:[e.jsx("div",{className:"w-14 h-14 bg-gray-300 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"h-5 bg-gray-300 rounded-lg w-3/4 mb-2"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded-lg w-1/2"})]})]},h))}):te.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center p-8",children:[e.jsx("div",{className:"w-20 h-20 bg-gradient-to-br from-orange-100 to-orange-200 rounded-full flex items-center justify-center mb-6 shadow-lg",children:e.jsx(ve,{className:"w-10 h-10 text-orange-600"})}),e.jsx("h3",{className:"text-xl font-semibold text-gray-900 mb-3",children:"No Conversations Yet"}),e.jsx("p",{className:"text-gray-600 text-base mb-6 leading-relaxed",children:"Start a conversation with a creator to see it here."}),e.jsxs(F,{onClick:()=>m(!0),size:"lg",children:[e.jsx(Ae,{className:"w-5 h-5 mr-2"}),"New Message"]})]}):e.jsx("div",{className:"py-3",children:te.map(i=>{const h=De(i),v=g===i.id;return e.jsxs("div",{onClick:()=>U(i.id),onMouseEnter:()=>L(i.id),className:`conversation-item flex items-center px-5 py-4 mx-2 mb-2 rounded-xl cursor-pointer relative message-enter ${v?"bg-gradient-to-r from-orange-100 to-orange-50 border-2 border-orange-300 shadow-lg":i.unreadCount>0?"hover:bg-white hover:shadow-md bg-orange-50/80 border-l-4 border-orange-400":"hover:bg-white hover:shadow-md bg-white/60"}`,children:[i.unreadCount>0&&!v&&e.jsx("div",{className:"absolute left-0 top-1/2 transform -translate-y-1/2 w-1 h-8 bg-orange-500 rounded-r-full"}),e.jsxs(Y,{className:"w-14 h-14 border-3 border-white shadow-lg ring-2 ring-orange-100",children:[e.jsx(X,{src:h?.profileImageUrl||void 0,alt:me(h)}),e.jsx(Z,{className:"bg-gradient-to-br from-orange-200 to-orange-300 text-orange-800 font-semibold text-lg",children:Ie(h)})]}),e.jsxs("div",{className:"ml-4 flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:`flex items-center gap-2 text-base font-semibold truncate ${v?"text-orange-900":"text-gray-900"}`,children:[e.jsx("span",{children:me(h)}),h?.isCreator&&e.jsx(O,{variant:"secondary",className:"text-xs bg-gradient-to-r from-orange-50 to-orange-100 text-orange-700 border-orange-200 font-medium",children:"Creator"})]}),e.jsx("p",{className:`text-xs ${v?"text-orange-600":"text-gray-500"}`,children:i.lastMessage&&We(i.lastMessage.createdAt)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-col space-y-1 min-w-0 flex-1",children:[e.jsx("p",{className:`text-sm truncate ${v?"text-orange-700":"text-gray-600"}`,children:i.lastMessage?.content||"No messages yet"}),e.jsx("div",{className:`text-xs ${v?"text-orange-600":"text-gray-500"} flex items-center gap-1`,children:(()=>{const I=i.participants.find(R=>R.user.id!==t?.id);if(I){const R=new Date(I.user.lastActiveAt),_=Math.floor((new Date().getTime()-R.getTime())/(1e3*60));if(_<5)return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-green-500"}),e.jsx("span",{children:"Active now"})]});if(_<60)return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-yellow-500"}),e.jsxs("span",{children:["Active ",_,"m ago"]})]});if(_<1440){const G=Math.floor(_/60);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-gray-400"}),e.jsxs("span",{children:["Active ",G,"h ago"]})]})}else{const G=Math.floor(_/1440);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-gray-400"}),e.jsxs("span",{children:["Active ",G,"d ago"]})]})}}return"No activity data"})()})]}),i.unreadCount>0&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx("div",{className:"w-6 h-6 bg-gradient-to-r from-orange-500 to-red-500 rounded-full flex items-center justify-center shadow-lg animate-pulse",children:e.jsx("span",{className:"text-xs font-bold text-white",children:i.unreadCount>9?"9+":i.unreadCount})})})]})]})]},i.id)})})})]}),e.jsx("div",{className:"flex-1 flex flex-col bg-gradient-to-b from-gray-50 to-white",children:S?e.jsx(ma,{onCancel:()=>m(!1),onConversationCreated:i=>{m(!1),b(i)}}):g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-8 py-6 border-b border-gray-200 bg-gradient-to-r from-white to-orange-50 shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsxs(Y,{className:"w-16 h-16 border-3 border-orange-400 shadow-xl",children:[e.jsx(X,{src:he?.profileImageUrl||void 0,alt:me(he)}),e.jsx(Z,{className:"bg-gradient-to-br from-orange-200 to-orange-300 text-orange-900 font-bold text-xl",children:Ie(he)})]}),e.jsxs("div",{className:"ml-4",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900",children:me(he)}),he?.isCreator&&e.jsx("p",{className:"text-lg text-orange-600 font-semibold",children:"Creator"})]})]}),e.jsx("div",{className:"flex items-center space-x-2"})]}),e.jsx("div",{className:"flex items-center space-x-4",children:c&&e.jsx(F,{variant:"ghost",size:"sm",onClick:()=>P(""),className:"text-gray-400 hover:text-gray-600",children:e.jsx(Ee,{className:"w-4 h-4"})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4",children:le?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((i,h)=>e.jsxs("div",{className:"flex space-x-2 animate-pulse",children:[e.jsx("div",{className:"w-8 h-8 bg-gray-200 rounded-full"}),e.jsx("div",{className:"flex-1",children:e.jsx("div",{className:"h-10 bg-gray-200 rounded-lg w-3/4"})})]},h))}):ge.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[e.jsx(ve,{className:"w-12 h-12 text-gray-300 mb-4"}),e.jsx("p",{className:"text-gray-500",children:c?"No messages found matching your search.":"No messages yet. Send the first message!"}),c&&e.jsx(F,{variant:"ghost",size:"sm",onClick:()=>P(""),className:"mt-2 text-orange-600",children:"Clear search"})]}):e.jsx("div",{className:"space-y-1",children:ge.map((i,h)=>{const v=i.senderId===t?.id,I=ge[h-1],R=ge[h+1],ae=!R||R.senderId!==i.senderId,_=!I||I.senderId!==i.senderId,G=_,Ne=ae;return e.jsx("div",{className:`flex ${v?"justify-end":"justify-start"} px-4 ${G?"mt-4":"mt-0.5"}`,children:e.jsxs("div",{className:`flex items-end space-x-2 max-w-lg ${v?"flex-row-reverse space-x-reverse":""}`,children:[!v&&e.jsx("div",{className:"w-8 h-8 flex-shrink-0",children:ae?e.jsxs(Y,{className:"w-8 h-8 border-2 border-white shadow-sm",children:[e.jsx(X,{src:i.sender.profileImageUrl||void 0}),e.jsx(Z,{className:"bg-gray-100 text-gray-600 text-xs",children:Ie(i.sender)})]}):e.jsx("div",{className:"w-8 h-8"})}),e.jsxs("div",{className:`relative ${v?"mr-4":"ml-1"}`,children:[_&&!v&&e.jsxs("div",{className:"text-xs text-gray-500 mb-1 ml-4",children:[me(i.sender),i.sender.isCreator&&e.jsx(O,{variant:"secondary",className:"ml-2 text-xs bg-orange-100 text-orange-700 border-orange-200",children:"Creator"})]}),e.jsx("div",{className:`message-bubble px-4 py-2.5 rounded-2xl max-w-sm break-words shadow-sm ${v?"bg-gradient-to-r from-orange-500 to-orange-600 text-white rounded-br-md":"bg-gray-100 text-gray-900 rounded-bl-md border border-gray-200"} ${G&&!Ne?v?"rounded-br-2xl":"rounded-bl-2xl":""} ${!G&&Ne?v?"rounded-br-md":"rounded-bl-md":""} ${!G&&!Ne?v?"rounded-br-2xl":"rounded-bl-2xl":""}`,children:e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap",children:i.content})}),Ne&&e.jsxs("div",{className:`text-xs text-gray-500 mt-1 ${v?"text-right mr-1":"text-left ml-1"}`,children:[je(new Date(i.createdAt),"h:mm a"),v&&e.jsx("span",{className:"ml-1",children:i.isRead?e.jsx(Pt,{className:"inline w-3 h-3 text-blue-500"}):e.jsx(Te,{className:"inline w-3 h-3 text-gray-400"})})]})]})]})},i.id)})})}),e.jsxs("div",{className:"px-8 py-6 border-t border-gray-200 bg-gradient-to-r from-white to-orange-50 shadow-lg",children:[T&&e.jsxs("div",{className:"mb-3 flex items-center space-x-2 text-sm text-gray-600 animate-pulse",children:[e.jsxs("div",{className:"flex space-x-1",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-gray-500 rounded-full animate-bounce"}),e.jsx("div",{className:"w-1.5 h-1.5 bg-gray-500 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),e.jsx("div",{className:"w-1.5 h-1.5 bg-gray-500 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]}),e.jsx("span",{className:"font-medium",children:"You are typing..."})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(ns,{ref:a,value:j,onChange:i=>Ke(i.target.value),placeholder:"Type a message... (Press Enter to send, Shift+Enter for new line)",rows:1,className:"resize-none pr-20 rounded-2xl border-2 border-gray-300 focus:border-[var(--public-focus-color)] focu
3s:ring-[var(--public-focus-color)] bg-gray-50 hover:bg-white transition-all duration-200 text-lg px-6 py-4 placeholder-gray-400 shadow-sm focus:shadow-lg",onKeyDown:Oe,disabled:se.isPending}),e.jsx(F,{onClick:ce,disabled:!j.trim()||se.isPending,size:"sm",className:"absolute right-3 top-1/2 -translate-y-1/2 rounded-full w-12 h-12 p-0",children:se.isPending?e.jsx("div",{className:"w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin"}):e.jsx(He,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex items-center space-x-2",children:Ue&&e.jsxs("div",{className:"flex items-center text-orange-600",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-orange-600 border-t-transparent rounded-full animate-spin mr-2"}),e.jsx("span",{className:"text-sm font-medium",children:"Syncing..."})]})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-xs text-gray-500",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx("span",{children:"Press Enter to send ⢠Shift+Enter for new line"}),xe&&(()=>{const i=xe.participants.find(h=>h.user.id!==t?.id);if(i){const h=new Date(i.user.lastActiveAt),I=Math.floor((new Date().getTime()-h.getTime())/(1e3*60));let R="";return I<5?R="Active now":I<60?R=`Active ${I}m ago`:I<1440?R=`Active ${Math.floor(I/60)}h ago`:R=`Active ${Math.floor(I/1440)}d ago`,e.jsxs("span",{className:"flex items-center space-x-1",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${I<5?"bg-green-500":I<30?"bg-yellow-500":"bg-gray-400"}`}),e.jsx("span",{children:R})]})}return null})()]}),se.isPending&&e.jsxs("div",{className:"flex items-center space-x-2 text-orange-600",children:[e.jsx(Et,{className:"w-3 h-3"}),e.jsx("span",{className:"font-medium",children:"Sending..."})]})]})]}),e.jsx("div",{ref:r})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center bg-gradient-to-b from-orange-50 to-white",children:[e.jsx("div",{className:"w-24 h-24 bg-gradient-to-br from-orange-200 to-orange-300 rounded-full flex items-center justify-center mb-8 shadow-lg",children:e.jsx(ve,{className:"w-12 h-12 text-orange-700"})}),e.jsx("h2",{className:"text-3xl font-bold text-gray-900 mb-6",children:"Select a Conversation"}),e.jsx("p",{className:"text-gray-700 max-w-md text-lg leading-relaxed",children:"Choose a conversation from the sidebar to start messaging with creators."})]})})]})}),e.jsx(At,{open:M!==null,onOpenChange:()=>$(null),children:e.jsxs(Ft,{className:"sm:max-w-md",children:[e.jsx(Lt,{children:e.jsx(zt,{children:"Delete Conversation"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-gray-600",children:"Are you sure you want to delete this conversation? This action cannot be undone and will remove all messages in this conversation."}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx(F,{variant:"outline",onClick:()=>$(null),disabled:we.isPending,children:"Cancel"}),e.jsx(F,{variant:"destructive",onClick:()=>{M&&we.mutate(M)},disabled:we.isPending,children:we.isPending?"Deleting...":"Delete"})]})]})]})})]})]}):e.jsxs("div",{className:"min-h-screen bg-[var(--public-ground)]",children:[e.jsx(ss,{}),e.jsx("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-16",children:e.jsxs("div",{className:"text-center bg-white rounded-2xl shadow-lg p-12",children:[e.jsx(ve,{className:"w-16 h-16 text-gray-300 mx-auto mb-4"}),e.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-2",children:"Sign In Required"}),e.jsx("p",{className:"text-gray-600",children:"Please sign in to access your messages."}),e.jsx(F,{asChild:!0,className:"mt-6",children:e.jsx("a",{href:"/login",children:"Sign In"})})]})})]})}function La({onSelectConversation:t,onNewMessage:s}){const{user:a}=ke(),[r,o]=n.useState(""),[d,x]=n.useState(null),{data:g,isLoading:b}=ee({queryKey:["/api/conversations"],queryFn:async()=>{const m=await fetch("/api/messages/conversations",{headers:{"Cache-Control":"no-cache"}});if(!m.ok)throw new Error("Failed to fetch conversations");return m.json()},refetchInterval:800,refetchOnWindowFocus:!0,staleTime:500,gcTime:5e3,refetchIntervalInBackgroun
3d:!0}),p=(g?.conversations||[]||[]).filter(m=>{if(!r.trim())return!0;const f=m.participants?.find(k=>k.userId!==a?.id)?.user,C=_e(f).toLowerCase(),T=m.lastMessage?.content?.toLowerCase()||"";return C.includes(r.toLowerCase())||T.includes(r.toLowerCase())}),y=m=>{try{const f=new Date(m);return isNaN(f.getTime())?"":is(f)?je(f,"h:mm a"):os(f)?"Yesterday":je(f,"MMM d")}catch{return""}},w=m=>{x(m),setTimeout(()=>{t(m)},50)},M=(m,f=42)=>m.length<=f?m:m.substring(0,f)+"...",$=m=>{if(!m)return"offline";const f=new Date(m),T=(new Date().getTime()-f.getTime())/(1e3*60);return T<5?"online":T<30?"away":"offline"},S=({status:m,isCreator:f})=>{const C=()=>{switch(m){case"online":return f?"bg-green-500":"bg-blue-500";case"away":return"bg-yellow-500";default:return"bg-gray-400"}};return e.jsx("div",{className:`w-3 h-3 rounded-full ${C()} ring-2 ring-white absolute -bottom-0.5 -right-0.5`})};return e.jsxs("div",{className:"flex flex-col h-full bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-white border-b border-gray-100",children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900",children:"Messages"}),e.jsx(F,{onClick:s,className:"h-9 w-9 rounded-full bg-blue-500 hover:bg-blue-600 shadow-md transition-all hover:scale-105 active:scale-95",children:e.jsx(Ae,{className:"w-4 h-4 text-white"})})]}),e.jsx("div",{className:"px-3 py-2 bg-[var(--public-ground)] border-b border-[var(--public-hairline)]",children:e.jsxs("div",{className:"relative",children:[e.jsx(Le,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-[var(--public-ink-3)]"}),e.jsx(Ve,{type:"text",placeholder:"Search conversations...",value:r,onChange:m=>o(m.target.value),className:"pl-10 h-8 bg-[var(--public-ground)] border-[var(--public-hairline)] rounded-full text-sm"})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:b?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"text-gray-500 text-sm",children:"Loading conversations..."})}):p.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 px-4",children:[e.jsx(ve,{className:"w-12 h-12 text-gray-300 mb-3"}),e.jsxs("div",{className:"text-gray-500 text-center",children:[e.jsx("p",{className:"font-medium text-sm",children:"No conversations yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Start a new conversation"})]})]}):e.jsx("div",{className:"divide-y divide-gray-50",children:p.map(m=>{const f=m.participants?.find(q=>q.userId!==a?.id)?.user;if(!f)return null;const C=m.lastMessage,T=m.unreadCount>0,k=$(f.lastActiveAt);return e.jsxs("button",{onClick:()=>w(m.id),className:`w-full px-4 py-3 flex items-center gap-3 transition-all duration-150 text-left touch-manipulation transform ${d===m.id?"bg-blue-50 border-r-2 border-blue-500 scale-[0.98]":"hover:bg-gray-50 active:bg-gray-100 active:scale-[0.98]"}`,children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsxs(Y,{className:"h-12 w-12",children:[e.jsx(X,{src:f.profileImageUrl||void 0}),e.jsx(Z,{className:"text-sm font-semibold bg-gradient-to-br from-blue-100 to-green-100 text-gray-700",children:Pe(f)})]}),e.jsx(S,{status:k,isCreator:f.isCreator})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:`font-semibold text-sm truncate ${T?"text-gray-900":"text-gray-700"}`,children:_e(f)}),f.isCreator&&e.jsx(O,{variant:"secondary",className:"text-xs bg-green-100 text-green-700 border-0 rounded-full px-1.5 py-0",children:"Creator"})]}),e.jsx("span",{className:"text-xs text-gray-500 flex-shrink-0",children:C&&y(C.createdAt)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:`text-sm truncate flex-1 ${T?"font-medium text-gray-900":"text-gray-500"}`,children:C?C.senderId===a?.id?e.jsxs("span",{className:"text-blue-600",children:["You: ",M(C.content)]}):M(C.content):"No messages yet"}),T&&e.jsx("div",{className:"bg-blue-500 text-white text-xs rounded-full h-5 w-5 flex items-center justify-center ml-2 flex-shrink-0",children:m.unreadCount>99?"99+":m.unreadCount})]})]})]},m.id)})})})]})}function za({user:t}){return e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2 animate-in fade-in duration-300",children:[e.jsxs(Y,{className:"h-8 w-8 mt-1",children:[e.jsx(X,{src:t.profileImageUrl||void 0}),e.jsx(Z,{className:"text-xs font-semibold bg-gradient-to-br from-blue-100 to-green-100 text-gray-700",children:Pe(t)})]}),e.jsx("div",{className:"bg-gray-100 rounded-2xl rounded-bl-md px-4 py-3 max-w-[240px] shadow-sm",children:e.jsx("div",{className:"flex items-center gap-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})})})]})}function Ua({conversationId:t,onBack:s}){const{user:a}=ke(),[r,o]=n.useState(""),[d,x]=n.useState(!1),[g,b]=n.useState(!1),j=n.useRef(null),p=n.useRef(null),y=n.useRef(null),w=Fe(),{data:M,isLoading:$}=ee({queryKey:["/api/conversations",t],queryFn:async()=>(await z(`/api/messages/conversations/${t}`,"GET")).json(),enabled:!!t,staleTime:6e4,gcTime:12e4,refetchOnWindowFocus:!1}),{data:S,isLoading:m,error:f}=ee({queryKey:["/api/messages",t],queryFn:async()=>(await z(`/api/messages/${t}?limit=50`,"GET")).json(),enabled:!!t,refetchInterval:500,staleTime:200,gcTime:2e3,refetchOnWindowFocus:!0,refetchOnMount:!0}
3),C=S?.messages||[],T=oe({mutationFn:async l=>{const D={id:`temp-${Date.now()}`,content:l,senderId:a?.id||"",conversationId:t,createdAt:new Date().toISOString(),sender:a||{id:"",firstName:"",lastName:"",username:""},messageType:"text"};return w.setQueryData(["/api/messages",t],A=>A?{...A,messages:[...A.messages||[],D]}:{messages:[D]}),o(""),B(),(await z("/api/messages","POST",{conversationId:t,content:l,messageType:"text"})).json()},onSuccess:l=>{w.setQueryData(["/api/messages",t],N=>{if(!N)return{messages:[l]};const D=N.messages.filter(E=>!E.id.startsWith("temp-"));return{...N,messages:[...D,l]}}),w.invalidateQueries({queryKey:["/api/conversations"]}),x(!1),j.current&&clearTimeout(j.current)},onError:()=>{w.invalidateQueries({queryKey:["/api/messages",t]})}}),k=()=>{r.trim()&&T.mutate(r.trim())},q=()=>{p.current?.scrollIntoView({behavior:"smooth"})},B=()=>{p.current?.scrollIntoView({behavior:"instant"})},J=l=>{o(l.target.value),y.current&&(y.current.style.height="auto",y.current.style.height=`${Math.min(y.current.scrollHeight,120)}px`),l.target.value.trim()&&!d&&x(!0),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{x(!1)},2e3)},H=l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),k())};n.useEffect(()=>{q()},[C]),n.useEffect(()=>{C.length>0&&setTimeout(()=>q(),100)},[t]);const c=M?.participants?.find(l=>l.userId!==a?.id)?.user||null,P=l=>{try{const N=new Date(l);return isNaN(N.getTime())?"Now":is(N)?je(N,"h:mm a"):os(N)?"Yesterday":je(N,"MMM d")}catch{return"Now"}},L=l=>{if(!l)return"bg-gray-400";try{const N=new Date(l);if(isNaN(N.getTime()))return"bg-gray-400";const E=(new Date().getTime()-N.getTime())/(1e3*60);return E<5?c?.isCreator?"bg-green-500":"bg-blue-500":E<30?"bg-yellow-500":"bg-gray-400"}catch{return"bg-gray-400"}},U=l=>{if(!l)return"Last seen long ago";try{const N=new Date(l);if(isNaN(N.getTime()))return"Last seen long ago";const E=(new Date().getTime()-N.getTime())/(1e3*60);return E<1?"Active now":E<5?"Online":E<30?"Away":E<60?`Last seen ${Math.floor(E)} minutes ago`:E<1440?`Last seen ${Math.floor(E/60)} hours ago`:`Last seen ${Math.floor(E/1440)} days ago`}catch{return"Last seen long ago"}};return $||!M?e.jsxs("div",{className:"h-screen bg-white flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-white border-b border-gray-200",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-gray-200 rounded-full animate-pulse"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 bg-gray-200 rounded-full animate-pulse"}),e.jsxs("div",{children:[e.jsx("div",{className:"w-20 h-4 bg-gray-200 rounded animate-pulse mb-1"}),e.jsx("div",{className:"w-16 h-3 bg-gray-200 rounded animate-pulse"})]})]})]}),e.jsx("div",{className:"w-6 h-6 bg-gray-200 rounded animate-pulse"})]}),e.jsx("div",{className:"flex-1 p-4 space-y-3 overflow-hidden",children:[1,2,3,4,5].map(l=>e.jsxs("div",{className:`flex ${l%2===0?"justify-end":"justify-start"}`,children:[l%2!==0&&e.jsx("div",{className:"w-7 h-7 bg-gray-200 rounded-full mr-2 animate-pulse"}),e.jsx("div",{className:"max-w-xs",children:e.jsx("div",{className:`h-10 bg-gray-200 rounded-2xl animate-pulse ${l%2===0?"rounded-br-md":"rounded-bl-md"}`})})]},l))}),e.jsx("div",{className:"p-4 border-t border-gray-200",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 h-9 bg-gray-200 rounded-full animate-pulse"}),e.jsx("div",{className:"w-9 h-9 bg-gray-200 rounded-full animate-pulse"})]})})]}):e.jsxs("div",{className:"flex flex-col h-full bg-gray-50 animate-in slide-in-from-right-4 duration-200",children:[e.jsxs("div",{className:"bg-white/95 backdrop-blur-md border-b border-gray-200/50 px-3 py-2.5 flex items-center justify-between shadow-sm animate-in slide-in-from-top-2 duration-300 delay-75",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{variant:"ghost",size:"sm",onClick:s,className:"h-9 w-9 p-0 hover:bg-gray-100 rounded-full transition-colors",children:e.jsx(Fs,{className:"w-5 h-5 text-gray-700"})}),c&&e.jsxs(e.Fragment,{children:[e.jsxs(Y,{className:"h-11 w-11 ring-2 ring-white shadow-sm",children:[e.jsx(X,{src:c.profileImageUrl||void 0}),e.jsx(Z,{className:"text-sm font-semibold bg-gradient-to-br from-blue-100 to-green-100 text-gray-700",children:Pe(c)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"font-semibold text-gray-900 truncate text-[16px] leading-tight",children:_e(c)}),c.isCreator&&e.jsx(O,{variant:"secondary",className:"text-xs bg-green-100 text-green-700 border-0 rounded-full px-2 py-0.5",children:"Creator"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${L(c.lastActiveAt)}`}),e.jsx("p",{className:"text-[13px] text-gray-500 font-medium",children:U(c.lastActiveAt)})]})]})]})]}),e.jsx("div",{className:"flex items-center gap-1",children:e.jsx(F,{variant:"ghost",size:"sm",className:"h-9 w-9 p-0 hover:bg-gray-100 rounded-full transition-colors",children:e.jsx(zs,{className:"w-5 h-5 text-gray-600"})})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-2 space-y-1 flex flex-col animate-in fade-in duration-400 delay-100",children:[m?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx("div",{className:"text-gray-500",children:"Loading messages..."})}):C.length===0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx("div",{className:"text-gray-500 mb-2 text-sm",children:"No messages yet"}),e.jsx("div",{className:"text-xs text-gray-400",children:"Start the conversation!"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1"}),C.map((l,N)=>{const D=l.senderId===a?.id,E=l.sender?.isCreator,A=!D&&(N===0||C[N-1].senderId!==l.senderId),K=N===C.length-1||new Date(C[N+1].createdAt).getTime()-new Date(l.createdAt).getTime()>3e5,le=()=>D?"bg-gradient-to-r from-blue-500 to-blue-600 text-white shadow-md":E?"bg-green-50 text-green-900 border border-green-200/50 shadow-sm":"bg-gray-100 text-gray-900 border border-gray-200/50 shadow-sm";return e.jsxs("div",{className:`flex items-end gap-1.5 ${D?"justify-end":"justify-start"} mb-0.5 animate-in slide-in-from-bottom-2 duration-300`,children:[!D&&e.jsx("div",{className:"w-7 h-7 flex-shrink-0",children:A&&e.jsxs(Y,{className:"h-7 w-7 ring-1 ring-white shadow-sm",children:[e.jsx(X,{src:l.sender?.profileImageUrl||void 0}),e.jsx(Z,{className:"text-xs font-medium bg-gradient-to-br from-blue-100 to-green-100",children:Pe(l.sender)})]})}),e.jsxs("div",{className:`max-w-[280px] ${D?"order-first":""}`,children:[e.jsx("div",{className:`px-3 py-2 rounded-[18px] break-words transition-all duration-200 ${le()}`,style:{borderRadius:D?"18px 18px 4px 18px":"18px 18px 18px 4px"},children:e.jsx("p",{className:"text-[14px] leading-[1.3] font-medium",children:l.content})}),K&&e.jsx("div",{className:`mt-1.5 text-xs text-gray-500 font-medium ${D?"text-right":"text-left"}`,children:P(l.createdAt)})]}),D&&e.jsx("div",{className:"w-8 h-8 flex-shrink-0"})]},l.id||N)})]}),d&&e.jsx("div",{className:"flex justify-start mb-2",children:e.jsxs("div",{className:"flex items-end gap-1.5",children:[e.jsx("div",{className:"w-7 h-7 flex-shrink-0",children:e.jsxs(Y,{className:"h-7 w-7 ring-1 ring-white shadow-sm",children:[e.jsx(X,{src:a?.profileImageUrl||void 0}),e.jsx(Z,{className:"text-xs font-medium bg-gradient-to-br from-blue-100 to-green-100",children:Pe(a)})]})}),e.jsx("div",{className:"bg-gray-100 px-4 py-2 rounded-2xl rounded-bl-md",children:e.jsxs("div",{className:"flex space-x-1",children:[e.jsx("div",{className:"w-2 h-2 bg-gray-500 rounded-full animate-bounce"}),e.jsx("div",{className:"w-2 h-2 bg-gray-500 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),e.jsx("div",{className:"w-2 h-2 bg-gray-500 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]})})]})}),Math.random()>.9&&c&&!d&&e.jsx(za,{user:c}),e.jsx("div",{ref:p})]}),e.jsx("div",{className:"bg-white/95 backdrop-blur-md border-t border-gray-200/50 px-3 py-2.5 shadow-sm animate-in slide-in-from-bottom-2 duration-300 delay-150",children:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("div",{className:"focus-ring-within flex-1 bg-gray-100/80 rounded-[20px] px-3 py-2 flex items-center gap-2 backdrop-blur-sm border border-gray-200/30",children:e.jsx("textarea",{ref:y,value:r,onChange:J,onKeyPress:H,placeholder:"Message...",className:"flex-1 bg-transparent border-none outline-none resize-none text-[15px] leading-[1.3] max-h-[100px] min-h-[18px] placeholder-gray-500 font-medium",rows:1})}),e.jsx(F,{onClick:k,disabled:!r.trim()||T.isPending,className:"h-9 w-9 p-0 rounded-full disabled:opacity-50 shadow-md transition-all duration-200 hover:scale-105 active:scale-95 bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700",children:e.jsx(He,{className:"w-4 h-4 text-white"})})]})})]})}function Ka({onCancel:t,onConversationCreated:s}){const{user:a}=ke(),r=Fe(),[o,d]=n.useState(null),[x,g]=n.useState(""),[b,j]=n.useState(""),[p,y]=n.useState(""),w=n.useRef(null),M=n.useRef(null);n.useEffect(()=>{const c=setTimeout(()=>{y(x)},300);return()=>clearTimeout(c)},[x]),n.useEffect(()=>{w.current?.focus()},[]),n.useEffect(()=>{o&&M.current?.focus()},[o]);const{data:$=[],isLoading:S}=ee({queryKey:["/api/users/messaging-search",p],queryFn:async()=>(await z(`/api/users/messaging-search?q=${encodeURIComponent(p)}`,"GET")).json(),enabled:p.length>=1}),{data:m=[]}=ee({queryKey:["/api/messages/recent-contacts"],queryFn:async()=>(await z("/api/messages/recent-contacts","GET")).json(),enabled:!p.trim()}),{data:f=[]}=ee({queryKey:["/api/creators"],queryFn:async()=>(await z("/api/creators","GET")).json(),enabled:!p.trim()}),C=oe({mutationFn:async({recipientId:c,content:P})=>{const U=await(await z("/api/messages/conversations","POST",{participantIds:[c]})).json();return P.trim()&&await z("/api/messages","POST",{conversationId:U.conversation.id,content:P.trim(),messageType:"text"}),U},onSuccess:c=>{r.invalidateQueries({queryKey:["/api/messages/conversations"]}),s(c.conversation.id)}}),T=c=>c.firstName&&c.lastName?`${c.firstName} ${c.lastName}`:c.username||c.firstName||c.lastName||"User",k=c=>`${c.firstName?.[0]||""}${c.lastName?.[0]||""}`.toUpperCase()||c.username?.[0]?.toUpperCase()||"?",q=()=>{o&&b.trim()&&C.mutate({recipientId:o.id,content:b.trim()})},B=c=>{},H=(p.trim()?$:[...m||[],...f||[]]).filter((c,P,L)=>c.id!==a?.id&&L.findIndex(U=>U.id===c.id)===P);return e.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col items-center justify-center p-4 sm:p-6",children:[e.jsx("div",{className:"absolute inset-0 bg-gray-900/40 backdrop-blur-md transition-opacity duration-300",onClick:t,"aria-hidden":"true"}),e.jsxs("div",{className:"relative w-full max-w-lg bg-white rounded-3xl shadow-2xl overflow-hidden flex flex-col max-h-[90vh] animate-in fade-in zoom-in duration-300",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100 bg-white/80 backdrop-blur-sm sticky top-0 z-20",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900 tracking-tight",children:"Refine Message"}),e.jsx("p",{className:"text-xs text-gray-500 font-medium uppercase tracking-wider",children:"AI-Powered Optimization"})]}),e.jsx(F,{variant:"ghost",size:"sm",onClick:t,className:"h-10 w-10 p-0 rounded-full hover:bg-gray-100 text-gray-400 hover:text-gray-900 transition-all",children:e.jsx(Ee,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:o?e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"bg-gray-50/50 border border-gray-100 rounded-3xl p-4 flex items-center justify-between group",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsxs("div",{className:"relative",children:[e.jsxs(Y,{className:"w-14 h-14 border-2 border-white shadow-md rounded-2xl",children:[e.jsx(X,{src:o.profileImageUrl,className:"rounded-2xl"}),e.jsx(Z,{className:"bg-gradient-to-br from-orange-100 to-orange-200 text-orange-700 font-bold rounded-2xl",children:k(o)})]}),e.jsx("div",{className:"absolute -bottom-1 -right-1 w-5 h-5 bg-white rounded-full flex items-center justify-center shadow-sm",children:e.jsx(Te,{className:"w-3 h-3 text-orange-600 font-bold"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-bold text-gray-900 text-lg",children:T(o)}),o.isCreator&&e.jsx(O,{variant:"secondary",className:"text-[10px] h-5 bg-orange-100 text-orange-700 border-orange-200/50 rounded-full px-2",children:"CREATOR"})]}),e.jsxs("p",{className:"text-sm text-gray-500 font-medium",children:["@",o.username]})]})]}),e.jsx(F,{variant:"ghost",size:"sm",onClick:()=>d(null),className:"h-10 w-10 p-0 rounded-2xl hover:bg-white hover:text-orange-600 transition-all text-gray-400",children:e.jsx(Ee,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-[13px] font-bold text-gray-500 uppercase tracking-wider px-1",children:"Compose Message"}),e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-0.5 bg-gradient-to-br from-orange-500/20 to-orange-600/20 rounded-[2rem] opacity-0 group-focus-within:opacity-100 transition duration-500"}),e.jsx(ns,{ref:M,placeholder:`Write your message for ${o.firstName||o.username}...`,value:b,onChange:c=>j(c.target.value),onKeyDown:B,className:"relative w-full min-h-[180px] text-base p-6 border-gray-200 focus:border-[var(--public-focus-color)] focu
3s:ring-4 focus:ring-[var(--public-focus-color)] rounded-[2rem] bg-white resize-none shadow-sm transition-all"})]}),e.jsx("div",{className:"flex justify-end px-2",children:e.jsxs("span",{className:`text-xs font-semibold ${b.length>500?"text-orange-600":"text-gray-400"}`,children:[b.length," / 1000"]})})]})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"p-6 bg-white border-b border-gray-50 sticky top-0 z-10",children:e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-0.5 bg-gradient-to-r from-orange-500 to-orange-600 rounded-full blur opacity-20 group-focus-within:opacity-40 transition duration-300"}),e.jsxs("div",{className:"relative flex items-center bg-white rounded-full",children:[e.jsx(Le,{className:"absolute left-4 w-5 h-5 text-gray-400 group-focus-within:text-[var(--public-focus-color)] transition-colors"}),e.jsx(Ve,{ref:w,placeholder:"Search for a recipient...",value:x,onChange:c=>g(c.target.value),className:"pl-12 h-12 text-base border-gray-200 focus:border-[var(--public-focus-color)] focus:ring-[var(--public-focus-color)] rounded-full bg-transparent"})]})]})}),e.jsx("div",{className:"p-2 space-y-1",children:S?e.jsx("div",{className:"px-4 py-6 space-y-4",children:[...Array(3)].map((c,P)=>e.jsxs("div",{className:"flex items-center space-x-4 animate-pulse",children:[e.jsx("div",{className:"w-12 h-12 bg-gray-100 rounded-2xl"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-4 bg-gray-100 rounded w-1/3"}),e.jsx("div",{className:"h-3 bg-gray-100 rounded w-1/2"})]})]},P))}):H.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-8 text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-orange-50 rounded-[2.5rem] flex items-center justify-center mb-6 rotate-3",children:e.jsx(Ls,{className:"w-10 h-10 text-orange-600"})}),e.jsx("h3",{className:"text-lg font-bold text-gray-900 mb-2",children:p?"User Not Found":"Find Your Connection"}),e.jsx("p",{className:"text-gray-500 max-w-[240px]",children:p?"We couldn't find anyone matching that search term.":"Search for creators or recent contacts to start a chat."})]}):e.jsx("div",{className:"px-4 pb-6",children:H.map(c=>e.jsx(Oa,{user:c,onClick:()=>d(c),getUserDisplayName:T,getUserInitials:k},c.id))})})]})}),e.jsxs("div",{className:"px-6 py-5 border-t border-gray-100 bg-gray-50/50 flex items-center gap-3",children:[e.jsx(F,{variant:"outline",onClick:t,className:"flex-1 h-12 rounded-2xl border-gray-200 text-gray-600 font-bold hover:bg-white hover:text-gray-900 transition-all",children:"Cancel"}),e.jsx(F,{onClick:q,disabled:!o||!b.trim()||C.isPending,className:"flex-[2] h-12 rounded-2xl bg-gray-900 hover:bg-black text-white font-bold transition-all shadow-lg shadow-gray-200/50 disabled:bg-gray-200 disabled:shadow-none",children:C.isPending?e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin"}),e.jsx("span",{children:"Generating..."})]}):e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(He,{className:"w-4 h-4"}),e.jsx("span",{children:"Generate"})]})})]})]})]})}function Oa({user:t,onClick:s,getUserDisplayName:a,getUserInitials:r}){return e.jsxs("div",{onClick:s,className:"flex items-center space-x-3 p-3 bg-white rounded-xl cursor-pointer hover:bg-orange-50 transition-all duration-200 active:scale-95 mb-2",children:[e.jsxs(Y,{className:"w-12 h-12 border-2 border-orange-200",children:[e.jsx(X,{src:t.profileImageUrl}),e.jsx(Z,{className:"bg-gradient-to-br from-orange-100 to-orange-200 text-orange-700 font-semibold",children:r(t)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-1",children:[e.jsx("span",{className:"font-semibold text-gray-900 truncate",children:a(t)}),t.isCreator&&e.jsx(O,{variant:"secondary",className:"text-xs bg-orange-100 text-orange-700 border-orange-200",children:"Creator"}),t.isVerifiedCreator&&e.jsx("div",{className:"w-4 h-4 bg-orange-600 rounded-full flex items-center justify-center flex-shrink-0",children:e.jsx(Te,{className:"w-2 h-2 text-white"})})]}),e.jsxs("p",{className:"text-sm text-gray-600 truncate",children:["@",t.username]}),t.bio&&e.jsx("p",{className:"text-xs text-gray-500 truncate mt-1",children:t.bio})]})]})}function qa(){return e.jsxs("div",{className:"animate-pulse",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-white dark:bg-slate-950 border-b border-slate-200 dark:border-slate-700",children:[e.jsx("div",{className:"w-8 h-8 bg-slate-200 dark:bg-slate-700 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"h-4 bg-slate-200 dark:bg-slate-700 rounded w-32 mb-1"}),e.jsx("div",{className:"h-3 bg-slate-200 dark:bg-slate-700 rounded w-20"})]})]}),e.jsx("div",{className:"flex-1 p-4 space-y-4",children:[1,2,3,4].map(t=>e.jsxs("div",{className:`flex ${t%2===0?"justify-end":"justify-start"}`,children:[t%2!==0&&e.jsx("div",{className:"w-7 h-7 bg-slate-200 dark:bg-slate-700 rounded-full mr-2"}),e.jsx("div",{className:"max-w-xs",children:e.jsx("div",{className:`h-10 bg-slate-200 dark:bg-slate-700 rounded-2xl ${t%2===0?"rounded-br-md":"rounded-bl-md"}`})})]},t))}),e.jsx("div",{className:"p-4 border-t border-slate-200 dark:border-slate-700",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 h-9 bg-slate-200 dark:bg-slate-700 rounded-full"}),e.jsx("div",{className:"w-9 h-9 bg-slate-200 dark:bg-slate-700 rounded-full"})]})})]})}function Qa(){const{user:t}=ke(),[s,a]=n.useState(null),[r,o]=n.useState(!1),[d,x]=n.useState(!1),[g,b]=n.useState("forward"),j=Fe();oe({mutationFn:async({recipientId:$,content:S})=>(await z("/api/conversations","POST",{recipientId:$,content:S})).json(),onSuccess:$=>{j.setQueryData(["/api/conversations"],S=>S?{...S,conversations:[$,...S.conversations||[]]}:{conversations:[$]}),o(!1),a($.id),setTimeout(()=>{j.invalidateQueries({queryKey:["/api/conversations"]})},100)}});const p=()=>{o(!0)},y=()=>{o(!1)},w=()=>{x(!0),b("back"),setTimeout(()=>{a(null),x(!1)},150)},M=$=>{x(!0),o(!1),requestAnimationFrame(()=>{a($),setTimeout(()=>x(!1),100)})};
3return d?e.jsx("div",{className:"h-screen bg-white",children:e.jsx("div",{className:"animate-pulse",children:e.jsx(qa,{})})}):s?e.jsx("div",{className:"h-screen overflow-hidden",children:e.jsx(Ua,{conversationId:s,onBack:w})}):r?e.jsx("div",{className:"h-screen",children:e.jsx(Ka,{onCancel:y,onConversationCreated:$=>{o(!1),a($)}})}):e.jsxs("div",{className:"h-dvh overflow-hidden flex flex-col bg-[var(--public-ground)]",children:[e.jsx(ss,{}),e.jsx("div",{className:"pt-16 flex-1 min-h-0",children:e.jsx(La,{onSelectConversation:M,onNewMessage:p})})]})}function rn(){const[t,s]=n.useState(!1);return n.useEffect(()=>{const a=()=>{s(window.innerWidth<768)};return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),t?e.jsx(Qa,{}):e.jsx(Fa,{})}export{rn 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.