import{i as v,A as w,b as l,a as p,r as f,t as y}from"./vendor-lit-B2r-dKc0.js";var m=Object.defineProperty,k=Object.getOwnPropertyDescriptor,d=(e,t,o,c)=>{for(var r=c>1?void 0:c?k(t,o):t,n=e.length-1,s;n>=0;n--)(s=e[n])&&(r=(c?s(t,o,r):s(r))||r);return c&&r&&m(t,o,r),r};let a=class extends v{constructor(){super(...arguments),this.projects=[],this.anchorEl=null,this.open=!1,this._query="",this._highlightIndex=0,this._onDocPointerDown=e=>this._handleDocPointerDown(e),this._onDocKeyDown=e=>this._handleDocKeyDown(e),this._previousFocus=null,this._listenersBound=!1}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.style.display="contents"}disconnectedCallback(){super.disconnectedCallback(),this._unbindListeners()}updated(e){e.has("open")&&(this.open?this._onOpen():this._onClose())}_isMobile(){return typeof window<"u"&&window.innerWidth<640}_onOpen(){this._previousFocus=document.activeElement??null,this._highlightIndex=0,this._bindListeners(),queueMicrotask(()=>{this.querySelector(".bobbit-project-picker-search")?.focus()})}_onClose(){this._unbindListeners();try{const e=this.anchorEl??this._previousFocus;e&&typeof e.focus=="function"&&e.focus()}catch{}this._previousFocus=null}_bindListeners(){this._listenersBound||(document.addEventListener("pointerdown",this._onDocPointerDown,!0),document.addEventListener("keydown",this._onDocKeyDown,!0),this._listenersBound=!0)}_unbindListeners(){this._listenersBound&&(document.removeEventListener("pointerdown",this._onDocPointerDown,!0),document.removeEventListener("keydown",this._onDocKeyDown,!0),this._listenersBound=!1)}_handleDocPointerDown(e){if(!this.open)return;const t=e.target;t&&(this.contains(t)||this.anchorEl&&this.anchorEl.contains(t)||this._fireClose())}_handleDocKeyDown(e){if(!this.open)return;const t=this._filteredProjects();switch(e.key){case"Escape":e.preventDefault(),e.stopPropagation(),this._fireClose();return;case"ArrowDown":e.preventDefault(),t.length>0&&(this._highlightIndex=(this._highlightIndex+1)%t.length);return;case"ArrowUp":e.preventDefault(),t.length>0&&(this._highlightIndex=(this._highlightIndex-1+t.length)%t.length);return;case"Enter":{if(t.length===0)return;const o=t[Math.max(0,Math.min(this._highlightIndex,t.length-1))];o&&(e.preventDefault(),this._pick(o.id));return}}}_filteredProjects(){const e=this._query.trim().toLowerCase();return e?this.projects.filter(t=>t.name.toLowerCase().includes(e)||t.id.toLowerCase().includes(e)):this.projects}_pick(e){this.dispatchEvent(new CustomEvent("project-pick",{detail:{projectId:e},bubbles:!0,composed:!0}))}_fireClose(){this.dispatchEvent(new CustomEvent("close",{bubbles:!0,composed:!0}))}_accent(e){return(document.documentElement.classList.contains("dark")?e.colorDark||e.colorLight:e.colorLight||e.colorDark)||e.color||"var(--muted-foreground)"}_computePosition(){const e=this.anchorEl,t=280;if(!e||typeof e.getBoundingClientRect!="function")return{top:16,left:16,flipRight:!1};const o=e.getBoundingClientRect(),c=typeof window<"u"?window.innerWidth:1024,r=o.bottom+4;let n=o.left,s=!1;return n+t>c-8&&(s=!0),{top:r,left:n,flipRight:s}}render(){if(!this.open)return w;const e=this._filteredProjects(),t=this._isMobile(),o=(i,h)=>{const u=h===this._highlightIndex,x=this._accent(i);return l`
				<button
					type="button"
					role="option"
					data-project-id=${i.id}
					aria-selected=${u?"true":"false"}
					class="bobbit-project-picker-row"
					style=${`display:flex;align-items:center;gap:8px;width:100%;text-align:left;padding:6px 10px;border:0;background:${u?"var(--accent, rgba(127,127,127,0.15))":"transparent"};color:inherit;cursor:pointer;font-size:13px;border-radius:4px;`}
					@mouseenter=${()=>{this._highlightIndex=h}}
					@click=${()=>this._pick(i.id)}
				>
					<span style=${`display:inline-block;width:10px;height:10px;border-radius:50%;background:${x};flex-shrink:0;`}></span>
					<span style="flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">${i.name}</span>
				</button>
			`},c=l`
			<div style="padding:8px 10px;border-bottom:1px solid var(--border);">
				<input
					type="text"
					class="bobbit-project-picker-search"
					placeholder="Search projects…"
					.value=${this._query}
					@input=${i=>{this._query=i.target.value,this._highlightIndex=0}}
					style="width:100%;padding:4px 8px;font-size:12px;border:1px solid var(--border);border-radius:4px;background:var(--background, transparent);color:inherit;outline:none;"
				/>
			</div>
		`,r=l`
			<div role="listbox" class="bobbit-project-picker-list" style="max-height:280px;overflow-y:auto;padding:4px;">
				${e.length===0?l`<div style="padding:10px;font-size:12px;color:var(--muted-foreground);text-align:center;">No projects match "${this._query}"</div>`:e.map((i,h)=>o(i,h))}
			</div>
		`,n=l`
			<div
				class="bobbit-project-picker"
				role="dialog"
				aria-label="Select a project"
				@click=${i=>i.stopPropagation()}
				style="background:var(--popover, var(--background, #1a1a2e));color:var(--popover-foreground, inherit);border:1px solid var(--border);border-radius:8px;box-shadow:0 4px 12px rgba(0,0,0,0.15);min-width:260px;max-width:360px;font-size:13px;"
			>
				${c}
				${r}
			</div>
		`;if(t)return l`
				<div
					class="bobbit-project-picker-backdrop"
					style="position:fixed;inset:0;z-index:50;background:rgba(0,0,0,0.4);display:flex;align-items:center;justify-content:center;padding:16px;"
					@click=${i=>{i.target===i.currentTarget&&this._fireClose()}}
				>
					<div style="width:100%;max-width:420px;">${n}</div>
				</div>
			`;const{top:s,left:g,flipRight:b}=this._computePosition(),_=b?`position:fixed;top:${s}px;right:8px;z-index:50;`:`position:fixed;top:${s}px;left:${g}px;z-index:50;`;return l`<div style=${_}>${n}</div>`}};d([p({attribute:!1})],a.prototype,"projects",2);d([p({attribute:!1})],a.prototype,"anchorEl",2);d([p({type:Boolean,reflect:!0})],a.prototype,"open",2);d([f()],a.prototype,"_query",2);d([f()],a.prototype,"_highlightIndex",2);a=d([y("project-picker-popover")],a);export{a as ProjectPickerPopover};
