define(['exports', 'preact/hooks', './eventsUtils-edf8f4e5', 'preact/jsx-runtime', './BaseButton-c86afd54', './Text-0609bf4d', './useTranslationBundle-7c40cb58', './hooks/PRIVATE_useVisSelection/themes/ClearSelection.css', './Layer-139c23c4', 'preact/compat', './LayerHost-733ade2f', './Floating-ae9845d4'], (function(e,t,n,o,r,l,i,c,s,a,u,d){"use strict";const p=({onAction:e})=>{const t=`${i.useTranslationBundle("@oracle/oraclejet-preact").vis_clearSelection()}`;return o.jsx("div",{class:c.clearButtonStyles.base,children:o.jsx(r.BaseButton,{styling:["default"],elementDetails:{type:"span",isFocusable:!1,isLabel:!0},variant:"outlined",onAction:e,children:o.jsx(l.Text,{truncation:"ellipsis",weight:"inherit",children:t})})})},f=18;const g=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],y=(e,t,o,r,l,i)=>{let c=new Set([]);if(null!=e){c=new Set(t);const n=t.has(e);"toggle"===r?n?c.delete(e):"single"===o?c=new Set([e]):c.add(e):n||(c=new Set([e]))}n.isEqual(c,t)||i?.({ids:[...c],data:[...c].map(l)})};e.useSelection=function({selection:e=[],selectionMode:n="none",idExtracter:r,onChange:l,isDrillEnabled:i,isKeyboardSelection:c,getDataById:a,ignoreAsTrigger:u}){const x=t.useRef(),{clearSelectionContent:h,tryToggleClearButton:S}=function({clearSelection:e}){const[n,r]=t.useState(!1),l=t.useRef({x:0,y:0}),i={mainAxis:2*f},c={current:l.current};return{clearSelectionContent:n?o.jsx(s.Layer,{children:o.jsx(d.Floating,{anchorRef:c,offsetValue:i,placement:"top",flipOptions:{crossAxis:!1,mainAxis:!1},shiftOptions:{crossAxis:!0,mainAxis:!0},children:o.jsx(p,{onAction:()=>{r(!1),e()}})})}):null,tryToggleClearButton:(e,t,o,i)=>"touch"===e.pointerType&&void 0===t&&"multiple"===o&&i.size>1&&(r(!n),l.current={x:e.clientX,y:e.clientY},!0)}}({clearSelection:()=>{y(void 0,new Set(e),n,"replace",a,l)}}),w=t.useCallback((t=>{if(u&&u(t.target))return;const o=new Set(e);if(x.current&&i)return clearTimeout(x.current),void(x.current=void 0);const c=r(t);if(S(t,c,n,o))return;const s=t.metaKey,d=t.ctrlKey;t.defaultPrevented||null==c&&(s||d)||(i?x.current=setTimeout((()=>{y(c,o,n,s||d||"touch"===t.pointerType?"toggle":"replace",a,l),x.current=void 0}),250):y(c,o,n,s||d||"touch"===t.pointerType?"toggle":"replace",a,l))}),[e,n,l,r,i,a,S,u]),A=t.useCallback((t=>{const o=r(t),i=t.ctrlKey;y(o,new Set(e),n,i?"toggle":"replace",a,l)}),[e,n,l,r,a]),m=t.useCallback((t=>{const o=t.shiftKey,i=t.ctrlKey&&" "===t.key,s=-1!==g.indexOf(t.key),u=r(t);if(s||i||c&&c(t)){const t=o||i?"toggle":"replace";y(u,new Set(e),n,t,a,l)}}),[e,n,l,r,c,a]);return{selectionContent:h,selectionProps:"none"===n||null==l?{}:{onKeyUp:m,onContextMenu:A,onPointerUp:w}}}}));
//# sourceMappingURL=useSelection-80e262f2.js.map
