import{cD as R,dD as E,eD as l,fD as i,gD as c,hD as w,iD as O,mD as y,nD as e}from"./cli-0.5.3-jbzr8k4s.mjs";import{xU as x,yU as s}from"./cli-0.5.3-hx550gz2.mjs";import{IW as k,KW as W,cX as Q,nX as K,pV as n,xW as j,yW as r}from"./cli-0.5.3-842pf3t4.mjs";import{MY as A,NY as V,OY as D,PY as v}from"./cli-0.5.3-vqmxwet2.mjs";import{QY as t}from"./cli-0.5.3-rch86nhn.mjs";import{Tma as q,Xma as p}from"./cli-0.5.3-0df3r78b.mjs";function X1(J){let b=S.c(17),{query:$,placeholder:N,isFocused:Z,isTerminalFocused:H,prefix:g,width:P,cursorOffset:_,borderless:Y}=J,G=N===void 0?"Search…":N,h=g===void 0?"⌕":g,L=Y===void 0?!1:Y,B=_??$.length,m=L?void 0:"round",z=Z?"suggestion":void 0,d=!Z,F=L?0:1,T=!Z,X;if(b[0]!==Z||b[1]!==H||b[2]!==B||b[3]!==G||b[4]!==$)X=Z?V(A,{children:$?H?D(A,{children:[V(W,{children:$.slice(0,B)}),V(W,{inverse:!0,children:B<$.length?$[B]:" "}),B<$.length&&V(W,{children:$.slice(B+1)})]}):V(W,{children:$}):H?D(A,{children:[V(W,{inverse:!0,children:G.charAt(0)}),V(W,{dimColor:!0,children:G.slice(1)})]}):V(W,{dimColor:!0,children:G})}):$?V(W,{children:$}):V(W,{children:G}),b[0]=Z,b[1]=H,b[2]=B,b[3]=G,b[4]=$,b[5]=X;else X=b[5];let M;if(b[6]!==h||b[7]!==T||b[8]!==X)M=D(W,{dimColor:T,children:[h," ",X]}),b[6]=h,b[7]=T,b[8]=X,b[9]=M;else M=b[9];let I;if(b[10]!==M||b[11]!==m||b[12]!==z||b[13]!==d||b[14]!==F||b[15]!==P)I=V(k,{flexShrink:0,borderStyle:m,borderColor:z,borderDimColor:d,paddingX:F,width:P,children:M}),b[10]=M,b[11]=m,b[12]=z,b[13]=d,b[14]=F,b[15]=P,b[16]=I;else I=b[16];return I}var S;var u=p(()=>{K();v();S=q(n(),1)});function d1(J){if(J.ctrl&&(J.key==="k"||J.key==="u"||J.key==="w"))return!0;if(J.meta&&J.key==="backspace")return!0;return!1}function T1(J){return(J.ctrl||J.meta)&&J.key==="y"}function W1({isActive:J,onExit:b,onCancel:$,onExitUp:N,columns:Z,passthroughCtrlKeys:H=[],initialQuery:g="",backspaceExitsOnEmpty:P=!0}){let{columns:_}=x(),Y=Z??_,[G,h]=U.useState(g),[L,B]=U.useState(g.length),m=U.useCallback((d)=>{h(d),B(d.length)},[]),z=(d)=>{if(!J)return;let F=y.fromText(G,Y,L);if(d.ctrl&&H.includes(d.key.toLowerCase()))return;if(!d1(d))l();if(!T1(d))O();if(d.key==="return"||d.key==="down"){d.preventDefault(),b();return}if(d.key==="up"){if(d.preventDefault(),N)N();return}if(d.key==="escape"){if(d.preventDefault(),$)$();else if(G.length>0)h(""),B(0);else b();return}if(d.key==="backspace"){if(d.preventDefault(),d.meta){let{cursor:X,killed:M}=F.deleteWordBefore();R(M,"prepend"),h(X.text),B(X.offset);return}if(G.length===0){if(P)($??b)();return}let T=F.backspace();h(T.text),B(T.offset);return}if(d.key==="delete"){d.preventDefault();let T=F.del();h(T.text),B(T.offset);return}if(d.key==="left"&&(d.ctrl||d.meta||d.fn)){d.preventDefault();let T=F.prevWord();B(T.offset);return}if(d.key==="right"&&(d.ctrl||d.meta||d.fn)){d.preventDefault();let T=F.nextWord();B(T.offset);return}if(d.key==="left"){d.preventDefault();let T=F.left();B(T.offset);return}if(d.key==="right"){d.preventDefault();let T=F.right();B(T.offset);return}if(d.key==="home"){d.preventDefault(),B(0);return}if(d.key==="end"){d.preventDefault(),B(G.length);return}if(d.ctrl){switch(d.preventDefault(),d.key.toLowerCase()){case"a":B(0);return;case"e":B(G.length);return;case"b":B(F.left().offset);return;case"f":B(F.right().offset);return;case"d":{if(G.length===0){($??b)();return}let T=F.del();h(T.text),B(T.offset);return}case"h":{if(G.length===0){if(P)($??b)();return}let T=F.backspace();h(T.text),B(T.offset);return}case"k":{let{cursor:T,killed:X}=F.deleteToLineEnd();R(X,"append"),h(T.text),B(T.offset);return}case"u":{let{cursor:T,killed:X}=F.deleteToLineStart();R(X,"prepend"),h(T.text),B(T.offset);return}case"w":{let{cursor:T,killed:X}=F.deleteWordBefore();R(X,"prepend"),h(T.text),B(T.offset);return}case"y":{let T=E();if(T.length>0){let X=F.offset,M=F.insert(T);i(X,T.length),h(M.text),B(M.offset)}return}case"g":case"c":if($){$();return}}return}if(d.meta){switch(d.preventDefault(),d.key.toLowerCase()){case"b":B(F.prevWord().offset);return;case"f":B(F.nextWord().offset);return;case"d":{let T=F.deleteWordAfter();h(T.text),B(T.offset);return}case"y":{let T=c();if(T){let{text:X,start:M,length:I}=T,f=G.slice(0,M),a=G.slice(M+I),C=f+X+a,o=M+X.length;w(X.length),h(C),B(o)}return}}return}if(d.key==="tab")return;if(d.key.length>=1&&!b1.has(d.key)){d.preventDefault();let T=F.insert(d.key);h(T.text),B(T.offset)}};return Q((d,F,T)=>{z(new j(T.keypress))},{isActive:J}),{query:G,setQuery:m,cursorOffset:L,handleKeyDown:z}}var U,b1;var B1=p(()=>{r();K();e();s();U=q(t(),1);b1=new Set(["pageup","pagedown","insert","wheelup","wheeldown","mouse","f1","f2","f3","f4","f5","f6","f7","f8","f9","f10","f11","f12"])});
export{X1 as gg,u as hg,W1 as ig,B1 as jg};
