var G=Object.defineProperty;var m=(e,o)=>G(e,"name",{value:o,configurable:!0});import{a7 as u,x as t,ah as X,a8 as T,n as O}from"../packem_chunks/bin.js";var Y=Object.defineProperty,W=m((e,o)=>Y(e,"name",{value:o,configurable:!0}),"n"),Z=Object.defineProperty,q=W((e,o)=>Z(e,"name",{value:o,configurable:!0}),"a"),_=Object.defineProperty,ee=q((e,o)=>_(e,"name",{value:o,configurable:!0}),"t");function P({children:e}){return u.jsx(u.Fragment,{children:e})}m(P,"r");W(P,"c");q(P,"o");ee(P,"Tab");var re=Object.defineProperty,z=m((e,o)=>re(e,"name",{value:o,configurable:!0}),"A"),ne=Object.defineProperty,B=z((e,o)=>ne(e,"name",{value:o,configurable:!0}),"A"),oe=Object.defineProperty,h=B((e,o)=>oe(e,"name",{value:o,configurable:!0}),"b");const te=/^\d$/u,ce=h(e=>e!=null&&typeof e=="object"&&"props"in e&&"name"in e.props,"isTabElement"),ae=h(e=>{const o=[];for(const c of t.Children.toArray(e))ce(c)&&o.push(c);return o},"collectTabs"),V=h((e,o)=>e.some(c=>o[c]),"matchesAnyKey"),ue=h((e,o,c)=>e?o?{backgroundColor:c?.activeTab?.backgroundColor??"green",color:c?.activeTab?.color??"black"}:{backgroundColor:"gray",color:"black"}:{backgroundColor:void 0,color:void 0},"getActiveTabColors");function E({children:e,colors:o,defaultValue:c,flexDirection:v="row",isFocused:g,keyMap:l,onChange:M,showIndex:H=!0,value:j,width:y}){const s=ae(e),a=s.length,d=t.useRef(s);d.current=s;const i=v==="column"||v==="column-reverse",C=j!==void 0,[J,L]=t.useState(()=>{const r=j??c;if(r==null||a===0)return 0;const n=s.findIndex(p=>p.props.name===r);return n===-1?0:n}),x=C?Math.max(0,s.findIndex(r=>r.props.name===j)):J,Q=t.useCallback(()=>{},[]),f=C?Q:L,b=t.useRef(M);b.current=M,t.useEffect(()=>{if(C)return;const r=d.current[x];r&&b.current(r.props.name,r)},[]);const R=t.useMemo(()=>l?.previous??[i?"upArrow":"leftArrow"],[l?.previous,i]),I=t.useMemo(()=>l?.next??[i?"downArrow":"rightArrow"],[l?.next,i]),$=l?.useNumbers??!0,D=l?.useTab??!0,k=t.useRef(x);k.current=x;const F=t.useCallback(r=>{f(r);const n=d.current[r];n&&b.current(n.props.name,n)},[f]),w=t.useCallback(()=>{const r=(k.current+1)%a;f(r);const n=d.current[r];n&&b.current(n.props.name,n)},[a,f]),A=t.useCallback(()=>{const r=(k.current-1+a)%a;f(r);const n=d.current[r];n&&b.current(n.props.name,n)},[a,f]);X(t.useCallback((r,n)=>{if(V(R,n)){A();return}if(V(I,n)){w();return}if(n.tab&&D&&g==null){n.shift?A():w();return}if($&&n.meta&&te.test(r)){const p=r==="0"?9:Number.parseInt(r,10)-1;p<a&&F(p)}},[R,I,D,$,g,A,w,a,F]),{isActive:g!==!1});const K=typeof y=="number"?y:6,U=t.useMemo(()=>i?"─".repeat(K):" | ",[i,K]);return u.jsx(T,{flexDirection:v,width:y,children:s.map((r,n)=>{const{name:p}=r.props,N=ue(x===n,g!==!1,o);let S=null;return H&&(S=u.jsxs(O,{color:"grey",children:[n+1,"."," "]})),u.jsxs(T,{flexDirection:v,children:[n!==0&&u.jsx(O,{color:"dim",children:U}),u.jsxs(T,{children:[S,u.jsx(O,{backgroundColor:N.backgroundColor,color:N.color,children:r})]})]},p)})})}m(E,"g");z(E,"or");B(E,"W");h(E,"Tabs");export{E as g,P as r};
