"use strict";const o=require("./jsx-runtime-Cek9Ww4S.cjs"),d=require("./Toggle-C-n_Itw1.cjs"),S=require("react"),g=require("./Pack-BNnq0Pnk.cjs"),u=require("./css-C4GOlJsi.cjs"),z=require("./aggregator-C5NNOlCt.cjs"),m=require("zod"),T=(l="",s=[])=>{var t;if(s.length!==0)return s.find(n=>n.tabKey===l)!=null?l:(t=s[s.length-1])==null?void 0:t.tabKey},q=(l,s,t)=>{if(s=s.trim(),s.length===0)return t;const n=t.find(e=>e.tabKey===l);return n==null||n.name===s?t:t.map(e=>e.tabKey===l?{...e,name:s}:e)},y=({tabs:l,content:s,selected:t,onSelect:n})=>{var a;const[e,r]=z.usePurePassthrough({initial:t??((a=l[0])==null?void 0:a.tabKey)??"",value:t,onChange:n}),c=d.useSyncedRef(t??e),i=S.useCallback(x=>{r(x),c.current==null&&(n==null||n(x))},[e,n]);return{tabs:l,selected:e,content:s,onSelect:i}},k=S.createContext({tabs:[]}),B=()=>S.useContext(k),N=({id:l,content:s,children:t,onSelect:n,selected:e,selectedAltColor:r,closable:c,tabs:i,onClose:a,onDragStart:x,onDragEnd:h,onCreate:C,onRename:E,emptyContent:R,className:b,onDragOver:p,onDrop:v,size:j="medium",direction:P="y",...M})=>o.jsxRuntimeExports.jsx(g.Space,{id:l,empty:!0,className:u.CSS(u.CSS.B("tabs"),b),onDragOver:p,onDrop:v,direction:P,...M,children:o.jsxRuntimeExports.jsxs(k.Provider,{value:{tabs:i,emptyContent:R,selected:e,closable:c,content:t??s,onSelect:n,onClose:a,onDragStart:x,onDragEnd:h,onRename:E,onCreate:C,onDrop:v},children:[o.jsxRuntimeExports.jsx(w,{size:j,direction:u.g.swap(P),altColor:r}),o.jsxRuntimeExports.jsx(_,{})]})}),Z=k.Provider,_=()=>{const{tabs:l,selected:s,content:t,emptyContent:n,onSelect:e}=B();let r=null;const c=l.find(i=>i.tabKey===s);return s==null||c==null?n??null:(t!=null?typeof t=="function"?r=t(c):r=t:c.content!=null&&(r=c.content),o.jsxRuntimeExports.jsx("div",{className:u.CSS.B("tabs-content"),onClick:()=>e==null?void 0:e(s),children:r}))},f="tabs-selector",w=({className:l,altColor:s=!1,size:t="medium",direction:n="x",...e})=>{const{tabs:r,selected:c,onSelect:i,onClose:a,closable:x,onDragEnd:h,onDragStart:C,onDrop:E,onRename:R,onCreate:b}=B();return o.jsxRuntimeExports.jsxs(g.Space,{className:u.CSS(u.CSS.B(f),u.CSS.size(t),l),align:"center",justify:"spaceBetween",onDrop:E,empty:!0,direction:n,...e,children:[o.jsxRuntimeExports.jsx(g.Space,{direction:n,className:u.CSS.BE(f,"tabs"),empty:!0,children:r.map(p=>o.jsxRuntimeExports.jsx(L,{selected:c,altColor:s,onSelect:i,onClose:a,onDragStart:C,onDragEnd:h,onRename:R,closable:p.closable??x,size:t,...p},p.tabKey))}),b!=null&&o.jsxRuntimeExports.jsx(g.Space,{className:u.CSS.BE(f,"actions"),children:o.jsxRuntimeExports.jsx(d.Icon,{size:t,sharp:!0,onClick:b,children:o.jsxRuntimeExports.jsx(d.St.Add,{})})})]})},L=({selected:l,altColor:s=!1,onSelect:t,onClose:n,tabKey:e,name:r,onDragStart:c,onDragEnd:i,onRename:a,closable:x=!0,icon:h,size:C,editable:E=!0})=>{const R=S.useCallback(j=>c==null?void 0:c(j,{tabKey:e,name:r}),[c,e,r]),b=S.useCallback(j=>i==null?void 0:i(j,{tabKey:e,name:r}),[i,e,r]),p=S.useCallback(j=>{j.stopPropagation(),n==null||n(e)},[n,e]),v=S.useCallback(()=>t==null?void 0:t(e),[t,e]);return o.jsxRuntimeExports.jsxs(g.Pack,{size:C,id:e,className:u.CSS(u.CSS.BE(f,"btn"),a==null&&u.CSS.BEM(f,"btn","uneditable"),u.CSS.selected(l===e),u.CSS.altColor(s),x&&n!=null&&u.CSS.BEM(f,"btn","closable")),draggable:!0,direction:"x",justify:"center",align:"center",onClick:v,onDragStart:R,onDragEnd:b,bordered:!1,rounded:!1,children:[o.jsxRuntimeExports.jsx(O,{name:r,tabKey:e,onRename:a,icon:h,editable:E,level:z.ComponentSizeLevels[C]}),x&&n!=null&&o.jsxRuntimeExports.jsx(d.Icon,{onClick:p,children:o.jsxRuntimeExports.jsx(d.St.Close,{"aria-label":"pluto-tabs__close"})})]})},O=({onRename:l,name:s,tabKey:t,icon:n,editable:e=!0,...r})=>l==null||!e?n!=null?o.jsxRuntimeExports.jsx(d.WithIcon,{startIcon:n,noWrap:!0,...r,children:s}):o.jsxRuntimeExports.jsx(d.Text,{noWrap:!0,...r,children:s}):o.jsxRuntimeExports.jsx(d.Editable,{onChange:c=>l(t,c),value:s,noWrap:!0,...r}),I=m.z.object({tabKey:m.z.string(),name:m.z.string(),closable:m.z.boolean().optional(),icon:m.z.unknown().optional(),editable:m.z.boolean().optional()}),W=I.extend({content:m.z.unknown().optional()}),A=Object.freeze(Object.defineProperty({__proto__:null,Content:_,Provider:Z,Selector:w,Tabs:N,TabsContext:k,rename:q,resetSelection:T,specZ:I,tabZ:W,useStatic:y,useTabsContext:B},Symbol.toStringTag,{value:"Module"}));exports.Tabs=N;exports.external=A;exports.rename=q;exports.resetSelection=T;exports.tabZ=W;exports.useStatic=y;
