import{a as e,L as n,y as o,_ as r,z as t,j as a,C as s,D as c,w as l,f as i,G as p,k as d,l as u,m as f,n as m,o as x,H as v,I as h,J as j,d as b,t as k,u as g}from"../../vendor.js";import{forwardRef as N,useState as y,useReducer as w,useImperativeHandle as C}from"react";import{usePopper as T}from"react-popper";import"react-dom";import{u as O,a as E}from"../../hooks.js";import{I as D}from"../Icon/index.js";import{T as I}from"../Text/index.js";function J(e,n){var o=k(e);if(g){var r=g(e);n&&(r=i(r).call(r,(function(n){return x(e,n).enumerable}))),o.push.apply(o,r)}return o}function P(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?J(Object(o),!0).forEach((function(n){d(e,n,o[n])})):u?f(e,u(o)):J(Object(o)).forEach((function(n){m(e,n,x(o,n))}))}return e}var _=N((function(d,u){var f,m,x=d.globalEventsTarget,k=void 0===x?global:x,g=d.placement,N=void 0===g?"bottom":g,J=d.popperOptions,_=void 0===J?{}:J,z=d.onToggle,A=void 0===z?function(){}:z,F=d.onAppend,G=void 0===F?function(){}:F,H=d.onPaste,L=void 0===H?function(){}:H,R=O(),S=R.components,q=void 0===S?[]:S,B=R.getComponent,K=R.oakRef,M=E().otherTabEnabled,Q=y(),U=e(Q,2),V=U[0],W=U[1],X=y(),Y=e(X,2),Z=Y[0],$=Y[1],ee=y(),ne=e(ee,2),oe=ne[0],re=ne[1],te=w(n,{opened:!1,clipboard:null}),ae=e(te,2),se=ae[0],ce=ae[1],le=T(Z,V,{placement:N,modifiers:o(f=[]).call(f,r(_.modifiers||[]),[{name:"preventOverflow",enabled:!0,options:{boundary:null==K?void 0:K.current}},{name:"arrow",options:{element:oe}},{name:"offset",options:{offset:[oe&&/-(start|end)/.test(N)?-5:0,16]}}])}),ie=le.styles,pe=le.attributes;t("click",(function(e){me(e)}),k),C(u,(function(){return{open:de,close:fe,opened:se.opened}}));var de=function(){ce({opened:!0}),A({opened:!0}),ue()},ue=function(){var e=v(h.mark((function e(){var n,o;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.t0=JSON,e.next=4,j.navigator.clipboard.readText();case 4:e.t1=e.sent,o=e.t0.parse.call(e.t0,e.t1),B(o.type)&&(n=o),e.next=11;break;case 9:e.prev=9,e.t2=e.catch(0);case 11:ce({clipboard:n});case 12:case"end":return e.stop()}}),e,null,[[0,9]])})));return function(){return e.apply(this,arguments)}}(),fe=function(){ce({opened:!1,clipboard:null}),A({opened:!1})},me=function(e){V&&Z&&(Z.contains(e.target)||Z===e.target||V.contains(e.target)||V===e.target||fe())},xe=function(e){var n,r,t;if(!e||!1===M&&"other"===e.id)return null;var c,p,d,u=o(n=o(r=[]).call(r,e.components)).call(n,l(t=i(q).call(q,(function(n){return n.group===e.id}))).call(t,(function(e){return e.component})));!1===M&&"core"===e.id&&(u=o(c=o(u).call(u,(null===(p=b(q).call(q,(function(e){return"other"===e.id})))||void 0===p?void 0:p.components)||[])).call(c,l(d=i(q).call(q,(function(e){return"other"===e.group}))).call(d,(function(e){return e.component}))));return a.exports.jsx("div",{className:"oak-components",children:l(u).call(u,(function(e,n){return a.exports.jsx("div",{className:s("oak-component","oak-component-"+(e.id||"unknown")),children:a.exports.jsxs("a",{href:"#",draggable:!1,onClick:ve.bind(null,e),children:[a.exports.jsx("div",{className:"oak-component-icon",children:"function"==typeof e.icon?e.icon({component:e,className:"oak-icons"}):a.exports.jsx(D,{children:e.icon})}),a.exports.jsx("span",{children:a.exports.jsx(I,{children:e.name})})]})},e.id||n)}))})},ve=function(e,n){null==n||n.preventDefault(),G(e)};return a.exports.jsxs("div",{className:s("oak-catalogue",{"oak-opened":se.opened}),children:[a.exports.jsx("a",{ref:$,className:"oak-handle",onClick:function(e){e.preventDefault(),se.opened?fe():de()},draggable:!1,href:"#",children:a.exports.jsx("span",{className:"oak-handle-inner",children:a.exports.jsx(D,{children:"add"})})}),se.opened&&a.exports.jsxs("div",P(P({ref:W,style:ie.popper,className:"oak-popover"},pe.popper),{},{"data-placement":N,children:[a.exports.jsxs("div",{className:"oak-groups",children:[a.exports.jsx(c,{children:l(m=i(q).call(q,(function(e){return"group"===e.type&&(!1!==M||"other"!==e.id)}))).call(m,(function(e,n){return a.exports.jsx(p,{title:a.exports.jsx(I,{children:e.name}),children:xe(e)},n)}))}),se.clipboard&&a.exports.jsxs("a",{onClick:L.bind(null,se.clipboard),className:"oak-clipboard",children:[a.exports.jsx(D,{children:"content_paste"}),a.exports.jsx(I,{name:"core.pasteFromClipboard",default:"Paste from clipboard"})]})]}),a.exports.jsx("div",{ref:re,style:ie.arrow,className:"oak-arrow"})]}))]})}));export{_ as C};
//# sourceMappingURL=index.js.map
