PageSourceSearch

https://fyra.life/assets/ClawTest-CpBi5c2U.js

js fyra.life collected 2026-10-02 02:00:20 UTC 43,860 bytes, 2 lines download raw bytes

1import{s as v,V as Tt,u as Rt,b as zt,r as g,W as Lt,Y as Ft,j as e,B as L,X as je,Z as Fe,N as Vt}from"./index-CEISlULX.js";import{safeInsertVaultTaste as At}from"./safeVaultInsert-DUrA829o.js";import{r as $t}from"./resolveDefaultShareVisibility-By_IKKys.js";import{C as Bt}from"./ConfirmDeleteDialog-DmP6G5fs.js";import{C as Wt}from"./checkbox-CEKeZsY9.js";import{d as Dt}from"./supabaseDirect-DK9s24Tr.js";import{r as Ot}from"./resolveBookCoverClient-erhY9SZd.js";import{u as Pt}from"./use-mobile-acVmXoix.js";import{L as J}from"./loader-circle-C0qiwHXp.js";import{A as qt}from"./arrow-left-Dt5WA4Nk.js";import{C as Gt}from"./chevron-down-CVkqx0vb.js";import{T as Mt}from"./tv-C88hoGGy.js";import{B as Ut}from"./book-open-CJtqdthI.js";import{W as Ht}from"./wine-Cbzkns94.js";import{F as Yt}from"./film-kc4h8MJx.js";import"./alert-dialog-0IVFOTPn.js";import"./index-CKv5A6hs.js";import"./index-yCNHGKsJ.js";import"./index-CzOLp-Ui.js";import"./check-BFjtj0TV.js";const ct=new Set(["vineyard","vineyards","winery","wineries","estate","estates","cellar","cellars","wine","wines","family","company","co","the","winegrowers","vintners"]),Xt=[[/\bsauv\.?\s*bl\.?\b/g,"sauvignon blanc"],[/\bsauv\b/g,"sauvignon"],[/\bcab\.?\s*sauv\.?\b/g,"cabernet sauvignon"],[/\bcab\b/g,"cabernet"],[/\bchard\b/g,"chardonnay"],[/\bzin\b/g,"zinfandel"],[/\bpinot\s+grigio\b/g,"pinot grigio"],[/\bst\.?\b/g,"saint"],[/\bmt\.?\b/g,"mount"]];function pe(s){return String(s||"").toLowerCase().normalize("NFKD").replace(/[\u0300-\u036f]/g,"").replace(/[’'`]/g,"").replace(/[^a-z0-9.\s]/g," ").replace(/\s+/g," ").trim()}function Ne(s){let a=s;for(const[f,h]of Xt)a=a.replace(f,h);return a.replace(/\./g," ").replace(/\s+/g," ").trim()}function he(s){return Ne(pe(s)).split(" ").filter(a=>a&&!ct.has(a)).join(" ")}function Ve(s){const a=Ne(pe(s));return a==="na"||a==="n a"?"":a}function Ae(s,a){const f=String(a??"").match(/\b(19|20)\d{2}\b/);if(f)return f[0];const h=s.match(/\b(19|20)\d{2}\b/);return h?h[0]:null}const Kt=/\b(chardonnay|sauvignon blanc|riesling|pinot grigio|pinot gris|viognier|chenin blanc|gewurztraminer|albarino|gruner|semillon|moscato|muscat|verdejo|vermentino|marsanne|roussanne|torrontes|fiano|white)\b/,Qt=/\b(cabernet sauvignon|cabernet franc|cabernet|merlot|pinot noir|syrah|shiraz|zinfandel|malbec|grenache|garnacha|tempranillo|sangiovese|nebbiolo|petite sirah|petit verdot|carmenere|mourvedre|barbera|gamay|red|rosso|tinto)\b/,dt=/\b(rose|rosado|rosato)\b/;function Jt(s){const a=pe(s);return a?dt.test(a)?"rose":/\bwhite\b|\bblanc\b/.test(a)?"white":/\bred\b/.test(a)?"red":/\bsparkling\b/.test(a)?"sparkling":null:null}function nt(s,a){const f=Jt(a);if(f)return f;const h=Ne(pe(s));if(dt.test(h))return"rose";const d=Kt.test(h),u=Qt.test(h);return d&&!u?"white":u&&!d?"red":null}const Zt=/^(\d+(ml|l|cl|m)?|ml|cl|bottle|magnum)$/;function st(s){const a=new Set(he(s.winery).split(" ").filter(Boolean)),f=new Set(Ve(s.region).split(" ").filter(Boolean)),h=Ne(pe(s.name)).split(" ").filter(Boolean).filter(d=>!a.has(d)&&!ct.has(d)).filter(d=>!f.has(d)).filter(d=>!/^(19|20)\d{2}$/.test(d)).filter(d=>!Zt.test(d));return new Set(h)}function en(s,a){if(s.size===0||s.size!==a.size)return!1;for(const f of s)if(!a.has(f))return!1;return!0}function ut(s,a){const f=he(s.winery),h=he(a.winery);if(!f||f!==h)return!1;const d=Ve(s.region),u=Ve(a.region);if(d!==u||!en(st(s),st(a)))return!1;const w=nt(s.name,s.color),j=nt(a.name,a.color);if(!w||!j||w!==j)return!1;const _=Ae(s.name,s.vintage),y=Ae(a.name,a.vintage);return _&&y?_===y:!0}function tn(s,a,f){const h=a.filter(d=>ut(s,f(d)));return h.length===1?h[0]:null}function at(s){return Ae(s.name,s.vintage)}function nn(s,a,f){const h=at(s),d=a.filter(u=>{const w=f(u),j=at(w);return(h?j:!j)?!1:ut(s,w)});return d.length!==1?null:{kind:h?"upgrade":"existing",candidate:d[0]}}const it=49;async function mt(s){var xe,C,ne,ce;const{userId:a,clawItemId:f,title:h,config:d}=s,u=s.facts,w=h.trim();if(!w)throw new Error("Wine has no name");const j=((xe=u.winery)==null?void 0:xe.trim())||null,_=((C=d.keyValue)==null?void 0:C.trim())||null;let y=null,Z=!1;if(_){const{data:x}=await v.from("corpus_products").select("id").eq(`external_ids->>${d.keyField}`,_).limit(1).maybeSingle();(x==null?void 0:x.id)!=null&&(y=String(x.id))}if(!y){let x=v.from("corpus_products").select("id").ilike("display_name",w);x=j?x.ilike("brand_name",j):x.is("brand_name",null);const{data:T}=await x.limit(1).maybeSingle();(T==null?void 0:T.id)!=null&&(y=String(T.id),Z=!0)}if(!y&&j){const x=he(j).split(" ")[0];if(x&&x.length>=3){const{data:T}=await v.from("corpus_products").select("id, display_name, brand_name, level_3, external_ids").eq("level_2","Wine").ilike("brand_name",`%${x}%`).limit(50),G={name:w,winery:j,region:u.region??null,color:u.color??u.style??null,vintage:u.vintage??null},B=tn(G,T??[],P=>{var Y,R,z;return{name:String(P.display_name||""),winery:P.brand_name,region:((Y=P.external_ids)==null?void 0:Y.region)??null,color:((R=P.external_ids)==null?void 0:R.color)??((z=P.external_ids)==null?void 0:z.style)??P.level_3??null}});(B==null?void 0:B.id)!=null&&(y=String(B.id),Z=!0)}}if(!y){const{data:x,error:T}=await v.from("corpus_products").insert({display_name:w,brand_name:j,level_2:"Wine",level_3:((ne=u.style)==null?void 0:ne.trim())||null,external_ids:d.createExternalIds,date_added:new Date().toISOString()}).select("id").single();if(T||!x)throw new Error("Couldn't add wine to catalog: "+((T==null?void 0:T.message)||"no data"));y=String(x.id)}let X=null;if(j)try{const x=he(j).split(" ")[0];if(x&&x.length>=3){const{data:T}=await v.from("user_vault_taste_search").select("vault_taste_id, entity_id").eq("user_id",a).eq("domain","product").eq("level_2","Wine").ilike("subtitle",`%${x}%`).limit(50),G=(T??[]).map(B=>
1String(B.entity_id)).filter(B=>/^\d+$/.test(B)&&B!==y);if(G.length){const{data:B}=await v.from("corpus_products").select("id, display_name, brand_name, level_3, external_ids").in("id",G.map(Number)),P=new Map((B??[]).map(z=>[String(z.id),z])),Y=(T??[]).filter(z=>P.has(String(z.entity_id))),R=nn({name:w,winery:j,region:u.region??null,color:u.color??u.style??null,vintage:u.vintage??null},Y,z=>{var K,we,de;const E=P.get(String(z.entity_id));return{name:String(E.display_name||""),winery:E.brand_name,region:((K=E.external_ids)==null?void 0:K.region)??null,color:((we=E.external_ids)==null?void 0:we.color)??((de=E.external_ids)==null?void 0:de.style)??E.level_3??null}});if((R==null?void 0:R.kind)==="existing"&&(X=String(R.candidate.vault_taste_id)),(R==null?void 0:R.kind)==="upgrade"){const z=String(R.candidate.vault_taste_id),{data:E,error:K}=await v.functions.invoke("wine-vault-upgrade",{body:{vault_taste_id:z,corpus_id:Number(y)}});!K&&(E!=null&&E.upgraded)?X=z:!K&&(E!=null&&E.existing_vault_taste_id)&&(X=String(E.existing_vault_taste_id))}}}}catch(x){console.warn(d.logTag,x)}let $;if(X)$={vaultTasteId:X};else{const x=await $t(a);$=await At({userId:a,entityType:"product",entityId:y,row:{user_id:a,entity_type:"product",entity_id:y,taxonomy_id:it,source:d.source,share_visibility:x}})}if($.error||!$.vaultTasteId)throw $.error instanceof Error?$.error:new Error(((ce=$.error)==null?void 0:ce.message)||"Couldn't save wine to vault");const{data:N,error:ve}=await v.from("claw_items").update({entity_id:y,match_confidence:"exact",saved_vault_taste_id:$.vaultTasteId}).eq("user_id",a).eq("id",f).select("id");if(ve)throw new Error("Saved to vault, but couldn't update the import row: "+ve.message);if(!N||N.length===0)throw new Error("Saved to vault, but the import row wasn't updated");const H=new Date().toISOString();try{Tt(a,{vault_taste_id:$.vaultTasteId,entity_id:y,domain:"product",level_1:"Beverages",level_2:"Wine",level_3:null,title:w,subtitle:j,thumbnail_url:null,search_text:[w,j].filter(Boolean).join(" ").toLowerCase(),website:null,food_tags:null,taxonomy_id:it,created_at:H,updated_at:H})}catch{}try{window.dispatchEvent(new CustomEvent("vault-rows-changed",{detail:{source:d.eventSource,vault_taste_id:$.vaultTasteId}}))}catch{}return Z&&d.linkStamp&&v.functions.invoke("vivino-link-stamp",{body:{corpus_id:Number(y),...d.linkStamp}}).catch(x=>console.warn("[vivino-link-stamp]",x)),{vaultTasteId:$.vaultTasteId,corpusId:y,created:!X}}async function sn(s){var u;const a=s.signals??{},f=((u=a.vivino_key)==null?void 0:u.trim())||null,h=a.vivino_stats??{},d=await mt({userId:s.userId,clawItemId:s.clawItemId,title:s.title,facts:a,config:{keyField:"vivino_key",keyValue:f,createExternalIds:{vivino_key:f,vivino_url:a.vivino_url??null,region:a.region??null,country:a.country??null,style:a.style??null,color:a.color??null,vivino_stats:{ratings_count:h.ratings_count??null,community_rating:h.community_rating??null,avg_price_usd:h.avg_price_usd??null,as_of:h.as_of??null}},source:"vivino_import",eventSource:"vivino-import",logTag:"[vivino vintage rule]",linkStamp:a.vivino_url||f?{vivino_url:a.vivino_url??null,vivino_key:f}:null}});return{vaultTasteId:d.vaultTasteId,corpusId:d.corpusId}}const an={love:2,like:1,neutral:0,dislike:-1,hate:-2};async function ft(s,a,f){const h=f==="interested"?{vault_taste_id:s,user_id:a,experienced_state:"not_tried",rating_value:null,interest_value:1}:{vault_taste_id:s,user_id:a,experienced_state:"tried",rating_value:an[f],interest_value:null};let d=null;for(let u=0;u<2;u++){const{error:w}=await v.from("user_taste_ratings").upsert(h,{onConflict:"vault_taste_id,user_id"});if(d=w,!w)break;u===0&&await new Promise(j=>setTimeout(j,500))}if(d)throw d}async function rn(s){var w;const a=s.signals??{},f=((w=a.cellartracker_iwine)==null?void 0:w.trim())||null,h=await mt({userId:s.userId,clawItemId:s.clawItemId,title:s.title,facts:{winery:a.winery,vintage:a.vintage,color:a.color,region:a.region},config:{keyField:"cellartracker_iwine",keyValue:f,createExternalIds:{cellartracker_iwine:f,cellartracker_url:a.cellartracker_url??null,region:a.region??null,country:a.country??null,color:a.color??null,varietal:a.varietal??null},source:"cellartracker_import",eventSource:"cellartracker-import",logTag:"[cellartracker vintage rule]",linkStamp:f?{cellartracker_iwine:f,cellartracker_url:a.cellartracker_url??null}:null}}),d=s.suggestedRating,u=a.ct_status==="tried"?["love","like","neutral","dislike"]:a.ct_status==="interested"?["interested"]:[];return h.created&&d&&u.includes(d)&&await ft(h.vaultTasteId,s.userId,d),{vaultTasteId:h.vaultTasteId,corpusId:h.corpusId}}const ln=new Set(["55P03","57014","40P01"]),on=8e3;async function cn(s){const a=async(f=3)=>{let h=null;for(let d=1;d<=f;d++){const{error:u}=await v.from("user_vault_tastes").delete().eq("id",s);if(!u)return;h=u;const w=String((u==null?void 0:u.code)||"");if(!(d<f&&ln.has(w)))break;await new Promise(_=>setTimeout(_,250*d))}if(h)throw h};return new Promise((f,h)=>{let d=!1;const u=setTimeout(()=>{d||(d=!0,f("timeout"))},on);a().then(()=>{d||(d=!0,clearTimeout(u),f("deleted"))},w=>{d||(d=!0,clearTimeout(u),h(w))})})}const rt={love:"Love",like:"Like",neutral:"Neutral",dislike:"Dislike",hate:"Hate",interested:"Interested"},lt=s=>s==="show"?Mt:s==="book"?Ut:s==="wine"?Ht:Yt,dn=({className:s})=>e.jsx("svg",{viewBox:"0 0 132 30",className:s,role:"img","aria-label":"Netflix",style:{overflow:"visible"},children:e.jsx("text",{x:"0",y:"24",fill:"#E50914",fontFamily:"'Arial Black', 'Helvetica Neue', Arial, sans-serif",fontSize:"26",fontWeight:"900",letterSpacing:"-1",children:"NETFLIX"})}),un=({className:s})=>e.jsx("svg",{viewBox:"0 0 132 26",className:s,role:"img","aria-label":"Goodreads",style:{overflow:"visible"},children:e.jsx("text",{x:"0",y:"20",fill:"#382110",fontFamily:"'Georgia', 'Times New Roman', serif",fontSize:"22",fontWeight:"700",letterSpacing:"-0.5",children:"goodreads"})}),mn=({className:s})=>e.jsxs("svg",{viewBox:"0 0 100 34",className:s,role:"img","aria-label":"Amazon",style:{overflow:"visible"},children:[e.jsx("text",{x:"0",y:"20",fill:"#131A22",fontFamily:"'Helvetica Neue', Arial, sans-serif",fontSize:"24",fontWeight:"700",letterSpacing:"-1",children:"amazon"}),e.jsx("path",{d:"M6 26 Q 38 36 70 25",stroke:"#FF9900",strokeWidth:"2.5",fill:"none",strokeLinecap:"round"})]}),fn=({className:s})=>e.jsxs("svg",{viewBox:"0 0 132 26",className:s,role:"img","aria-label":"Letterboxd",style:{overflow:"visible"},children:[e.jsx("circle",{cx:"7",cy:"13",r:"6",fill:"#FF8000"}),e.jsx("circle",{cx:"18",cy:"13",r:"6",fill:"#00E054",fillOpacity:"0.9"}),e.jsx("circle",{cx:"29",cy:"13",r:"6",fill:"#40BCF4",fillOpacity:"0.9"}),e.jsx("text",{x:"40",y:"19",fill:"#202830",fontFamily:"'Helvetica Neue', Arial, sans-serif",fontSize:"17",fontWeight:"700",letterSpacing:"-0.3",children:"Letterboxd"})]}),gn=({className:s})=>e.jsx("svg",{viewBox:"0 0 132 26",className:s,role:"img","aria-label":"StoryGraph",style:{overflow:"visible"},children:e.jsx("text",{x:"0",y:"19",fill:"#0E7C86",fontFamily:"'Helvetica Neue', Arial, sans-serif",fontSize:"17",fontWeight:"700",letterSpacing:"-0.3",children:"StoryGraph"})}),hn=({className:s})=>e.jsx("svg",{viewBox:"0 0 132 26",className:s,role:"img","aria-label":"Vivino",style:{overflow:"visible"},children:e.jsx("text",{x:"0",y:"19",fill:"#A8172B",fontFamily:"'Helvetica Neue', Arial, sans-serif",fontSize:"17",fontWeight:"700",letterSpacing:"-0.3",children:"Vivino"})}),pn=({className:s})=>e.jsx("svg",{viewBox:"0 0 132 26",className:s,role:"img","aria-label":"CellarTracker",style:{overflow:"visible"},children:e.jsx("text",{x:"0",y:"19",fill:"#7B1E2B",fontFamily:"Georgia, serif",fontSize:"16",fontWeight:"700",children:"CellarTracker"})}),gt="claw-csv-netflix",ht="claw-csv-goodreads",vn="claw-csv-letterboxd",pt="claw-csv-vivino",vt="claw-csv-cellartracker",xn=gt,ot=s=>s===ht?"Goodreads":s===vn?"Letterboxd":s==="claw-csv-storygraph"?"StoryGraph":s===pt?"Vivino":s===vt?"CellarTracker":"Netflix",le=1e3,wn=!1,_n=[{key:"netflix",Logo:dn,
1connectClawId:gt,steps:[{text:"In a web browser, open your Netflix viewing activity and sign in.",link:{label:"netflix.com/viewingactivity",href:"https://www.netflix.com/viewingactivity"}},{text:"Choose the profile you want from the profile menu. The file covers one profile at a time."},{text:"Scroll to the very bottom of the page and tap “Download all”. The file saves right away."},{text:"Come back here and upload the CSV, or if on iPhone, click share and save to Fyra."}]},{key:"letterboxd",Logo:fn,steps:[{text:"In a web browser (not the app), sign in to Letterboxd.",link:{label:"letterboxd.com",href:"https://letterboxd.com/sign-in/"}},{text:"Go to Settings, then the “Import & Export” tab.",link:{label:"letterboxd.com/settings",href:"https://letterboxd.com/settings/"}},{text:"Tap “Export your data”. A .zip downloads right away."},{text:"Come back here and upload the whole .zip, or if on iPhone, click share and save to Fyra."}]},{key:"goodreads",Logo:un,connectClawId:ht,steps:[{text:"In a web browser, sign in to Goodreads.",link:{label:"goodreads.com/user/sign_in",href:"https://www.goodreads.com/user/sign_in"}},{text:"Open the import/export page.",link:{label:"goodreads.com/review/import",href:"https://www.goodreads.com/review/import"}},{text:"Tap “Export Library” and wait a few seconds."},{text:"Tap the “Your export” link to download the CSV."},{text:"Come back here and upload the CSV, or if on iPhone, click share and save to Fyra."}]},{key:"storygraph",Logo:gn,steps:[{text:"In a web browser (not the app), sign in to StoryGraph.",link:{label:"app.thestorygraph.com",href:"https://app.thestorygraph.com/"}},{text:"Open the menu (your avatar), then Manage Account, then Manage Your Data."},{text:"Tap “Export StoryGraph Library”. The CSV downloads right away (a big library takes a moment)."},{text:"Come back here and upload the CSV, or if on iPhone, click share and save to Fyra."}]},{key:"vivino",Logo:hn,steps:[{text:"In a web browser (not the app), sign in to vivino.com.",link:{label:"vivino.com",href:"https://www.vivino.com/"}},{text:"Click your profile icon (top-right) and choose Cellar.",link:{label:"vivino.com/cellar",href:"https://www.vivino.com/cellar/"}},{text:"On the Cellar page, click Export (top-right). The CSV downloads right away."},{text:"Come back here and upload the CSV, or if on iPhone, click share and save to Fyra."}]},{key:"cellartracker",Logo:pn,steps:[{text:"In a web browser (not the app), sign in to CellarTracker.",link:{label:"cellartracker.com",href:"https://www.cellartracker.com/"}},{text:"Open your Cellar, Tasting Notes or Wish List, then choose Export and pick CSV (you can upload several files at once)."},{text:"Come back here and upload the CSV, or if on iPhone, click share and save to Fyra."}]},{key:"amazon",Logo:mn,steps:[],hidden:!0}];function oe(s){var a,f;return s.media_type==="wine"?(a=s.signals)!=null&&a.cellartracker_iwine?s.entity_id??`cellartracker:${s.signals.cellartracker_iwine}`:s.entity_id??`vivino:${((f=s.signals)==null?void 0:f.vivino_key)||s.id}`:s.entity_id?s.entity_id:s.media_type==="book"?`claw-book:${s.id}`:null}function yn(s,a){const f=new Map;for(const u of s??[])f.set(u.id,u);for(const u of a)f.set(u.id,u);const h=u=>(u.match_confidence==="exact"?4:0)+(u.saved_vault_taste_id?2:0)+(u.status!=="dismissed"?1:0),d=new Map;for(const u of f.values()){if(!u.entity_id)continue;const w=d.get(u.entity_id);(!w||h(u)>h(w))&&d.set(u.entity_id,u)}return[...f.values()].filter(u=>!u.entity_id||d.get(u.entity_id)===u)}function Pn(){const s=Rt(),a=Pt(),[f,h]=zt(),[d,u]=g.useState(null),[w,j]=g.useState(null),[_,y]=g.useState("idle"),[Z,X]=g.useState(xn),$=g.useRef(null),[N,ve]=g.useState(null),[H,xe]=g.useState(null),[C,ne]=g.useState(null),[ce,x]=g.useState(!1),[T,G]=g.useState(null),[B,P]=g.useState(null),[Y,R]=g.useState(null),[z,E]=g.useState(new Set),[K,we]=g.useState(!1),[de,_e]=g.useState(null),[$e,ye]=g.useState(null),[Be,We]=g.useState(null),[Q,q]=g.useState(null),[se,ue]=g.useState(new Set),[De,xt]=g.useState(!1),[ae,Oe]=g.useState(!1),[Ie,Ce]=g.useState(null),Ee=g.useRef(null),Pe=g.useRef(null),be=g.useRef(null),[wt,_t]=g.useState({}),[ke,qe]=g.useState(null),[Ge,Me]=g.useState([]),Te=g.useRef([]),Re=g.useRef(0),me=g.useRef(!1),ze=g.useRef(""),fe=g.useRef([]),Ue=g.useRef(!1),He=g.useRef(null);g.useEffect(()=>{v.auth.getSession().then(({data:t})=>j(!!t.session))},[]);const Le=t=>{const l=ze.current?`${ze.current}: `:"";fe.current=[...fe.current,`${l}${t}`],Me(fe.current)},yt=()=>{me.current=!1,qe(null),Ue.current?(y("done"),h({view:"review"})):(G(fe.current.join(`
2`)||"Nothing could be imported."),y("error"))},bt=async t=>{ze.current=t.name,y("uploading"),G(null),P(null),Ee.current=null;try{const{data:{session:l}}=await v.auth.getSession();if(!(l!=null&&l.access_token))throw new Error("Your session expired. Sign in and try again.");const r=new FormData;r.append("file",t,t.name);const c=await fetch("https://vauhodpuhdnypebxfeod.supabase.co/functions/v1/claw-upload",{method:"POST",headers:{Authorization:`Bearer ${l.access_token}`},body:r}),o=await c.json().catch(()=>({}));if(!c.ok||!(o!=null&&o.jobId))throw new Error((o==null?void 0:o.hint)??(o==null?void 0:o.detail)??(o==null?void 0:o.error)??`Upload failed (${c.status})`);typeof o.clawId=="string"&&($.current=o.clawId,X(o.clawId)),ne(null),ve(o.jobId),xe(null),x(!1),y("running")}catch(l){Le(l instanceof Error?l.message:"Upload failed"),ge()}},ge=()=>{const t=Te.current.shift();if(!t){yt();return}qe({index:Re.current-Te.current.length,total:Re.current}),bt(t)},Ye=t=>{Te.current=[...t],Re.current=t.length,me.current=!0,fe.current=[],Me([]),ge()},[ee,M]=g.useState(null),Xe=g.useRef(()=>{}),Ke=g.useRef(()=>{}),ie=g.useRef(!1),Qe=g.useRef(new Set);g.useEffect(()=>{if(!Lt.isNativePlatform())return;const t=20,l=1500;let r=!1,c=!1,o=0,I=null;const V=()=>{I!==null&&(window.clearTimeout(I),I=null)},S=i=>{if(r||o>=t){console.warn("[ClawShare] giving up after",o,"retries:",i);return}V(),o+=1,console.log(`[ClawShare] retry ${o}/${t} in ${l}ms (${i})`),I=window.setTimeout(()=>{F()},l)},F=async()=>
2{if(!(r||c)){c=!0,console.log("[ClawShare] drain start");try{const{data:{session:i}}=await v.auth.getSession();if(!(i!=null&&i.user)){console.log("[ClawShare] no session yet"),ie.current||M({kind:"waiting-auth",text:"Waiting for sign-in to check for shared files…"}),S("no session");return}console.log("[ClawShare] session ready"),o=0,console.log("[ClawShare] calling getPendingClawFilesWithData");const{items:p}=await Fe.getPendingClawFilesWithData(),b=(p??[]).filter(m=>!Qe.current.has(m.path));if(console.log("[ClawShare] plugin returned",(p==null?void 0:p.length)??0,"item(s),",b.length,"new"),!b.length){ie.current||M(m=>(m==null?void 0:m.kind)==="waiting-auth"?null:m);return}const A=[];for(const m of b){if(!m.base64){console.warn("[ClawShare] skipping file with no data:",m.name);continue}const k=atob(m.base64),O=new Uint8Array(k.length);for(let te=0;te<k.length;te++)O[te]=k.charCodeAt(te);const Se=m.name.toLowerCase().endsWith(".zip")?"application/zip":"text/csv";console.log("[ClawShare] decoded",m.name,O.length,"bytes"),A.push(new File([O],m.name,{type:Se}))}if(!A.length){M({kind:"error",text:"Couldn't import shared file: the file was empty or unreadable. Share it again."}),await Fe.clearPendingClawFiles({paths:b.map(m=>m.path)}),console.log("[ClawShare] cleared unreadable staged files");return}const D=A.map(m=>m.name).join(", ");M({kind:"detected",text:`Shared file detected: ${D}`}),console.log("[ClawShare] file count",A.length,"- starting upload"),b.forEach(m=>Qe.current.add(m.path)),ie.current=!0,M({kind:"importing",text:`Importing ${D}…`}),Ye(A);try{await Fe.clearPendingClawFiles({paths:b.map(m=>m.path)}),console.log("[ClawShare] cleared staged files")}catch(m){console.error("[ClawShare] clear failed (files won't be re-imported this session)",m)}}catch(i){const p=i instanceof Error?i.message:String(i);if(console.error("[ClawShare] drain failed",i),/not implemented/i.test(p)){M({kind:"error",text:"This app build can't read shared files yet. Update the app."});return}M({kind:"error",text:`Couldn't import shared file: ${p}`,retryable:!0}),S(p)}finally{c=!1}}};Xe.current=()=>{o=0,F()},Ke.current=()=>{V(),o=t},F();const U=Ft.addListener("appStateChange",({isActive:i})=>{i&&(console.log("[ClawShare] app foregrounded"),o=0,F())}),{data:{subscription:n}}=v.auth.onAuthStateChange((i,p)=>{p!=null&&p.user&&(i==="SIGNED_IN"||i==="TOKEN_REFRESHED"||i==="INITIAL_SESSION")&&(console.log("[ClawShare] auth event",i),F())});return()=>{r=!0,V(),U.then(i=>i.remove()),n.unsubscribe()}},[]),g.useEffect(()=>{ie.current&&(_==="done"?(ie.current=!1,M(null)):_==="error"&&(ie.current=!1,M({kind:"error",text:`Couldn't import shared file: ${T??"import failed"}`})))},[_,T]),g.useEffect(()=>{(C==null?void 0:C.status)!=="failed"||!N||!me.current||He.current!==N&&(He.current=N,Le(C.error??"Import failed"),ge())},[C==null?void 0:C.status,N]),g.useEffect(()=>{if(!N)return;const t=v.channel(`claw-job-${N}`).on("postgres_changes",{event:"*",schema:"public",table:"claw_jobs",filter:`id=eq.${N}`},l=>{const r=l.new;r!=null&&r.id&&ne(r)}).subscribe();return v.from("claw_jobs").select("id, status, error, progress").eq("id",N).maybeSingle().then(({data:l})=>{l&&ne(l)}),()=>{v.removeChannel(t)}},[N]);const W=(C==null?void 0:C.status)??"";g.useEffect(()=>{(W==="waiting_for_login"||W==="needs_user")&&H&&x(!0)},[W,H]),g.useEffect(()=>{if(W!=="done"||!N||Ee.current===N)return;Ee.current=N;let t=!1;return(async()=>{var r;const l=new Map;for(let c=0;;c+=le){const{data:o,error:I}=await v.from("claw_raw").select("profile_name").eq("job_id",N).range(c,c+le-1);if(I){t||(G(`claw_raw read failed: ${I.message}`),y("error"));return}for(const V of o??[]){const S=V.profile_name??"(no profile)";l.set(S,(l.get(S)??0)+1)}if(!o||o.length<le)break}if(!t){const c=[...l.entries()].map(([o,I])=>({name:o,count:I})).sort((o,I)=>I.count-o.count);c.length>0&&c.every(o=>o.name==="(no profile)")?(r=be.current)==null||r.call(be,"(no profile)"):P(c)}})(),()=>{t=!0}},[W,N]);const Je=async(t,l)=>{if(!N)return;y("finalizing"),_e(null),G(null);const r=i=>{if(_e(null),me.current){Le(i),ge();return}G(i),y("error")},{error:c}=await v.functions.invoke("claw-finalize",{body:{jobId:N,profileName:t==="(no profile)"?void 0:t,...l?{profileLabel:l}:{}}});if(c)return r(c.message??"claw-finalize failed");let o=$.current??Z;{const{data:i}=await v.from("claw_jobs").select("claw_id").eq("id",N).maybeSingle();i!=null&&i.claw_id&&(o=i.claw_id)}let I=1/0;for(;o!==pt&&o!==vt;){const{data:i,error:p}=await v.functions.invoke("claw-resolve",{body:{jobId:N}});if(p||typeof(i==null?void 0:i.remaining)!="number")return r((p==null?void 0:p.message)??(i==null?void 0:i.error)??"claw-resolve failed");if(_e(i.remaining),i.remaining===0)break;if(i.remaining>=I)return r("Title matching stopped making progress.");I=i.remaining}const{data:V,error:S}=await v.from("claw_items").select("id, title, media_type, status, last_activity, entity_id, match_confidence, saved_vault_taste_id, suggested_rating, signals").eq("claw_id",o);if(S)return r(`claw_items read failed: ${S.message}`);const F=new Set;for(let i=0;;i+=le){const{data:p,error:b}=await v.from("user_vault_tastes").select("entity_id").order("id").range(i,i+le-1);if(b)return r(`user_vault_tastes read failed: ${b.message}`);for(const A of p??[]){const D=A.entity_id;if(!D)continue;F.add(D);const m=D.match(/^tmdb-movie-(\d+)$/);m&&F.add(`tmdb:${m[1]}`)}if(!p||p.length<le)break}const U=V??[],n=U.map(i=>i.saved_vault_taste_id).filter(i=>!!i);if(n.length>0){const i=new Set;for(let b=0;b<n.length;b+=200){const{data:A}=await v.from("user_vault_tastes").select("id").in("id",n.slice(b,b+200));for(const D of A??[])i.add(D.id)}const p=U.filter(b=>b.saved_vault_taste_id&&!i.has(b.saved_vault_taste_id));if(p.length>0){await v.from("claw_items").update({saved_vault_taste_id:null}).in("id",p.map(b=>b.id));for(const b of p)b.saved_vault_taste_id=null}}Ue.current=!0,E(F),R(i=>yn(i,U)),_e(null),me.current?ge():(y("done"),h({view:"review"}))};be.current=Je;const Ze=async t=>{var p,b,A,D;const l=oe(t);if(!l||t.saved_vault_taste_id||z.has(l))return;const{data:{session:r}}=await v.auth.getSession();if(!(r!=null&&r.access_token))throw new Error("Your session expired. Sign in and try again.");if(t.media_type==="wine"){const m=(p=t.signals)!=null&&p.cellartracker_iwine?await rn({userId:r.user.id,clawItemId:t.id,title:t.title,signals:t.signals,suggestedRating:t.suggested_rating??null}):await sn({userId:r.user.id,clawItemId:t.id,title:t.title,signals:t.signals});v.functions.invoke("vivino-bottle-image",{body:{corpus_id:Number(m.corpusId)}}).catch(k=>console.warn("[vivino-bottle-image]",k)),E(k=>new Set(k).add(l)),R(k=>(k==null?void 0:k.map(O=>O.id===t.id?{...O,entity_id:m.corpusId,match_confidence:"exact",saved_vault_taste_id:m.vaultTasteId}:O))??k),ue(k=>{const O=new Set(k);return O.delete(t.id),O});return}const c=Number((b=t.signals)==null?void 0:b.release_year)||void 0;let o=null;if(t.media_type==="movie"||t.media_type==="show")try{const{data:m,error:k}=await v.functions.invoke("fetch-poster",{body:{entity_type:t.media_type,entity_id:l,title:t.title,year:c}});
2!k&&typeof(m==null?void 0:m.poster_url)=="string"&&(o=m.poster_url)}catch{}else t.media_type==="book"&&(o=await Ot(t.title,(A=t.signals)==null?void 0:A.author));const I=t.media_type==="book",S=await Dt("save-media-to-vault",{id:l,entity_id:l,media_type:t.media_type||"",title:t.title,display_name:t.title,...I&&((D=t.signals)!=null&&D.author)?{subtitle:t.signals.author}:{},thumbnail_url:o,poster_url:o,metadata:c?{release_year:c}:{}},{accessToken:r.access_token,timeoutMs:25e3,retries:1}),F=(S==null?void 0:S.vault_taste_id)||(S==null?void 0:S.id);if(!S||S.error||!F)throw new Error((S==null?void 0:S.error)||"save-media-to-vault returned no vault row");const{error:U}=await v.from("claw_items").update({saved_vault_taste_id:F}).eq("id",t.id);if(U)throw U;let n=null;if(t.suggested_rating&&rt[t.suggested_rating])try{await ft(F,r.user.id,t.suggested_rating)}catch(m){n=`Saved, but rating failed: ${m instanceof Error?m.message:"unknown error"}`}const i=l;E(m=>new Set(m).add(i)),R(m=>(m==null?void 0:m.map(k=>k.id===t.id?{...k,saved_vault_taste_id:F}:k))??m),ue(m=>{const k=new Set(m);return k.delete(t.id),k}),n&&q({id:t.id,message:n})},kt=async t=>{const l=oe(t);if(!(!l||t.saved_vault_taste_id||z.has(l))){ye(t.id),q(null);try{await Ze(t)}catch(r){q({id:t.id,message:r instanceof Error?r.message:"Save failed"})}finally{ye(null)}}},St=async t=>{const l=t.filter(r=>se.has(r.id));if(l.length){Oe(!0),q(null),Ce({done:0,total:l.length});for(let r=0;r<l.length;r++){const c=l[r];ye(c.id);try{await Ze(c)}catch(o){q({id:c.id,message:o instanceof Error?o.message:"Save failed"})}Ce({done:r+1,total:l.length})}ye(null),Oe(!1),Ce(null)}},et=async t=>{q(null);const{error:l}=await v.from("claw_items").update({status:"dismissed"}).eq("id",t.id);if(l){q({id:t.id,message:l.message});return}R(r=>(r==null?void 0:r.map(c=>c.id===t.id?{...c,status:"dismissed"}:c))??r),ue(r=>{const c=new Set(r);return c.delete(t.id),c})},jt=async t=>{q(null);const{error:l}=await v.from("claw_items").update({status:""}).eq("id",t.id);if(l){q({id:t.id,message:l.message});return}R(r=>(r==null?void 0:r.map(c=>c.id===t.id?{...c,status:""}:c))??r)},Nt=async t=>{var l;if(t.saved_vault_taste_id){We(t.id),q(null);try{await cn(t.saved_vault_taste_id);const{error:r}=await v.from("claw_items").update({saved_vault_taste_id:null}).eq("id",t.id);if(r)throw r;if(E(c=>{const o=new Set(c);if(t.entity_id&&o.delete(t.entity_id),t.media_type==="wine"){const I=oe(t);I&&o.delete(I)}return o}),t.media_type==="wine"){const c=t.saved_vault_taste_id,{data:{session:o}}=await v.auth.getSession();if((l=o==null?void 0:o.user)!=null&&l.id)try{Vt(o.user.id,[c])}catch{}try{window.dispatchEvent(new CustomEvent("vault-rows-changed",{detail:{source:"vivino-import",vault_taste_id:c}}))}catch{}}R(c=>(c==null?void 0:c.map(o=>o.id===t.id?{...o,saved_vault_taste_id:null}:o))??c)}catch(r){q({id:t.id,message:r instanceof Error?r.message:"Undo failed"})}finally{We(null)}}};if(w===null)return e.jsx("div",{className:"flex min-h-screen items-center justify-center text-muted-foreground",children:e.jsx(J,{className:"h-5 w-5 animate-spin"})});if(!w)return e.jsxs("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 p-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sign in to test the claw flow."}),e.jsx(L,{onClick:()=>s("/auth"),children:"Go to sign in"})]});const re=f.get("view")==="review"&&_==="done"&&!!Y,It=W==="waiting_for_login"||W==="needs_user",Ct=W==="requesting"||W==="waiting_for_export"||W==="downloading"||W==="parsing";return e.jsxs("div",{className:"mx-auto max-w-3xl p-6",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(L,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":"Go back",onClick:()=>{if(re){h({});return}s("/app-connectors")},children:e.jsx(qt,{className:"h-5 w-5"})}),e.jsx("h1",{className:"text-xl font-semibold",children:re?"Review imports":"Bulk imports"})]}),e.jsx(L,{size:"sm",variant:"outline",onClick:()=>s("/vault"),children:_==="done"?"View in Vault":"Vault"})]}),!re&&ee&&e.jsxs("div",{role:"status",className:`mb-3 flex items-start justify-between gap-2 rounded-md border p-3 text-sm ${ee.kind==="error"?"border-destructive/50 text-destructive":"text-foreground"}`,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[(ee.kind==="importing"||ee.kind==="waiting-auth")&&e.jsx(J,{className:"mt-0.5 h-4 w-4 animate-spin"}),e.jsx("span",{children:ee.text})]}),ee.kind==="error"&&e.jsxs("div",{className:"flex shrink-0 gap-1",children:[ee.retryable&&e.jsx(L,{size:"sm",variant:"outline",onClick:()=>Xe.current(),children:"Retry"}),e.jsx(L,{size:"sm",variant:"ghost",onClick:()=>{Ke.current(),M(null)},children:"Dismiss"})]})]}),!re&&(_==="idle"||_==="done"||_==="error")&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2 border-t pt-4",children:[e.jsx(L,{className:"w-full sm:w-auto",onClick:()=>{var t;return(t=Pe.current)==null?void 0:t.click()},children:"Upload your file(s)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"See below for instructions on how to get your data"})]}),_n.filter(t=>!t.hidden).map(t=>{const l=t.Logo,r=!!wt[t.key];return e.jsxs("div",{className:"space-y-3 border-t py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"flex items-center overflow-visible",children:e.jsx(l,{className:"relative z-10 h-6 w-auto shrink-0"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[wn,e.jsxs("button",{type:"button","aria-expanded":r,className:"inline-flex items-center gap-1.5 text-sm font-medium text-primary underline underline-offset-2",onClick:()=>_t(c=>({...c,[t.key]:!c[t.key]})),children:["How to get your data",e.jsx(Gt,{className:`h-4 w-4 transition-transform ${r?"rotate-180":""}`})]})]})]}),r&&e.jsx("ol",{className:"list-decimal space-y-1.5 pl-5 text-sm",children:t.steps.map(c=>e.jsxs("li",{children:[c.text,c.link&&e.jsxs(e.Fragment,{children:[" ",e.jsx("a",{href:c.link.href,target:"_blank",rel:"noopener",className:"break-all font-medium text-primary underline underline-offset-2",children:c.link.label})]})]},c.text))})]},t.key)}),_!=="error"&&Ge.length>0&&e.jsx("div",{className:"space-y-1 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-xs",children:Ge.map((t,l)=>e.jsx("p",{children:t},l))})]}),e.jsx("input",{ref:Pe,type:"file",accept:".zip,.csv",multiple:!0,className:"hidden",onChange:t=>{const l=t.target.files;l&&l.length&&Ye(Array.from(l)),t.target.value=""}}),ke&&ke.total>1&&(_==="uploading"||_==="running"||_==="finalizing")&&e.jsxs("p",{className:"mb-2 text-xs text-muted-foreground",children:["Importing file ",ke.index," of ",ke.total,"…"]}),_==="uploading"&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(J,{className:"h-4 w-4 animate-spin"})," Uploading and parsing…"]}),_==="starting"&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(J,{className:"h-4 w-4 animate-spin"})," Starting job…"]}),(_==="running"||_==="finalizing")&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-md border p-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Status:"})," ",W||"…"]}),Ct&&(C==null?void 0:C.progress)&&e.jsx("div",{className:"mt-1 text-muted-foreground",children:C.progress}),It&&H&&!ce&&e.jsx(L,{className:"mt-3",variant:"outline",onClick:()=>
2x(!0),children:"Reopen live view"})]}),W==="done"&&B&&_==="running"&&e.jsxs("div",{className:"rounded-md border p-4",children:[e.jsx("p",{className:"mb-3 text-sm font-medium",children:"Pick a profile to finalize:"}),e.jsx("div",{className:"space-y-2",children:B.map(t=>e.jsxs(L,{variant:"outline",className:"w-full justify-between",onClick:()=>Je(t.name),children:[e.jsx("span",{children:t.name}),e.jsxs("span",{className:"text-muted-foreground",children:[t.count," rows"]})]},t.name))})]}),_==="finalizing"&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(J,{className:"h-4 w-4 animate-spin"}),de===null?"Finalizing…":`Matching titles… ${de} left`]})]}),e.jsx(Bt,{open:!!d,onOpenChange:t=>{t||u(null)},title:"Remove from your vault?",description:d?`"${d.title}" will be removed from your vault.`:"",actionLabel:"Remove",onConfirm:()=>{const t=d;u(null),t&&Nt(t)}}),!re&&_==="done"&&Y&&e.jsx(L,{variant:"outline",className:"mt-4 w-full",onClick:()=>h({view:"review"}),children:"Review imported items"}),re&&Y&&(()=>{const t=Y.filter(n=>n.title&&n.title.trim()).filter(n=>n.media_type==="book"||n.media_type==="wine"||n.match_confidence==="exact").sort((n,i)=>(i.last_activity??"").localeCompare(n.last_activity??"")),l=n=>{var i;return n.media_type==="wine"?n.entity_id?!!n.saved_vault_taste_id||z.has(n.entity_id):((i=n.signals)==null?void 0:i.in_vault)===!0||!!n.saved_vault_taste_id||(()=>{const p=oe(n);return!!p&&z.has(p)})():!!n.entity_id&&z.has(n.entity_id)},r=t.filter(n=>n.status==="dismissed"),c=t.filter(n=>n.status!=="dismissed"),o=c.filter(l).length,I=K?c:c.filter(n=>!l(n)),V=c.filter(n=>oe(n)&&!l(n)&&!n.saved_vault_taste_id),S=V.length>0&&V.every(n=>se.has(n.id)),F=n=>{ue(i=>{const p=new Set(i);return p.has(n)?p.delete(n):p.add(n),p})},U=()=>{ue(n=>{const i=new Set(n);return S?V.forEach(p=>i.delete(p.id)):V.forEach(p=>i.add(p.id)),i})};return e.jsxs("div",{className:"space-y-4 pb-20",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("p",{className:"text-sm font-medium",children:[c.length-o," new · ",o," already in vault",r.length>0&&` · ${r.length} dismissed`]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[V.length>0&&e.jsx(L,{size:"sm",variant:"outline",onClick:U,disabled:ae,children:S?"Deselect all":"Select all"}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:K,onChange:n=>we(n.target.checked)}),"Show items already in my vault"]}),r.length>0&&e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:De,onChange:n=>xt(n.target.checked)}),"Show dismissed"]})]})]}),e.jsx("div",{className:"hidden justify-end gap-3 pr-[72px] text-[11px] font-medium text-muted-foreground sm:flex",children:e.jsx("span",{className:"w-16 text-center",children:"Rating"})}),e.jsx("div",{className:"divide-y",children:I.map(n=>{var A,D,m,k,O,Se,te,tt;const i=lt(n.media_type),p=!!oe(n)&&!l(n)&&!n.saved_vault_taste_id,b=e.jsxs(e.Fragment,{children:[p?e.jsx(Wt,{checked:se.has(n.id),onCheckedChange:()=>F(n.id),disabled:ae,"aria-label":`Select ${n.title}`}):null,e.jsx(i,{className:"h-5 w-5 shrink-0 text-muted-foreground","aria-label":n.media_type==="show"?"Show":n.media_type==="book"?"Book":"Movie"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"line-clamp-2 text-xs leading-snug",children:n.title}),n.media_type==="book"&&((A=n.signals)==null?void 0:A.author)&&e.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:n.signals.author}),n.media_type==="wine"&&e.jsxs("p",{className:"hidden truncate text-[11px] text-muted-foreground sm:block",children:[[(D=n.signals)==null?void 0:D.winery,(m=n.signals)==null?void 0:m.wine,((k=n.signals)==null?void 0:k.vintage)??"NV",(O=n.signals)==null?void 0:O.region,(Se=n.signals)==null?void 0:Se.country].filter(Boolean).join(" · "),((te=n.signals)==null?void 0:te.vivino_url)&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("a",{href:n.signals.vivino_url,target:"_blank",rel:"noopener noreferrer",className:"underline",children:"Vivino"})]}),((tt=n.signals)==null?void 0:tt.cellartracker_url)&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("a",{href:n.signals.cellartracker_url,target:"_blank",rel:"noopener noreferrer",className:"underline",children:"CellarTracker"})]})]}),l(n)&&n.media_type!=="wine"&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(in vault)"}),n.media_type==="book"&&n.match_confidence==="exact"&&e.jsx("span",{className:"ml-1 text-[10px] text-muted-foreground",children:"matched"}),(Q==null?void 0:Q.id)===n.id&&e.jsx("p",{className:"text-xs text-destructive",children:Q.message})]}),e.jsx("span",{className:"hidden w-16 shrink-0 text-center text-[11px] text-muted-foreground sm:block",children:n.suggested_rating?rt[n.suggested_rating]??n.suggested_rating:""}),e.jsx("div",{className:"shrink-0",children:n.media_type==="wine"&&!p&&!n.saved_vault_taste_id?e.jsxs("span",{className:"flex items-center gap-1",children:[l(n)&&e.jsx("span",{"aria-disabled":"true",title:"Already in your vault",className:"inline-flex h-6 cursor-default items-center rounded-md border border-input bg-transparent px-3 text-xs text-muted-foreground select-none",children:"Vault"}),e.jsx(L,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs text-muted-foreground",title:"Not interested — won't show up again",onClick:()=>et(n),children:e.jsx(je,{className:"h-3 w-3"})})]}):n.saved_vault_taste_id?e.jsxs("span",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Saved"}),e.jsx(L,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",disabled:Be===n.id,onClick:Et=>{Et.preventDefault(),u(n)},children:Be===n.id?e.jsx(J,{className:"h-3 w-3 animate-spin"}):"Undo"})]}):p?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(L,{size:"sm",variant:"outline",className:"h-6 px-3 text-xs",disabled:ae||$e===n.id,onClick:()=>kt(n),children:$e===n.id?e.jsx(J,{className:"h-3 w-3 animate-spin"}):"Save"}),e.jsx(L,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs text-muted-foreground",disabled:ae,title:"Not interested — won't show up again",onClick:()=>et(n),children:e.jsx(je,{className:"h-3 w-3"})})]}):null})]});return p?e.jsx("label",{className:"flex cursor-pointer items-center gap-3 py-2.5",children:b},n.id):e.jsx("div",{className:"flex items-center gap-3 py-2.5",children:b},n.id)})}),De&&r.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:["Dismissed (",r.length,")"]}),e.jsx("div",{className:"divide-y rounded-md border opacity-70",children:r.map(n=>{const i=lt(n.media_type);return e.jsxs("div",{className:"flex items-center gap-3 p-2",children:[e.jsx(i,{className:"h-5 w-5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"line-clamp-2 text-xs leading-snug",children:n.title}),(Q==null?void 0:Q.id)===n.id&&e.jsx("p",{className:"text-xs text-destructive",children:Q.message})]}),e.jsx(L,{size:"sm",variant:"ghost",className:"h-6 shrink-0 px-2 text-xs",onClick:()=>jt(n),children:"Undo"})]},n.id)})})]}),se.size>0&&e.jsxs("div",{className:"sticky bottom-0 -mx-6 flex items-center justify-between gap-2 border-t bg-background px-6 py-3",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:Ie?`Saving ${Ie.done} of ${Ie.total}…`:`${se.size} selected`}),e.jsxs(L,{size:"sm",onClick:()=>St(V),disabled:ae,children:[ae&&e.jsx(J,{className:"mr-2 h-4 w-4 animate-spin"}),"Save ",se.size," to vault"]})]})]})})(),(_==="error"||W==="failed")&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm",children:T??(C==null?void 0:C.error)??"Something went wrong."}),ce&&H&&(a?e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col bg-background",children:[e.jsxs("div",{className:"flex items-start gap-2 border-b p-2",children:[e.jsx(L,{variant:"ghost",size:"sm",className:"h-8 w-8 shrink-0 p-0",onClick:()=>x(!1),"aria-label":"Close live view",children:e.jsx(je,{className:"h-4 w-4"})}),e.jsxs("p",{className:"pt-1.5 text-xs text-muted-foreground",children:["Sign in to ",ot(Z)," — Fyra never sees your password"]})]}),e.jsx("iframe",{src:H,className:"w-full flex-1",title:"Claw live view"})]}):e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col items-center justify-start overflow-y-auto bg-black/70 p-6",children:[e.jsxs("div",{className:"flex w-full max-w-md items-center justify-between pb-3",children:[e.jsxs("p",{className:"text-sm text-white/90",children:["Sign in to ",ot(Z)," — Fyra never sees your password"]}),e.jsxs(L,{variant:"ghost",size:"sm",className:"shrink-0 text-white hover:bg-white/10 hover:text-white",onClick:()=>x(!1),children:[e.jsx(je,{className:"mr-1 h-4 w-4"})," Close"]})]}),e.jsx("div",{className:"w-full max-w-[390px] overflow-hidden rounded-[2rem] border border-white/20 bg-background shadow-2xl",style:{height:"min(88vh, 819px)"},children:e.jsx("iframe",{src:H,className:"h-full w-full",title:"Claw live view"})})]}))]})}export{Pn 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.