import"./CWj6FrbW.js";import{e as q,p as E,j as N,k as R,aH as j,f as I,d as A,t as M,b as T,c as z,r as C,aI as B,h as _,u as K,i as O,l as U}from"./BRMnbBOX.js";import{a as H,o as F,b as G}from"./CB3MYTwM.js";import{c as b}from"./3HVf2z3Q.js";import{s as L}from"./DMtzEpj5.js";import{p as h,s as J,a as P}from"./DCT4VKzQ.js";import{w as Q}from"./B394X4Dm.js";import{b as W}from"./CmatTLDp.js";function X(a,e,l,m,f){const r=e()==="horizontal";if(a.key==="Home"){a.preventDefault(),l.length&&m(l[0].value,!0);return}if(a.key==="End"){a.preventDefault(),l.length&&m(l[l.length-1].value,!0);return}if(r&&(a.key==="ArrowRight"||a.key==="ArrowLeft")){a.preventDefault(),f(a.key==="ArrowRight"?1:-1);return}if(!r&&(a.key==="ArrowDown"||a.key==="ArrowUp")){a.preventDefault(),f(a.key==="ArrowDown"?1:-1);return}}var Y=I('<div><div class="tablist svelte-126ak3w" role="tablist"><!></div></div>');function ue(a,e){E(e,!0);let l=h(e,"value",11,null),m=h(e,"defaultValue",3,null),f=h(e,"ariaLabel",3,"Tabs"),r=h(e,"class",3,""),d=h(e,"orientation",3,"horizontal");const t=N([]);let u=null;const x=Q(null);R(()=>{l()!==null?u=l():u===null&&t.length&&(u=m()??t[0].value),x.set(u)});function y(n){var c;const i=t.find(g=>g.value===n);(c=i==null?void 0:i.getEl())==null||c.focus()}function s(n,i=!1){var c;n!==(l()??u)&&(l()===null&&(u=n),(c=e.onChange)==null||c.call(e,{value:n}),i&&queueMicrotask(()=>y(n)))}function S(n){const i=t.findIndex(c=>c.id===n.id);i===-1?t.push(n):t[i]=n}function w(n){var c;const i=t.findIndex(g=>g.id===n);if(i!==-1&&t.splice(i,1),l()===null&&u&&!t.some(g=>g.value===u)&&t.length){const g=t[Math.max(0,i-1)].value;u=g,(c=e.onChange)==null||c.call(e,{value:g})}}function o(n){return t.findIndex(i=>i.value===n)}function D(n){if(!t.length)return;const c=((u?o(u):0)+n+t.length)%t.length;s(t[c].value,!0)}j("rc-tabs",{value:x,requestSelect:n=>s(n),register:S,unregister:w});var k=Y(),v=A(k);v.__keydown=[X,d,t,s,D];var V=A(v);H(V,()=>e.children),C(v),C(k),M(()=>{L(k,1,`tabs-root ${r()}`,"svelte-126ak3w"),b(v,"aria-label",f()),b(v,"aria-orientation",d())}),T(a,k),z()}q(["keydown"]);function Z(a,e,l,m,f){var r;e()||(l==null||l.requestSelect(m()),(r=f.onclick)==null||r.call(f,a))}var p=I('<button type="button" role="tab"><!></button>');function oe(a,e){E(e,!0);const l=()=>P(S,"$valueStore",m),[m,f]=J();let r=h(e,"value",7,""),d=h(e,"id",7,""),t=h(e,"disabled",3,!1),u=h(e,"class",3,"");const x=Math.random().toString(36).slice(2,8);d()||d(`tab-${x}`),r()||r(d());let y=O(null);const s=B("rc-tabs"),S=s.value;let w=K(()=>l()===r());F(()=>{s==null||s.register({id:d(),value:r(),getEl:()=>_(y)})}),G(()=>{s==null||s.unregister(d())});var o=p();let D;o.__click=[Z,t,s,r,e];var k=A(o);H(k,()=>e.children),C(o),W(o,v=>U(y,v),()=>_(y)),M(v=>{D=L(o,1,`tab ${u()??""}`,"svelte-184qymf",D,v),o.disabled=t(),b(o,"id",d()),b(o,"aria-selected",_(w)),b(o,"aria-controls",`panel-${r()}`),b(o,"tabindex",_(w)?0:-1)},[()=>({active:_(w)})]),T(a,o),z(),f()}q(["click"]);export{ue as T,oe as a};
