PageSourceSearch

https://fyra.life/assets/SharedGuide-gN30oSOb.js

js fyra.life collected 2026-10-02 02:01:28 UTC 28,089 bytes, 1 lines download raw bytes

1import{r as m,x as Oe,j as e,B as F,a4 as Be,u as Me,a0 as He,a as De,s as x,_ as Ge}from"./index-CEISlULX.js";import{s as Fe}from"./perfTrace-CDMfaol-.js";import{S as ue}from"./skeleton-BKqmq49x.js";import{S as Le}from"./StashIcon-JEYRozzv.js";import{f as Je}from"./functionErrorMessage-DvAoPto1.js";import{D as qe,a as ze,b as Ye,c as Ke}from"./dialog-DL4GLjds.js";import{B as Ze}from"./badge-CmNrSZhw.js";import{C as Xe}from"./chevron-left-CwPhAN8D.js";import{C as We}from"./chevron-right-BR3dueKL.js";import{M as Qe}from"./map-pin-DzyMqwtX.js";import{E as et}from"./external-link-DoOQ4sOr.js";import{C as tt}from"./check-BFjtj0TV.js";import{L as W}from"./loader-circle-C0qiwHXp.js";import{P as rt}from"./plus-CMUH1C5J.js";import{u as st,b as ot,c as at,S as nt,a as it,e as Ne,f as lt,g as dt,h as ct,i as mt,j as ut,k as pt,l as ht,A as ft}from"./StashWidgetRenderer-DSlT5LpF.js";import{l as _t,b as Ce,h as Ae,j as gt,e as yt,d as pe,f as G}from"./stashWidgets-BUzXcvw_.js";import{s as ke}from"./imageTransform-D9pM4sAU.js";import{A as xt}from"./list-plus-CO4sYOI4.js";import"./index-CKv5A6hs.js";import"./index-yCNHGKsJ.js";import"./textarea-DmWS1sXw.js";import"./send-C5489gX8.js";import"./upload-C39KYR9i.js";import"./sparkles-BpeD-uNo.js";import"./layout-grid-C-WsiPBY.js";import"./index--mM4HYI_.js";import"./salad-mVL4LnpN.js";import"./user-check-B_6ZaR46.js";import"./archive-Jd8RlV9D.js";import"./wallpaper-CeJbgLzY.js";import"./thumbs-up-CruyU46y.js";import"./arrow-left-Dt5WA4Nk.js";import"./arrow-right-Ckpzlj9J.js";import"./arrow-up-right-BrJUeDFD.js";import"./arrow-up-BblLnKwc.js";import"./volleyball-DIJWUPwn.js";import"./ticket-Dap17UU8.js";import"./umbrella-D-zeEICs.js";import"./bell-C4TOMhw-.js";import"./book-open-CJtqdthI.js";import"./book-user-CU26YudE.js";import"./circle-help-snkdi1k5.js";import"./user-round-plus-7aXduXl6.js";import"./briefcase-ki10mlMI.js";import"./pen-tool-DS2ilMZt.js";import"./cake-BCyyd8ED.js";import"./calendar-BfvDU277.js";import"./keyboard-BVXJEfl6.js";import"./camera-CR32InGn.js";import"./chart-no-axes-column-_7dx5Hci.js";import"./chef-hat-CwRyf-_j.js";import"./chevron-down-CVkqx0vb.js";import"./chevron-up-DZivf4pR.js";import"./graduation-cap-BKvrl9S-.js";import"./circle-alert-DD1fZH5W.js";import"./circle-check-big-DXI_pL0q.js";import"./circle-check-BMYdMzAm.js";import"./zoom-out-jt_1THDy.js";import"./circle-x-nZdDvV64.js";import"./circle-ChqNdpqJ.js";import"./clock-CsInmizx.js";import"./tree-pine-CVC2rmdh.js";import"./compass-DU-94JJU.js";import"./cookie-CeYVh1Mq.js";import"./copy-BxYBM9wg.js";import"./crown-FH-WU3HK.js";import"./redo-2-S-bbb5SV.js";import"./store-CkUsUNn0.js";import"./download-dcXx3E28.js";import"./dumbbell-BNBXgND1.js";import"./save-CI9MkljJ.js";import"./eye-off-D2l0jZEC.js";import"./eye-OdF1rFDD.js";import"./file-spreadsheet-ChSkyAIe.js";import"./file-text-CamhJ3w8.js";import"./film-kc4h8MJx.js";import"./flag-d9lSX6Fp.js";import"./flame-JRnXPgHe.js";import"./flask-conical-BoF3E8Ti.js";import"./mountain-Cosd5fS9.js";import"./gamepad-2-Dj5IAcM9.js";import"./gem-CQpK3PY6.js";import"./gift-DCKDU-AH.js";import"./globe-C9iVOL1m.js";import"./grid-3x3-BJOgqLIf.js";import"./grip-vertical-BMU1IbGG.js";import"./scissors-DRod-a_U.js";import"./hand-heart-B_myFvqi.js";import"./headphones-Ca_UJjsb.js";import"./heart-handshake-BdNSckxu.js";import"./heart-BdtuOGcS.js";import"./hotel-DboxzOQB.js";import"./house-DyEJdHUq.js";import"./image-plus-uQ0IJYfW.js";import"./image-UOq2Pr3V.js";import"./square-check-big-BB3BQxpw.js";import"./share-Cvxz-ci4.js";import"./key-round-DkD0MM1j.js";import"./key-DL662AMv.js";import"./landmark-DMJlToWM.js";import"./layers-D4Zk86Ck.js";import"./lightbulb-BB3_VrXi.js";import"./link-2-BkhClLri.js";import"./link-BLtkoFqS.js";import"./list-checks-CbBnCJnX.js";import"./list-music-CYsM_wzB.js";import"./list-ordered-BzOeGYTg.js";import"./list-DJBNQVyl.js";import"./lock-DHrReJOO.js";import"./mail-CJfty1xB.js";import"./megaphone-DlJHIds_.js";import"./message-circle-question-CV7HfJK1.js";import"./message-circle-D7UkCYZL.js";import"./message-square-BMoi7LMp.js";import"./mic-CA9kkvLV.js";import"./minus-DiBQwzSu.js";import"./music-2-ga3ZXLz6.js";import"./package-CJ2GCcQQ.js";import"./palette-A7zxrGyD.js";import"./pen-line-D3QIzx2D.js";import"./pencil-DZdaQ7Ww.js";import"./zap-Chv97BCW.js";import"./plane-DCSeTjAi.js";import"./plug-GVKN3J5k.js";import"./podcast-DOqFhd3u.js";import"./refresh-cw-uC6mqHyu.js";import"./rotate-ccw-BiNSGnP5.js";import"./scan-barcode-CvSB7jiw.js";import"./search-Ctpt4-cV.js";import"./settings-BTcXQ77j.js";import"./share-2-BanhKmSi.js";import"./shield-tkiE8X1o.js";import"./shirt-Cr7saDpI.js";import"./shopping-bag-u8-RJDu1.js";import"./smartphone-CXHDx8n6.js";import"./sparkle-CpWw7Pff.js";
1import"./star-ESAhzt-i.js";import"./tag-BQdqCxAu.js";import"./telescope-6m63hefb.js";import"./trash-2-DSAvAWKG.js";import"./trending-up-Wq_xQ3a7.js";import"./triangle-alert-Byinhax_.js";import"./tv-C88hoGGy.js";import"./undo-2-Bo2MK0yM.js";import"./user-plus-DDOf94UL.js";import"./user-DpvtsXRI.js";import"./users-BDheGP7O.js";import"./utensils-crossed-BO4e05Nu.js";import"./utensils-VfXwFIzS.js";import"./video-DcZVB1n-.js";import"./wand-sparkles-BEO6-Ma6.js";import"./wine-Cbzkns94.js";import"./wrench-Dk5C-6Dh.js";import"./youtube-B-NPx3E6.js";import"./zoom-in-CPgIt-kO.js";import"./AppleMapView-AwWSXE3e.js";import"./useGeolocation-xM1TYFdZ.js";import"./switch-EWfemxkv.js";import"./index-CzOLp-Ui.js";import"./dropdown-menu-Cuuz4TQG.js";import"./index-C6i_x82y.js";import"./index-B0RLvCOv.js";import"./scroll-area-CiD1SC6W.js";import"./index-BdQq_4o_.js";import"./normalizeMediaLevel2-BFbM6i_V.js";import"./input-CaLoYHgx.js";import"./imageUpload-BIv5lkJD.js";const L="fyra:pendingStashIntent",bt=30*60*1e3;function Te(o){if(!o)return null;try{return JSON.parse(o)}catch{return null}}function he(o,p){return!(!o||o.slug!==p||typeof o.ts!="number"||Date.now()-o.ts>bt||o.action!=="add-one"&&o.action!=="import-all")}function wt(o){const p={...o,ts:Date.now()},c=JSON.stringify(p);try{localStorage.setItem(L,c)}catch{}try{sessionStorage.setItem(L,c)}catch{}return p}function vt(){try{localStorage.removeItem(L)}catch{}try{sessionStorage.removeItem(L)}catch{}}function St(o){const p={...o,ts:Date.now()},c=JSON.stringify(p);return btoa(unescape(encodeURIComponent(c))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function jt(o){if(!o)return null;try{const p=o.replace(/-/g,"+").replace(/_/g,"/"),c=p+"=".repeat((4-p.length%4)%4),g=decodeURIComponent(escape(atob(c)));return JSON.parse(g)}catch{return null}}function It(o,p){const c=jt(p);if(he(c,o))return c;const g=Te(typeof sessionStorage<"u"?sessionStorage.getItem(L):null);if(he(g,o))return g;const s=Te(typeof localStorage<"u"?localStorage.getItem(L):null);return he(s,o)?s:null}const Nt=({open:o,onOpenChange:p,item:c,isAlreadyInVault:g,isAdding:s,onAdd:$})=>{const[U,j]=m.useState(0);if(Oe.useEffect(()=>{j(0)},[c==null?void 0:c.taste_id]),!c)return null;const a=c.detail||null,S=a!=null&&a.photos&&a.photos.length>0?a.photos:c.thumbnail_url?[c.thumbnail_url]:[],i=S[U]||null,E=a!=null&&a.place?[a.place.city,a.place.state,a.place.country].filter(Boolean).join(", "):null,O=a!=null&&a.product?[a.product.brand,a.product.model].filter(Boolean).join(" · "):null,P=(a==null?void 0:a.category_label)||c.level_2||null;return e.jsx(qe,{open:o,onOpenChange:p,children:e.jsxs(ze,{className:"sm:max-w-lg max-h-[90dvh] overflow-y-auto",children:[e.jsx(Ye,{children:e.jsx(Ke,{className:"pr-6",children:c.display_name})}),i&&e.jsxs("div",{className:"relative w-full aspect-square rounded-lg overflow-hidden bg-muted",children:[e.jsx("img",{src:i,alt:c.display_name,className:"w-full h-full object-cover",loading:"lazy"}),S.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"absolute left-2 top-1/2 -translate-y-1/2 h-8 w-8 rounded-full bg-background/80 backdrop-blur flex items-center justify-center hover:bg-background",onClick:()=>j(C=>(C-1+S.length)%S.length),"aria-label":"Previous photo",children:e.jsx(Xe,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 h-8 w-8 rounded-full bg-background/80 backdrop-blur flex items-center justify-center hover:bg-background",onClick:()=>j(C=>(C+1)%S.length),"aria-label":"Next photo",children:e.jsx(We,{className:"h-4 w-4"})}),e.jsxs("div",{className:"absolute bottom-2 left-1/2 -translate-x-1/2 px-2 py-0.5 rounded-full bg-background/80 text-xs",children:[U+1," / ",S.length]})]})]}),e.jsxs("div",{className:"space-y-3",children:[c.subtitle&&e.jsx("p",{className:"text-sm text-muted-foreground",children:c.subtitle}),e.jsx("div",{className:"flex flex-wrap gap-2",children:P&&e.jsx(Ze,{variant:"secondary",className:"uppercase text-xs",children:P})}),(a==null?void 0:a.description)&&e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-line",children:a.description}),E&&e.jsxs("div",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(Qe,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsx("span",{children:E})]}),O&&e.jsx("div",{className:"text-sm text-muted-foreground",children:O}),(a==null?void 0:a.website)&&e.jsxs("a",{href:a.website,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-sm text-primary hover:underline",children:[e.jsx(et,{className:"h-4 w-4"}),"Visit website"]}),e.jsx("div",{className:"pt-2",children:g?e.jsxs(F,{variant:"outline",className:"w-full",disabled:!0,children:[e.jsx(tt,{className:"h-4 w-4 mr-2"}),"In your Vault"]}):e.jsxs(F,{className:"w-full",onClick:$,disabled:s,children:[s?e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(rt,{className:"h-4 w-4 mr-2"}),"Add to Vault"]})})]})]})})},kt=({guideId:o,title:p,description:c,coverUrl:g,ownerName:s,ownerAvatarUrl:$,coAuthors:U,templateConfig:j,widgets:a,sections:S,items:i,userId:E,comments:O,onOpenItem:P})=>{var K,Z;const[C,re]=m.useState("All"),Q=!!(a!=null&&a.some(t=>t.widget_type==="voting")),J=!!(a!=null&&a.some(t=>t.widget_type==="commenting")),{votes:se,comments:oe,refresh:ae}=st(Q||J?o:null,E??null,O),R=m.useMemo(()=>i.map(t=>({vault_taste_id:t.taste_id,entity_id:t.entity_id??null,domain:t.domain??null,title:t.title||t.dis
1play_name||null,subtitle:t.subtitle??null,thumbnail_url:t.thumbnail_url??null,level_1:t.level_1??null,level_2:t.level_2??null,product_metadata:t.product_metadata??null})),[i]),I=m.useMemo(()=>{const t={};for(const h of i)h.annotation&&(t[h.taste_id]=h.annotation);return t},[i]),B=m.useMemo(()=>{const t={};for(const h of i)h.section_id&&(t[h.taste_id]=h.section_id);return t},[i]),ne=m.useMemo(()=>i.filter(t=>t.domain==="place"&&t.entity_id&&typeof t.lat=="number"&&typeof t.lng=="number").map(t=>({entityId:String(t.entity_id),title:t.title||t.display_name||"Unknown",subtitle:t.subtitle||"",lat:t.lat,lng:t.lng,thumbnailUrl:t.thumbnail_url||void 0,category:t.level_2||t.level_1||void 0})),[i]),q=a==null?void 0:a.find(t=>t.widget_type==="view"),H=(K=q==null?void 0:q.config)==null?void 0:K.layout,A=H?_t(H):Ce(j).key,D=A==="black_book"?[]:ot(R,S,B),z=D.find(t=>t.key===C)?C:"All",T={items:z==="All"?R:((Z=D.find(t=>t.key===z))==null?void 0:Z.items)??R,config:j,notesByVaultId:I,onOpen:t=>P(t.vault_taste_id)};let N=null;H==="big"?N=e.jsx(Ne,{...T,variant:"big"}):A==="the_shelf"?N=e.jsx(lt,{...T}):A==="the_reel"?N=e.jsx(dt,{...T}):A==="songbook"?N=e.jsx(ct,{...T}):A==="black_book"?N=e.jsx(mt,{...T,sections:S,itemSectionMap:B,showCategories:!0,mapAnnotations:ne,onAnnotationTap:t=>{const h=i.find(le=>String(le.entity_id)===String(t));h&&P(h.taste_id)},stashMode:!0,canSaveReference:!1,guideId:o,userId:E??null,votingEnabled:Q,commentingEnabled:J,votes:se,comments:oe,onEngagementChanged:ae}):A==="the_cabinet"?N=e.jsx(ut,{...T}):A==="tasting_notes"?N=e.jsx(pt,{...T}):A==="gallery"?N=e.jsx(Ne,{...T,variant:"grid"}):N=e.jsx(ht,{...T,sections:S,itemSectionMap:B});const Y=e.jsxs(e.Fragment,{children:[e.jsx(at,{categoryDefs:D,totalCount:R.length,activeCat:z,onChange:re}),N]});return e.jsx(nt,{config:j,title:p,coverUrl:g,description:c,sharedByProfile:s?{name:s,avatarUrl:$?ke($,"avatar")??null:null}:null,coAuthors:(U||[]).map(t=>({id:t.id,name:t.name,avatarUrl:t.avatar_url?ke(t.avatar_url,"avatar")??null:null})),ctaLabel:Ae(j)||"Save stash",isOwner:!1,children:a&&a.length>0?e.jsx(it,{widgets:a,viewSlot:Y,items:R,guideId:o,userId:E??null,canEdit:!1,onOpenItem:t=>P(t)}):Y})},Uo=()=>{var ge,ye,xe,be,we,ve,Se;const{slug:o}=Be(),p=Me(),c=He(),{toast:g}=De(),[s,$]=m.useState(null),[U,j]=m.useState(!0),[a,S]=m.useState(null),[i,E]=m.useState(null),[O,P]=m.useState(!1),[C,re]=m.useState(!1),[Q,J]=m.useState(new Set),[se,oe]=m.useState(new Set),[ae,R]=m.useState(null),[I,B]=m.useState(null),[ne,q]=m.useState(!1);m.useEffect(()=>{let r=!1;return(async()=>{var n,f;try{const u=await Promise.race([x.auth.getUser(),new Promise(d=>setTimeout(()=>d(null),2500))]);if(r)return;E(((f=(n=u==null?void 0:u.data)==null?void 0:n.user)==null?void 0:f.id)||null)}catch{r||E(null)}})(),()=>{r=!0}},[]),m.useEffect(()=>{(async()=>{if(!o){S("Invalid share link"),j(!1);return}const l=Fe("Stash Detail","/shared-guide");try{const n=async()=>{const _="https://vauhodpuhdnypebxfeod.supabase.co",y="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InZhdWhvZHB1aGRueXBlYnhmZW9kIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjIyNjkyNTYsImV4cCI6MjA3Nzg0NTI1Nn0.xeUsN95iY99HHOSUVHLQbOHp38Byn0I49YnTm5Kr-Kk";for(let V=0;V<3;V++){const k=new AbortController,te=window.setTimeout(()=>k.abort(),8e3);try{const w=await fetch(`${_}/functions/v1/shared-guide-data`,{method:"POST",headers:{"Content-Type":"application/json",apikey:y,Authorization:`Bearer ${y}`},body:JSON.stringify({slug:o}),signal:k.signal});if(w.ok){const M=await w.json();if(M!=null&&M.guide)return M.guide}if(w.status===404)return null;console.error("SharedGuide edge fetch failed",{attempt:V,status:w.status,slug:o})}catch(w){console.error("SharedGuide edge fetch error",{attempt:V,e:w,slug:o})}finally{window.clearTimeout(te)}await new Promise(w=>setTimeout(w,500*(V+1)))}return null},f=Promise.race([Promise.resolve(x.from("user_guide_shares").select("id, guide_id, owner_user_id, view_count").eq("share_slug",o).eq("is_public",!0).maybeSingle()).then(({data:_,error:y})=>(y&&console.warn("[SharedGuide] share row read failed",y),_??null)),new Promise(_=>setTimeout(()=>_(null),4e3))]).catch(()=>null);
1f.then(_=>{_&&(x.from("user_guide_shares").update({view_count:(_.view_count||0)+1,last_viewed_at:new Date().toISOString()}).eq("id",_.id),i&&x.from("user_share_views").upsert({share_id:_.id,viewer_user_id:i,last_viewed_at:new Date().toISOString()},{onConflict:"share_id,viewer_user_id"}))});const u=await n();if(u){$(u),j(!1);return}const d=await f;if(!d){S("This stash link isn't available right now"),j(!1);return}const{data:v,error:ee}=await x.from("user_guides").select("id, name, user_id, extra").eq("id",d.guide_id).maybeSingle();if(ee||!v){S("Guide data not found"),j(!1);return}const{data:b}=await x.from("profiles").select("username, first_name").eq("id",d.owner_user_id).maybeSingle(),{data:je}=await x.from("user_guide_items").select("id, taste_id, display_name").eq("guide_id",d.guide_id),Ie=(je||[]).map(_=>_.taste_id);let ce={};if(Ie.length>0){const{data:_}=await x.from("user_vault_taste_search").select("vault_taste_id, thumbnail_url, subtitle, domain, level_2, entity_id, taxonomy_id").in("vault_taste_id",Ie);(_||[]).forEach(y=>{ce[y.vault_taste_id]=y});try{const{isUserUploadedTastePhoto:y}=await Ge(async()=>{const{isUserUploadedTastePhoto:k}=await import("./isUserUploadedTastePhoto-BN6myZWc.js");return{isUserUploadedTastePhoto:k}},[]),V=Array.from(new Set((_||[]).filter(k=>k.domain==="place"&&k.entity_id).map(k=>Number(k.entity_id)).filter(k=>!Number.isNaN(k))));if(V.length>0){const{data:k}=await x.from("corpus_places_here_ephemeral").select("corpus_place_id, image_url").in("corpus_place_id",V),te={};(k||[]).forEach(w=>{w.image_url&&(te[String(w.corpus_place_id)]=w.image_url)});for(const w of _||[]){if(w.domain!=="place"||!w.entity_id||y(w.thumbnail_url))continue;const M=te[String(w.entity_id)];M&&(ce[w.vault_taste_id].thumbnail_url=M)}}}catch(y){console.warn("[SharedGuide] fresh place photo hydration failed:",y)}}const Ve=(je||[]).map(_=>{const y=ce[_.taste_id]||{};return{id:_.id,taste_id:_.taste_id,display_name:_.display_name,thumbnail_url:y.thumbnail_url||null,subtitle:y.subtitle||null,domain:y.domain||null,level_2:y.level_2||null,entity_id:y.entity_id||null,taxonomy_id:y.taxonomy_id??null}}),me=v!=null&&v.extra&&typeof v.extra=="object"?v.extra:null;$({id:v.id,name:v.name,owner_name:(b==null?void 0:b.first_name)||(b==null?void 0:b.username)||"Someone",owner_user_id:d.owner_user_id,items:Ve,extra:me?{cover_url:me.cover_url??null,template:me.template??null}:null})}catch(n){console.error("Error fetching shared guide:",n),S("Failed to load guide")}finally{j(!1),l.end()}})()},[o,i]),m.useEffect(()=>{if(!U)return;const r=window.setTimeout(()=>{j(l=>(l&&S("This stash took too long to load. Check your connection and try again."),!1))},15e3);return()=>window.clearTimeout(r)},[U]),m.useEffect(()=>{if(!s||!i||i===s.owner_user_id)return;const r=s.items.map(l=>l.entity_id).filter(Boolean);r.length!==0&&(async()=>{const{data:l}=await x.from("user_vault_tastes").select("entity_id").eq("user_id",i).in("entity_id",r);J(new Set((l||[]).map(n=>n.entity_id)))})()},[s,i]),m.useEffect(()=>{!s||!i||i===s.owner_user_id&&(re(!0),p(`/vault?guide=${s.id}&guideName=${encodeURIComponent(s.name)}`,{replace:!0}))},[s,i,p]);const H=r=>{wt(r);const l=St(r),n=`/shared-guide/${encodeURIComponent(r.slug)}?intent=${l}`;p(`/auth?return=${encodeURIComponent(n)}`)},A=r=>{B(r),!r.detail&&o&&(async()=>{var l;try{const{data:n,error:f}=await x.functions.invoke("shared-guide-data",{body:{slug:o}});if(f||!((l=n==null?void 0:n.guide)!=null&&l.items))return;const u=n.guide.items.find(d=>d.taste_id===r.taste_id);u!=null&&u.detail&&(B(d=>d&&d.taste_id===r.taste_id?{...d,detail:u.detail}:d),$(d=>d&&{...d,items:d.items.map(v=>v.taste_id===r.taste_id?{...v,detail:u.detail}:v)}))}catch(n){console.warn("openItemDetail: lazy detail fetch failed",n)}})()},D=async r=>{if(!i){if(!o||!r.taste_id)return;H({slug:o,action:"add-one",itemTasteId:r.taste_id});return}if(r.entity_id){R(r.taste_id);try{const{data:l,error:n}=await x.from("user_vault_tastes").insert({user_id:i,entity_id:r.entity_id,entity_type:r.domain||"media",source:"shared_guide",taxonomy_id:r.taxonomy_id??null}).select("id").single();if(n)throw n;l!=null&&l.id&&(r.display_name||r.thumbnail_url)&&await x.from("user_vault_taste_search").update({title:r.display_name||r.entity_id,thumbnail_url:r.thumbnail_url||null,level_2:r.level_2||"other",taxonomy_id:r.taxonomy_id??null}).eq("vault_taste_id",l.id),oe(f=>new Set(f).add(r.taste_id)),J(f=>new Set(f).add(r.entity_id)),g({title:"Added to Vault",description:r.display_name})}catch(l){console.error("Error adding item:",l),g({title:"Failed to add",variant:"destructive"})}finally{R(null)}}},z=r=>r.domain==="media"&&(r.level_2||"").toLowerCase()==="song",fe=!!(s!=null&&s.items.some(z)),[ie,T]=m.useState(!1),N=async()=>
1{if(!(!s||!o)){T(!0);try{const{data:{user:r}}=await x.auth.getUser();if(!r){sessionStorage.setItem("pending_guide_export","apple_shared"),sessionStorage.setItem("apple_return_to",window.location.href),p(`/auth?return=${encodeURIComponent(window.location.pathname)}`);return}const{data:l}=await x.from("oauth_connections").select("access_token").eq("user_id",r.id).eq("provider","apple").maybeSingle();if(!(l!=null&&l.access_token)){g({title:"Connecting to Apple Music",description:"You'll be redirected to authorize Apple Music access…"}),sessionStorage.setItem("pending_guide_export","apple_shared"),sessionStorage.setItem("apple_return_to",window.location.href),p("/intake-apple-music");return}const{data:n,error:f}=await x.functions.invoke("apple-create-playlist-from-share",{body:{share_slug:o,guide_id:s.id}});if(f)throw new Error(await Je(f,"Apple Music could not create this playlist. Please reconnect and try again."));const u=n==null?void 0:n.error;if(u==="not_connected"||u==="invalid_token"||u==="auth_error"){sessionStorage.setItem("pending_guide_export","apple_shared"),sessionStorage.setItem("apple_return_to",window.location.href),g({title:"Reconnect Apple Music",description:"Authorize Apple Music to finish this export."}),p("/intake-apple-music");return}if(u)throw new Error(n.message||u);const d=(n==null?void 0:n.tracks_added)||0,v=(n==null?void 0:n.tracks_unresolved)||0;g({title:"Playlist created in Apple Music",description:v>0?`Added ${d} tracks · ${v} not found in Apple Music.`:`Added ${d} tracks.`})}catch(r){console.error("[SharedGuide] Apple export error:",r),g({title:"Export failed",description:(r==null?void 0:r.message)||"Unknown error",variant:"destructive"})}finally{T(!1)}}},Y=m.useRef(!1);m.useEffect(()=>{Y.current||!s||!o||sessionStorage.getItem("pending_guide_export")==="apple_shared"&&(Y.current=!0,sessionStorage.removeItem("pending_guide_export"),sessionStorage.removeItem("apple_return_to"),N())},[s,o]);const K=async()=>{if(!i){if(!o)return;H({slug:o,action:"import-all"});return}if(s){P(!0);try{const r=s.items.map(b=>b.taste_id),{data:l}=await x.from("user_vault_taste_search").select("vault_taste_id, entity_id, domain, level_1, level_2, level_3, title, subtitle, thumbnail_url").in("vault_taste_id",r);if(!l||l.length===0){g({title:"No items to import",description:"Could not find item details to import",variant:"destructive"});return}const n=l.map(b=>b.entity_id),{data:f}=await x.from("user_vault_tastes").select("entity_id").eq("user_id",i).in("entity_id",n),u=new Set((f||[]).map(b=>b.entity_id)),d=l.filter(b=>!u.has(b.entity_id));if(d.length===0){g({title:"Already in Vault",description:"All items from this guide are already in your Vault"});return}const v=d.map(b=>({user_id:i,entity_id:b.entity_id,entity_type:b.domain||"media",source:"shared_guide",taxonomy_id:b.taxonomy_id??null})),{error:ee}=await x.from("user_vault_tastes").insert(v);if(ee)throw ee;g({title:"Imported to Vault",description:`Added ${d.length} item${d.length===1?"":"s"} to your Vault`})}catch(r){console.error("Error importing to vault:",r),g({title:"Import failed",description:"Failed to import items to your Vault",variant:"destructive"})}finally{P(!1)}}},Z=m.useRef(!1);if(m.useEffect(()=>{if(!i||!s||!o||C||i===s.owner_user_id||Z.current)return;const r=`fyra:intentConsumed:${o}`;try{if(sessionStorage.getItem(r)==="1")return}catch{}const l=new URLSearchParams(c.search),n=l.get("intent"),f=It(o,n);if(f){Z.current=!0;try{sessionStorage.setItem(r,"1")}catch{}if(vt(),n){l.delete("intent");const u=l.toString();p(`${c.pathname}${u?`?${u}`:""}`,{replace:!0})}if(f.action==="import-all"){K();return}if(f.action==="add-one"&&f.itemTasteId){const u=s.items.find(d=>d.taste_id===f.itemTasteId);u&&D(u)}}},[i,s,o,C,c.search]),U)return e.jsx("div",{className:"min-h-screen bg-background p-4",children:e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsxs("p",{className:"mb-4 flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(W,{className:"h-4 w-4 animate-spin"}),"Opening stash…"]}),e.jsx(ue,{className:"h-8 w-32 mb-4"}),e.jsx(ue,{className:"h-6 w-48 mb-6"}),e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(r=>e.jsx(ue,{className:"h-16 w-full"},r))})]})});if(C)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(W,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{children:"Opening your stash..."})]})});if(a||!s)return e.jsxs("div",{className:"min-h-screen bg-background flex flex-col items-center justify-center p-4",children:[e.jsx(Le,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Can't open this 
1stash"}),e.jsx("p",{className:"text-muted-foreground mb-4 text-center max-w-sm",children:a||"This Stash doesn't exist or isn't publicly shared"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(F,{onClick:()=>window.location.reload(),children:"Try again"}),e.jsx(F,{variant:"outline",onClick:()=>p("/"),children:"Go home"})]})]});const t=gt(s.extra??null),h=Ce(t),le=yt(t);h.fontPair.heading;const de=pe(h.themeTokens.heroToHsl,h.themeTokens.foregroundHsl),X=pe(h.themeTokens.boxHsl,h.themeTokens.foregroundHsl),_e=pe(h.themeTokens.accentHsl,de),Ee=((ge=s.extra)==null?void 0:ge.cover_url)||null,Pe=((xe=(ye=t==null?void 0:t.hero)==null?void 0:ye.title)==null?void 0:xe.trim())||s.name;(we=(be=t==null?void 0:t.hero)==null?void 0:be.subtitle)!=null&&we.trim();const $e=((Se=(ve=t==null?void 0:t.hero)==null?void 0:ve.intro)==null?void 0:Se.trim())||null,Ue=G(t,"cover");G(t,"title"),G(t,"subtitle"),G(t,"intro"),G(t,"curator"),G(t,"primary_cta");const Re=Ae(t);return[s.owner_name,...(s.collaborator_names||[]).filter(Boolean)],(s.access_tier||"").toLowerCase(),e.jsxs("div",{className:"min-h-screen",style:{...le,backgroundColor:`hsl(${h.themeTokens.heroToHsl})`,color:`hsl(${de})`},"data-stash-template":h.key,children:[e.jsx("main",{className:"p-4 pb-24",children:e.jsxs("div",{className:"mx-auto max-w-2xl space-y-4",children:[s.gifted_note&&e.jsxs("div",{className:"rounded-xl px-4 py-3 border shadow-sm",style:{backgroundColor:`hsl(${h.themeTokens.boxHsl})`,color:`hsl(${X})`,borderColor:`hsl(${X} / 0.18)`},children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wider font-semibold mb-1",style:{color:`hsl(${X})`,fontFamily:h.fontPair.body},children:s.gifted_to_name?`A note for ${s.gifted_to_name}`:"A note for you"}),e.jsxs("p",{className:"text-sm leading-relaxed italic",style:{color:`hsl(${X} / 0.92)`},children:['"',s.gifted_note,'"']}),e.jsxs("p",{className:"text-xs mt-2",style:{color:`hsl(${X} / 0.70)`},children:["— ",s.owner_name]})]}),e.jsx(kt,{guideId:s.id,title:Pe,description:$e||s.description||null,coverUrl:Ue?Ee:null,ownerName:s.owner_name,ownerAvatarUrl:s.owner_avatar_url??null,coAuthors:(s.collaborators||[]).map(r=>({id:r.id,name:r.name,avatar_url:r.avatar_url??null})),templateConfig:t,widgets:s.widgets||[],sections:s.sections||[],items:s.items,userId:i,comments:s.comments,onOpenItem:r=>{const l=s.items.find(n=>n.taste_id===r);l&&A(l)}}),e.jsxs("div",{className:"space-y-2",children:[fe&&e.jsxs(e.Fragment,{children:[e.jsxs(F,{className:"w-full h-12 rounded-full font-semibold shadow-md gap-2",style:{backgroundColor:`hsl(${h.themeTokens.accentHsl})`,color:`hsl(${_e})`,fontFamily:h.fontPair.body},onClick:N,disabled:ie,children:[ie?e.jsx(W,{className:"h-4 w-4 animate-spin"}):e.jsx(xt,{className:"h-4 w-4"}),"Export to Apple Music"]}),e.jsx("p",{className:"text-xs text-center",style:{color:`hsl(${de} / 0.7)`},children:"Other streaming platforms coming soon"})]}),i&&i!==s.owner_user_id&&e.jsxs(F,{className:"w-full h-12 rounded-full font-semibold shadow-md",style:{backgroundColor:`hsl(${h.themeTokens.accentHsl})`,color:`hsl(${_e})`,fontFamily:h.fontPair.body},onClick:K,disabled:O,children:[O?e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}):null,Re," — import to my vault"]}),!i&&e.jsxs("button",{type:"button",onClick:()=>{if(!o)return;const r=`/shared-guide/${encodeURIComponent(o)}`;p(`/auth?return=${encodeURIComponent(r)}`)},className:"w-full text-left rounded-lg border border-primary/30 bg-primary/5 hover:bg-primary/10 transition-colors px-4 py-3",children:[e.jsx("p",{className:"text-sm font-medium text-primary",children:"Join Fyra to save these to your own vault"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Browse the whole stash freely — an account only adds one-tap saving and your own recommendations."})]})]})]})}),e.jsx(Nt,{open:!!I,onOpenChange:r=>{r||B(null)},item:I?{...I,subtitle:I.subtitle??null}:null,isAlreadyInVault:!!I&&(Q.has(I.entity_id||"")||se.has(I.taste_id)),isAdding:!!I&&ae===I.taste_id,onAdd:()=>I&&D(I)}),i&&i!==s.owner_user_id&&e.jsx(ft,{open:ne,onOpenChange:q,guideId:s.id,guideName:s.name,ownerName:s.owner_name})]})};export{Uo 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.