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