import"./CWj6FrbW.js";import{F as q,p as E,g as H,u as N,aB as R,f as M,d as A,t as T,b as z,c as I,r as C,aC as j,h as _,l as F,e as K,j as O}from"./DhlfkVbH.js";import{w as U,a as L,o as G,c as J}from"./CwfCwap7.js";import{s as w}from"./Chh6QAMO.js";import{s as V}from"./BvHT2aoj.js";import{p as h,s as P,a as Q}from"./BzCf-tSc.js";import{b as W}from"./BFwtWT9F.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 re(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=H([]);let u=null;const x=U(null);N(()=>{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 S(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&&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 D(n){if(!t.length)return;const c=((u?o(u):0)+n+t.length)%t.length;s(t[c].value,!0)}R("rc-tabs",{value:x,requestSelect:n=>s(n),register:S,unregister:b});var k=Y(),v=A(k);v.__keydown=[X,d,t,s,D];var B=A(v);L(B,()=>e.children),C(v),C(k),T(()=>{V(k,1,`w-full ${r()}`,"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 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 ue(a,e){E(e,!0);const l=()=>Q(S,"$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=K(null);const s=j("rc-tabs"),S=s.value;let b=F(()=>l()===r());G(()=>{s==null||s.register({id:d(),value:r(),getEl:()=>_(y)})}),J(()=>{s==null||s.unregister(d())});var o=p();let D;o.__click=[Z,t,s,r,e];var k=A(o);L(k,()=>e.children),C(o),W(o,v=>O(y,v),()=>_(y)),T(v=>{D=V(o,1,`tab ${u()??""}`,"svelte-184qymf",D,v),o.disabled=t(),w(o,"id",d()),w(o,"aria-selected",_(b)),w(o,"aria-controls",`panel-${r()}`),w(o,"tabindex",_(b)?0:-1)},[()=>({active:_(b)})]),z(a,o),I(),f()}q(["click"]);export{re as T,ue as a};
