"use strict";const u=require("./jsx-runtime-evvPGacs.cjs"),d=require("react"),j=require("./Toggle-r0neBlcF.cjs"),R=require("./Center-7mG_M7Co.cjs"),o=require("./css-SuMNMmEe.cjs");require("react-hook-form");const y=require("./aggregator-Plx04vqJ.cjs"),B=(r="",e=[])=>{var t;if(e.length!==0)return e.find(s=>s.tabKey===r)!=null?r:(t=e[e.length-1])==null?void 0:t.tabKey},k=(r,e,t)=>{if(e=e.trim(),e.length===0)return t;const s=t.find(n=>n.tabKey===r);return s==null||s.name===e?t:t.map(n=>n.tabKey===r?{...n,name:e}:n)},T=({tabs:r,content:e,onSelect:t})=>{var c;const[s,n]=d.useState(((c=r[0])==null?void 0:c.tabKey)??""),l=d.useCallback(i=>{n(i),t==null||t(i)},[n,t]);return{tabs:r,selected:s,content:e,onSelect:l}},f=d.createContext({tabs:[]}),v=()=>d.useContext(f),q=({content:r,children:e,onSelect:t,selected:s,closable:n,tabs:l,onClose:c,onDragStart:i,onDragEnd:p,onCreate:h,onRename:m,emptyContent:E,className:b,onDragOver:S,onDrop:a,size:g="medium",direction:x="y",..._})=>u.jsxRuntimeExports.jsx(R.Space,{empty:!0,className:o.CSS(o.CSS.B("tabs"),b),onDragOver:S,onDrop:a,direction:x,..._,children:u.jsxRuntimeExports.jsxs(f.Provider,{value:{tabs:l,emptyContent:E,selected:s,closable:n,content:e??r,onSelect:t,onClose:c,onDragStart:i,onDragEnd:p,onRename:m,onCreate:h,onDrop:a},children:[u.jsxRuntimeExports.jsx(P,{size:g,direction:o.Cu.swap(x)}),u.jsxRuntimeExports.jsx(N,{})]})}),w=f.Provider,N=()=>{const{tabs:r,selected:e,content:t,emptyContent:s,onSelect:n}=v();let l=null;const c=r.find(i=>i.tabKey===e);return e==null||c==null?s??null:(t!=null?l=t(c):c.content!=null&&(l=c.content),u.jsxRuntimeExports.jsx("div",{className:o.CSS.B("tabs-content"),onClick:()=>n==null?void 0:n(e),style:{width:"100%",height:"100%",position:"relative",overflow:"hidden"},children:l}))},C="tabs-selector",P=({className:r,size:e="medium",direction:t="x",...s})=>{const{tabs:n,selected:l,onSelect:c,onClose:i,closable:p,onDragEnd:h,onDragStart:m,onDrop:E,onRename:b,onCreate:S}=v();return u.jsxRuntimeExports.jsxs(R.Space,{className:o.CSS(o.CSS.B(C),o.CSS.size(e),r),align:"center",justify:"spaceBetween",onDrop:E,empty:!0,direction:t,...s,children:[u.jsxRuntimeExports.jsx(R.Space,{direction:t,className:o.CSS.BE(C,"tabs"),empty:!0,children:n.map(a=>u.jsxRuntimeExports.jsx(I,{selected:l,onSelect:c,onClose:i,onDragStart:m,onDragEnd:h,onRename:b,closable:a.closable??p,size:e,...a},a.tabKey))}),u.jsxRuntimeExports.jsx(R.Space,{className:o.CSS.BE(C,"actions"),children:S!=null&&u.jsxRuntimeExports.jsx(j.Icon,{size:e,sharp:!0,onClick:S,children:u.jsxRuntimeExports.jsx(j.u0.Add,{})})})]})},I=({selected:r,onSelect:e,onClose:t,tabKey:s,name:n,onDragStart:l,onDragEnd:c,onRename:i,closable:p=!0,icon:h,size:m,editable:E=!0})=>{const b=d.useCallback(x=>l==null?void 0:l(x,{tabKey:s,name:n}),[l,s,n]),S=d.useCallback(x=>c==null?void 0:c(x,{tabKey:s,name:n}),[c,s,n]),a=d.useCallback(x=>{x.stopPropagation(),t==null||t(s)},[t,s]),g=d.useCallback(()=>e==null?void 0:e(s),[e,s]);return u.jsxRuntimeExports.jsxs(R.Pack,{size:m,className:o.CSS(o.CSS.BE(C,"btn"),i==null&&o.CSS.BEM(C,"btn","uneditable"),o.CSS.selected(r===s),p&&t!=null&&o.CSS.BEM(C,"btn","closable")),draggable:!0,direction:"x",justify:"center",align:"center",onClick:g,onDragStart:b,onDragEnd:S,bordered:!1,rounded:!1,children:[u.jsxRuntimeExports.jsx(W,{name:n,tabKey:s,onRename:i,icon:h,editable:E,level:y.ComponentSizeLevels[m]}),p&&t!=null&&u.jsxRuntimeExports.jsx(j.Icon,{onClick:a,children:u.jsxRuntimeExports.jsx(j.u0.Close,{"aria-label":"pluto-tabs__close"})})]})},W=({onRename:r,name:e,tabKey:t,icon:s,editable:n=!0,...l})=>r==null||!n?s!=null?u.jsxRuntimeExports.jsx(j.WithIcon,{startIcon:s,noWrap:!0,...l,children:e}):u.jsxRuntimeExports.jsx(j.Text,{noWrap:!0,...l,children:e}):u.jsxRuntimeExports.jsx(j.Editable,{onChange:c=>r(t,c),value:e,noWrap:!0,...l}),M=Object.freeze(Object.defineProperty({__proto__:null,Content:N,Provider:w,Selector:P,Tabs:q,TabsContext:f,rename:k,resetSelection:B,useStatic:T,useTabsContext:v},Symbol.toStringTag,{value:"Module"}));exports.Tabs=q;exports.external=M;exports.rename=k;exports.resetSelection=B;exports.useStatic=T;
//# sourceMappingURL=external-EnGFYnrD.cjs.map
