import"./CWj6FrbW.js";import{A as q,p as E,g as N,u as R,ab as B,f as M,d as S,t as T,b as z,c as I,r as C,ac as K,h as _,l as O,e as U,i as j}from"./CVHvdSBf.js";import{w as F,a as L,o as G,c as J}from"./DujX6kBV.js";import{c as V,s as k}from"./BkclRFLx.js";import{p as h,s as P,a as Q}from"./yWz0pZR0.js";import{b as W}from"./DQqJYxgt.js";function X(a,e,l,g,f){const r=e()==="horizontal";if(a.key==="Home"){a.preventDefault(),l.length&&g(l[0].value,!0);return}if(a.key==="End"){a.preventDefault(),l.length&&g(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=M('<div><div class="tablist svelte-126ak3w" role="tablist"><!></div></div>');function ie(a,e){E(e,!0);let l=h(e,"value",11,null),g=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=F(null);R(()=>{l()!==null?u=l():u===null&&t.length&&(u=g()??t[0].value),x.set(u)});function y(n){var c;const i=t.find(m=>m.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 D(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(m=>m.id===n);if(i!==-1&&t.splice(i,1),l()===null&&u&&!t.some(m=>m.value===u)&&t.length){const m=t[Math.max(0,i-1)].value;u=m,(c=e.onChange)==null||c.call(e,{value:m})}}function o(n){return t.findIndex(i=>i.value===n)}function A(n){if(!t.length)return;const c=((u?o(u):0)+n+t.length)%t.length;s(t[c].value,!0)}B("rc-tabs",{value:x,requestSelect:n=>s(n),register:D,unregister:w});var b=Y(),v=S(b);v.__keydown=[X,d,t,s,A];var H=S(v);L(H,()=>e.children),C(v),C(b),T(()=>{V(b,1,`tabs-root ${r()}`,"svelte-126ak3w"),k(v,"aria-label",f()),k(v,"aria-orientation",d())}),z(a,b),I()}q(["keydown"]);function Z(a,e,l,g,f){var r;e()||(l==null||l.requestSelect(g()),(r=f.onclick)==null||r.call(f,a))}var p=M('<button type="button" role="tab"><!></button>');function re(a,e){E(e,!0);const l=()=>Q(D,"$valueStore",g),[g,f]=P();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=U(null);const s=K("rc-tabs"),D=s.value;let w=O(()=>l()===r());G(()=>{s==null||s.register({id:d(),value:r(),getEl:()=>_(y)})}),J(()=>{s==null||s.unregister(d())});var o=p();let A;o.__click=[Z,t,s,r,e];var b=S(o);L(b,()=>e.children),C(o),W(o,v=>j(y,v),()=>_(y)),T(v=>{A=V(o,1,`tab ${u()??""}`,"svelte-184qymf",A,v),o.disabled=t(),k(o,"id",d()),k(o,"aria-selected",_(w)),k(o,"aria-controls",`panel-${r()}`),k(o,"tabindex",_(w)?0:-1)},[()=>({active:_(w)})]),z(a,o),I(),f()}q(["click"]);export{ie as T,re as a};
