PageSourceSearch

https://fyra.life/assets/ProfileMock-tILuPbhA.js

js fyra.life collected 2026-09-24 15:05:42 UTC 239,827 bytes, 3 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useGeolocation-CkgjOHRY.js","assets/index-QPhecp7O.js","assets/index-Bc0UvdKs.css","assets/pdfToText-Bt1irvKN.js"])))=>i.map(i=>d[i]);
2import{r as n,s as U,j as e,a as js,B as Lt,X as _s,P as Jr,y as Xn,S as Cr,g as Y,G as Zn,F as ea,Q as ta,E as sa,u as lr,v as Qr,b as In,x as Ke,N as Xr,a3 as ra,_ as Rn,U as na}from"./index-QPhecp7O.js";import{l as aa}from"./songArtworkLookup-CQbMnUX5.js";import{D as cr,a as dr,b as Ur,c as Wr,d as ia}from"./dialog-B4fMj6Ww.js";import{P as oa,a as la,b as ca}from"./popover-DIGmcqKs.js";import{g as da,u as ua,B as ma}from"./BottomNav-QviNxM5x.js";import{S as Hs,a as qs,b as fa,c as ha}from"./sheet-C11EBZeg.js";import{P as Zr}from"./PhotoUploadFlow-4brib44i.js";import en from"./SavedUrls-pvkVc-0l.js";import{I as ds}from"./input-BnMyCCzr.js";import{B as pa}from"./badge-Dg7tijz_.js";import{P as Ns}from"./plus-lCzA0iSD.js";import{r as xa,i as ga}from"./buildProductSearchUrl-BCkapsmk.js";import{a as ba}from"./openExternalLink-CiouaCzR.js";import{B as ur}from"./book-open-BMnKN2Lg.js";import{S as es}from"./shopping-bag-DJvVNQ0P.js";import{E as va}from"./external-link-D95Rt55e.js";import{M as ht}from"./map-pin-DU4obpP5.js";import{S as ys}from"./sparkles-vkZQ-Xe1.js";import{L as wt}from"./loader-circle-BD1gDHKb.js";import{U as _a}from"./undo-2-BMqOo2I5.js";import{a as ya,C as Dn,N as Xt,T as wa,b as ja,c as Na,B as ka,P as Sa,d as Ca,e as Ma,S as La}from"./index-Cacxs6j8.js";import{S as zs}from"./StashIcon-DABuCisL.js";import{A as Ea}from"./AppleMapView-nHb9ddU3.js";import{s as Et,m as Vt}from"./imageTransform-D9pM4sAU.js";import{getCachedRatings as Pa,loadRatings as Aa}from"./ratingsCache-CX3szAhY.js";import{g as Ta,s as tn}from"./stashHubCache-a4Qu5Uvn.js";import{t as On,A as sn,a as Ia,b as rn}from"./avatar-DZOGgYKJ.js";import{D as Gt,a as Ht,b as qt,c as ct}from"./dropdown-menu-Ce6COgMA.js";import{C as Gr}from"./ConfirmDeleteDialog-Bat8BPSA.js";import{I as Ra}from"./InviteTreeGraph-DkMTwh-F.js";import{u as Da}from"./useTaxonomyProjection-BwYg7C3Y.js";import{F as nn}from"./flame-D6zaIPn7.js";import{A as Oa,m as Ba}from"./proxy-Cr60Kmxz.js";import{E as Bn}from"./eye-216OF-5b.js";import{U as $a}from"./user-plus-BkfJrMVP.js";import{F as $n}from"./film-ibZUa_yj.js";import{P as ws}from"./palette-Cv02Dzm4.js";import{C as an}from"./calendar-BrOVilju.js";import{T as za,g as Ua}from"./groupWishlist-BSAd8qdk.js";import{V as Wa}from"./VaultItemDialog-vc37It-z.js";import{S as Ga}from"./SaveToVaultSheet-CO4r6HDf.js";import{L as Tr}from"./lightbulb-D_qcfk1_.js";import{C as mt}from"./check-FunNIplL.js";import{M as Ha}from"./music-2-dhar1ue0.js";import{L as ar}from"./layers-SEi4Qne2.js";import{I as mr}from"./image-Cg50P5Wj.js";import{C as qa}from"./CreateGuideDialog-CF6pJ6Se.js";import{L as on}from"./label-CzPXKXNd.js";import{S as Us}from"./search-BHnbPM4m.js";import{u as zn}from"./useSharedGuides-D733Dw5f.js";import{u as Va}from"./useSelfHealingProductThumbnail-Cdd8-VZe.js";import{u as Fa}from"./useSelfHealingPlaceThumbnail-CI6ecaVK.js";import{L as Ka}from"./LongPressPeek-D_vaZ8hs.js";import{a as Ir}from"./addItemToWishlist-mFync5O1.js";import{s as Ya,l as ln}from"./perfTrace-DiHBgXrf.js";import{u as Ja}from"./useRetryOnResume-6vstSpqf.js";import{S as Qa}from"./settings-Bf2pI4h2.js";import{H as Ft}from"./heart-BnH5JrOl.js";import{H as Un}from"./hand-heart-DlzUPpXr.js";import{A as Xa}from"./arrow-up-BYm5qmqi.js";import{S as Za}from"./save-CiyujzRu.js";import{C as jt}from"./chevron-down-Cb7pTAo6.js";import{G as Bs}from"./gift-DIcO9VUH.js";import{C as Rr}from"./compass-Dz7GumhO.js";import{B as Hr}from"./user-round-plus-rvy3Gdga.js";import{P as vs,M as Wn}from"./zoom-out-1tjWO7i0.js";import{U as ei}from"./users-DT6Ui4NJ.js";import{C as qr}from"./chevron-right-DsELGuPe.js";import{S as ti}from"./star-BQv2XTWC.js";import{M as si}from"./minus-DfrYPyn3.js";import{L as ri}from"./layout-grid-muAS7mgz.js";import{L as ni}from"./list-DzdKiqO7.js";import{C as ai}from"./chevron-left-CecELXL0.js";import{U as Gn}from"./utensils-C7_4knq7.js";import{T as Vs}
2from"./trash-2-ka7vD4Uv.js";import{S as ii}from"./send-Cwn6kuvl.js";import{L as oi}from"./link-2-821WhS-4.js";import{N as li}from"./user-check-myzQdhcl.js";import{W as cn}from"./wine-SkXKsIZ6.js";import{H as ci}from"./hotel-CX5d3Aex.js";import{M as di}from"./mountain-rh52mZ_Y.js";import{L as ui}from"./landmark-C9D3pWLX.js";import{P as mi}from"./plane-B1ETENlb.js";import{T as fi}from"./tv-BDuGCcu6.js";import{M as hi}from"./mic-DtDEFnGB.js";import{G as pi}from"./gamepad-2-CSYGkzSG.js";import{C as xi}from"./chef-hat-MzA__Ub8.js";import{H as dn,S as gi}from"./scissors-B4A-Xcxv.js";import{P as bi}from"./pen-line-DLmAkYdY.js";import{B as vi}from"./volleyball-BdLQdbN-.js";import{S as _i}from"./smartphone-DAxNVrWC.js";import{W as un}from"./wrench-CIqoFDLU.js";import{S as yi}from"./shirt-C7VfXTPD.js";import{T as wi}from"./tree-pine-BUUAmWcM.js";import{B as ji}from"./briefcase-DE2MSivg.js";import{C as Ni}from"./camera-CUR8QQ-M.js";import{T as ki}from"./tag-BYXAAYDd.js";import{E as Si}from"./eye-off-CIeMTQAE.js";import"./index-DZ8y-Lbp.js";import"./index-CxtiVhNj.js";import"./useQuery-G3MkN2eb.js";import"./gem-j1Kvi_SR.js";import"./heart-handshake-CAjNKm-u.js";import"./ratingUtils-DG8oVE9k.js";import"./select-l0EhNwtV.js";import"./index-BdQq_4o_.js";import"./index-DWyeoR8t.js";import"./index-BOYu34nj.js";import"./chevron-up-CzAuRTHN.js";import"./skeleton-D6L9K5rZ.js";import"./checkbox-B5DEy-ud.js";import"./textarea-CLcFyTZl.js";import"./parseFraction-DtooggxV.js";import"./sparkle-g0uXXTyQ.js";import"./useDefaultShareVisibility-PJaaKmBJ.js";import"./useProductGenderPreference-CSZC0Lvk.js";import"./productGenderGuard-DsVQbY7X.js";import"./saveProductToCorpus-Be0UnuMh.js";import"./resolveProductTaxonomy-Ce13_JRk.js";import"./isL1Taxonomy-CfvEgPBW.js";import"./inferProductTaxonomyFromTitle-Ca0PTqqI.js";import"./friendlyError-UL1BAfr1.js";import"./alert-dialog-BK1mCcw4.js";import"./imageUpload-Di1Y4sN2.js";import"./useHomeRegion-DKJD3q9_.js";import"./FullscreenGallery-DO1Rqxjs.js";import"./moderateContent-DGjFqjKB.js";import"./CreateCreationDialog-C6qXgNaI.js";import"./circle-check-D9JJrPdb.js";import"./pen-tool-BGAVuZEp.js";import"./wallpaper-jqEl_1xM.js";import"./video-BkLzvDdW.js";import"./user-9XkIIR5u.js";import"./pencil-DolZbbEI.js";import"./house-CwYoGqrH.js";import"./utensils-crossed-BpaNZmDS.js";import"./cake-BZCQMn02.js";import"./lock-_e-nMnrw.js";import"./image-plus-CeipAUAo.js";import"./wand-sparkles-BC1u9C1A.js";import"./link-46xnJMSj.js";import"./file-text-BcrWaxWw.js";import"./upload-D898F4f9.js";import"./list-ordered-iRzUxKGg.js";import"./circle-alert-CqE5Fdk1.js";import"./refresh-cw-d30BIT2I.js";import"./clock-BQv71rI-.js";import"./arrow-right-Dy7fK3Gp.js";import"./wishlistRatingSync-D6BG7N7Y.js";import"./sanitizePrice-DR5ZJc2g.js";import"./BrandIcons-DgXCvF6_.js";import"./arrow-left-1zOQukEW.js";import"./share-CaqXHNGZ.js";import"./package-Bkrf7Qhi.js";import"./triangle-alert-CWUqKKJR.js";import"./archive-BodlYIAy.js";import"./index-BDibRDnp.js";import"./salad-DOzbnJX8.js";import"./list-plus-VpQdoEAI.js";import"./thumbs-up-IogT2Klj.js";import"./arrow-up-right-eYRua0tq.js";import"./ticket-CsDT6AJQ.js";import"./umbrella-CDMlYqMF.js";import"./bell-Gt4iuGB7.js";import"./book-user-CfFz24o2.js";import"./circle-help-BJN4Nl1d.js";import"./keyboard-BVZj1MTl.js";import"./chart-no-axes-column-CzUNI9oB.js";import"./graduation-cap-CCnu8ifM.js";import"./circle-check-big-BTFb4pdE.js";import"./circle-x-C3Fb38AV.js";import"./circle-Bd3gEYwT.js";import"./cookie-B87TZ8IX.js";import"./copy-Oj4HHmYc.js";import"./crown-DpBWkogX.js";import"./redo-2-DULsUuHG.js";import"./store-DvhjDBKa.js";import"./download-D3sXq4m6.js";import"./dumbbell-BPXhm4OU.js";import"./file-spreadsheet-Cj_djAC0.js";import"./flag-C9KeUqjT.js";import"./flask-conical-DgIQGeAK.js";import"./globe-J2Z7hv67.js";import"./grid-3x3-DJSk-DU4.js";import"./grip-vertical-JiWNhmMu.js";import"./headphones-PZ_8Hi7j.js";import"./square-check-big-D2K7ewG5.js";import"./key-round-Ctb8uNc5.js";import"./key-6SMO0qiC.js";import"./list-checks-aK-3JFjm.js";import"./list-music-DxBC2sni.js";import"./mail-B3muztMy.js";import"./megaphone-C8pignzT.js";import"./message-circle-question-QpBz6Ih5.js";import"./message-circle-CJnO7nHb.js";import"./message-square-CiJW8S9W.js";import"./zap-ftiOFpMX.js";import"./plug-CV8Vyskg.js";import"./podcast-Dffdvlcc.js";import"./rotate-ccw-74Cg983g.js";import"./scan-barcode-a3SnMYIz.js";import"./share-2-a56zFr3J.js";import"./shield-Cb_L6uil.js";import"./telescope-CinKabOw.js";import"./trending-up-7-AsjtL8.js";import"./youtube-DKGn-_D7.js";import"./zoom-in-CbCUrRVg.js";import"./useGeolocation-CkgjOHRY.js";import"./switch-INBvQRXn.js";import"./scroll-area-BVnNqPl9.js";import"./swrStore-O-pESH9R.js";import"./index-CK33rdK8.js";import"./appleMaps-B8Ncjd3q.js";import"./pdfToText-Bt1irvKN.js";import"./normalizeBookCoverUrl-CSpwtQu4.js";import"./search-input-DBQ35MvL.js";import"./useSendToFavorites-Bw6O-QZm.js";import"./scrubAITextCorruption-DeMgGqDF.js";import"./useCamera-C75vYRK8.js";import"./index-Nuuq4BDb.js";import"./useTrailerUrl-JO8Hh1Kh.js";import"./openYouTubeTrailer-Cm02zW4C.js";import"./openYouTubeChannel-CZ46FYus.js";import"./isUserUploadedTastePhoto-BN6myZWc.js";
2import"./isPlaceholderImage-DUTkz-6J.js";import"./CreatorCreditPill-2s3tSk9E.js";import"./usePlaceAttribution-DNg1uGQ3.js";import"./humanizeTitle-2ZcthfUi.js";import"./cleanSongTitle-BWCBRKKh.js";import"./AppleMapsLogo-BDwSI0rW.js";import"./StashMediaSearch-CT9Txcxh.js";import"./triggerPlacePlaceholder-7k4gQZqi.js";import"./EmptyState-CSgghk4P.js";import"./detectBookAndSaveAsMedia-Cw0SbQQW.js";import"./sessionRefresh-dvAguF1I.js";import"./mediaSearchFallback-hKvt390_.js";import"./supabaseDirect-DK9s24Tr.js";import"./normalizeMediaLevel2-BFbM6i_V.js";import"./safeVaultInsert-owqQE1y3.js";import"./invokeWithTimeout-w9u7G3q_.js";import"./stashWidgets-BUzXcvw_.js";import"./resumeRecovery-Dzes16JQ.js";function Ci(){const[t,a]=n.useState([]),[r,s]=n.useState(!0),[i,c]=n.useState(0),m=n.useCallback(()=>c(d=>d+1),[]);return n.useEffect(()=>{let d=!1,v=null,_=null;(async()=>{const{data:{session:S}}=await U.auth.getSession();if(!(S!=null&&S.user)){d||(a([]),s(!1));return}const x=S.user.id,[L,W,V]=await Promise.all([U.from("user_saved_urls").select("id, url, title, scraped_title, scraped_image_url, created_at").eq("user_id",x).eq("status","unresolved").order("created_at",{ascending:!1}).limit(60),U.from("user_pending_photos").select("id, photo_url, storage_path, ai_name, ai_brand, created_at").eq("user_id",x).order("created_at",{ascending:!1}).limit(30),U.from("deleted_pending_photo_paths").select("storage_path").eq("user_id",x)]),E=new Set((V.data??[]).map(se=>se.storage_path).filter(Boolean)),J=(W.data??[]).filter(se=>!se.storage_path||!E.has(se.storage_path)),O=new Set,X=J.filter(se=>{var ye;const G=(ye=se.photo_url)==null?void 0:ye.split("?")[0];return!G||O.has(G)?!1:(O.add(G),!0)}),ge=await da(x,X.map(se=>se.photo_url)),Re=X.filter(se=>{var G;return!ge.has((G=se.photo_url)==null?void 0:G.split("?")[0])}).map(se=>({kind:"photo",id:se.id,title:se.ai_name||se.ai_brand||"Pending photo",thumbnail:se.photo_url,created_at:se.created_at})),ve=(L.data??[]).map(se=>{let G="";try{G=new URL(se.url).hostname.replace(/^www\./,"")}catch{}return{kind:"url",id:se.id,title:se.scraped_title||se.title||G||"Saved link",thumbnail:se.scraped_image_url||null,created_at:se.created_at}}),it=[...Re,...ve].sort((se,G)=>(G.created_at||"").localeCompare(se.created_at||""));if(d)return;a(it),s(!1);const B=ve.some(se=>!se.thumbnail),Z=Re.some(se=>!se.title||se.title==="Pending photo");(B||Z)&&(v=setTimeout(()=>{d||c(se=>se+1)},3e3))})(),(async()=>{const{data:{session:S}}=await U.auth.getSession();if(!(S!=null&&S.user)||d)return;const x=S.user.id;_=U.channel(`pending-review-${x}`).on("postgres_changes",{event:"UPDATE",schema:"public",table:"user_saved_urls",filter:`user_id=eq.${x}`},()=>{d||c(L=>L+1)}).on("postgres_changes",{event:"INSERT",schema:"public",table:"user_pending_photos",filter:`user_id=eq.${x}`},()=>{d||c(L=>L+1)}).on("postgres_changes",{event:"UPDATE",schema:"public",table:"user_pending_photos",filter:`user_id=eq.${x}`},()=>{d||c(L=>L+1)}).on("postgres_changes",{event:"DELETE",schema:"public",table:"user_pending_photos",filter:`user_id=eq.${x}`},()=>{d||c(L=>L+1)}).subscribe()})();const y=()=>{d||c(S=>S+1)},j=()=>{d||c(S=>S+1)};return typeof window<"u"&&(window.addEventListener("fyra:pending-media-ingested",y),window.addEventListener("fyra:pending-media-failed",j)),()=>{d=!0,v&&clearTimeout(v),_&&U.removeChannel(_),typeof window<"u"&&(window.removeEventListener("fyra:pending-media-ingested",y),window.removeEventListener("fyra:pending-media-failed",j))}},[i]),{items:t,loading:r,refresh:m}}function Mi(){const[t,a]=n.useState(0);return n.useEffect(()=>{const r=typeof window<"u"?window.visualViewport:null;if(!r)return;const s=()=>{const i=Math.max(0,window.innerHeight-r.height-r.offsetTop);a(i>40?i:0)};return s(),r.addEventListener("resize",s),r.addEventListener("scroll",s),()=>{r.removeEventListener("resize",s),r.removeEventListener("scroll",s)}},[]),t}function Li({open:t,onOpenChange:a,kind:r,onChanged:s,initialUrlId:i,initialPhotoId:c}){const m=Mi();return r==="url"&&i?t?e.jsx(en,{embedded:!0,directOnly:!0,onClose:()=>{a(!1),s==null||s()},initialUrlId:i}):null:r==="photo"&&c?t?e.jsx(Zr,{onClose:()=>{a(!1),s==null||s()},initialPhotoId:c}):null:e.jsx(Hs,{open:t,onOpenChange:d=>{a(d),d||s==null||s()},children:e.jsx(qs,{side:"bottom",className:"p-0 overflow-y-auto",style:{height:m>0?`calc(100dvh - ${m}px - 8px)`:"92dvh"},children:e.jsxs("div",{className:"h-full",children:[r==="photo"&&e.jsx(Zr,{onClose:()=>a(!1),initialPhotoId:c??null}),r==="url"&&e.jsx(en,{embedded:!0,directOnly:!!i,onClose:()=>a(!1),initialUrlId:i??null})]})})})}const Ei=["Vegetarian","Vegan","Pescatarian","Gluten-free","Dairy-free","Kosher","Halal","Keto","Low-carb","Nut-free"],Pi=["Peanuts","Tree nuts","Shellfish","Dairy","Eggs","Soy","Wheat","Fish","Sesame"],Mr=({label:t,values:a,setValues:r,presets:s,allowOther:i,placeholder:c})=>{const[m,d]=n.useState(""),[v,_]=n.useState(!1),M=x=>{const L=x.trim();L&&(a.some(W=>W.toLowerCase()===L.toLowerCase())||(r([...a,L]),d(""),_(!1)))},y=x=>r(a.filter(L=>L!==x)),j=(s||[]).filter(x=>!a.some(L=>L.toLowerCase()===x.toLowerCase())),S=i&&!v;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:t}),a.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(x=>e.jsxs(pa,{variant:"secondary",className:"gap-1 pr-1",children:[x,e.jsx("button",{type:"button",onClick:()=>
2y(x),className:"rounded-full hover:bg-muted-foreground/20 p-0.5","aria-label":`Remove ${x}`,children:e.jsx(_s,{className:"h-3 w-3"})})]},x))}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[j.map(x=>e.jsxs("button",{type:"button",onClick:()=>M(x),className:"text-xs px-2 py-1 rounded-full border border-border/60 bg-card/40 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",children:["+ ",x]},x)),S&&e.jsxs("button",{type:"button",onClick:()=>_(!0),className:"text-xs px-2 py-1 rounded-full border border-border/60 bg-card/40 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors inline-flex items-center gap-1",children:[e.jsx(Ns,{className:"h-3 w-3"})," Other"]})]}),v&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ds,{value:m,onChange:x=>d(x.target.value),onFocus:x=>{setTimeout(()=>{x.target.scrollIntoView({block:"center",behavior:"smooth"})},300)},onKeyDown:x=>{(x.key==="Enter"||x.key===",")&&(x.preventDefault(),M(m))},placeholder:c||"Add your own",className:"h-9 text-sm",autoFocus:!0}),e.jsx(Lt,{type:"button",size:"sm",variant:"outline",onClick:()=>M(m),disabled:!m.trim(),children:"Add"})]}),!s&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ds,{value:m,onChange:x=>d(x.target.value),onFocus:x=>{setTimeout(()=>{x.target.scrollIntoView({block:"center",behavior:"smooth"})},300)},onKeyDown:x=>{(x.key==="Enter"||x.key===",")&&(x.preventDefault(),M(m))},placeholder:c||"Add your own",className:"h-9 text-sm"}),e.jsx(Lt,{type:"button",size:"sm",variant:"outline",onClick:()=>M(m),disabled:!m.trim(),children:"Add"})]})]})},Ai=({open:t,onOpenChange:a})=>{const{toast:r}=js(),[s,i]=n.useState(!1),[c,m]=n.useState(!1),[d,v]=n.useState([]),[_,M]=n.useState([]),[y,j]=n.useState([]);n.useEffect(()=>{t&&(async()=>{i(!0);const{data:{user:x}}=await U.auth.getUser();if(!x){i(!1);return}const{data:L}=await U.from("profiles").select("dietary_restrictions, food_allergies, food_dislikes").eq("id",x.id).maybeSingle(),W=L||{};v(Array.isArray(W.dietary_restrictions)?W.dietary_restrictions.filter(Boolean):[]),M(Array.isArray(W.food_allergies)?W.food_allergies.filter(Boolean):[]),j(Array.isArray(W.food_dislikes)?W.food_dislikes.filter(Boolean):[]),i(!1)})()},[t]);const S=async()=>{m(!0);const{data:{user:x}}=await U.auth.getUser();if(!x){m(!1);return}const{error:L}=await U.from("profiles").update({dietary_restrictions:d,food_allergies:_,food_dislikes:y}).eq("id",x.id);if(m(!1),L){r({title:"Couldn't save",description:L.message,variant:"destructive"});return}r({title:"Dietary preferences saved",description:"We'll factor these into your recipe recommendations."}),a(!1)};return e.jsx(cr,{open:t,onOpenChange:a,children:e.jsxs(dr,{className:"max-w-md max-h-[85vh] overflow-y-auto pb-[env(safe-area-inset-bottom)]",children:[e.jsx(Ur,{children:e.jsx(Wr,{children:"Dietary preferences"})}),s?e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:"Loading…"}):e.jsxs("div",{className:"space-y-5",children:[e.jsx(Mr,{label:"Preferences",values:d,setValues:v,presets:Ei,allowOther:!0,placeholder:"Add a diet"}),e.jsx(Mr,{label:"Allergies",values:_,setValues:M,presets:Pi,allowOther:!0,placeholder:"Add an allergy"}),e.jsx(Mr,{label:"Dislikes",values:y,setValues:j,placeholder:"e.g. Bell peppers"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(Lt,{variant:"ghost",onClick:()=>a(!1),disabled:c,children:"Cancel"}),e.jsx(Lt,{onClick:S,disabled:c||s,children:c?"Saving…":"Save"})]})]})})},Ti=[{label:"Interested",emoji:"✨",experienced_state:"not_tried",rating_value:null,interest_value:1},{label:"Not for me",emoji:"🚫",experienced_state:"tried",rating_value:-1,interest_value:null},{label:"Neutral",emoji:"😐",experienced_state:"tried",rating_value:0,interest_value:null},{label:"Liked",emoji:"👍",experienced_state:"tried",rating_value:1,interest_value:null},{label:"Loved",emoji:"❤️",experienced_state:"tried",rating_value:2,interest_value:null}];function Lr(t){const a=String(t??"").trim();if(!a)return null;const r=a.toLowerCase();return r==="songs"||r==="music"?"Music":a.charAt(0).toUpperCase()+a.slice(1)}const Dt=new Map,er=new Map,Ws="fyra_preview_url_cache_v6",Hn=6*60*60*1e3;function Ii(t){try{const a=new URL(t).searchParams.get("hdnea"),r=a==null?void 0:a.match(/(?:^|~)exp=(\d+)/);return r!=null&&r[1]?Number(r[1]):null}catch{return null}}function Vr(t){if(!t)return!1;const a=Ii(t);return a?a>Math.floor(Date.now()/1e3)+45:!0}function Ri(){try{for(const s of["fyra_preview_url_cache_v5","fyra_preview_url_cache_v4","fyra_preview_url_cache_v3"])try{localStorage.removeItem(s)}catch{}const t=localStorage.getItem(Ws);if(!t)return;const a=JSON.parse(t),r=Date.now();for(const[s,i]of Object.entries(a)){if(!i||typeof i.at!="number"||r-i.at>Hn)continue;const c=s.split("|")[1]??"";i.url&&!Vn(c,i.performer??null)||i.url&&!Vr(i.url)||Dt.has(s)||Dt.set(s,i.url??null)}}catch{}}function qn(t,a,r){try{const s=localStorage.getItem(Ws),i=s?JSON.parse(s):{},c=Date.now();for(const[m,d]of Object.entries(i))(!d||typeof d.at!="number"||c-d.at>Hn)&&delete i[m];i[t]={url:a,at:c,performer:r??null},localStorage.setItem(Ws,JSON.stringify(i))}catch{}}const Dr=t=>(t||"").trim().replace(/^(?:song|track|single|album|music|movie|film|show|series|book|podcast|episode)s?\s*(?:by|[:·•\-–—])\s*/i,"").replace(/^(?:performed|written|sung)\s+by\s+/i,"").trim(),mn=t=>(t||"").toLowerCase().replace(/^the\s+/,"").replace(/[^a-z0-9,]+/g," ").replace(/\s*,\s*/g,",").trim();function Vn(t,a){const r=mn(t),s=mn(a);if(!r||!s||r.replace(/,/g," ")===s.replace(/,/g," "))return!0;const i=d=>
2d.split(/,|\s(?:and|&|feat|featuring|ft|with|x)\s/).map(v=>v.trim()).filter(Boolean),c=i(r),m=i(s);return!!(c.some(d=>m.includes(d))||m.some(d=>c.includes(d)))}const fn=t=>(t||"").toLowerCase().replace(/\((?:[^)]*)\)|\[[^\]]*\]/g," ").replace(/\s-\s.*$/," ").replace(/[^a-z0-9]+/g," ").trim();function Di(t,a){const r=fn(t),s=fn(a);if(!r||!s||r===s)return!0;const i=r.length<=s.length?r:s,c=r.length<=s.length?s:r;return i.length>=4&&(c.startsWith(`${i} `)||c.endsWith(` ${i}`))}Ri();const Fr=(t,a)=>`${(t||"").trim().toLowerCase()}|${Dr(a).toLowerCase()}`;function Oi(t,a){const r=Fr(t,a);Dt.delete(r),qn(r,null,null);try{const s=localStorage.getItem(Ws);if(s){const i=JSON.parse(s);delete i[r],localStorage.setItem(Ws,JSON.stringify(i))}}catch{}}function Bi(t,a){const r=Fr(t,a),s=Dt.get(r)??null;return s&&!Vr(s)?(Dt.delete(r),null):s}async function Er(t,a,r,s){const i=Fr(t,a);if(s!=null&&s.forceRefresh)Dt.delete(i),er.delete(i);else if(Dt.has(i)){const d=Dt.get(i)??null;if(!d||Vr(d))return d;Dt.delete(i)}const c=s!=null&&s.forceRefresh?void 0:er.get(i);if(c)return c;const m=(async()=>{const d=U.functions.invoke("deezer-preview-url",{body:{title:t,artist:Dr(a),force_refresh:(s==null?void 0:s.forceRefresh)===!0}});let v;const _=new Promise((M,y)=>{v=setTimeout(()=>y(new Error("deezer-preview-timeout")),r)});try{const{data:M,error:y}=await Promise.race([d,_]);if(y)throw y;const j=M;let S=(j==null?void 0:j.preview_url)??null;return S&&!Vn(Dr(a),j==null?void 0:j.track_artist)&&(console.warn(`[preview] rejected mismatched artist for "${t}": expected "${a}", got "${j==null?void 0:j.track_artist}"`),S=null),S&&(j!=null&&j.track_title)&&!Di(t,j.track_title)&&(console.warn(`[preview] rejected mismatched title for "${t}": got "${j.track_title}"`),S=null),Dt.set(i,S),qn(i,S,(j==null?void 0:j.track_artist)??null),S}finally{v&&clearTimeout(v),er.delete(i)}})();return er.set(i,m),m}function $i({open:t,onOpenChange:a,items:r,onRate:s,onRemove:i,onWishlist:c}){const{toast:m}=js(),[d,v]=n.useState(null),[_,M]=n.useState([]),[y,j]=n.useState(0),S=n.useRef(0);n.useEffect(()=>{S.current=y},[y]);const[x,L]=n.useState(!1),[W,V]=n.useState(0),[E,J]=n.useState([]),[O,X]=n.useState(null),ge=n.useRef(!1),Re=n.useMemo(()=>{const g=new Map;for(const D of r){const k=Lr(D.level_1);k&&g.set(k,(g.get(k)??0)+1)}return Array.from(g.entries()).sort((D,k)=>k[1]-D[1]).map(([D,k])=>({label:D,count:k}))},[r]);n.useEffect(()=>{if(!t)return;const g=d?r.filter(D=>Lr(D.level_1)===d):r;M(g),j(0),J([]),X(null)},[t,d]),n.useEffect(()=>{t&&M(g=>{const D=d?r.filter(he=>Lr(he.level_1)===d):r;if(D.length===g.length&&D.every((he,ee)=>{var je;return he.vault_taste_id===((je=g[ee])==null?void 0:je.vault_taste_id)}))return g;const k=new Set(D.map(he=>he.vault_taste_id)),h=S.current,p=g.filter((he,ee)=>ee<=h||k.has(he.vault_taste_id)),H=new Set(p.map(he=>he.vault_taste_id)),te=D.filter(he=>!H.has(he.vault_taste_id));return[...p,...te]})},[r,t,d]),n.useEffect(()=>{t&&(v(null),V(0),ge.current=!1)},[t]),n.useEffect(()=>{X(null)},[y]);const[ve,it]=n.useState({});n.useEffect(()=>{if(!t)return;const g=new Set;for(let k=y;k<Math.min(y+4,_.length);k++){const h=_[k];if(!h)continue;const p=String(h.level_1??"").toLowerCase();if(!(p==="music"||p==="songs"))continue;const te=(h.subtitle||"").trim().toLowerCase();if(te&&te!=="music"&&te!=="songs"&&te!==(h.level_1||"").toLowerCase())continue;const he=h.entity_id;he&&!ve[he]&&g.add(he)}if(g.size===0)return;const D=Array.from(g);(async()=>{try{const{data:k}=await U.from("corpus_media_song").select("apple_catalog_id, artists").in("apple_catalog_id",D),h={};(k||[]).forEach(p=>{p!=null&&p.apple_catalog_id&&(p!=null&&p.artists)&&(h[p.apple_catalog_id]=String(p.artists))}),Object.keys(h).length&&it(p=>({...p,...h}))}catch{}})()},[t,y,_,ve]);const B=_[y],Z=Math.max(0,_.length-y),se=_.length>0&&y>=_.length,G=E.filter(g=>g.kind==="skipped"),ye=G.length,Ye=()=>{const g=G.map(D=>_[D.prevIdx]).filter(D=>!!D);g.length!==0&&(M(g),j(0),J([]),X(null))},[Pe,Ve]=n.useState({}),Le=n.useRef(new Set);n.useEffect(()=>{if(t)for(let g=1;g<=3;g++){const D=_[y+g],k=(D==null?void 0:D.thumbnail_url)??Pe[(D==null?void 0:D.vault_taste_id)??""];if(!k)continue;const h=new Image;h.decoding="async",h.src=k}},[t,y,_,Pe]),n.useEffect(()=>{if(!t)return;const g=_.slice(y,y+6).filter(k=>!k.thumbnail_url&&!Pe[k.vault_taste_id]&&!Le.current.has(k.vault_taste_id));if(g.length===0)return;for(const k of g)Le.current.add(k.vault_taste_id);const D=g.map(k=>{const h=P(k),p=(k.level_2||"").toLowerCase(),H=h?"songs":p.includes("movie")?"movies":p.includes("show")?"shows":p.includes("book")?"books":p||"media";return{id:k.vault_taste_id,title:h&&k.subtitle?`${k.subtitle} - ${k.title}`:k.title,category:H,entity_id:k.entity_id??void 0}});U.functions.invoke("resolve-media-images",{body:{items:D}}).then(({data:k})=>{const h=(k==null?void 0:k.images)||{};Object.keys(h).length>0&&Ve(p=>({...p,...h}))}).catch(()=>{})},[t,y,_,Pe]);const $=async g=>{if(!B||x)return;L(!0);const D=B,k=y;j(h=>h+1);try{await s(D.vault_taste_id,{experienced_state:g.experienced_state,rating_value:g.rating_value,interest_value:g.interest_value,label:g.label})>0?(V(p=>p+1),J(p=>[...p,{vault_taste_id:D.vault_taste_id,prevIdx:k,kind:"rated"}
2])):m({title:"Couldn't save rating",description:"We'll retry next time.",variant:"destructive"})}catch(h){console.error("RateUnratedSheet onRate failed:",h),m({title:"Couldn't save rating",description:"We'll retry next time.",variant:"destructive"})}finally{L(!1)}},le=g=>{if(!B||x)return;if(g.rating_value!==null&&g.rating_value<0&&i){X(g);return}$(g)},ne=async()=>{if(!B||!c||x)return;L(!0);const g=B,D=y;j(k=>k+1);try{const k=await c(g.vault_taste_id);(typeof k=="number"?k:0)>0?(V(h=>h+1),J(h=>[...h,{vault_taste_id:g.vault_taste_id,prevIdx:D,kind:"rated"}])):m({title:"Couldn't add to wishlist",description:"We'll retry next time.",variant:"destructive"})}catch(k){console.error("RateUnratedSheet onWishlist failed:",k),m({title:"Couldn't add to wishlist",description:"We'll retry next time.",variant:"destructive"})}finally{L(!1)}},de=()=>{const g=O;g&&(X(null),$(g))},De=async()=>{const g=O;if(!B||!g||!i||x)return;L(!0);const D=B;X(null),j(k=>k+1);try{try{await s(D.vault_taste_id,{experienced_state:g.experienced_state,rating_value:g.rating_value,interest_value:g.interest_value,label:g.label})}catch{}const k=await i(D.vault_taste_id);(typeof k=="number"?k:0)>0?V(h=>h+1):m({title:"Couldn't remove",description:"We'll retry next time.",variant:"destructive"})}catch(k){console.error("RateUnratedSheet onRemove failed:",k),m({title:"Couldn't remove",description:"We'll retry next time.",variant:"destructive"})}finally{L(!1)}},Ee=()=>{B&&(J(g=>[...g,{vault_taste_id:B.vault_taste_id,prevIdx:y,kind:"skipped"}]),j(g=>g+1))},C=async()=>{if(x||E.length===0)return;const g=E[E.length-1];if(J(D=>D.slice(0,-1)),j(g.prevIdx),g.kind==="rated"){L(!0);try{await s(g.vault_taste_id,{experienced_state:"not_tried",rating_value:null,interest_value:null,label:"Unrated"}),V(D=>Math.max(0,D-1))}catch(D){console.error("RateUnratedSheet undo failed:",D),m({title:"Couldn't undo",description:"Try re-rating the item.",variant:"destructive"})}finally{L(!1)}}},z=n.useMemo(()=>{if(!B)return null;const g=B.title||"",D=B.subtitle||"",k=(B.domain||"").toLowerCase(),h=(B.level_1||"").toLowerCase(),p=(B.level_2||"").toLowerCase(),H=encodeURIComponent(`${g} ${D}`.trim());if(k==="creation"||k==="recipe"||h==="creations"||h==="recipes"||p==="recipe")return null;const we=k==="song"||h==="music"||h==="songs"||p==="song"||p==="songs",he=k==="book"||h==="books"||p==="book"||p==="books",ee=k==="movie"||k==="show"||h==="movies"||h==="shows"||p==="movie"||p==="show",je=k==="place"||h==="places",Ae=k==="product"||h==="products";return we?{kind:"song",label:"Preview"}:ee?{kind:"link",label:"Trailer",url:`https://www.youtube.com/results?search_query=${H}+trailer`,Icon:Jr}:he?{kind:"link",label:"Read",url:`https://openlibrary.org/search?q=${H}`,Icon:ur}:Ae?{kind:"link",label:B.website&&!ga(B.website)?"Site":"Shop",url:xa(B.website,B.title||"",null),Icon:es}:je?{kind:"link",label:B.website?"Site":"Map",url:B.website||`https://www.google.com/maps/search/?api=1&query=${H}`,Icon:B.website?va:ht}:null},[B]),[F,ue]=n.useState(null),[re,xe]=n.useState(!1),oe=n.useRef(0);n.useEffect(()=>{Xn(),Cr(),ue(null),xe(!1),oe.current+=1},[B==null?void 0:B.vault_taste_id,t]);const P=g=>{if(!g)return!1;const D=(g.domain||"").toLowerCase(),k=(g.level_1||"").toLowerCase(),h=(g.level_2||"").toLowerCase();return D==="song"||k==="music"||k==="songs"||h==="song"||h==="songs"},K=async g=>{if(!B)return;const D=B.vault_taste_id;if(!(g!=null&&g.auto)&&F===D){ea(),ue(null);return}g!=null&&g.auto||(ge.current=!0),ta();const k=++oe.current,h=()=>k!==oe.current,p=(te,we)=>{h()||(sa(te,{onEnded:()=>{h()||ue(null)},onError:()=>{if(!h()){if((we==null?void 0:we.allowRetry)!==!1){Oi(B.title,B.subtitle),xe(!0),Er(B.title,B.subtitle,25e3,{forceRefresh:!0}).then(he=>{if(!h()){if(he){p(he,{allowRetry:!1});return}ue(null),m({title:"Preview unavailable",description:"Couldn't play this 30s preview.",variant:"destructive"})}}).catch(()=>{h()||(ue(null),m({title:"Preview unavailable",description:"Couldn't play this 30s preview.",variant:"destructive"}))}).finally(()=>{h()||xe(!1)});return}ue(null),m({title:"Preview unavailable",description:"Couldn't play this 30s preview.",variant:"destructive"})}}}),ue(D))},H=Bi(B.title,B.subtitle);if(H){p(H);return}xe(!0);try{const te=await Er(B.title,B.subtitle,25e3);if(h())return;te?p(te):(Cr(),ue(null),m({title:"Preview unavailable",description:"No 30-second preview is available for this track."}))}catch(te){if(h())return;Cr(),ue(null);const we=te instanceof Error&&te.message==="deezer-preview-timeout";m({title:"Preview unavailable",description:we?"Preview took too long to load — try again.":"Couldn't load preview.",variant:"destructive"})}finally{h()||xe(!1)}};return n.useEffect(()=>{if(!t)return;let g=!1;const D=_.slice(y,y+8).filter(P);return(async()=>{for(let h=0;h<D.length;h+=3){if(g)return;await Promise.all(D.slice(h,h+3).map(p=>Er(p.title,p.subtitle,25e3).catch(()=>null)))}})(),()=>{g=!0}},[t,y,_]),n.useEffect(()=>{if(!t||!B||!ge.current||!P(B))return;const g=setTimeout(()=>{K({auto:!0})},200);return()=>clearTimeout(g)},[B==null?void 0:B.vault_taste_id,t]),e.jsx(Hs,{open:t,onOpenChange:a,children:e.jsxs(qs,{side:"bottom",className:"h-[92dvh] p-0 flex flex-col",children:[e.jsx("div",{className:"flex items-center justify-between px-4 pt-4 pb-2 border-b border-border/40",children:e.jsxs("div",{children:[e.jsx("div",{className:"text-base font-semibold tracking-tight",children:"Rate your vault"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:se?[`${W} rated`,ye>0?`${ye}
2 skipped`:null].filter(Boolean).join(" · "):[`${Z} unrated`,W>0?`${W} done`:null,ye>0?`${ye} skipped`:null].filter(Boolean).join(" · ")})]})}),Re.length>1&&e.jsx("div",{className:"border-b border-border/40 px-3 py-2 overflow-x-auto no-scrollbar",children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-max",children:[e.jsxs("button",{onClick:()=>v(null),className:Y("h-7 px-3 rounded-full text-[12px] font-medium whitespace-nowrap transition-colors border",d===null?"bg-foreground text-background border-foreground":"bg-card text-muted-foreground border-border/60 hover:text-foreground"),children:["All · ",r.length]}),Re.map(({label:g,count:D})=>e.jsxs("button",{onClick:()=>v(g),className:Y("h-7 px-3 rounded-full text-[12px] font-medium whitespace-nowrap transition-colors border",d===g?"bg-foreground text-background border-foreground":"bg-card text-muted-foreground border-border/60 hover:text-foreground"),children:[g," · ",D]},g))]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-3 flex flex-col items-center justify-start",children:se||!B?e.jsxs("div",{className:"text-center py-10",children:[e.jsx("div",{className:"text-4xl mb-3",children:"🎉"}),e.jsx("div",{className:"text-lg font-semibold tracking-tight",children:"All caught up!"}),e.jsx("div",{className:"text-sm text-muted-foreground mt-1",children:W>0&&ye>0?`You rated ${W} taste${W===1?"":"s"} and skipped ${ye}.`:W>0?`You rated ${W} taste${W===1?"":"s"} — your recs will get sharper.`:ye>0?`You skipped ${ye} taste${ye===1?"":"s"}.`:"Nothing left to rate right now."}),e.jsxs("div",{className:"mt-6 flex flex-col items-center gap-2",children:[e.jsx(Lt,{onClick:()=>a(!1),children:"Done"}),ye>0&&e.jsxs(Lt,{variant:"ghost",size:"sm",onClick:Ye,children:["Go back to skipped (",ye,")"]})]})]}):e.jsxs("div",{className:"w-full max-w-sm",children:[(()=>{const g=String(B.domain??"").toLowerCase(),D=String(B.level_1??"").toLowerCase(),k=g==="place"||D==="places";return e.jsxs("div",{className:Y("relative w-full mx-auto rounded-2xl overflow-hidden bg-muted/30 border border-border/40 shadow-sm",k?"aspect-[4/3] max-h-[32vh]":"aspect-square max-h-[36vh]"),style:{maxWidth:"min(100%, 36vh)"},children:[B.thumbnail_url||Pe[B.vault_taste_id]?e.jsx("img",{src:B.thumbnail_url||Pe[B.vault_taste_id],alt:B.title,className:"h-full w-full object-cover",loading:"eager"}):e.jsx("div",{className:"h-full w-full bg-gradient-to-br from-muted to-muted/50 flex items-center justify-center",children:e.jsx(ys,{className:"h-10 w-10 text-foreground/30"})}),z&&(()=>{const h=z.kind==="link"?z.Icon:null;return e.jsxs("button",{type:"button",onClick:z.kind==="song"?()=>{K()}:()=>ba(z.url),disabled:re,"aria-label":z.kind==="song"?F===B.vault_taste_id?"Pause preview":"Play preview":z.label,className:"absolute bottom-2 right-2 z-10 inline-flex items-center gap-1 h-8 px-2.5 rounded-full bg-black/60 backdrop-blur text-white text-[11px] font-medium hover:bg-black/75 active:scale-[0.97] transition-all disabled:opacity-60",children:[z.kind==="song"?re?e.jsx(wt,{className:"h-3.5 w-3.5 animate-spin"}):F===B.vault_taste_id?e.jsx(Zn,{className:"h-3.5 w-3.5"}):e.jsx(Jr,{className:"h-3.5 w-3.5"}):h?e.jsx(h,{className:"h-3.5 w-3.5"}):null,z.label]})})()]})})(),e.jsxs("div",{className:"mt-3 text-center",children:[e.jsx("div",{className:"text-lg font-semibold leading-tight line-clamp-2",children:B.title}),(()=>{const g=String(B.level_1??"").toLowerCase(),D=g==="music"||g==="songs",k=(B.subtitle||"").trim(),h=k.toLowerCase(),p=h==="music"||h==="songs"||h===g,H=B.entity_id?ve[B.entity_id]:void 0,te=D&&((p?H||"":k)||H)||"";return D&&te?e.jsx("div",{className:"text-sm text-muted-foreground mt-0.5 line-clamp-1",children:te}):B.level_1?e.jsx("div",{className:"text-sm text-muted-foreground mt-0.5 line-clamp-1",children:B.level_1}):null})()]})]})}),!se&&B&&e.jsx("div",{className:"border-t border-border/40 bg-background/95 backdrop-blur-xl px-2 pt-4 pb-[max(env(safe-area-inset-bottom),16px)]",children:O?e.jsxs("div",{className:"px-2 pb-1",children:[e.jsxs("div",{className:"text-center mb-3",children:[e.jsx("div",{className:"text-2xl mb-1",children:O.emoji}),e.jsx("div",{className:"text-sm font-semibold",children:"Do you want to remove this from your Vault?"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:de,disabled:x,className:"h-12 inline-flex items-center justify-center rounded-xl text-sm font-medium bg-muted text-foreground hover:bg-muted/80 active:scale-[0.98] transition-all disabled:opacity-60",children:"Keep in vault"}),e.jsxs("button",{onClick:De,disabled:x,className:"h-12 inline-flex items-center justify-center gap-1.5 rounded-xl text-sm font-semibold bg-destructive text-destructive-foreground hover:bg-destructive/90 active:scale-[0.98] transition-all disabled:opacity-60",children:[x?e.jsx(wt,{className:"h-4 w-4 animate-spin"}):null,"Remove from Vault"]})]}),e.jsx("button",{onClick:()=>X(null),disabled:x,className:"w-full h-9 mt-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[(()=>{const g=String(B.domain??"").toLowerCase(),D=String(B.level_1??"").toLowerCase(),k=String(B.level_2??"").toLowerCase(),H=(g==="product"||g==="place"||g==="media"&&(D==="books"||D==="book"||new Set(["book","books","ebook","ebooks","audiobook","audiobooks","cookbook","cookbooks","graphic novel","graphic novels","comic book","comic books","
2novel","novels"]).has(k)))&&!!c;return e.jsx("div",{className:"grid grid-cols-5 gap-1.5 mb-3",children:Ti.map(te=>{const we=te.label==="Interested",he={current:null},ee={current:!1},je=()=>{!we||!H||(ee.current=!1,he.current=setTimeout(()=>{ee.current=!0,ne()},500))},Ae=()=>{he.current&&(clearTimeout(he.current),he.current=null)};return e.jsxs("button",{onClick:()=>{if(ee.current){ee.current=!1;return}le(te)},onPointerDown:je,onPointerUp:Ae,onPointerLeave:Ae,onPointerCancel:Ae,disabled:x,className:Y("flex flex-col items-center justify-center gap-1.5 h-[76px] px-0.5 rounded-xl border border-border/60 bg-card/60 hover:bg-card active:scale-[0.96] transition-all overflow-hidden",x&&"opacity-60"),"aria-label":we&&H?`${te.label} — hold to add to wishlist`:te.label,title:we&&H?"Hold to add to wishlist":void 0,children:[e.jsx("span",{className:"text-[24px] leading-none",children:te.emoji}),e.jsx("span",{className:"text-[10px] font-medium text-muted-foreground leading-[1.05] text-center break-words",children:te.label})]},te.label)})})})(),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:C,disabled:x||E.length===0,className:Y("h-11 inline-flex items-center justify-center gap-1.5 rounded-xl text-sm font-medium transition-colors",E.length===0?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),"aria-label":"Undo previous rating",children:[e.jsx(_a,{className:"h-4 w-4"}),"Undo"]}),e.jsxs("button",{onClick:Ee,disabled:x,className:"h-11 inline-flex items-center justify-center gap-1.5 rounded-xl text-sm font-medium text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:[x?e.jsx(wt,{className:"h-4 w-4 animate-spin"}):e.jsx(ya,{className:"h-4 w-4"}),"Skip"]})]})]})})]})})}function zi(t){return(t||"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9\s]+/g," ").replace(/\s+/g," ").trim()}const Rs=new Map,Or=4e4;function hn(t){const a=Rs.get(t);if(a!==void 0)return a;const r=zi(t);if(Rs.size>=Or){let s=Or/2;for(const i of Rs.keys())if(Rs.delete(i),--s<=0)break}return Rs.set(t,r),r}function Ui(t){return t<=3?0:t<=7?1:2}function pn(t,a,r){if(r<=0)return t===a;if(Math.abs(t.length-a.length)>r)return!1;const s=[];for(let i=0;i<=t.length;i++)s.push(new Array(a.length+1).fill(0)),s[i][0]=i;for(let i=0;i<=a.length;i++)s[0][i]=i;for(let i=1;i<=t.length;i++){let c=s[i][0];for(let m=1;m<=a.length;m++){const d=t[i-1]===a[m-1]?0:1;let v=Math.min(s[i][m-1]+1,s[i-1][m]+1,s[i-1][m-1]+d);i>1&&m>1&&t[i-1]===a[m-2]&&t[i-2]===a[m-1]&&(v=Math.min(v,s[i-2][m-2]+1)),s[i][m]=v,v<c&&(c=v)}if(c>r)return!1}return s[t.length][a.length]<=r}const tr=new Map;function xn(t){const a=tr.get(t);if(a!==void 0)return a;const r=t.split(" ").filter(Boolean);return tr.size>=Or&&tr.clear(),tr.set(t,r),r}function Wi(t,a,r){if(!t||r.includes(t))return!0;const s=Ui(t.length);if(s===0)return!1;for(const i of a)if(i.startsWith(t)||t.startsWith(i)||pn(t,i,s)||i.length>t.length&&pn(t,i.slice(0,t.length),s))return!0;return!1}function us(t,...a){const r=hn(t);if(!r)return!0;const s=a.filter(Boolean).join(" ");if(!s)return!1;const i=hn(s);if(!i)return!1;if(i.includes(r))return!0;const c=xn(i);return xn(r).every(d=>Wi(d,c,i))}const gn={media:"Media",place:"Places",product:"Products",creations:"Creations"},Gi={place:"hsl(218, 55%, 35%)",product:"hsl(24, 70%, 48%)",media:"hsl(220, 45%, 50%)",creations:"hsl(280, 45%, 50%)"},Hi=new Set(["media","place","product","creations"]),qi=({domain:t})=>{switch(t){case"place":return e.jsx(ht,{className:"h-3.5 w-3.5"});case"product":return e.jsx(es,{className:"h-3.5 w-3.5"});case"creations":return e.jsx(ws,{className:"h-3.5 w-3.5"});default:return e.jsx($n,{className:"h-3.5 w-3.5"})}},Vi=({trigger:t,extraSection:a}={})=>{const{toast:r}=js(),s=lr(),[i,c]=n.useState(null),[m,d]=n.useState(0),[v,_]=n.useState(0),[M,y]=n.useState(0),[j,S]=n.useState(0),[x,L]=n.useState(0),[W,V]=n.useState(null),[E,J]=n.useState(null),[O,X]=n.useState(!1),[ge,Re]=n.useState(!1),[ve,it]=n.useState([]),[B,Z]=n.useState([]),[se,G]=n.useState([]),ye=Da(),Ye=n.useRef(ye);n.useEffect(()=>{Ye.current=ye},[ye]);
2const[Pe,Ve]=n.useState(null),[Le,$]=n.useState(new Set),[le,ne]=n.useState(new Set),[de,De]=n.useState(null),[Ee,C]=n.useState(null);n.useEffect(()=>{re()},[]);const z="fyra-score-cache-v1",F=h=>{try{const p=sessionStorage.getItem(`${z}:${h}`);if(!p)return!1;const H=JSON.parse(p);return Array.isArray(H.topL1Categories)&&Z(H.topL1Categories),Array.isArray(H.domainBreakdown)&&it(H.domainBreakdown),Array.isArray(H.tasteInsights)&&G(H.tasteInsights.map(te=>({...te,icon:an}))),!0}catch{return!1}},ue=(h,p)=>{try{const H=`${z}:${h}`,te=sessionStorage.getItem(H),we={...te?JSON.parse(te):{},...p};Array.isArray(we.tasteInsights)&&(we.tasteInsights=we.tasteInsights.map(he=>({label:he.label,value:he.value,color:he.color}))),sessionStorage.setItem(H,JSON.stringify(we))}catch{}},re=async(h=0)=>{try{const{data:p,error:H}=await U.functions.invoke("invite-tree");if(H)throw H;c((p==null?void 0:p.score)??0),d((p==null?void 0:p.invite_count)??0),_((p==null?void 0:p.direct_invite_count)??0),y((p==null?void 0:p.taste_count)??0),S((p==null?void 0:p.category_count)??0),L((p==null?void 0:p.stash_count)??0),V((p==null?void 0:p.tree)??null),J((p==null?void 0:p.inviter)??null)}catch(p){console.error(`Failed to fetch Fyra Score (attempt ${h+1}):`,p),h<3&&setTimeout(()=>re(h+1),1500*(h+1))}},xe=async()=>{var h,p;try{const{data:{session:H}}=await U.auth.getSession(),te=(H==null?void 0:H.user)??null;if(!te)return;const{data:we,error:he}=await U.from("user_vault_taste_search").select("entity_id, domain, level_1, level_2, created_at").eq("user_id",te.id).limit(1e4);if(he){console.error("Failed to fetch breakdown:",he);return}if(!we||we.length===0)return;const ee={},je={};let Ae=null,pt=null;const ae={Songs:"Music",song:"Music",songs:"Music",Video:"Movies",video:"Movies",Audio:"Podcasts",audio:"Podcasts",Publishers:"Books",publishers:"Books",podcast:"Podcasts",other:"Music","Visual Art":"Art","Craft & Making":"Crafting","Religious & Spiritual":"Spiritual","Home & Living":"Home","Home & Kitchen":"Home","Garden & Outdoor":"Backyard","Outdoor Living":"Backyard","Office & Stationery":"Tools","Home Improvement":"Tools","Sporting Goods":"Sports","Pet Supplies":"Pets","Baby & Kids":"Baby","Beauty & Care":"Beauty","Games & Puzzles":"Games"},ut={media:"Media",place:"Places",product:"Products",creations:"Creations",creation:"Creations"};for(const Ue of we){const tt=Ue.domain||"media",R=tt==="creation"?"creations":tt;if(!Hi.has(R))continue;ee[R]=(ee[R]||0)+1;let ie=(Ue.level_1||"").trim();(!ie||ie==="Other"||ie==="other")&&(ie=R==="media"?"Music":"Uncategorized");let st=ie;if(R==="creations"){const We=(h=Ye.current)==null?void 0:h.getL1NameByLabel("creations",ie);We?st=We:!((p=Ye.current)!=null&&p.ready)&&ie!=="Uncategorized"?st="Recipes":st=ae[ie]||ie}else st=ae[ie]||ie;je[st]||(je[st]={count:0,domain:ut[R]||R}),je[st].count+=1,Ue.created_at&&((!Ae||Ue.created_at<Ae)&&(Ae=Ue.created_at),(!pt||Ue.created_at>pt)&&(pt=Ue.created_at))}const _e=Object.values(ee).reduce((Ue,tt)=>Ue+tt,0),Ze=Object.entries(ee).map(([Ue,tt])=>({domain:Ue,count:tt,percentage:Math.round(tt/_e*100)})).sort((Ue,tt)=>tt.count-Ue.count);it(Ze);const et=Object.entries(je).filter(([Ue])=>Ue!=="Uncategorized").sort((Ue,tt)=>tt[1].count-Ue[1].count).slice(0,5).map(([Ue,{count:tt,domain:R}])=>({name:Ue,count:tt,domain:R}));Z(et);const Te=[],bt=te.created_at?new Date(te.created_at):null;if(bt){const Ue=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];Te.push({icon:an,label:"Member Since",value:`${Ue[bt.getMonth()]} ${bt.getFullYear()}`,color:"hsl(280, 45%, 50%)"})}G(Te),ue(te.id,{domainBreakdown:Ze,topL1Categories:et,tasteInsights:Te})}catch(H){console.error("Failed to fetch breakdown:",H)}},oe=async()=>{try{const{data:{session:h}}=await U.auth.getSession(),p=(h==null?void 0:h.user)??null;if(!p)return;Ve(p.id);const[H,te,we,he]=await Promise.all([U.from("user_connections").select("connected_user_id").eq("user_id",p.id).eq("status","accepted"),U.from("user_connections").select("user_id").eq("connected_user_id",p.id).eq("status","accepted"),U.from("user_connections").select("connected_user_id").eq("user_id",p.id).eq("status","pen
2ding"),U.from("user_connections").select("user_id").eq("connected_user_id",p.id).eq("status","pending")]),ee=new Set;ee.add(p.id),(H.data||[]).forEach(Ae=>ee.add(Ae.connected_user_id)),(te.data||[]).forEach(Ae=>ee.add(Ae.user_id)),$(ee);const je=new Set;(we.data||[]).forEach(Ae=>je.add(Ae.connected_user_id)),(he.data||[]).forEach(Ae=>je.add(Ae.user_id)),ne(je)}catch(h){console.error("Failed to fetch connections:",h)}},P=async()=>{X(!0),C(null);let h=!1;try{const{data:{session:p}}=await U.auth.getSession(),H=(p==null?void 0:p.user)??null;H&&(h=F(H.id))}catch{}W||(h||Re(!0),await re(),Re(!1)),xe(),oe()},K=n.useCallback(h=>{h.user_id!==Pe&&C(h)},[Pe]),g=h=>h===Pe?"self":Le.has(h)?"connected":le.has(h)?"pending":"available",D=async h=>{if(Pe){De(h);try{const{error:p}=await U.from("user_connections").insert({user_id:Pe,connected_user_id:h,status:"pending"});if(p)throw p;ne(H=>new Set([...H,h])),r({title:"Connection request sent!"}),C(null)}catch(p){console.error("Failed to send connection request:",p),r({title:"Failed to send request",variant:"destructive"})}finally{De(null)}}},k=h=>{X(!1),s(`/x-gifting-friend/${h}`)};return i===null?null:e.jsxs(e.Fragment,{children:[t?e.jsx("span",{onClick:P,className:"contents cursor-pointer",children:t}):e.jsxs("button",{onClick:P,className:"w-full flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-full bg-gradient-to-r from-orange-500/15 via-amber-500/15 to-yellow-500/15 hover:from-orange-500/25 hover:via-amber-500/25 hover:to-yellow-500/25 border border-orange-400/30 shadow-sm shadow-orange-500/10 transition-all duration-200",title:"Fyra Points",children:[e.jsx(nn,{className:"h-3.5 w-3.5 text-orange-500 drop-shadow-sm"}),e.jsx("span",{className:"text-xs font-bold bg-gradient-to-r from-orange-600 to-amber-500 bg-clip-text text-transparent",children:i})]}),e.jsx(cr,{open:O,onOpenChange:h=>{X(h),h||C(null)},children:e.jsx(dr,{className:"max-w-lg max-h-[88vh] overflow-hidden flex flex-col p-0 gap-0 border-0 bg-transparent shadow-none [&>button]:hidden",children:e.jsx(Oa,{children:O&&e.jsxs(Ba.div,{initial:{opacity:0,scale:.9,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.9,y:20},transition:{type:"spring",damping:25,stiffness:350},className:"relative rounded-2xl overflow-hidden bg-gradient-to-b from-background via-background to-background border border-border/50 shadow-2xl flex flex-col max-h-[88vh]",children:[e.jsxs("div",{className:"relative overflow-hidden flex-shrink-0",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary/20 via-primary/10 to-accent/15"}),e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-primary/10 rounded-full blur-3xl -translate-y-8 translate-x-8"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-accent/10 rounded-full blur-2xl translate-y-4 -translate-x-4"}),e.jsx("button",{onClick:()=>X(!1),className:"absolute top-3 right-3 z-10 h-8 w-8 rounded-full bg-background/80 backdrop-blur-sm border border-border/50 flex items-center justify-center text-muted-foreground hover:text-foreground transition-colors",children:e.jsx("span",{className:"text-lg leading-none",children:"×"})}),e.jsxs("div",{className:"relative px-5 pt-4 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-gradient-to-br from-primary to-primary/70 flex items-center justify-center shadow-lg shadow-primary/25",children:e.jsx(nn,{className:"h-5 w-5 text-primary-foreground"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Fyra Points"})}),e.jsx("p",{className:"text-2xl font-bold text-foreground tracking-tight",children:i==null?void 0:i.toLocaleString()}),e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-0.5 flex items-center gap-1",children:[e.jsx(ys,{className:"h-2.5 w-2.5"}),"Unlocks exclusive perks (coming soon)"]})]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-1.5",children:[e.jsxs("div",{className:"rounded-xl bg-background/70 backdrop-blur-sm border border-border/50 px-1 py-2 text-center min-w-0",children:[e.jsx("p",{className:"text-[9px] font-medium uppercase tracking-wide text-muted-foreground truncate",children:"Tastes"}),e.jsx("p",{className:"text-base font-bold text-foreground tabular-nums",children:M==null?void 0:M.toLocaleStr
2ing()}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:"×1"})]}),e.jsxs("div",{className:"rounded-xl bg-background/70 backdrop-blur-sm border border-border/50 px-1 py-2 text-center min-w-0",children:[e.jsx("p",{className:"text-[9px] font-medium uppercase tracking-wide text-muted-foreground truncate",children:"Categories"}),e.jsx("p",{className:"text-base font-bold text-foreground tabular-nums",children:j}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:"×25"})]}),e.jsxs("div",{className:"rounded-xl bg-background/70 backdrop-blur-sm border border-border/50 px-1 py-2 text-center min-w-0",children:[e.jsx("p",{className:"text-[9px] font-medium uppercase tracking-wide text-muted-foreground truncate",children:"Stashes"}),e.jsx("p",{className:"text-base font-bold text-foreground tabular-nums",children:x}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:"×50"})]}),e.jsxs("div",{className:"rounded-xl bg-background/70 backdrop-blur-sm border border-border/50 px-1 py-2 text-center min-w-0",title:"People you personally invited",children:[e.jsx("p",{className:"text-[9px] font-medium uppercase tracking-wide text-muted-foreground truncate",children:"Invitees"}),e.jsx("p",{className:"text-base font-bold text-foreground tabular-nums",children:v}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:"×50"})]})]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:[a&&e.jsx("div",{className:"border-t border-border/30 px-5 py-4",children:a}),B.length>0&&e.jsxs("div",{className:"border-t border-border/30 px-5 py-4",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3",children:"Your Top 5 Categories"}),e.jsx("div",{className:"space-y-2",children:B.map((h,p)=>{const H=Object.keys(gn).find(we=>gn[we]===h.domain)||"media",te=Gi[H]||"hsl(var(--muted-foreground))";return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground w-4 text-right tabular-nums",children:p+1}),e.jsx("div",{className:"h-7 w-7 rounded-lg flex items-center justify-center shrink-0",style:{backgroundColor:`${te}1f`,color:te},children:e.jsx(qi,{domain:H})}),e.jsx("span",{className:"text-sm font-medium text-foreground flex-1 truncate",children:h.name}),e.jsx("span",{className:"inline-flex items-center text-[10px] font-medium px-2 py-0.5 rounded-full min-w-[60px] justify-center",style:{backgroundColor:`${te}1f`,color:te},children:h.domain}),e.jsx("span",{className:"text-sm text-muted-foreground tabular-nums w-10 text-right",children:h.count.toLocaleString()})]},h.name)})})]}),e.jsxs("div",{className:"border-t border-border/30 px-5 py-4",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3",children:"Network"}),e.jsxs("div",{className:"relative h-[260px] rounded-xl overflow-hidden bg-muted/20 border border-border/30",children:[ge?e.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"h-8 w-8 rounded-full border-2 border-primary/30 border-t-primary animate-spin"}),e.jsx("span",{className:"text-sm",children:"Loading your network..."})]})}):W?e.jsx(Ra,{tree:W,onNodeClick:K}):e.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"No invite data available"}),Ee&&e.jsxs("div",{className:"absolute bottom-3 left-3 right-3 bg-card border border-border rounded-xl p-3 shadow-xl backdrop-blur-sm flex items-center gap-3 z-20",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:Ee.label}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:g(Ee.user_id)==="connected"?"Already connected":g(Ee.user_id)==="pending"?"Request pending":"Not yet connected"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[g(Ee.user_id)==="connected"&&e.jsxs(Lt,{size:"sm",variant:"outline",onClick:()=>k(Ee.user_id),className:"gap-1.5 h-8",children:[e.jsx(Bn,{className:"h-3.5 w-3.5"}),"View"]}
2),g(Ee.user_id)==="available"&&e.jsxs(Lt,{size:"sm",onClick:()=>D(Ee.user_id),disabled:de===Ee.user_id,className:"gap-1.5 h-8",children:[de===Ee.user_id?e.jsx(wt,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx($a,{className:"h-3.5 w-3.5"}),"Connect"]}),g(Ee.user_id)==="pending"&&e.jsx("span",{className:"text-xs text-muted-foreground px-2",children:"Pending"})]})]})]})]}),E&&e.jsx("div",{className:"border-t border-border/30 px-5 py-3 flex items-center justify-center",children:e.jsxs("button",{onClick:()=>k(E.user_id),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-muted/50 hover:bg-muted border border-border/50 transition-colors",title:"View profile",children:[e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-wider text-muted-foreground",children:"Invited by"}),E.avatar_url?e.jsx("img",{src:On(E.avatar_url),alt:"",className:"h-4 w-4 rounded-full object-cover border border-border/50"}):e.jsx("div",{className:"h-4 w-4 rounded-full bg-primary/20 flex items-center justify-center text-[8px] font-bold text-primary",children:((E.first_name||E.username||"?")[0]||"?").toUpperCase()}),e.jsx("span",{className:"text-[11px] font-semibold text-foreground",children:E.first_name?[E.first_name,E.last_name].filter(Boolean).join(" "):E.username||"A Fyra user"})]})})]})]})})})})]})},Fi=t=>t.kind==="region"||t.kind==="subregion"?ht:t.kind==="creator"?t.domain==="product"?es:Ha:t.kind==="genre"?t.domain==="media"?Dn:ar:t.domain==="place"?ht:t.domain==="product"?es:t.domain==="media"?mr:t.domain==="creations"?ws:ar,Ki=t=>t.kind==="region"||t.kind==="subregion"?"from-emerald-500/25 to-emerald-500/5 text-emerald-600":t.kind==="genre"?"from-violet-500/25 to-violet-500/5 text-violet-600":t.kind==="creator"?"from-sky-500/25 to-sky-500/5 text-sky-600":"from-amber-500/25 to-amber-500/5 text-amber-600",Yi=({open:t,onOpenChange:a,userId:r,initialSuggestions:s,onCreated:i})=>{const{toast:c}=js(),[m,d]=n.useState(!1),[v,_]=n.useState(s||[]),[M,y]=n.useState(null),[j,S]=n.useState(!1),x=n.useCallback(async()=>{d(!0),S(!1);try{const{data:V,error:E}=await U.functions.invoke("stash-suggestions",{body:{}});if(E)throw E;_((V==null?void 0:V.suggestions)||[])}catch(V){console.warn("[StashSuggestions] load failed",V),S(!0)}finally{d(!1)}},[]);n.useEffect(()=>{if(t){if(s!=null&&s.length){_(s);return}x()}},[t,x,s]);const L=async V=>{if(_(J=>J.filter(O=>O.key!==V.key)),!r)return;const{error:E}=await U.from("user_stash_suggestion_dismissals").upsert({user_id:r,suggestion_key:V.key},{onConflict:"user_id,suggestion_key"});E&&console.warn("[StashSuggestions] dismiss failed",E)},W=async V=>{if(!(!r||M)){y(V.key);try{const{data:E,error:J}=await U.from("user_guides").insert({user_id:r,name:V.label,extra:{from_suggestion:V.key}}).select("id").single();if(J)throw J;const O=V.taste_ids.map(X=>({guide_id:E.id,taste_id:X,display_name:""}));if(O.length){const{error:X}=await U.from("user_guide_items").insert(O);if(X)throw X}await U.from("user_stash_suggestion_dismissals").upsert({user_id:r,suggestion_key:V.key},{onConflict:"user_id,suggestion_key"}),c({title:`“${V.label}” stash created`,description:`${V.count} tastes added.`}),i(E.id,V.label)}catch(E){console.error("[StashSuggestions] create failed",E),c({title:"Couldn't create that stash",description:E==null?void 0:E.message,variant:"destructive"})}finally{y(null)}}};return e.jsx(Hs,{open:t,onOpenChange:a,children:e.jsxs(qs,{side:"bottom",className:"rounded-t-3xl p-0 max-h-[88dvh] flex flex-col",children:[e.jsx(fa,{className:"px-5 pt-5 pb-3 text-left",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-2xl bg-gradient-to-br from-amber-400/30 to-amber-500/10 flex items-center justify-center",children:e.jsx(Tr,{className:"h-5 w-5 text-amber-500"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(ha,{className:"text-base leading-tight",children:"Suggested stashes"}),e.jsx("p",{className:"text-[12px] text-muted-foreground leading-tight mt-0.5",children:"Themes you've saved a lot of — one tap to turn them into a stash."})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-[calc(env(safe-area-inset-bottom)+1.25rem)]",children:m?e.jsxs("div",{className:"pt-1",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-3",children:[e.jsx(wt,{className:"h-4 w-4 animate-spin text-amber-500"}),e.jsx("p",{className:"text-[13px] font-medium text-muted-foreground",children:"Scanning your vault for themes…"})]}),e.jsx("div",{className:"space-y-3",children:[0,1,2].map(V=>e.jsxs("div",{className:"h-[104px] rounded-2xl border border-border/60 bg-muted/30 p-3 overflow-hidden relative",style:{animationDelay:`${V*120}ms`},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-xl bg-muted animate-pulse"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-3 w-2/5 rounded bg-muted animate-pulse"}),e.jsx("div",{className:"h-2.5 w-1/4 rounded bg-muted animate-pulse"})]})]}),e.jsx("div",{className:"mt-3 flex gap-2",children:[0,1,2,3].map(E=>e.jsx("div",{className:"h-10 w-10 rounded-lg bg-muted animate-pulse"},E))}),e.jsx("div",{className:"pointer-events-none absolute inset-0 animate-shimmer bg-gradient-to-r from-transparent via-foreground
2/[0.06] to-transparent"})]},V))}),e.jsx("p",{className:"pt-4 text-center text-[12px] text-muted-foreground",children:"This can take a few seconds for large vaults."})]}):j?e.jsxs("div",{className:"py-12 text-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Couldn't load suggestions."}),e.jsx("button",{onClick:x,className:"mt-3 text-sm font-semibold text-primary",children:"Try again"})]}):v.length===0?e.jsxs("div",{className:"py-12 text-center px-6",children:[e.jsx("div",{className:"mx-auto h-12 w-12 rounded-2xl bg-muted flex items-center justify-center",children:e.jsx(mt,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("p",{className:"mt-3 text-sm font-semibold",children:"You're all caught up"}),e.jsx("p",{className:"mt-1 text-[12.5px] text-muted-foreground",children:"Save 10+ tastes around a new place, artist, or category and we'll suggest a stash for it."})]}):e.jsx("div",{className:"space-y-3 pt-1",children:v.map(V=>{const E=Fi(V),J=M===V.key;return e.jsxs("div",{className:"relative rounded-2xl border border-border/60 bg-card overflow-hidden shadow-sm",children:[e.jsx("button",{onClick:()=>L(V),"aria-label":`Dismiss ${V.label} suggestion`,className:"absolute top-2 right-2 z-10 h-7 w-7 rounded-full bg-background/85 backdrop-blur border border-border/60 flex items-center justify-center text-muted-foreground active:scale-95 transition",children:e.jsx(_s,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"p-3.5",children:[e.jsxs("div",{className:"flex items-start gap-3 pr-8",children:[e.jsx("div",{className:Y("h-9 w-9 shrink-0 rounded-xl bg-gradient-to-br flex items-center justify-center",Ki(V)),children:e.jsx(E,{className:"h-4.5 w-4.5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("h3",{className:"font-semibold text-[15px] tracking-tight truncate",children:V.label}),e.jsxs("span",{className:"text-[11px] font-semibold text-muted-foreground shrink-0",children:[V.count," tastes"]})]}),e.jsx("p",{className:"text-[12px] text-muted-foreground truncate mt-0.5",children:V.samples.length?V.samples.join(" · "):V.blurb})]})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("div",{className:"flex -space-x-2",children:V.thumbs.slice(0,4).map((O,X)=>e.jsx("div",{className:"h-9 w-9 rounded-xl overflow-hidden border-2 border-card bg-muted",children:e.jsx("img",{src:O,alt:"",loading:"lazy",className:"h-full w-full object-cover"})},X))}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:()=>W(V),disabled:J,className:"h-9 px-4 rounded-full bg-primary text-primary-foreground text-[13px] font-semibold inline-flex items-center gap-1.5 active:scale-[0.97] transition disabled:opacity-70",children:[J?e.jsx(wt,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Tr,{className:"h-3.5 w-3.5"}),J?"Creating…":"Create stash"]})]})]})]},V.key)})})})]})})};function Fn({open:t,onOpenChange:a,userId:r,onAdded:s}){const[i,c]=n.useState(""),[m,d]=n.useState(""),[v,_]=n.useState([]),[M,y]=n.useState(null),[j,S]=n.useState(!1),[x,L]=n.useState(!1);n.useEffect(()=>{t||(c(""),d(""),_([]),y(null),L(!1))},[t]),n.useEffect(()=>{if(!t)return;const E=m.trim();if(E.length<3){_([]);return}let J=!1;S(!0);const O=setTimeout(async()=>{try{const{data:X,error:ge}=await U.functions.invoke("search-addresses",{body:{query:E}});if(J)return;if(ge)throw ge;_((X==null?void 0:X.suggestions)||[])}catch(X){console.warn("[AddSavedLocationDialog] search failed",X),J||_([])}finally{J||S(!1)}},300);return()=>{J=!0,clearTimeout(O)}},[m,t]);const W=!!r&&!!M&&i.trim().length>0&&!x,V=async()=>{if(!(!r||!M||!i.trim())){L(!0);try{const{data:E}=await U.from("user_saved_locations").select("id, sort_order").eq("user_id",r),J=!E||E.length===0,O=(E||[]).reduce((Re,ve)=>Math.max(Re,Number(ve.sort_order)||0),0),{data:X,error:ge}=await U.from("user_saved_locations").insert({user_id:r,name:i.trim(),city:M.city||null,state:M.state||null,country:M.country||null,latitude:M.latitude,longitude:M.longitude,is_home:J,icon:"map-pin",address:M.label,sort_order:J?1:O+1}).select("id, name, latitude, longitude, is_home").single();if(ge)throw ge;Qr.success(`Location "${i.trim()}" saved`),s({id:X.id,name:X.name,lat:Number(X.latitude),lng:Number(X.longitude),is_home:!!X.is_home}),a(!1)}
2catch(E){console.error("[AddSavedLocationDialog] save failed",E),Qr.error((E==null?void 0:E.message)||"Failed to save location")}finally{L(!1)}}};return e.jsx(cr,{open:t,onOpenChange:a,children:e.jsxs(dr,{className:"max-w-md max-h-[90dvh] overflow-y-auto",children:[e.jsxs(Ur,{children:[e.jsx(Wr,{children:"Add saved location"}),e.jsx(ia,{children:"Save a place you want to measure distance from. It will also appear in Settings → Saved locations."})]}),e.jsxs("div",{className:"space-y-4 mt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(on,{htmlFor:"loc-name",children:"Name"}),e.jsx(ds,{id:"loc-name",placeholder:"e.g. Lake House",value:i,onChange:E=>c(E.target.value),style:{fontSize:16}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(on,{htmlFor:"loc-search",children:"Address"}),e.jsxs("div",{className:"relative",children:[e.jsx(Us,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ds,{id:"loc-search",placeholder:"Search for an address...",value:m,onChange:E=>{d(E.target.value),y(null)},className:"pl-9",style:{fontSize:16}}),j&&e.jsx(wt,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 animate-spin text-muted-foreground"})]}),M&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-border bg-muted/40 p-2 text-sm",children:[e.jsx(ht,{className:"h-4 w-4 mt-0.5 text-primary shrink-0"}),e.jsx("span",{className:"flex-1",children:M.label})]}),!M&&v.length>0&&e.jsx("div",{className:"max-h-56 overflow-y-auto rounded-md border border-border divide-y divide-border",children:v.map((E,J)=>e.jsxs("button",{type:"button",onClick:()=>{y(E),d(E.label),_([])},className:"w-full text-left px-3 py-2 hover:bg-muted text-sm flex items-start gap-2",children:[e.jsx(ht,{className:"h-4 w-4 mt-0.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"flex-1",children:E.label})]},`${E.latitude},${E.longitude},${J}`))})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(Lt,{variant:"ghost",onClick:()=>a(!1),disabled:x,children:"Cancel"}),e.jsx(Lt,{onClick:V,disabled:!W,children:x?e.jsx(wt,{className:"h-4 w-4 animate-spin"}):"Save location"})]})]})]})})}const bn=/^(?:\d{4}\s+)?(?:.*\s)?(?:remaster(?:ed)?|remastered\s+version|deluxe(?:\s+edition)?|album\s+version|single\s+version|radio\s+(?:edit|version)|mono|stereo|explicit|clean|bonus\s+track|short\s+version|expanded(?:\s+edition)?|anniversary(?:\s+edition)?|reissue|feat\.?\s+.*|ft\.?\s+.*|featuring\s+.*)$/i,vn=/\b(live|unplugged|acoustic|remix|cover|instrumental|vocal|demo|session|sessions|karaoke|reprise|mix)\b/i;function Ji(t){let a=t;for(let r=0;r<4;r++){const i=a.replace(/\s*[([]([^)\]]*)[)\]]\s*$/,(c,m)=>{const d=String(m).trim();return d?vn.test(d)?c:bn.test(d)?"":c:""}).replace(/\s+[-–—]\s+([^-–—]+)$/,(c,m)=>{const d=String(m).trim();return vn.test(d)?c:bn.test(d)?"":c});if(i===a)break;a=i}return a.trim()}const Pr=t=>t.toLowerCase().replace(/[^a-z0-9]+/g," ").replace(/\s+/g," ").trim(),Qi=t=>t.replace(/^(?:song|track|single|album|music|movie|film|show|series|book|podcast|episode)s?\s*(?:by|[:·•\-–—])\s*/i,"").trim();function Xi(t,a){const r=(t||"").trim().toLowerCase(),s=(a||"").trim().toLowerCase();return r==="music"||r==="songs"?!0:["song","songs","music","album","albums"].includes(s)}function Zi(t){const a=String(t.title||"").trim(),r=Pr(Qi(String(t.subtitle||"")));return Xi(t.level_1,t.level_2)?`song|${Pr(Ji(a))}|${r}`:`${(t.domain||"").toLowerCase()}|${Pr(a)}|${r}`}function eo(t){const a=new Map,r=[];for(const c of t){const m=Zi(c),d=a.get(m);d?d.push(c):(a.set(m,[c]),r.push(m))}const s=[],i=new Map;for(const c of r){const m=a.get(c);let d=m[0];if(m.length>1){const v=_=>(_.thumbnail_url?2:0)+(/[([]/.test(String(_.title||""))?0:1);for(const _ of m)v(_)>v(d)&&(d=_);i.set(d.vault_taste_id,m.filter(_=>_.vault_taste_id!==d.vault_taste_id).map(_=>_.vault_taste_id))}s.push(d)}return{items:s,siblings:i}}const os={place:"hsl(152, 55%, 38%)",product:"hsl(24, 85%, 52%)",media:"hsl(275, 65%, 70%)",creation:"hsl(212, 80%, 52%)"},_n="hsl(var(--primary))",to=t=>e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",...t,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 6.5 8.2 9.3l1.5 4.5h4.6l1.5-4.5z"}),e.jsx("path",{d:"M12 6.5V2.2"}),e.jsx("path",{d:"m8.2 9.3-4.1-1.3"}),e.jsx("path",{d:"m15.8 9.3 4.1-1.3"}),e.jsx("path",{d:"m9.7 13.8-2.5 3.5"}),e.jsx("path",{d:"m14.3 13.8 2.5 3.5"})]}),so=t=>e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",...t,children:[e.jsx("path",{d:"M9 2.5h4.5L15 6.5h-7z"}
2),e.jsx("rect",{x:"7.5",y:"6.5",width:"8",height:"3.2",rx:"0.6"}),e.jsx("rect",{x:"8.5",y:"9.7",width:"6",height:"12",rx:"1"})]}),ro=[{re:/restaurant|cafe|coffee|eatery|food|dining|bistro/,Icon:Gn},{re:/bar|wine|cocktail|brewery|pub|spirit|winery|vineyard|cellars/,Icon:cn},{re:/hotel|lodging|inn|resort|stay/,Icon:ci},{re:/park|garden/,Icon:ja},{re:/trail|hike|mountain|outdoor|nature/,Icon:di},{re:/museum|gallery|landmark|monument|attraction|sight/,Icon:ui},{re:/beach|surf|water/,Icon:ht},{re:/travel|airport|flight/,Icon:mi},{re:/movie|film|cinema/,Icon:$n},{re:/show|tv|series/,Icon:fi},{re:/music|song|album|artist/,Icon:na},{re:/book|novel|read/,Icon:ur},{re:/podcast|audio/,Icon:hi},{re:/game|gaming/,Icon:pi},{re:/creator|influencer/,Icon:ws},{re:/recipe|cook|meal|dish|cuisine/,Icon:xi},{re:/build|construction|diy|renovation|woodwork|furniture build/,Icon:dn},{re:/craft|knit|sew|textile|maker|making/,Icon:gi},{re:/writ|poem|story|journal|essay/,Icon:bi},{re:/production|film making|video|short/,Icon:Dn},{re:/art|paint|draw|sketch/,Icon:ws},{re:/beverage|drink|soda|juice|tea(?!\s*tree)/,Icon:cn},{re:/grocery|pantry|snack/,Icon:Na},{re:/baby|infant|nursery/,Icon:vi},{re:/toy|puzzle|lego|plaything/,Icon:ka},{re:/pet/,Icon:Sa},{re:/electronic|gadget|tech/,Icon:_i},{re:/^tools?$/,Icon:un},{re:/home improvement|hardware|tool(?!s?$)/,Icon:dn},{re:/beauty|skincare|cosmetic|fragrance|makeup|lipstick/,Icon:so},{re:/wellness|supplement|vitamin|mindful|meditation|therapy|recovery/,Icon:Un},{re:/apparel|cloth|fashion|shoe|accessor/,Icon:yi},{re:/backyard|outdoor living|patio|yard|garden|grill|bbq/,Icon:wi},{re:/home|decor|furniture|kitchen|appliance/,Icon:Ca},{re:/fitness|sport|gym|workout|athletic/,Icon:to},{re:/auto|car|vehicle/,Icon:Ma},{re:/work|office|business/,Icon:ji},{re:/camera|photo/,Icon:Ni},{re:/service|repair|maintenance/,Icon:un},{re:/product|shop|store/,Icon:es},{re:/place|venue|spot/,Icon:ht}];function yn(t){const a=(t||"").toLowerCase();for(const r of ro)if(r.re.test(a))return{Icon:r.Icon};return{Icon:ki}}const Br={alabama:"al",alaska:"ak",arizona:"az",arkansas:"ar",california:"ca",colorado:"co",connecticut:"ct",delaware:"de",florida:"fl",georgia:"ga",hawaii:"hi",idaho:"id",illinois:"il",indiana:"in",iowa:"ia",kansas:"ks",kentucky:"ky",louisiana:"la",maine:"me",maryland:"md",massachusetts:"ma",michigan:"mi",minnesota:"mn",mississippi:"ms",missouri:"mo",montana:"mt",nebraska:"ne",nevada:"nv","new hampshire":"nh","new jersey":"nj","new mexico":"nm","new york":"ny","north carolina":"nc","north dakota":"nd",ohio:"oh",oklahoma:"ok",oregon:"or",pennsylvania:"pa","rhode island":"ri","south carolina":"sc","south dakota":"sd",tennessee:"tn",texas:"tx",utah:"ut",vermont:"vt",virginia:"va",washington:"wa","west virginia":"wv",wisconsin:"wi",wyoming:"wy","district of columbia":"dc","washington dc":"dc","washington d.c.":"dc"},wn={"united states":"🇺🇸",usa:"🇺🇸",us:"🇺🇸",america:"🇺🇸",canada:"🇨🇦",mexico:"🇲🇽",france:"🇫🇷",spain:"🇪🇸",portugal:"🇵🇹",italy:"🇮🇹",germany:"🇩🇪",netherlands:"🇳🇱",belgium:"🇧🇪",switzerland:"🇨🇭",austria:"🇦🇹",ireland:"🇮🇪",iceland:"🇮🇸",norway:"🇳🇴",sweden:"🇸🇪",finland:"🇫🇮",denmark:"🇩🇰","united kingdom":"🇬🇧",uk:"🇬🇧","great britain":"🇬🇧",england:"🏴󠁧󠁢󠁥󠁮󠁧󠁿",scotland:"🏴󠁧󠁢󠁳󠁣󠁴󠁿",wales:"🏴󠁧󠁢󠁷󠁬󠁳󠁿","northern ireland":"🇬🇧",japan:"🇯🇵",china:"🇨🇳","south korea":"🇰🇷",korea:"🇰🇷","north korea":"🇰🇵",taiwan:"🇹🇼","hong kong":"🇭🇰",singapore:"🇸🇬",thailand:"🇹🇭",vietnam:"🇻🇳",philippines:"🇵🇭",indonesia:"🇮🇩",malaysia:"🇲🇾",india:"🇮🇳",nepal:"🇳🇵","sri lanka":"🇱🇰",australia:"🇦🇺","new zealand":"🇳🇿",fiji:"🇫🇯",brazil:"🇧🇷",argentina:"🇦🇷",chile:"🇨🇱",peru:"🇵🇪",colombia:"🇨🇴",ecuador:"🇪🇨",uruguay:"🇺🇾",bolivia:"🇧🇴",venezuela:"🇻🇪","costa rica":"🇨🇷",panama:"🇵🇦",cuba:"🇨🇺","dominican republic":"🇩🇴","puerto rico":"🇵🇷",jamaica:"🇯🇲",ba
2hamas:"🇧🇸",barbados:"🇧🇧",greece:"🇬🇷",turkey:"🇹🇷",croatia:"🇭🇷",slovenia:"🇸🇮",hungary:"🇭🇺","czech republic":"🇨🇿",czechia:"🇨🇿",poland:"🇵🇱",romania:"🇷🇴",bulgaria:"🇧🇬",serbia:"🇷🇸",albania:"🇦🇱",ukraine:"🇺🇦",russia:"🇷🇺",egypt:"🇪🇬",morocco:"🇲🇦","south africa":"🇿🇦",kenya:"🇰🇪",tanzania:"🇹🇿",nigeria:"🇳🇬",ghana:"🇬🇭",ethiopia:"🇪🇹",uae:"🇦🇪","united arab emirates":"🇦🇪","saudi arabia":"🇸🇦",qatar:"🇶🇦",kuwait:"🇰🇼",bahrain:"🇧🇭",oman:"🇴🇲",israel:"🇮🇱",jordan:"🇯🇴",lebanon:"🇱🇧",montenegro:"🇲🇪",malta:"🇲🇹",cyprus:"🇨🇾",luxembourg:"🇱🇺",monaco:"🇲🇨",andorra:"🇦🇩"};function no(t){const a=(t||"").toLowerCase().trim();if(!a)return{kind:"emoji",value:"🌐"};if(wn[a])return{kind:"emoji",value:wn[a]};const r=Br[a];return r?{kind:"img",url:`https://flagcdn.com/w40/us-${r}.png`,alt:`${t} flag`}:{kind:"emoji",value:"🌐"}}function jn({name:t}){const a=no(t);return a.kind==="img"?e.jsx("img",{src:a.url,alt:a.alt,loading:"lazy",className:"h-3.5 w-5 rounded-[2px] object-cover shrink-0"}):e.jsx("span",{className:"text-base leading-none shrink-0","aria-hidden":"true",children:a.value})}function Rt(t){if(!t)return null;const a=t.toLowerCase().trim();return a.startsWith("place")?"place":a.startsWith("product")?"product":a.startsWith("creation")?"creation":a==="media"||a==="movie"||a==="movies"||a==="show"||a==="shows"||a==="tv"||a==="song"||a==="songs"||a==="music"||a==="album"||a==="artist"||a==="book"||a==="books"||a==="podcast"||a==="podcasts"||a==="creator"||a==="creators"||a==="game"||a==="gaming"?"media":null}const Kn=Ke.createContext(null),ao=[{label:"Interested",emoji:"✨",experienced_state:"not_tried",rating_value:null,interest_value:1},{label:"Not for me",emoji:"🚫",experienced_state:"tried",rating_value:-1,interest_value:null},{label:"Neutral",emoji:"😐",experienced_state:"tried",rating_value:0,interest_value:null},{label:"Liked",emoji:"👍",experienced_state:"tried",rating_value:1,interest_value:null},{label:"Loved",emoji:"❤️",experienced_state:"tried",rating_value:2,interest_value:null}],fr=({item:t,onOpen:a,className:r,children:s})=>{const i=Ke.useContext(Kn);if(!i)return e.jsx(e.Fragment,{children:s});const c=nt(t.domain),d=(dt[c]||dt.place).icon,v=i.ratings[t.vault_taste_id],_=(v==null?void 0:v.rating_value)??null,M=(v==null?void 0:v.experienced_state)??null,y=_!=null||M==="not_tried",j=e.jsxs("div",{className:"flex flex-col",children:[e.jsx("div",{className:"aspect-square w-full bg-muted overflow-hidden flex items-center justify-center",children:t.thumbnail_url?e.jsx("img",{src:Et(t.thumbnail_url,"card")??t.thumbnail_url,alt:"",className:"w-full h-full object-cover",referrerPolicy:"no-referrer",loading:"lazy",decoding:"async",onError:Vt(t.thumbnail_url)}):e.jsx(d,{className:"h-10 w-10 text-muted-foreground"})}),e.jsxs("div",{className:"p-3",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground line-clamp-2",children:t.title||"Untitled"}),t.subtitle&&e.jsx("div",{className:"text-xs text-muted-foreground line-clamp-1 mt-0.5",children:t.subtitle})]})]}),S=[{label:"Open",icon:e.jsx(Bn,{className:"h-4 w-4"}),onSelect:a},{label:"Remove from vault",icon:e.jsx(Vs,{className:"h-4 w-4"}),destructive:!0,onSelect:()=>i.removeItem(t.vault_taste_id)}],x=L=>e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground mb-1.5 px-1",children:y?"Your rating":"Rate it"}),e.jsx("div",{className:"grid grid-cols-5 gap-1",children:ao.map(W=>{const V=W.experienced_state==="not_tried"?M==="not_tried":M==="tried"&&_===W.rating_value;return e.jsxs("button",{"aria-label":W.label,title:W.label,onClick:E=>{E.stopPropagation(),i.quickRate(t.vault_taste_id,W),L()},className:Y("flex flex-col items-center justify-center gap-1 h-[68px] px-0.5 rounded-xl border border-border/60 bg-card/60 hover:bg-card active:scale-[0.96] transition-all overflow-hidden",V&&"ring-2 ring-primary bg-primary/10"),children:[e.jsx("span",{className:"text-[22px] leading-none",children:W.emoji}),e.jsx("span",{className:"text-[9.5px] font-medium text-muted-foreground leading-[1.05] text-center break-words",children:W.label})]},W.label)})})]});return e.jsx(Ka,{preview:j,actions:S,extra:x,className:r,children:s})},io=t=>{if(!Number.isFinite(t))return"0";if(t<1e3)return String(t);if(t<1e4){const a=Math.round(t/100)/10;return`${a%1===0?a.toFixed(0):a.toFixed(1)}k`}return`${Math.round(t/1e3)}k`},oo=[{key:"walking",label:"Walking distance",max:1.60934},{key:"short",label:"Short drive (under 5 miles)",max:8.04672},{key:"local",label:"Local (5-20 miles)",max:32.1869},{key:"localish",label:"Localish (under 50 miles)",max:80.4672},{key:"getaway",label:"Getaway (under 150 miles)",max:241.402},{key:"daytrip",label:"Day trip (under 500 miles)",max:804.672},{key:"far",label:"Farther afield (500+ miles)",max:1/0}],lo=[{key:"walking",label:"Walking distance under 1 mile",max:1.60934},{key:"short",label:"Short drive (under 5 miles)",max:8.04672},{key:"local",label:"Local (5-20 miles)",max:32.1869}],Nn=32.1869;function Ds(t,a){const s=d=>d*Math.PI/180,i=s(a.lat-t.lat),c=s(a.lng-t.lng),m=Math.sin(i/2)**2+Math.cos(s(t.lat))*Math.cos(s(a.lat))*Math.sin(c/2)**2;return 2*6371*Math.asin(Math.sqrt(m))}const dt={place:{label:"Places",short:"Places",icon:ht,tint:"from-emerald-500/25 to-emerald-500/5",chip:"bg-emerald-500/90"}
2,product:{label:"Products",short:"Products",icon:es,tint:"from-amber-500/25 to-amber-500/5",chip:"bg-amber-500/90"},media:{label:"Media",short:"Media",icon:mr,tint:"from-sky-500/25 to-sky-500/5",chip:"bg-sky-500/90"},creations:{label:"Creations",short:"Creations",icon:ws,tint:"from-fuchsia-500/25 to-fuchsia-500/5",chip:"bg-fuchsia-500/90"},topic:{label:"Topic",short:"Topic",icon:ar,tint:"from-violet-500/25 to-violet-500/5",chip:"bg-violet-500/90"}},nt=t=>t==="creation"?"creations":t||"",co=[{id:"all",label:"All",icon:ar},{id:"place",label:"Places",icon:ht},{id:"product",label:"Products",icon:es},{id:"media",label:"Media",icon:mr},{id:"creations",label:"Creations",icon:ws}],uo={place:new Set(["Dining","Lodging","Recreation","Culture","Shopping","Services","Education","Entertainment","Areas","Spiritual"]),product:new Set(["Fashion","Automotive","Baby","Beauty","Beverages","Electronics","Grocery","Games","Home","Backyard","Pets","Sports","Tools","Wellness","Toys"]),media:new Set(["Music","Movies","Shows","Books","Podcasts","Creators","Gaming"]),creations:new Set(["Building","Crafting","Productions","Recipes","Art","Writing"])},mo=[{key:"unrated",label:"Unrated",icon:ti,iconClass:"text-muted-foreground",match:t=>!t||t.rating_value==null&&t.experienced_state!=="not_tried"},{key:"interested",label:"Interested",icon:Hr,match:t=>(t==null?void 0:t.experienced_state)==="not_tried"&&(t==null?void 0:t.rating_value)==null},{key:"love",label:"Loved",icon:Ft,iconClass:"text-rose-500 fill-rose-500",match:t=>(t==null?void 0:t.rating_value)===2},{key:"like",label:"Liked",icon:Ft,iconClass:"text-rose-400",match:t=>(t==null?void 0:t.rating_value)===1},{key:"neutral",label:"Neutral",icon:si,iconClass:"text-muted-foreground",match:t=>(t==null?void 0:t.rating_value)===0},{key:"dislike",label:"Disliked",icon:wa,iconClass:"text-muted-foreground",match:t=>(t==null?void 0:t.rating_value)===-1||(t==null?void 0:t.rating_value)===-2}],fo=({onRetry:t})=>{const[a,r]=n.useState(!1);return n.useEffect(()=>{const s=window.setTimeout(()=>r(!0),6e3);return()=>window.clearTimeout(s)},[]),e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 h-[80vh] px-6 text-center",children:[e.jsx(wt,{className:"h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading your vault…"}),a&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-xs text-muted-foreground max-w-xs",children:"This is taking longer than usual. Your connection may be weak."}),e.jsx("button",{onClick:()=>{r(!1),t()},className:"px-4 py-2 rounded-md bg-primary text-primary-foreground text-sm",children:"Try again"})]})]})},Nm=()=>{var Jt,Zs;const t=lr(),[a,r]=n.useState(!0),[s,i]=n.useState(null),[c,m]=n.useState(null),[d,v]=n.useState([]),[_,M]=n.useState(!1),[y,j]=n.useState([]),[S,x]=n.useState(0),[L,W]=n.useState(!1),[V,E]=n.useState(0),[J,O]=n.useState([]),[X,ge]=n.useState(!0),[Re,ve]=n.useState({}),[it,B]=n.useState([]),[Z,se]=n.useState({}),[G,ye]=In(),Ye=["all","place","product","media","creations"],Pe=["saves","stashes","wishlist","nearby"],Ve=Ye.includes(G.get("d"))?G.get("d"):"all",Le=G.get("wishes")==="1"?"wishlist":Pe.includes(G.get("tab"))?G.get("tab"):"saves",[$,le]=n.useState(Le),[ne,de]=n.useState(Ve),[De,Ee]=n.useState(Ve==="all"?"recent":"category"),[C,z]=n.useState("carousel"),F=$==="wishlist",ue=Ke.useCallback(f=>le(f?"wishlist":"saves"),[]),[re,xe]=n.useState(!1),[oe,P]=n.useState(!1);n.useEffect(()=>{const f=b=>{var A;const I=!!((A=b.detail)!=null&&A.active);P(I)};return window.addEventListener("vault:bulk-select-change",f),()=>window.removeEventListener("vault:bulk-select-change",f)},[]),n.useEffect(()=>{const f=new URLSearchParams(G);ne==="all"?f.delete("d"):f.set("d",ne),$==="saves"?f.delete("tab"):f.set("tab",$),f.delete("wishes");const b=G.toString(),I=f.toString();b!==I&&ye(f,{replace:!0})},[ne,$]);const[K,g]=n.useState(!1),[D,k]=n.useState(""),h=zn(s),[p,H]=n.useState("mine"),te=D.trim().toLowerCase(),we=n.useMemo(()=>te?d.filter(f=>us(te,f.name)):d,[d,te]),he=n.useMemo(()=>{const f=h.sharedWithMe||[];return te?f.filter(b=>us(te,b.guide_name,b.owner_name)):f},[h.sharedWithMe,te]);!te&&we.length+he.length>=6;const[ee,je]=n.useState(null),[Ae,pt]=n.useState(!1),[ae,ut]=n.useState([]),_e=n.useRef([]),{prevItem:Ze,nextItem:et}=n.useMemo(()=>
2{if(!ee)return{prevItem:null,nextItem:null};const f=_e.current.length>0?_e.current:ae,b=f.findIndex(I=>I.vault_taste_id===ee.vault_taste_id);return b===-1?{prevItem:null,nextItem:null}:{prevItem:b>0?f[b-1]:null,nextItem:b<f.length-1?f[b+1]:null}},[ee,ae]),Te=G.get("openEntity"),bt=(G.get("openDomain")||"").toLowerCase(),Ue=n.useRef(null),tt=n.useRef(null);n.useEffect(()=>{if(!Te||Ue.current===Te||y.length===0)return;const f=bt==="place"?"place":bt==="product"?"product":bt==="media"?"media":bt==="creations"||bt==="providers"?"creations":null,b=y.find(A=>{if(A.entity_id!==Te)return!1;if(!f)return!0;const pe=(A.domain||"").toLowerCase();return f==="creations"?pe==="creations"||pe==="providers":pe===f});if(!b){tt.current!==Te&&(tt.current=Te,E(A=>A+1));return}Ue.current=Te,_e.current=[],je(b),pt(!0);const I=new URLSearchParams(G);I.delete("openEntity"),I.delete("openDomain"),ye(I,{replace:!0})},[Te,bt,y,G,ye]);const[R,ie]=n.useState(!1),[st,We]=n.useState(!1),[Nt,Pt]=n.useState(!1),[At,ms]=n.useState(!1),[gr,ks]=n.useState(null),[Kr,Ot]=n.useState(!1),Ss=n.useRef(!1);n.useEffect(()=>{$!=="stashes"||!s||Ss.current||(Ss.current=!0,(async()=>{for(let f=0;f<2;f++)try{const{data:b,error:I}=await U.functions.invoke("stash-suggestions",{body:{}});if(I)throw I;ks((b==null?void 0:b.suggestions)||[]),Ot(!1);return}catch(b){console.warn("[StashSuggestions] probe failed",f,b),await new Promise(I=>setTimeout(I,1200))}Ot(!0)})())},[$,s]);const Kt=n.useRef(null),br=()=>{var f;try{(f=document.scrollingElement)==null||f.scrollTo({top:0,behavior:"smooth"})}catch{}window.scrollTo({top:0,behavior:"smooth"})};ua();const[Bt,Cs]=n.useState({}),[fs,Fs]=n.useState({}),[Ks,Ms]=n.useState({}),[vr,Ls]=n.useState({}),[_r,ts]=n.useState(null),[ss,Ys]=n.useState([]),[Tt,hs]=n.useState("auto"),[ps,yr]=n.useState(null);n.useEffect(()=>{De==="distance"&&ne!=="place"&&Ee("category"),De==="region"&&ne!=="place"&&Ee("category"),De==="recent"&&ne!=="all"&&Ee("category"),F&&ne!=="all"&&ue(!1),C==="map"&&ne!=="place"&&z("carousel"),C==="map"&&ne==="place"&&De!=="distance"&&Ee("distance")},[ne,De,F,C]);const Es=n.useRef(ne);n.useEffect(()=>{Es.current!=="place"&&ne==="place"&&C!=="map"&&Ee("region"),Es.current=ne},[ne,C]);const[Yt,vt]=n.useState(!0),[wr,Yr]=n.useState(!1),rs=n.useRef(typeof window<"u"?window.scrollY:0);n.useEffect(()=>{rs.current=window.scrollY,vt(!0);const f=()=>{const I=window.scrollY,A=I-rs.current;I<40?vt(!0):A>6?vt(!1):A<-6&&vt(!0),Yr(I>600),rs.current=I},b=()=>{rs.current=window.scrollY,vt(!0)};return window.addEventListener("scroll",f,{passive:!0}),window.addEventListener("pageshow",b),document.addEventListener("visibilitychange",b),()=>{window.removeEventListener("scroll",f),window.removeEventListener("pageshow",b),document.removeEventListener("visibilitychange",b)}},[]),n.useEffect(()=>{let f=!1;const b=Ya("Profile / Vault Hub","/profile");let I=!1;const A=window.setTimeout(()=>{f||(r(Ne=>Ne&&!1),I||(W(!0),ln("Vault Hub (stalled)","/vault",1e4)))},1e4),pe=(Ne,fe,Ge)=>new Promise((Oe,_t)=>{const St=setTimeout(()=>_t(new Error(`${Ge} timed out after ${fe}ms`)),fe);Promise.resolve(Ne).then(yt=>{clearTimeout(St),Oe(yt)},yt=>{clearTimeout(St),_t(yt)})});return(async()=>{const{data:{session:Ne}}=await pe(U.auth.getSession(),5e3,"ProfileMock session").catch(()=>({data:{session:null}})),fe=Ne==null?void 0:Ne.user;if(!fe){window.clearTimeout(A),r(!1),W(!0);return}i(fe.id);const Ge=25,Oe=()=>{I||(I=!0,window.clearTimeout(A),r(!1),W(!1),b==null||b.end())},_t=pe(U.from("profiles").select("id, username, first_name, last_name, avatar_url, home_city, home_state, home_country").eq("id",fe.id).maybeSingle(),8e3,"ProfileMock profile"),St=pe(U.from("user_vault_taste_search").select("vault_taste_id, entity_id, domain, level_1, level_2, title, subtitle, thumbnail_url, website, taxonomy_id, created_at").eq("user_id",fe.id).order("created_at",{ascending:!1}).limit(Ge),8e3,"ProfileMock fast paint");_t.catch(()=>{}),St.catch(()=>{}),_t.then(ce=>{f||ce!=null&&ce.data&&m(ce.data)}).catch(()=>{});const yt=([ce,Be,Xe])=>{var Me;if(!f&&((Me=ce==null?void 0:ce.rows)!=null&&Me.length)){const He=ce.rows.slice(0,1e4);j($e=>$e.length>He.length?$e:He),x($e=>Math.max($e,He.length)),Oe()}if(!f&&(Be!=null&&Be.map)){const He={};
2for(const[$e,Je]of Object.entries(Be.map))He[$e]={rating_value:Je.rating_value,experienced_state:Je.experienced_state};ve($e=>Object.keys($e).length?{...He,...$e}:He)}!f&&(Xe!=null&&Xe.length)&&(v(He=>He.length?He:Xe.map($e=>({id:$e.id,name:$e.name,cover_url:$e.cover_url,domain:$e.domain,domain_count:$e.domain_count,item_count:$e.item_count,updated_at:null,created_at:$e.created_at}))),M(!0))},Wt=Promise.all([ra(fe.id).catch(()=>null),Pa(fe.id).catch(()=>null),Ta(fe.id).catch(()=>null)]);try{const ce=await pe(Wt,1500,"ProfileMock idb cache");yt(ce)}catch{ln("Vault Hub (idb stall)","/vault",1500),Wt.then(yt).catch(()=>{})}let Mt={data:[]},lt=!1;try{Mt=await St,Mt!=null&&Mt.error&&(lt=!0)}catch(ce){console.warn("[ProfileMock] fast paint timed out — keeping cached vault if present",ce),lt=!0}if(f)return;const Se=(Mt==null?void 0:Mt.data)||[];Se.length>0?(j(ce=>{if(ce.length<=Se.length)return Se;const Be=new Set(Se.map(Xe=>Xe.vault_taste_id));return[...Se,...ce.filter(Xe=>!Be.has(Xe.vault_taste_id))]}),x(ce=>Math.max(ce,Se.length)),W(!1)):lt&&j(ce=>(ce.length===0&&W(!0),ce)),Oe();const Ce=()=>U.from("user_guides").select("id, name, extra, created_at, updated_at").eq("user_id",fe.id).order("updated_at",{ascending:!1,nullsFirst:!1}).limit(200),Fe=(async()=>{let ce=await Ce();return ce.error&&(await new Promise(Be=>setTimeout(Be,600)),ce=await Ce()),ce})(),Is=U.from("user_vault_taste_search").select("vault_taste_id, entity_id, domain, level_1, level_2, title, subtitle, thumbnail_url, website, taxonomy_id, created_at").eq("user_id",fe.id).order("created_at",{ascending:!1}).range(Ge,1e4),bs=Aa(fe.id).then(ce=>ce.fresh),as=U.from("user_wishlist_items").select("vault_taste_id, created_at, is_hidden, is_priority, note").eq("user_id",fe.id).order("created_at",{ascending:!1}).limit(200);bs.then(ce=>{if(f)return;const Be={};for(const[Xe,Me]of Object.entries(ce||{}))Be[Xe]={rating_value:Me.rating_value,experienced_state:Me.experienced_state};ve(Be)}).catch(ce=>console.warn("[ProfileMock] ratings load failed",ce)),Is.then(ce=>{if(f)return;const Be=ce.data||[];if(Be.length>0){const Xe=new Set(Se.map(He=>He.vault_taste_id)),Me=[...Se,...Be.filter(He=>!Xe.has(He.vault_taste_id))];j(Me),x(Me.length),W(!1)}else ce!=null&&ce.error&&Se.length===0&&j(Xe=>(Xe.length===0&&W(!0),Xe))}).catch(ce=>console.warn("[ProfileMock] full vault load failed",ce)),Fe.then(ce=>{if(f)return;if(ce.error){console.warn("[ProfileMock] stashes load failed — keeping cached stashes",ce.error);return}const Be=(ce.data||[]).map(Me=>{var He,$e,Je;return{id:Me.id,name:Me.name,cover_url:((He=Me.extra)==null?void 0:He.cover_url)||null,domain:(($e=Me.extra)==null?void 0:$e.domain)||null,domain_count:(Je=Me.extra)!=null&&Je.domain?1:0,item_count:0,updated_at:Me.updated_at||null,created_at:Me.created_at||null}});v(Be),M(!0),tn(fe.id,Be.map(Me=>({id:Me.id,name:Me.name,cover_url:Me.cover_url,domain:Me.domain,domain_count:Me.domain_count,item_count:Me.item_count,created_at:Me.created_at||""}))).catch(()=>{});const Xe=Be.map(Me=>Me.id);Xe.length&&(async()=>{try{const He=await Promise.all(Array.from({length:Math.ceil(Xe.length/100)},(u,N)=>U.from("user_guide_items").select("guide_id, taste_id").in("guide_id",Xe.slice(N*100,N*100+100))));if(f)return;const $e=He.flatMap(({data:u})=>u||[]);B($e);const Je=Array.from(new Set($e.map(u=>u.taste_id).filter(Boolean))),gt=200,is=await Promise.all(Array.from({length:Math.ceil(Je.length/gt)},(u,N)=>U.from("user_vault_taste_search").select("vault_taste_id, domain, level_1, level_2, taxonomy_id, title, subtitle, thumbnail_url, entity_id").eq("user_id",fe.id).in("vault_taste_id",Je.slice(N*gt,N*gt+gt))));if(f)return;const Qt={},l={};if(is.forEach(({data:u})=>{(u||[]).forEach(N=>{const w=nt(N.domain);Qt[N.vault_taste_id]={domain:w,l1:Zt(N)},w&&(l[N.vault_taste_id]=w)})}),f)return;se(Qt);const o={};$e.forEach(u=>{var N;u.taste_id&&(o[N=u.guide_id]||(o[N]=[])).push(u.taste_id)}),v(u=>{const N=u.map(w=>{var ze;const T=o[w.id];if(!T||T.length===0)return{...w,item_count:0};const q={},Q=new Set;T.forEach(Qe=>{const ke=l[Qe];ke&&(q[ke]=(q[ke]||0)+1,Q.add(ke))});const Ie=((ze=Object.entries(q).sort((Qe,ke)=>ke[1]-Qe[1])[0])==null?void 0:ze[0])||""||w.domain;return{...w,domain:Ie,domain_count:Q.size,item_count:T.length}});return tn(fe.id,N.map(w=>({id:w.id,name:w.name,cover_url:w.cover_url,domain:w.domain,domain_count:w.domain_count,item_count:w.item_count,created_at:w.created_at||""}))).catch(()=>{}),N})}catch(Me){console.warn("[ProfileMock] stash hydration failed",Me)}})()}).catch(ce=>{console.warn("[ProfileMock] stashes load failed",ce),f||M(!0)}),as.then(ce=>{f||(async()=>{const Be=new Map;
2(ce.data||[]).forEach(Je=>{Be.set(Je.vault_taste_id,{is_hidden:!!Je.is_hidden,note:Je.note??null,is_priority:!!Je.is_priority})});const Xe=(ce.data||[]).map(Je=>Je.vault_taste_id).filter(Boolean);if(!Xe.length){f||(O([]),ge(!1));return}const{data:Me}=await U.from("user_vault_taste_search").select("vault_taste_id, title, subtitle, thumbnail_url, domain, level_1, level_2").in("vault_taste_id",Xe),He=new Map(Xe.map((Je,gt)=>[Je,gt])),$e=(Me||[]).map(Je=>{var gt,is,Qt;return{...Je,is_hidden:((gt=Be.get(Je.vault_taste_id))==null?void 0:gt.is_hidden)||!1,note:((is=Be.get(Je.vault_taste_id))==null?void 0:is.note)||null,is_priority:((Qt=Be.get(Je.vault_taste_id))==null?void 0:Qt.is_priority)||!1}}).sort((Je,gt)=>(He.get(Je.vault_taste_id)??999)-(He.get(gt.vault_taste_id)??999));f||(O($e),ge(!1))})().catch(Be=>{console.warn("[ProfileMock] wishlist enrichment failed",Be),f||ge(!1)})}).catch(ce=>{console.warn("[ProfileMock] wishlist load failed",ce),f||ge(!1)})})().catch(Ne=>{console.error("[ProfileMock] load",Ne),window.clearTimeout(A),r(!1),W(!0)}),()=>{f=!0,window.clearTimeout(A)}},[V]),Ja(a,()=>E(f=>f+1)),n.useEffect(()=>{let f=!1;return(async()=>{var b;try{const{data:{session:I}}=await U.auth.getSession(),A=(b=I==null?void 0:I.user)==null?void 0:b.id;if(!A)return;let pe=null;const be=await U.from("user_saved_locations").select("id, name, latitude, longitude, is_home, sort_order").eq("user_id",A);if(be.error?console.warn("[ProfileMock] saved locations primary query failed",be.error):pe=be.data||[],!pe)return;const Ne=pe.map(fe=>({id:fe.id,name:fe.name,lat:Number(fe.latitude),lng:Number(fe.longitude),is_home:!!fe.is_home,sort_order:typeof fe.sort_order=="number"?fe.sort_order:9999})).filter(fe=>Number.isFinite(fe.lat)&&Number.isFinite(fe.lng)).sort((fe,Ge)=>fe.sort_order-Ge.sort_order).map(({sort_order:fe,...Ge})=>Ge);if(f)return;Ys(Ne),Ne.length&&hs(fe=>fe&&fe!=="auto"?fe:Ne[0].id)}catch(I){console.warn("[ProfileMock] saved locations load failed",I)}})(),()=>{f=!0}},[V]);const jr=n.useMemo(()=>c&&(c.first_name||c.username)||"You",[c]),Js=c!=null&&c.username?`@${c.username}`:"",Nr=[c==null?void 0:c.home_city,c==null?void 0:c.home_state,c==null?void 0:c.home_country].filter(Boolean).join(", "),kr=n.useMemo(()=>ne==="all"?y:y.filter(f=>nt(f.domain)===ne),[y,ne]),Qs=n.useMemo(()=>Ho(y,fs,Ks),[y,fs,Ks]),$t=n.useMemo(()=>y.filter(f=>nt(f.domain)==="place"&&f.entity_id).map(f=>String(f.entity_id)).filter(f=>/^\d+$/.test(f)).join(","),[y]);n.useEffect(()=>{const f=$t?$t.split(","):[];if(!f.length)return;let b=!1;return(async()=>{try{const A={};for(let be=0;be<f.length&&!b;be+=100){const Ne=f.slice(be,be+100).map(Oe=>Number(Oe)),[fe,Ge]=await Promise.all([U.from("corpus_places_here_ephemeral").select("corpus_place_id, lat, lng").in("corpus_place_id",Ne),U.from("corpus_places_apple_enrichment").select("corpus_place_id, apple_lat, apple_lng").in("corpus_place_id",Ne)]);(Ge.data||[]).forEach(Oe=>{Oe.apple_lat!=null&&Oe.apple_lng!=null&&(A[String(Oe.corpus_place_id)]={lat:Oe.apple_lat,lng:Oe.apple_lng})}),(fe.data||[]).forEach(Oe=>{Oe.lat!=null&&Oe.lng!=null&&(A[String(Oe.corpus_place_id)]={lat:Oe.lat,lng:Oe.lng})})}if(b)return;Cs(A);const pe=f.filter(be=>!A[String(be)]&&/^\d+$/.test(String(be)));if(pe.length)for(let Ne=0;Ne<pe.length&&!b;Ne+=50){const fe=pe.slice(Ne,Ne+50);try{const{data:Ge}=await U.functions.invoke("backfill-place-coords",{body:{corpus_place_ids:fe}}),Oe=(Ge==null?void 0:Ge.coords)||{};!b&&Object.keys(Oe).length&&Cs(_t=>({..._t,...Oe}))}catch(Ge){console.warn("[ProfileMock] backfill-place-coords failed",Ge)}}}catch(I){console.warn("[ProfileMock] place coords fetch failed",I)}})(),()=>{b=!0}},[$t]),n.useEffect(()=>{const f=$t?$t.split(","):[];if(!f.length)return;let b=!1;return(async()=>{try{const A=[];for(let Se=0;Se<f.length;Se+=100)A.push(f.slice(Se,Se+100).map(Ce=>Number(Ce)));const pe={};if((await Promise.all(A.map(Se=>U.from("corpus_places").select("id, state, country, city").in("id",Se)))).forEach(Se=>{(Se.data||[]).forEach(Ce=>{pe[String(Ce.id)]={state:(Ce.state||"").trim()||null,country:(Ce.country||"").trim()||null,city:(Ce.city||"").trim()||null}})}),b||(Fs(pe),!Object.keys(pe).length))return;const Ne="fyra_corpus_regions_v2",fe=6*60*60*1e3;try{for(let Se=0;Se<sessionStorage.length;Se+=1){const Ce=sessionStorage.key(Se);Ce&&Ce.startsWith("fyra_corpus_regions_v")&&Ce!==Ne&&sessionStorage.removeItem(Ce)}}catch{}let Ge=null;try{const Se=sessionStorage.getItem(Ne);Se&&(Ge=JSON.parse(Se))}catch{}if(Ge!=null&&Ge.cityMap&&Ge.ts&&Date.now()-Ge.ts<fe){Ms(Ge.cityMap),Ls(Ge.parents||{});return}const Oe={},_t={},St=Se=>
2{(Se||[]).forEach(Ce=>{const Fe=(Ce.city||"").toLowerCase(),Is=(Ce.state||"").toLowerCase(),bs=(Ce.country||"").toLowerCase(),as=Ce.region_name||"",ce={region_name:as,region_emoji:Ce.region_emoji??null};if(Oe[`${Fe}|${Is}|${bs}`]=ce,Oe[`${Fe}||${bs}`]=ce,as){const Be=as.toLowerCase();Ce.state?_t[Be]={parent:Ce.state,kind:"state"}:Ce.country&&(_t[Be]={parent:Ce.country,kind:"country"})}})},yt=1e3;let Wt=0,Mt=!1,lt=0;for(;!b&&!Mt&&lt<5;){lt+=1;const Se=[0,1,2,3].map(Fe=>U.from("corpus_regions").select("city, state, country, region_name, region_emoji").range(Wt+Fe*yt,Wt+Fe*yt+yt-1)),Ce=await Promise.all(Se);Ce.forEach(Fe=>St(Fe.data)),Mt=Ce.some(Fe=>!Fe.data||Fe.data.length<yt),Wt+=4*yt}if(b)return;Ms(Oe),Ls(_t);try{sessionStorage.setItem(Ne,JSON.stringify({cityMap:Oe,parents:_t,ts:Date.now()}))}catch{}}catch(I){console.warn("[ProfileMock] region metadata fetch failed",I)}})(),()=>{b=!0}},[$t]),n.useEffect(()=>{if(Tt==="current"){ps&&ts(ps);return}const f=ss.find(I=>I.id===Tt);if(f){ts({lat:f.lat,lng:f.lng});return}const b=Object.values(Bt);if(b.length){const I=b.map(be=>be.lat).sort((be,Ne)=>be-Ne),A=b.map(be=>be.lng).sort((be,Ne)=>be-Ne),pe=Math.floor(b.length/2);ts({lat:I[pe],lng:A[pe]})}},[Tt,ss,ps,Bt]);const xs=async()=>{try{const{getCachedGeoPosition:f}=await Rn(async()=>{const{getCachedGeoPosition:I}=await import("./useGeolocation-CkgjOHRY.js");return{getCachedGeoPosition:I}},__vite__mapDeps([0,1,2])),b=await f();if(!b)return;yr({lat:b.lat,lng:b.lng}),hs("current")}catch(f){console.warn("[ProfileMock] geolocation failed",f)}},gs=f=>{_e.current=ae.slice(),je(f),pt(!0)},{toast:at}=js(),xt=Ke.useCallback(async(f,b)=>{if(!s)return;const I=Re[f];ve(A=>({...A,[f]:{rating_value:b.rating_value,experienced_state:b.experienced_state}}));try{const{error:A}=await U.from("user_taste_ratings").upsert({vault_taste_id:f,user_id:s,rating_value:b.rating_value,experienced_state:b.experienced_state,interest_value:b.interest_value},{onConflict:"vault_taste_id,user_id"});if(A)throw A;at({title:`Rated: ${b.label}`})}catch(A){console.error("Quick rate failed:",A),ve(pe=>{const be={...pe};return I?be[f]=I:delete be[f],be}),at({title:"Couldn't save rating",variant:"destructive"})}},[s,Re,at]),Ps=Ke.useCallback(async(f,b)=>{if(!s||f.length===0)return 0;const I={};ve(A=>{const pe={...A};return f.forEach(be=>{I[be]=A[be],pe[be]={rating_value:b.rating_value,experienced_state:b.experienced_state}}),pe});try{const A=f.map(be=>({vault_taste_id:be,user_id:s,rating_value:b.rating_value,experienced_state:b.experienced_state,interest_value:b.interest_value})),{error:pe}=await U.from("user_taste_ratings").upsert(A,{onConflict:"vault_taste_id,user_id"});if(pe)throw pe;return at({title:`Marked ${f.length} as ${b.label}`}),f.length}catch(A){return console.error("Bulk apply rating failed:",A),ve(pe=>{const be={...pe};return f.forEach(Ne=>{I[Ne]?be[Ne]=I[Ne]:delete be[Ne]}),be}),at({title:"Couldn't save",variant:"destructive"}),0}},[s,at]),rt=Ke.useCallback(async(f,b)=>{if(!s)return 0;const I=Re[f];ve(A=>({...A,[f]:{rating_value:b.rating_value,experienced_state:b.experienced_state}}));try{const{error:A}=await U.from("user_taste_ratings").upsert({vault_taste_id:f,user_id:s,rating_value:b.rating_value,experienced_state:b.experienced_state,interest_value:b.interest_value},{onConflict:"vault_taste_id,user_id"});if(A)throw A;return 1}catch(A){return console.error("Silent rating failed:",A),ve(pe=>{const be={...pe};return I?be[f]=I:delete be[f],be}),0}},[s,Re]),ot=Ke.useCallback(async f=>{if(!s||f.length===0)return 0;const b=new Set(f),I=y;j(A=>A.filter(pe=>!b.has(pe.vault_taste_id)));try{const{error:A}=await U.from("user_vault_tastes").delete().in("id",f).eq("user_id",s);if(A)throw A;return Xr(s,f),at({title:`Removed ${f.length} from vault`}),f.length}catch(A){return console.error("Bulk remove failed:",A),j(I),at({title:"Couldn't remove",variant:"destructive"}),0}},[s,y,at]),Sr=Ke.useCallback(async f=>{if(!s)return 0;const b=y.find(A=>A.vault_taste_id===f),I=y;j(A=>A.filter(pe=>pe.vault_taste_id!==f));try{const{error:A}=await U.from("user_vault_tastes").delete().eq("id",f).eq("user_id",s);if(A)throw A;return Xr(s,[f]),b!=null&&b.title&&U.from("user_browse_dismissals").upsert({user_id:s,title:b.title,domain:b.domain||null,category:b.level_2||b.level_1||null},{onConflict:"user_id,title"}),1}catch(A){return console.error("Rate-sheet remove failed:",A),j(I),at({title:"Couldn't remove",variant:"destructive"}),0}},[s,y,at]),Xs=Ke.useCallback(async f=>{if(!s)return 0;try{return await Ir(s,f),j(b=>b.map(I=>I.vault_taste_id===f?{...I,interest_value:2}:I)),1}catch(b){return console.error("Rate-sheet wishlist add failed:",b),at({title:"Couldn't add to wishlist",variant:"destructive"}),0}},[s,at]),ns=Ke.useCallback(async f=>{if(!s)return;const b=y;j(I=>I.filter(A=>A.vault_taste_id!==f));try{const{error:I}=await U.from("user_vault_tastes").delete().eq("id",f).eq("user_id",s);if(I)throw I;at({title:"Removed from vault"})}catch(I){console.error("Remove failed:",I),j(b),at({title:"Couldn't remove",variant:"destructive"})}},[s,y,at]),As={recent:"Recent",rating:"Rating",category:"Category",distance:"Distance",region:"Region"},zt=async f=>{if(s){O(b=>b.filter(I=>I.vault_taste_id!==f));try{await U.from("user_wishlist_items").delete().eq("user_id",s).eq("vault_taste_id",f)}catch(b){console.warn("[ProfileMock] wish remove failed",b)}}},Ut=async(f,b)=>{if(s){O(I=>I.map(A=>A.vault_taste_id===f?{...A,is_hidden:b}:A));try{await U.from("user_wishlist_items").update({is_hidden:b}).eq("user_id",s).eq("vault_taste_id",f)}catch(I){console.warn("[ProfileMock] wish hide toggle failed",I)}}},kt=async(f,b)=>{if(s){O(I=>I.map(A=>A.vault_taste_id===f?{...A,is_priority:b}:A));try{await U.from("user_wishlist_items").update({is_priority:b}).eq("user_id",s).eq("vault_taste_id",f)}catch(I){console.warn("[ProfileMock] wish priority toggle failed",I),O(A=>A.map(pe=>pe.vault_taste_id===f?{...pe,is_priority:!b}:pe))}}},Ts=async f=>{if(s){O(b=>b.some(A=>A.vault_taste_id===f.vault_taste_id)?b:[{vault_taste_id:f.vault_taste_id,title:f.title,subtitle:f.subtitle,thumbnail_url:f.thumbnail_url,domain:f.domain,level_1:f.level_1,level_2:f.level_2,is_hidden:!1,note:null,is_priority:!1},...b]);try{await Ir(s,f.vault_taste_id)}catch(b){console.warn("[ProfileMock] wish add failed",b)}}};return e.jsxs("div",{className:"min-h-dvh bg-background pb-[calc(env(safe-area-inset-bottom)+10rem)]",children:[a?e.jsx(fo,{onRetry:()=>E(f=>f+1)}):e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"pt-[env(safe-area-inset-top)] px-3 pt-2.5 pb-2.5 flex items-center gap-2 flex-shrink-0 border-b border-border/50 backdrop-blur-xl bg-background/85",children:[e.jsxs("button",{onClick:()=>g(!0),"aria-label":"Search your Vault",title:"Search your Vault",className:"flex-1 min-w-0 h-9 pl-3 pr-3.5 rounded-full inline-flex items-center gap-2 bg-muted/60 text-muted-foreground ring-1 ring-inset ring-border/40 hover:bg-muted/80 active:scale-[0.99] transition-all",children:[e.jsx(Us,{className:"h-[15p
2x] w-[15px] flex-shrink-0 opacity-70",strokeWidth:2.5}),e.jsx("span",{className:"text-[13px] font-medium tracking-tight truncate",children:"Search tastes and stashes"})]}),e.jsx("button",{onClick:()=>t("/settings"),"aria-label":"Settings",title:"Settings",className:"h-9 w-9 flex-shrink-0 rounded-full inline-flex items-center justify-center bg-muted/60 ring-1 ring-inset ring-border/40 text-muted-foreground hover:text-foreground hover:bg-muted/80 active:scale-95 transition-all",children:e.jsx(Qa,{className:"h-[18px] w-[18px]"})})]}),!oe&&!re&&e.jsx("section",{className:"px-4 pt-3 pb-1",children:e.jsxs("div",{className:"flex items-center gap-4",children:[s?e.jsx(Vi,{trigger:e.jsx("button",{"aria-label":"Your Fyra score",className:"relative h-[72px] w-[72px] rounded-full p-[2px] bg-gradient-to-br from-primary via-accent to-primary/40 active:scale-95 transition-transform shrink-0",children:e.jsx("span",{className:"block h-full w-full rounded-full bg-background p-[2px]",children:e.jsxs(sn,{className:"h-full w-full",children:[e.jsx(Ia,{src:On((c==null?void 0:c.avatar_url)||void 0),alt:"Your profile"}),e.jsx(rn,{className:"text-lg font-semibold bg-muted",children:(((Jt=c==null?void 0:c.first_name)==null?void 0:Jt[0])||((Zs=c==null?void 0:c.username)==null?void 0:Zs[0])||"Y").toUpperCase()})]})})}),extraSection:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ys,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Taste Coordinates"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Four directions your taste keeps pointing to."}),e.jsx(za,{userId:s,isSelf:!0,inlineDetail:!0})]})}):e.jsx(sn,{className:"h-[72px] w-[72px]",children:e.jsx(rn,{className:"text-lg font-semibold bg-muted",children:"Y"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h1",{className:"text-[19px] font-semibold tracking-tight leading-tight truncate",children:jr}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:[Js,Nr].filter(Boolean).join(" · ")})]})]})}),!re&&e.jsx("nav",{ref:Kt,className:"sticky top-0 z-20 mt-2 bg-background/85 backdrop-blur-xl border-b border-border/50",children:e.jsx("div",{className:"px-4 pt-1.5 pb-0",children:e.jsx("div",{className:"grid grid-cols-4",children:[{id:"saves",label:"Tastes",icon:Ft,count:y.length},{id:"stashes",label:"Stashes",icon:zs,count:d.length},{id:"wishlist",label:"Wishlist",icon:Un,count:J.length},{id:"nearby",label:"Nearby",icon:Xt,count:ss.length}].map(f=>{const b=f.icon,I=$===f.id;return e.jsxs("button",{onClick:()=>{de("all"),le(f.id)},"aria-current":I?"page":void 0,className:Y("relative flex flex-col items-center justify-center gap-0.5 pt-1.5 pb-2 transition-colors duration-200",I?"text-foreground":"text-muted-foreground"),children:[e.jsx(b,{className:Y("h-[18px] w-[18px]",I?"opacity-100":"opacity-70"),strokeWidth:I?2.4:2}),e.jsx("span",{className:Y("text-[11px] tracking-tight",I?"font-semibold":"font-medium"),children:f.label}),e.jsx("span",{className:Y("text-[11px] font-semibold tabular-nums leading-none",I?"text-foreground":"text-muted-foreground/80"),children:L&&f.count===0?"—":io(f.count)}),e.jsx("span",{"aria-hidden":!0,className:Y("absolute -bottom-px left-1/2 -translate-x-1/2 h-[2px] w-10 rounded-full transition-all duration-200",I?"bg-foreground opacity-100":"opacity-0")})]},f.id)})})})}),e.jsx("main",{className:"pt-3",children:e.jsx(Kn.Provider,{value:{ratings:Re,quickRate:xt,removeItem:ns},children:$!=="stashes"?e.jsx(go,{domain:ne,setDomain:de,sortKey:De,setSortKey:Ee,sortLabel:As,viewMode:C,setViewMode:z,showWishes:F,setShowWishes:ue,items:kr,ratings:Re,wishes:J,wishesLoading:X,searchQuery:D,onCardClick:gs,placeCoords:Bt,placeRegions:fs,regionLabelMap:Qs,subRegionParent:vr,anchorCoords:_r,savedLocations:ss,distanceRef:Tt,setDistanceRef:hs,requestCurrentLocation:xs,hasCurrentCoords:!!ps,onVisibleListChange:ut,onBulkApplyRating:Ps,onBulkRemove:ot,onWishRemove:zt,onWishToggleHide:Ut,onWishTogglePriority:kt,onWishAdd:Ts,vaultAll:y,userId:s,onSavedLocationAdded:f=>Ys(b=>[...b,f]),onCategoryScopeChange:xe,loadFailed:L,onRetryLoad:()=>{W(!1),E(f=>f+1)},onSilentRate:rt,onSilentRemove:Sr,onSilentWishlist:Xs,stashes:d,nearbyMode:$==="nearby",onExitNearby:()=>le("saves")}):e.jsx("div",{className:"px-4",children:e.jsx(Yo,{stashes:d,userId:s,searchQuery:D,navigate:t,onCreateStash:()=>Pt(!0),vault:y,guideItems:it,guideItemMeta:Z,stashScope:p,setStashScope:H,sharedWithMe:h.sharedWithMe,markAsViewed:h.markAsViewed,stashesLoaded:_,sharedLoading:h.loading})})})}),!oe&&e.jsxs("div",{className:Y("fixed right-4 z-40 flex items-center gap-2","transition-all duration-300",Yt?"opacity-100 translate-y-0":"opacity-0 translate-y-6 pointer-events-none"),style:{bottom:"calc(env(safe-area-inset-bottom) + 4.75rem)"},children:[$==="stashes"&&e.jsxs("button",{onClick:()=>ms(!0),"aria-label":"See suggested stashes",className:Y("h-14 roun
2ded-full bg-card text-foreground border border-border/70 inline-flex items-center gap-1.5 pl-3.5 pr-4","active:scale-95 transition-all duration-300"),style:{boxShadow:"0 0 0 3px hsl(var(--background)), 0 12px 28px -8px hsl(var(--foreground) / 0.28)"},children:[e.jsx(Tr,{className:"h-5 w-5 text-amber-500",strokeWidth:2.4}),e.jsx("span",{className:"text-sm font-semibold tracking-tight",children:"Suggested"})]}),e.jsxs("button",{onClick:()=>{$==="stashes"?Pt(!0):ie(!0)},"aria-label":$==="stashes"?"Create a stash":"Add to your Vault",className:Y("h-14 rounded-full bg-primary text-primary-foreground inline-flex items-center gap-2 pl-4 pr-5","active:scale-95 transition-all duration-300"),style:{boxShadow:"0 0 0 3px hsl(var(--background)), 0 12px 28px -6px hsl(var(--primary) / 0.55), 0 4px 12px hsl(var(--foreground) / 0.18)"},children:[e.jsx(Ns,{className:"h-6 w-6",strokeWidth:3}),e.jsx("span",{className:"text-sm font-semibold tracking-tight",children:$==="stashes"?"New stash":"Add"})]})]}),e.jsx("button",{onClick:br,"aria-label":"Scroll to top",className:Y("fixed left-4 z-40 h-9 w-9 rounded-full bg-card/90 backdrop-blur border border-border shadow-md","flex items-center justify-center text-foreground hover:bg-card transition-all duration-300 active:scale-95",wr&&Yt?"translate-y-0 opacity-100":"translate-y-24 opacity-0 pointer-events-none"),style:{bottom:"calc(env(safe-area-inset-bottom) + 5.75rem)"},children:e.jsx(Xa,{className:"h-4 w-4"})}),K&&e.jsx(Qo,{vault:y,stashes:d,userId:s,query:D,setQuery:k,onClose:()=>{g(!1),k("")},onPickTaste:(f,b)=>{_e.current=b&&b.length?b.slice():[],je(f),pt(!0),g(!1),k("")},onPickStash:(f,b)=>{t(`/vault?guide=${f}&guideName=${encodeURIComponent(b)}&returnTo=/profile?tab=stashes`),g(!1),k("")}})]}),e.jsx(ma,{activeTab:"profile",visible:Yt}),e.jsx(Hs,{open:R,onOpenChange:ie,children:e.jsx(qs,{side:"top",className:"rounded-b-3xl pt-[calc(env(safe-area-inset-top)+1rem)] pb-6 max-h-[92dvh] overflow-y-auto",children:e.jsxs("div",{className:"mx-auto max-w-md",children:[e.jsx("h2",{className:"text-center text-lg font-semibold",children:"What do you want to add?"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mt-4",children:[e.jsxs("button",{onClick:()=>{ie(!1),We(!0)},className:"group rounded-2xl border border-border/60 bg-card p-4 flex flex-col items-center text-center active:scale-[0.98] transition-all hover:border-primary/40 hover:shadow-md",children:[e.jsx("div",{className:"h-11 w-11 rounded-xl bg-gradient-to-br from-primary/20 to-accent/20 flex items-center justify-center",children:e.jsx(Za,{className:"h-5 w-5 text-primary"})}),e.jsx("div",{className:"mt-3 font-semibold text-sm",children:"Save something"})]}),e.jsxs("button",{onClick:()=>{ie(!1),Pt(!0)},className:"group rounded-2xl border border-border/60 bg-card p-4 flex flex-col items-center text-center active:scale-[0.98] transition-all hover:border-accent/40 hover:shadow-md",children:[e.jsx("div",{className:"h-11 w-11 rounded-xl bg-gradient-to-br from-accent/25 to-primary/15 flex items-center justify-center",children:e.jsx(ys,{className:"h-5 w-5 text-accent-foreground"})}),e.jsx("div",{className:"mt-3 font-semibold text-sm",children:"Create a stash"})]})]})]})})}),e.jsx(Ga,{open:st,onOpenChange:We,userId:s}),s&&e.jsx(qa,{open:Nt,onOpenChange:Pt,userId:s,onGuideCreated:(f,b)=>{Pt(!1),t(`/vault?guide=${f}&guideName=${encodeURIComponent(b)}&returnTo=/profile?tab=stashes`)}}),e.jsx(Yi,{open:At,onOpenChange:ms,initialSuggestions:gr,userId:s,onCreated:(f,b)=>{ms(!1),t(`/vault?guide=${f}&guideName=${encodeURIComponent(b)}&returnTo=/profile?tab=stashes`)}}),e.jsx(Wa,{item:ee?{vault_taste_id:ee.vault_taste_id,entity_id:ee.entity_id,domain:ee.domain||"",level_1:ee.level_1||void 0,level_2:ee.level_2,title:ee.title,subtitle:ee.subtitle,thumbnail_url:ee.thumbnail_url,website:ee.website,taxonomy_id:ee.taxonomy_id}:null,open:Ae,onOpenChange:f=>{pt(f),f||(_e.current=[])},onPrev:Ze?()=>je(Ze):null,onNext:et?()=>je(et):null,onRatingChange:(f,b,I)=>ve(A=>({...A,[f]:{rating_value:b,experienced_state:I}})),onTitleChange:(f,b)=>j(I=>I.map(A=>A.vault_taste_id===f?{...A,...b.title!=null?{title:b.title}:{}
2,...b.subtitle!=null?{subtitle:b.subtitle}:{},...b.website!=null?{website:b.website}:{}}:A)),onThumbnailChange:(f,b)=>j(I=>I.map(A=>A.vault_taste_id===f?{...A,thumbnail_url:b}:A)),onRemoved:()=>{ee&&j(f=>f.filter(b=>b.vault_taste_id!==ee.vault_taste_id)),pt(!1)}})]})},ho={all:"All saves",unrated:"Unrated",interested:"Interested",loved:"Loved",liked:"Liked",loved_liked:"Loved + Liked"},kn=({count:t,totalCount:a,saving:r,onCancel:s,onApply:i,onToggleAll:c,onDelete:m})=>{const d=a>0&&t>=a,[v,_]=n.useState(!1),[M,y]=n.useState(!1);n.useRef(null),n.useRef(!1);const j=t===0||r;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium",children:[e.jsx("button",{type:"button",onClick:()=>{j||i({experienced_state:"not_tried",rating_value:null,interest_value:1,label:"Interested"})},disabled:j,className:Y("h-7 px-3 rounded-full text-xs font-semibold border bg-background transition-colors select-none",j?"border-border/50 text-muted-foreground/60":"border-[hsl(145,30%,35%)] text-[hsl(145,30%,35%)] hover:bg-[hsl(145,30%,95%)]"),children:"Interested"}),e.jsx("button",{type:"button",onClick:()=>{j||i({experienced_state:"tried",rating_value:2,interest_value:null,label:"Loved"})},disabled:j,"aria-label":"Loved",className:Y("h-7 px-2.5 rounded-full border bg-background transition-colors select-none inline-flex items-center justify-center",j?"border-border/50 opacity-60":"border-[hsl(210,55%,38%)] hover:bg-[hsl(210,55%,38%)]/10"),children:e.jsx(Ft,{className:"h-3.5 w-3.5 fill-[hsl(0,65%,48%)] text-[hsl(0,65%,48%)]",strokeWidth:2})}),e.jsx("button",{type:"button",onClick:()=>{j||i({experienced_state:"tried",rating_value:1,interest_value:null,label:"Liked"})},disabled:j,"aria-label":"Liked",className:Y("h-7 px-2.5 rounded-full border bg-background transition-colors select-none inline-flex items-center justify-center",j?"border-border/50 opacity-60":"border-[hsl(210,55%,38%)] hover:bg-[hsl(210,55%,38%)]/10"),children:e.jsx("span",{"aria-hidden":!0,className:"text-xs leading-none",children:"👍"})}),m&&e.jsx("button",{type:"button",onClick:()=>{j||y(!0)},disabled:j,"aria-label":"Remove from vault",className:Y("h-7 px-2.5 rounded-full border bg-background transition-colors select-none inline-flex items-center justify-center",j?"border-border/50 opacity-60":"border-[hsl(0,70%,45%)] text-[hsl(0,70%,45%)] hover:bg-[hsl(0,70%,45%)]/10"),children:e.jsx(Vs,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:c,disabled:r||a===0,className:"ml-auto whitespace-nowrap text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?"Clear":"Select all"}),e.jsx("span",{className:"text-muted-foreground tabular-nums",children:r?"Saving…":`${t}`}),e.jsx("button",{onClick:s,disabled:r,className:"text-muted-foreground hover:text-foreground disabled:opacity-50",children:"Cancel"})]}),m&&e.jsx(Gr,{open:M,onOpenChange:y,onConfirm:()=>{y(!1),m()},title:`Remove ${t} taste${t===1?"":"s"} from your vault?`,description:"This will permanently delete the selected tastes from your vault. This action cannot be undone.",actionLabel:"Remove from Vault",isDeleting:r})]})},po=({count:t,totalCount:a,saving:r,onCancel:s,onApply:i,onToggleAll:c,onApplyRating:m,onDelete:d})=>{const v=a>0&&t>=a,_=t===0||r,[M,y]=n.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium",children:[e.jsx("button",{type:"button",onClick:()=>{_||i()},disabled:_,className:Y("h-7 px-3 rounded-full text-xs font-semibold transition-colors select-none",_?"bg-muted text-muted-foreground/60":"bg-primary text-primary-foreground hover:opacity-90"),children:"+ Wishlist"}),m&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>{_||m({experienced_state:"tried",rating_value:2,interest_value:null,label:"Loved"})},disabled:_,"aria-label":"Loved",className:Y("h-7 px-2.5 rounded-full border bg-background transition-colors select-none inline-flex items-center justify-center",_?"border-border/50 opacity-60":"border-[hsl(210,55%,38%)] hover:bg-[hsl(210,55%,38%)]/10"),children:e.jsx(Ft,{className:"h-3.5 w-3.5 fill-[hsl(0,65%,48%)] text-[hsl(0,65%,48%)]",strokeWidth:2})}),e.jsx("button",{type:"button",onClick:()=>{_||m({experienced_state:"tried",rating_value:1,interest_value:null,label:"Liked"})},disabled:_,"aria-label":"Liked",className:Y("h-7 px-2.5 rounded-full border bg-background transition-colors select-none inline-flex items-center justify-center",_?"border-border/50 opacity-60":"border-[hsl(210,55%,38%)] hover:bg-[hsl(210,55%,38%)]/10"),children:e.jsx("span",{"aria-hidden":!0,
2className:"text-xs leading-none",children:"👍"})})]}),d&&e.jsx("button",{type:"button",onClick:()=>{_||y(!0)},disabled:_,"aria-label":"Remove from vault",className:Y("h-7 px-2.5 rounded-full border bg-background transition-colors select-none inline-flex items-center justify-center",_?"border-border/50 opacity-60":"border-[hsl(0,70%,45%)] text-[hsl(0,70%,45%)] hover:bg-[hsl(0,70%,45%)]/10"),children:e.jsx(Vs,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:c,disabled:r||a===0,className:"ml-auto whitespace-nowrap text-muted-foreground hover:text-foreground disabled:opacity-50",children:v?"Clear":"Select all"}),e.jsx("span",{className:"text-muted-foreground tabular-nums",children:r?"Saving…":`${t}`}),e.jsx("button",{onClick:s,disabled:r,className:"text-muted-foreground hover:text-foreground disabled:opacity-50",children:"Cancel"})]}),d&&e.jsx(Gr,{open:M,onOpenChange:y,onConfirm:()=>{y(!1),d()},title:`Remove ${t} taste${t===1?"":"s"} from your vault?`,description:"This will permanently delete the selected tastes from your vault. This action cannot be undone.",actionLabel:"Remove from Vault",isDeleting:r})]})},xo=({items:t,ratings:a,ratingFilter:r,setRatingFilter:s,categoryFilter:i,setCategoryFilter:c,onCardClick:m,categoryLabelFor:d,ratingFilterMatch:v,scopedItems:_,miscScopeLabels:M,setMiscScopeLabels:y,categoryL2Filter:j,setCategoryL2Filter:S,placeCoords:x,placeRegions:L,regionLabelMap:W,subRegionParent:V,anchorCoords:E,savedLocations:J,distanceRef:O,setDistanceRef:X,hasCurrentCoords:ge,requestCurrentLocation:Re,userId:ve,onSavedLocationAdded:it,showWishes:B,setShowWishes:Z,onBulkApplyRating:se,onSilentRate:G,onSilentRemove:ye,onSilentWishlist:Ye,onBulkRemove:Pe,stashes:Ve,nearbyMode:Le=!1,onExitNearby:$})=>{lr();const[le,ne]=n.useState(!1),[de,De]=n.useState(null),[Ee,C]=n.useState(!1),[z,F]=n.useState(""),[ue,re]=n.useState([]),[xe,oe]=n.useState(!1),P=n.useRef(null),[K,g]=n.useState("category"),[D,k]=n.useState(new Set);n.useEffect(()=>{k(new Set),g("category")},[de==null?void 0:de.lat,de==null?void 0:de.lng]);const[h,p]=n.useState(()=>typeof window>"u"?"distance":window.localStorage.getItem("fyra-place-l2-sort")==="region"?"region":"distance");n.useEffect(()=>{typeof window>"u"||window.localStorage.setItem("fyra-place-l2-sort",h)},[h]),n.useEffect(()=>{if(!Ee)return;const l=z.trim();if(l.length<3){re([]),oe(!1);return}return P.current&&window.clearTimeout(P.current),oe(!0),P.current=window.setTimeout(async()=>{try{const{data:o}=await U.functions.invoke("search-addresses",{body:{query:l}}),u=(o==null?void 0:o.suggestions)||[];re(u.filter(N=>typeof N.latitude=="number"&&typeof N.longitude=="number"))}catch(o){console.warn("[nearby] address search failed",o),re([])}finally{oe(!1)}},300),()=>{P.current&&window.clearTimeout(P.current)}},[z,Ee]);const H=Ke.useCallback((l,o,u)=>{y(null),s("all"),De({lat:o,lng:u,label:l}),c(`__nearby:${l}`),C(!1),F(""),re([])},[y,s,c]),te=Ke.useCallback(()=>{const l=J.find(o=>o.lat!=null&&o.lng!=null);l?H(l.name,Number(l.lat),Number(l.lng)):E?H("Current location",E.lat,E.lng):(ge||Re(),C(!0))},[J,E,ge,Re,H]),we=n.useRef(!1),he=n.useRef(!1);n.useEffect(()=>{Le&&!we.current?(we.current=!0,he.current=!1,te()):!Le&&we.current&&(we.current=!1,he.current=!1,De(null),c(null))},[Le]),n.useEffect(()=>{!Le||he.current||i!=null&&i.startsWith(gs)||de||(J.length>0||E)&&te()},[Le,J,E,i,de]),n.useEffect(()=>{if(Le){if(i!=null&&i.startsWith(gs)){he.current=!0;return}he.current&&!i&&($==null||$())}},[i,Le]);const[ee,je]=n.useState(!1),[Ae,pt]=n.useState("rate"),[ae,ut]=n.useState(new Set),[_e,Ze]=n.useState(!1),{toast:et}=js(),Te=Ke.useCallback(()=>{je(!1),pt("rate"),ut(new Set)},[]);n.useEffect(()=>(window.dispatchEvent(new CustomEvent("vault:bulk-select-change",{detail:{active:ee}})),()=>{ee&&window.dispatchEvent(new CustomEvent("vault:bulk-select-change",{detail:{active:!1}}))}),[ee]),n.useEffect(()=>{if(!i){Te();return}Ae==="rate"&&r!=="unrated"&&Te(),Ae==="wishlist"&&r!=="interested"&&Te()},[i,r,Ae,Te]);const bt=Ke.useCallback(async l=>{if(!ve||l.length===0)return 0;let o=0;for(const u of l)try{await Ir(ve,u),o+=1}catch{}return et({title:o>0?`Added ${o} to wishlist`:"Couldn't add to wishlist"}),o},[ve,et]),[Ue,tt]=n.useState(!1),[R,ie]=n.useState(!1),[st,We]=n.useState(""),[Nt,Pt]=n.useState(null),At=Ke.useMemo(()=>{const l=t.length?t:_,o=new Map(l.map(N=>
2[N.vault_taste_id,N])),u=[];return ae.forEach(N=>{const w=o.get(N);w&&u.push(w)}),u},[t,_,ae]),ms=Ke.useMemo(()=>{if(At.length===0)return"";const l=new Map;for(const N of At){const w=d(N)||N.level_1||"Other";l.has(w)||l.set(w,[]),l.get(w).push(N)}const u=[i?`${i} — my picks`:"My picks",""];for(const[N,w]of Array.from(l.entries()).sort((T,q)=>T[0].localeCompare(q[0]))){u.push(N);for(const T of w){const q=(T.title||"(Untitled)").trim(),Q=(T.subtitle||"").trim();u.push(Q?`• ${q} — ${Q}`:`• ${q}`)}u.push("")}return u.push("Shared from Fyra"),u.join(`
3`).trim()},[At,d,i]),gr=Ke.useCallback(async()=>{const l=ms;if(l){try{if(typeof navigator<"u"&&navigator.share){await navigator.share({text:l,title:i?`${i} — my picks`:"My picks"});return}}catch{}try{const o=encodeURIComponent(l);window.location.href=`sms:&body=${o}`;return}catch{}try{await navigator.clipboard.writeText(l),et({title:"Copied to clipboard"})}catch{et({title:"Couldn't share",variant:"destructive"})}}},[ms,i,et]),ks=Ke.useCallback(async l=>{var o;if(console.log("[stash-add] click",{stashId:l,userId:ve,selectedCount:ae.size,resolvedCount:At.length}),!ve){et({title:"Please sign in again",variant:"destructive"});return}if(ae.size===0){et({title:"Nothing selected",variant:"destructive"});return}if(At.length===0){console.warn("[stash-add] selectedIds present but no items resolved from vault",Array.from(ae)),et({title:"Couldn't find selected items",description:"Try reopening the vault and selecting again.",variant:"destructive"});return}Pt(l);try{const{data:u,error:N}=await U.from("user_guide_items").select("taste_id").eq("guide_id",l);if(N)throw N;const w=new Set((u||[]).map(me=>me.taste_id)),T=At.filter(me=>!w.has(me.vault_taste_id)).map(me=>({guide_id:l,taste_id:me.vault_taste_id,display_name:me.title||"(Untitled)",added_by_user_id:ve}));if(console.log("[stash-add] insert plan",{existing:w.size,newRows:T.length}),T.length>0){const{error:me}=await U.from("user_guide_items").insert(T);if(me)throw console.error("[stash-add] insert error",me),me;try{const{autoAssignStashSections:Ie}=await Rn(async()=>{const{autoAssignStashSections:ze}=await import("./pdfToText-Bt1irvKN.js").then(Qe=>Qe.b);return{autoAssignStashSections:ze}},__vite__mapDeps([3,1,2]));Ie(l,T.map(ze=>ze.taste_id)).catch(()=>{})}catch{}}const q=At.length-T.length,Q=((o=Ve.find(me=>me.id===l))==null?void 0:o.name)||"Stash";et({title:T.length>0?`Added ${T.length} to ${Q}`:`Already in ${Q}`,description:T.length>0&&q>0?`${q} already in stash`:void 0});try{localStorage.setItem("last_stash_id",l)}catch{}tt(!1),Te()}catch(u){console.error("bulk add to stash failed",u),et({title:"Failed to add to stash",description:(u==null?void 0:u.message)||void 0,variant:"destructive"})}finally{Pt(null)}},[ve,ae,At,Ve,et,Te]),Kr=Ke.useCallback(async()=>{if(!ve)return;const l=st.trim();if(l){Pt("__new__");try{const{data:o,error:u}=await U.from("user_guides").insert({user_id:ve,name:l}).select("id").single();if(u||!o)throw u||new Error("no id");await ks(o.id),We("")}catch(o){console.error("create stash failed",o),et({title:"Couldn't create stash",variant:"destructive"}),Pt(null)}}},[ve,st,ks,et]),Ot=Ke.useCallback(l=>{ut(o=>{const u=new Set(o);return u.has(l)?u.delete(l):u.add(l),u})},[]),Ss=n.useMemo(()=>[...t].sort((l,o)=>(o.created_at||"").localeCompare(l.created_at||"")).slice(0,15),[t]),{items:Kt,refresh:br}=Ci(),[Bt,Cs]=n.useState(!1),[fs,Fs]=n.useState(null),[Ks,Ms]=n.useState(null),[vr,Ls]=n.useState(null),[_r,ts]=n.useState(null),ss=Ke.useCallback((l,o)=>{Fs(l),Ms(l==="url"?o??null:null),Ls(l==="photo"?o??null:null),ts(null)},[]),Ys=Ke.useCallback((l,o)=>{const u=`${l}:${o}`;ts(u),setTimeout(()=>ss(l,o),50)},[ss]),{items:Tt,siblings:hs}=n.useMemo(()=>{const l=t.filter(o=>{const u=a[o.vault_taste_id];return!u||u.rating_value==null&&u.experienced_state!=="not_tried"}).sort((o,u)=>(u.created_at||"").localeCompare(o.created_at||""));return eo(l)},[t,a]),ps=Ke.useCallback(async(l,o)=>{const u=await G(l,o),N=hs.get(l);return N!=null&&N.length&&await Promise.all(N.map(w=>G(w,o))),u},[G,hs]),[yr,Es]=n.useState(!1),Yt=n.useMemo(()=>{const l=new Map,o=new Map;t.forEach(w=>{const T=d(w);if(!T||T.toLowerCase()==="other")return;l.set(T,(l.get(T)||0)+1);const q=Rt(w.domain);if(q){const Q=o.get(T)||{};Q[q]=(Q[q]||0)+1,o.set(T,Q)}});const u=new Map;t.filter(v).forEach(w=>{const T=d(w);!T||T.toLowerCase()==="other"||u.set(T,(u.get(T)||0)+1)});const N=["product","place","media","creation"];return Array.from(l.entries()).sort((w,T)=>T[1]-w[1]).slice(0,12).map(([w])=>{const T=o.get(w)||{};let q=null,Q=-1;
3for(const me of N){const Ie=T[me]||0;Ie>Q&&(Q=Ie,q=Ie>0?me:q)}return{label:w,count:u.get(w)||0,domain:q}}).filter(w=>w.count>0)},[t,r,d,v]),[vt,wr]=n.useState(!1),[Yr,rs]=n.useState(new Set);n.useCallback(l=>{rs(o=>{const u=new Set(o);return u.has(l)?u.delete(l):u.add(l),u})},[]);const[jr,Js]=n.useState(new Set),Nr=n.useCallback(l=>{Js(o=>{const u=new Set(o);return u.has(l)?u.delete(l):u.add(l),u})},[]);n.useEffect(()=>{vt||(rs(new Set),Js(new Set))},[vt]);const kr=1,Qs=n.useMemo(()=>{const l=new Map;for(const w of t){const T=d(w);if(!T||T.toLowerCase()==="other")continue;const q=Rt(w.domain);if(!q)continue;let Q=l.get(q);Q||(Q=new Map,l.set(q,Q)),Q.set(T,(Q.get(T)||0)+1)}const o=["place","product","media","creation"],u={place:"Places",product:"Products",media:"Media",creation:"Creations"},N=[];for(const w of o){const T=l.get(w);if(!T)continue;const q=Array.from(T.entries()).sort((Qe,ke)=>ke[1]-Qe[1]),Q=[],me=[];let Ie=0;for(const[Qe,ke]of q)ke>=kr?Q.push({label:Qe,count:ke}):(me.push(Qe),Ie+=ke);let ze=null;me.length>=2?ze={count:Ie,labels:me}:me.length===1&&Q.push({label:me[0],count:Ie}),!(Q.length===0&&!ze)&&N.push({domain:w,label:u[w]||w,chips:Q,misc:ze})}return N},[t,d,Yt]),$t=Qs.length>0,xs="__region:",gs="__nearby:",at=i&&i.startsWith(xs)?i.slice(xs.length):null,xt=!!at,Ps=i&&i.startsWith(gs)?i.slice(gs.length):null,rt=!!Ps,ot=n.useMemo(()=>{if(M&&M.length>0){const l=new Set(M);return t.filter(o=>l.has(d(o)))}if(at)return t.filter(l=>{var o;return Rt(l.domain)==="place"&&(((o=W.get(l.vault_taste_id))==null?void 0:o.label)||hr(l,L))===at});if(rt){const l=t.filter(o=>Rt(o.domain)==="place");return de?l.filter(o=>{const u=x[String(o.entity_id)];return u?Ds(de,u)<=Nn:!1}):l}return i?t.filter(l=>d(l)===i):[]},[t,i,M,d,at,rt,L,W,de,x]),Sr=n.useMemo(()=>{const l={all:0,unrated:0,interested:0,loved:0};for(const o of ot){l.all+=1;const u=a[o.vault_taste_id],N=!u||u.rating_value==null&&u.experienced_state!=="not_tried",w=!!u&&u.experienced_state==="not_tried"&&u.rating_value==null,T=(u==null?void 0:u.rating_value)===2;N&&(l.unrated+=1),w&&(l.interested+=1),T&&(l.loved+=1)}return l},[ot,a]),Xs=n.useMemo(()=>{if(!i||ot.length===0)return[];const l=new Map;if(xt)for(const o of ot){const u=Zt(o);!u||u.toLowerCase()==="other"||l.set(u,(l.get(u)||0)+1)}else{const o=(i||"").toLowerCase()==="recipes";for(const u of ot){const N=(u.level_2||"").trim();!N||N.toLowerCase()==="other"||o&&N.toLowerCase()==="creations"||l.set(N,(l.get(N)||0)+1)}}return Array.from(l.entries()).sort((o,u)=>u[1]-o[1]||o[0].localeCompare(u[0])).map(([o,u])=>({label:o,count:u}))},[i,ot,xt]),ns=n.useMemo(()=>{const l=t.filter(u=>Rt(u.domain)==="place");return l.length===0?[]:or(l,L,W).map(u=>({label:u.label,emoji:u.emoji,count:u.items.filter(v).length})).filter(u=>u.count>0&&u.label!=="Unknown")},[t,L,W,r,v]);n.useEffect(()=>{S(null)},[i]);const As=i==="Music",zt=i==="Movies",Ut=As||zt,[kt,Ts]=n.useState(null),[Jt,Zs]=n.useState({});n.useEffect(()=>{Ts(null)},[i]);const f=Ke.useCallback(l=>{let o=(l||"").trim();return o?(o=o.replace(/\s+films?$/i,""),o.replace(/\b\w/g,u=>u.toUpperCase())):""},[]);n.useEffect(()=>{if(!Ut||ot.length===0)return;let l=!1;return(async()=>{try{const o=ot.filter(N=>!(N.vault_taste_id in Jt));if(o.length===0)return;const u={};if(zt){const N=new Map,w=new Map;for(const T of o){const q=String(T.entity_id||"");if(!q)continue;let Q=q.match(/^Q_tmdb_movie_(\d+)$/);if(Q||(Q=q.match(/^tmdb[-_]movie[-_](\d+)$/i)),Q){const me=w.get(Q[1])||[];me.push(T.vault_taste_id),w.set(Q[1],me);continue}if(/^Q\d+$/.test(q)){const me=N.get(q)||[];me.push(T.vault_taste_id),N.set(q,me)}}if(N.size>0){const T=Array.from(N.keys());for(let q=0;q<T.length;q+=200){const{data:Q}=await U.from("corpus_media_movie").select("id,genre_names").in("id",T.slice(q,q+200));for(const me of Q||[]){const Ie=me,ze=String(Ie.genre_names||"").split("|").map(f).filter(Boolean);for(const Qe of N.get(String(Ie.id||""))||[])u[Qe]=ze}}}if(w.size>0){const T=Array.from(w.keys()).map(Number).filter(Number.isFinite);for(let q=0;q<T.length;q+=200){const{data:Q}=await U.from("corpus_media_movie").select("tmdb_id,genre_names").in("tmdb_id",T.slice(q,q+200));for(const me of Q||[]){const Ie=me,ze=String(Ie.genre_names||"").split("|").map(f).filter(
3Boolean);for(const Qe of w.get(String(Ie.tmdb_id??""))||[])u[Qe]=ze}}}}else if(As){const N=new Map,w=new Map;for(const q of o){const Q=String(q.entity_id||"");if(!Q)continue;const me=Q.match(/^music\|soundchart:([0-9a-f-]{36})$/i);if(me){const ze=w.get(me[1])||[];ze.push(q.vault_taste_id),w.set(me[1],ze);continue}const Ie=Q.match(/^(?:a\.|i\.|a\.i\.)?(\d+)$/);if(Ie){const ze=N.get(Ie[1])||[];ze.push(q.vault_taste_id),N.set(Ie[1],ze)}}const T=q=>String(q||"").split(/[,|]/).map(Q=>Q.trim()).filter(Boolean);if(N.size>0){const q=Array.from(N.keys());for(let Q=0;Q<q.length;Q+=200){const{data:me}=await U.from("corpus_media_song").select("apple_catalog_id,song_genres").in("apple_catalog_id",q.slice(Q,Q+200));for(const Ie of me||[]){const ze=Ie,Qe=T(ze.song_genres||"");for(const ke of N.get(String(ze.apple_catalog_id??""))||[])u[ke]=Qe}}}if(w.size>0){const q=Array.from(w.keys());for(let Q=0;Q<q.length;Q+=200){const{data:me}=await U.from("corpus_media_song").select("uuid,song_genres").in("uuid",q.slice(Q,Q+200));for(const Ie of me||[]){const ze=Ie,Qe=T(ze.song_genres||"");for(const ke of w.get(String(ze.uuid||""))||[])u[ke]=Qe}}}}for(const N of o)N.vault_taste_id in u||(u[N.vault_taste_id]=[]);l||Zs(N=>({...N,...u}))}catch{}})(),()=>{l=!0}},[Ut,As,zt,ot]);const b=n.useMemo(()=>{if(!Ut)return[];const l=new Map;for(const o of ot){const u=Jt[o.vault_taste_id];if(!u||u.length===0)continue;const N=new Set;for(const w of u){const T=zt?f(w):w;!T||N.has(T)||(N.add(T),l.set(T,(l.get(T)||0)+1))}}return Array.from(l.entries()).sort((o,u)=>u[1]-o[1]||o[0].localeCompare(u[0])).slice(0,20).map(([o,u])=>({label:o,count:u}))},[Ut,zt,ot,Jt,f]),I=Ke.useCallback(l=>{if(!kt)return!0;const o=Jt[l.vault_taste_id]||[];return zt?o.some(u=>f(u)===kt):o.some(u=>u===kt)},[kt,Jt,zt,f]),A=i==="Fashion",pe=i==="Recipes",[be,Ne]=n.useState(!1),[fe,Ge]=n.useState(null),[Oe,_t]=n.useState({});n.useEffect(()=>{Ge(null)},[i]),n.useEffect(()=>{if(!A||ot.length===0)return;let l=!1;return(async()=>{try{const o=ot.filter(w=>!(w.vault_taste_id in Oe));if(o.length===0)return;const u=new Map;for(const w of o){const T=String(w.entity_id||"").trim();if(!T||!/^\d+$/.test(T))continue;const q=u.get(T)||[];q.push(w.vault_taste_id),u.set(T,q)}const N={};if(u.size>0){const w=Array.from(u.keys());for(let T=0;T<w.length;T+=200){const{data:q}=await U.from("corpus_products").select("id,brand_name").in("id",w.slice(T,T+200));for(const Q of q||[]){const me=Q,Ie=String(me.brand_name||"").trim();if(Ie)for(const ze of u.get(String(me.id??""))||[])N[ze]=Ie}}}for(const w of o)w.vault_taste_id in N||(N[w.vault_taste_id]="");l||_t(w=>({...w,...N}))}catch{}})(),()=>{l=!0}},[A,ot]);const St=Ke.useCallback(l=>{const o=String(l.subtitle||"").trim();return o||(Oe[l.vault_taste_id]||"").trim()},[Oe]),yt=n.useMemo(()=>{if(!A)return[];const l=new Map;for(const o of ot){const u=St(o);u&&l.set(u,(l.get(u)||0)+1)}return Array.from(l.entries()).sort((o,u)=>o[0].localeCompare(u[0])).map(([o,u])=>({label:o,count:u}))},[A,ot,St]),Wt=Ke.useCallback(l=>fe?St(l)===fe:!0,[fe,St]),lt=n.useMemo(()=>{var u;if(rt)return"place";if(!i||ot.length===0)return null;const l={};for(const N of ot){const w=nt(N.domain)||"";w&&(l[w]=(l[w]||0)+1)}return((u=Object.entries(l).sort((N,w)=>w[1]-N[1])[0])==null?void 0:u[0])||null},[i,ot,rt])==="place",Se=n.useMemo(()=>rt&&de?{lat:de.lat,lng:de.lng}:E,[rt,de,E]),Ce=n.useMemo(()=>!rt||!de?_:_.filter(l=>{if(Rt(l.domain)!=="place")return!1;const o=x[String(l.entity_id)];return o?Ds(de,o)<=Nn:!1}),[_,rt,de,x]),Fe=n.useMemo(()=>{let l=Ut&&kt?Ce.filter(I):Ce;if(A&&fe&&(l=l.filter(Wt)),lt&&!xt&&!rt&&Se)return $s(l,x,Se).flatMap(u=>u.items);if(rt&&lt)return cs(l).flatMap(u=>u.items);const o=[...l].sort((u,N)=>(N.created_at||"").localeCompare(u.created_at||""));if(r==="loved_liked"&&!(lt&&!xt&&Se)){const u=N=>{const w=a[N.vault_taste_id];return(w==null?void 0:w.rating_value)===2?0:(w==null?void 0:w.rating_value)===1?1:2};return o.sort((N,w)=>u(N)-u(w))}return o},[Ce,lt,xt,rt,Se,x,r,a,Ut,kt,I,A,fe,Wt]),Is=n.useMemo(()=>{if(O==="current")return"Current location";const l=J.find(o=>o.id===O);return(l==null?void 0:l.name)||"Pick reference"},[O,J]),bs=[{key:"all",label:"All"},{key:"unrated",label:"Unrated"},{key:"interested",label:"Interested"},{key:"loved",label:"Loved"}],as={all:"all",unrated:"unrated",interested:"interested",loved:"loved_liked"},Be={all:"all",unrated:"unrated",interested:"interested",loved:"loved",liked:"loved",loved_liked:"loved"}[r]??null,[Xe,Me]=n.useState(!1),He=n.useRef(null),$e=n.useRef(!1),Je=()=>{$e.current=!1,He.current&&window.clearTimeout(He.current),He.current=window.setTimeout(()=>{$e.current=!0,Me(!0)},380)},gt=()=>{He.current&&(window.clearTimeout(He.current),He.current=null)},is=n.useMemo(()=>lt&&(rt||xt)?cs(Ce):[],[lt,rt,xt,Ce]),Qt=e.jsxs("div",{className:"inline-flex items-stretch h-10 rounded-full border overflow-hidden",style:{borderColor:`${os.place}4D`,background:`${os.place}14`},children:[e.jsxs("button",{type:"button",onClick:()=>C(!0),className:"inline-flex items-center gap-2 pl-3.5 pr-3 transition-all active:scale-[0.98]","aria-label":"Choose Nearby location",children:[e.jsx(Xt,{className:"h-[18px] w-[18px] shrink-0",style:{color:os.place}}),e.jsx("span",{className:"text-sm font-semibold tracking-tight text-foreground max-w-[150px] truncate",children:(de==null?void 0:de.label)||"Choose location"})]}),e.jsxs(oa,{open:Ee,onOpenChange:C,children:[e.jsx(la,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex items-center justify-center px-2.5 border-l transition-colors hover:bg-background/40 active:scale-[0.98]",style:{borderColor:`${os.place}33`},"aria-label":"Choose Nearby location",children:e.jsx(jt,{className:"h-4 w-4 text-foreground
3/70"})})}),e.jsx(ca,{align:"start",className:"w-72 p-2",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("button",{onClick:()=>{if(!ge){Re();return}E&&H("Current location",E.lat,E.lng)},className:"w-full flex items-center gap-2 px-2 py-2 rounded-md hover:bg-muted text-left text-sm",children:[e.jsx(Xt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:ge?"Current location":"Use current location"})]}),J.map(l=>l.lat!=null&&l.lng!=null?e.jsxs("button",{onClick:()=>H(l.name,Number(l.lat),Number(l.lng)),className:"w-full flex items-center gap-2 px-2 py-2 rounded-md hover:bg-muted text-left text-sm",children:[e.jsx(ht,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:l.name})]},l.id):null),e.jsxs("div",{className:"border-t border-border/60 mt-1 pt-2",children:[e.jsx("input",{type:"text",inputMode:"search",autoComplete:"off",placeholder:"Search an address or place…",value:z,onChange:l=>F(l.target.value),className:"w-full h-9 px-2.5 rounded-md border border-border/60 bg-background text-[16px] focus:outline-none focus:ring-1 focus:ring-primary"}),xe&&e.jsx("div",{className:"px-2 py-2 text-xs text-muted-foreground",children:"Searching…"}),!xe&&ue.length>0&&e.jsx("div",{className:"mt-1 max-h-56 overflow-auto",children:ue.map((l,o)=>e.jsxs("button",{onClick:()=>H(l.label,Number(l.latitude),Number(l.longitude)),className:"w-full flex items-center gap-2 px-2 py-2 rounded-md hover:bg-muted text-left text-xs",children:[e.jsx(ht,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"truncate",children:l.label})]},`${l.label}-${o}`))})]})]})})]})]});if(i){const l=Le&&rt;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 -mt-1",children:[!l&&e.jsx("button",{onClick:()=>{c(null),s("all"),De(null)},className:"inline-flex items-center justify-center h-9 w-9 -ml-2 rounded-full hover:bg-muted/60 transition-colors","aria-label":"Back to Tastes",children:e.jsx(ai,{className:"h-5 w-5"})}),l?Qt:e.jsx("h2",{className:"text-lg font-semibold tracking-tight",children:at||(Ps?`Near ${Ps}`:i)}),rt&&e.jsxs("div",{className:"ml-auto inline-flex items-center rounded-full border border-border/60 bg-card/60 p-0.5 text-[11px] font-medium",children:[e.jsx("button",{type:"button",onClick:()=>g("category"),className:Y("px-2.5 h-7 rounded-full transition-colors",K==="category"?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"),"aria-pressed":K==="category",children:"Category"}),e.jsx("button",{type:"button",onClick:()=>g("distance"),className:Y("px-2.5 h-7 rounded-full transition-colors",K==="distance"?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"),"aria-pressed":K==="distance",children:"Distance"})]}),!rt&&e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[pe&&e.jsxs("button",{type:"button",onClick:()=>Ne(!0),className:"inline-flex items-center gap-1 h-8 px-2.5 rounded-full border border-border/60 bg-card/60 text-xs font-medium text-foreground hover:bg-card transition-colors","aria-label":"Set dietary preferences",title:"Dietary preferences",children:[e.jsx(Gn,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Dietary"})]}),Ut&&b.length>=2?e.jsxs(Gt,{children:[e.jsx(Ht,{asChild:!0,children:e.jsxs("button",{type:"button",className:Y("inline-flex items-center gap-1 h-8 px-2.5 rounded-full border text-xs font-medium transition-colors",kt?"bg-foreground text-background border-foreground":"border-border/60 bg-card/60 text-foreground hover:bg-card"),"aria-label":"Filter by genre",children:[e.jsx("span",{className:"max-w-[140px] truncate",children:kt||"All genres"}),e.jsx(jt,{className:"h-3 w-3 opacity-70"})]})}),e.jsxs(qt,{align:"end",className:"min-w-[200px] max-h-[60vh] overflow-y-auto",children:[e.jsxs(ct,{onClick:()=>Ts(null),className:"flex items-center justify-between",children:[e.jsx("span",{children:"All genres"}),!kt&&e.jsx(mt,{className:"h-3.5 w-3.5"})]}),b.map(o=>e.jsxs(ct,{onClick:()=>Ts(o.label),className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:o.label}),e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[o.count,kt===o.label&&e.jsx(mt,{className:"h-3.5 w-3.5 text-foreground"})]})]},o.label))]})]}):A?e.jsxs(Gt,{children:[e.jsx(Ht,{asChild:!0,children:e.jsxs("button",{type:"button",className:Y("inline-flex items-center gap-1 h-8 px-2.5 rounded-full border text-xs font-medium transition-colors",fe?"bg-foreground text-background border-foreground":"border-border/60 bg-card/60 text-foreground hover:bg-card"),"aria-label":"Filter by brand",children:[e.jsx("span",{className:"max-w-[140px] truncate",children:fe||"All brands"}),e.jsx(jt,{className:"h-3 w-3 opacity-70"})]})}),e.jsxs(qt,{align:"end",className:"min-w-[200px] max-h-[60vh] overflow-y-auto",children:[e.jsxs(ct,{onClick:()=>Ge(null),className:"flex items-center justify-between",children:[e.jsx("span",{children:"All brands"}),!fe&&e.jsx(mt,{className:"h-3.5 w-3.5"})]}),yt.map(o=>e.jsxs(ct,{onClick:()=>Ge(o.label),className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:o.label}),e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[o.count,fe===o.label&&e.jsx(mt,{className:"h-3.5 w-3.5 text-foreground"})]})]},o.label))]})]}):Xs.length>=2&&e.jsxs(Gt,{children:[e.jsx(Ht,{asChild:!0,children:e.jsxs("button",{type:"button",className:Y("inline-flex items-center gap-1 h-8 px-2.5 rounded-full border text-xs font-medium transition-colors",j?"bg-foreground text-background border-foreground":"border-border/60 bg-card/60 text-foreground hover:bg-card"),"aria-label":"Filter by subcategory",children:[e.jsx("span",{className:"max-w-[140px] truncate",children:j||(xt?"All categories":"All types")}),e.jsx(jt,{className:"h-3 w-3 opacity-70"})]})}),e.jsxs(qt,{align:"end",className:"min-w-[200px] max-h-[60vh] overflow-y-auto",children:[e.jsxs(ct,{onClick:()=>S(null),className:"flex items-center justify-between",children:[e.jsx("span",{children:xt?"All categories":"All types"}),!j&&e.jsx(mt,{className:"h-3.5 w-3.5"})]}),Xs.map(o=>e.jsxs(ct,{onClick:()=>S(o.label),className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:o.label}),e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[o.count,j===o.label&&e.jsx(mt,{className:"h-3.5 w-3.5 text-foreground"})]})]},o.label))]})]})]})]}),e.jsx(Ai,{open:be,onOpenChange:Ne}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[bs.map(o=>{const u=Sr[o.key];if(o.key==="unrated"&&u===0)return null;const N=Be===o.key,w=u===0&&o.key!=="all",T=Y("inline-flex items-center gap-1 h-9 px-3.5 rounded-full border text-sm font-medium transition-colors",N?"bg-foreground text-background border-foreground":w?"border-border/40 bg-card/30 text-muted-foreground
3/50 cursor-not-allowed":"border-border/60 bg-card/60 text-foreground hover:bg-card",ee&&!N?"opacity-50":"");if(o.key==="loved"){const q=r!=="loved";return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",disabled:w||ee,className:T,"aria-label":"Loved and Liked (hold for Loved only)",onPointerDown:Q=>{(Q.pointerType!=="mouse"||Q.button===0)&&Je()},onPointerUp:gt,onPointerLeave:gt,onPointerCancel:gt,onContextMenu:Q=>Q.preventDefault(),onClick:Q=>{if($e.current){Q.preventDefault();return}s("loved_liked")},children:[e.jsx(Ft,{"aria-hidden":!0,className:"h-4 w-4 fill-[hsl(0,65%,48%)] text-[hsl(0,65%,48%)]",strokeWidth:2}),q&&e.jsx("span",{"aria-hidden":!0,className:"text-base leading-none",children:"👍"})]}),Xe&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onPointerDown:()=>Me(!1)}),e.jsx("div",{role:"menu",className:"absolute right-0 top-full mt-1 z-50 min-w-[160px] rounded-md border border-border bg-popover text-popover-foreground shadow-md p-1",children:e.jsxs("button",{type:"button",role:"menuitem",className:"flex w-full items-center justify-between gap-3 px-2 py-1.5 text-sm rounded-sm hover:bg-accent hover:text-accent-foreground",onClick:()=>{s(r==="loved"?"loved_liked":"loved"),Me(!1)},children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ft,{"aria-hidden":!0,className:"h-3.5 w-3.5 fill-[hsl(0,65%,48%)] text-[hsl(0,65%,48%)]",strokeWidth:2}),e.jsx("span",{children:"Loved only"})]}),r==="loved"&&e.jsx(mt,{className:"h-3.5 w-3.5"})]})})]})]},o.key)}return e.jsx("button",{onClick:()=>s(as[o.key]),disabled:w||ee,className:T,"aria-label":o.label,children:o.label},o.key)}),!ee&&r!=="unrated"&&r!=="interested"&&Fe.length>0&&e.jsx("button",{type:"button",onClick:()=>{pt("manage"),ut(new Set(Fe.map(o=>o.vault_taste_id))),je(!0)},className:"inline-flex items-center gap-1 h-9 px-3.5 rounded-full border text-sm font-medium transition-colors border-border/60 bg-card/60 text-foreground hover:bg-card",children:"Select all"})]}),!ee&&r==="unrated"&&Fe.length>0&&e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{type:"button",onClick:()=>{ut(new Set),je(!0)},className:"text-xs font-medium text-primary hover:underline",children:"Select"})}),!ee&&r==="interested"&&Fe.length>0&&e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{type:"button",onClick:()=>{pt("wishlist"),ut(new Set),je(!0)},className:"text-xs font-medium text-primary hover:underline",children:"Select"})}),ee&&Ae==="rate"&&!lt&&e.jsx("div",{className:"sticky top-0 z-30 -mx-4 px-4 py-3 bg-background/95 backdrop-blur-xl border-b border-border/40",children:e.jsx(kn,{count:ae.size,totalCount:Fe.length,saving:_e,onCancel:Te,onToggleAll:()=>{ae.size>=Fe.length?ut(new Set):ut(new Set(Fe.map(o=>o.vault_taste_id)))},onApply:async o=>{if(ae.size===0||_e)return;Ze(!0);const u=await se(Array.from(ae),o);Ze(!1),u>0&&Te()},onDelete:async()=>{if(ae.size===0||_e)return;Ze(!0);const o=await Pe(Array.from(ae));Ze(!1),o>0&&Te()}})}),ee&&Ae==="wishlist"&&e.jsx("div",{className:"sticky top-0 z-30 -mx-4 px-4 py-3 bg-background/95 backdrop-blur-xl border-b border-border/40",children:e.jsx(po,{count:ae.size,totalCount:Fe.length,saving:_e,onCancel:Te,onToggleAll:()=>{ae.size>=Fe.length?ut(new Set):ut(new Set(Fe.map(o=>o.vault_taste_id)))},onApply:async()=>{if(ae.size===0||_e)return;Ze(!0);const o=await bt(Array.from(ae));Ze(!1),o>0&&Te()},onApplyRating:async o=>{if(ae.size===0||_e)return;Ze(!0);const u=await se(Array.from(ae),o);Ze(!1),u>0&&Te()},onDelete:async()=>{if(ae.size===0||_e)return;Ze(!0);const o=await Pe(Array.from(ae));Ze(!1),o>0&&Te()}})}),ee&&Ae==="manage"&&e.jsx("div",{className:"sticky top-0 z-30 -mx-4 px-4 py-3 bg-background/95 backdrop-blur-xl border-b border-border/40",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium",children:[e.jsxs("button",{type:"button",onClick:()=>ae.size>0&&ie(!0),disabled:ae.size===0||_e,className:Y("h-7 px-3 rounded-full border bg-background transition-colors select-none inline-flex items-center gap-1.5",ae.size===0||_e?"border-border/50 text-muted-foreground
3/60":"border-[hsl(0,70%,45%)] text-[hsl(0,70%,45%)] hover:bg-[hsl(0,70%,45%)]/10"),children:[e.jsx(Vs,{className:"h-3.5 w-3.5"})," Delete"]}),e.jsxs("button",{type:"button",onClick:()=>ae.size>0&&tt(!0),disabled:ae.size===0||_e,className:Y("h-7 px-3 rounded-full border bg-background transition-colors select-none inline-flex items-center gap-1.5",ae.size===0||_e?"border-border/50 text-muted-foreground/60":"border-[hsl(210,55%,38%)] text-[hsl(210,55%,38%)] hover:bg-[hsl(210,55%,38%)]/10"),children:[e.jsx(zs,{className:"h-3.5 w-3.5"})," Stash"]}),e.jsxs("button",{type:"button",onClick:()=>{ae.size>0&&gr()},disabled:ae.size===0||_e,className:Y("h-7 px-3 rounded-full border bg-background transition-colors select-none inline-flex items-center gap-1.5",ae.size===0||_e?"border-border/50 text-muted-foreground/60":"border-[hsl(145,30%,35%)] text-[hsl(145,30%,35%)] hover:bg-[hsl(145,30%,95%)]"),children:[e.jsx(ii,{className:"h-3.5 w-3.5"})," Share"]}),e.jsx("button",{onClick:Te,disabled:_e,className:"ml-auto text-muted-foreground hover:text-foreground disabled:opacity-50",children:"Cancel"})]})}),e.jsx(Gr,{open:R,onOpenChange:ie,onConfirm:async()=>{if(ie(!1),ae.size===0||_e)return;Ze(!0);const o=await Pe(Array.from(ae));Ze(!1),o>0&&Te()},title:`Delete ${ae.size} taste${ae.size===1?"":"s"} from your vault?`,description:"This will permanently remove the selected tastes from your vault. This action cannot be undone.",actionLabel:"Delete from Vault",isDeleting:_e}),e.jsx(Hs,{open:Ue,onOpenChange:tt,children:e.jsxs(qs,{side:"top",className:"max-h-[85vh] rounded-b-2xl safe-top overflow-y-auto",children:[e.jsxs("div",{className:"mb-3",children:[e.jsxs("h3",{className:"text-sm font-semibold",children:["Add ",ae.size," taste",ae.size===1?"":"s"," to a Stash"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Pick an existing stash or create a new one."})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ds,{value:st,onChange:o=>We(o.target.value),placeholder:"New stash name",className:"h-9 text-sm",disabled:Nt!==null}),e.jsx(Lt,{size:"sm",onClick:()=>void Kr(),disabled:!st.trim()||Nt!==null,children:Nt==="__new__"?e.jsx(wt,{className:"h-3.5 w-3.5 animate-spin"}):"Create"})]}),e.jsx("div",{className:"space-y-1 overflow-y-auto max-h-[45vh]",children:Ve.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"No stashes yet. Create one above."}):Ve.map(o=>e.jsxs("button",{onClick:()=>void ks(o.id),disabled:Nt!==null,className:"w-full text-left px-3 py-2.5 rounded-md hover:bg-accent/50 text-sm font-medium flex items-center gap-3 transition-colors disabled:opacity-50",children:[o.cover_url?e.jsx("img",{src:Et(o.cover_url,"avatarXs")??o.cover_url,alt:"",loading:"lazy",decoding:"async",className:"h-9 w-9 rounded-md object-cover flex-shrink-0"}):e.jsx("div",{className:"h-9 w-9 rounded-md bg-muted flex items-center justify-center flex-shrink-0",children:e.jsx(ur,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx("span",{className:"truncate flex-1",children:o.name}),Nt===o.id&&e.jsx(wt,{className:"h-3.5 w-3.5 animate-spin flex-shrink-0"})]},o.id))})]})}),lt&&!xt&&!rt&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(Gt,{children:[e.jsx(Ht,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1 h-7 px-2.5 rounded-full bg-muted/50 text-[11px] font-medium text-muted-foreground hover:bg-muted transition-colors",children:[h==="distance"?e.jsx(Xt,{className:"h-3 w-3 text-primary"}):e.jsx(ht,{className:"h-3 w-3 text-primary"}),h==="distance"?"Sorted by distance":"Sorted by region",e.jsx(jt,{className:"h-3 w-3 text-muted-foreground"})]})}),e.jsxs(qt,{align:"start",className:"min-w-[180px]",children:[e.jsxs(ct,{onClick:()=>p("distance"),className:"flex items-center justify-between",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Xt,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Distance"]}),h==="distance"&&e.jsx(mt,{className:"h-4 w-4 text-primary"})]}),e.jsxs(ct,{onClick:()=>p("region"),className:"flex items-center justify-between",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ht,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Region"]}),h==="region"&&e.jsx(mt,{className:"h-4 w-4 text-primary"})]})]})]}),h==="distance"&&e.jsxs(Gt,{children:[e.jsx(Ht,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 h-8 px-3 rounded-full bg-muted/60 text-xs font-medium text-foreground
3/80 hover:bg-muted transition-colors",children:[e.jsx("span",{className:"text-muted-foreground",children:"From:"}),e.jsx("span",{children:Is}),e.jsx(jt,{className:"h-3 w-3 text-muted-foreground"})]})}),e.jsxs(qt,{align:"start",className:"min-w-[200px]",children:[J.map(o=>e.jsxs(ct,{onClick:()=>X(o.id),className:"flex items-center justify-between",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ht,{className:"h-3.5 w-3.5 text-muted-foreground"}),o.name]}),O===o.id&&e.jsx(mt,{className:"h-4 w-4 text-primary"})]},o.id)),e.jsxs(ct,{onClick:()=>{ge?X("current"):Re()},className:"flex items-center justify-between",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Xt,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Current location"]}),O==="current"&&e.jsx(mt,{className:"h-4 w-4 text-primary"})]}),e.jsxs(ct,{onClick:()=>ne(!0),className:"flex items-center gap-1.5 border-t border-border mt-1 pt-2",children:[e.jsx(Ns,{className:"h-3.5 w-3.5 text-muted-foreground"}),"New location…"]})]})]}),e.jsx(Fn,{open:le,onOpenChange:ne,userId:ve,onAdded:o=>{it(o),X(o.id)}})]}),ee&&Ae==="rate"&&lt&&e.jsx("div",{className:"sticky top-0 z-30 -mx-4 px-4 py-3 bg-background/95 backdrop-blur-xl border-b border-border/40",children:e.jsx(kn,{count:ae.size,totalCount:Fe.length,saving:_e,onCancel:Te,onToggleAll:()=>{ae.size>=Fe.length?ut(new Set):ut(new Set(Fe.map(o=>o.vault_taste_id)))},onApply:async o=>{if(ae.size===0||_e)return;Ze(!0);const u=await se(Array.from(ae),o);Ze(!1),u>0&&Te()},onDelete:async()=>{if(ae.size===0||_e)return;Ze(!0);const o=await Pe(Array.from(ae));Ze(!1),o>0&&Te()}})}),Fe.length===0?rt&&de&&(()=>{const o=_.filter(w=>Rt(w.domain)==="place"),u=o.filter(w=>!!x[String(w.entity_id)]);return o.length>0&&u.length<Math.max(3,Math.floor(o.length*.5))})()?e.jsxs("div",{className:"py-16 text-center text-sm text-muted-foreground",children:[e.jsx("div",{className:"mx-auto mb-3 h-6 w-6 animate-spin rounded-full border-2 border-muted-foreground/30 border-t-primary"}),"Loading nearby places…"]}):e.jsx(xr,{icon:Hr,title:rt?"Nothing saved within ~20 miles":"No items match",body:rt?"Pick a different location, or save more places nearby.":"Try a different rating filter."}):rt&&lt?K==="distance"&&de?e.jsx("div",{className:"space-y-6",children:$s(Ce,x,de,lo).map(o=>e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold tracking-tight",children:o.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:o.items.length})]}),e.jsx(ls,{items:o.items,onCardClick:m,selectMode:ee,selectedIds:ae,onToggleSelect:Ot,ratings:a,hideDomainIcon:!0})]},o.key))}):e.jsx("div",{className:"space-y-2",children:is.map(o=>{const u=D.has(o.key),N=de?[...o.items].sort((w,T)=>{const q=x[String(w.entity_id)],Q=x[String(T.entity_id)],me=q?Ds(de,q):Number.POSITIVE_INFINITY,Ie=Q?Ds(de,Q):Number.POSITIVE_INFINITY;return me-Ie}):o.items;return e.jsxs("section",{className:"rounded-xl border border-border/60 bg-card/40",children:[e.jsxs("button",{type:"button",onClick:()=>k(w=>{const T=new Set(w);return T.has(o.key)?T.delete(o.key):T.add(o.key),T}),className:"flex w-full items-center justify-between gap-2 px-3 py-2.5 text-left","aria-expanded":u,children:[e.jsx("span",{className:"text-sm font-semibold tracking-tight",children:o.label}),e.jsxs("span",{className:"flex items-center gap-2 text-[11px] text-muted-foreground tabular-nums",children:[o.items.length,e.jsx(jt,{className:Y("h-4 w-4 transition-transform",u&&"rotate-180")})]})]}),u&&e.jsx("div",{className:"px-3 pb-3",children:e.jsx(ls,{items:N,onCardClick:m,selectMode:ee,selectedIds:ae,onToggleSelect:Ot,ratings:a,hideDomainIcon:!0})})]},o.key)})}):xt&&lt?e.jsx("div",{className:"space-y-6",children:is.map(o=>e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold tracking-tight",children:o.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:o.items.length})]}),e.jsx(ls,{items:o.items,onCardClick:m,selectMode:ee,selectedIds:ae,onToggleSelect:Ot,ratings:a,hideDomainIcon:!0})]},o.key))}):lt&&!xt&&h==="region"?e.jsx("div",{className:"space-y-6",children:or(Ce,L).map(o=>e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold tracking-tight",children:o.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:o.items.length})]}),e.jsx(ls,{items:o.items,onCardClick:m,selectMode:ee,selectedIds:ae,onToggleSelect:Ot,ratings:a,hideDomainIcon:!0})]},o.key))}):lt&&!xt&&Se?e.jsx("div",{className:"space-y-6",children:$s(Ce,x,Se).map(o=>e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold tracking-tight",children:o.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:o.items.length})]}),e.jsx(ls,{items:o.items,onCardClick:m,selectMode:ee,selectedIds:ae,onToggleSelect:Ot,ratings:a,hideDomainIcon:!0})]},o.key))}):e.jsx(ls,{items:Fe,onCardClick:m,selectMode:ee,selectedIds:ae,onToggleSelect:Ot,ratings:a,hideDomainIcon:!0})]})}return e.jsxs("div",{className:"space-y-3",children:[(Ss.length>0||Kt.length>0)&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-1 mb-2",children:[e.jsx("button",{onClick:()=>Cs(!1),"aria-pressed":!Bt,className:Y("inline-flex items-center h-8 px-3.5 rounded-full text-xs font-semibold tracking-tight transition-colors border whitespace-nowrap",Bt?"bg-muted/50 text-muted-foreground border-transparent hover:bg-muted":"bg-foreground text-background border-foreground"),children:"Recent"}),Kt.length>0&&e.jsxs("button",{onClick:()=>Cs(!0),"aria-pressed":Bt,className:Y("inline-flex items-center gap-1 h-8 px-3.5 rounded-full text-xs font-semibold transition-colors border whitespace-nowrap",Bt?"bg-red-500 text-white border-red-500":"bg-red-500/10 text-red-600 dark:text-red-400 border-transparent hover:bg-red-500/20"),"aria-label":`${Kt.length} item${Kt.length===1?"":"s"} need review`,children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"}
3),"Needs review · ",Kt.length]}),Tt.length>0&&e.jsxs("button",{onClick:()=>Es(!0),className:"inline-flex items-center gap-1 h-8 px-3.5 rounded-full text-xs font-semibold transition-colors border whitespace-nowrap bg-amber-500/10 text-amber-700 dark:text-amber-400 border-transparent hover:bg-amber-500/20","aria-label":`Rate ${Tt.length} unrated item${Tt.length===1?"":"s"}`,children:["Unrated · ",Tt.length]})]}),e.jsx("div",{className:"-mx-4 px-4 overflow-x-auto no-scrollbar",children:e.jsx("div",{className:"flex gap-2 pb-1 items-start",children:Bt?Kt.map(l=>{const o=_r===`${l.kind}:${l.id}`;return e.jsxs("button",{onClick:()=>Ys(l.kind,l.id),disabled:o,"aria-busy":o,className:"shrink-0 w-[4.5rem] active:scale-[0.97] transition-transform text-left disabled:opacity-80 disabled:scale-100",children:[e.jsxs("div",{className:"relative aspect-square w-[4.5rem] overflow-hidden rounded-lg border border-red-500/40 bg-muted/30",children:[l.thumbnail?e.jsx("img",{src:Et(l.thumbnail,"thumb")??l.thumbnail,alt:l.title,className:"h-full w-full object-cover",loading:"lazy",decoding:"async"}):e.jsx("div",{className:"h-full w-full bg-gradient-to-br from-muted to-muted/50 flex items-center justify-center",children:l.kind==="url"?e.jsx(oi,{className:"h-6 w-6 text-foreground/40"}):e.jsx(mr,{className:"h-6 w-6 text-foreground/40"})}),e.jsx("div",{className:"absolute top-1 left-1 h-4 w-4 rounded-full bg-red-500 shadow ring-2 ring-background"}),o&&e.jsxs("div",{className:"absolute inset-0 bg-black/45 backdrop-blur-[2px] flex flex-col items-center justify-center gap-1.5",children:[e.jsx(wt,{className:"h-6 w-6 animate-spin text-white"}),e.jsx("span",{className:"text-[10px] font-semibold text-white",children:"Opening…"})]})]}),e.jsx("div",{className:"mt-1 text-[10px] font-medium leading-tight line-clamp-2",children:l.title})]},`${l.kind}:${l.id}`)}):Ss.map(l=>{const o=dt[nt(l.domain)]||dt.place,u=o.icon,N=a[l.vault_taste_id],w=(N==null?void 0:N.rating_value)??null,T=(N==null?void 0:N.experienced_state)==="not_tried"&&w==null,q=w!=null||T,Q=w===2?"❤️":w===1?"👍":w===0?"😐":w===-1?"👎":w===-2?"🚫":"✨",me=w===2?"Loved":w===1?"Liked":w===0?"Neutral":w===-1?"Disliked":w===-2?"Hated":T?"Interested":"Not yet rated";return e.jsx(fr,{item:l,onOpen:()=>m(l),className:"shrink-0 w-[4.5rem]",children:e.jsxs("button",{onClick:()=>m(l),className:"w-full active:scale-[0.97] transition-transform text-left",children:[e.jsxs("div",{className:"relative aspect-square w-[4.5rem] overflow-hidden rounded-lg border border-border/40 bg-muted/30",children:[e.jsx(pr,{item:l,className:"h-full w-full object-cover",fallbackIcon:e.jsx("div",{className:Y("h-full w-full bg-gradient-to-br flex items-center justify-center",o.tint),children:e.jsx(u,{className:"h-6 w-6 text-foreground/40"})})}),q&&e.jsx("div",{className:"absolute top-1 left-1 h-4 w-4 rounded-full inline-flex items-center justify-center bg-background/85 backdrop-blur-sm shadow",title:me,"aria-label":me,children:e.jsx("span",{className:"text-[10px] leading-none",children:Q})})]}),e.jsx("div",{className:"mt-1 text-[10px] font-medium leading-tight line-clamp-2",children:l.title})]})},l.vault_taste_id)})})})]}),e.jsx(Li,{open:fs!==null,onOpenChange:l=>{l||(Fs(null),Ms(null),Ls(null),ts(null))},kind:fs,initialUrlId:Ks,initialPhotoId:vr,onChanged:br}),e.jsx($i,{open:yr,onOpenChange:Es,items:Tt.map(l=>({vault_taste_id:l.vault_taste_id,title:l.title||"(untitled)",subtitle:l.subtitle,thumbnail_url:l.thumbnail_url,domain:l.domain,level_1:l.level_1,level_2:l.level_2,website:l.website,entity_id:l.entity_id})),onRate:ps,onRemove:ye,onWishlist:Ye}),e.jsx("section",{className:Y(Le?"-mt-3":"hidden"),children:e.jsx("div",{className:"flex items-center gap-2",children:Qt})}),(Yt.length>0||!0)&&e.jsxs("section",{className:"border-t border-border/40 pt-3 pb-3",children:[!vt&&e.jsx("div",{className:"mb-2",children:e.jsx("h3",{className:"text-sm font-semibold tracking-tight",children:"Top categories"})}),Yt.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[!vt&&Yt.filter(l=>l.domain!=="place").map(l=>{const{Icon:o}=yn(l.label),u=l.domain&&os[l.domain]||_n;return e.jsxs("button",{onClick:()=>{y(null),s("all"),c(l.label)},className:"inline-flex items-center gap-1.5 h-8 pl-2.5 pr-3 rounded-full border border-border/60 bg-card/60 text-xs font-medium hover:bg-card transition-colors",children:[e.jsx(o,{className:"h-3.5 w-3.5 shrink-0",style:{color:u}}),l.label]},l.label)}),!vt&&ns.slice(0,3).map(l=>e.jsxs("button",{onClick:()=>{y(null),s("all"),c(`${xs}${l.label}`)},className:"inline-flex items-center gap-1.5 h-8 pl-2.5 pr-3 rounded-full border border-border/60 bg-card/60 text-xs font-medium hover:bg-card transition-colors",children:[l.emoji?e.jsx("span",{className:"text-sm leading-none",children:l.emoji}):e.jsx(jn,{name:l.label}),l.label]},`region-${l.label}`)),($t||ns.length>3)&&e.jsxs("button",{onClick:()=>wr(l=>!l),className:"inline-flex items-center gap-1 h-8 px-3 rounded-full border border-dashed border-border/70 bg-transparent text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-card/60 transition-colors",children:[vt?"Show less":"Show all",e.jsx(jt,{className:Y("h-3.5 w-3.5 transition-transform",vt&&"rotate-180")}
3)]})]}),($t||ns.length>0)&&vt&&(()=>{var o;const l=[];if(ns.length>0){const u=os.place,N=[],w=[],T=[];for(const ke of ns){const qe=(ke.label||"").toLowerCase().trim();if(ke.emoji||qe.startsWith("elsewhere in ")){N.push(ke);continue}Br[qe]?w.push(ke):T.push(ke)}const q={"columbia river gorge":{parent:"Oregon",kind:"state"}},Q=ke=>{const qe=ke.toLowerCase().trim();if(q[qe])return q[qe];if(qe.startsWith("elsewhere in ")){const Ct=ke.slice(13);return{parent:Ct,kind:Br[Ct.toLowerCase()]?"state":"country"}}const ft=V[qe];return ft||null},me=new Map;for(const ke of N){const qe=Q(ke.label),ft=(qe==null?void 0:qe.parent)||"Other",Ct=(qe==null?void 0:qe.kind)||"country",It=me.get(ft)||{kind:Ct,chips:[]};It.chips.push(ke),me.set(ft,It)}const Ie=Array.from(me.entries()).map(([ke,qe])=>({parent:ke,kind:qe.kind,chips:qe.chips})),ze=(ke,qe)=>e.jsx("div",{className:"flex flex-wrap gap-2",children:qe.map(ft=>e.jsxs("button",{onClick:()=>{y(null),s("all"),c(`${xs}${ft.label}`)},className:"inline-flex items-center gap-1.5 h-8 pl-2.5 pr-3 rounded-full border border-border/60 bg-background/70 text-xs font-medium hover:bg-card transition-colors",children:[ft.emoji?e.jsx("span",{className:"text-sm leading-none",children:ft.emoji}):e.jsx(jn,{name:ft.label}),ft.label]},`region-all-${ke}-${ft.label}`))}),Qe=[];for(const ke of Ie)Qe.push({key:`regions-${ke.parent}`,label:ke.parent,chips:ke.chips});if(w.length>0&&Qe.push({key:"states",label:"States",chips:w}),T.length>0&&Qe.push({key:"countries",label:"Countries",chips:T}),Qe.length>0){const ke=Qe.reduce((qe,ft)=>qe+ft.chips.reduce((Ct,It)=>Ct+It.count,0),0);Qe.sort((qe,ft)=>ft.chips.reduce((Ct,It)=>Ct+It.count,0)-qe.chips.reduce((Ct,It)=>Ct+It.count,0)),l.push({key:"place:all",heading:"Places",count:ke,color:u,body:e.jsx("div",{className:"space-y-2.5",children:Qe.map((qe,ft)=>{const Ct=qe.chips.reduce((It,Qn)=>It+Qn.count,0);return e.jsxs("div",{className:Y("pl-2.5 border-l-2",ft===0?"pt-0.5":"pt-2.5"),style:{borderColor:`${u}33`},children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:qe.label}),e.jsx("span",{className:"text-[10px] font-medium text-muted-foreground/60 tabular-nums",children:Ct})]}),ze(qe.key,qe.chips)]},qe.key)})})})}}for(const u of Qs.filter(N=>N.domain!=="place")){const N=os[u.domain]||_n,w=u.chips.reduce((T,q)=>T+q.count,0)+(((o=u.misc)==null?void 0:o.count)||0);l.push({key:`domain:${u.domain}`,heading:u.label,count:w,color:N,body:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[u.chips.map(T=>{const{Icon:q}=yn(T.label);return e.jsxs("button",{onClick:()=>{y(null),s("all"),c(T.label)},className:"inline-flex items-center gap-1.5 h-8 pl-2.5 pr-3 rounded-full border border-border/60 bg-background/70 text-xs font-medium hover:bg-card transition-colors",children:[e.jsx(q,{className:"h-3 w-3 shrink-0",style:{color:N}}),T.label]},T.label)}),u.misc&&e.jsxs("button",{onClick:()=>{y(u.misc.labels),s("all"),c(`Misc · ${u.label}`)},className:"inline-flex items-center gap-1.5 h-8 px-3 rounded-full border border-dashed border-border/70 bg-transparent text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-card transition-colors",children:["Misc · ",u.misc.count]},`${u.domain}-misc`)]})})}return l.sort((u,N)=>N.count-u.count),e.jsx("div",{className:"mt-3 space-y-1.5",children:l.map(u=>{const N=jr.has(u.key);return e.jsxs("div",{className:Y("rounded-xl border border-border/40 bg-card/40 overflow-hidden transition-colors",N&&"bg-card/70"),children:[e.jsxs("button",{type:"button",onClick:()=>Nr(u.key),className:"w-full flex items-center justify-between gap-2 px-3 py-2.5 text-left hover:bg-muted/30 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{backgroundColor:u.color}}),e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider truncate",style:{color:u.color},children:u.heading}),e.jsx("span",{className:"inline-flex items-center justify-center min-w-[22px] h-[18px] px-1.5 rounded-full bg-muted/60 text-[10px] font-semibold text-muted-foreground tabular-nums",children:u.count})]}
3),e.jsx(jt,{className:Y("h-4 w-4 text-muted-foreground/70 transition-transform shrink-0",N&&"rotate-180")})]}),N&&e.jsx("div",{className:"px-3 pb-3 pt-1 border-t border-border/30",children:u.body})]},u.key)})})})()]})]})},go=({domain:t,setDomain:a,sortKey:r,setSortKey:s,sortLabel:i,viewMode:c,setViewMode:m,showWishes:d,setShowWishes:v,items:_,ratings:M,wishes:y,wishesLoading:j,searchQuery:S,onCardClick:x,placeCoords:L,placeRegions:W,regionLabelMap:V,subRegionParent:E,anchorCoords:J,savedLocations:O,distanceRef:X,setDistanceRef:ge,requestCurrentLocation:Re,hasCurrentCoords:ve,onVisibleListChange:it,onBulkApplyRating:B,onBulkRemove:Z,onSilentRate:se,onSilentRemove:G,onSilentWishlist:ye,onWishRemove:Ye,onWishToggleHide:Pe,onWishTogglePriority:Ve,onWishAdd:Le,vaultAll:$,userId:le,onSavedLocationAdded:ne,onCategoryScopeChange:de,loadFailed:De,onRetryLoad:Ee,stashes:C,nearbyMode:z=!1,onExitNearby:F})=>{const ue=lr(),[re]=In(),xe=re.get("from")==="community",oe=Ke.useCallback(()=>{if(xe){ue("/community");return}v(!1)},[xe,ue,v]),[P,K]=n.useState(!1),[g,D]=n.useState("all"),[k,h]=n.useState("all"),[p,H]=n.useState(null),[te,we]=n.useState(null),[he,ee]=n.useState(null);n.useEffect(()=>{D("all")},[t,r]),n.useEffect(()=>{t!=="all"&&(h("all"),H(null),we(null),ee(null))},[t]),n.useEffect(()=>{p||(we(null),ee(null))},[p]),n.useEffect(()=>{d&&(H(null),we(null),ee(null))},[d,H]),n.useEffect(()=>{if(de)return de(!!p&&t==="all"&&!z&&!d),()=>{de(!1)}},[p,t,de,z,d]);const je=S.trim().toLowerCase(),Ae=n.useMemo(()=>je?_.filter(R=>us(je,R.title,R.subtitle,R.level_2)):_,[_,je]),pt=n.useMemo(()=>{if(r!=="rating"||t==="all")return[];const R=uo[t]||null,ie=new Set;return Ae.forEach(st=>{const We=Zt(st);!We||We.toLowerCase()==="other"||R&&!R.has(We)||ie.add(We)}),Array.from(ie).sort()},[Ae,r,t]),ae=R=>{if(k==="all")return!0;const ie=M[R.vault_taste_id];switch(k){case"unrated":return!ie||ie.rating_value==null&&ie.experienced_state!=="not_tried";case"interested":return!!ie&&ie.experienced_state==="not_tried"&&ie.rating_value==null;case"loved":return(ie==null?void 0:ie.rating_value)===2;case"liked":return(ie==null?void 0:ie.rating_value)===1;case"loved_liked":return((ie==null?void 0:ie.rating_value)??-99)>=1}return!0},ut=R=>Zt(R),_e=n.useMemo(()=>{let R=Ae;r==="rating"&&t!=="all"&&g!=="all"&&(R=R.filter(We=>Zt(We)===g)),k!=="all"&&(R=R.filter(ae));const ie=p&&p.startsWith("__region:")?p.slice(9):null,st=p&&p.startsWith("__nearby:")?p.slice(9):null;if(te&&te.length>0){const We=new Set(te);R=R.filter(Nt=>We.has(ut(Nt)))}else ie?R=R.filter(We=>{var Nt;return Rt(We.domain)==="place"&&(((Nt=V.get(We.vault_taste_id))==null?void 0:Nt.label)||hr(We,W))===ie}):st?R=R.filter(We=>Rt(We.domain)==="place"):p&&(R=R.filter(We=>ut(We)===p));return p&&he&&(ie?R=R.filter(We=>Zt(We)===he):R=R.filter(We=>(We.level_2||"").trim()===he)),R},[Ae,r,t,g,k,p,he,te,M,W,V]),Ze=!!p&&p.startsWith("__nearby:"),et=n.useMemo(()=>je?y.filter(R=>us(je,R.title,R.subtitle)):y,[y,je]),Te=n.useMemo(()=>{const R=t==="place"?[{key:"region",label:"Region"},{key:"category",label:"Category"}]:[{key:"category",label:"Category"}];return R.push({key:"rating",label:"Rating"}),t==="place"&&R.push({key:"distance",label:"Distance"}),t==="all"&&R.push({key:"recent",label:"Recent"}),R},[t]),bt=n.useMemo(()=>{if(X==="current")return"Current location";const R=O.find(ie=>ie.id===X);return(R==null?void 0:R.name)||"Pick reference"},[X,O]),Ue=n.useMemo(()=>d?[...et].sort((ie,st)=>+!!st.is_priority-+!!ie.is_priority||+!!ie.is_hidden-+!!st.is_hidden).map(ie=>({vault_taste_id:ie.vault_taste_id,entity_id:ie.vault_taste_id,domain:ie.domain||"",title:ie.title,subtitle:ie.subtitle,thumbnail_url:ie.thumbnail_url,level_1:null,level_2:null,website:null,taxonomy_id:null,created_at:""})):r==="rating"?$r(_e,M).flatMap(R=>R.items):r==="category"?cs(_e).flatMap(R=>R.items):r==="distance"&&t==="place"&&J?$s(_e,L,J).flatMap(R=>R.items):r==="region"&&t==="place"?or(_e,W).flatMap(R=>R.items):t==="all"?_e:cs(_e).flatMap(R=>R.items),[d,r,_e,et,M,t,J,L,W]);n.useEffect(()=>{it(Ue)},[Ue,it]);const tt=t==="all"&&!je&&r==="recent";return e.jsxs("div",{children:[!tt&&e.jsx("div",{className:"px-3",children:e.jsx("div",{className:"grid grid-cols-5 ga
3p-1 rounded-2xl bg-muted/50 p-1",children:co.map(R=>{const ie=R.icon,st=t===R.id;return e.jsxs("button",{onClick:()=>a(R.id),className:Y("min-w-0 flex flex-col items-center justify-center gap-0.5 h-12 rounded-xl text-[10.5px] font-medium transition-all px-1",st?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[e.jsx(ie,{className:"h-4 w-4"}),e.jsx("span",{className:"truncate w-full text-center",children:R.label})]},R.id)})})}),!tt&&e.jsxs("div",{className:"px-4 mt-3 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c!=="map"&&!Ze&&e.jsxs(Gt,{children:[e.jsx(Ht,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 h-9 px-3 rounded-full border border-border/60 bg-card/60 text-sm font-medium hover:bg-card transition-colors",children:[e.jsx("span",{className:"text-muted-foreground",children:"Sort:"}),e.jsx("span",{children:i[r]}),e.jsx(jt,{className:"h-3.5 w-3.5 text-muted-foreground"})]})}),e.jsx(qt,{align:"start",className:"min-w-[160px]",children:Te.map(R=>e.jsxs(ct,{onClick:()=>s(R.key),className:"flex items-center justify-between",children:[e.jsx("span",{children:R.label}),r===R.key&&e.jsx(mt,{className:"h-4 w-4 text-primary"})]},R.key))})]}),r==="rating"&&t!=="all"&&pt.length>=2&&e.jsxs(Gt,{children:[e.jsx(Ht,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 h-9 px-3 rounded-full border border-border/60 bg-card/60 text-sm font-medium hover:bg-card transition-colors",children:[e.jsx("span",{children:g==="all"?"All":g}),e.jsx(jt,{className:"h-3.5 w-3.5 text-muted-foreground"})]})}),e.jsxs(qt,{align:"start",sideOffset:6,collisionPadding:16,avoidCollisions:!0,className:"min-w-[180px] max-h-[min(60dvh,360px)] overflow-y-auto overscroll-contain",children:[e.jsxs(ct,{onClick:()=>D("all"),className:"flex items-center justify-between",children:[e.jsx("span",{children:"All"}),g==="all"&&e.jsx(mt,{className:"h-4 w-4 text-primary"})]}),pt.map(R=>e.jsxs(ct,{onClick:()=>D(R),className:"flex items-center justify-between",children:[e.jsx("span",{children:R}),g===R&&e.jsx(mt,{className:"h-4 w-4 text-primary"})]},R))]})]}),t==="all"&&e.jsxs("button",{onClick:()=>v(!d),className:Y("inline-flex items-center gap-1.5 h-9 px-3 rounded-full border text-sm font-medium transition-colors",d?"bg-primary text-primary-foreground border-primary":"bg-card/60 text-foreground/80 border-border/60 hover:bg-card"),children:[e.jsx(Bs,{className:Y("h-3.5 w-3.5",d?"":"text-muted-foreground")}),"Wishlist"]})]}),t!=="all"&&e.jsx(bo,{viewMode:c,setViewMode:m,showMap:t==="place"})]}),t==="place"&&(r==="distance"||c==="map")&&e.jsxs("div",{className:"px-4 mt-2",children:[e.jsxs(Gt,{children:[e.jsx(Ht,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 h-8 px-3 rounded-full bg-muted/60 text-xs font-medium text-foreground/80 hover:bg-muted transition-colors",children:[e.jsx(Xt,{className:"h-3 w-3 text-primary"}),e.jsx("span",{className:"text-muted-foreground",children:"From:"}),e.jsx("span",{children:bt}),e.jsx(jt,{className:"h-3 w-3 text-muted-foreground"})]})}),e.jsxs(qt,{align:"start",className:"min-w-[200px]",children:[O.map(R=>e.jsxs(ct,{onClick:()=>ge(R.id),className:"flex items-center justify-between",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ht,{className:"h-3.5 w-3.5 text-muted-foreground"}),R.name]}),X===R.id&&e.jsx(mt,{className:"h-4 w-4 text-primary"})]},R.id)),e.jsxs(ct,{onClick:()=>{ve?ge("current"):Re()},className:"flex items-center justify-between",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Xt,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Current location"]}),X==="current"&&e.jsx(mt,{className:"h-4 w-4 text-primary"})]}),e.jsxs(ct,{onClick:()=>K(!0),className:"flex items-center gap-1.5 border-t border-border mt-1 pt-2",children:[e.jsx(Ns,{className:"h-3.5 w-3.5 text-muted-foreground"}),"New location…"]})]})]}),e.jsx(Fn,{open:P,onOpenChange:K,userId:le,onAdded:R=>
3{ne(R),ge(R.id)}})]}),e.jsx("div",{className:"px-4 mt-3",children:(()=>{const R=z||t==="all"&&!je&&r==="recent";return R&&d?e.jsx(En,{items:et,loading:j,onClose:oe,onCardClick:x,onRemove:Ye,onToggleHide:Pe,onTogglePriority:Ve,userId:le,vaultAll:$,onAdd:Le}):R?e.jsx(xo,{items:Ae,ratings:M,ratingFilter:k,setRatingFilter:h,categoryFilter:p,setCategoryFilter:H,onCardClick:x,categoryLabelFor:ut,ratingFilterMatch:ae,scopedItems:_e,miscScopeLabels:te,setMiscScopeLabels:we,categoryL2Filter:he,setCategoryL2Filter:ee,placeCoords:L,placeRegions:W,regionLabelMap:V,subRegionParent:E,anchorCoords:J,savedLocations:O,distanceRef:X,setDistanceRef:ge,hasCurrentCoords:ve,requestCurrentLocation:Re,userId:le,onSavedLocationAdded:ne,showWishes:d,setShowWishes:v,onBulkApplyRating:B,onSilentRate:se,onSilentRemove:G,onSilentWishlist:ye,onBulkRemove:Z,stashes:C,nearbyMode:z,onExitNearby:F}):e.jsxs(e.Fragment,{children:[(p||k!=="all")&&t==="all"&&e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[p&&e.jsxs("button",{onClick:()=>H(null),className:"inline-flex items-center gap-1.5 h-8 pl-3 pr-2 rounded-full bg-primary/10 text-primary border border-primary/20 text-xs font-medium",children:[p,e.jsx(_s,{className:"h-3.5 w-3.5"})]}),k!=="all"&&e.jsxs("button",{onClick:()=>h("all"),className:"inline-flex items-center gap-1.5 h-8 pl-3 pr-2 rounded-full bg-muted text-foreground border border-border/60 text-xs font-medium",children:[ho[k],e.jsx(_s,{className:"h-3.5 w-3.5"})]})]}),d?e.jsx(En,{items:et,loading:j,onClose:oe,onCardClick:x,onRemove:Ye,onToggleHide:Pe,onTogglePriority:Ve,userId:le,vaultAll:$,onAdd:Le}):_e.length===0?_.length===0&&!je?De?e.jsxs("div",{className:"mx-auto max-w-sm text-center py-14 px-4",children:[e.jsx("div",{className:"mx-auto h-14 w-14 rounded-full bg-muted/60 flex items-center justify-center",children:e.jsx(Rr,{className:"h-6 w-6 text-muted-foreground"})}),e.jsx("h3",{className:"mt-4 font-semibold",children:"Couldn't load your vault"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"We weren't able to reach the server. Check your connection and try again."}),e.jsx("button",{type:"button",onClick:()=>Ee==null?void 0:Ee(),className:"mt-5 inline-flex items-center gap-2 h-10 px-5 rounded-full bg-primary text-primary-foreground text-sm font-medium shadow-sm active:scale-[0.98] transition-transform",children:"Retry"})]}):e.jsx(Jo,{onGoCompass:()=>ue("/compass")}):e.jsx(xr,{icon:Hr,title:je?"No matches":"Nothing here yet",body:je?"Try a different search.":"Items matching this filter will appear here."}):e.jsx(vo,{domain:t,sortKey:r,viewMode:c,items:_e,ratings:M,placeCoords:L,placeRegions:W,anchorCoords:J,onCardClick:x})]})})()})]})},bo=({viewMode:t,setViewMode:a,showMap:r})=>{const s=[{id:"carousel",icon:ri,label:"Grid"},{id:"list",icon:ni,label:"List"},...r?[{id:"map",icon:Wn,label:"Map"}]:[]];return e.jsx("div",{className:"inline-flex items-center rounded-full border border-border/60 bg-card/60 p-0.5",children:s.map(i=>{const c=i.icon,m=t===i.id;return e.jsx("button",{onClick:()=>a(i.id),"aria-label":i.label,className:Y("h-8 w-8 rounded-full inline-flex items-center justify-center transition-colors",m?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"),children:e.jsx(c,{className:"h-4 w-4"})},i.id)})})},vo=({domain:t,sortKey:a,viewMode:r,items:s,ratings:i,placeCoords:c,placeRegions:m,anchorCoords:d,onCardClick:v})=>{const _=n.useMemo(()=>t==="all"?a==="rating"?$r(s,i):a==="category"?cs(s):null:a==="rating"?$r(s,i):a==="category"?cs(s):a==="distance"&&t==="place"&&d?$s(s,c,d):a==="region"&&t==="place"?s.length>0&&Object.keys(m).length===0?[]:or(s,m):cs(s),[t,a,s,i,c,m,d]);return t==="all"?_?e.jsx(Ln,{sections:_,onCardClick:v}):e.jsx(ls,{items:s,onCardClick:v,ratings:i}):r==="map"&&t==="place"?e.jsx(Fo,{items:s,placeCoords:c,onCardClick:v}):r==="list"?e.jsx(Vo,{sections:_??[],onCardClick:v}):e.jsx(Ln,{sections:_??[],onCardClick:v})};function $r(t,a){return mo.map(r=>({key:r.key,label:r.label,items:t.filter(s=>r.match(a[s.vault_taste_id]))})).filter(r=>r.items.length>0)}const Sn={music:"Music",song:"Music",songs:"Music",album:"Music",albums:"Music",artist:"Music",artists:"Music",track:"Music",tracks:"Music",audio:"Music",movies:"Movies",movie:"Movies",film:"Movies",films:"Movies",shows:"Shows",show:"Shows",series:"Shows",tv:"Shows",television:"Shows",books:"Books",book:"Books",publishers:"Books",publisher:"Books",author:"Books",authors:"Books",literature:"Books",podcasts:"Podcasts",podcast:"Podcasts",creators:"Creators",creator:"Creators",youtube:"Creators",gaming:"Gaming",game:"Gaming",games:"Gaming"},_o=new Set(["Music","Movies","Shows","Books","Podcasts","Creators","Gaming"]);function yo(t){const a=(t.entity_id||"").toLowerCase();if(a.startsWith("music|")||/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(a))return"Music";if(a.startsWith("rawg:"))return"Gaming";const r=a.startsWith("yt_channel:")||/^uc[a-z0-9_-]{22}$/i.test(t.entity_id||""),s=(t.level_2||"").trim();if(s){const c=Sn[s.toLowerCase()];if(c&&(c!=="Creators"||r))return c}const i=(t.level_1||"").trim();if(i){const c=Sn[i.toLowerCase()];if(c&&(c!=="Creators"||r))return c;if(_o.has(i)&&(i!=="Creators"||r))return i}return"Music"}const Ar={restaurant:"Dining",restaurants:"Dining",cafe:"Dining",café:"Dining",bakery:"Dining",bar:"Dining",winery:"Dining",brewery:"Dining",distillery:"Dining","coffee shop":"Dining",diner:"Dining",steakhouse:"Dining","wine bar":"Dining","cocktail bar":"Dining",pub:"Dining",hotel:"Lodging",resort:"Lodging",motel:"Lodging",inn:"Lodging",hostel:"Lodging","b&b":"Lodging","bed and breakfast":"Lodging","tourist site":"Culture",landmark:"Culture",museum:"Culture","art gallery":"Culture",theater:"Culture",theatre:"Culture",park:"Recreation","national park":"Recreation",beach:"Recreation","hiking trail":"Recreation","outdoor sports":"Recreation","ski resort":"Recreation","golf course":"Recreation",gym:"Services",spa:"Services",salon:"Services",boutique:"Shopping",shop:"Shopping",store:"Shopping",market:"Shopping",grocery:"Shopping"},wo=new Set(["Dining","Lodging","Recreation","Culture","Shopping","Services","Education","Entertainment","Areas","Spiritual"]);function jo(t,a){const r=(t||"").trim();if(r&&wo.has(r))return r;const s=Ar[r.toLowerCase()];if(s)return s;const i=(a||"").trim().toLowerCase();return i&&Ar[i]?Ar[i]:r||"Other"}const No=new Set(["Fashion","Automotive","Baby","Beauty","Beverages","Electronics","Grocery","Games","Home","Backyard","Pets","Sports","Tools","Wellness","Toys"]),Cn={"home & kitchen":"Home","sporting goods":"Sports","pet supplies":"Pets","baby & kids":"Baby","home improvement":"Tools","outdoor living":"Backyard","beauty & care":"Beauty","games & puzzles":"Games","beauty & personal care":"Beauty","health & beauty":"Beauty","personal care":"Beauty",wellness:"Wellness",supplements:"Wellness","supplements & vitamins":"Wellness",vitamins:"Wellness","garden & outdoor":"Backyard",outdoor:"Backyard","outdoor gear":"Sports",camping:"Sports","camping & hiking":"Sports",hiking:"Sports",fishing:"Sports",coolers:"Backyard","food & grocery":"Grocery",drink:"Beverages",drinks:"Beverages",beverage:"Beverages",spirit:"Beverages",spirits:"Beverages",wine:"Beverages",beer
3:"Beverages",toys:"Toys","toys & games":"Toys",product:"Other"},sr={footwear:"Fashion","bags & luggage":"Fashion",activewear:"Fashion","outerwear & coats":"Fashion","tops & shirts":"Fashion",bottoms:"Fashion","accessories & jewelry":"Fashion","apparel accessories":"Fashion","dresses & skirts":"Fashion",apparel:"Fashion",skincare:"Beauty",fragrance:"Beauty","hair care":"Beauty","makeup & cosmetics":"Beauty","oral care":"Beauty","dental & oral":"Beauty","men's grooming":"Beauty","supplements & vitamins":"Wellness","sleep & recovery":"Wellness","cold & heat therapy":"Wellness","mental wellness & mindfulness":"Wellness","fitness recovery & mobility":"Wellness","drinkware & barware":"Home","kitchen & cookware":"Home","home decor":"Home","home furniture":"Home","home appliances":"Home","bedding & bath":"Home","office supplies":"Home",lighting:"Home","storage & organization":"Home","audio equipment":"Electronics","cameras & photography":"Electronics","computers & laptops":"Electronics","gaming hardware":"Electronics","phones, tablets & wearables":"Electronics","smart home":"Electronics","tvs & displays":"Electronics","board games":"Games",puzzles:"Games","card games":"Games","video games":"Games","party games":"Games","strategy games":"Games","outdoor games":"Games","general toys":"Toys","building sets & blocks":"Toys","plush & stuffed toys":"Toys","action figures & dolls":"Toys","educational toys":"Toys","arts & crafts":"Toys","ride-on & outdoor toys":"Toys","non-alcoholic drinks":"Beverages","coffee & tea":"Beverages","mountain & snow sports":"Sports",cycling:"Sports","fitness & yoga":"Sports","water sports":"Sports","running & track":"Sports","fitness & gym equipment":"Sports","field & court sports":"Sports","golf equipment":"Sports","racket sports":"Sports","camping & hiking":"Sports","hydration & water filtration":"Sports","snacks & chips":"Grocery","pantry & dry goods":"Grocery","condiments & sauces":"Grocery","candy & sweets":"Grocery","dairy & eggs":"Grocery","grills & bbq":"Backyard","patio furniture":"Backyard","garden tools & plants":"Backyard","fire pits & heaters":"Backyard","coolers & outdoor cooking":"Backyard","outdoor lighting":"Backyard","hot tubs & pools":"Backyard","sheds & outdoor storage":"Backyard","pool & spa accessories":"Backyard"};function ko(t,a){const r=(t||"").trim();if(r&&No.has(r))return r;const s=r.toLowerCase();if(s&&Cn[s])return Cn[s];const i=(a||"").trim().toLowerCase();return i&&sr[i]?sr[i]:s&&sr[s]?sr[s]:"Other"}function Zt(t){const a=nt(t.domain);return a==="media"?yo(t):a==="place"?jo(t.level_1,t.level_2):a==="product"?ko(t.level_1,t.level_2):t.level_1||a||"Other"}function cs(t){const a=new Map;return t.forEach(r=>{const s=Zt(r),i=a.get(s)||[];
3i.push(r),a.set(s,i)}),Array.from(a.entries()).sort((r,s)=>s[1].length-r[1].length).map(([r,s])=>({key:r,label:Os(r),items:s}))}function Os(t){return t.replace(/[_-]+/g," ").replace(/\b\w/g,a=>a.toUpperCase())}const rr={music:"Music",song:"Music",songs:"Music",album:"Music",albums:"Music",movie:"Movies",movies:"Movies",film:"Movies",films:"Movies",show:"Shows",shows:"Shows",tv:"Shows",television:"Shows",book:"Books",books:"Books",audiobook:"Books",audiobooks:"Books",podcast:"Podcasts",podcasts:"Podcasts",creator:"Creators",creators:"Creators","yt channel":"Creators",youtube:"Creators",game:"Gaming",games:"Gaming",gaming:"Gaming","video game":"Gaming"};function So(t){const a=(t.level_1||"").trim().toLowerCase(),r=(t.level_2||"").trim().toLowerCase(),s=String(t.entity_id||"").toLowerCase();return rr[a]?rr[a]:rr[r]?rr[r]:s.startsWith("music|")||s.startsWith("spotify_track:")||s.startsWith("apple_song:")?"Music":s.startsWith("yt_channel:")||/^uc[a-z0-9_-]{20,}$/i.test(s)?"Creators":s.startsWith("rawg:")?"Gaming":s.startsWith("tmdb_movie:")||s.startsWith("q_tmdb_movie_")?"Movies":s.startsWith("tmdb_tv:")||s.startsWith("q_tmdb_tv_")?"Shows":s.startsWith("ol/")||s.startsWith("openlibrary:")||/^ol\d+w$/i.test(s)?"Books":"Media"}function ir(t){const a=(t.subtitle||"").trim(),r=(t.level_2||"").trim(),s=t.domain?t.domain==="creation"?"creations":t.domain:"",i=c=>c.replace(/[_-]+/g," ").replace(/\b\w/g,m=>m.toUpperCase());return s==="media"?So({level_1:t.level_1??null,level_2:t.level_2??null,entity_id:t.entity_id??null}):s==="creations"||s==="place"||s==="product"?r?i(r):a:a||(r?i(r):"")}function $s(t,a,r,s=oo){const i={},c=[];t.forEach(d=>{const v=a[String(d.entity_id)];if(!v){c.push(d);return}const _=Ds(r,v),M=s.find(j=>_<j.max),y=(M==null?void 0:M.key)||"far";(i[y]=i[y]||[]).push({item:d,d:_})});const m=s.map(d=>({key:d.key,label:d.label,items:(i[d.key]||[]).sort((v,_)=>v.d-_.d).map(v=>v.item)})).filter(d=>d.items.length>0);return c.length&&m.push({key:"unknown",label:"Distance unknown",items:c}),m}const Co=/^(us|usa|u\.s\.a?\.?|united states(\s+of\s+america)?)$/i,Gs={AL:"Alabama",AK:"Alaska",AZ:"Arizona",AR:"Arkansas",CA:"California",CO:"Colorado",CT:"Connecticut",DE:"Delaware",FL:"Florida",GA:"Georgia",HI:"Hawaii",ID:"Idaho",IL:"Illinois",IN:"Indiana",IA:"Iowa",KS:"Kansas",KY:"Kentucky",LA:"Louisiana",ME:"Maine",MD:"Maryland",MA:"Massachusetts",MI:"Michigan",MN:"Minnesota",MS:"Mississippi",MO:"Missouri",MT:"Montana",NE:"Nebraska",NV:"Nevada",NH:"New Hampshire",NJ:"New Jersey",NM:"New Mexico",NY:"New York",NC:"North Carolina",ND:"North Dakota",OH:"Ohio",OK:"Oklahoma",OR:"Oregon",PA:"Pennsylvania",RI:"Rhode Island",SC:"South Carolina",SD:"South Dakota",TN:"Tennessee",TX:"Texas",UT:"Utah",VT:"Vermont",VA:"Virginia",WA:"Washington",WV:"West Virginia",WI:"Wisconsin",WY:"Wyoming",DC:"District of Columbia"},nr={日本:"Japan",日本国:"Japan",中国:"China",中華人民共和国:"China",한국:"South Korea",대한민국:"South Korea",台灣:"Taiwan",台湾:"Taiwan",méxico:"Mexico",españa:"Spain",ελλάδα:"Greece",россия:"Russia",deutschland:"Germany",österreich:"Austria",schweiz:"Switzerland",brasil:"Brazil",ประเทศไทย:"Thailand",भारत:"India",türkiye:"Turkey",italia:"Italy",polska:"Poland",česko:"Czechia",magyarország:"Hungary",nederland:"Netherlands",sverige:"Sweden",norge:"Norway",suomi:"Finland",danmark:"Denmark",ísland:"Iceland",україна:"Ukraine","việt nam":"Vietnam"};function Yn(t){const a=(t||"").trim();if(!a)return"";if(nr[a])return nr[a];const r=a.toLowerCase();return nr[r]?nr[r]:["us","usa","u.s.","u.s.a.","united states of america"].includes(r)?"United States":a}function Mo(t){const a=(t||"").trim();if(!a)return"";const r=a.match(/^([A-Z]{2})[\s-]+\d/);return r?r[1]:/^\d{4,5}\s+\S+/.test(a)?"":a}const Lo=/^(united kingdom|great britain|uk|gbr|gb|u\.k\.)$/i,Eo=new Set(["edinburgh","glasgow","aberdeen","dundee","inverness","stirling","perth","st andrews","oban","fort william"]),Po=new Set(["cardiff","swansea","newport","wrexham","bangor","st davids","aberystwyth"]),Ao=new Set(["belfast","derry","londonderry","lisbur
3n","newry","armagh"]),To=/^(AB|DD|DG|EH|FK|G|HS|IV|KA|KW|KY|ML|PA|PH|TD|ZE)\d/i,Io=/^(CF|LL|SA|NP|LD)\d/i,Ro=/^BT\d/i;function Do(t,a){const r=(t||"").trim();if(/^england$/i.test(r))return"England";if(/^scotland$/i.test(r))return"Scotland";if(/^wales$/i.test(r))return"Wales";if(/^northern ireland$/i.test(r)||Ro.test(r))return"Northern Ireland";if(To.test(r))return"Scotland";if(Io.test(r))return"Wales";const s=(a||"").trim().toLowerCase();return Eo.has(s)?"Scotland":Po.has(s)?"Wales":Ao.has(s)?"Northern Ireland":"England"}const Oo=new Set(["district of columbia","dc","virginia","va","maryland","md"]),Bo=new Set(["washington","washington dc","washington d.c.","georgetown","arlington","alexandria","mclean","falls church","vienna","tysons","tysons corner","reston","herndon","fairfax","annandale","springfield","great falls","ashburn","leesburg","sterling","clarendon","rosslyn","merrifield","burke","centreville","chantilly","dunn loring","oakton","manassas","woodbridge","lorton","mount vernon","shirlington","bethesda","chevy chase","silver spring","rockville","takoma park","gaithersburg","potomac","north bethesda","college park","hyattsville","bowie","kensington","wheaton","laurel","greenbelt","riverdale park","mount rainier","germantown","olney","clarksburg","cabin john","garrett park"]);function $o(t,a){const r=(t||"").trim().toLowerCase(),s=(a||"").trim().toLowerCase();return Oo.has(r)?r==="district of columbia"||r==="dc"?!0:Bo.has(s):!1}function Jn(t){const a=(t||"").replace(/^\s*(?:restaurant|cafe|bakery\/cafe|brewery|bar|hotel|trail|park|landmark)\s*[·•]\s*/i,"").trim();if(!a)return null;const r=a.split(",").map(s=>s.trim()).filter(Boolean);if(r.length===1)return{city:null,state:null,country:r[0]||null};if(r.length>=3){const s=r.slice(-3);return{city:s[0]||null,state:s[1]||null,country:s[2]||null}}if(r.length===2){const[s,i]=r;return Gs[i.toUpperCase()]||/^(oregon|california|washington|new york|texas|utah|arizona|florida)$/i.test(i)?{city:s,state:i,country:"United States"}:/^(oregon|california|washington|new york|texas|utah|arizona|florida)$/i.test(s)||Gs[s.toUpperCase()]?{city:null,state:s,country:i}:{city:s,state:null,country:i}}return null}function hr(t,a){const r=a[String(t.entity_id)]||null,s=Jn(t.subtitle),i=r&&(r.country||r.state)?r:s||r,c=Yn((i==null?void 0:i.country)||""),m=Mo((i==null?void 0:i.state)||""),d=((i==null?void 0:i.city)||"").trim();if(Co.test(c)){if(!m)return"United States";const v=m.toUpperCase(),_=Gs[v]||Os(m);return $o(_,d||"")?"DC Metro Area":_}return Lo.test(c)?Do((i==null?void 0:i.state)||"",(i==null?void 0:i.city)||d):c?Os(c):m?Os(m):d&&d.toLowerCase()!==(t.title||"").trim().toLowerCase()?Os(d):"Unknown"}const zo=new Set(["Oregon","California","France","England","New York","Washington"]),Uo=5,Mn={Oregon:"🌲",California:"☀️",France:"🇫🇷",England:"🏴󠁧󠁢󠁥󠁮󠁧󠁿","New York":"🗽",Washington:"🏔️","DC Metro Area":"🏛️"};function Wo(t,a){const r=a[String(t.entity_id)]||null,s=Jn(t.subtitle),i=r&&(r.city||r.state||r.country)?r:s||r;if(!i)return null;const c=(i.city||"").trim().toLowerCase();let m=(i.state||"").trim();const d=m.toUpperCase();Gs[d]&&(m=Gs[d]);const v=Yn(i.country||"").trim(),_=(t.subtitle||"").split(/[,·|]/).map(y=>y.trim().toLowerCase()).filter(Boolean),M=Array.from(new Set([c,..._,(t.title||"").trim().toLowerCase()].filter(Boolean)));return M.length===0?null:{keys:M.flatMap(y=>[`${y}|${m.toLowerCase()}|${v.toLowerCase()}`,`${y}||${v.toLowerCase()}`,`${y}||`]),city:c,state:m,country:v}}const Go={oregon:{region_name:"Willamette Valley",region_emoji:"🍇"},california:{region_name:"Northern California",region_emoji:"🐻"},france:{region_name:"France Regions",region_emoji:"🇫🇷"},washington:{region_name:"Puget Sound",region_emoji:"⛴️"}};function Ho(t,a,r){const s=t.filter(d=>Rt(d.domain)==="place"),i=[],c=new Map;for(const d of s){const v=hr(d,a);i.push({id:d.vault_taste_id,it:d,top:v}),c.set(v,(c.get(v)||0)+1)}const m=new Map;for(const{id:d,it:v,top:_}of i){if(!(zo.has(_)&&(c.get(_)||0)>=Uo)){m.set(d,{label:_,emoji:Mn[_]??null});continue}const y=Wo(v,a);let j=null;if(y){for(const W of y.keys)if(r[W]){j=r[W];break}}const S=Go[_.toLowerCase()],x=(j==null?void 0:j.region_name)||(S==null?void 0:S.region_name)||`Elsewhere in ${_}`,L=(j==null?void 0:j.region_emoji)||(S==null?void 0:S.region_emoji)||Mn[_]||"📍";
3m.set(d,{label:x,emoji:L})}return m}function or(t,a,r){const s=c=>{if(r){const m=r.get(c.vault_taste_id);if(m)return m}return{label:hr(c,a),emoji:null}},i=new Map;return t.forEach(c=>{const m=s(c),d=i.get(m.label)||{emoji:m.emoji,items:[]};!d.emoji&&m.emoji&&(d.emoji=m.emoji),d.items.push(c),i.set(m.label,d)}),Array.from(i.entries()).map(([c,m])=>({key:c,label:c,emoji:m.emoji,items:m.items})).sort((c,m)=>{const d=c.key==="Unknown"||c.key.startsWith("Elsewhere in "),v=m.key==="Unknown"||m.key.startsWith("Elsewhere in ");return d!==v?d?1:-1:m.items.length!==c.items.length?m.items.length-c.items.length:c.label.localeCompare(m.label)})}const pr=({item:t,className:a,fallbackIcon:r})=>{const s=nt(t.domain),i=s==="product",c=s==="place",{displaySrc:m,onImgError:d}=Va({entityId:t.entity_id?String(t.entity_id):t.vault_taste_id,vaultTasteId:t.vault_taste_id,title:t.title||"",src:t.thumbnail_url,domain:"product",category:t.level_2||t.level_1||null,enabled:i}),{displaySrc:v,onImgError:_}=Fa({entityId:t.entity_id?String(t.entity_id):null,title:t.title||"",src:t.thumbnail_url,category:t.level_2||t.level_1||null,location:t.subtitle||null,enabled:c}),M=i?m:c?v:t.thumbnail_url,y=i?d:c?_:void 0;if(M){const j=Et(M,"card")??M;return/\/taste-photos\//.test(M)?e.jsx("img",{src:j,alt:t.title||"",className:a,loading:"lazy",decoding:"async",onError:Vt(M,y)}):e.jsx("img",{src:j,alt:t.title||"",className:a,loading:"lazy",decoding:"async",onError:Vt(M,y)})}return e.jsx(e.Fragment,{children:r})},ls=({items:t,onCardClick:a,selectMode:r,selectedIds:s,onToggleSelect:i,ratings:c,hideDomainIcon:m})=>e.jsx("div",{className:"grid grid-cols-3 gap-2",children:t.map(d=>e.jsx(qo,{item:d,onClick:()=>{r&&i?i(d.vault_taste_id):a(d)},selectMode:r,selected:r?!!(s!=null&&s.has(d.vault_taste_id)):!1,rating:c==null?void 0:c[d.vault_taste_id],hideDomainIcon:m},d.vault_taste_id))}),qo=({item:t,onClick:a,selectMode:r,selected:s,rating:i,hideDomainIcon:c})=>{const m=nt(t.domain),d=dt[m]||dt.place,v=d.icon,_=(i==null?void 0:i.rating_value)??null,y=((i==null?void 0:i.experienced_state)??null)==="not_tried"&&_==null,j=_!=null||y,S=()=>_===2?e.jsx("span",{className:"text-[12px] leading-none",children:"❤️"}):_===1?e.jsx("span",{className:"text-[12px] leading-none",children:"👍"}):_===0?e.jsx("span",{className:"text-[12px] leading-none",children:"😐"}):_===-1?e.jsx("span",{className:"text-[12px] leading-none",children:"👎"}):_===-2?e.jsx("span",{className:"text-[12px] leading-none",children:"🚫"}):e.jsx("span",{className:"text-[12px] leading-none",children:"✨"}),x=_===2?"Loved":_===1?"Liked":_===0?"Neutral":_===-1?"Disliked":_===-2?"Hated":"Interested",L=e.jsxs("button",{onClick:a,className:Y("group relative aspect-square w-full overflow-hidden rounded-lg border bg-muted/30 text-left active:scale-[0.98] transition-transform",r&&s?"border-primary ring-2 ring-primary":"border-border/40",r&&!s?"opacity-60":""),children:[e.jsx(pr,{item:t,className:"h-full w-full object-cover",fallbackIcon:e.jsx("div",{className:Y("h-full w-full bg-gradient-to-br flex items-center justify-center",d.tint),children:e.jsx(v,{className:"h-6 w-6 text-foreground/40"})})}),j?e.jsx("div",{className:"absolute top-1.5 left-1.5 h-5 w-5 rounded-full inline-flex items-center justify-center bg-background/85 backdrop-blur-sm shadow",title:x,"aria-label":x,children:S()}):c?null:e.jsx("div",{className:Y("absolute top-1.5 left-1.5 h-5 w-5 rounded-full inline-flex items-center justify-center text-white shadow",d.chip),title:d.label,children:e.jsx(v,{className:"h-3 w-3"})}),r&&e.jsx("div",{className:Y("absolute top-1.5 right-1.5 h-5 w-5 rounded-full inline-flex items-center justify-center shadow border",s?"bg-primary border-primary text-primary-foreground":"bg-background/80 border-border/60 text-transparent"),children:e.jsx(mt,{className:"h-3 w-3"})}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/70 via-transparent to-transparent"}),e.jsx("div",{className:"absolute bottom-0 inset-x-0 p-1.5 text-white",children:e.jsx("div",{className:"text-[11px] font-medium leading-tight line-clamp-2",children:t.title})})]});return r?L:e.jsx(fr,{item:t,onOpen:a,children:L})},Ln=({sections:t,onCardClick:a})=>e.jsx("div",{className:"space-y-5",children:t.map(r=>e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold tracking-tight",children:r.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:r.items.length})]}),e.jsx("div",{className:"-mx-4 px-4 overflow-x-auto no-scrollbar",children:e.jsx("div",{className:"flex gap-2.5 pb-1",children:r.items.map(s=>e.jsx(fr,{item:s,onOpen:()=>a(s),className:"shrink-0 w-28",children:e.jsxs("button",{onClick:()=>a(s),className:"w-full active:scale-[0.97] transition-transform text-left",children:[e.jsx("div",{className:"relative aspect-square w-28 overflow-hidden rounded-lg border border-border/40 bg-muted/30",children:(()=>{const i=dt[nt(s.domain)]||dt.place,c=i.icon;
3return e.jsx(pr,{item:s,className:"h-full w-full object-cover",fallbackIcon:e.jsx("div",{className:Y("h-full w-full bg-gradient-to-br flex items-center justify-center",i.tint),children:e.jsx(c,{className:"h-6 w-6 text-foreground/40"})})})})()}),e.jsx("div",{className:"mt-1.5 text-[11px] font-medium leading-tight line-clamp-2",children:s.title}),ir(s)&&e.jsx("div",{className:"text-[10px] text-muted-foreground line-clamp-1",children:ir(s)})]})},s.vault_taste_id))})})]},r.key))}),Vo=({sections:t,onCardClick:a})=>{const[r,s]=n.useState({}),i=t.map(m=>m.key).join("|");n.useEffect(()=>{s(m=>{const d={};return t.forEach(v=>{d[v.key]=m[v.key]??!1}),d})},[i]);const c=m=>s(d=>({...d,[m]:!d[m]}));return e.jsx("div",{className:"space-y-2",children:t.map(m=>{const d=!!r[m.key];return e.jsxs("section",{className:"rounded-2xl border border-border/60 bg-card/40 overflow-hidden",children:[e.jsxs("button",{onClick:()=>c(m.key),className:"w-full flex items-center justify-between gap-2 px-3 py-2.5 text-left hover:bg-muted/30 transition-colors","aria-expanded":d,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qr,{className:Y("h-4 w-4 text-muted-foreground transition-transform",d&&"rotate-90")}),e.jsx("h3",{className:"text-sm font-semibold tracking-tight",children:m.label})]}),e.jsx("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:m.items.length})]}),d&&e.jsx("ul",{className:"divide-y divide-border/50 border-t border-border/50",children:m.items.map(v=>{const _=nt(v.domain),y=(dt[_]||dt.place).icon;return e.jsx("li",{children:e.jsx(fr,{item:v,onOpen:()=>a(v),children:e.jsxs("button",{onClick:()=>a(v),className:"w-full flex items-center gap-3 p-2.5 text-left hover:bg-muted/40 active:scale-[0.99] transition-all",children:[e.jsx("div",{className:"relative h-12 w-12 rounded-lg overflow-hidden bg-muted shrink-0 flex items-center justify-center",children:e.jsx(pr,{item:v,className:"h-full w-full object-cover",fallbackIcon:e.jsx(y,{className:"h-5 w-5 text-muted-foreground"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:v.title||"Untitled"}),ir(v)&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:ir(v)})]})]})})},v.vault_taste_id)})})]},m.key)})})},Fo=({items:t,placeCoords:a,onCardClick:r})=>{const s=n.useMemo(()=>t.map(c=>{const m=a[String(c.entity_id)];return m?{entityId:String(c.entity_id),title:c.title||"",subtitle:c.subtitle||"",lat:m.lat,lng:m.lng,thumbnailUrl:c.thumbnail_url||void 0,category:c.level_1||c.level_2||void 0}:null}).filter(Boolean),[t,a]),i=n.useMemo(()=>{const c=new Map;return t.forEach(m=>c.set(String(m.entity_id),m)),c},[t]);return s.length===0?e.jsxs("div",{className:"rounded-2xl border border-border/60 bg-muted/30 p-8 text-center",children:[e.jsx(Wn,{className:"h-8 w-8 mx-auto text-muted-foreground"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"No places with map coordinates yet."})]}):e.jsx("div",{className:"-mx-4 rounded-none overflow-hidden border-y border-border/60",children:e.jsx(Ea,{annotations:s,heightClass:"h-[60vh]",onAnnotationTap:c=>{const m=i.get(c);m&&r(m)}})})},En=({items:t,loading:a,onClose:r,onCardClick:s,onRemove:i,onToggleHide:c,onTogglePriority:m,userId:d,vaultAll:v,onAdd:_})=>{const[M,y]=n.useState(!1),j=n.useMemo(()=>new Set(t.map(O=>O.vault_taste_id)),[t]),S=n.useMemo(()=>Ua(t.map(O=>({...O,id:O.vault_taste_id}))),[t]),x=n.useMemo(()=>t.filter(O=>O.is_hidden),[t]),L=!!_&&!!v,W=L?e.jsxs("button",{type:"button",onClick:()=>y(!0),"aria-label":"Add a wish",className:"ml-auto h-8 pl-2.5 pr-3 rounded-full inline-flex items-center gap-1.5 border border-primary/30 bg-primary/10 text-primary text-xs font-semibold hover:bg-primary/15 active:scale-95 transition",children:[e.jsx(Bs,{className:"h-4 w-4",strokeWidth:2.25}),"Add wish"]}):null,V=L&&e.jsx(Ko,{open:M,onOpenChange:y,vaultAll:v,wishIds:j,onAdd:O=>_(O)});if(t.length===0)return a?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center px-1 pb-1",children:W}),e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(wt,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),V]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center px-1 pb-1",children:W}),e.jsx(xr,{icon:Bs,title:"No wishes yet",body:"Add things you'd love to receive — connections can see them when picking gifts."}),V]});const E=O=>{const X=!!O.is_hidden;return e.jsxs("li",{className:Y("flex items-stretch",X&&"bg-muted/40",O.is_priority&&!X&&"bg-primary/[0.05] border-l-2 border-l-primary"),children:[e.jsxs("button",{onClick:()=>s({vault_taste_id:O.vault_taste_id,entity_id:O.vault_taste_id,domain:O.domain||"",title:O.title,subtitle:O.subtitle,thumbnail_url:O.thumbnail_url,level_1:O.level_1??null,level_2:O.level_2??null,website:null,taxonomy_id:null,created_at:""}),className:Y("flex-1 min-w-0 flex items-center gap-3 p-3 text-left hover:bg-muted/40 active:scale-[0.99] transition-all",X&&"opacity-60"),children:[e.jsx("div",{className:"relative h-12 w-12 rounded-lg overflow-hidden bg-muted shrink-0 flex items-center justify-center",children:O.thumbnail_url?e.jsx("img",{src:Et(O.thumbnail_url,"thumb")??O.thumbnail_url,alt:O.title||"",className:Y("h-full w-full object-cover",X&&"grayscale"),loading:"lazy",decoding:"async",onError:Vt(O.thumbnail_url)}):e.jsx(Bs,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-sm font-medium truncate",children:O.title||"Untitled"}),O.subtitle&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:O.subtitle}),O.note&&e.jsxs("div",{className:"mt-1 flex items-start gap-1 text-xs italic text-amber-700 dark:text-amber-400",children:[e.jsx(La,{className:"h-3 w-3 mt-0.5 shrink-0"}),e.jsx("span",{className:"line-clamp-2",children:O.note})]}),X&&e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground mt-0.5",children:"Hidden from others"})]})]}),!O.is_priority&&e.jsx("button",{"aria-label":"Pin as Top Pick",title:"Pin as Top Pick",onClick:ge=>{ge.stopPropagation(),m(O.vault_taste_id,!0)},className:"px-3 flex items-center justify-center transition-colors touch-manipulation text-muted-foreground
3/60 hover:text-primary hover:bg-muted/40",children:e.jsx(vs,{className:"h-4 w-4",style:{transform:"rotate(45deg)",fill:"none"}})}),e.jsxs(Gt,{children:[e.jsx(Ht,{asChild:!0,children:e.jsx("button",{"aria-label":"Wishlist options",className:"px-3 flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/40 transition-colors",onClick:ge=>ge.stopPropagation(),children:e.jsx(_s,{className:"h-4 w-4"})})}),e.jsxs(qt,{align:"end",className:"w-56",children:[O.is_priority&&e.jsxs(ct,{onClick:()=>m(O.vault_taste_id,!1),children:[e.jsx(vs,{className:"h-4 w-4 mr-2",style:{transform:"rotate(45deg)",fill:"currentColor"}}),"Remove from Top Picks"]}),e.jsxs(ct,{onClick:()=>i(O.vault_taste_id),children:[e.jsx(Vs,{className:"h-4 w-4 mr-2"}),"Remove from wishlist",e.jsx("span",{className:"sr-only",children:" (item stays in your vault)"})]}),e.jsxs(ct,{onClick:()=>c(O.vault_taste_id,!X),children:[e.jsx(Si,{className:"h-4 w-4 mr-2"}),X?"Unhide from others":"Hide from others"]})]})]})]},O.vault_taste_id)},J=(O,X)=>e.jsx("ul",{className:"divide-y divide-border/50 rounded-2xl border border-border/60 bg-card/40 overflow-hidden",children:X.map(E)});return e.jsxs("div",{children:[e.jsxs("div",{className:"space-y-5",children:[S.topPicks.length>0&&e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-bold text-primary mb-2 flex items-center gap-1.5",children:[e.jsx(vs,{className:"h-3.5 w-3.5",style:{transform:"rotate(45deg)"},fill:"currentColor"}),"Top Picks",W]}),J(null,S.topPicks)]}),S.domains.map((O,X)=>e.jsxs("section",{children:[e.jsxs("h3",{className:"text-base font-bold text-foreground mb-2 flex items-center gap-2",children:[O.label,X===0&&S.topPicks.length===0?W:null]}),J(null,O.l2Groups.flatMap(ge=>ge.items).filter(ge=>!ge.is_hidden))]},O.domain)),S.topPicks.length===0&&S.domains.length===0&&W&&e.jsx("div",{className:"flex justify-end",children:W}),x.length>0&&e.jsxs("section",{children:[e.jsx("h3",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider mb-1.5 flex items-center gap-1.5",children:"Hidden from others"}),J(null,x)]})]}),V]})},Pn=[{key:"product",label:"Products",icon:es,match:t=>t.domain==="product"},{key:"place",label:"Places",icon:ht,match:t=>t.domain==="place"},{key:"book",label:"Books",icon:ur,match:t=>t.domain==="media"&&(t.level_1||"").toLowerCase()==="books"}],Ko=({open:t,onOpenChange:a,vaultAll:r,wishIds:s,onAdd:i})=>{const[c,m]=n.useState("product"),[d,v]=n.useState(""),[_,M]=n.useState(new Set);n.useEffect(()=>{t||(v(""),M(new Set))},[t]);const y=Pn.find(S=>S.key===c),j=n.useMemo(()=>{const S=d.trim().toLowerCase();return r.filter(x=>y.match(x)).filter(x=>!s.has(x.vault_taste_id)).filter(x=>S?us(S,x.title,x.subtitle):!0).slice(0,200)},[r,y,s,d]);return e.jsx(cr,{open:t,onOpenChange:a,children:e.jsxs(dr,{className:"max-w-md p-0 gap-0 max-h-[85dvh] flex flex-col",children:[e.jsx(Ur,{className:"px-4 pt-4 pb-2 shrink-0",children:e.jsx(Wr,{className:"text-base",children:"Add to wishlist"})}),e.jsx("div",{className:"px-4 pb-2 flex gap-1.5 shrink-0",children:Pn.map(S=>{const x=S.icon,L=S.key===c;return e.jsxs("button",{type:"button",onClick:()=>m(S.key),className:Y("inline-flex items-center gap-1.5 h-8 px-3 rounded-full text-xs font-medium border transition-colors",L?"bg-primary text-primary-foreground border-primary":"bg-background text-muted-foreground border-border/60 hover:bg-muted/60"),children:[e.jsx(x,{className:"h-3.5 w-3.5"}),S.label]},S.key)})}),e.jsx("div",{className:"px-4 pb-2 shrink-0",children:e.jsxs("div",{className:"relative",children:[e.jsx(Us,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(ds,{value:d,onChange:S=>v(S.target.value),placeholder:`Search your ${y.label.toLowerCase()}…`,className:"pl-8 h-9 text-base",style:{fontSize:16}})]})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-2 pb-3",children:j.length===0?e.jsx("div",{className:"py-10 text-center text-sm text-muted-foreground",children:d?"No matches in your vault.":`Nothing in your vault under ${y.label} that isn't already on your wishlist.`}):e.jsx("ul",{className:"divide-y divide-border/40",children:j.map(S=>{const x=_.has(S.vault_taste_id);return e.jsxs("li",{className:"flex items-center gap-3 px-2 py-2",children:[e.jsx("div",{className:"h-11 w-11 rounded-lg overflow-hidden bg-muted shrink-0 flex items-center justify-center",children:S.thumbnail_url?e.jsx("img",{src:Et(S.thumbnail_url,"thumb")??S.thumbnail_url,alt:S.title||"",className:"h-full w-full object-cover",loading:"lazy",decoding:"async",onError:Vt(S.thumbnail_url)}):e.jsx(Bs,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:S.title||"Untitled"}),S.subtitle&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:S.subtitle})]}),e.jsx("button",{type:"button",disabled:x,onClick:()=>{i(S),M(L=>{const W=new Set(L);return W.add(S.vault_taste_id),W})},className:Y("h-8 px-3 rounded-full text-xs font-medium inline-flex items-center gap-1 transition-colors shrink-0",x?"bg-muted text-muted-foreground":"bg-primary text-primary-foreground hover:bg-primary/90 active:scale-95"),children:x?e.jsxs(e.Fragment,{children:[e.jsx(mt,{className:"h-3.5 w-3.5"})," Added"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ns,{className:"h-3.5 w-3.5"})," Add"]})})]},S.vault_taste_id)})})})]})})},Yo=({stashes:t,userId:a,searchQuery:r,navigate:s,onCreateStash:i,vault:c,guideItems:m,guideItemMeta:d,stashScope:v,setStashScope:_,sharedWithMe:M,markAsViewed:y,stashesLoaded:j=!0,sharedLoading:S=!1})=>{const x=r.trim().toLowerCase(),[L,W]=n.useState(null),V=(C,z,F,ue,re)=>{const xe=`/vault?guide=${C}&guideName=${encodeURIComponent(z)}&returnTo=/profile?tab=stashes`;W({rect:F,coverUrl:ue,name:z,domain:re,targetUrl:xe,phase:"start"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{W(oe=>oe&&{...oe,phase:"expand"})})}),window.setTimeout(()=>s(xe),320)},E=n.useMemo(()=>x?t.filter(C=>us(x,C.name)):t,[t,x]),J=n.useMemo(()=>{const C=M||[];return x?C.filter(z=>us(x,z.guide_name,z.owner_name)):C}
3,[M,x]),[O,X]=n.useState({});n.useEffect(()=>{const C=(M||[]).map(F=>F.guide_id).filter(Boolean);if(C.length===0){X({});return}let z=!1;return(async()=>{const F={};for(let ue=0;ue<C.length;ue+=100){const re=C.slice(ue,ue+100),{data:xe}=await U.from("user_guide_items").select("guide_id").in("guide_id",re);(xe||[]).forEach(oe=>{F[oe.guide_id]=(F[oe.guide_id]||0)+1})}z||X(F)})(),()=>{z=!0}},[M]);const[ge,Re]=n.useState({});n.useEffect(()=>{const C=(M||[]).map(F=>F.guide_id).filter(Boolean);if(C.length===0){Re({});return}let z=!1;return(async()=>{const F={};for(let re=0;re<C.length;re+=200){const{data:xe,error:oe}=await U.rpc("get_guide_domain_counts",{p_guide_ids:C.slice(re,re+200)});if(oe){console.warn("[sharedDomainMap] rpc failed",oe);continue}xe==null||xe.forEach(P=>{const K=nt(P.domain);K&&(F[P.guide_id]=F[P.guide_id]||{},F[P.guide_id][K]=(F[P.guide_id][K]||0)+Number(P.cnt||0))})}if(z)return;const ue={};Object.entries(F).forEach(([re,xe])=>{const oe=Object.entries(xe).sort((g,D)=>D[1]-g[1]);if(!oe.length)return;const P=oe.reduce((g,[,D])=>g+D,0),K=oe.length>1&&oe[1][1]/Math.max(P,1)>=.2;ue[re]={top:oe[0][0],multi:K}}),Re(ue)})(),()=>{z=!0}},[M]);const[ve,it]=n.useState(new Set);n.useEffect(()=>{if(!a){it(new Set);return}let C=!1;return(async()=>{const{data:z}=await U.from("stash_likes").select("guide_id").eq("user_id",a);C||it(new Set((z||[]).map(F=>F.guide_id).filter(Boolean)))})(),()=>{C=!0}},[a]);const[B,Z]=n.useState(new Set),[se,G]=n.useState(new Set);n.useEffect(()=>{if(!a){Z(new Set);return}let C=!1;return(async()=>{const{data:z}=await U.from("stash_pins").select("guide_id").eq("user_id",a);C||Z(new Set((z||[]).map(F=>F.guide_id).filter(Boolean)))})(),()=>{C=!0}},[a]);const ye=n.useCallback(async C=>{if(!a||!C)return;let z=!1;Z(F=>{z=F.has(C);const ue=new Set(F);return z?ue.delete(C):ue.add(C),ue});try{z?await U.from("stash_pins").delete().eq("user_id",a).eq("guide_id",C):await U.from("stash_pins").insert({user_id:a,guide_id:C})}catch(F){Z(ue=>{const re=new Set(ue);return z?re.add(C):re.delete(C),re}),console.error("[togglePinStash] failed",F)}},[a]),{stashL1Map:Ye,stashDomainMap:Pe,stashSecondaryDomains:Ve}=n.useMemo(()=>{const C=new Map(c.map(oe=>[oe.vault_taste_id,oe])),z=new Map,F=new Map;for(const oe of m){const P=d[oe.taste_id],K=C.get(oe.taste_id),g=(P==null?void 0:P.l1)||(K?Zt(K):""),D=(P==null?void 0:P.domain)||(K?nt(K.domain):"");if(!g&&!D)continue;if(g){const p=z.get(oe.guide_id)||{};p[g]=(p[g]||0)+1,z.set(oe.guide_id,p)}const k=D||"mixed",h=F.get(oe.guide_id)||{};h[k]=(h[k]||0)+1,F.set(oe.guide_id,h)}const ue={};for(const[oe,P]of z){const K=Object.values(P).reduce((k,h)=>k+h,0),[g,D]=Object.entries(P).sort((k,h)=>h[1]-k[1])[0];ue[oe]=K>0&&D/K>=.5?g:"Mixed"}const re={},xe={};for(const[oe,P]of F){const K=Object.values(P).reduce((p,H)=>p+H,0),g=Object.entries(P).sort((p,H)=>H[1]-p[1]),[D]=g[0],k=K>
30?D:"";k&&(re[oe]=k);const h=g.filter(([p,H])=>p!==k&&H>=2&&H/K>=.1).slice(0,3).map(([p])=>p);h.length&&(xe[oe]=h)}return{stashL1Map:ue,stashDomainMap:re,stashSecondaryDomains:xe}},[c,m,d]),Le=n.useMemo(()=>{const C=new Map,z=(P,K)=>{const g=C.get(P)||[];g.push(K),C.set(P,g)},F=new Set(["place","product","media","creations","topic"]),ue=(P,K)=>{const g=nt(P==="mine"?K.domain:K.guide_domain),D=P==="mine"?K.id:K.guide_id,k=P==="shared"?ge[D]:void 0,h=(P==="shared"?k==null?void 0:k.top:Pe[D])||"";if(P==="shared"?!!(k!=null&&k.multi):(Ve[D]||[]).length>0)return"topic";const H=h||g;return H&&F.has(H)?H:"topic"};v!=="shared"&&E.forEach(P=>{if(B.has(P.id))return;const K=ue("mine",P);K&&z(K,{kind:"mine",row:P,dom:K})}),v!=="mine"&&J.forEach(P=>{if(B.has(P.guide_id))return;const K=ue("shared",P);K&&z(K,{kind:"shared",row:P,dom:K})});const re=new Map;for(const P of m)re.set(P.guide_id,(re.get(P.guide_id)||0)+1);const xe=P=>String(P.kind==="mine"?P.row.name:P.row.guide_name||"").toLowerCase();for(const P of C.values())P.sort((K,g)=>xe(K).localeCompare(xe(g)));const oe={place:"Places",product:"Products",media:"Media",creations:"Creations",topic:"Topics"};return Array.from(C.entries()).filter(([,P])=>P.length>0).map(([P,K])=>({dom:P,label:oe[P]||P,arr:K})).sort((P,K)=>P.arr.length!==K.arr.length?K.arr.length-P.arr.length:P.label.localeCompare(K.label))},[E,J,Pe,ge,Ve,v,m,O,ve,B]);n.useMemo(()=>{const C=Date.now()-2592e6,z=re=>{if(!re)return!1;const xe=new Date(re).getTime();return Number.isFinite(xe)&&xe>=C},F=v==="shared"?[]:E.filter(re=>z(re.created_at||"")).map(re=>({kind:"mine",ts:re.created_at||"",row:re})),ue=v==="mine"?[]:J.filter(re=>z(re.created_at||"")).map(re=>({kind:"shared",ts:re.created_at||"",row:re}));return[...F,...ue].sort((re,xe)=>(xe.ts||"").localeCompare(re.ts||"")).slice(0,10)},[E,J,v]);const $=E.length===0&&J.length===0,le=!j||S,ne=null,de=n.useMemo(()=>{if(B.size===0)return[];const C=(v==="shared"?[]:E).filter(F=>B.has(F.id)).map(F=>({kind:"mine",ts:F.updated_at||F.created_at||"",row:F})),z=(v==="mine"?[]:J).filter(F=>B.has(F.guide_id)).map(F=>({kind:"shared",ts:F.updated_at||F.created_at||"",row:F}));return[...C,...z].sort((F,ue)=>(ue.ts||"").localeCompare(F.ts||"")).slice(0,20)},[E,J,B,v]),De=E.length+J.length,Ee=!x&&De>=6;return e.jsxs("div",{className:"space-y-5",children:[$&&le?e.jsx("div",{className:"rounded-2xl border border-border/50 bg-card/30 p-8 flex items-center justify-center",children:e.jsx(wt,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):$?x?e.jsx(xr,{icon:ys,title:"No matches",body:"Try a different search."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-2xl border border-dashed border-border bg-card/40 p-6 text-center",children:[e.jsx(ys,{className:"h-8 w-8 mx-auto text-primary"}),e.jsx("h3",{className:"mt-2 font-semibold",children:"Create your first stash"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Stashes are curated collections of your saves — by city, vibe, or whatever you want."}),e.jsxs("button",{onClick:i,className:"mt-3 inline-flex items-center gap-1.5 h-9 px-4 rounded-full text-sm font-semibold bg-primary text-primary-foreground hover:bg-primary/90 transition-colors",children:[e.jsx(Ns,{className:"h-4 w-4"}),"Create a stash"]})]}),ne]}):Ee?e.jsxs(e.Fragment,{children:[de.length>0?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-0.5",children:[e.jsx(vs,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-[12px] font-semibold tracking-tight text-muted-foreground uppercase",children:"Pinned"})]}),e.jsx("div",{className:"flex gap-3.5 overflow-x-auto no-scrollbar -mx-4 px-4 pb-1",children:de.map(C=>{const z=C.row,F=C.kind==="mine",ue=F?z.id:z.guide_id,re=F?z.name:z.guide_name,xe=F?z.domain:z.guide_domain,oe=!F&&z.is_new;return e.jsxs("button",{onClick:P=>{const K=P.currentTarget.getBoundingClientRect();F||y(z.id),V(ue,re,K,z.cover_url,xe)},className:"shrink-0 w-[68px] flex flex-col items-center gap-1.5 active:scale-[0.97] transition-transform",children:[e.jsx("span",{className:Y("relative h-[62px] w-[62px] rounded-full p-[2px]",oe?"bg-gradient-to-br from-primary to-accent":"bg-border/70"),children:e.jsx("span",{className:"block h-full w-full rounded-full overflow-hidden bg-muted ring-2 ring-background",children:z.cover_url?e.jsx("img",{src:Et(z.cover_url,"avatar")??z.cover_url,alt:re,loading:"lazy",decoding:"async",className:"h-full w-full object-cover"}):e.jsx("span",{className:"h-full w-full flex items-center justify-center",children:e.jsx(zs,{className:"h-5 w-5 text-muted-foreground"})})})}),e.jsx("span",{className:"w-full text-[10.5px] leading-tight text-center text-foreground
3/85 line-clamp-2",children:re})]},`pin-${C.kind}-${z.id}`)})})]}):e.jsxs("div",{className:"rounded-2xl border border-dashed border-border/60 bg-card/40 px-4 py-3 flex items-center gap-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(vs,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-semibold leading-tight",children:"Pin your favorites"}),e.jsx("div",{className:"text-[11px] text-muted-foreground leading-snug mt-0.5",children:"Tap the pin on any stash to keep it up top."})]})]}),(E.length>0||J.length>0)&&e.jsx("div",{className:"flex items-center gap-1.5",children:[{k:"mine",label:"Mine",count:E.length},{k:"shared",label:"Shared with me",count:J.length}].map(C=>{const z=v===C.k;return e.jsxs("button",{onClick:()=>_(C.k),className:Y("inline-flex items-center gap-1.5 h-8 px-3 rounded-full border text-xs font-medium transition-colors",z?"bg-foreground text-background border-foreground":"border-border/60 bg-card/60 text-foreground hover:bg-card"),children:[e.jsx("span",{children:C.label}),e.jsx("span",{className:Y("inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full text-[10px] tabular-nums",z?"bg-background/20 text-background":"bg-muted text-muted-foreground"),children:C.count})]},C.k)})}),Le.length>0&&e.jsx("section",{className:"space-y-5",children:Le.map(({dom:C,label:z,arr:F})=>{const ue=dt[C]||dt.place,re=ue.icon,xe=se.has(C);return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>G(oe=>{const P=new Set(oe);return P.has(C)?P.delete(C):P.add(C),P}),className:"w-full flex items-center justify-between mb-2 px-0.5 group","aria-expanded":xe,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:Y("h-6 w-6 rounded-lg bg-gradient-to-br flex items-center justify-center",ue.tint),children:e.jsx(re,{className:"h-3.5 w-3.5 text-foreground/70",strokeWidth:2})}),e.jsx("h3",{className:"text-sm font-semibold tracking-tight",children:z})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:F.length}),e.jsx(jt,{className:Y("h-4 w-4 text-muted-foreground transition-transform",xe?"rotate-0":"-rotate-90")})]})]}),xe&&e.jsx("div",{className:"rounded-2xl border border-border/60 bg-card/40 overflow-hidden divide-y divide-border/50",children:F.map(oe=>{if(oe.kind==="mine"){const K=oe.row;return e.jsx(Tn,{name:K.name,domain:K.domain,coverUrl:K.cover_url,pinned:B.has(K.id),onTogglePin:()=>ye(K.id),onClick:g=>V(K.id,K.name,g,K.cover_url,K.domain)},`m-${K.id}`)}const P=oe.row;return e.jsx(Tn,{name:P.guide_name,domain:P.guide_domain,coverUrl:P.cover_url,ownerName:P.owner_name||null,ownerAvatarUrl:P.owner_avatar_url||null,isNew:P.is_new,isFriendOfFriend:P.is_friend_of_friend,pinned:B.has(P.guide_id),onTogglePin:()=>ye(P.guide_id),onClick:K=>{y(P.id),V(P.guide_id,P.guide_name,K,P.cover_url,P.guide_domain)}},`s-${P.guide_id}`)})})]},C)})})]}):e.jsxs(e.Fragment,{children:[E.length>0&&e.jsxs("section",{children:[e.jsx(An,{title:"My stashes",count:E.length}),e.jsx("div",{className:"grid grid-cols-2 gap-3 mt-2",children:E.map(C=>e.jsx(zr,{name:C.name,domain:C.domain,coverUrl:C.cover_url,onClick:z=>V(C.id,C.name,z,C.cover_url,C.domain)},C.id))})]}),J.length>0?e.jsxs("section",{children:[e.jsx(An,{title:"Shared with you",count:J.length,icon:ei}),e.jsx("div",{className:"grid grid-cols-2 gap-3 mt-2",children:J.map(C=>e.jsx(zr,{name:C.guide_name,domain:C.guide_domain,coverUrl:C.cover_url,ownerName:C.owner_name||null,ownerAvatarUrl:C.owner_avatar_url||null,isNew:C.is_new,onClick:z=>{y(C.id),V(C.guide_id,C.guide_name,z,C.cover_url,C.guide_domain)}},C.id))})]}):null]}),L&&e.jsxs("div",{className:"fixed inset-0 z-[100] pointer-events-none",children:[e.jsx("div",{className:"absolute inset-0 bg-background transition-opacity duration-[280ms] ease-out",style:{opacity:L.phase==="expand"?1:0}}),e.jsxs("div",{className:"absolute overflow-hidden shadow-2xl will-change-transform",style:{to
3p:L.phase==="expand"?0:L.rect.top,left:L.phase==="expand"?0:L.rect.left,width:L.phase==="expand"?"100vw":L.rect.width,height:L.phase==="expand"?"100vh":L.rect.height,borderRadius:L.phase==="expand"?0:16,transition:"top 320ms cubic-bezier(0.22, 1, 0.36, 1), left 320ms cubic-bezier(0.22, 1, 0.36, 1), width 320ms cubic-bezier(0.22, 1, 0.36, 1), height 320ms cubic-bezier(0.22, 1, 0.36, 1), border-radius 320ms ease-out"},children:[L.coverUrl?e.jsx("img",{src:Et(L.coverUrl,"card")??L.coverUrl,alt:"",className:"w-full h-full object-cover",onError:Vt(L.coverUrl)}):e.jsx("div",{className:Y("w-full h-full bg-gradient-to-br",(dt[L.domain||""]||dt.place).tint)}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/40 via-transparent to-transparent"})]})]})]})},An=({title:t,count:a,icon:r})=>e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[r&&e.jsx(r,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h3",{className:"text-sm font-semibold tracking-tight",children:t})]}),e.jsx("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:a})]}),zr=({name:t,domain:a,coverUrl:r,badge:s,isNew:i,ownerName:c,ownerAvatarUrl:m,onClick:d})=>{const v=dt[a||""]||dt.place,_=v.icon,M=c?c.split(" ")[0]:null;return e.jsxs("button",{onClick:y=>d(y.currentTarget.getBoundingClientRect()),className:"group relative aspect-[4/3] text-left active:scale-[0.98] transition-transform",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden rounded-2xl border border-border/60 bg-card",children:[e.jsx("div",{className:Y("absolute inset-0 bg-gradient-to-br flex items-center justify-center",v.tint),children:e.jsx(_,{className:"h-10 w-10 text-foreground/40",strokeWidth:1.4})}),r?e.jsx("img",{src:Et(r,"card")||r,alt:"",className:"absolute inset-0 h-full w-full object-cover group-hover:scale-105 transition-transform duration-500",loading:"lazy",decoding:"async",onError:Vt(r,y=>{y.currentTarget.style.display="none"})}):null,e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/75 via-black/10 to-transparent"}),e.jsxs("div",{className:"absolute bottom-0 inset-x-0 p-3 pr-11 text-white",children:[e.jsx("div",{className:"font-medium text-sm leading-tight line-clamp-2",children:t}),M?e.jsxs("div",{className:"text-[10px] text-white/80 mt-0.5",children:["By ",M]}
3):s?e.jsx("div",{className:"text-[10px] text-white/80 mt-0.5",children:s}):null]})]}),m||M?e.jsx("div",{className:"absolute -bottom-1.5 -right-1.5 h-8 w-8 rounded-full overflow-hidden ring-2 ring-background bg-muted flex items-center justify-center shadow-sm",children:m?e.jsx("img",{src:m,alt:M||"",className:"h-full w-full object-cover",loading:"lazy"}):e.jsx("span",{className:"text-[11px] font-semibold text-foreground/70",children:(M||"?").charAt(0).toUpperCase()})}):null]})},Tn=({name:t,domain:a,coverUrl:r,badge:s,isNew:i,ownerName:c,ownerAvatarUrl:m,pinned:d,isFriendOfFriend:v,onTogglePin:_,onClick:M})=>{const y=dt[nt(a)]||dt.place,j=y.icon,S=c?c.split(" ")[0]:null,x=!!(m||S);return e.jsxs("div",{role:"button",tabIndex:0,onClick:L=>M(L.currentTarget.getBoundingClientRect()),onKeyDown:L=>{(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),M(L.currentTarget.getBoundingClientRect()))},className:"group flex items-center gap-3 px-3 py-2.5 active:bg-muted/60 hover:bg-muted/40 transition-colors cursor-pointer outline-none",children:[e.jsxs("div",{className:"relative h-11 w-11 shrink-0",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden rounded-xl border border-border/60 bg-card",children:[e.jsx("div",{className:Y("absolute inset-0 bg-gradient-to-br flex items-center justify-center",y.tint),children:e.jsx(j,{className:"h-4 w-4 text-foreground/40",strokeWidth:1.6})}),r?e.jsx("img",{src:Et(r,"thumb")||r,alt:"",className:"absolute inset-0 h-full w-full object-cover",loading:"lazy",decoding:"async",onError:Vt(r,L=>{L.currentTarget.style.display="none"})}):null]}),x?e.jsx("div",{className:"absolute -bottom-1.5 -right-1.5 h-5 w-5 rounded-full overflow-hidden ring-2 ring-background bg-muted flex items-center justify-center shadow-sm",children:m?e.jsx("img",{src:m,alt:S||"",className:"h-full w-full object-cover",loading:"lazy"}):e.jsx("span",{className:"text-[9px] font-semibold text-foreground/70",children:(S||"?").charAt(0).toUpperCase()})}):null]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[14px] font-medium leading-tight truncate",children:t}),S?e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 min-w-0",children:[e.jsxs("span",{className:"text-[11px] text-muted-foreground leading-snug truncate",children:["By ",S]}),v&&e.jsxs("span",{className:"shrink-0 inline-flex items-center gap-1 rounded-full bg-muted px-1.5 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-muted-foreground ring-1 ring-border/60",children:[e.jsx(li,{className:"h-2.5 w-2.5"}),"Friend of friend"]})]}):s?e.jsx("div",{className:"text-[11px] text-muted-foreground leading-snug mt-0.5 truncate",children:s}):null]}),_&&e.jsx("button",{type:"button","aria-label":d?"Unpin stash":"Pin stash",onClick:L=>{L.stopPropagation(),_()},className:Y("shrink-0 h-8 w-8 rounded-full flex items-center justify-center transition-all active:scale-90",d?"text-primary":"text-muted-foreground/60"),children:e.jsx(vs,{className:Y("h-3.5 w-3.5",d&&"fill-current"),strokeWidth:d?2:2.2})}),e.jsx(qr,{className:"h-4 w-4 text-muted-foreground/50 shrink-0",strokeWidth:2})]})},xr=({icon:t,title:a,body:r})=>e.jsxs("div",{className:"mx-auto max-w-sm text-center py-14",children:[e.jsx("div",{className:"mx-auto h-14 w-14 rounded-full bg-muted/60 flex items-center justify-center",children:e.jsx(t,{className:"h-6 w-6 text-muted-foreground"})}),e.jsx("h3",{className:"mt-4 font-semibold",children:a}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:r})]}),Jo=({onGoCompass:t})=>e.jsxs("div",{className:"mx-auto max-w-sm text-center py-12 px-4",children:[e.jsx("div",{className:"mx-auto h-16 w-16 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Rr,{className:"h-7 w-7 text-primary"})}),e.jsx("h3",{className:"mt-4 text-lg font-semibold",children:"Your vault is empty"}),e.jsxs("p",{className:"mt-1.5 text-sm text-muted-foreground",children:["Start exploring picks tuned to your taste in Compass, or tap ",e.jsx("span",{className:"font-medium text-foreground",children:"Add new"})," below to save a favorite directly."]}),e.jsxs("button",{type:"button",onClick:t,className:"mt-5 inline-flex items-center gap-2 h-11 px-5 rounded-full bg-primary text-primary-foreground text-sm font-medium shadow-sm active:scale-[0.98] transition-transform",children:[e.jsx(Rr,{className:"h-4 w-4"}),"Explore Compass"]})]}),Qo=({vault:t,stashes:a,userId:r,query:s,onClose:i,onPickTaste:c,onPickStash:m})=>{const d=zn(r),v=Z=>(Z||"").normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase(),[_,M]=n.useState(s);n.useEffect(()=>{M(s)},[s]);const y=n.useDeferredValue(_),j=n.useMemo(()=>v(y.trim()),[y]),S=n.useMemo(()=>j?t.filter(Z=>v(Z.title||"").includes(j)||v(Z.subtitle||"").includes(j)||v(Z.level_2||"").includes(j)).slice(0,40):[],[t,j]),x=n.useMemo(()=>
3{if(!j)return[];const Z=a.filter(G=>v(G.name).includes(j)).map(G=>({id:G.id,name:G.name,cover_url:G.cover_url,domain:G.domain})),se=(d.sharedWithMe||[]).filter(G=>v(G.guide_name).includes(j)||v(G.owner_name||"").includes(j)).map(G=>({id:G.guide_id,name:G.guide_name,cover_url:G.cover_url,domain:G.guide_domain,badge:G.owner_name?`By ${G.owner_name.split(" ")[0]}`:void 0}));return[...Z,...se]},[a,d.sharedWithMe,j]),[L,W]=n.useState({});n.useEffect(()=>{const Z=S.filter(G=>nt(G.domain)==="place"&&/^\d+$/.test(G.entity_id||"")).map(G=>G.entity_id).filter(G=>L[G]===void 0);if(Z.length===0)return;let se=!1;return(async()=>{const G=Array.from(new Set(Z)).map(Ye=>Number(Ye)),{data:ye}=await U.from("corpus_places").select("id, city").in("id",G);se||!ye||W(Ye=>{const Pe={...Ye};for(const Ve of Z)Pe[Ve]="";for(const Ve of ye)Pe[String(Ve.id)]=Ve.city||"";return Pe})})(),()=>{se=!0}},[S,L]);const[V,E]=n.useState({}),J=n.useRef(new Set),O=n.useRef({});O.current=V;const[X,ge]=n.useState("");n.useEffect(()=>{const Z=setTimeout(()=>ge(j),350);return()=>clearTimeout(Z)},[j]),n.useEffect(()=>{if(X.length<2||X!==j)return;const Z=S.slice(0,12).filter($=>!$.thumbnail_url&&!O.current[$.vault_taste_id]&&!J.current.has($.vault_taste_id));if(Z.length===0)return;Z.forEach($=>J.current.add($.vault_taste_id));let se=!1;const G=$=>{if(!(se||Object.keys($).length===0)&&(E(le=>({...le,...$})),r))for(const[le,ne]of Object.entries($))U.from("user_vault_taste_search").update({thumbnail_url:ne}).eq("vault_taste_id",le).eq("user_id",r).then(()=>{})},ye=Z.filter($=>nt($.domain)==="place"&&!!$.entity_id);ye.length>0&&U.functions.invoke("resolve-place-images",{body:{items:ye.map($=>({id:$.vault_taste_id,entity_id:$.entity_id,title:$.title||"",category:$.level_2||$.subtitle||"local business"})),mode:"save"}}).then(({data:$})=>G(($==null?void 0:$.images)||{})).catch(()=>{});const Ye=Z.filter($=>nt($.domain)==="product"&&!!$.entity_id);if(Ye.length>0){const $=Ye.map(le=>parseInt(le.entity_id,10)).filter(le=>!Number.isNaN(le));$.length>0&&U.from("corpus_product_listings").select("product_id, image_url").in("product_id",$).not("image_url","is",null).then(({data:le})=>{if(!le)return;const ne={};for(const de of le){let De=de.image_url;if(!De)continue;De.startsWith("//")&&(De="https:"+De),De.startsWith("http://")&&(De=De.replace("http://","https://"));const Ee=Ye.find(C=>C.entity_id===String(de.product_id));Ee&&!ne[Ee.vault_taste_id]&&(ne[Ee.vault_taste_id]=De)}G(ne)})}const Pe=new Map([["movie","movies"],["movies","movies"],["show","shows"],["shows","shows"],["tv show","shows"],["tv shows","shows"],["book","books"],["books","books"]]),Ve=Z.filter($=>nt($.domain)==="media"&&!!$.title).map($=>{const le=($.level_2||$.level_1||"").toLowerCase(),ne=Pe.get(le);return ne?{id:$.vault_taste_id,title:$.title,category:ne,entity_id:$.entity_id}:null}).filter(Boolean);Ve.length>0&&U.functions.invoke("resolve-media-images",{body:{items:Ve}}).then(({data:$})=>G(($==null?void 0:$.images)||{})).catch(()=>{});const Le=Z.filter($=>{if(nt($.domain)!=="media")return!1;const le=($.level_2||$.level_1||"").toLowerCase();if(!(le==="song"||le==="songs"||le==="music"||le==="album"||le==="albums"))return!1;const ne=($.title||"").trim();return!(!ne||/^a?\.?[il]\.[A-Za-z0-9]+$/.test(ne)||ne===$.entity_id)});return Le.length>0&&Promise.all(Le.map(async $=>{const le=($.title||"").split("—")[0].trim(),ne=await aa(le,$.subtitle||"");return ne?[$.vault_taste_id,ne]:null})).then($=>{const le={};for(const ne of $)ne&&(le[ne[0]]=ne[1]);G(le)}),()=>{se=!0}},[S,r,X,j]),n.useEffect(()=>{const Z=G=>{G.key==="Escape"&&i()};window.addEventListener("keydown",Z);const se=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",Z),document.body.style.overflow=se}},[i]);const Re=S.length+x.length,[ve,it]=n.useState("tastes");n.useEffect(()=>{S.length===0&&x.length>0?it("stashes"):x.length===0&&S.length>0&&it("tastes")},[S.length,x.length]);const B=S.length>0&&x.length>0;return e.jsx("div",{className:"fixed inset-0 z-[60] bg-foreground
3/45 backdrop-blur-[2px] animate-in fade-in duration-150",onClick:i,children:e.jsxs("div",{className:"absolute inset-x-0 top-0 bg-background border-b border-border shadow-2xl animate-in slide-in-from-top duration-200",style:{paddingTop:"env(safe-area-inset-top)"},onClick:Z=>Z.stopPropagation(),children:[e.jsxs("div",{className:"px-3 py-3 flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Us,{className:"h-4 w-4 absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e.jsx(ds,{autoFocus:!0,value:_,onChange:Z=>M(Z.target.value),placeholder:"Search tastes and stashes…",className:"pl-9 pr-3 h-11 text-base rounded-xl bg-muted/50 border-transparent focus-visible:bg-background focus-visible:border-border",style:{fontSize:"16px"}})]}),e.jsx("button",{type:"button",onClick:i,"aria-label":"Close search",className:"h-11 w-11 rounded-full inline-flex items-center justify-center text-foreground bg-muted/60 hover:bg-muted transition-colors active:scale-95",children:e.jsx(_s,{className:"h-5 w-5"})})]}),e.jsx("div",{className:"max-h-[calc(100dvh-env(safe-area-inset-top)-5rem)] overflow-y-auto pb-6",children:j?Re===0?e.jsxs("div",{className:"px-6 py-12 text-center",children:[e.jsx("div",{className:"mx-auto h-12 w-12 rounded-full bg-muted/60 flex items-center justify-center",children:e.jsx(Us,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("h3",{className:"mt-3 font-semibold text-sm",children:"No matches"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Try a different search."})]}):e.jsxs("div",{className:"space-y-5 px-4 pt-2",children:[B&&e.jsxs("div",{className:"inline-flex w-full rounded-xl bg-muted/60 p-1 text-xs font-semibold",children:[e.jsxs("button",{type:"button",onClick:()=>it("tastes"),className:Y("flex-1 inline-flex items-center justify-center gap-1.5 rounded-lg px-3 py-2 transition-colors",ve==="tastes"?"bg-background text-foreground shadow-sm":"text-muted-foreground"),children:[e.jsx(Ft,{className:"h-3.5 w-3.5"})," Tastes",e.jsx("span",{className:"ml-1 opacity-70",children:S.length})]}),e.jsxs("button",{type:"button",onClick:()=>it("stashes"),className:Y("flex-1 inline-flex items-center justify-center gap-1.5 rounded-lg px-3 py-2 transition-colors",ve==="stashes"?"bg-background text-foreground shadow-sm":"text-muted-foreground"),children:[e.jsx(zs,{className:"h-3.5 w-3.5"})," Stashes",e.jsx("span",{className:"ml-1 opacity-70",children:x.length})]})]}),S.length>0&&(!B||ve==="tastes")&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:[e.jsx(Ft,{className:"h-3.5 w-3.5"})," Tastes"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:S.length})]}),e.jsx("ul",{className:"divide-y divide-border/60 rounded-xl border border-border/60 bg-card/40 overflow-hidden",children:S.map((Z,se)=>{const G=dt[nt(Z.domain)]||dt.place,ye=G.icon,Ye=Z.thumbnail_url||V[Z.vault_taste_id]||null,Pe=Et(Ye,"avatarXs",{height:64,resize:"contain"}),Ve=se<16;return e.jsx("li",{children:e.jsxs("button",{onClick:()=>{const Le=S.map(le=>{const ne=V[le.vault_taste_id];return ne&&!le.thumbnail_url?{...le,thumbnail_url:ne}:le}),$=Le.find(le=>le.vault_taste_id===Z.vault_taste_id)||Z;c($,Le)},className:"w-full flex items-center gap-3 p-2.5 text-left hover:bg-muted/40 active:bg-muted/60 transition-colors",children:[e.jsxs("div",{className:"relative h-12 w-12 shrink-0 rounded-lg overflow-hidden bg-muted",children:[e.jsx("div",{className:Y("absolute inset-0 bg-gradient-to-br flex items-center justify-center",G.tint),children:e.jsx(ye,{className:"h-5 w-5 text-foreground/40"})}),Ye?e.jsx("img",{src:Pe||Ye,alt:"",width:48,height:48,className:"relative h-full w-full object-contain",loading:Ve?"eager":"lazy",decoding:"async",...Ve?{fetchPriority:"high"}:{},onError:Vt(Ye,Le=>{Le.currentTarget.style.display="none"})}):null]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:Z.title||"Untitled"}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate inline-flex items-center gap-1",children:[e.jsx(ye,{className:"h-3 w-3"}),e.jsx("span",{children:Z.level_2||G.label}),(()=>{const Le=Z.subtitle||"",$=nt(Z.domain)==="place";let le=Le;if($){const ne=L[Z.entity_id],de=Le?Le.split(",")[0].trim():"",De=/\d/.test(de)||/\b(trl|trail|dr|drive|rd|road|ave|avenue|st|street|blvd|boulevard|hwy|highway|loop|ln|lane|ct|court|way|pkwy|parkway|pl|place|ter|terrace)\b\.?$/i.test(de)||/\(\s*\d/.test(de);ne?le=ne:de&&!De?le=de:le=""}
3return le?e.jsxs("span",{className:"text-muted-foreground/60",children:["· ",le]}):null})()]})]}),e.jsx(qr,{className:"h-4 w-4 text-muted-foreground shrink-0"})]})},Z.vault_taste_id)})})]}),x.length>0&&(!B||ve==="stashes")&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:[e.jsx(zs,{className:"h-3.5 w-3.5"})," Stashes"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:x.length})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:x.map(Z=>e.jsx(zr,{name:Z.name,domain:Z.domain,coverUrl:Z.cover_url,badge:Z.badge,onClick:()=>m(Z.id,Z.name)},Z.id))})]})]}):e.jsx("div",{className:"px-6 py-12 text-center text-sm text-muted-foreground",children:"Search your Vault"})})]})})};export{Ho as buildRegionLabelMap,Nm 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.