import{i as f,b as i,A as m,o as g,a as u,t as h}from"./vendor-lit-B2r-dKc0.js";import{a as p}from"./vendor-mini-lit-CpUQub-j.js";import{H as d,G as x,k as v,as as y,A as $}from"./vendor-lucide-B9Yl1Gez.js";import"./vendor-marked-_iteVaMm.js";var b=Object.defineProperty,_=Object.getOwnPropertyDescriptor,c=(e,s,r,t)=>{for(var n=t>1?void 0:t?_(s,r):s,a=e.length-1,l;a>=0;a--)(l=e[a])&&(n=(t?l(s,r,n):l(n))||n);return t&&n&&b(s,r,n),n};let o=class extends f{constructor(){super(...arguments),this.results=[],this.loading=!1,this.query=""}createRenderRoot(){return this}_handleClick(e){this.dispatchEvent(new CustomEvent("result-click",{bubbles:!0,composed:!0,detail:{type:e.type,id:e.id,sessionId:e.sessionId,goalId:e.goalId}}))}render(){if(this.loading&&this.results.length===0)return i`
				<div class="flex items-center justify-center py-8 text-muted-foreground text-sm gap-2">
					<span class="inline-block animate-spin">${p(d,"sm")}</span>
					Searching…
				</div>
			`;if(!this.loading&&this.query&&this.results.length===0)return i`
				<div class="flex flex-col items-center justify-center py-8 text-muted-foreground text-sm gap-1">
					<span>No matches for "${this.query}"</span>
				</div>
			`;if(!this.query)return m;const e=this.results.filter(t=>t.type==="goal"),s=this.results.filter(t=>t.type==="session"),r=this.results.filter(t=>t.type==="message");return i`
			<div class="flex flex-col gap-1 px-2 pb-2 overflow-y-auto text-sm">
				${this.loading?i`
					<div class="flex items-center gap-1.5 px-2 py-1 text-xs text-muted-foreground">
						<span class="inline-block animate-spin">${p(d,"sm")}</span>
						Updating…
					</div>
				`:""}
				${e.length?this._renderGroup("Goals",x,e):""}
				${s.length?this._renderGroup("Sessions",v,s):""}
				${r.length?this._renderGroup("Messages",y,r):""}
			</div>
		`}_renderGroup(e,s,r){return i`
			<div class="mb-1">
				<div class="flex items-center gap-1.5 px-2 py-1 text-xs font-medium text-muted-foreground uppercase tracking-wider">
					${p(s,"sm")}
					${e}
					<span class="ml-auto text-[10px] tabular-nums">${r.length}</span>
				</div>
				${r.map(t=>this._renderResult(t))}
			</div>
		`}_renderResult(e){const s=e.type==="message"&&e.sessionTitle||e.title;return i`
			<button
				class="w-full text-left px-2 py-1.5 rounded-md hover:bg-accent/50 transition-colors cursor-pointer flex flex-col gap-0.5 group"
				@click=${()=>this._handleClick(e)}
			>
				<div class="flex items-center gap-1.5 min-w-0">
					<span class="truncate font-medium text-foreground text-xs">${s||"Untitled"}</span>
					${e.archived?i`
						<span class="shrink-0 inline-flex items-center gap-0.5 px-1 py-0 rounded text-[10px] bg-muted text-muted-foreground">
							${p($,"xs")}
						</span>
					`:""}
					<span class="ml-auto shrink-0 text-[10px] text-muted-foreground tabular-nums">
						${w(e.timestamp)}
					</span>
				</div>
				${e.snippet?i`
					<div class="text-xs text-muted-foreground line-clamp-2 leading-relaxed search-snippet">
						${g(M(e.snippet))}
					</div>
				`:""}
			</button>
		`}};c([u({attribute:!1})],o.prototype,"results",2);c([u({type:Boolean})],o.prototype,"loading",2);c([u({type:String})],o.prototype,"query",2);o=c([h("search-results")],o);function w(e){if(!e)return"";const s=Math.max(0,Date.now()-e),r=Math.floor(s/1e3);if(r<60)return"now";const t=Math.floor(r/60);if(t<60)return`${t}m`;const n=Math.floor(t/60);if(n<24)return`${n}h`;const a=Math.floor(n/24);return a<30?`${a}d`:`${Math.floor(a/30)}mo`}function M(e){return e.replace(/<b>/gi,"\0B").replace(/<\/b>/gi,"\0E").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\x00B/g,"<b>").replace(/\x00E/g,"</b>")}export{o as SearchResults};
