1import{j as _}from"./vendor-tanstack-_NmhRw_9.js";import{j as O,g as R,r as d,u as M}from"./vendor-react-CrIuOpVI.js";import{u as V,g as q,S as z,a as B}from"./useImportPearlCount-CCW7EXAu.js";import{A as U}from"./AnonSignInPromptModal-Fa_n_16a.js";import{w as W,y as Y,s as D}from"./index-DjaHTvW6.js";import{u as J,A as G,a as H,S as Z,L as K}from"./useClaimSharedPearl-BVZnKbbD.js";import"./useCaptcha-DBzc44n1.js";import"./landingPieces-OIgj6RMN.js";import"./index-udQ19Zbk.js";import"./lightbulb-fuB61zGE.js";import"./V11VideoBeatShare-hy9fES2w.js";import"./VideoOverlay-DjXbjl7A.js";import"./AILaunchMenuShare-CquwM4D4.js";import"./floating-ui.react-BEBq48GU.js";import"./ProviderWordmark-BToUHPFp.js";import"./PearlFlowDiagram-BWWgk0eT.js";import"./ConnectedAIsCard-B731VxYj.js";import"./Badge-SSRc3KDM.js";import"./LoginCard-DhDvcv61.js";const Q="https://db.wisdomrecall.com";function x(r){return r?r.trim().split(/\s+/)[0]||r:null}function X(r,n){const h=new Date().toISOString();return{id:r.original_id??n,owner_id:"",version:r.version??1,original_pearl_id:r.original_pearl_id??null,is_current:!0,label:r.label,pearl_type:r.pearl_type??"reference",content:r.content,priority:r.priority??3,source_context:r.source_context??null,summary:r.summary??null,synopsis:r.synopsis??null,tags:r.tags??[],deletion_status:"none",deletion_requested_at:null,access_count:0,last_accessed_at:null,created_at:r.created_at??h,updated_at:r.updated_at??r.created_at??h,content_updated_at:r.content_updated_at??r.updated_at??r.created_at??h,source_exchange_log_id:null,channel:null,project_ids:[],template_id:null}}function ee(r){return{name:(r==null?void 0:r.name)??"",description:(r==null?void 0:r.description)??null,pearl_titles:Array.isArray(r==null?void 0:r.pearls)?r.pearls.map(n=>n==null?void 0:n.label).filter(n=>!!n):[]}}function re(r){if(!r)return null;const n=r.match(/^(.+)-([A-Za-z0-9_-]{8})$/);return n?{short_id:n[2]}:r.length===16?{token:r}:null}function Se(){const r=O(),n=r.slug??r.token,h=re(n),k=n,[N]=R(),I=N.get("claimed")==="1",[e,a]=d.useState({status:"loading"}),[w,S]=d.useState(!1),[c,b]=d.useState("unknown"),j=M(),{addToast:y}=W(),C=J(),T=d.useRef(!1),{tier:P}=Y(),g=V();d.useEffect(()=>{const s=document.querySelector('meta[name="robots"]'),i=(s==null?void 0:s.getAttribute("content"))??null,u=s??(()=>{const l=document.createElement("meta");return l.setAttribute("name","robots"),document.head.appendChild(l),l})();return u.setAttribute("content","noindex, nofollow"),()=>{i!=null?u.setAttribute("content",i):u.remove()}},[]),d.useEffect(()=>{let s=!1;return(async()=>{try{const{data:i}=await D.auth.getSession();if(s)return;b(i.session?"yes":"no")}catch{if(s)return;b("no")}})(),()=>{s=!0}},[]),d.useEffect(()=>{if(!h){a({status:"error",message:"This share link is malformed."});return}let s=!1;return(async()=>{var i,u;try{const l=q(),{data:{session:p}}=await D.auth.getSession(),m={"Content-Type":"application/json"};p!=null&&p.access_token&&(m.Authorization=`Bearer ${p.access_token}`);const o=await fetch(`${Q}/functions/v1/resolve-share`,{method:"POST",headers:m,body:JSON.stringify({...h,anon_session_token:l})});if(s)return;if(o.status===404){a({status:"error",message:"This share link doesn't exist or has been removed."});return}if(o.status===410){a({status:"error",message:"This share link has expired or been revoked."});return}if(o.status===429){a({status:"error",message:"Too many requests. Please try again in a moment."});return}if(!o.ok){a({status:"error",message:"Failed to load share link."});return}const t=await o.json();if(s)return;if(t.resource_type==="pearl"){if(!t.snapshot_data||!t.resource_id||!t.share_link_id){a({status:"error",message:"This share link could not be loaded. Try opening it in a fresh browser."});return}a({status:"first_visit",resource_type:"pearl",pearl:X(t.snapshot_data,t.resource_id),sharerDisplayName:x((i=t.inviter)==null?void 0:i.display_name),shareLinkId:t.share_link_id,resourceId:t.resource_id,snapshot:t.snapshot_data});return}if(t.resource_type==="project"){if(!t.resource_id||!t.share_link_id){a({status:"error",message:"This share link could not be loaded. Try opening it in a fresh browser."});return}const f=t.teaser?t.teaser:t.snapshot_data?ee(t.snapshot_data):null;if(!f){a({status:"error",message:"This share link could not be loaded. Try opening it in a fresh browser."});return}a({status:"first_visit",resource_type:"project",teaser:f,snapshot:t.snapshot_data??null,sharerDisplayName:x((u=t.inviter)==null?void 0:u.display_name),shareLinkId:t.share_link_id,resourceId:t.resource_id});return}a({status:"wrong_type"})}catch{if(s)return;a({status:"error",message:"Failed to load share link."})}})(),()=>{s=!0}},[k]);function v(s){if(T.current)return;T.current=!0;const{sharerDisplayName:i,shareLinkId:u,resourceId:l,snapshot:p,resourceType:m}=s,o=m==="project"?"Strand":"Pearl";a(m==="pearl"?{status:"claiming",resource_type:"pearl",pearl:s.pearl,sharerDisplayName:i}:{status:"claiming",resource_type:"project",teaser:s.teaser,sharerDisplayName:i}),C.mutate({shareLinkId:u,snapshot:p,resourceId:l,resourceType:m},{onSuccess:t=>{const f=m==="project"?`/strands/${t.newPearlId}`:`/pearl/${t.newPearlId}`;j(f,{replace:!0,state:{sharerDisplayName:i}})},onError:t=>{if(t instanceof G){const f=t.resourceType==="project"?`/strands/${t.existingId}?claimed=1`:`/pearl/${t.existingId}`;y(t.resourceType==="project"?"You already have this Strand in your library.":"You already have this Pearl in y
1our library.","success"),j(f,{replace:!0});return}if(t instanceof H){b("unknown"),T.current=!1,s.resourceType==="pearl"?a({status:"first_visit",resource_type:"pearl",pearl:s.pearl,sharerDisplayName:i,shareLinkId:u,resourceId:l,snapshot:p}):a({status:"first_visit",resource_type:"project",teaser:s.teaser,sharerDisplayName:i,shareLinkId:u,resourceId:l,snapshot:p}),S(!0),y(`Please sign in again to save this ${o}.`,"error");return}if(t instanceof Z){y("This share link is missing data needed to save it.","error"),a({status:"error",message:"This share link is missing data needed to save it. Try opening the original link again."});return}if(t instanceof K){y(`Could not save ${o} due to a label conflict.`,"error"),a({status:"error",message:`We could not save this ${o} because a label conflict could not be resolved.`});return}y((t==null?void 0:t.message)??`Failed to save ${o}.`,"error"),a({status:"error",message:(t==null?void 0:t.message)??`Failed to save ${o}.`})}})}d.useEffect(()=>{I&&c==="yes"&&e.status==="first_visit"&&(e.resource_type==="project"&&!e.snapshot||(e.resource_type==="project"?v({resourceType:"project",teaser:e.teaser,sharerDisplayName:e.sharerDisplayName,shareLinkId:e.shareLinkId,resourceId:e.resourceId,snapshot:e.snapshot}):v({resourceType:"pearl",pearl:e.pearl,sharerDisplayName:e.sharerDisplayName,shareLinkId:e.shareLinkId,resourceId:e.resourceId,snapshot:e.snapshot})))},[I,c,e.status]);function L(){if(c==="yes"&&e.status==="first_visit"){if(e.resource_type==="project"){e.snapshot&&v({resourceType:"project",teaser:e.teaser,sharerDisplayName:e.sharerDisplayName,shareLinkId:e.shareLinkId,resourceId:e.resourceId,snapshot:e.snapshot});return}v({resourceType:"pearl",pearl:e.pearl,sharerDisplayName:e.sharerDisplayName,shareLinkId:e.shareLinkId,resourceId:e.resourceId,snapshot:e.snapshot});return}if(k)try{localStorage.setItem("auth_return_to",`/share/${k}`)}catch{}S(!0)}if(e.status==="gate")return _.jsx(z,{returnTo:`/share/${k}`});const A=e.status==="first_visit"||e.status==="claiming"?e.sharerDisplayName:null,$=e.status==="first_visit"&&c==="unknown",E=e.status==="loading"||I&&c!=="no"||$?{status:"loading"}:e.status==="claiming"?{status:"claiming"}:e.status==="wrong_type"?{status:"error",message:"This share link is for a different content type. Visit the original link to view."}:e.status==="error"?{status:"error",message:e.message}:e.status==="first_visit"?e.resource_type==="project"?c==="yes"&&e.snapshot?{status:"full",resource_type:"project",snapshot_data:e.snapshot,resource_id:e.resourceId,share_link_id:e.shareLinkId}:{status:"teaser",resource_type:"project",teaser:e.teaser}:c==="yes"?{status:"full",resource_type:"pearl",snapshot_data:e.snapshot,resource_id:e.resourceId,share_link_id:e.shareLinkId}:{status:"teaser",resource_type:"pearl",teaser:{title:e.pearl.label,pearl_type:e.pearl.pearl_type,preview:e.pearl.content??"",summary:e.pearl.summary??void 0,synopsis:e.pearl.synopsis??void 0}}:{status:"loading"},F=P==="free_reader"&&c==="yes"&&g.count!==null&&g.count>0&&!g.loading?_.jsxs("div",{role:"status","aria-live":"polite",style:{display:"inline-flex",alignItems:"center",gap:6,padding:"5px 10px",borderRadius:20,fontSize:"0.75rem",fontWeight:500,marginBottom:12,background:"rgba(14, 116, 144, 0.08)",border:"1px solid rgba(14, 116, 144, 0.20)",color:"#0e7490",fontFamily:"'Plus Jakarta Sans', sans-serif"},children:["You've imported ",g.count," pearl",g.count===1?"":"s"," on the Free plan",_.jsx("a",{href:"/billing/checkout?plan=personal_single_monthly",style:{marginLeft:4,textDecoration:"underline",fontWeight:600,color:"inherit"},onClick:s=>{s.stopPropagation()},children:"Upgrade for unlimited imports"})]}):null;return _.jsxs("div",{className:"share-dev-wrap",children:[_.jsx(B,{state:E,sharerDisplayName:A,onClaim:L,importCountChip:F,devMode:!0,devVariant:2}),w&&e.status==="first_visit"&&_.jsx(U,{sharerDisplayName:e.sharerDisplayName,pearlType:e.resource_type==="pearl"?e.pearl.pearl_type:void 0,onDismiss:()=>S(!1)})]})}export{Se 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.