import"./CWj6FrbW.js";import{D as C,p as E,ay as N,u as R,aq as B,f as M,d as A,t as T,b as z,c as I,r as q,ao as K,g as _,k as O,e as U,i as j}from"./DOPisAOl.js";import{a as L}from"./Xc3_nZLd.js";import{s as y}from"./CGcWBEH0.js";import{s as V}from"./eylS3834.js";import{p as m,s as F,a as G}from"./DO9Exidn.js";import{w as J}from"./yjlNamjV.js";import{o as P,a as Q}from"./x2n8lXq-.js";import{b as W}from"./CEk_xq3X.js";function X(a,e,l,h,f){const r=e()==="horizontal";if(a.key==="Home"){a.preventDefault(),l.length&&h(l[0].value,!0);return}if(a.key==="End"){a.preventDefault(),l.length&&h(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 oe(a,e){E(e,!0);let l=m(e,"value",11,null),h=m(e,"defaultValue",3,null),f=m(e,"ariaLabel",3,"Tabs"),r=m(e,"class",3,""),d=m(e,"orientation",3,"horizontal");const t=N([]);let u=null;const x=J(null);R(()=>{l()!==null?u=l():u===null&&t.length&&(u=h()??t[0].value),x.set(u)});function w(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(()=>w(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(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)}B("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 H=A(v);L(H,()=>e.children),q(v),q(k),T(()=>{V(k,1,`w-full ${r()}`,"svelte-126ak3w"),y(v,"aria-label",f()),y(v,"aria-orientation",d())}),z(a,k),I()}C(["keydown"]);function Z(a,e,l,h,f){var r;e()||(l==null||l.requestSelect(h()),(r=f.onclick)==null||r.call(f,a))}var p=M('<button type="button" role="tab"><!></button>');function se(a,e){E(e,!0);const l=()=>G(S,"$valueStore",h),[h,f]=F();let r=m(e,"value",7,""),d=m(e,"id",7,""),t=m(e,"disabled",3,!1),u=m(e,"class",3,"");const x=Math.random().toString(36).slice(2,8);d()||d(`tab-${x}`),r()||r(d());let w=U(null);const s=K("rc-tabs"),S=s.value;let b=O(()=>l()===r());P(()=>{s==null||s.register({id:d(),value:r(),getEl:()=>_(w)})}),Q(()=>{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),q(o),W(o,v=>j(w,v),()=>_(w)),T(v=>{D=V(o,1,`tab ${u()??""}`,"svelte-184qymf",D,v),o.disabled=t(),y(o,"id",d()),y(o,"aria-selected",_(b)),y(o,"aria-controls",`panel-${r()}`),y(o,"tabindex",_(b)?0:-1)},[()=>({active:_(b)})]),z(a,o),I(),f()}C(["click"]);export{oe as T,se as a};
