import{a as e,S as n,y as o,_ as r,z as t,j as a,C as s,O as c,w as l,D as i,k as p,l as d,m as u,n as f,o as m,G as x,H as v,I as h,f 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{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 P(e,n){var o=k(e);if(g){var r=g(e);n&&(r=j(r).call(r,(function(n){return m(e,n).enumerable}))),o.push.apply(o,r)}return o}function S(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?P(Object(o),!0).forEach((function(n){p(e,n,o[n])})):d?u(e,d(o)):P(Object(o)).forEach((function(n){f(e,n,m(o,n))}))}return e}var _=N((function(p,d){var u,f,m=p.globalEventsTarget,k=void 0===m?global:m,g=p.placement,N=void 0===g?"bottom":g,P=p.popperOptions,_=void 0===P?{}:P,z=p.onToggle,A=void 0===z?function(){}:z,F=p.onAppend,G=void 0===F?function(){}:F,H=p.onPaste,J=void 0===H?function(){}:H,R=O(),q=R.components,B=void 0===q?[]:q,K=R.getComponent,L=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(u=[]).call(u,r(_.modifiers||[]),[{name:"preventOverflow",enabled:!0,options:{boundary:null==L?void 0:L.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(d,(function(){return{open:de,close:fe,opened:se.opened}}));var de=function(){ce({opened:!0}),A({opened:!0}),ue()},ue=function(){var e=x(v.mark((function e(){var n,o;return v.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.t0=JSON,e.next=4,h.navigator.clipboard.readText();case 4:e.t1=e.sent,o=e.t0.parse.call(e.t0,e.t1),K(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,i,p,d=o(n=o(r=[]).call(r,e.components)).call(n,l(t=j(B).call(B,(function(n){return n.group===e.id}))).call(t,(function(e){return e.component})));!1===M&&"core"===e.id&&(d=o(c=o(d).call(d,(null===(i=b(B).call(B,(function(e){return"other"===e.id})))||void 0===i?void 0:i.components)||[])).call(c,l(p=j(B).call(B,(function(e){return"other"===e.group}))).call(p,(function(e){return e.component}))));return a.exports.jsx("div",{className:"oak-components",children:l(d).call(d,(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",S(S({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(f=j(B).call(B,(function(e){return"group"===e.type&&(!1!==M||"other"!==e.id)}))).call(f,(function(e,n){return a.exports.jsx(i,{title:a.exports.jsx(I,{children:e.name}),children:xe(e)},n)}))}),se.clipboard&&a.exports.jsxs("a",{onClick:J.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
