PageSourceSearch

https://us-save.ai/assets/SearchResults-CMSLEFkE.js

js us-save.ai collected 2026-10-05 14:45:50 UTC 37,242 bytes, 11 lines download raw bytes

1import{c as gt,x as It,u as Mt,ac as zt,l as Et,ad as Lt,f as qt,a as Pe,i as Re,j as e,R as At,Y as st,K as L,L as Y,y as ce,ae as $t,k as K,X as Dt,S as T,Z as Ft,af as Qt}from"./index-B0VBF-zr.js";import{r as c,u as _t,c as Bt,L as rt}from"./react-vendor-vGczuDvc.js";import{D as Ot}from"./DashboardLayout-DZYeHBmM.js";import{C as Ie}from"./card-BIK7HAgp.js";import{B as U}from"./badge-Bm8FK5hT.js";import{T as Tt,C as Ut}from"./ComparisonButton-Dk7clZj3.js";import{W as Ht,a as nt,S as Vt,M as de,E as at}from"./WorkspacePrimitives-B52oYTaO.js";import{g as ot}from"./zipcode-storage-Lx-H-GfE.js";import{m as it,L as Me,a as ze,g as G,b as lt,r as ct,f as Kt,n as Wt,i as Xt}from"./search-result-utils-CQvMUY5g.js";import{S as Zt}from"./scroll-to-top-LC7dCuCG.js";import{T as Jt}from"./textarea-CwTeiDJB.js";import{u as Yt}from"./i18n-Brfxm0Dd.js";import{S as dt}from"./scale-CSX3RCeE.js";import{B as ut}from"./badge-check-DsW40Dxn.js";import{S as Ee}from"./sliders-horizontal-ij5eF6-k.js";import{R as Gt}from"./ruler-DFqqfGeM.js";import{Z as es}from"./zap-CNsNOwuk.js";import{S as ts}from"./star-Bo3l7b1H.js";import{A as ss}from"./arrow-up-right-BuF18BsP.js";import"./mail-pvdlx0zZ.js";import"./useRefreshOnReturn-B2Rq07Fk.js";import"./wallet-1wD3QDwg.js";import"./useConsoleScope-KvuAm5zL.js";import"./commandPaletteBus-DPKR2nuM.js";import"./plus-BRfGymWD.js";/**
2 * @license lucide-react v0.536.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const rs=[["path",{d:"m16 16 2 2 4-4",key:"gfu2re"}],["path",{d:"M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14",key:"e7tb2h"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["line",{x1:"12",x2:"12",y1:"22",y2:"12",key:"a4e8g8"}]],mt=gt("package-check",rs);/**
7 * @license lucide-react v0.536.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const ns=[["circle",{cx:"8",cy:"21",r:"1",key:"jimo8o"}],["circle",{cx:"19",cy:"21",r:"1",key:"13723u"}],["path",{d:"M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12",key:"9zh506"}]],ft=gt("shopping-cart",ns);function as(){const[s,d]=c.useState({phase:"connecting",queryStates:new Map,isComplete:!1,error:null}),p=c.useCallback(m=>{const b=m.data,z=b.phase||m.type||"",x=z.match(/^q(\d+):(.+)$/),I=x?parseInt(x[1],10):0,P=x?x[2]:z;if(b.error){console.warn(`Search q${I} phase "${P}" error:`,b.error);return}if(b.matches&&b.matches.length>0){const E=it(b.matches);let h="connecting";P==="vector"?h="vector":P==="local"?h="local":P==="national"&&(h="national"),d(N=>{const R=new Map(N.queryStates),C=R.get(I)||{items:[],finalResult:null,isComplete:!1};return R.set(I,{...C,items:os([...C.items,...E])}),{...N,phase:h,queryStates:R}})}if(P==="complete"&&b.finalResult){const E=b.finalResult.matches||b.finalResult.items||[],h=it(E);d(N=>{const R=new Map(N.queryStates);R.set(I,{items:h,finalResult:b.finalResult,isComplete:!0});const C=Array.from(R.values()).every(W=>W.isComplete);return{...N,phase:C?"complete":N.phase,isComplete:C,queryStates:R}})}},[]),v=c.useCallback(()=>{d(m=>m.isComplete?m:{...m,phase:"complete",isComplete:!0})},[]),w=c.useCallback(m=>{d(b=>({...b,phase:"error",isComplete:!0,error:m}))},[]),j=c.useCallback(()=>{d({phase:"connecting",queryStates:new Map,isComplete:!1,error:null})},[]);return{...s,handleEvent:p,markComplete:v,markError:w,reset:j}}function os(s){const d=new Map;for(const p of s){const v=p.id||`${p.title}-${p.url}`;d.has(v)||d.set(v,p)}return Array.from(d.values())}const H=24,ue=s=>s?s.toString().trim().toLowerCase():"",pt=s=>{const d=parseFloat(s);return Number.isFinite(d)?d:void 0},fe="Unknown Seller",me=s=>{const d=[s.seller,s.platform,s.platformEngine];for(const p of d){const v=Wt(p);if(v)return v}return fe},F=s=>{if(typeof s.discountPercent=="number"&&Number.isFinite(s.discountPercent))return s.discountPercent;if(typeof s.savings=="number"&&typeof s.price=="number"){const d=s.price+s.savings;if(d>0){const p=s.savings/d*100;return Number.isFinite(p)?Math.max(0,p):0}}return 0};function xt(s){return s.toLowerCase().replace(/(\d+)\s*[-]?\s*(?:in(?:ch(?:es)?)?\.?|"|'|ft\.?|feet|foot|mm|cm|m)\b/g,"$1").replace(/\s*[x×X]\s*/g,"x").replace(/\s+by\s+/g,"x").replace(/(\d)\s+x\s+(\d)/g,"$1x$2")}function ht(s){const d=s.match(/\b(\d+x\d+)\b/g)||[];return[...new Set(d)]}function is(s){return(s.toLowerCase().replace(/\d+\s*[-]?\s*(?:in(?:ch(?:es)?)?\.?|"|'|ft\.?|feet|foot|mm|cm|m)?\s*[x×X]\s*\d+\s*[-]?\s*(?:in(?:ch(?:es)?)?\.?|"|'|ft\.?|feet|foot|mm|cm|m)?/g,"").match(/\b(\d+)\b/g)||[]).map(Number).filter(w=>w>=2&&w<=999)}function ls(s){const d=s.toLowerCase().trim(),p=xt(d),v=ht(p),w=v.length===0?is(d):[],j=new Set(["a","an","the","for","and","or","in","on","at","to","of","with","by","is","it","as","be","do","no","not","but","from","that","this","inch","inches","ft","feet","foot","mm","cm"]),m=d.replace(/\d+\s*[-]?\s*(?:in(?:ch(?:es)?)?\.?|"|'|ft\.?|feet|foot|mm|cm|m)?\s*[x×X]\s*\d+\s*[-]?\s*(?:in(?:ch(?:es)?)?\.?|"|'|ft\.?|feet|foot|mm|cm|m)?/g,"").replace(/\b\d+\s*[-]?\s*(?:in(?:ch(?:es)?)?\.?|"|'|ft\.?|feet|foot|mm|cm|m)\b/g,"").split(/[\s,;:.()\-/]+/).filter(b=>b.length>2&&!j.has(b)&&!/^\d+$/.test(b));return{dimPairs:v,standaloneNums:w,keywords:m,rawQuery:d}}function cs(s,d){var P,E;const p=(s.title||"").toLowerCase(),v=(((P=s.specs)==null?void 0:P.dimensionLabel)||"").toLowerCase(),w=(((E=s.specs)==null?void 0:E.variant)||"").toLowerCase(),j=`${p} ${v} ${w}`,m=xt(j),b=ht(m);let z=0,x=0;if(d.dimPairs.length>0||d.standaloneNums.length>=2,d.dimPairs.length>0){const h=d.dimPairs.filter(N=>{const R=N.split("x"),C=`${R[1]}x${R[0]}`;return b.includes(N)||b.includes(C)||m.includes(N)||m.includes(C)});h.length===d.dimPairs.length?z=65:h.length>0&&(z=30*(h.length/d.dimPairs.length))}else if(d.standaloneNums.length>=2){const h=d.standaloneNums.filter(N=>new RegExp(`\\b${N}\\b`).test(m));h.length===d.standaloneNums.length?z=55:h.length>0&&(z=25*(h.length/d.standaloneNums.length))}d.keywords.length>0&&(x=35*(d.keywords.filter(R=>j.includes(R)).length/d.keywords.length));const I=z+x;return Math.round(I)}function ds(s,d){if(!d.trim()||s.length===0)return{exactMatches:s,variations:[]};const p=ls(d);if(!(p.dimPairs.length>0||p.standaloneNums.length>=2||p.keywords.length>=2))return{exactMatches:s,variations:[]};const w=s.map(x=>({item:x,relevance:cs(x,p)})),m=p.dimPairs.length>0||p.standaloneNums.length>=2?60:50,b=w.filter(x=>x.relevance>=m).sort((x,I)=>{const P=typeof x.item.price=="number"?x.item.price:1/0,E=typeof I.item.price=="number"?I.item.price:1/0;return P!==E?P-E:F(I.item)-F(x.item)}).map(x=>x.item),z=w.filter(x=>x.relevance<m).sort((x,I)=>{const P=F(I.item)-F(x.item);if(Math.abs(P)>.5)return P;const E=typeof x.item.price=="number"?x.item.price:1/0,h=typeof I.item.price=="number"?I.item.price:1/0;return E-h}).map(x=>x.item);return{exactMatches:b,variations:z}}function us(s){const d=new Map;
11return s.forEach(p=>{const v=me(p);if(v===fe)return;const w=v.toLowerCase();d.has(w)||d.set(w,v)}),Array.from(d.entries()).map(([p,v])=>({value:p,label:v})).sort((p,v)=>p.label.localeCompare(v.label))}function Ds(){var et;const{t:s,i18n:d}=Yt("search-results"),p=_t(),v=Bt(),{user:w}=It(),{activeTenant:j}=Mt(),m=p.state,b=c.useRef(null);b.current===null&&(m!=null&&m.streamingPayload)&&(b.current={payload:m.streamingPayload,queries:m.streamingQueries||[]});const z=b.current!==null,x=sessionStorage.getItem("ussave:lastQuery")||"",I=()=>{var n;const t=[];if(Array.isArray(m==null?void 0:m.resultSets)&&m.resultSets.length>0)m.resultSets.forEach((o,i)=>{t.push(ct(o,i))});else{const o=sessionStorage.getItem(Me);if(o)try{const i=JSON.parse(o);Array.isArray(i)&&i.forEach((u,S)=>{t.push(ct(u,S))})}catch{}}if(t.length===0){let o=null;if(Array.isArray(m==null?void 0:m.results)&&m.results.length>0)o=m.results;else{const i=sessionStorage.getItem("ussave:lastResults");if(i)try{const u=JSON.parse(i);Array.isArray(u)&&(o=u)}catch{}}if(o&&o.length>0){const i=(typeof(m==null?void 0:m.query)=="string"&&m.query.trim().length>0?m.query:x)||s("fallback.recentSearch");t.push({id:G(0),query:i,items:o,totalResults:o.length})}}const r=typeof(m==null?void 0:m.activeSetId)=="string"&&m.activeSetId||sessionStorage.getItem(ze)||"",a=t.find(o=>o.id===r),l=(a==null?void 0:a.id)??((n=t[0])==null?void 0:n.id)??"";return{sets:t,activeId:l}},{sets:P,activeId:E}=I(),h=as(),[N,R]=c.useState(P),[C,W]=c.useState(E),[pe,Le]=c.useState(""),[M,qe]=c.useState(!1),[Ae,X]=c.useState(null),[y,ge]=c.useState(null),[ee,$e]=c.useState(""),[xe,te]=c.useState(null),[he,be]=c.useState(""),[ye,ve]=c.useState(""),[se,De]=c.useState(!1),Fe=!!(y!=null&&y.requiresRefinement&&y.options.length>0),je=()=>{ge(null),$e(""),te(null),be(""),ve("")},[Ne,Se]=c.useState("best-match"),[f,Qe]=c.useState({category:"",brand:"",seller:"",primeOnly:!1,minPrice:"",maxPrice:""}),{comparison:bt}=zt(),re=bt.length,[V,ne]=c.useState(()=>{var t;return Math.min(H,((t=P[0])==null?void 0:t.items.length)??0)}),_e=c.useRef(null),Be=c.useRef(null),A=c.useMemo(()=>N.length?N.find(r=>r.id===C)??N[0]:null,[N,C]),g=(A==null?void 0:A.items)??[],q=(A==null?void 0:A.query)??x,Oe=Et(d.language),Te=c.useMemo(()=>{var r;const t=ot();return Lt({offerCurrency:(r=g.find(a=>a.currency))==null?void 0:r.currency,countryCode:t==null?void 0:t.countryCode,region:j==null?void 0:j.region})},[g,j==null?void 0:j.region]),Q=c.useCallback((t,r)=>qt(t,r??Te,Oe),[Te,Oe]),k=c.useMemo(()=>{if(!(y!=null&&y.options.length))return null;if(xe){const t=y.options.find(r=>r.id===xe);if(t)return t}return y.options[0]},[y,xe]),Ue=((et=k==null?void 0:k.unitLabel)==null?void 0:et.trim())||"units";c.useEffect(()=>{if(!(y!=null&&y.options.length)){te(null);return}te(t=>t&&y.options.some(r=>r.id===t)?t:y.options[0].id)},[y]),c.useEffect(()=>{y||(be(""),ve(""))},[y]),c.useEffect(()=>{sessionStorage.setItem(Me,JSON.stringify(N))},[N]),c.useEffect(()=>{C&&sessionStorage.setItem(ze,C)},[C]),c.useEffect(()=>{q&&sessionStorage.setItem("ussave:lastQuery",q)},[q]);const He=c.useRef([]);c.useEffect(()=>{if(!b.current)return;const{payload:t,queries:r}=b.current,a=j!=null&&j.id&&!t.tenantId?{...t,tenantId:j.id}:t;window.history.replaceState({...p.state,streamingPayload:void 0,streamingQueries:void 0},"");const l=r.map((o,i)=>({id:G(i),query:o,items:[],totalResults:0}));if(l.length===0){const o=G(0);l.push({id:o,query:"Search",items:[],totalResults:0})}He.current=l.map(o=>o.id),R(l),W(l[0].id);const n=new AbortController;return Pe.postStream("/search/text/stream",a,o=>{h.handleEvent(o)},{signal:n.signal}).then(()=>{h.markComplete()}).catch(o=>{(o==null?void 0:o.name)!=="AbortError"&&(h.markError((o==null?void 0:o.message)||"Search failed"),Re(o,{showToast:!0}))}),()=>{n.abort()}},[]),c.useEffect(()=>{var o;if(!z||h.queryStates.size===0)return;const t=((o=b.current)==null?void 0:o.queries)||[],r=He.current,a=[];let l=!1;for(const[i,u]of h.queryStates){const S=t[i]||`Search ${i+1}`,J=r[i]||G(i);if(u.finalResult){l=!0;const ke=lt(u.finalResult,S,i,!0);a[i]={...ke,id:J}}else a[i]={id:J,query:S,items:u.items,totalResults:u.items.length}}for(let i=0;i<Math.max(t.length,a.length);i++)a[i]||(a[i]={id:r[i]||G(i),query:t[i]||`Search ${i+1}`,items:[],totalResults:0});
11const n=a.filter(Boolean);R(n),h.isComplete&&l&&(sessionStorage.setItem(Me,JSON.stringify(n)),n[0]&&sessionStorage.setItem(ze,n[0].id))},[z,h.queryStates,h.isComplete]);const Ve=z&&!h.isComplete,yt=(()=>{switch(h.phase){case"connecting":return s("streaming.connecting","Searching...");case"vector":return s("streaming.vector","Found matches in database");case"local":return s("streaming.local","Found local products");case"national":return s("streaming.national","Searching nationally...");case"finalizing":return s("streaming.finalizing","Finalizing results...");case"complete":return s("streaming.complete","Search complete");default:return""}})(),ae=c.useMemo(()=>{const t=new Map;return g.forEach(r=>{var n;const a=(n=r.category)==null?void 0:n.trim();if(!a)return;const l=ue(a);t.has(l)||t.set(l,a)}),Array.from(t.entries()).map(([r,a])=>({value:r,label:a})).sort((r,a)=>r.label.localeCompare(a.label))},[g]),oe=c.useMemo(()=>{const t=new Map;return g.forEach(r=>{var n;const a=(n=r.brand)==null?void 0:n.trim();if(!a)return;const l=ue(a);t.has(l)||t.set(l,a)}),Array.from(t.entries()).map(([r,a])=>({value:r,label:a})).sort((r,a)=>r.label.localeCompare(a.label))},[g]),ie=c.useMemo(()=>us(g),[g]),$=c.useMemo(()=>{const t=pt(f.minPrice),r=pt(f.maxPrice);let a=g.map(n=>({...n,normalizedCategory:ue(n.category),normalizedBrand:ue(n.brand),normalizedSeller:me(n).toLowerCase()})).filter(n=>!(f.category&&n.normalizedCategory!==f.category||f.brand&&n.normalizedBrand!==f.brand||f.seller&&n.normalizedSeller!==f.seller||f.primeOnly&&!n.prime||typeof t=="number"&&typeof n.price=="number"&&n.price<t||typeof r=="number"&&typeof n.price=="number"&&n.price>r));const l=(n,o,i=!0)=>{const u=typeof n=="number"?n:-1/0,S=typeof o=="number"?o:-1/0;return i?S-u:u-S};return a.sort((n,o)=>{switch(Ne){case"best-value":return l(n.valueScore??n.discountPercent??n.savings,o.valueScore??o.discountPercent??o.savings,!0);case"price-asc":return l(n.price,o.price,!1);case"price-desc":return l(n.price,o.price,!0);case"rating-desc":return l(n.rating,o.rating,!0);case"savings-desc":return l(n.discountPercent??n.savings,o.discountPercent??o.savings,!0);case"best-match":default:return l(n.overallScore??n.score??n.relevanceScore,o.overallScore??o.score??o.relevanceScore,!0)}}),a},[g,f,Ne]),{exactMatches:_,variations:le}=c.useMemo(()=>ds($,q),[$,q]);c.useEffect(()=>{ne(Math.min(H,$.length||H))},[$.length]),c.useEffect(()=>{const t=_e.current;if(!t||V>=$.length)return;const r=new IntersectionObserver(a=>{const[l]=a;l.isIntersecting&&ne(n=>Math.min(n+H,$.length))},{rootMargin:"200px 0px"});return r.observe(t),()=>r.disconnect()},[$.length,V]);const we=c.useMemo(()=>[..._,...le],[_,le]),Ce=c.useMemo(()=>we.slice(0,V),[we,V]),vt=V<we.length,Ke=Math.min(_.length,V),We=Ce.slice(0,Ke),Xe=Ce.slice(Ke),B=c.useMemo(()=>{const t=g.filter(u=>typeof u.discountPercent=="number"&&u.discountPercent>0||typeof u.savings=="number"&&u.savings>0),r=g.reduce((u,S)=>Math.max(u,F(S)),0),a=g.reduce((u,S)=>u+(typeof S.savings=="number"&&S.savings>0?S.savings:0),0),l=t.length>0?t.reduce((u,S)=>u+F(S),0)/t.length:0;let n=null,o=0;g.forEach(u=>{const S=F(u);S>o&&(o=S,n=u)});const i=new Set(g.map(u=>me(u)).filter(u=>u!==fe));return{totalProducts:g.length,productsWithDiscount:t.length,maxDiscount:r,avgDiscount:l,totalSavings:a,bestDeal:n,bestDealSavings:o,sellerCount:i.size}},[g]),D=c.useMemo(()=>{const t=g.filter(i=>typeof i.price=="number"),r=t.length?t.reduce((i,u)=>i+(u.price??0),0)/t.length:null,a=g.map(i=>i.overallScore??i.relevanceScore??i.score).filter(i=>typeof i=="number"&&Number.isFinite(i)),l=a.length?a.reduce((i,u)=>i+u,0)/a.length:null,n=g.map(i=>i.rating).filter(i=>typeof i=="number"&&Number.isFinite(i)),o=n.length?n.reduce((i,u)=>i+u,0)/n.length:null;return{averagePrice:r,averageScore:l,averageRating:o,visibleCount:$.length,exactCount:_.length}},[_.length,$.length,g]),Ze=c.useMemo(()=>{var r,a,l;const t=[];if(f.category){const n=((r=ae.find(o=>o.value===f.category))==null?void 0:r.label)??f.category;t.push({key:"category",label:n})}if(f.brand){const n=((a=oe.find(o=>o.value===f.brand))==null?void 0:a.label)??f.brand;t.push({key:"brand",label:n})}
11if(f.seller){const n=((l=ie.find(o=>o.value===f.seller))==null?void 0:l.label)??f.seller;t.push({key:"seller",label:n})}return f.primeOnly&&t.push({key:"primeOnly",label:"Prime"}),f.minPrice&&t.push({key:"minPrice",label:`${s("filters.minLabel")} ${Q(Number(f.minPrice))}`}),f.maxPrice&&t.push({key:"maxPrice",label:`${s("filters.maxLabel")} ${Q(Number(f.maxPrice))}`}),t},[f,ae,oe,ie,Q,s]),O=c.useCallback((t,r)=>{Qe(a=>({...a,[t]:r}))},[]),jt=t=>{O(t,typeof f[t]=="boolean"?!1:"")},Z=c.useCallback(()=>{Qe({category:"",brand:"",seller:"",primeOnly:!1,minPrice:"",maxPrice:""})},[]),Nt=c.useCallback(t=>{if(!(t!=null&&t.id))return;const r=`/product/${encodeURIComponent(t.id)}`;v(r,{state:{product:t,origin:"search-results",fromSetId:C}})},[v,C]),Je=async t=>{const r=t.trim();if(!(!r||M)){qe(!0),X(null);try{const a={type:"text",recipientEmail:w==null?void 0:w.email,queries:[r],exactMatchOnly:!1};j!=null&&j.id&&(a.tenantId=j.id);const l=ot();l&&(l.zipcode&&(a.location=l.zipcode),l.latitude&&(a.latitude=l.latitude),l.longitude&&(a.longitude=l.longitude),a.countryCode=l.countryCode||Qt(j==null?void 0:j.region));const n=await Pe.post("/search/text",a),o=Array.isArray(n==null?void 0:n.results)&&n.results.length>0&&n.results.every(u=>Xt(u))?n.results:[n],i={current:null};R(u=>{const S=u.length,J=[...u];return o.forEach((ke,Rt)=>{const tt=lt(ke,r,S+Rt,!0);J.push(tt),i.current=tt}),J}),i.current&&(W(i.current.id),ne(Math.min(H,i.current.items.length))),je(),Z(),Se("best-match"),Le("")}catch(a){throw Re(a,{onError:X,showToast:!0}),a}finally{qe(!1)}}},St=async t=>{if(t.preventDefault(),M||se)return;const r=pe.trim();if(r){$e(r),ge(null),De(!0),X(null);try{const a=await Pe.post("/ai/search/plan",{query:r,category:f.category||void 0,context:q});!a.requiresRefinement||a.options.length===0?await Je(r):(ge(a),requestAnimationFrame(()=>{var l;(l=Be.current)==null||l.scrollIntoView({behavior:"smooth",block:"start"})}))}catch(a){Re(a,{onError:X,showToast:!0})}finally{De(!1)}}},wt=()=>{var l,n;const t=ee.trim();if(!t)return"";const r=[];if(k){const o=((l=k.measurementType)==null?void 0:l.trim())||((n=k.label)==null?void 0:n.toLowerCase())||null;o&&r.push(`Quote pricing ${o}`)}k!=null&&k.askForQuantity&&he.trim()&&r.push(`Approximate requirement is ${he.trim()} ${Ue}`),ye.trim()&&r.push(`Constraints: ${ye.trim()}`);const a=r.length?`${r.join(". ")}.`:"";return a?`${t}. ${a}`:t},Ct=()=>{je()},Ye=async t=>{if(!ee||M)return;const r=t?wt():ee;if(r.trim())try{await Je(r),je()}catch{}},kt=c.useCallback(t=>{if(t===C)return;W(t),Z(),Se("best-match");const r=N.find(a=>a.id===t);ne(Math.min(H,(r==null?void 0:r.items.length)??H))},[C,N,Z]),Pt=Ce.length>0,Ge=t=>{const r=Ft(t.tag),a=Kt(t.specs),l=F(t),n=typeof t.savings=="number"&&t.savings>0,o=n&&typeof t.price=="number"?t.price+t.savings:void 0,i=me(t),u=t.overallScore??t.relevanceScore??t.score??t.valueScore;return e.jsx(Ie,{role:"article",className:"motion-stack-card group cursor-pointer overflow-hidden rounded-lg border-border/65 bg-card/85 transition hover:border-foreground
11/20",onClick:()=>Nt(t),children:e.jsxs("div",{className:"grid min-h-full gap-0 sm:grid-cols-[116px_minmax(0,1fr)]",children:[e.jsxs("div",{className:"relative border-b border-border/55 bg-muted/45 sm:border-b-0 sm:border-r",children:[t.imageUrl?e.jsx("img",{src:t.imageUrl,alt:t.title,className:"aspect-[5/4] h-full min-h-[136px] w-full object-cover grayscale-[0.15] transition duration-300 group-hover:scale-[1.02] sm:aspect-auto",loading:"lazy"}):e.jsx("div",{className:"flex aspect-[5/4] min-h-[136px] items-center justify-center sm:aspect-auto sm:h-full",children:e.jsx(ft,{className:"size-7 text-muted-foreground/35"})}),l>0&&e.jsx("div",{className:"absolute left-3 top-3 rounded-md border border-border/70 bg-card/90 px-2 py-1 text-[11px] font-semibold text-foreground",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Tt,{className:"size-3"}),s("product.discount",{percent:l.toFixed(0)})]})})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[i!==fe&&e.jsx("span",{className:"truncate font-medium text-foreground/75",children:i}),typeof t.rating=="number"&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ts,{className:"size-3 fill-muted-foreground text-muted-foreground"}),t.rating.toFixed(1),typeof t.reviewCount=="number"&&e.jsxs("span",{className:"text-muted-foreground/60",children:["(",t.reviewCount.toLocaleString(),")"]})]})]}),e.jsx("h3",{className:"mt-2 line-clamp-2 text-sm font-semibold leading-snug text-foreground",children:t.title})]}),typeof u=="number"&&e.jsxs("div",{className:"shrink-0 rounded-md border border-border/65 bg-muted/35 px-2 py-1 text-right",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:s("product.score")}),e.jsx("p",{className:"font-mono text-xs font-semibold text-foreground",children:Math.round(u)})]})]}),a&&e.jsx("p",{className:"line-clamp-2 text-xs leading-5 text-muted-foreground",children:a}),(r||t.brand||t.prime)&&e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[t.brand&&e.jsx(U,{variant:"secondary",className:"px-1.5 py-0 text-[10px]",children:t.brand}),r&&!r.toLowerCase().includes("%")&&e.jsx(U,{variant:"secondary",className:"px-1.5 py-0 text-[10px]",children:r}),t.prime&&e.jsx(U,{variant:"outline",className:"border-border px-1.5 py-0 text-[10px] text-muted-foreground",children:"Prime"})]}),e.jsxs("div",{className:"mt-auto flex flex-col gap-3 border-t border-border/45 pt-3",children:[e.jsxs("div",{className:"flex items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[typeof t.price=="number"&&e.jsx("span",{className:"font-mono text-2xl font-semibold tracking-[-0.05em] text-foreground",children:Q(t.price,t.currency)}),o&&e.jsx("span",{className:"text-sm text-muted-foreground line-through",children:Q(o,t.currency)})]}),n&&e.jsx("p",{className:"mt-1 text-xs font-medium text-muted-foreground",children:s("product.youSave",{amount:Q(t.savings,t.currency)})})]}),typeof t.valueScore=="number"&&e.jsxs("div",{className:"hidden text-right text-xs text-muted-foreground sm:block",children:[e.jsx("p",{children:s("product.value")}),e.jsx("p",{className:"font-mono font-semibold text-foreground",children:Math.round(t.valueScore)})]})]}),e.jsxs("div",{className:"flex gap-2",onClick:S=>S.stopPropagation(),children:[t.url?e.jsx(L,{asChild:!0,variant:"default",size:"sm",className:"flex-1",children:e.jsxs("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center gap-1.5 text-xs",children:[s("product.viewOffer"),e.jsx(ss,{className:"size-3.5"})]})}):e.jsx(L,{variant:"outline",size:"sm",className:"flex-1",disabled:!0,children:s("product.noOffer")}),e.jsx(Ut,{item:t,className:"shrink-0"})]})]})]})]})},t.id)};return e.jsxs(Ot,{title:s("header.title"),description:s("header.description"),hideHeader:!0,children:[Ae&&e.jsx("div",{className:"max-w-4xl",children:e.jsx(At,{title:s("error.title"),message:Ae.userMessage,onDismiss:()=>X(null)})}),e.jsx(Ht,{eyebrow:"Decision workspace",icon:mt,title:g.length?`Review ${g.length} products for ${q}`:"Run or refine a sourcing search.",description:g.length?s("workspace.description",{count:B.totalProducts,sellers:B.sellerCount}):s("header.description"),actions:e.jsxs(e.Fragment,{children:[e.jsx(L,{asChild:!0,variant:"outline",children:e.jsx(rt,{to:"/search",children:s("header.actions.startNewSearch")})}),re>0&&e.jsxs(L,{variant:"outline",onClick:()=>v("/comparison"),children:[e.jsx(dt,{className:"size-4"}),s("header.actions.compare",{count:re})]})]}),aside:e.jsxs("form",{onSubmit:St,className:"flex w-full flex-wrap items-center gap-3 sm:flex-nowrap",children:[e.jsxs("div",{className:"relative min-w-[220px] flex-1",children:[e.jsx(st,{className:"pointer-events-none absolute left-4 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}
11),e.jsx("input",{type:"text",value:pe,onChange:t=>Le(t.target.value),placeholder:s("search.placeholder"),className:"h-11 w-full rounded-md border border-border/70 bg-background/70 pl-11 pr-4 text-sm text-foreground placeholder:text-muted-foreground transition focus:border-foreground focus:outline-none",disabled:M||se})]}),e.jsx(L,{type:"submit",disabled:!pe.trim()||M||se,className:"w-full px-6 sm:w-auto",children:M?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"size-4 animate-spin"}),s("search.searching")]}):se?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"size-4 animate-spin"}),s("search.analyzingQuery")]}):s(Fe?"search.updateDetails":"search.searchButton")}),re>0&&e.jsxs(L,{type:"button",variant:"outline",className:"w-full px-5 sm:w-auto",onClick:()=>v("/comparison"),children:[e.jsx(dt,{className:"size-4"}),s("header.actions.compare",{count:re})]})]})}),g.length>0&&e.jsx(nt,{className:"p-0",children:e.jsxs("div",{className:"space-y-5 p-4 sm:p-6",children:[e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1fr)_300px]",children:[e.jsx(Vt,{eyebrow:s("workspace.eyebrow"),title:s("workspace.title",{query:q}),description:s("workspace.description",{count:B.totalProducts,sellers:B.sellerCount})}),e.jsxs("div",{className:"rounded-lg border border-border/60 bg-background/35 p-4",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:s("workspace.sortTitle")}),e.jsx("div",{className:"mt-3",children:e.jsx(ce,{value:Ne,onChange:t=>Se(t),options:[{value:"best-match",label:s("sort.bestMatch")},{value:"best-value",label:s("sort.bestValue")},{value:"price-asc",label:s("sort.priceAsc")},{value:"price-desc",label:s("sort.priceDesc")},{value:"rating-desc",label:s("sort.ratingDesc")},{value:"savings-desc",label:s("sort.savingsDesc")}],size:"sm","aria-label":s("workspace.sortTitle")})})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(de,{label:s("metrics.shown"),value:D.visibleCount,detail:q,icon:mt}),e.jsx(de,{label:s("metrics.markets"),value:B.sellerCount,detail:s("savingsHero.subtitle",{count:B.totalProducts,sellers:B.sellerCount}),icon:$t}),e.jsx(de,{label:s("metrics.averagePrice"),value:D.averagePrice===null?"—":Q(D.averagePrice),detail:s("metrics.exactMatches",{count:D.exactCount}),icon:ft}),e.jsx(de,{label:s("metrics.confidence"),value:D.averageScore===null?"—":Math.round(D.averageScore),detail:D.averageRating===null?s("metrics.noRatings"):s("metrics.averageRating",{rating:D.averageRating.toFixed(1)}),icon:ut})]}),N.length>1&&e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:N.map(t=>{const r=t.id===((A==null?void 0:A.id)??"");return e.jsxs("button",{type:"button",onClick:()=>kt(t.id),className:K("shrink-0 rounded-md border px-3 py-2 text-left text-xs transition",r?"border-foreground bg-foreground text-background":"border-border bg-background text-muted-foreground hover:border-foreground
11/40 hover:text-foreground"),children:[e.jsx("span",{className:"block max-w-[18rem] truncate font-medium",children:t.query}),e.jsx("span",{className:"opacity-70",children:s("queries.results",{count:t.items.length})})]},t.id)})}),e.jsxs("div",{className:"rounded-lg border border-border/60 bg-background/30 p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx(Ee,{className:"size-3.5"}),s("filters.label")]}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2 xl:grid-cols-[1fr_1fr_1fr_auto]",children:[ie.length>1&&e.jsx(ce,{value:f.seller,onChange:t=>O("seller",t),options:[{value:"",label:s("filters.allSellers")},...ie.map(t=>({value:t.value,label:t.label}))],size:"sm","aria-label":s("filters.allSellers")}),ae.length>1&&e.jsx(ce,{value:f.category,onChange:t=>O("category",t),options:[{value:"",label:s("filters.allCategories")},...ae.map(t=>({value:t.value,label:t.label}))],size:"sm","aria-label":s("filters.allCategories")}),oe.length>1&&e.jsx(ce,{value:f.brand,onChange:t=>O("brand",t),options:[{value:"",label:s("filters.allBrands")},...oe.map(t=>({value:t.value,label:t.label}))],size:"sm","aria-label":s("filters.allBrands")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:0,value:f.minPrice,onChange:t=>O("minPrice",t.target.value),className:"h-10 min-w-0 flex-1 rounded-md border border-border/70 bg-background/75 px-3 text-xs text-foreground focus:border-foreground focus:outline-none",placeholder:s("filters.minPricePlaceholder")}),e.jsx("input",{type:"number",min:0,value:f.maxPrice,onChange:t=>O("maxPrice",t.target.value),className:"h-10 min-w-0 flex-1 rounded-md border border-border/70 bg-background/75 px-3 text-xs text-foreground focus:border-foreground focus:outline-none",placeholder:s("filters.maxPricePlaceholder")}),e.jsx("button",{type:"button",onClick:()=>O("primeOnly",!f.primeOnly),className:K("h-10 rounded-md border px-3 text-xs font-medium transition",f.primeOnly?"border-foreground bg-muted text-foreground":"border-border text-muted-foreground hover:border-foreground
11/30"),children:"Prime"})]})]})]}),Ze.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/55 pt-3",children:[Ze.map(({key:t,label:r})=>e.jsxs(U,{variant:"secondary",className:"flex items-center gap-1 rounded-md px-2 py-0.5 text-[11px]",children:[r,e.jsx("button",{type:"button",className:"rounded-sm p-0.5 text-muted-foreground transition hover:text-foreground",onClick:()=>jt(t),children:e.jsx(Dt,{className:"size-2.5"})})]},t)),e.jsx("button",{type:"button",onClick:Z,className:"text-xs text-muted-foreground transition hover:text-foreground",children:s("filters.clearAll")})]})]})}),Fe&&e.jsxs(Ie,{ref:Be,className:"mt-4 space-y-5 border-border/65 bg-card/85 px-6 py-5 shadow-none",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex size-11 items-center justify-center rounded-md border border-border/65 bg-muted/35 text-muted-foreground",children:e.jsx(Ee,{className:"size-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:s("refinement.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(y==null?void 0:y.reason)||s("refinement.defaultReason")})]})]}),e.jsx("div",{className:"rounded-md border border-border bg-background px-4 py-1 text-xs text-muted-foreground",children:ee})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:y==null?void 0:y.options.map(t=>{const r=(k==null?void 0:k.id)===t.id;return e.jsxs("button",{type:"button",onClick:()=>te(t.id),className:K("rounded-lg border px-4 py-3 text-left transition-colors",r?"border-foreground
11/70 bg-background":"border-border bg-transparent hover:border-foreground/40"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm font-semibold",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gt,{className:`size-4 ${r?"text-foreground":"text-muted-foreground"}`}),e.jsx("span",{className:r?"text-foreground":"text-muted-foreground",children:t.label})]}),t.askForQuantity&&e.jsx(U,{variant:"outline",className:"rounded-md border-border text-[10px] uppercase tracking-[0.2em] text-foreground",children:s("refinement.queryBadge")})]}),t.description&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:t.description}),t.unitLabel&&e.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:s("refinement.unitHint",{unit:t.unitLabel})})]},t.id)})}),e.jsxs("div",{className:K("grid gap-4",k!=null&&k.askForQuantity?"md:grid-cols-2":""),children:[(k==null?void 0:k.askForQuantity)&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:s("refinement.quantity")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:"0",step:"0.01",inputMode:"decimal",value:he,onChange:t=>be(t.target.value),placeholder:"120",className:"flex-1 rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:border-foreground focus:outline-none"}),e.jsx("span",{className:"rounded-md border border-border bg-transparent px-3 py-1 text-xs font-semibold text-muted-foreground",children:Ue})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:s("refinement.constraints")}),e.jsx(Jt,{value:ye,onChange:t=>ve(t.target.value),placeholder:s("refinement.constraintsPlaceholder"),className:"min-h-[90px]"})]})]}),y!=null&&y.followUpQuestions.length?e.jsxs("div",{className:"rounded-lg border border-border bg-transparent px-4 py-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground",children:s("refinement.followUps")}),e.jsx("ul",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:y.followUpQuestions.map((t,r)=>e.jsxs("li",{children:["• ",t]},`${t}-${r}`))})]}):null,e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3",children:[e.jsx(L,{type:"button",variant:"ghost",onClick:Ct,disabled:M,children:s("refinement.buttons.cancel")}),e.jsx(L,{type:"button",variant:"outline",onClick:()=>Ye(!1),disabled:M,children:s("refinement.buttons.searchWithout")}),e.jsx(L,{type:"button",className:"px-6",onClick:()=>Ye(!0),disabled:M,children:M?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"mr-2 size-4 animate-spin"}),s("search.searching")]}):s("refinement.buttons.searchWith")})]})]}),e.jsx(Zt,{}),Ve&&(()=>{const t=[{key:"vector",label:s("streaming.vector","Database")},{key:"local",label:s("streaming.local","Local")},{key:"national",label:s("streaming.national","National")}],r=t.findIndex(a=>a.key===h.phase);return e.jsxs(nt,{className:"px-5 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[e.jsx(Y,{className:"size-4 animate-spin text-foreground"}),yt]}),g.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[g.length," ",g.length===1?s("streaming.product","product"):s("streaming.products","products")," ",s("streaming.found","found")]})]}),e.jsx("div",{className:"flex items-center gap-1",children:t.map((a,l)=>{const n=r>l,o=r===l;return e.jsxs("div",{className:"flex-1 flex flex-col gap-1",children:[e.jsx("div",{className:K("h-1.5 rounded-full transition-all duration-500",n?"bg-foreground":o?"bg-foreground
11/50 animate-pulse":"bg-muted")}),e.jsx("span",{className:K("text-[10px] text-center",n?"font-medium text-foreground":o?"font-medium text-foreground/70":"text-muted-foreground/50"),children:a.label})]},a.key)})})]})})(),g.length===0&&!M&&!Ve&&e.jsx(at,{icon:st,title:s("empty.noResults"),description:s("empty.noResultsDescription"),children:e.jsx(L,{asChild:!0,variant:"outline",children:e.jsx(rt,{to:"/search",children:s("empty.startSearch")})})}),M&&e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:Array.from({length:12}).map((t,r)=>e.jsxs(Ie,{className:"overflow-hidden",children:[e.jsx(T,{className:"aspect-[4/3] w-full"}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx(T,{className:"h-3 w-1/3"}),e.jsx(T,{className:"h-4 w-3/4"}),e.jsx(T,{className:"h-4 w-1/2"}),e.jsx(T,{className:"h-6 w-1/3"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{className:"h-8 flex-1 rounded-xl"}),e.jsx(T,{className:"h-8 w-8 rounded-xl"})]})]})]},r))}),!M&&We.length>0&&e.jsxs("section",{children:[le.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ut,{className:"size-5 text-foreground"}),e.jsx("h2",{className:"text-base font-bold text-foreground",children:s("sections.exactMatches")})]}),e.jsxs(U,{variant:"secondary",className:"rounded-md text-xs",children:[_.length," ",s("sections.products")]}),e.jsx("div",{className:"flex-1 h-px bg-border/20"})]}),e.jsx("p",{className:"text-xs text-muted-foreground ml-7",children:s("sections.exactDesc",{query:q})})]}),e.jsx("div",{className:"grid gap-4 lg:grid-cols-2 2xl:grid-cols-3",children:We.map(Ge)})]}),!M&&Xe.length>0&&e.jsxs("section",{children:[_.length>0&&e.jsxs("div",{className:"mb-4 mt-8",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{className:"size-5 text-foreground"}),e.jsx("h2",{className:"text-base font-bold text-foreground",children:s("sections.variations")})]}),e.jsxs(U,{variant:"secondary",className:"rounded-md text-xs",children:[le.length," ",s("sections.products")]}),e.jsx("div",{className:"flex-1 h-px bg-border/20"})]}),e.jsx("p",{className:"text-xs text-muted-foreground ml-7",children:s("sections.variationsDesc")})]}),e.jsx("div",{className:"grid gap-4 lg:grid-cols-2 2xl:grid-cols-3",children:Xe.map(Ge)})]}),!M&&!Pt&&g.length>0&&e.jsx(at,{icon:Ee,title:s("empty.noMatchesFilters"),description:s("empty.noMatchesDescription"),children:e.jsx(L,{variant:"outline",onClick:Z,children:s("filters.clearAll")})}),!M&&vt&&e.jsx("div",{ref:_e,className:"flex items-center justify-center py-8",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Y,{className:"size-4 animate-spin"}),s("loading.more")]})})]})}export{Ds 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.