import{a as te}from"./chunk-5PNMVXO4.mjs";import{a as oe}from"./chunk-OVV7FA2W.mjs";import{a as b}from"./chunk-GS2F3THJ.mjs";import{b as M}from"./chunk-UG6FE2XS.mjs";import{forwardRef as ke,useState as R}from"react";import{IconButton as ie}from"@baseapp-frontend/design-system/components/web/buttons";import{ConfirmDialog as Be}from"@baseapp-frontend/design-system/components/web/dialogs";import{SwipeableDrawer as Le}from"@baseapp-frontend/design-system/components/web/drawers";import{TrashCanIcon as xe}from"@baseapp-frontend/design-system/components/web/icons";import{usePopover as Te}from"@baseapp-frontend/design-system/hooks/common";import{LoadingButton as Ae}from"@mui/lab";import{Box as I,Divider as $e,Typography as le}from"@mui/material";import{LongPressCallbackReason as Me,useLongPress as He}from"use-long-press";import{jsx as n,jsxs as D,Fragment as Re}from"react/jsx-runtime";function O(e){"@babel/helpers - typeof";return O=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},O(e)}function re(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(f){return Object.getOwnPropertyDescriptor(e,f).enumerable})),o.push.apply(o,r)}return o}function a(e){for(var t=1;t<arguments.length;t++){var o=arguments[t]!=null?arguments[t]:{};t%2?re(Object(o),!0).forEach(function(r){we(e,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):re(Object(o)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}function we(e,t,o){return(t=Pe(t))in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function Pe(e){var t=Ce(e,"string");return O(t)=="symbol"?t:t+""}function Ce(e,t){if(O(e)!="object"||!e)return e;var o=e[Symbol.toPrimitive];if(o!==void 0){var r=o.call(e,t||"default");if(O(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function H(e,t){return _e(e)||je(e,t)||Se(e,t)||Ie()}function Ie(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Se(e,t){if(e){if(typeof e=="string")return ne(e,t);var o={}.toString.call(e).slice(8,-1);return o==="Object"&&e.constructor&&(o=e.constructor.name),o==="Map"||o==="Set"?Array.from(e):o==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?ne(e,t):void 0}}function ne(e,t){(t==null||t>e.length)&&(t=e.length);for(var o=0,r=Array(t);o<t;o++)r[o]=e[o];return r}function je(e,t){var o=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(o!=null){var r,f,m,v,d=[],s=!0,h=!1;try{if(m=(o=o.call(e)).next,t===0){if(Object(o)!==o)return;s=!1}else for(;!(s=(r=m.call(o)).done)&&(d.push(r.value),d.length!==t);s=!0);}catch(u){h=!0,f=u}finally{try{if(!s&&o.return!=null&&(v=o.return(),Object(v)!==v))return}finally{if(h)throw f}}return d}}function _e(e){if(Array.isArray(e))return e}var Ee=ke(function(e,t){var o=e.actions,r=o===void 0?[]:o,f=e.children,m=e.title,v=m===void 0?"Item":m,d=e.showDeleteButton,s=d===void 0?!1:d,h=e.isDeletingItem,u=h===void 0?!1:h,E=e.disableDeleteButton,g=E===void 0?!1:E,N=e.handleDeleteItem,S=N===void 0?function(){}:N,F=e.offsetTop,K=F===void 0?0:F,V=e.offsetRight,U=V===void 0?0:V,W=e.ContainerProps,ae=W===void 0?{}:W,Y=e.SwipeableDrawerProps,se=Y===void 0?{}:Y,q=e.DeleteDialogProps,ue=q===void 0?{}:q,z=e.SwipeableDrawer,ce=z===void 0?Le:z,G=e.hoverOverlayMode,j=G===void 0?b.default:G,fe=R(!1),J=H(fe,2),de=J[0],_=J[1],pe=R(!1),Q=H(pe,2),me=Q[0],w=Q[1],ve=R({isLongPressingItem:!1,shouldOpenItemOptions:!1}),X=H(ve,2),k=X[0],B=X[1],P=Te(),Z=function(){w(!1),P.onClose()},he=He(function(i){i.stopPropagation(),B({isLongPressingItem:!0,shouldOpenItemOptions:!0})},{onCancel:function(y,l){var c,x=l.reason,p=(y==null||(c=y.target)===null||c===void 0?void 0:c.className)||"",T=typeof p=="string"?p:"",A=T.includes("MuiBackdrop");x===Me.CancelledByRelease&&A&&B(function($){return a(a({},$),{},{isLongPressingItem:!1})})},cancelOutsideElement:!0,threshold:400}),C=function(){B({isLongPressingItem:!1,shouldOpenItemOptions:!1})},L=function(){_(!0)},ge=function(){_(!1),w(!1),P.onClose()},ee=typeof window<"u"&&window.matchMedia("(hover: hover)").matches,ye=function(){_(!1),S?.(),C(),w(!1),P.onClose()},be=function(){return n(Be,a({title:"Delete ".concat(v,"?"),content:"Are you sure you want to delete? This action cannot be undone.",action:n(Ae,{color:"error",onClick:ye,disabled:u,loading:u,children:"Delete"}),onClose:ge,open:de},ue))},De=function(){if(!ee){var y=function(){k.isLongPressingItem||C()};return n(ce,a(a({open:k.shouldOpenItemOptions&&k.isLongPressingItem,onClose:y,"aria-label":"actions overlay"},se),{},{children:D(I,{display:"grid",gridTemplateColumns:"1fr",justifySelf:"start",gap:1,width:"100%",children:[r?.map(function(l){var c=l.label,x=l.icon,p=l.onClick,T=l.disabled,A=l.hasPermission,$=l.closeOnClick;if(!A)return null;var Oe=function(){p?.(),$&&C()};return n(ie,{onClick:Oe,disabled:T,sx:{width:"fit-content"},"aria-label":c,children:D(M,{children:[n(I,{display:"grid",justifySelf:"center",height:"min-content",children:x}),n(le,{variant:"body2",color:"text.primary",children:c})]})},c)}),s&&D(Re,{children:[n($e,{}),n(ie,{onClick:L,disabled:u||g,sx:{width:"fit-content"},"aria-label":"delete item",children:D(M,{children:[n(I,{display:"grid",justifySelf:"center",height:"min-content",children:n(xe,{sx:{color:g?"text.disabled":"error.main"}})}),n(le,{variant:"body2",color:g?"text.disabled":"error.main",children:"Delete"})]})})]})]})}))}if(ee&&me){if(j===b.default)return n(te,{offsetRight:U,offsetTop:K,showDeleteButton:s,isDeletingItem:u,disableDeleteButton:g,handleDeleteDialogOpen:L,actions:r,handleLongPressItemOptionsClose:C});if(j===b.threeDotsMenu)return n(oe,{offsetRight:U,offsetTop:K,showDeleteButton:s,isDeletingItem:u,disableDeleteButton:g,handleDeleteDialogOpen:L,actions:r,handleClosePopover:Z,popover:P})}return n("div",{})};return D(I,a(a(a(a({ref:t,onMouseEnter:function(){return w(!0)},onMouseLeave:Z,position:"relative"},he()),j===b.threeDotsMenu&&{sx:{width:"100%",display:"flex",justifyContent:"flex-end"}}),ae),{},{children:[be(),De(),f]}))}),tt=Ee;export{tt as a};
//# sourceMappingURL=chunk-DUTRTT6Y.mjs.map