react-admin-crud-manager 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +31 -31
- package/dist/index.es.js.map +1 -1
- package/dist/types/OptionalSnackbarProvider.d.ts +6 -0
- package/dist/types/components/Button/Button.d.ts +11 -0
- package/dist/types/components/Chip/Chip.d.ts +8 -0
- package/dist/types/components/CrudPage.d.ts +4 -0
- package/dist/types/components/Details/Details.d.ts +12 -0
- package/dist/types/components/Details/components/CardGroup.d.ts +6 -0
- package/dist/types/components/Details/components/DetailRow.d.ts +6 -0
- package/dist/types/components/Details/components/GroupRow.d.ts +6 -0
- package/dist/types/components/Filter/FilterDrawer.d.ts +17 -0
- package/dist/types/components/Form/Form.d.ts +21 -0
- package/dist/types/components/Form/components/AudioPicker.d.ts +18 -0
- package/dist/types/components/Form/components/Checkbox.d.ts +19 -0
- package/dist/types/components/Form/components/ImageCropperModal.d.ts +12 -0
- package/dist/types/components/Form/components/ImagePicker.d.ts +19 -0
- package/dist/types/components/Form/components/Input.d.ts +18 -0
- package/dist/types/components/Form/components/InputLabel.d.ts +8 -0
- package/dist/types/components/Form/components/PhoneInput.d.ts +15 -0
- package/dist/types/components/Form/components/Radio.d.ts +17 -0
- package/dist/types/components/Form/components/RenderFields.d.ts +42 -0
- package/dist/types/components/Form/components/Select.d.ts +25 -0
- package/dist/types/components/Form/components/Switch.d.ts +13 -0
- package/dist/types/components/Form/components/TextArea.d.ts +9 -0
- package/dist/types/components/Form/components/TinyEditor.d.ts +20 -0
- package/dist/types/components/Form/components/VideoPicker.d.ts +18 -0
- package/dist/types/components/Loader/Spinner.d.ts +7 -0
- package/dist/types/components/Modal/Modal.d.ts +20 -0
- package/dist/types/components/Table/Table.d.ts +10 -0
- package/dist/types/components/Table/components/ImagePreview.d.ts +8 -0
- package/dist/types/components/Table/components/SortDropdown.d.ts +13 -0
- package/dist/types/components/Table/components/TableSkeleton.d.ts +6 -0
- package/dist/types/components/Table/utils/sortUtils.d.ts +58 -0
- package/dist/types/data/countries.d.ts +6 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/lib/utils.d.ts +2 -0
- package/dist/types/types/crudtypes.d.ts +217 -0
- package/package.json +6 -2
package/dist/index.cjs.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
w-max max-w-xs bg-white text-black dark:bg-black dark:text-white text-xs\r
|
|
9
9
|
rounded px-2 py-1 opacity-0 shadow-lg\r
|
|
10
10
|
group-hover:opacity-100 transition-opacity\r
|
|
11
|
-
duration-200 pointer-events-none z-50`,children:e})]})]})})}const zt=({options:n=[],value:a="",defaultValue:e="",onChange:r,placeholder:o="Select option",className:i="",disabled:s=!1,search:c=!1,label:f="",required:d=!1,name:p="",parentClass:h="",multiple:l=!1,dropdownMaxHeight:m="",formData:g={},dependencyKey:j=""})=>{var B;const[v,R]=b.useState(!1),[A,L]=b.useState(""),[C,I]=b.useState(!0),E=b.useRef(null),x=b.useRef(null),[w,S]=b.useState([]),D=a||a===!1?a:e,P=M=>M==null||M===""?"":String(typeof M=="boolean"?M:M??"");b.useEffect(()=>{(async()=>{if(typeof n=="function"){const k=await n(g);S(k||[])}else S(n||[])})()},j?[n,g==null?void 0:g[j]]:[n]);const Y=l?(D||[]).map(P):P(D),ee=w.filter(M=>M.label.toLowerCase().includes(A.toLowerCase())),
|
|
11
|
+
duration-200 pointer-events-none z-50`,children:e})]})]})})}const zt=({options:n=[],value:a="",defaultValue:e="",onChange:r,placeholder:o="Select option",className:i="",disabled:s=!1,search:c=!1,label:f="",required:d=!1,name:p="",parentClass:h="",multiple:l=!1,dropdownMaxHeight:m="",formData:g={},dependencyKey:j=""})=>{var B;const[v,R]=b.useState(!1),[A,L]=b.useState(""),[C,I]=b.useState(!0),E=b.useRef(null),x=b.useRef(null),[w,S]=b.useState([]),D=a||a===!1?a:e,P=M=>M==null||M===""?"":String(typeof M=="boolean"?M:M??"");b.useEffect(()=>{(async()=>{if(typeof n=="function"){const k=await n(g);S(k||[])}else S(n||[])})()},j?[n,g==null?void 0:g[j]]:[n]);const Y=l?(D||[]).map(P):P(D),ee=w.filter(M=>M.label.toLowerCase().includes(A.toLowerCase())),G=M=>{const k=P(M);return l?Y.includes(k):k===Y};b.useEffect(()=>{const M=k=>{E.current&&!E.current.contains(k.target)&&(R(!1),L(""))};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]),b.useEffect(()=>{if(v&&E.current){const M=E.current.getBoundingClientRect(),z=window.innerHeight-M.bottom;I(z<200)}},[v]),b.useEffect(()=>{v&&x.current&&x.current.focus()},[v]);const N=M=>{let k=M;if(M==="true"?k=!0:M==="false"&&(k=!1),l){const z=Y.includes(P(M));let H;z?H=(Array.isArray(a)?a:[]).filter(F=>P(F)!==P(M)):H=[...Array.isArray(a)?a:[],k],r==null||r(H)}else r==null||r(k),R(!1);L("")},X=l?w.filter(M=>G(M.value)).map(M=>M.label).join(", "):(B=w.find(M=>G(M.value)))==null?void 0:B.label;return b.useEffect(()=>{(D||D===!1)&&setTimeout(()=>{r==null||r(D)},100)},[]),t.jsxs("div",{className:h||"col-span-12",children:[t.jsx(Q,{label:f,required:d}),t.jsxs("div",{className:`relative ${i}`,ref:E,children:[t.jsx("select",{name:"hidden_select_for_validation",value:X||"",required:d,multiple:l,className:"absolute opacity-0 right-1/2 top-[80%] -translate-x-1/2 -translate-y-1/2 pointer-events-none h-[10px]",onChange:()=>{},children:t.jsx("option",{hidden:!0,value:X,children:X})}),t.jsxs("button",{type:"button",onClick:()=>!s&&R(!v),disabled:s,className:`w-full h-10 px-3 border border-gray-300 dark:border-gray-600 rounded-md text-left text-sm flex items-center justify-between
|
|
12
12
|
${X?"dark:text-white":"text-gray-500 dark:text-gray-400"}
|
|
13
13
|
${s?"opacity-50 cursor-not-allowed":"dark:bg-gray-700"}`,children:[t.jsx("span",{className:"truncate",children:X||o}),t.jsx(U.ChevronDown,{className:`w-4 h-4 transition-transform ${v?"rotate-180":""}`})]}),v&&t.jsxs("div",{className:`absolute z-50 w-full border rounded-md bg-white dark:bg-gray-700 shadow-lg
|
|
14
14
|
${C?"bottom-full mb-1":"top-full mt-1"}`,children:[c&&t.jsx("div",{className:"p-2 border-b border-gray-200 dark:border-gray-600",children:t.jsxs("div",{className:"relative",children:[t.jsx(U.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),t.jsx("input",{ref:x,type:"text",value:A,onChange:M=>L(M.target.value),placeholder:"Search...",className:"w-full pl-9 pr-3 py-2 text-sm border rounded-md bg-white dark:bg-gray-800 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none"})]})}),t.jsx("div",{className:"max-h-40 overflow-y-auto",style:{maxHeight:m||""},children:ee.length>0?ee.map(M=>t.jsxs("button",{type:"button",onClick:()=>N(String(M.value)),className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-gray-100 dark:hover:bg-gray-600
|
|
15
|
-
${
|
|
15
|
+
${G(M.value)?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":""}`,children:[t.jsx("span",{children:M.label}),l&&G(M.value)&&t.jsx(U.Check,{className:"w-4 h-4"})]},String(M.value))):t.jsx("div",{className:"px-3 py-2 text-sm text-gray-500 dark:text-gray-400",children:"No options found"})})]})]})]},p)},mt=b.forwardRef(({label:n,required:a,parentClass:e="col-span-12",className:r="",value:o=!1,onChange:i,disabled:s=!1,...c},f)=>t.jsxs("div",{className:`flex justify-between ${e}`,children:[n&&t.jsx(Q,{label:n,required:a}),t.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[t.jsx("input",{type:"checkbox",ref:f,className:"sr-only peer",checked:o,onChange:d=>i==null?void 0:i(d.target.checked),disabled:s,...c}),t.jsx("div",{className:`
|
|
16
16
|
w-11 h-6 bg-gray-200 peer-focus:outline-none
|
|
17
17
|
rounded-full peer dark:bg-gray-700
|
|
18
18
|
peer-checked:bg-primary-600
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
border-left: 0;
|
|
125
125
|
border-right: 0;
|
|
126
126
|
}
|
|
127
|
-
`,dr=1,ur=3,hr=1,pr=function(n){$t(a,n);function a(){var e=n!==null&&n.apply(this,arguments)||this;return e.cropperRef=ie.createRef(),e.imageRef=ie.createRef(),e.videoRef=ie.createRef(),e.containerPosition={x:0,y:0},e.containerRef=null,e.styleRef=null,e.containerRect=null,e.mediaSize={width:0,height:0,naturalWidth:0,naturalHeight:0},e.dragStartPosition={x:0,y:0},e.dragStartCrop={x:0,y:0},e.gestureZoomStart=0,e.gestureRotationStart=0,e.isTouching=!1,e.lastPinchDistance=0,e.lastPinchRotation=0,e.rafDragTimeout=null,e.rafPinchTimeout=null,e.wheelTimer=null,e.currentDoc=typeof document<"u"?document:null,e.currentWindow=typeof window<"u"?window:null,e.resizeObserver=null,e.previousCropSize=null,e.isInitialized=!1,e.state={cropSize:null,hasWheelJustStarted:!1,mediaObjectFit:void 0},e.initResizeObserver=function(){if(!(typeof window.ResizeObserver>"u"||!e.containerRef)){var r=!0;e.resizeObserver=new window.ResizeObserver(function(o){if(r){r=!1;return}e.computeSizes()}),e.resizeObserver.observe(e.containerRef)}},e.preventZoomSafari=function(r){return r.preventDefault()},e.cleanEvents=function(){e.currentDoc&&(e.currentDoc.removeEventListener("mousemove",e.onMouseMove),e.currentDoc.removeEventListener("mouseup",e.onDragStopped),e.currentDoc.removeEventListener("touchmove",e.onTouchMove),e.currentDoc.removeEventListener("touchend",e.onDragStopped),e.currentDoc.removeEventListener("gesturechange",e.onGestureChange),e.currentDoc.removeEventListener("gestureend",e.onGestureEnd),e.currentDoc.removeEventListener("scroll",e.onScroll))},e.clearScrollEvent=function(){e.containerRef&&e.containerRef.removeEventListener("wheel",e.onWheel),e.wheelTimer&&clearTimeout(e.wheelTimer)},e.onMediaLoad=function(){var r=e.computeSizes();r&&(e.previousCropSize=r,e.emitCropData(),e.setInitialCrop(r),e.isInitialized=!0),e.props.onMediaLoaded&&e.props.onMediaLoaded(e.mediaSize)},e.setInitialCrop=function(r){if(e.props.initialCroppedAreaPercentages){var o=or(e.props.initialCroppedAreaPercentages,e.mediaSize,e.props.rotation,r,e.props.minZoom,e.props.maxZoom),i=o.crop,s=o.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(s)}else if(e.props.initialCroppedAreaPixels){var c=ir(e.props.initialCroppedAreaPixels,e.mediaSize,e.props.rotation,r,e.props.minZoom,e.props.maxZoom),i=c.crop,s=c.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(s)}},e.computeSizes=function(){var r,o,i,s,c,f,d=e.imageRef.current||e.videoRef.current;if(d&&e.containerRef){e.containerRect=e.containerRef.getBoundingClientRect(),e.saveContainerPosition();var p=e.containerRect.width/e.containerRect.height,h=((r=e.imageRef.current)===null||r===void 0?void 0:r.naturalWidth)||((o=e.videoRef.current)===null||o===void 0?void 0:o.videoWidth)||0,l=((i=e.imageRef.current)===null||i===void 0?void 0:i.naturalHeight)||((s=e.videoRef.current)===null||s===void 0?void 0:s.videoHeight)||0,m=d.offsetWidth<h||d.offsetHeight<l,g=h/l,j=void 0;if(m)switch(e.state.mediaObjectFit){default:case"contain":j=p>g?{width:e.containerRect.height*g,height:e.containerRect.height}:{width:e.containerRect.width,height:e.containerRect.width/g};break;case"horizontal-cover":j={width:e.containerRect.width,height:e.containerRect.width/g};break;case"vertical-cover":j={width:e.containerRect.height*g,height:e.containerRect.height};break}else j={width:d.offsetWidth,height:d.offsetHeight};e.mediaSize=W(W({},j),{naturalWidth:h,naturalHeight:l}),e.props.setMediaSize&&e.props.setMediaSize(e.mediaSize);var v=e.props.cropSize?e.props.cropSize:er(e.mediaSize.width,e.mediaSize.height,e.containerRect.width,e.containerRect.height,e.props.aspect,e.props.rotation);return(((c=e.state.cropSize)===null||c===void 0?void 0:c.height)!==v.height||((f=e.state.cropSize)===null||f===void 0?void 0:f.width)!==v.width)&&e.props.onCropSizeChange&&e.props.onCropSizeChange(v),e.setState({cropSize:v},e.recomputeCropPosition),e.props.setCropSize&&e.props.setCropSize(v),v}},e.saveContainerPosition=function(){if(e.containerRef){var r=e.containerRef.getBoundingClientRect();e.containerPosition={x:r.left,y:r.top}}},e.onMouseDown=function(r){e.currentDoc&&(r.preventDefault(),e.currentDoc.addEventListener("mousemove",e.onMouseMove),e.currentDoc.addEventListener("mouseup",e.onDragStopped),e.saveContainerPosition(),e.onDragStart(a.getMousePoint(r)))},e.onMouseMove=function(r){return e.onDrag(a.getMousePoint(r))},e.onScroll=function(r){e.currentDoc&&(r.preventDefault(),e.saveContainerPosition())},e.onTouchStart=function(r){e.currentDoc&&(e.isTouching=!0,!(e.props.onTouchRequest&&!e.props.onTouchRequest(r))&&(e.currentDoc.addEventListener("touchmove",e.onTouchMove,{passive:!1}),e.currentDoc.addEventListener("touchend",e.onDragStopped),e.saveContainerPosition(),r.touches.length===2?e.onPinchStart(r):r.touches.length===1&&e.onDragStart(a.getTouchPoint(r.touches[0]))))},e.onTouchMove=function(r){r.preventDefault(),r.touches.length===2?e.onPinchMove(r):r.touches.length===1&&e.onDrag(a.getTouchPoint(r.touches[0]))},e.onGestureStart=function(r){e.currentDoc&&(r.preventDefault(),e.currentDoc.addEventListener("gesturechange",e.onGestureChange),e.currentDoc.addEventListener("gestureend",e.onGestureEnd),e.gestureZoomStart=e.props.zoom,e.gestureRotationStart=e.props.rotation)},e.onGestureChange=function(r){if(r.preventDefault(),!e.isTouching){var o=a.getMousePoint(r),i=e.gestureZoomStart-1+r.scale;if(e.setNewZoom(i,o,{shouldUpdatePosition:!0}),e.props.onRotationChange){var s=e.gestureRotationStart+r.rotation;e.props.onRotationChange(s)}}},e.onGestureEnd=function(r){e.cleanEvents()},e.onDragStart=function(r){var o,i,s=r.x,c=r.y;e.dragStartPosition={x:s,y:c},e.dragStartCrop=W({},e.props.crop),(i=(o=e.props).onInteractionStart)===null||i===void 0||i.call(o)},e.onDrag=function(r){var o=r.x,i=r.y;e.currentWindow&&(e.rafDragTimeout&&e.currentWindow.cancelAnimationFrame(e.rafDragTimeout),e.rafDragTimeout=e.currentWindow.requestAnimationFrame(function(){if(e.state.cropSize&&!(o===void 0||i===void 0)){var s=o-e.dragStartPosition.x,c=i-e.dragStartPosition.y,f={x:e.dragStartCrop.x+s,y:e.dragStartCrop.y+c},d=e.props.restrictPosition?ke(f,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):f;e.props.onCropChange(d)}}))},e.onDragStopped=function(){var r,o;e.isTouching=!1,e.cleanEvents(),e.emitCropData(),(o=(r=e.props).onInteractionEnd)===null||o===void 0||o.call(r)},e.onWheel=function(r){if(e.currentWindow&&!(e.props.onWheelRequest&&!e.props.onWheelRequest(r))){r.preventDefault();var o=a.getMousePoint(r),i=Qt(r).pixelY,s=e.props.zoom-i*e.props.zoomSpeed/200;e.setNewZoom(s,o,{shouldUpdatePosition:!0}),e.state.hasWheelJustStarted||e.setState({hasWheelJustStarted:!0},function(){var c,f;return(f=(c=e.props).onInteractionStart)===null||f===void 0?void 0:f.call(c)}),e.wheelTimer&&clearTimeout(e.wheelTimer),e.wheelTimer=e.currentWindow.setTimeout(function(){return e.setState({hasWheelJustStarted:!1},function(){var c,f;return(f=(c=e.props).onInteractionEnd)===null||f===void 0?void 0:f.call(c)})},250)}},e.getPointOnContainer=function(r,o){var i=r.x,s=r.y;if(!e.containerRect)throw new Error("The Cropper is not mounted");return{x:e.containerRect.width/2-(i-o.x),y:e.containerRect.height/2-(s-o.y)}},e.getPointOnMedia=function(r){var o=r.x,i=r.y,s=e.props,c=s.crop,f=s.zoom;return{x:(o+c.x)/f,y:(i+c.y)/f}},e.setNewZoom=function(r,o,i){var s=i===void 0?{}:i,c=s.shouldUpdatePosition,f=c===void 0?!0:c;if(!(!e.state.cropSize||!e.props.onZoomChange)){var d=Ue(r,e.props.minZoom,e.props.maxZoom);if(f){var p=e.getPointOnContainer(o,e.containerPosition),h=e.getPointOnMedia(p),l={x:h.x*d-p.x,y:h.y*d-p.y},m=e.props.restrictPosition?ke(l,e.mediaSize,e.state.cropSize,d,e.props.rotation):l;e.props.onCropChange(m)}e.props.onZoomChange(d)}},e.getCropData=function(){if(!e.state.cropSize)return null;var r=e.props.restrictPosition?ke(e.props.crop,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):e.props.crop;return rr(r,e.mediaSize,e.state.cropSize,e.getAspect(),e.props.zoom,e.props.rotation,e.props.restrictPosition)},e.emitCropData=function(){var r=e.getCropData();if(r){var o=r.croppedAreaPercentages,i=r.croppedAreaPixels;e.props.onCropComplete&&e.props.onCropComplete(o,i),e.props.onCropAreaChange&&e.props.onCropAreaChange(o,i)}},e.emitCropAreaChange=function(){var r=e.getCropData();if(r){var o=r.croppedAreaPercentages,i=r.croppedAreaPixels;e.props.onCropAreaChange&&e.props.onCropAreaChange(o,i)}},e.recomputeCropPosition=function(){var r,o;if(e.state.cropSize){var i=e.props.crop;if(e.isInitialized&&(!((r=e.previousCropSize)===null||r===void 0)&&r.width)&&(!((o=e.previousCropSize)===null||o===void 0)&&o.height)){var s=Math.abs(e.previousCropSize.width-e.state.cropSize.width)>1e-6||Math.abs(e.previousCropSize.height-e.state.cropSize.height)>1e-6;if(s){var c=e.state.cropSize.width/e.previousCropSize.width,f=e.state.cropSize.height/e.previousCropSize.height;i={x:e.props.crop.x*c,y:e.props.crop.y*f}}}var d=e.props.restrictPosition?ke(i,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):i;e.previousCropSize=e.state.cropSize,e.props.onCropChange(d),e.emitCropData()}},e.onKeyDown=function(r){var o,i,s=e.props,c=s.crop,f=s.onCropChange,d=s.keyboardStep,p=s.zoom,h=s.rotation,l=d;if(e.state.cropSize){r.shiftKey&&(l*=.2);var m=W({},c);switch(r.key){case"ArrowUp":m.y-=l,r.preventDefault();break;case"ArrowDown":m.y+=l,r.preventDefault();break;case"ArrowLeft":m.x-=l,r.preventDefault();break;case"ArrowRight":m.x+=l,r.preventDefault();break;default:return}e.props.restrictPosition&&(m=ke(m,e.mediaSize,e.state.cropSize,p,h)),r.repeat||(i=(o=e.props).onInteractionStart)===null||i===void 0||i.call(o),f(m)}},e.onKeyUp=function(r){var o,i;switch(r.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":r.preventDefault();break;default:return}e.emitCropData(),(i=(o=e.props).onInteractionEnd)===null||i===void 0||i.call(o)},e}return a.prototype.componentDidMount=function(){!this.currentDoc||!this.currentWindow||(this.containerRef&&(this.containerRef.ownerDocument&&(this.currentDoc=this.containerRef.ownerDocument),this.currentDoc.defaultView&&(this.currentWindow=this.currentDoc.defaultView),this.initResizeObserver(),typeof window.ResizeObserver>"u"&&this.currentWindow.addEventListener("resize",this.computeSizes),this.props.zoomWithScroll&&this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}),this.containerRef.addEventListener("gesturestart",this.onGestureStart)),this.currentDoc.addEventListener("scroll",this.onScroll),this.props.disableAutomaticStylesInjection||(this.styleRef=this.currentDoc.createElement("style"),this.styleRef.setAttribute("type","text/css"),this.props.nonce&&this.styleRef.setAttribute("nonce",this.props.nonce),this.styleRef.innerHTML=cr,this.currentDoc.head.appendChild(this.styleRef)),this.imageRef.current&&this.imageRef.current.complete&&this.onMediaLoad(),this.props.setImageRef&&this.props.setImageRef(this.imageRef),this.props.setVideoRef&&this.props.setVideoRef(this.videoRef),this.props.setCropperRef&&this.props.setCropperRef(this.cropperRef))},a.prototype.componentWillUnmount=function(){var e,r;!this.currentDoc||!this.currentWindow||(typeof window.ResizeObserver>"u"&&this.currentWindow.removeEventListener("resize",this.computeSizes),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),this.containerRef&&this.containerRef.removeEventListener("gesturestart",this.preventZoomSafari),this.styleRef&&((r=this.styleRef.parentNode)===null||r===void 0||r.removeChild(this.styleRef)),this.cleanEvents(),this.props.zoomWithScroll&&this.clearScrollEvent())},a.prototype.componentDidUpdate=function(e){var r,o,i,s,c,f,d,p,h;e.rotation!==this.props.rotation?(this.computeSizes(),this.recomputeCropPosition()):e.aspect!==this.props.aspect?this.computeSizes():e.objectFit!==this.props.objectFit?this.computeSizes():e.zoom!==this.props.zoom?this.recomputeCropPosition():((r=e.cropSize)===null||r===void 0?void 0:r.height)!==((o=this.props.cropSize)===null||o===void 0?void 0:o.height)||((i=e.cropSize)===null||i===void 0?void 0:i.width)!==((s=this.props.cropSize)===null||s===void 0?void 0:s.width)?this.computeSizes():(((c=e.crop)===null||c===void 0?void 0:c.x)!==((f=this.props.crop)===null||f===void 0?void 0:f.x)||((d=e.crop)===null||d===void 0?void 0:d.y)!==((p=this.props.crop)===null||p===void 0?void 0:p.y))&&this.emitCropAreaChange(),e.zoomWithScroll!==this.props.zoomWithScroll&&this.containerRef&&(this.props.zoomWithScroll?this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}):this.clearScrollEvent()),e.video!==this.props.video&&((h=this.videoRef.current)===null||h===void 0||h.load());var l=this.getObjectFit();l!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:l},this.computeSizes)},a.prototype.getAspect=function(){var e=this.props,r=e.cropSize,o=e.aspect;return r?r.width/r.height:o},a.prototype.getObjectFit=function(){var e,r,o,i;if(this.props.objectFit==="cover"){var s=this.imageRef.current||this.videoRef.current;if(s&&this.containerRef){this.containerRect=this.containerRef.getBoundingClientRect();var c=this.containerRect.width/this.containerRect.height,f=((e=this.imageRef.current)===null||e===void 0?void 0:e.naturalWidth)||((r=this.videoRef.current)===null||r===void 0?void 0:r.videoWidth)||0,d=((o=this.imageRef.current)===null||o===void 0?void 0:o.naturalHeight)||((i=this.videoRef.current)===null||i===void 0?void 0:i.videoHeight)||0,p=f/d;return p<c?"horizontal-cover":"vertical-cover"}return"horizontal-cover"}return this.props.objectFit},a.prototype.onPinchStart=function(e){var r=a.getTouchPoint(e.touches[0]),o=a.getTouchPoint(e.touches[1]);this.lastPinchDistance=st(r,o),this.lastPinchRotation=it(r,o),this.onDragStart(lt(r,o))},a.prototype.onPinchMove=function(e){var r=this;if(!(!this.currentDoc||!this.currentWindow)){var o=a.getTouchPoint(e.touches[0]),i=a.getTouchPoint(e.touches[1]),s=lt(o,i);this.onDrag(s),this.rafPinchTimeout&&this.currentWindow.cancelAnimationFrame(this.rafPinchTimeout),this.rafPinchTimeout=this.currentWindow.requestAnimationFrame(function(){var c=st(o,i),f=r.props.zoom*(c/r.lastPinchDistance);r.setNewZoom(f,s,{shouldUpdatePosition:!1}),r.lastPinchDistance=c;var d=it(o,i),p=r.props.rotation+(d-r.lastPinchRotation);r.props.onRotationChange&&r.props.onRotationChange(p),r.lastPinchRotation=d})}},a.prototype.render=function(){var e=this,r,o=this.props,i=o.image,s=o.video,c=o.mediaProps,f=o.cropperProps,d=o.transform,p=o.crop,h=p.x,l=p.y,m=o.rotation,g=o.zoom,j=o.cropShape,v=o.showGrid,R=o.roundCropAreaPixels,A=o.style,L=A.containerStyle,C=A.cropAreaStyle,I=A.mediaStyle,E=o.classes,x=E.containerClassName,w=E.cropAreaClassName,S=E.mediaClassName,D=(r=this.state.mediaObjectFit)!==null&&r!==void 0?r:this.getObjectFit();return ie.createElement("div",{onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart,ref:function(Y){return e.containerRef=Y},"data-testid":"container",style:L,className:Te("reactEasyCrop_Container",x)},i?ie.createElement("img",W({alt:"",className:Te("reactEasyCrop_Image",D==="contain"&&"reactEasyCrop_Contain",D==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",D==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",S)},c,{src:i,ref:this.imageRef,style:W(W({},I),{transform:d||"translate(".concat(h,"px, ").concat(l,"px) rotate(").concat(m,"deg) scale(").concat(g,")")}),onLoad:this.onMediaLoad})):s&&ie.createElement("video",W({autoPlay:!0,playsInline:!0,loop:!0,muted:!0,className:Te("reactEasyCrop_Video",D==="contain"&&"reactEasyCrop_Contain",D==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",D==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",S)},c,{ref:this.videoRef,onLoadedMetadata:this.onMediaLoad,style:W(W({},I),{transform:d||"translate(".concat(h,"px, ").concat(l,"px) rotate(").concat(m,"deg) scale(").concat(g,")")}),controls:!1}),(Array.isArray(s)?s:[{src:s}]).map(function(P){return ie.createElement("source",W({key:P.src},P))})),this.state.cropSize&&ie.createElement("div",W({ref:this.cropperRef,style:W(W({},C),{width:R?Math.round(this.state.cropSize.width):this.state.cropSize.width,height:R?Math.round(this.state.cropSize.height):this.state.cropSize.height}),tabIndex:0,onKeyDown:this.onKeyDown,onKeyUp:this.onKeyUp,"data-testid":"cropper",className:Te("reactEasyCrop_CropArea",j==="round"&&"reactEasyCrop_CropAreaRound",v&&"reactEasyCrop_CropAreaGrid",w)},f)))},a.defaultProps={zoom:1,rotation:0,aspect:4/3,maxZoom:ur,minZoom:dr,cropShape:"rect",objectFit:"contain",showGrid:!0,style:{},classes:{},mediaProps:{},cropperProps:{},zoomSpeed:1,restrictPosition:!0,zoomWithScroll:!0,keyboardStep:hr},a.getMousePoint=function(e){return{x:Number(e.clientX),y:Number(e.clientY)}},a.getTouchPoint=function(e){return{x:Number(e.clientX),y:Number(e.clientY)}},a}(ie.Component);const ct=ae,fr=n=>new Promise((a,e)=>{const r=new Image;r.addEventListener("load",()=>a(r)),r.addEventListener("error",o=>e(o)),r.setAttribute("crossOrigin","anonymous"),r.src=n}),Mt=n=>n*Math.PI/180,br=(n,a,e)=>{const r=Mt(e);return{width:Math.abs(Math.cos(r)*n)+Math.abs(Math.sin(r)*a),height:Math.abs(Math.sin(r)*n)+Math.abs(Math.cos(r)*a)}},gr=async(n,a,e="image/jpeg",r=0)=>{const o=await fr(n),i=document.createElement("canvas"),s=i.getContext("2d");if(!s)throw new Error("Canvas context is not available");const c=Mt(r),{width:f,height:d}=br(o.width,o.height,r);i.width=f,i.height=d,s.translate(f/2,d/2),s.rotate(c),s.translate(-o.width/2,-o.height/2),s.drawImage(o,0,0);const p=document.createElement("canvas"),h=p.getContext("2d");if(!h)throw new Error("Canvas context is not available");return p.width=a.width,p.height=a.height,h.drawImage(i,a.x,a.y,a.width,a.height,0,0,a.width,a.height),new Promise((l,m)=>{p.toBlob(g=>{if(!g){m(new Error("Image cropping failed"));return}l(g)},e,.95)})},mr=({isOpen:n,imageSrc:a,fileType:e="image/jpeg",fileName:r="cropped-image",aspect:o=1/1,title:i="Crop Image",onClose:s,onApply:c})=>{const[f,d]=b.useState({x:0,y:0}),[p,h]=b.useState(1),[l,m]=b.useState(null);b.useEffect(()=>{n&&(d({x:0,y:0}),h(1),m(null))},[n]);const g=b.useCallback((v,R)=>{m(R)},[]),j=async()=>{var v,R;if(!(!a||!l))try{const A=await gr(a,l,e),L=((R=(v=e==null?void 0:e.split("/"))==null?void 0:v[1])==null?void 0:R.replace("jpeg","jpg"))||"jpg",C=new File([A],`${r}.${L}`,{type:e});c==null||c(C)}catch{s==null||s()}};return n?t.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[t.jsx("div",{className:"fixed inset-0 bg-gray-500 opacity-75",onClick:s}),t.jsxs("div",{className:"relative bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col dark:bg-gray-800",children:[t.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[t.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:i}),t.jsx("button",{type:"button",onClick:s,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300","aria-label":"Close crop modal",children:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-6 h-6"})})]}),t.jsxs("div",{className:"p-4 space-y-4",children:[t.jsx("div",{className:"relative h-72 w-full bg-gray-900 rounded-md overflow-hidden",children:a&&t.jsx(pr,{image:a,crop:f,zoom:p,aspect:o,onCropChange:d,onZoomChange:h,onCropComplete:g})}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-sm text-gray-700 dark:text-gray-300",children:"Zoom"}),t.jsx("input",{type:"range",min:1,max:3,step:.1,value:p,onChange:v=>h(Number(v.target.value)),className:"w-full"})]})]}),t.jsxs("div",{className:"px-4 py-3 flex justify-end gap-3 border-t border-gray-200 dark:border-gray-700 sm:!px-6",children:[t.jsx(ct,{type:"button",onClick:s,variant:"outlined",color:"default",children:"Cancel"}),t.jsx(ct,{type:"button",onClick:j,variant:"contained",color:"primary",children:"Apply Crop"})]})]})]}):null},xr=ae,ue=n=>{typeof n=="string"&&n.startsWith("blob:")&&URL.revokeObjectURL(n)},yr=({label:n="",value:a=null,onChange:e,required:r=!1,accept:o="image/*",aspect:i="1",id:s,dragDrop:c=!1,cropImage:f=!1,name:d="",parentClass:p=""})=>{const[h,l]=b.useState(a),[m,g]=b.useState(!1),[j,v]=b.useState(!1),[R,A]=b.useState(""),[L,C]=b.useState("image/jpeg"),[I,E]=b.useState("cropped-image"),x=b.useRef(null),w=b.useRef(""),S=b.useRef("");b.useEffect(()=>{if(a instanceof File){const k=URL.createObjectURL(a);ue(S.current),S.current=k,l({file:a,preview:k})}else a&&typeof a=="object"&&"preview"in a,l(a)},[a]),b.useEffect(()=>()=>{ue(S.current),ue(w.current)},[]);const D=()=>{v(!1),ue(w.current),w.current="",A(""),x.current&&(x.current.value="")},P=k=>{const z=URL.createObjectURL(k);ue(S.current),S.current=z,l({file:k,preview:z}),e==null||e(k),D()},Y=k=>{if(!k||k.length===0)return;const z=k[0];if(f){const F=URL.createObjectURL(z);ue(w.current),w.current=F,A(F),C(z.type||"image/jpeg"),E((z.name||"cropped-image").replace(/\.[^/.]+$/,"")),v(!0);return}const H=URL.createObjectURL(z);ue(S.current),S.current=H,l({file:z,preview:H}),e==null||e(z)},ee=k=>{k&&k.stopPropagation(),ue(S.current),S.current="",l(null),e==null||e(null),x.current&&(x.current.value="")},K=k=>{c&&(k.preventDefault(),g(!0))},N=k=>{c&&(k.preventDefault(),g(!1))},X=k=>{var z,H,F,te;c&&(k.preventDefault(),g(!1),(te=(F=(H=(z=k.dataTransfer)==null?void 0:z.files)==null?void 0:H[0])==null?void 0:F.type)!=null&&te.includes("image/")&&Y(k.dataTransfer.files))},B=()=>{var k;(k=x.current)==null||k.click()},M=h&&typeof h=="object"&&"preview"in h?h.preview:typeof h=="string"?h:"";return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:p||"col-span-12",children:[t.jsx(Q,{label:n,required:r}),t.jsxs("div",{className:`relative rounded-md p-2 transition-all ${m?"border-2 border-dashed border-blue-500 bg-blue-50 dark:bg-blue-900/20":"border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800"}`,onDragOver:K,onDragLeave:N,onDrop:X,children:[t.jsx("input",{ref:x,id:s,type:"file",accept:o,onChange:k=>Y(k.target.files),required:r&&!h,className:"absolute opacity-0 right-[50%] top-[80%] -translate-y-1/2 pointer-events-none h-[10px]"}),t.jsxs("div",{className:`flex items-center space-x-4 transition-all ${m?"opacity-50":""}`,children:[h?t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:M,alt:"preview",className:"object-cover w-20 h-20 rounded-full shadow-md"}),!r&&t.jsx("button",{type:"button",onClick:ee,className:"absolute top-0 -right-2 bg-red-500 text-white rounded-full p-1 shadow-lg hover:bg-red-600 transition-colors focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2","aria-label":"Remove image",children:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-3 h-3"})})]}):t.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:t.jsx(ce.Icon,{icon:"ri:image-add-fill",className:"text-gray-400 w-10 h-10"})}),t.jsxs("div",{className:"flex flex-col items-center space-y-1",children:[t.jsx(xr,{type:"button",onClick:B,variant:"outlined",color:"default",children:h?"Change Image":"Select Image"}),c&&!h&&t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop"})]})]}),c&&m&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-md",children:t.jsx("span",{className:"text-blue-600 dark:text-blue-400 font-semibold text-lg",children:"Drop image here"})})]})]},d),t.jsx(mr,{isOpen:j,imageSrc:R,fileType:L,fileName:I,onClose:D,onApply:P,aspect:Number(i)})]})},Rt=b.forwardRef(({label:n,value:a,required:e,parentClass:r="",className:o="",type:i="text",onKeyDown:s,negativeNumberAllow:c=!0,defaultValue:f="",field:d={},onChange:p,mask:h="",maskApplyOnValue:l=!0,...m},g)=>{const[j,v]=b.useState(!1),R=C=>{if(i==="number"){if(["e","E","+"].includes(C.key)){C.preventDefault();return}if(c==!1&&C.key==="-"){C.preventDefault();return}if(["ArrowUp","ArrowDown"].includes(C.key)){C.preventDefault();return}}s==null||s(C)},A=`
|
|
127
|
+
`,dr=1,ur=3,hr=1,pr=function(n){$t(a,n);function a(){var e=n!==null&&n.apply(this,arguments)||this;return e.cropperRef=ie.createRef(),e.imageRef=ie.createRef(),e.videoRef=ie.createRef(),e.containerPosition={x:0,y:0},e.containerRef=null,e.styleRef=null,e.containerRect=null,e.mediaSize={width:0,height:0,naturalWidth:0,naturalHeight:0},e.dragStartPosition={x:0,y:0},e.dragStartCrop={x:0,y:0},e.gestureZoomStart=0,e.gestureRotationStart=0,e.isTouching=!1,e.lastPinchDistance=0,e.lastPinchRotation=0,e.rafDragTimeout=null,e.rafPinchTimeout=null,e.wheelTimer=null,e.currentDoc=typeof document<"u"?document:null,e.currentWindow=typeof window<"u"?window:null,e.resizeObserver=null,e.previousCropSize=null,e.isInitialized=!1,e.state={cropSize:null,hasWheelJustStarted:!1,mediaObjectFit:void 0},e.initResizeObserver=function(){if(!(typeof window.ResizeObserver>"u"||!e.containerRef)){var r=!0;e.resizeObserver=new window.ResizeObserver(function(o){if(r){r=!1;return}e.computeSizes()}),e.resizeObserver.observe(e.containerRef)}},e.preventZoomSafari=function(r){return r.preventDefault()},e.cleanEvents=function(){e.currentDoc&&(e.currentDoc.removeEventListener("mousemove",e.onMouseMove),e.currentDoc.removeEventListener("mouseup",e.onDragStopped),e.currentDoc.removeEventListener("touchmove",e.onTouchMove),e.currentDoc.removeEventListener("touchend",e.onDragStopped),e.currentDoc.removeEventListener("gesturechange",e.onGestureChange),e.currentDoc.removeEventListener("gestureend",e.onGestureEnd),e.currentDoc.removeEventListener("scroll",e.onScroll))},e.clearScrollEvent=function(){e.containerRef&&e.containerRef.removeEventListener("wheel",e.onWheel),e.wheelTimer&&clearTimeout(e.wheelTimer)},e.onMediaLoad=function(){var r=e.computeSizes();r&&(e.previousCropSize=r,e.emitCropData(),e.setInitialCrop(r),e.isInitialized=!0),e.props.onMediaLoaded&&e.props.onMediaLoaded(e.mediaSize)},e.setInitialCrop=function(r){if(e.props.initialCroppedAreaPercentages){var o=or(e.props.initialCroppedAreaPercentages,e.mediaSize,e.props.rotation,r,e.props.minZoom,e.props.maxZoom),i=o.crop,s=o.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(s)}else if(e.props.initialCroppedAreaPixels){var c=ir(e.props.initialCroppedAreaPixels,e.mediaSize,e.props.rotation,r,e.props.minZoom,e.props.maxZoom),i=c.crop,s=c.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(s)}},e.computeSizes=function(){var r,o,i,s,c,f,d=e.imageRef.current||e.videoRef.current;if(d&&e.containerRef){e.containerRect=e.containerRef.getBoundingClientRect(),e.saveContainerPosition();var p=e.containerRect.width/e.containerRect.height,h=((r=e.imageRef.current)===null||r===void 0?void 0:r.naturalWidth)||((o=e.videoRef.current)===null||o===void 0?void 0:o.videoWidth)||0,l=((i=e.imageRef.current)===null||i===void 0?void 0:i.naturalHeight)||((s=e.videoRef.current)===null||s===void 0?void 0:s.videoHeight)||0,m=d.offsetWidth<h||d.offsetHeight<l,g=h/l,j=void 0;if(m)switch(e.state.mediaObjectFit){default:case"contain":j=p>g?{width:e.containerRect.height*g,height:e.containerRect.height}:{width:e.containerRect.width,height:e.containerRect.width/g};break;case"horizontal-cover":j={width:e.containerRect.width,height:e.containerRect.width/g};break;case"vertical-cover":j={width:e.containerRect.height*g,height:e.containerRect.height};break}else j={width:d.offsetWidth,height:d.offsetHeight};e.mediaSize=W(W({},j),{naturalWidth:h,naturalHeight:l}),e.props.setMediaSize&&e.props.setMediaSize(e.mediaSize);var v=e.props.cropSize?e.props.cropSize:er(e.mediaSize.width,e.mediaSize.height,e.containerRect.width,e.containerRect.height,e.props.aspect,e.props.rotation);return(((c=e.state.cropSize)===null||c===void 0?void 0:c.height)!==v.height||((f=e.state.cropSize)===null||f===void 0?void 0:f.width)!==v.width)&&e.props.onCropSizeChange&&e.props.onCropSizeChange(v),e.setState({cropSize:v},e.recomputeCropPosition),e.props.setCropSize&&e.props.setCropSize(v),v}},e.saveContainerPosition=function(){if(e.containerRef){var r=e.containerRef.getBoundingClientRect();e.containerPosition={x:r.left,y:r.top}}},e.onMouseDown=function(r){e.currentDoc&&(r.preventDefault(),e.currentDoc.addEventListener("mousemove",e.onMouseMove),e.currentDoc.addEventListener("mouseup",e.onDragStopped),e.saveContainerPosition(),e.onDragStart(a.getMousePoint(r)))},e.onMouseMove=function(r){return e.onDrag(a.getMousePoint(r))},e.onScroll=function(r){e.currentDoc&&(r.preventDefault(),e.saveContainerPosition())},e.onTouchStart=function(r){e.currentDoc&&(e.isTouching=!0,!(e.props.onTouchRequest&&!e.props.onTouchRequest(r))&&(e.currentDoc.addEventListener("touchmove",e.onTouchMove,{passive:!1}),e.currentDoc.addEventListener("touchend",e.onDragStopped),e.saveContainerPosition(),r.touches.length===2?e.onPinchStart(r):r.touches.length===1&&e.onDragStart(a.getTouchPoint(r.touches[0]))))},e.onTouchMove=function(r){r.preventDefault(),r.touches.length===2?e.onPinchMove(r):r.touches.length===1&&e.onDrag(a.getTouchPoint(r.touches[0]))},e.onGestureStart=function(r){e.currentDoc&&(r.preventDefault(),e.currentDoc.addEventListener("gesturechange",e.onGestureChange),e.currentDoc.addEventListener("gestureend",e.onGestureEnd),e.gestureZoomStart=e.props.zoom,e.gestureRotationStart=e.props.rotation)},e.onGestureChange=function(r){if(r.preventDefault(),!e.isTouching){var o=a.getMousePoint(r),i=e.gestureZoomStart-1+r.scale;if(e.setNewZoom(i,o,{shouldUpdatePosition:!0}),e.props.onRotationChange){var s=e.gestureRotationStart+r.rotation;e.props.onRotationChange(s)}}},e.onGestureEnd=function(r){e.cleanEvents()},e.onDragStart=function(r){var o,i,s=r.x,c=r.y;e.dragStartPosition={x:s,y:c},e.dragStartCrop=W({},e.props.crop),(i=(o=e.props).onInteractionStart)===null||i===void 0||i.call(o)},e.onDrag=function(r){var o=r.x,i=r.y;e.currentWindow&&(e.rafDragTimeout&&e.currentWindow.cancelAnimationFrame(e.rafDragTimeout),e.rafDragTimeout=e.currentWindow.requestAnimationFrame(function(){if(e.state.cropSize&&!(o===void 0||i===void 0)){var s=o-e.dragStartPosition.x,c=i-e.dragStartPosition.y,f={x:e.dragStartCrop.x+s,y:e.dragStartCrop.y+c},d=e.props.restrictPosition?ke(f,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):f;e.props.onCropChange(d)}}))},e.onDragStopped=function(){var r,o;e.isTouching=!1,e.cleanEvents(),e.emitCropData(),(o=(r=e.props).onInteractionEnd)===null||o===void 0||o.call(r)},e.onWheel=function(r){if(e.currentWindow&&!(e.props.onWheelRequest&&!e.props.onWheelRequest(r))){r.preventDefault();var o=a.getMousePoint(r),i=Qt(r).pixelY,s=e.props.zoom-i*e.props.zoomSpeed/200;e.setNewZoom(s,o,{shouldUpdatePosition:!0}),e.state.hasWheelJustStarted||e.setState({hasWheelJustStarted:!0},function(){var c,f;return(f=(c=e.props).onInteractionStart)===null||f===void 0?void 0:f.call(c)}),e.wheelTimer&&clearTimeout(e.wheelTimer),e.wheelTimer=e.currentWindow.setTimeout(function(){return e.setState({hasWheelJustStarted:!1},function(){var c,f;return(f=(c=e.props).onInteractionEnd)===null||f===void 0?void 0:f.call(c)})},250)}},e.getPointOnContainer=function(r,o){var i=r.x,s=r.y;if(!e.containerRect)throw new Error("The Cropper is not mounted");return{x:e.containerRect.width/2-(i-o.x),y:e.containerRect.height/2-(s-o.y)}},e.getPointOnMedia=function(r){var o=r.x,i=r.y,s=e.props,c=s.crop,f=s.zoom;return{x:(o+c.x)/f,y:(i+c.y)/f}},e.setNewZoom=function(r,o,i){var s=i===void 0?{}:i,c=s.shouldUpdatePosition,f=c===void 0?!0:c;if(!(!e.state.cropSize||!e.props.onZoomChange)){var d=Ue(r,e.props.minZoom,e.props.maxZoom);if(f){var p=e.getPointOnContainer(o,e.containerPosition),h=e.getPointOnMedia(p),l={x:h.x*d-p.x,y:h.y*d-p.y},m=e.props.restrictPosition?ke(l,e.mediaSize,e.state.cropSize,d,e.props.rotation):l;e.props.onCropChange(m)}e.props.onZoomChange(d)}},e.getCropData=function(){if(!e.state.cropSize)return null;var r=e.props.restrictPosition?ke(e.props.crop,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):e.props.crop;return rr(r,e.mediaSize,e.state.cropSize,e.getAspect(),e.props.zoom,e.props.rotation,e.props.restrictPosition)},e.emitCropData=function(){var r=e.getCropData();if(r){var o=r.croppedAreaPercentages,i=r.croppedAreaPixels;e.props.onCropComplete&&e.props.onCropComplete(o,i),e.props.onCropAreaChange&&e.props.onCropAreaChange(o,i)}},e.emitCropAreaChange=function(){var r=e.getCropData();if(r){var o=r.croppedAreaPercentages,i=r.croppedAreaPixels;e.props.onCropAreaChange&&e.props.onCropAreaChange(o,i)}},e.recomputeCropPosition=function(){var r,o;if(e.state.cropSize){var i=e.props.crop;if(e.isInitialized&&(!((r=e.previousCropSize)===null||r===void 0)&&r.width)&&(!((o=e.previousCropSize)===null||o===void 0)&&o.height)){var s=Math.abs(e.previousCropSize.width-e.state.cropSize.width)>1e-6||Math.abs(e.previousCropSize.height-e.state.cropSize.height)>1e-6;if(s){var c=e.state.cropSize.width/e.previousCropSize.width,f=e.state.cropSize.height/e.previousCropSize.height;i={x:e.props.crop.x*c,y:e.props.crop.y*f}}}var d=e.props.restrictPosition?ke(i,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):i;e.previousCropSize=e.state.cropSize,e.props.onCropChange(d),e.emitCropData()}},e.onKeyDown=function(r){var o,i,s=e.props,c=s.crop,f=s.onCropChange,d=s.keyboardStep,p=s.zoom,h=s.rotation,l=d;if(e.state.cropSize){r.shiftKey&&(l*=.2);var m=W({},c);switch(r.key){case"ArrowUp":m.y-=l,r.preventDefault();break;case"ArrowDown":m.y+=l,r.preventDefault();break;case"ArrowLeft":m.x-=l,r.preventDefault();break;case"ArrowRight":m.x+=l,r.preventDefault();break;default:return}e.props.restrictPosition&&(m=ke(m,e.mediaSize,e.state.cropSize,p,h)),r.repeat||(i=(o=e.props).onInteractionStart)===null||i===void 0||i.call(o),f(m)}},e.onKeyUp=function(r){var o,i;switch(r.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":r.preventDefault();break;default:return}e.emitCropData(),(i=(o=e.props).onInteractionEnd)===null||i===void 0||i.call(o)},e}return a.prototype.componentDidMount=function(){!this.currentDoc||!this.currentWindow||(this.containerRef&&(this.containerRef.ownerDocument&&(this.currentDoc=this.containerRef.ownerDocument),this.currentDoc.defaultView&&(this.currentWindow=this.currentDoc.defaultView),this.initResizeObserver(),typeof window.ResizeObserver>"u"&&this.currentWindow.addEventListener("resize",this.computeSizes),this.props.zoomWithScroll&&this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}),this.containerRef.addEventListener("gesturestart",this.onGestureStart)),this.currentDoc.addEventListener("scroll",this.onScroll),this.props.disableAutomaticStylesInjection||(this.styleRef=this.currentDoc.createElement("style"),this.styleRef.setAttribute("type","text/css"),this.props.nonce&&this.styleRef.setAttribute("nonce",this.props.nonce),this.styleRef.innerHTML=cr,this.currentDoc.head.appendChild(this.styleRef)),this.imageRef.current&&this.imageRef.current.complete&&this.onMediaLoad(),this.props.setImageRef&&this.props.setImageRef(this.imageRef),this.props.setVideoRef&&this.props.setVideoRef(this.videoRef),this.props.setCropperRef&&this.props.setCropperRef(this.cropperRef))},a.prototype.componentWillUnmount=function(){var e,r;!this.currentDoc||!this.currentWindow||(typeof window.ResizeObserver>"u"&&this.currentWindow.removeEventListener("resize",this.computeSizes),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),this.containerRef&&this.containerRef.removeEventListener("gesturestart",this.preventZoomSafari),this.styleRef&&((r=this.styleRef.parentNode)===null||r===void 0||r.removeChild(this.styleRef)),this.cleanEvents(),this.props.zoomWithScroll&&this.clearScrollEvent())},a.prototype.componentDidUpdate=function(e){var r,o,i,s,c,f,d,p,h;e.rotation!==this.props.rotation?(this.computeSizes(),this.recomputeCropPosition()):e.aspect!==this.props.aspect?this.computeSizes():e.objectFit!==this.props.objectFit?this.computeSizes():e.zoom!==this.props.zoom?this.recomputeCropPosition():((r=e.cropSize)===null||r===void 0?void 0:r.height)!==((o=this.props.cropSize)===null||o===void 0?void 0:o.height)||((i=e.cropSize)===null||i===void 0?void 0:i.width)!==((s=this.props.cropSize)===null||s===void 0?void 0:s.width)?this.computeSizes():(((c=e.crop)===null||c===void 0?void 0:c.x)!==((f=this.props.crop)===null||f===void 0?void 0:f.x)||((d=e.crop)===null||d===void 0?void 0:d.y)!==((p=this.props.crop)===null||p===void 0?void 0:p.y))&&this.emitCropAreaChange(),e.zoomWithScroll!==this.props.zoomWithScroll&&this.containerRef&&(this.props.zoomWithScroll?this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}):this.clearScrollEvent()),e.video!==this.props.video&&((h=this.videoRef.current)===null||h===void 0||h.load());var l=this.getObjectFit();l!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:l},this.computeSizes)},a.prototype.getAspect=function(){var e=this.props,r=e.cropSize,o=e.aspect;return r?r.width/r.height:o},a.prototype.getObjectFit=function(){var e,r,o,i;if(this.props.objectFit==="cover"){var s=this.imageRef.current||this.videoRef.current;if(s&&this.containerRef){this.containerRect=this.containerRef.getBoundingClientRect();var c=this.containerRect.width/this.containerRect.height,f=((e=this.imageRef.current)===null||e===void 0?void 0:e.naturalWidth)||((r=this.videoRef.current)===null||r===void 0?void 0:r.videoWidth)||0,d=((o=this.imageRef.current)===null||o===void 0?void 0:o.naturalHeight)||((i=this.videoRef.current)===null||i===void 0?void 0:i.videoHeight)||0,p=f/d;return p<c?"horizontal-cover":"vertical-cover"}return"horizontal-cover"}return this.props.objectFit},a.prototype.onPinchStart=function(e){var r=a.getTouchPoint(e.touches[0]),o=a.getTouchPoint(e.touches[1]);this.lastPinchDistance=st(r,o),this.lastPinchRotation=it(r,o),this.onDragStart(lt(r,o))},a.prototype.onPinchMove=function(e){var r=this;if(!(!this.currentDoc||!this.currentWindow)){var o=a.getTouchPoint(e.touches[0]),i=a.getTouchPoint(e.touches[1]),s=lt(o,i);this.onDrag(s),this.rafPinchTimeout&&this.currentWindow.cancelAnimationFrame(this.rafPinchTimeout),this.rafPinchTimeout=this.currentWindow.requestAnimationFrame(function(){var c=st(o,i),f=r.props.zoom*(c/r.lastPinchDistance);r.setNewZoom(f,s,{shouldUpdatePosition:!1}),r.lastPinchDistance=c;var d=it(o,i),p=r.props.rotation+(d-r.lastPinchRotation);r.props.onRotationChange&&r.props.onRotationChange(p),r.lastPinchRotation=d})}},a.prototype.render=function(){var e=this,r,o=this.props,i=o.image,s=o.video,c=o.mediaProps,f=o.cropperProps,d=o.transform,p=o.crop,h=p.x,l=p.y,m=o.rotation,g=o.zoom,j=o.cropShape,v=o.showGrid,R=o.roundCropAreaPixels,A=o.style,L=A.containerStyle,C=A.cropAreaStyle,I=A.mediaStyle,E=o.classes,x=E.containerClassName,w=E.cropAreaClassName,S=E.mediaClassName,D=(r=this.state.mediaObjectFit)!==null&&r!==void 0?r:this.getObjectFit();return ie.createElement("div",{onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart,ref:function(Y){return e.containerRef=Y},"data-testid":"container",style:L,className:Te("reactEasyCrop_Container",x)},i?ie.createElement("img",W({alt:"",className:Te("reactEasyCrop_Image",D==="contain"&&"reactEasyCrop_Contain",D==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",D==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",S)},c,{src:i,ref:this.imageRef,style:W(W({},I),{transform:d||"translate(".concat(h,"px, ").concat(l,"px) rotate(").concat(m,"deg) scale(").concat(g,")")}),onLoad:this.onMediaLoad})):s&&ie.createElement("video",W({autoPlay:!0,playsInline:!0,loop:!0,muted:!0,className:Te("reactEasyCrop_Video",D==="contain"&&"reactEasyCrop_Contain",D==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",D==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",S)},c,{ref:this.videoRef,onLoadedMetadata:this.onMediaLoad,style:W(W({},I),{transform:d||"translate(".concat(h,"px, ").concat(l,"px) rotate(").concat(m,"deg) scale(").concat(g,")")}),controls:!1}),(Array.isArray(s)?s:[{src:s}]).map(function(P){return ie.createElement("source",W({key:P.src},P))})),this.state.cropSize&&ie.createElement("div",W({ref:this.cropperRef,style:W(W({},C),{width:R?Math.round(this.state.cropSize.width):this.state.cropSize.width,height:R?Math.round(this.state.cropSize.height):this.state.cropSize.height}),tabIndex:0,onKeyDown:this.onKeyDown,onKeyUp:this.onKeyUp,"data-testid":"cropper",className:Te("reactEasyCrop_CropArea",j==="round"&&"reactEasyCrop_CropAreaRound",v&&"reactEasyCrop_CropAreaGrid",w)},f)))},a.defaultProps={zoom:1,rotation:0,aspect:4/3,maxZoom:ur,minZoom:dr,cropShape:"rect",objectFit:"contain",showGrid:!0,style:{},classes:{},mediaProps:{},cropperProps:{},zoomSpeed:1,restrictPosition:!0,zoomWithScroll:!0,keyboardStep:hr},a.getMousePoint=function(e){return{x:Number(e.clientX),y:Number(e.clientY)}},a.getTouchPoint=function(e){return{x:Number(e.clientX),y:Number(e.clientY)}},a}(ie.Component);const ct=ae,fr=n=>new Promise((a,e)=>{const r=new Image;r.addEventListener("load",()=>a(r)),r.addEventListener("error",o=>e(o)),r.setAttribute("crossOrigin","anonymous"),r.src=n}),Mt=n=>n*Math.PI/180,br=(n,a,e)=>{const r=Mt(e);return{width:Math.abs(Math.cos(r)*n)+Math.abs(Math.sin(r)*a),height:Math.abs(Math.sin(r)*n)+Math.abs(Math.cos(r)*a)}},gr=async(n,a,e="image/jpeg",r=0)=>{const o=await fr(n),i=document.createElement("canvas"),s=i.getContext("2d");if(!s)throw new Error("Canvas context is not available");const c=Mt(r),{width:f,height:d}=br(o.width,o.height,r);i.width=f,i.height=d,s.translate(f/2,d/2),s.rotate(c),s.translate(-o.width/2,-o.height/2),s.drawImage(o,0,0);const p=document.createElement("canvas"),h=p.getContext("2d");if(!h)throw new Error("Canvas context is not available");return p.width=a.width,p.height=a.height,h.drawImage(i,a.x,a.y,a.width,a.height,0,0,a.width,a.height),new Promise((l,m)=>{p.toBlob(g=>{if(!g){m(new Error("Image cropping failed"));return}l(g)},e,.95)})},mr=({isOpen:n,imageSrc:a,fileType:e="image/jpeg",fileName:r="cropped-image",aspect:o=1/1,title:i="Crop Image",onClose:s,onApply:c})=>{const[f,d]=b.useState({x:0,y:0}),[p,h]=b.useState(1),[l,m]=b.useState(null);b.useEffect(()=>{n&&(d({x:0,y:0}),h(1),m(null))},[n]);const g=b.useCallback((v,R)=>{m(R)},[]),j=async()=>{var v,R;if(!(!a||!l))try{const A=await gr(a,l,e),L=((R=(v=e==null?void 0:e.split("/"))==null?void 0:v[1])==null?void 0:R.replace("jpeg","jpg"))||"jpg",C=new File([A],`${r}.${L}`,{type:e});c==null||c(C)}catch{s==null||s()}};return n?t.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[t.jsx("div",{className:"fixed inset-0 bg-gray-500 opacity-75",onClick:s}),t.jsxs("div",{className:"relative bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col dark:bg-gray-800",children:[t.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[t.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:i}),t.jsx("button",{type:"button",onClick:s,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300","aria-label":"Close crop modal",children:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-6 h-6"})})]}),t.jsxs("div",{className:"p-4 space-y-4",children:[t.jsx("div",{className:"relative h-72 w-full bg-gray-900 rounded-md overflow-hidden",children:a&&t.jsx(pr,{image:a,crop:f,zoom:p,aspect:o,onCropChange:d,onZoomChange:h,onCropComplete:g})}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-sm text-gray-700 dark:text-gray-300",children:"Zoom"}),t.jsx("input",{type:"range",min:1,max:3,step:.1,value:p,onChange:v=>h(Number(v.target.value)),className:"w-full"})]})]}),t.jsxs("div",{className:"px-4 py-3 flex justify-end gap-3 border-t border-gray-200 dark:border-gray-700 sm:!px-6",children:[t.jsx(ct,{type:"button",onClick:s,variant:"outlined",color:"default",children:"Cancel"}),t.jsx(ct,{type:"button",onClick:j,variant:"contained",color:"primary",children:"Apply Crop"})]})]})]}):null},xr=ae,ue=n=>{typeof n=="string"&&n.startsWith("blob:")&&URL.revokeObjectURL(n)},yr=({label:n="",value:a=null,onChange:e,required:r=!1,accept:o="image/*",aspect:i="1",id:s,dragDrop:c=!1,cropImage:f=!1,name:d="",parentClass:p=""})=>{const[h,l]=b.useState(a),[m,g]=b.useState(!1),[j,v]=b.useState(!1),[R,A]=b.useState(""),[L,C]=b.useState("image/jpeg"),[I,E]=b.useState("cropped-image"),x=b.useRef(null),w=b.useRef(""),S=b.useRef("");b.useEffect(()=>{if(a instanceof File){const k=URL.createObjectURL(a);ue(S.current),S.current=k,l({file:a,preview:k})}else a&&typeof a=="object"&&"preview"in a,l(a)},[a]),b.useEffect(()=>()=>{ue(S.current),ue(w.current)},[]);const D=()=>{v(!1),ue(w.current),w.current="",A(""),x.current&&(x.current.value="")},P=k=>{const z=URL.createObjectURL(k);ue(S.current),S.current=z,l({file:k,preview:z}),e==null||e(k),D()},Y=k=>{if(!k||k.length===0)return;const z=k[0];if(f){const F=URL.createObjectURL(z);ue(w.current),w.current=F,A(F),C(z.type||"image/jpeg"),E((z.name||"cropped-image").replace(/\.[^/.]+$/,"")),v(!0);return}const H=URL.createObjectURL(z);ue(S.current),S.current=H,l({file:z,preview:H}),e==null||e(z)},ee=k=>{k&&k.stopPropagation(),ue(S.current),S.current="",l(null),e==null||e(null),x.current&&(x.current.value="")},G=k=>{c&&(k.preventDefault(),g(!0))},N=k=>{c&&(k.preventDefault(),g(!1))},X=k=>{var z,H,F,te;c&&(k.preventDefault(),g(!1),(te=(F=(H=(z=k.dataTransfer)==null?void 0:z.files)==null?void 0:H[0])==null?void 0:F.type)!=null&&te.includes("image/")&&Y(k.dataTransfer.files))},B=()=>{var k;(k=x.current)==null||k.click()},M=h&&typeof h=="object"&&"preview"in h?h.preview:typeof h=="string"?h:"";return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:p||"col-span-12",children:[t.jsx(Q,{label:n,required:r}),t.jsxs("div",{className:`relative rounded-md p-2 transition-all ${m?"border-2 border-dashed border-blue-500 bg-blue-50 dark:bg-blue-900/20":"border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800"}`,onDragOver:G,onDragLeave:N,onDrop:X,children:[t.jsx("input",{ref:x,id:s,type:"file",accept:o,onChange:k=>Y(k.target.files),required:r&&!h,className:"absolute opacity-0 right-[50%] top-[80%] -translate-y-1/2 pointer-events-none h-[10px]"}),t.jsxs("div",{className:`flex items-center space-x-4 transition-all ${m?"opacity-50":""}`,children:[h?t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:M,alt:"preview",className:"object-cover w-20 h-20 rounded-full shadow-md"}),!r&&t.jsx("button",{type:"button",onClick:ee,className:"absolute top-0 -right-2 bg-red-500 text-white rounded-full p-1 shadow-lg hover:bg-red-600 transition-colors focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2","aria-label":"Remove image",children:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-3 h-3"})})]}):t.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:t.jsx(ce.Icon,{icon:"ri:image-add-fill",className:"text-gray-400 w-10 h-10"})}),t.jsxs("div",{className:"flex flex-col items-center space-y-1",children:[t.jsx(xr,{type:"button",onClick:B,variant:"outlined",color:"default",children:h?"Change Image":"Select Image"}),c&&!h&&t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop"})]})]}),c&&m&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-md",children:t.jsx("span",{className:"text-blue-600 dark:text-blue-400 font-semibold text-lg",children:"Drop image here"})})]})]},d),t.jsx(mr,{isOpen:j,imageSrc:R,fileType:L,fileName:I,onClose:D,onApply:P,aspect:Number(i)})]})},Rt=b.forwardRef(({label:n,value:a,required:e,parentClass:r="",className:o="",type:i="text",onKeyDown:s,negativeNumberAllow:c=!0,defaultValue:f="",field:d={},onChange:p,mask:h="",maskApplyOnValue:l=!0,...m},g)=>{const[j,v]=b.useState(!1),R=C=>{if(i==="number"){if(["e","E","+"].includes(C.key)){C.preventDefault();return}if(c==!1&&C.key==="-"){C.preventDefault();return}if(["ArrowUp","ArrowDown"].includes(C.key)){C.preventDefault();return}}s==null||s(C)},A=`
|
|
128
128
|
h-10 placeholder-gray-400 dark:placeholder-gray-400
|
|
129
129
|
${i==="password"?"pr-10":""}
|
|
130
130
|
${i==="number"?"no-spinner":""}
|
|
@@ -143,10 +143,10 @@
|
|
|
143
143
|
${s}
|
|
144
144
|
${i}
|
|
145
145
|
${r}`,children:n})},_t=({col:n,data:a})=>{var f;const e=n==null?void 0:n.icon,r=n.label;let o=a[n.key];const i=n.type,s=n.variant||"outline";let c=n.defaultColor;if(i==="chip"&&((f=n.chipOptions)==null?void 0:f.length)>0){const d=n==null?void 0:n.chipOptions.find(p=>p.value==o);d&&(o=d.label,c=d.color)}return t.jsxs("div",{className:`col-span-12 flex items-center space-x-4 p-4 rounded-xl
|
|
146
|
-
bg-gray-100 dark:bg-gray-900 ${n.blockClass||""}`,children:[e&&t.jsx("div",{className:"flex-shrink-0",children:e}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:r}),i==="chip"?t.jsx(Et,{label:o,variant:s,color:c,className:"mt-1"}):i==="tinyEditor"?t.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-white break-words",dangerouslySetInnerHTML:{__html:o}}):i==="audio"?o?t.jsx("audio",{controls:!0,src:o instanceof File?URL.createObjectURL(o):o,onClick:d=>d.stopPropagation(),className:"shadow-md rounded-full mt-1"},o instanceof File?URL.createObjectURL(o):o):t.jsx("p",{className:"mt-1 text-sm text-gray-400",children:"N/A"}):t.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-white break-words",children:i=="date"?t.jsx("span",{children:gt(o,n.format||"DD MMM YYYY")}):o||"N/A"})]})]})},kr=({value:n=!0,onChange:a,text:e,options:r=[],label:o,required:i,name:s="",disabled:c=!1,parentClass:f=""})=>{const d=r.length>0?r:[{label:"Active",value:!0},{label:"Inactive",value:!1}];return t.jsx(t.Fragment,{children:t.jsxs("div",{className:f||"col-span-12",children:[t.jsx(Q,{label:o,required:i}),t.jsxs("div",{className:"flex items-center justify-between h-10 gap-4 bg-gray-100 dark:bg-gray-700 px-3 rounded-md border border-gray-100 dark:border-gray-600",children:[e&&t.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap max-w-[200px]",children:e}),t.jsx("div",{className:"flex items-center gap-6",children:d.map((p,h)=>t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"radio",name:"switch-field",required:i&&h===0,value:String(p.value),disabled:c,checked:n===p.value,onChange:()=>a==null?void 0:a(p.value),className:"w-4 h-4 border-gray-300 cursor-pointer"}),t.jsx("span",{className:"text-sm text-gray-700 dark:text-white",children:p.label})]},h))})]})]},s)})},pt=ae,Sr=({label:n="",value:a=null,onChange:e,required:r=!1,accept:o="video/*",id:i,dragDrop:s=!1,name:c="",parentClass:f="",maxSize:d=0})=>{const[p,h]=b.useState(null),[l,m]=b.useState(!1),g=b.useRef(null),j=d*1024*1024;b.useEffect(()=>{if(!a){v(),h(null);return}if(a instanceof File){const x=URL.createObjectURL(a);return h({file:a,preview:x}),()=>{URL.revokeObjectURL(x)}}else typeof a=="string"?h({preview:a}):a!=null&&a.preview&&h(a)},[a]);const v=()=>{p!=null&&p.preview&&p.preview.startsWith("blob:")&&URL.revokeObjectURL(p.preview)},R=x=>{if(!x||x.length===0)return;const w=x[0];if(j&&w.size>j){le.enqueueSnackbar(`File is too large. Maximum allowed size is ${d} MB`,{variant:"warning"});return}const S=URL.createObjectURL(w);v(),h({file:w,preview:S}),e==null||e(w)},A=x=>{x&&x.stopPropagation(),v(),h(null),e==null||e(null),g.current&&(g.current.value="")},L=x=>{s&&(x.preventDefault(),m(!0))},C=x=>{s&&(x.preventDefault(),m(!1))},I=x=>{var w,S,D,P;s&&(x.preventDefault(),m(!1),(P=(D=(S=(w=x.dataTransfer)==null?void 0:w.files)==null?void 0:S[0])==null?void 0:D.type)!=null&&P.includes("video/")&&R(x.dataTransfer.files))},E=()=>{var x;(x=g.current)==null||x.click()};return t.jsxs("div",{className:f||"col-span-12",children:[t.jsx(Q,{label:n,required:r}),t.jsxs("div",{className:`relative rounded-lg p-2 transition-all ${l?"border-2 border-dashed border-blue-500 bg-blue-50 dark:bg-blue-900/20":"border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800"}`,onDragOver:L,onDragLeave:C,onDrop:I,children:[t.jsx("input",{ref:g,id:i,type:"file",accept:o,onChange:x=>R(x.target.files),required:r&&!p,className:"absolute opacity-0 pointer-events-none h-[10px]"}),t.jsx("div",{className:`flex items-center space-x-4 transition-all ${l?"opacity-50":""}`,children:p?t.jsxs("div",{className:"flex items-center space-x-4",children:[t.jsxs("div",{className:"relative",children:[!r&&t.jsx("button",{type:"button",onClick:A,className:"absolute -top-2 -right-2 bg-red-500 text-white rounded-full p-1 shadow hover:bg-red-600 z-10",children:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-3 h-3"})}),t.jsx("video",{src:p.preview,controls:!0,controlsList:"nodownload",className:"w-[260px] h-[150px] rounded-md object-cover"},p.preview)]}),t.jsx(pt,{type:"button",onClick:E,children:"Change Video File"})]}):t.jsxs("div",{className:"flex items-center justify-center space-x-4",children:[t.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:t.jsx(ce.Icon,{icon:"mdi:video",className:"text-gray-400 w-10 h-10"})}),t.jsx(pt,{type:"button",onClick:E,variant:"outlined",children:"Choose Video File"}),s&&t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop your video here"})]})}),s&&l&&!p&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-lg",children:t.jsx("span",{className:"text-blue-600 dark:text-blue-400 font-semibold text-lg bg-white dark:bg-gray-800 px-4 py-2 rounded-lg shadow-lg",children:"Drop video here"})})]})]},c)},Pt=({field:n,formData:a,handleChange:e})=>{const{key:r,label:o,type:i,options:s,placeholder:c,rows:f,inputClass:d,search:p,accept:h,text:l,required:m=!1,minLength:g,dragDrop:j,parentClass:v,countriesList:R,defaultCountry:A,multiple:L,dropdownMaxHeight:C,editorKey:I,fontFamily:E,disabled:x,negativeNumberAllow:w,defaultValue:S,renderCondition:D,pattern:P,renderType:Y,cropImage:ee,aspectRatio:
|
|
146
|
+
bg-gray-100 dark:bg-gray-900 ${n.blockClass||""}`,children:[e&&t.jsx("div",{className:"flex-shrink-0",children:e}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:r}),i==="chip"?t.jsx(Et,{label:o,variant:s,color:c,className:"mt-1"}):i==="tinyEditor"?t.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-white break-words",dangerouslySetInnerHTML:{__html:o}}):i==="audio"?o?t.jsx("audio",{controls:!0,src:o instanceof File?URL.createObjectURL(o):o,onClick:d=>d.stopPropagation(),className:"shadow-md rounded-full mt-1"},o instanceof File?URL.createObjectURL(o):o):t.jsx("p",{className:"mt-1 text-sm text-gray-400",children:"N/A"}):t.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-white break-words",children:i=="date"?t.jsx("span",{children:gt(o,n.format||"DD MMM YYYY")}):o||"N/A"})]})]})},kr=({value:n=!0,onChange:a,text:e,options:r=[],label:o,required:i,name:s="",disabled:c=!1,parentClass:f=""})=>{const d=r.length>0?r:[{label:"Active",value:!0},{label:"Inactive",value:!1}];return t.jsx(t.Fragment,{children:t.jsxs("div",{className:f||"col-span-12",children:[t.jsx(Q,{label:o,required:i}),t.jsxs("div",{className:"flex items-center justify-between h-10 gap-4 bg-gray-100 dark:bg-gray-700 px-3 rounded-md border border-gray-100 dark:border-gray-600",children:[e&&t.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap max-w-[200px]",children:e}),t.jsx("div",{className:"flex items-center gap-6",children:d.map((p,h)=>t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"radio",name:"switch-field",required:i&&h===0,value:String(p.value),disabled:c,checked:n===p.value,onChange:()=>a==null?void 0:a(p.value),className:"w-4 h-4 border-gray-300 cursor-pointer"}),t.jsx("span",{className:"text-sm text-gray-700 dark:text-white",children:p.label})]},h))})]})]},s)})},pt=ae,Sr=({label:n="",value:a=null,onChange:e,required:r=!1,accept:o="video/*",id:i,dragDrop:s=!1,name:c="",parentClass:f="",maxSize:d=0})=>{const[p,h]=b.useState(null),[l,m]=b.useState(!1),g=b.useRef(null),j=d*1024*1024;b.useEffect(()=>{if(!a){v(),h(null);return}if(a instanceof File){const x=URL.createObjectURL(a);return h({file:a,preview:x}),()=>{URL.revokeObjectURL(x)}}else typeof a=="string"?h({preview:a}):a!=null&&a.preview&&h(a)},[a]);const v=()=>{p!=null&&p.preview&&p.preview.startsWith("blob:")&&URL.revokeObjectURL(p.preview)},R=x=>{if(!x||x.length===0)return;const w=x[0];if(j&&w.size>j){le.enqueueSnackbar(`File is too large. Maximum allowed size is ${d} MB`,{variant:"warning"});return}const S=URL.createObjectURL(w);v(),h({file:w,preview:S}),e==null||e(w)},A=x=>{x&&x.stopPropagation(),v(),h(null),e==null||e(null),g.current&&(g.current.value="")},L=x=>{s&&(x.preventDefault(),m(!0))},C=x=>{s&&(x.preventDefault(),m(!1))},I=x=>{var w,S,D,P;s&&(x.preventDefault(),m(!1),(P=(D=(S=(w=x.dataTransfer)==null?void 0:w.files)==null?void 0:S[0])==null?void 0:D.type)!=null&&P.includes("video/")&&R(x.dataTransfer.files))},E=()=>{var x;(x=g.current)==null||x.click()};return t.jsxs("div",{className:f||"col-span-12",children:[t.jsx(Q,{label:n,required:r}),t.jsxs("div",{className:`relative rounded-lg p-2 transition-all ${l?"border-2 border-dashed border-blue-500 bg-blue-50 dark:bg-blue-900/20":"border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800"}`,onDragOver:L,onDragLeave:C,onDrop:I,children:[t.jsx("input",{ref:g,id:i,type:"file",accept:o,onChange:x=>R(x.target.files),required:r&&!p,className:"absolute opacity-0 pointer-events-none h-[10px]"}),t.jsx("div",{className:`flex items-center space-x-4 transition-all ${l?"opacity-50":""}`,children:p?t.jsxs("div",{className:"flex items-center space-x-4",children:[t.jsxs("div",{className:"relative",children:[!r&&t.jsx("button",{type:"button",onClick:A,className:"absolute -top-2 -right-2 bg-red-500 text-white rounded-full p-1 shadow hover:bg-red-600 z-10",children:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-3 h-3"})}),t.jsx("video",{src:p.preview,controls:!0,controlsList:"nodownload",className:"w-[260px] h-[150px] rounded-md object-cover"},p.preview)]}),t.jsx(pt,{type:"button",onClick:E,children:"Change Video File"})]}):t.jsxs("div",{className:"flex items-center justify-center space-x-4",children:[t.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:t.jsx(ce.Icon,{icon:"mdi:video",className:"text-gray-400 w-10 h-10"})}),t.jsx(pt,{type:"button",onClick:E,variant:"outlined",children:"Choose Video File"}),s&&t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop your video here"})]})}),s&&l&&!p&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-lg",children:t.jsx("span",{className:"text-blue-600 dark:text-blue-400 font-semibold text-lg bg-white dark:bg-gray-800 px-4 py-2 rounded-lg shadow-lg",children:"Drop video here"})})]})]},c)},Pt=({field:n,formData:a,handleChange:e})=>{const{key:r,label:o,type:i,options:s,placeholder:c,rows:f,inputClass:d,search:p,accept:h,text:l,required:m=!1,minLength:g,dragDrop:j,parentClass:v,countriesList:R,defaultCountry:A,multiple:L,dropdownMaxHeight:C,editorKey:I,fontFamily:E,disabled:x,negativeNumberAllow:w,defaultValue:S,renderCondition:D,pattern:P,renderType:Y,cropImage:ee,aspectRatio:G,dependencyKey:N,mask:X,maskApplyOnValue:B,maxSize:M}=n;let k=a==null?void 0:a[r];k==null&&(k="");const z=c||(i==="select"?`Select ${o}`:`Enter ${o}`),H="w-full px-3 py-2 rounded-md border border-gray-300 dark:border-gray-600 text-sm focus:outline-none focus:ring-1 focus:ring-blue-200 bg-white text-black dark:bg-gray-700 dark:text-white";if(D&&typeof D=="function"&&!D(a))return null;if(Y&&Y=="details")switch(i){case"group":return t.jsx(Ct,{col:n,data:a});case"cardGroup":return t.jsx(Dt,{col:n,data:a});default:return t.jsx(_t,{col:n,data:a})}switch(i){case"select":return t.jsx(zt,{options:s||[],value:k,formData:a,dependencyKey:N,onChange:F=>e(r,F),placeholder:z,className:d||"",search:p,required:m,defaultValue:S,label:o||"",name:r,disabled:x,parentClass:v||"",multiple:L,dropdownMaxHeight:C});case"checkbox":return t.jsx(wr,{name:r,label:o||"",options:s||[],value:k,onChange:F=>e(r,F),required:m,parentClass:v||"",className:d||"",multiSelect:L,disabled:x});case"radio":return t.jsx(kr,{value:k,onChange:F=>e(r,F),text:l,options:s||[],label:o||"",required:m,name:r,disabled:x,parentClass:v||""});case"switch":return t.jsx(mt,{value:!!k,onChange:F=>e(r,F),label:o||"",required:m,name:r,disabled:x,className:"",parentClass:v||""});case"phone":return t.jsx(Bt,{value:k,onChange:F=>e(r,F),countriesList:R,defaultCountry:A,required:m,placeholder:z,search:p,label:o||"",name:r,disabled:x,parentClass:v||""});case"textarea":return t.jsx(xt,{value:k,onChange:F=>e(r,F.target.value),placeholder:z,rows:f||3,className:`${H} ${d||""}`,required:m,name:r,label:o||"",disabled:x,parentClass:v||""});case"image":return t.jsx(yr,{value:k,onChange:F=>e(r,F),required:m,accept:h||"image/*",aspect:G,id:`file-${r}`,dragDrop:j,cropImage:ee,label:o||"",name:r,parentClass:v||""});case"audio":return t.jsx(jr,{value:k,onChange:F=>e(r,F),required:m,accept:h||"audio/*",id:`file-${r}`,dragDrop:j,label:o||"",name:r,parentClass:v||"",maxSize:M});case"video":return t.jsx(Sr,{value:k,onChange:F=>e(r,F),required:m,accept:h||"video/*",id:`file-${r}`,dragDrop:j,label:o||"",name:r,maxSize:M,parentClass:v||""});case"tinyEditor":return t.jsx(vr,{value:k,onChange:F=>e(r,F),required:m,placeholder:z,label:o||"",parentClass:v||"",fontFamily:E,editorKey:I||"",disabled:x});default:return t.jsx(Rt,{field:n,type:i||"text",defaultValue:S,value:k,onChange:F=>e(r,F),placeholder:z,className:`${H} ${d||""}`,required:m,name:r,minLength:g,label:o||"",negativeNumberAllow:w,parentClass:v||"",disabled:x,pattern:P,mask:X,maskApplyOnValue:B})}},Nr=({isOpen:n,onClose:a,config:e,onApply:r})=>{var p;const[o,i]=b.useState({}),s=(h,l)=>{i(m=>({...m,[h]:l}))},c=()=>{r(o),a()},f=()=>{i({}),r({}),a()},d=e==null?void 0:e.component;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`fixed inset-0 bg-black/50 z-40 transition-opacity duration-300 ${n?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none"}`,onClick:a}),t.jsxs("div",{className:`fixed top-0 right-0 h-full w-[28rem] bg-white dark:bg-gray-900 shadow-2xl z-50 flex flex-col border-l border-gray-200 dark:border-gray-700
|
|
147
147
|
transform transition-transform duration-300 ease-in-out
|
|
148
148
|
${n?"translate-x-0":"translate-x-full"}
|
|
149
|
-
`,children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Filters"}),t.jsx("button",{onClick:a,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md transition",children:t.jsx(U.X,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),n&&t.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:d?t.jsx(d,{filters:o,onFilterChange:s}):t.jsx("div",{className:"space-y-4",children:(p=e==null?void 0:e.fields)==null?void 0:p.map(h=>t.jsx(Pt,{field:h,formData:o,handleChange:s},h.key))})}),t.jsxs("div",{className:"flex gap-2 px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:[t.jsx(ae,{onClick:c,variant:"contained",color:"primary",fullWidth:!0,children:"Apply Filters"}),t.jsx(ae,{onClick:f,variant:"contained",className:"min-w-[150px]",children:"Reset"})]})]})]})},Mr=({rows:n=5,columns:a=5})=>t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w-full mb-6 inline-flex justify-end items-center",children:t.jsx("div",{className:"h-8 w-80 bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})}),t.jsx("div",{className:"overflow-hidden rounded-md border border-gray-200 dark:border-gray-800",children:t.jsxs("table",{className:"w-full border-collapse",children:[t.jsx("thead",{children:t.jsx("tr",{className:"bg-gray-50 dark:bg-gray-900",children:Array.from({length:a}).map((e,r)=>t.jsx("th",{className:"px-4 py-3",children:t.jsx("div",{className:"h-6 w-24 bg-gray-300 dark:bg-gray-700 rounded animate-pulse inline-flex justify-center items-center"})},r))})}),t.jsx("tbody",{children:Array.from({length:n}).map((e,r)=>t.jsx("tr",{className:"border-t border-gray-200 dark:border-gray-800",children:Array.from({length:a}).map((o,i)=>t.jsx("td",{className:"px-4 py-6",children:t.jsx("div",{className:"h-6 w-full bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})},i))},r))})]})})]}),Rr=({options:n=[],value:a="",onChange:e,clearLabel:r=""})=>{const[o,i]=b.useState(!1),s=b.useRef(null),c=!!a;b.useEffect(()=>{const d=p=>{s.current&&!s.current.contains(p.target)&&i(!1)};return document.addEventListener("click",d),()=>document.removeEventListener("click",d)},[]);const f=d=>{const p=n.find(h=>h.value===d);e(d,p||null),i(!1)};return n!=null&&n.length?t.jsxs("div",{className:"relative",ref:s,children:[t.jsxs("button",{type:"button",onClick:()=>i(d=>!d),className:"relative inline-flex items-center justify-center h-[36px] w-[36px] rounded-md border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-700 text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-600 transition","aria-label":"Open sort options",children:[t.jsx(U.ArrowUpDown,{className:"w-4 h-4"}),c&&t.jsx("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]}),o&&t.jsxs("div",{className:"absolute right-0 mt-2 z-20 min-w-[220px] max-h-[260px] overflow-auto rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-lg",children:[!!(r!=null&&r.trim())&&t.jsx("button",{type:"button",onClick:()=>f(""),className:`w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700 ${a?"text-gray-700 dark:text-gray-200":"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-white"}`,children:r}),n.map(d=>t.jsx("button",{type:"button",onClick:()=>f(d.value),className:`w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700 ${a===d.value?"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-white":"text-gray-700 dark:text-gray-200"}`,children:d.label},d.value))]})]}):null},Ge={enabled:!1,useServerSideSorting:!1,options:[],fields:[],defaultValue:"",autoGenerate:!0,clearLabel:"",onChange:null},Cr=n=>n===!0?{...Ge,enabled:!0}:!n||typeof n!="object"?Ge:{...Ge,...n,enabled:n.enabled??!0,autoGenerate:n.autoGenerate??!0},Dr=(n=[])=>n.filter(a=>{const e=["menu_actions","index","audio","avatar"];return a.type&&e.includes(a.type)?!1:!!(a.sortKey||(a.type==="group"?a.titleKey:a.key))}),Er=n=>{if(n.sortType)return n.sortType;if(n.type==="date")return"date";if(n.type==="number")return"number";const a=String(n.sortKey||(n.type==="group"?n.titleKey:n.key)||"").toLowerCase();return["phone","mobile","contact","tel","whatsapp"].some(r=>a.includes(r))?"phone":Array.isArray(n.chipOptions)&&n.chipOptions.length>0&&n.chipOptions.every(o=>typeof o.value=="boolean")?"boolean":"string"},ft=(n=[])=>n.flatMap(a=>{const e=a.sortKey||(a.type==="group"?a.titleKey:a.key),r=a.sortLabel||a.title||e,o=Er(a);return e?o==="number"?[{value:`${e}_asc`,label:`${r} (Low-High)`,key:e,order:"asc",type:o},{value:`${e}_desc`,label:`${r} (High-Low)`,key:e,order:"desc",type:o}]:o==="phone"?[{value:`${e}_asc`,label:`${r} (0-9)`,key:e,order:"asc",type:o},{value:`${e}_desc`,label:`${r} (9-0)`,key:e,order:"desc",type:o}]:o==="date"?[{value:`${e}_desc`,label:`${r} (Newest First)`,key:e,order:"desc",type:o},{value:`${e}_asc`,label:`${r} (Oldest First)`,key:e,order:"asc",type:o}]:o==="boolean"?[{value:`${e}_desc`,label:`${r} (True First)`,key:e,order:"desc",type:o},{value:`${e}_asc`,label:`${r} (False First)`,key:e,order:"asc",type:o}]:[{value:`${e}_asc`,label:`${r} (A-Z)`,key:e,order:"asc",type:o},{value:`${e}_desc`,label:`${r} (Z-A)`,key:e,order:"desc",type:o}]:[]}),_r=(n,a=[])=>{if(Array.isArray(n.options)&&n.options.length>0)return n.options.map(o=>({...o,type:o.type||"string",order:o.order==="desc"?"desc":"asc"}));const r=Array.isArray(n.fields)?n.fields:[];if(r.length>0){const o=r.map(i=>{const s=typeof i=="string"?i:i.key,c=a.find(f=>f.key===s||f.sortKey===s||f.type==="group"&&f.titleKey===s);return c?{...c,sortKey:typeof i=="object"&&i.key?i.key:c.sortKey,sortType:typeof i=="object"&&i.type?i.type:c.sortType,sortLabel:typeof i=="object"&&i.label?i.label:c.sortLabel}:null}).filter(i=>i!==null);return ft(o)}return n.autoGenerate?ft(a):[]},Pr=(n=[],a="",e,r=[])=>{if(!(e!=null&&e.enabled)||!a||e!=null&&e.useServerSideSorting)return n;const o=r==null?void 0:r.find(d=>d.value===a);if(!(o!=null&&o.key))return n;const i=o.order==="desc"?"desc":"asc",s=o.key,c=o.type||"string",f=d=>String(d??"").replace(/[^\d]/g,"").trim();return[...n].sort((d,p)=>{const h=d==null?void 0:d[s],l=p==null?void 0:p[s];if(h==null&&l==null)return 0;if(h==null)return i==="asc"?1:-1;if(l==null)return i==="asc"?-1:1;let m=0;return c==="number"?m=Number(h)-Number(l):c==="phone"?m=f(h).localeCompare(f(l),void 0,{numeric:!0}):c==="date"?m=new Date(h).getTime()-new Date(l).getTime():c==="boolean"?m=+!!h-+!!l:m=String(h).localeCompare(String(l)),i==="asc"?m:-m})},Ar=({config:n,setShowAdd:a,title:e,buttonText:r,description:o,showAddButton:i})=>{const{data:s=[],table_head:c=[],loading:f=!1,search:d={enabled:!1,placeholder:"Search...",useServerSideSearch:!1},filter:p={enabled:!1,useServerSideFilters:!1},sort:h={enabled:!1},pagination:l={enabled:!1,rows_per_page:10,useServerSidePagination:!1},emptyMessage:m="No data available",onMenuAction:g,setServerSidePaginationData:j=()=>{},onFilterApply:v,filterConfig:R=null,rowClick:A=null}=n,[L,C]=b.useState(""),[I,E]=b.useState(null),[x,w]=b.useState([]),[S,D]=b.useState({top:0,left:0}),[P,Y]=b.useState(!1),[ee,K]=b.useState({}),N=b.useMemo(()=>Cr(h),[h]),X=b.useMemo(()=>Dr(c),[c]),B=b.useMemo(()=>_r(N,X),[N,X]),[M,k]=b.useState((N==null?void 0:N.defaultValue)||""),[z,H]=b.useState(null),[F,te]=b.useState(!1),pe=b.useMemo(()=>!d.enabled||!L.trim()||d.useServerSideSearch?s:Ot(s,L,d.searchKeys||[]),[s,L,d]),ne=b.useMemo(()=>Pr(pe,M,N,B),[pe,M,N,B]),[V,re]=b.useState(1),[J,xe]=b.useState((l==null?void 0:l.rows_per_page)||50),[ye,Se]=b.useState(pe.length||0),fe=l!=null&&l.useServerSidePagination?l.total_pages:Math.ceil(pe.length/J),ve=b.useMemo(()=>{if(l.useServerSidePagination)return ne;const u=(V-1)*J;return ne.slice(u,u+J)},[ne,V,J,l.useServerSidePagination]),be=b.useRef(null),we=b.useRef({}),ge=b.useRef(null),Ne=u=>{C(u),re(1),d.useServerSideSearch&&(ge.current&&clearTimeout(ge.current),ge.current=setTimeout(async()=>{try{await j(y=>({...y,search:u,current_page:1}))}catch(y){console.error("Search error:",y)}},800))},Me=(u,y=null)=>{k(u),re(1);const T={value:u,option:y,key:(y==null?void 0:y.key)||"",order:(y==null?void 0:y.order)||"",type:(y==null?void 0:y.type)||""};typeof(N==null?void 0:N.onChange)=="function"&&N.onChange(T)},Re=(u,y,T)=>{T.stopPropagation(),E(null),g==null||g(u.type,y)},Ce=(u,y,T)=>{y.stopPropagation(),w(T);const $=y.currentTarget;we.current[u]=$;const Z=$.getBoundingClientRect(),se=192,de=T.length*40,Fe=window.innerWidth,et=window.innerHeight,At=Fe-Z.right<se?Z.left-se+Z.width:Z.left,Lt=et-Z.bottom<de&&Z.top>de?Z.top-de-2:Z.bottom+2;D({top:Math.max(8,Math.min(Lt,et-de-8)),left:Math.max(8,Math.min(At,Fe-se-8))}),E(I===u?null:u)},De=u=>(V-1)*J+u+1,Ee=u=>{let y=u;y&&y.src instanceof File&&(y={...y,src:URL.createObjectURL(y.src)}),H(y),te(!0)},je=(u,y,T,$=null,Z=null)=>t.jsx(t.Fragment,{children:u?t.jsx("img",{src:u instanceof File?URL.createObjectURL(u):u,alt:y||"Avatar",onClick:se=>{se.stopPropagation(),se.preventDefault(),Ee({src:u,alt:y})},className:`w-10 h-10 cursor-pointer shrink-0 rounded-full object-cover border border-gray-200 dark:border-gray-700 ${T||""}`}):t.jsx(t.Fragment,{children:$?typeof $=="function"?$(Z):$:t.jsx("div",{className:`w-10 h-10 flex items-center shrink-0 justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-gray-200 dark:bg-gray-600 ${T||""}`,children:t.jsx(U.User,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),_e=(u,y)=>t.jsx(t.Fragment,{children:u?t.jsx("audio",{controls:!0,src:u instanceof File?URL.createObjectURL(u):u,onClick:T=>{T.stopPropagation()},className:`w-64 cursor-pointer ${y||""}`},u instanceof File?URL.createObjectURL(u):u):t.jsx(t.Fragment,{children:t.jsx("div",{className:`w-12 h-12 flex items-center shrink-0 justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-gray-200 dark:bg-gray-600 ${y||""}`,children:t.jsx(U.Music,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),Pe=(u,y)=>t.jsxs("div",{className:`flex items-center space-x-4 ${y.className||""}`,children:[y.imageKey?je(u[y.imageKey],u[y.titleKey],"group-avatar",y.fallback_icon,u):"",t.jsxs("div",{children:[t.jsx("p",{className:"font-medium text-gray-900 dark:text-white group-title",children:u[y.titleKey]||""}),t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 group-sub-title",children:u[y.subtitleKey]||""})]})]}),Ae=(u,y)=>{var se;let T=String(u);const $=y.variant||"contained";let Z=y.defaultColor;if(((se=y==null?void 0:y.chipOptions)==null?void 0:se.length)>0){const de=y==null?void 0:y.chipOptions.find(Fe=>Fe.value==u);de&&(T=de.label,Z=de.color)}return t.jsx(Et,{label:T,variant:$,color:Z,className:y.className||""})},Le=(u,y,T)=>{const $=y[u.key];return u.type==="menu_actions"?t.jsx("div",{className:`text-center ${u.className||""}`,children:t.jsx("button",{ref:Z=>{we.current[y.id||y._id]=Z},onClick:Z=>Ce(y.id||y._id,Z,u.menuList),className:"p-2 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-full transition text-gray-700 dark:text-gray-300",children:t.jsx(U.EllipsisVertical,{className:"h-4 w-4"})})}):u.type==="index"?t.jsx("span",{className:u.className||"",children:De(T)}):u.type==="group"?Pe(y,u):u.type==="chip"?t.jsx(t.Fragment,{children:Ae($,u)}):u.type==="date"?t.jsx("span",{className:u.className||"",children:gt($,u.format||"DD MMM YYYY")}):u.type==="avatar"?t.jsx(t.Fragment,{children:t.jsx("div",{className:"min-w-[40px]",children:je($,u.alt,u.className,u.fallback_icon,y)})}):u.type==="audio"?t.jsx(t.Fragment,{children:_e($,u.className)}):t.jsx("span",{className:u.className||"",children:$||"N/A"})},_=u=>{if(typeof A=="function")return A(u);if(A)return g==null?void 0:g("view",u)},O=(u,y)=>{if(u.onClickDetails)return g==null?void 0:g("view",y);if(typeof u.handleClick=="function")return u.handleClick(y)},G=()=>A||typeof A=="function",oe=u=>u.onClickDetails||typeof u.handleClick=="function";return b.useEffect(()=>{const u=()=>{I&&E(null)};return window.addEventListener("scroll",u,!0),()=>{window.removeEventListener("scroll",u,!0)}},[I]),b.useEffect(()=>{const u=y=>{be.current&&!be.current.contains(y.target)&&E(null)};return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[]),b.useEffect(()=>{l!=null&&l.rows_per_page&&(l!=null&&l.useServerSidePagination)&&xe((l==null?void 0:l.rows_per_page)||50),l.current_page&&re(l.current_page)},[l.rows_per_page,l==null?void 0:l.useServerSidePagination,l.current_page]),b.useEffect(()=>{Se(l!=null&&l.useServerSidePagination?l.total_records:ne.length),ne.length<=J*(V-1)&&!(l!=null&&l.useServerSidePagination)&&re(u=>u-1||1)},[ne.length,l.total_records,l==null?void 0:l.useServerSidePagination]),b.useEffect(()=>{if(!(N!=null&&N.enabled)){k("");return}if(B.some(y=>y.value===N.defaultValue)){k(N.defaultValue);return}k("")},[N,B]),b.useEffect(()=>{if(!(N!=null&&N.enabled)||!(N!=null&&N.useServerSideSorting))return;const u=B==null?void 0:B.find(y=>y.value===M);j(y=>({...y,current_page:1,sort_by:(u==null?void 0:u.key)||"",sort_order:(u==null?void 0:u.order)||""}))},[M,N==null?void 0:N.enabled,N==null?void 0:N.useServerSideSorting,B,j]),t.jsxs(t.Fragment,{children:[f?t.jsx(Mr,{rows:6,columns:6}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col lg:!flex-row lg:!justify-between gap-4 mb-3",children:[t.jsxs("div",{className:"table-heading",children:[t.jsx("h1",{children:e}),t.jsx("p",{children:o})]}),t.jsxs("div",{className:"flex flex-col justify-end items-stretch lg:!items-end gap-2 w-full lg:!w-auto",children:[i&&t.jsxs(ae,{onClick:()=>a(!0),variant:"contained",color:"primary",children:[t.jsx(U.Plus,{className:"w-4 h-4 mr-2"}),r||"Add New"]}),t.jsxs("div",{className:"flex flex-col sm:!flex-row sm:!flex-wrap justify-end items-stretch sm:!items-center gap-2 w-full",children:[d.enabled&&t.jsx("div",{className:"w-full sm:!w-auto",children:t.jsxs("div",{className:"table-search-field",children:[t.jsx(U.Search,{className:"search-icon"}),t.jsx("input",{type:"text",placeholder:d.placeholder||"Search...",value:L,onChange:u=>Ne(u.target.value)})]})}),N!=null&&N.enabled&&(B==null?void 0:B.length)>0||R&&p.enabled?t.jsxs("div",{className:"flex items-center justify-end gap-2 w-full sm:!w-auto",children:[R&&p.enabled&&t.jsxs("div",{className:"filter-button-wrapper",children:[t.jsxs(ae,{onClick:()=>Y(!0),variant:"contained",className:"w-full sm:!w-auto",children:[t.jsx(U.Filter,{className:"w-4 h-4 mr-2"}),"Filters"]}),Object.keys(ee).length>0&&t.jsx("span",{className:"red-dot"})]}),(N==null?void 0:N.enabled)&&(B==null?void 0:B.length)>0&&t.jsx(Rr,{options:B,value:M,onChange:Me,clearLabel:N==null?void 0:N.clearLabel})]}):null]})]})]}),t.jsxs("div",{className:"table-container",children:[t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{children:[t.jsx("thead",{children:t.jsx("tr",{children:c.map(u=>t.jsx("th",{className:`table-head-data ${u.headClass||""}`,children:u.title},u.key))})}),t.jsx("tbody",{children:ve.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:c.length,className:"no-data-message",children:m})}):ve.map((u,y)=>t.jsx("tr",{className:`table-row ${G()?"cursor-pointer":""}`,onClick:()=>{G()&&_(u)},children:c.map(T=>t.jsx("td",{className:`table-data ${T.type=="audio"?"":"max-w-[300px]"} truncate ${oe(T)?"cursor-pointer":""}`,title:String(u[T.key]??""),onClick:$=>{oe(T)&&($.stopPropagation(),$.preventDefault(),O(T,u))},children:T.render?T.render(u,y):Le(T,u,y)},T.key))},u.id||u._id||y))})]})}),(l==null?void 0:l.enabled)&&ne.length>0&&t.jsxs("div",{className:"pagination-wrapper",children:[t.jsxs("span",{children:["Showing ",(V-1)*J+1," to"," ",Math.min(V*J,ye)," of"," ",ye," results"]}),t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{children:"Rows per page:"}),t.jsx("select",{value:J,onChange:u=>{const y=Number(u.target.value);xe(y),re(1),l.useServerSidePagination&&j(T=>({...T,current_page:1,rows_per_page:y}))},className:"rows-number-select",children:[10,25,50,100].map(u=>t.jsx("option",{value:u,children:u},u))})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>{if(V>1){const u=V-1;re(u),l.useServerSidePagination&&j(y=>({...y,current_page:u}))}},disabled:V===1,className:"arrow-icons",children:t.jsx(U.ChevronLeft,{className:"h-4 w-4"})}),t.jsxs("span",{children:["Page ",V," of ",fe]}),t.jsx("button",{onClick:()=>{if(V<fe){const u=V+1;re(u),l.useServerSidePagination&&j(y=>({...y,current_page:u}))}},disabled:V===fe,className:"arrow-icons",children:t.jsx(U.ChevronRight,{className:"h-4 w-4"})})]})]})]})]})]}),I&&Ft.createPortal(t.jsx("div",{ref:be,style:{position:"fixed",top:`${S.top}px`,left:`${S.left}px`,zIndex:9999},className:"w-48 bg-white dark:bg-gray-700 rounded-md shadow-lg border border-gray-200 dark:border-gray-600",children:x.map((u,y)=>t.jsxs("button",{onClick:T=>Re(u,s.find($=>$.id===I||$._id==I),T),className:`w-full flex items-center gap-2 px-4 py-2 text-sm text-left hover:bg-gray-100 dark:hover:bg-gray-600 ${u.variant==="danger"?"text-red-600 dark:text-red-500":"text-gray-700 dark:text-gray-200"}`,children:[u.icon&&t.jsx("span",{className:"shrink-0",children:u.icon}),u.title]},y))}),document.body),R&&t.jsx(Nr,{isOpen:P,onClose:()=>Y(!1),config:R,onApply:u=>{K(u),v==null||v(u)}}),F&&z&&t.jsx(Qe,{src:z.src,alt:z.alt,isOpen:F,setIsOpen:te})]})},Oe=({isOpen:n,onClose:a,icon:e,title:r,children:o,size:i="md",actionButtons:s=[],onFormSubmit:c=()=>{},loadingBtn:f=!1,executeFunction:d=()=>{},selectedItem:p=null})=>{if(!n)return null;const h={sm:"max-w-md",md:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-full"};return t.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[t.jsx("div",{className:"fixed inset-0 bg-gray-500 opacity-75",onClick:()=>a()}),t.jsxs("div",{className:`relative bg-white rounded-lg shadow-xl w-full ${h[i]||h.md} max-h-[90vh] flex flex-col dark:bg-gray-800`,children:[t.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[e&&t.jsx("span",{children:e}),t.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:r})]}),t.jsx("button",{onClick:()=>a(),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:t.jsx(U.X,{className:"w-6 h-6"})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:o}),s.length>0&&t.jsx("div",{className:"px-4 py-3 flex justify-end gap-3 border-t border-gray-200 dark:border-gray-700 sm:!px-6",children:s.map((l,m)=>t.jsx(ae,{onClick:g=>{l.type=="submit"?c(g):d(()=>{var j;return Promise.resolve((j=l==null?void 0:l.onClick)==null?void 0:j.call(l,g,p))},j=>a==null?void 0:a(j))},disabled:f||l.disabled,variant:l.variant||"contained",color:l.color||"primary",className:`min-w-[100px] ${l.className||""}`,type:l.type||"button",children:f?t.jsxs("div",{className:"flex items-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-2 border-t-white mr-2"}),l.label||"Submit","..."]}):l.label||"Submit"},`${l.label||"action"}-${m}`))})]})]})},bt=({config:n,onSubmit:a,initialData:e,fetchRowDetails:r,type:o})=>{const i=e||{},{formClass:s="grid grid-cols-12 gap-4",formFields:c=[]}=n||{},[f,d]=b.useState(i),[p,h]=b.useState(!0),l=async()=>{r==null||r(i).then(j=>{d(j.data)}).catch(j=>{le.enqueueSnackbar(j.message,{variant:"error"})}).finally(()=>{h(!1)})};b.useEffect(()=>{r instanceof Function?l():(d(i),h(!1))},[]);const m=(j,v)=>{d(R=>({...R,[j]:v}))},g=j=>{j.preventDefault();const v=j.currentTarget;if(!v.checkValidity()){v.reportValidity();return}a(f)};return p?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsx("div",{className:"rounded-full border-4 border-blue-500 border-t-gray-200 animate-spin w-8 h-8",style:{borderTopColor:"border-primary-500"}})}):t.jsx("form",{id:o==="add"?"addForm":o==="edit"?"editForm":"defaultForm",onSubmit:g,className:s,noValidate:!1,children:c.map(j=>t.jsx(Pt,{field:j,formData:f,handleChange:m},j.key))})};function Lr({data:n,config:a,fetchRowDetails:e}){const{fields:r=[],containerClass:o}=a||{},i=n||{},[s,c]=b.useState(i),[f,d]=b.useState(!0),p=async()=>{e==null||e(i).then(h=>{c(h.data)}).catch(h=>{le.enqueueSnackbar(h.message,{variant:"error"})}).finally(()=>{d(!1)})};return b.useEffect(()=>{e instanceof Function?p():(c(i),d(!1))},[]),f?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsx("div",{className:"rounded-full border-4 border-blue-500 border-t-gray-200 animate-spin w-8 h-8",style:{borderTopColor:"border-primary-500"}})}):t.jsx(t.Fragment,{children:t.jsx("div",{className:`grid grid-cols-12 gap-4 ${o||""}`,children:r.map(h=>h.renderCondition&&typeof h.renderCondition=="function"&&!h.renderCondition(s)?null:h.type=="group"?t.jsx(Ct,{col:h,data:s},h.key||h.titleKey):h.type=="cardGroup"?t.jsx(Dt,{col:h,data:s},h.key||h.titleKey):t.jsx(_t,{col:h,data:s},h.key||h.label))})})}const Fr=({config:n})=>{var J,xe,ye,Se,fe,ve,be,we,ge,Ne,Me,Re,Ce,De,Ee,je,_e,Pe,Ae,Le;const{title:a,fetchData:e,fetchRowDetails:r,isStaticData:o=!1,tableConfig:i,modalConfig:s,filterConfig:c}=n,[f,d]=b.useState(!0),[p,h]=b.useState(!1),[l,m]=b.useState([]),[g,j]=b.useState(null),[v,R]=b.useState({search:"",rows_per_page:50,current_page:1,sort_by:"",sort_order:""}),[A,L]=b.useState({}),[C,I]=b.useState(!1),[E,x]=b.useState(!1),[w,S]=b.useState(!1),[D,P]=b.useState(!1),[Y,ee]=b.useState(!1),[K,N]=b.useState(null),X=(_,O)=>{_==="edit"?(N(O),S(!0)):_==="view"?(N(O),ee(!0)):_==="delete"&&(N(O),P(!0))},B=async(_,O,G="",oe="")=>{h(!0);try{if(!_)return;const u=await _();(G||u!=null&&u.message)&&le.enqueueSnackbar(G||u.message||"Success",{variant:"success"}),O==null||O(u)}catch(u){(oe||u!=null&&u.message)&&le.enqueueSnackbar(oe||u.message||"Error occurred",{variant:"error"})}finally{h(!1)}},M=_=>{const O=_.newObject;o?(m(G=>[O,...G]),j(G=>({...G,current_page:1}))):(R(G=>({...G,current_page:1})),v.current_page===1&&te()),x(!1)},k=_=>{const{newObject:O,targetObject:G}=_;o?m(oe=>oe.map(u=>u.id===G.id?{...u,...O}:u)):te(),S(!1)},z=_=>{if(!_){P(!1),N(null);return}o?m(O=>O.filter(G=>G.id!==_.targetObject.id)):l.length===1&&v.current_page>1?R(O=>({...O,current_page:O.current_page-1})):te(),P(!1),N(null)},H=_=>B(()=>{var O;return(O=s==null?void 0:s.addModal)!=null&&O.handleSubmit?s.addModal.handleSubmit(_):Promise.resolve({newObject:null})},M),F=_=>B(()=>{var O;return(O=s==null?void 0:s.editModal)!=null&&O.handleSubmit?s.editModal.handleSubmit(_,K):Promise.resolve({newObject:null,targetObject:null})},k),te=async()=>{d(!0);try{const _=await e({...v,...A});m(_.data||[]),j(_.pagination||null)}catch(_){le.enqueueSnackbar(_.message||"Failed to fetch data",{variant:"error"})}finally{d(!1)}},pe=_=>{var O;L(G=>({..._})),(O=i==null?void 0:i.filter)!=null&&O.useServerSideFilters&&I(G=>!G)},ne=(_,O)=>_.filter(G=>Object.entries(O).every(([oe,u])=>G[oe]===u)),V=b.useMemo(()=>{var _;return(_=i==null?void 0:i.filter)!=null&&_.useServerSideFilters?l:ne(l,A)},[l,A,(J=i==null?void 0:i.filter)==null?void 0:J.useServerSideFilters]),re=(xe=s==null?void 0:s.viewModal)==null?void 0:xe.component;return b.useEffect(()=>{te()},[v.search,v.rows_per_page,v.current_page,v.sort_by,v.sort_order,C]),t.jsxs("div",{children:[t.jsx(Ar,{title:a,setShowAdd:x,description:n.description,buttonText:n.buttonText,showAddButton:!!(s!=null&&s.addModal),config:{...i,pagination:{...i.pagination,...g},data:V,setServerSidePaginationData:R,onMenuAction:X,filterConfig:c,onFilterApply:pe,loading:f}}),t.jsx(Oe,{isOpen:E,onClose:()=>{p||x(!1)},icon:(ye=s==null?void 0:s.addModal)==null?void 0:ye.icon,title:((Se=s==null?void 0:s.addModal)==null?void 0:Se.title)||"Add New",size:((fe=s==null?void 0:s.addModal)==null?void 0:fe.size)||"md",onFormSubmit:()=>{var _;return(_=document.querySelector("#addForm"))==null?void 0:_.requestSubmit()},loadingBtn:p,actionButtons:((ve=s==null?void 0:s.addModal)==null?void 0:ve.actionButtons)||[],children:t.jsx(bt,{config:(s==null?void 0:s.addModal)||{},onSubmit:H,initialData:{},type:"add",loading:p})}),t.jsx(Oe,{isOpen:w,onClose:()=>{p||S(!1)},icon:(be=s==null?void 0:s.editModal)==null?void 0:be.icon,title:((we=s==null?void 0:s.editModal)==null?void 0:we.title)||"Edit",size:((ge=s==null?void 0:s.editModal)==null?void 0:ge.size)||"md",onFormSubmit:()=>{var _;return(_=document.querySelector("#editForm"))==null?void 0:_.requestSubmit()},actionButtons:((Ne=s==null?void 0:s.editModal)==null?void 0:Ne.actionButtons)||[],loadingBtn:p,children:t.jsx(bt,{config:(s==null?void 0:s.editModal)||{},onSubmit:F,initialData:K,type:"edit",loading:p,fetchRowDetails:r})}),D&&t.jsx(Oe,{isOpen:D,onClose:_=>{z(_)},icon:((Me=s==null?void 0:s.deleteModal)==null?void 0:Me.icon)||t.jsx(ce.Icon,{icon:"ph:warning-bold",className:"w-6 h-6 text-red-500"}),title:((Re=s==null?void 0:s.deleteModal)==null?void 0:Re.title)||"Confirm Delete",size:((Ce=s==null?void 0:s.deleteModal)==null?void 0:Ce.size)||"md",loading:p,actionButtons:((De=s==null?void 0:s.deleteModal)==null?void 0:De.actionButtons)||[],executeFunction:B,selectedItem:K,children:t.jsx("div",{className:"flex items-center space-x-2 py-3",children:t.jsxs("div",{children:[t.jsx("p",{className:"text-md text-gray-700 dark:text-white",children:((Ee=s==null?void 0:s.deleteModal)==null?void 0:Ee.confirmText)||"Are you sure you want to delete this item?"}),((je=s==null?void 0:s.deleteModal)==null?void 0:je.referenceKey)&&t.jsx("p",{className:"text-md font-semibold text-gray-700 dark:text-white",children:K==null?void 0:K[(_e=s==null?void 0:s.deleteModal)==null?void 0:_e.referenceKey]})]})})}),(s==null?void 0:s.viewModal)&&t.jsx(Oe,{isOpen:Y,onClose:()=>{ee(!1),N(null)},icon:(Pe=s==null?void 0:s.viewModal)==null?void 0:Pe.icon,title:((Ae=s==null?void 0:s.viewModal)==null?void 0:Ae.title)||"View Details",size:((Le=s==null?void 0:s.viewModal)==null?void 0:Le.size)||"lg",footerConfig:s==null?void 0:s.viewModal.footer,children:re?t.jsx(re,{data:K}):t.jsx(Lr,{data:K,fetchRowDetails:r,config:(s==null?void 0:s.viewModal)||{}})})]})};function Ir({children:n}){return le.useSnackbar(),n}function Tr({children:n}){try{return t.jsx(Ir,{children:n})}catch{return t.jsx(le.SnackbarProvider,{anchorOrigin:{vertical:"bottom",horizontal:"right"},action:e=>t.jsx("button",{onClick:()=>{window.dispatchEvent(new CustomEvent("closeSnackbar",{detail:e}))},className:"p-1 hover:bg-white/20 rounded-full transition-colors duration-200 text-white flex items-center justify-center",children:t.jsx(U.X,{className:"h-4 w-4"})}),maxSnack:3,autoHideDuration:3e3,children:n})}}const Or=()=>{if(typeof document>"u"||document.getElementById("react-admin-crud-manager-styles"))return;const n=document.createElement("style");n.id="react-admin-crud-manager-styles",n.textContent=`
|
|
149
|
+
`,children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Filters"}),t.jsx("button",{onClick:a,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md transition",children:t.jsx(U.X,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),n&&t.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:d?t.jsx(d,{filters:o,onFilterChange:s}):t.jsx("div",{className:"space-y-4",children:(p=e==null?void 0:e.fields)==null?void 0:p.map(h=>t.jsx(Pt,{field:h,formData:o,handleChange:s},h.key))})}),t.jsxs("div",{className:"flex gap-2 px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:[t.jsx(ae,{onClick:c,variant:"contained",color:"primary",fullWidth:!0,children:"Apply Filters"}),t.jsx(ae,{onClick:f,variant:"contained",className:"min-w-[150px]",children:"Reset"})]})]})]})},Mr=({rows:n=5,columns:a=5})=>t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w-full mb-6 inline-flex justify-end items-center",children:t.jsx("div",{className:"h-8 w-80 bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})}),t.jsx("div",{className:"overflow-hidden rounded-md border border-gray-200 dark:border-gray-800",children:t.jsxs("table",{className:"w-full border-collapse",children:[t.jsx("thead",{children:t.jsx("tr",{className:"bg-gray-50 dark:bg-gray-900",children:Array.from({length:a}).map((e,r)=>t.jsx("th",{className:"px-4 py-3",children:t.jsx("div",{className:"h-6 w-24 bg-gray-300 dark:bg-gray-700 rounded animate-pulse inline-flex justify-center items-center"})},r))})}),t.jsx("tbody",{children:Array.from({length:n}).map((e,r)=>t.jsx("tr",{className:"border-t border-gray-200 dark:border-gray-800",children:Array.from({length:a}).map((o,i)=>t.jsx("td",{className:"px-4 py-6",children:t.jsx("div",{className:"h-6 w-full bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})},i))},r))})]})})]}),Rr=({options:n=[],value:a="",onChange:e,clearLabel:r=""})=>{const[o,i]=b.useState(!1),s=b.useRef(null),c=!!a;b.useEffect(()=>{const d=p=>{s.current&&!s.current.contains(p.target)&&i(!1)};return document.addEventListener("click",d),()=>document.removeEventListener("click",d)},[]);const f=d=>{const p=n.find(h=>h.value===d);e(d,p||null),i(!1)};return n!=null&&n.length?t.jsxs("div",{className:"relative",ref:s,children:[t.jsxs("button",{type:"button",onClick:()=>i(d=>!d),className:"relative inline-flex items-center justify-center h-[36px] w-[36px] rounded-md border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-700 text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-600 transition","aria-label":"Open sort options",children:[t.jsx(U.ArrowUpDown,{className:"w-4 h-4"}),c&&t.jsx("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]}),o&&t.jsxs("div",{className:"absolute right-0 mt-2 z-20 min-w-[220px] max-h-[260px] overflow-auto rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-lg",children:[!!(r!=null&&r.trim())&&t.jsx("button",{type:"button",onClick:()=>f(""),className:`w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700 ${a?"text-gray-700 dark:text-gray-200":"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-white"}`,children:r}),n.map(d=>t.jsx("button",{type:"button",onClick:()=>f(d.value),className:`w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700 ${a===d.value?"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-white":"text-gray-700 dark:text-gray-200"}`,children:d.label},d.value))]})]}):null},Ge={enabled:!1,useServerSideSorting:!1,options:[],fields:[],defaultValue:"",autoGenerate:!0,clearLabel:"",onChange:null},Cr=n=>n===!0?{...Ge,enabled:!0}:!n||typeof n!="object"?Ge:{...Ge,...n,enabled:n.enabled??!0,autoGenerate:n.autoGenerate??!0},Dr=(n=[])=>n.filter(a=>{const e=["menu_actions","index","audio","avatar"];return a.type&&e.includes(a.type)?!1:!!(a.sortKey||(a.type==="group"?a.titleKey:a.key))}),Er=n=>{if(n.sortType)return n.sortType;if(n.type==="date")return"date";if(n.type==="number")return"number";const a=String(n.sortKey||(n.type==="group"?n.titleKey:n.key)||"").toLowerCase();return["phone","mobile","contact","tel","whatsapp"].some(r=>a.includes(r))?"phone":Array.isArray(n.chipOptions)&&n.chipOptions.length>0&&n.chipOptions.every(o=>typeof o.value=="boolean")?"boolean":"string"},ft=(n=[])=>n.flatMap(a=>{const e=a.sortKey||(a.type==="group"?a.titleKey:a.key),r=a.sortLabel||a.title||e,o=Er(a);return e?o==="number"?[{value:`${e}_asc`,label:`${r} (Low-High)`,key:e,order:"asc",type:o},{value:`${e}_desc`,label:`${r} (High-Low)`,key:e,order:"desc",type:o}]:o==="phone"?[{value:`${e}_asc`,label:`${r} (0-9)`,key:e,order:"asc",type:o},{value:`${e}_desc`,label:`${r} (9-0)`,key:e,order:"desc",type:o}]:o==="date"?[{value:`${e}_desc`,label:`${r} (Newest First)`,key:e,order:"desc",type:o},{value:`${e}_asc`,label:`${r} (Oldest First)`,key:e,order:"asc",type:o}]:o==="boolean"?[{value:`${e}_desc`,label:`${r} (True First)`,key:e,order:"desc",type:o},{value:`${e}_asc`,label:`${r} (False First)`,key:e,order:"asc",type:o}]:[{value:`${e}_asc`,label:`${r} (A-Z)`,key:e,order:"asc",type:o},{value:`${e}_desc`,label:`${r} (Z-A)`,key:e,order:"desc",type:o}]:[]}),_r=(n,a=[])=>{if(Array.isArray(n.options)&&n.options.length>0)return n.options.map(o=>({...o,type:o.type||"string",order:o.order==="desc"?"desc":"asc"}));const r=Array.isArray(n.fields)?n.fields:[];if(r.length>0){const o=r.map(i=>{const s=typeof i=="string"?i:i.key,c=a.find(f=>f.key===s||f.sortKey===s||f.type==="group"&&f.titleKey===s);return c?{...c,sortKey:typeof i=="object"&&i.key?i.key:c.sortKey,sortType:typeof i=="object"&&i.type?i.type:c.sortType,sortLabel:typeof i=="object"&&i.label?i.label:c.sortLabel}:null}).filter(i=>i!==null);return ft(o)}return n.autoGenerate?ft(a):[]},Pr=(n=[],a="",e,r=[])=>{if(!(e!=null&&e.enabled)||!a||e!=null&&e.useServerSideSorting)return n;const o=r==null?void 0:r.find(d=>d.value===a);if(!(o!=null&&o.key))return n;const i=o.order==="desc"?"desc":"asc",s=o.key,c=o.type||"string",f=d=>String(d??"").replace(/[^\d]/g,"").trim();return[...n].sort((d,p)=>{const h=d==null?void 0:d[s],l=p==null?void 0:p[s];if(h==null&&l==null)return 0;if(h==null)return i==="asc"?1:-1;if(l==null)return i==="asc"?-1:1;let m=0;return c==="number"?m=Number(h)-Number(l):c==="phone"?m=f(h).localeCompare(f(l),void 0,{numeric:!0}):c==="date"?m=new Date(h).getTime()-new Date(l).getTime():c==="boolean"?m=+!!h-+!!l:m=String(h).localeCompare(String(l)),i==="asc"?m:-m})},Ar=({config:n,setShowAdd:a,title:e,buttonText:r,description:o,showAddButton:i})=>{const{data:s=[],table_head:c=[],loading:f=!1,search:d={enabled:!1,placeholder:"Search...",useServerSideSearch:!1},filter:p={enabled:!1,useServerSideFilters:!1},sort:h={enabled:!1},pagination:l={enabled:!1,rows_per_page:10,useServerSidePagination:!1},emptyMessage:m="No data available",onMenuAction:g,setServerSidePaginationData:j=()=>{},onFilterApply:v,filterConfig:R=null,rowClick:A=null}=n,[L,C]=b.useState(""),[I,E]=b.useState(null),[x,w]=b.useState([]),[S,D]=b.useState({top:0,left:0}),[P,Y]=b.useState(!1),[ee,G]=b.useState({}),N=b.useMemo(()=>Cr(h),[h]),X=b.useMemo(()=>Dr(c),[c]),B=b.useMemo(()=>_r(N,X),[N,X]),[M,k]=b.useState((N==null?void 0:N.defaultValue)||""),[z,H]=b.useState(null),[F,te]=b.useState(!1),pe=b.useMemo(()=>!d.enabled||!L.trim()||d.useServerSideSearch?s:Ot(s,L,d.searchKeys||[]),[s,L,d]),ne=b.useMemo(()=>Pr(pe,M,N,B),[pe,M,N,B]),[V,re]=b.useState(1),[J,xe]=b.useState((l==null?void 0:l.rows_per_page)||50),[ye,Se]=b.useState(pe.length||0),fe=l!=null&&l.useServerSidePagination?l.total_pages:Math.ceil(pe.length/J),ve=b.useMemo(()=>{if(l.useServerSidePagination)return ne;const u=(V-1)*J;return ne.slice(u,u+J)},[ne,V,J,l.useServerSidePagination]),be=b.useRef(null),we=b.useRef({}),ge=b.useRef(null),Ne=u=>{C(u),re(1),d.useServerSideSearch&&(ge.current&&clearTimeout(ge.current),ge.current=setTimeout(async()=>{try{await j(y=>({...y,search:u,current_page:1}))}catch(y){console.error("Search error:",y)}},800))},Me=(u,y=null)=>{k(u),re(1);const T={value:u,option:y,key:(y==null?void 0:y.key)||"",order:(y==null?void 0:y.order)||"",type:(y==null?void 0:y.type)||""};typeof(N==null?void 0:N.onChange)=="function"&&N.onChange(T)},Re=(u,y,T)=>{T.stopPropagation(),E(null),g==null||g(u.type,y)},Ce=(u,y,T)=>{y.stopPropagation(),w(T);const $=y.currentTarget;we.current[u]=$;const Z=$.getBoundingClientRect(),se=192,de=T.length*40,Fe=window.innerWidth,et=window.innerHeight,At=Fe-Z.right<se?Z.left-se+Z.width:Z.left,Lt=et-Z.bottom<de&&Z.top>de?Z.top-de-2:Z.bottom+2;D({top:Math.max(8,Math.min(Lt,et-de-8)),left:Math.max(8,Math.min(At,Fe-se-8))}),E(I===u?null:u)},De=u=>(V-1)*J+u+1,Ee=u=>{let y=u;y&&y.src instanceof File&&(y={...y,src:URL.createObjectURL(y.src)}),H(y),te(!0)},je=(u,y,T,$=null,Z=null)=>t.jsx(t.Fragment,{children:u?t.jsx("img",{src:u instanceof File?URL.createObjectURL(u):u,alt:y||"Avatar",onClick:se=>{se.stopPropagation(),se.preventDefault(),Ee({src:u,alt:y})},className:`w-10 h-10 cursor-pointer shrink-0 rounded-full object-cover border border-gray-200 dark:border-gray-700 ${T||""}`}):t.jsx(t.Fragment,{children:$?typeof $=="function"?$(Z):$:t.jsx("div",{className:`w-10 h-10 flex items-center shrink-0 justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-gray-200 dark:bg-gray-600 ${T||""}`,children:t.jsx(U.User,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),_e=(u,y)=>t.jsx(t.Fragment,{children:u?t.jsx("audio",{controls:!0,src:u instanceof File?URL.createObjectURL(u):u,onClick:T=>{T.stopPropagation()},className:`w-64 cursor-pointer ${y||""}`},u instanceof File?URL.createObjectURL(u):u):t.jsx(t.Fragment,{children:t.jsx("div",{className:`w-12 h-12 flex items-center shrink-0 justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-gray-200 dark:bg-gray-600 ${y||""}`,children:t.jsx(U.Music,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),Pe=(u,y)=>t.jsxs("div",{className:`flex items-center space-x-4 ${y.className||""}`,children:[y.imageKey?je(u[y.imageKey],u[y.titleKey],"group-avatar",y.fallback_icon,u):"",t.jsxs("div",{children:[t.jsx("p",{className:"font-medium text-gray-900 dark:text-white group-title",children:u[y.titleKey]||""}),t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 group-sub-title",children:u[y.subtitleKey]||""})]})]}),Ae=(u,y)=>{var se;let T=String(u);const $=y.variant||"contained";let Z=y.defaultColor;if(((se=y==null?void 0:y.chipOptions)==null?void 0:se.length)>0){const de=y==null?void 0:y.chipOptions.find(Fe=>Fe.value==u);de&&(T=de.label,Z=de.color)}return t.jsx(Et,{label:T,variant:$,color:Z,className:y.className||""})},Le=(u,y,T)=>{const $=y[u.key];return u.type==="menu_actions"?t.jsx("div",{className:`text-center ${u.className||""}`,children:t.jsx("button",{ref:Z=>{we.current[y.id||y._id]=Z},onClick:Z=>Ce(y.id||y._id,Z,u.menuList),className:"p-2 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-full transition text-gray-700 dark:text-gray-300",children:t.jsx(U.EllipsisVertical,{className:"h-4 w-4"})})}):u.type==="index"?t.jsx("span",{className:u.className||"",children:De(T)}):u.type==="group"?Pe(y,u):u.type==="chip"?t.jsx(t.Fragment,{children:Ae($,u)}):u.type==="date"?t.jsx("span",{className:u.className||"",children:gt($,u.format||"DD MMM YYYY")}):u.type==="avatar"?t.jsx(t.Fragment,{children:t.jsx("div",{className:"min-w-[40px]",children:je($,u.alt,u.className,u.fallback_icon,y)})}):u.type==="audio"?t.jsx(t.Fragment,{children:_e($,u.className)}):t.jsx("span",{className:u.className||"",children:$||"N/A"})},_=u=>{if(typeof A=="function")return A(u);if(A)return g==null?void 0:g("view",u)},O=(u,y)=>{if(u.onClickDetails)return g==null?void 0:g("view",y);if(typeof u.handleClick=="function")return u.handleClick(y)},K=()=>A||typeof A=="function",oe=u=>u.onClickDetails||typeof u.handleClick=="function";return b.useEffect(()=>{const u=()=>{I&&E(null)};return window.addEventListener("scroll",u,!0),()=>{window.removeEventListener("scroll",u,!0)}},[I]),b.useEffect(()=>{const u=y=>{be.current&&!be.current.contains(y.target)&&E(null)};return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[]),b.useEffect(()=>{l!=null&&l.rows_per_page&&(l!=null&&l.useServerSidePagination)&&xe((l==null?void 0:l.rows_per_page)||50),l.current_page&&re(l.current_page)},[l.rows_per_page,l==null?void 0:l.useServerSidePagination,l.current_page]),b.useEffect(()=>{Se(l!=null&&l.useServerSidePagination?l.total_records:ne.length),ne.length<=J*(V-1)&&!(l!=null&&l.useServerSidePagination)&&re(u=>u-1||1)},[ne.length,l.total_records,l==null?void 0:l.useServerSidePagination]),b.useEffect(()=>{if(!(N!=null&&N.enabled)){k("");return}if(B.some(y=>y.value===N.defaultValue)){k(N.defaultValue);return}k("")},[N,B]),b.useEffect(()=>{if(!(N!=null&&N.enabled)||!(N!=null&&N.useServerSideSorting))return;const u=B==null?void 0:B.find(y=>y.value===M);j(y=>({...y,current_page:1,sort_by:(u==null?void 0:u.key)||"",sort_order:(u==null?void 0:u.order)||""}))},[M,N==null?void 0:N.enabled,N==null?void 0:N.useServerSideSorting,B,j]),t.jsxs(t.Fragment,{children:[f?t.jsx(Mr,{rows:6,columns:6}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col lg:!flex-row lg:!justify-between gap-4 mb-3",children:[t.jsxs("div",{className:"table-heading",children:[t.jsx("h1",{children:e}),t.jsx("p",{children:o})]}),t.jsxs("div",{className:"flex flex-col justify-end items-stretch lg:!items-end gap-2 w-full lg:!w-auto",children:[i&&t.jsxs(ae,{onClick:()=>a(!0),variant:"contained",color:"primary",children:[t.jsx(U.Plus,{className:"w-4 h-4 mr-2"}),r||"Add New"]}),t.jsxs("div",{className:"flex flex-col sm:!flex-row sm:!flex-wrap justify-end items-stretch sm:!items-center gap-2 w-full",children:[d.enabled&&t.jsx("div",{className:"w-full sm:!w-auto",children:t.jsxs("div",{className:"table-search-field",children:[t.jsx(U.Search,{className:"search-icon"}),t.jsx("input",{type:"text",placeholder:d.placeholder||"Search...",value:L,onChange:u=>Ne(u.target.value)})]})}),N!=null&&N.enabled&&(B==null?void 0:B.length)>0||R&&p.enabled?t.jsxs("div",{className:"flex items-center justify-end gap-2 w-full sm:!w-auto",children:[R&&p.enabled&&t.jsxs("div",{className:"filter-button-wrapper",children:[t.jsxs(ae,{onClick:()=>Y(!0),variant:"contained",className:"w-full sm:!w-auto",children:[t.jsx(U.Filter,{className:"w-4 h-4 mr-2"}),"Filters"]}),Object.keys(ee).length>0&&t.jsx("span",{className:"red-dot"})]}),(N==null?void 0:N.enabled)&&(B==null?void 0:B.length)>0&&t.jsx(Rr,{options:B,value:M,onChange:Me,clearLabel:N==null?void 0:N.clearLabel})]}):null]})]})]}),t.jsxs("div",{className:"table-container",children:[t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{children:[t.jsx("thead",{children:t.jsx("tr",{children:c.map(u=>t.jsx("th",{className:`table-head-data ${u.headClass||""}`,children:u.title},u.key))})}),t.jsx("tbody",{children:ve.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:c.length,className:"no-data-message",children:m})}):ve.map((u,y)=>t.jsx("tr",{className:`table-row ${K()?"cursor-pointer":""}`,onClick:()=>{K()&&_(u)},children:c.map(T=>t.jsx("td",{className:`table-data ${T.type=="audio"?"":"max-w-[300px]"} truncate ${oe(T)?"cursor-pointer":""}`,title:String(u[T.key]??""),onClick:$=>{oe(T)&&($.stopPropagation(),$.preventDefault(),O(T,u))},children:T.render?T.render(u,y):Le(T,u,y)},T.key))},u.id||u._id||y))})]})}),(l==null?void 0:l.enabled)&&ne.length>0&&t.jsxs("div",{className:"pagination-wrapper",children:[t.jsxs("span",{children:["Showing ",(V-1)*J+1," to"," ",Math.min(V*J,ye)," of"," ",ye," results"]}),t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{children:"Rows per page:"}),t.jsx("select",{value:J,onChange:u=>{const y=Number(u.target.value);xe(y),re(1),l.useServerSidePagination&&j(T=>({...T,current_page:1,rows_per_page:y}))},className:"rows-number-select",children:[10,25,50,100].map(u=>t.jsx("option",{value:u,children:u},u))})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>{if(V>1){const u=V-1;re(u),l.useServerSidePagination&&j(y=>({...y,current_page:u}))}},disabled:V===1,className:"arrow-icons",children:t.jsx(U.ChevronLeft,{className:"h-4 w-4"})}),t.jsxs("span",{children:["Page ",V," of ",fe]}),t.jsx("button",{onClick:()=>{if(V<fe){const u=V+1;re(u),l.useServerSidePagination&&j(y=>({...y,current_page:u}))}},disabled:V===fe,className:"arrow-icons",children:t.jsx(U.ChevronRight,{className:"h-4 w-4"})})]})]})]})]})]}),I&&Ft.createPortal(t.jsx("div",{ref:be,style:{position:"fixed",top:`${S.top}px`,left:`${S.left}px`,zIndex:9999},className:"w-48 bg-white dark:bg-gray-700 rounded-md shadow-lg border border-gray-200 dark:border-gray-600",children:x.map((u,y)=>t.jsxs("button",{onClick:T=>Re(u,s.find($=>$.id===I||$._id==I),T),className:`w-full flex items-center gap-2 px-4 py-2 text-sm text-left hover:bg-gray-100 dark:hover:bg-gray-600 ${u.variant==="danger"?"text-red-600 dark:text-red-500":"text-gray-700 dark:text-gray-200"}`,children:[u.icon&&t.jsx("span",{className:"shrink-0",children:u.icon}),u.title]},y))}),document.body),R&&t.jsx(Nr,{isOpen:P,onClose:()=>Y(!1),config:R,onApply:u=>{G(u),v==null||v(u)}}),F&&z&&t.jsx(Qe,{src:z.src,alt:z.alt,isOpen:F,setIsOpen:te})]})},Oe=({isOpen:n,onClose:a,icon:e,title:r,children:o,size:i="md",actionButtons:s=[],onFormSubmit:c=()=>{},loadingBtn:f=!1,executeFunction:d=()=>{},selectedItem:p=null})=>{if(!n)return null;const h={sm:"max-w-md",md:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-full"};return t.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[t.jsx("div",{className:"fixed inset-0 bg-gray-500 opacity-75",onClick:()=>a()}),t.jsxs("div",{className:`relative bg-white rounded-lg shadow-xl w-full ${h[i]||h.md} max-h-[90vh] flex flex-col dark:bg-gray-800`,children:[t.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[e&&t.jsx("span",{children:e}),t.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:r})]}),t.jsx("button",{onClick:()=>a(),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:t.jsx(U.X,{className:"w-6 h-6"})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:o}),s.length>0&&t.jsx("div",{className:"px-4 py-3 flex justify-end gap-3 border-t border-gray-200 dark:border-gray-700 sm:!px-6",children:s.map((l,m)=>t.jsx(ae,{onClick:g=>{l.type=="submit"?c(g):d(()=>{var j;return Promise.resolve((j=l==null?void 0:l.onClick)==null?void 0:j.call(l,g,p))},j=>a==null?void 0:a(j))},disabled:f||l.disabled,variant:l.variant||"contained",color:l.color||"primary",className:`min-w-[100px] ${l.className||""}`,type:l.type||"button",children:f?t.jsxs("div",{className:"flex items-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-2 border-t-white mr-2"}),l.label||"Submit","..."]}):l.label||"Submit"},`${l.label||"action"}-${m}`))})]})]})},bt=({config:n,onSubmit:a,initialData:e,fetchRowDetails:r,type:o})=>{const i=e||{},{formClass:s="grid grid-cols-12 gap-4",formFields:c=[]}=n||{},[f,d]=b.useState(i),[p,h]=b.useState(!0),l=async()=>{r==null||r(i).then(j=>{d(j.data)}).catch(j=>{le.enqueueSnackbar(j.message,{variant:"error"})}).finally(()=>{h(!1)})};b.useEffect(()=>{r instanceof Function?l():(d(i),h(!1))},[]);const m=(j,v)=>{d(R=>({...R,[j]:v}))},g=j=>{j.preventDefault();const v=j.currentTarget;if(!v.checkValidity()){v.reportValidity();return}a(f)};return p?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsx("div",{className:"rounded-full border-4 border-blue-500 border-t-gray-200 animate-spin w-8 h-8",style:{borderTopColor:"border-primary-500"}})}):t.jsx("form",{id:o==="add"?"addForm":o==="edit"?"editForm":"defaultForm",onSubmit:g,className:s,noValidate:!1,children:c.map(j=>t.jsx(Pt,{field:j,formData:f,handleChange:m},j.key))})};function Lr({data:n,config:a,fetchRowDetails:e}){const{fields:r=[],containerClass:o}=a||{},i=n||{},[s,c]=b.useState(i),[f,d]=b.useState(!0),p=async()=>{e==null||e(i).then(h=>{c(h.data)}).catch(h=>{le.enqueueSnackbar(h.message,{variant:"error"})}).finally(()=>{d(!1)})};return b.useEffect(()=>{e instanceof Function?p():(c(i),d(!1))},[]),f?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsx("div",{className:"rounded-full border-4 border-blue-500 border-t-gray-200 animate-spin w-8 h-8",style:{borderTopColor:"border-primary-500"}})}):t.jsx(t.Fragment,{children:t.jsx("div",{className:`grid grid-cols-12 gap-4 ${o||""}`,children:r.map(h=>h.renderCondition&&typeof h.renderCondition=="function"&&!h.renderCondition(s)?null:h.type=="group"?t.jsx(Ct,{col:h,data:s},h.key||h.titleKey):h.type=="cardGroup"?t.jsx(Dt,{col:h,data:s},h.key||h.titleKey):t.jsx(_t,{col:h,data:s},h.key||h.label))})})}const Fr=({config:n})=>{var J,xe,ye,Se,fe,ve,be,we,ge,Ne,Me,Re,Ce,De,Ee,je,_e,Pe,Ae,Le;const{title:a,fetchData:e,fetchRowDetails:r,isStaticData:o=!1,tableConfig:i,modalConfig:s,filterConfig:c}=n,[f,d]=b.useState(!0),[p,h]=b.useState(!1),[l,m]=b.useState([]),[g,j]=b.useState(null),[v,R]=b.useState({search:"",rows_per_page:50,current_page:1,sort_by:"",sort_order:""}),[A,L]=b.useState({}),[C,I]=b.useState(!1),[E,x]=b.useState(!1),[w,S]=b.useState(!1),[D,P]=b.useState(!1),[Y,ee]=b.useState(!1),[G,N]=b.useState(null),X=(_,O)=>{_==="edit"?(N(O),S(!0)):_==="view"?(N(O),ee(!0)):_==="delete"&&(N(O),P(!0))},B=async(_,O,K="",oe="")=>{h(!0);try{if(!_)return;const u=await _();(K||u!=null&&u.message)&&le.enqueueSnackbar(K||u.message||"Success",{variant:"success"}),O==null||O(u)}catch(u){(oe||u!=null&&u.message)&&le.enqueueSnackbar(oe||u.message||"Error occurred",{variant:"error"})}finally{h(!1)}},M=_=>{const O=_.newObject;o?(m(K=>[O,...K]),j(K=>({...K,current_page:1}))):(R(K=>({...K,current_page:1})),v.current_page===1&&te()),x(!1)},k=_=>{const{newObject:O,targetObject:K}=_;o?m(oe=>oe.map(u=>u.id===K.id?{...u,...O}:u)):te(),S(!1)},z=_=>{if(!_){P(!1),N(null);return}o?m(O=>O.filter(K=>K.id!==_.targetObject.id)):l.length===1&&v.current_page>1?R(O=>({...O,current_page:O.current_page-1})):te(),P(!1),N(null)},H=_=>B(()=>{var O;return(O=s==null?void 0:s.addModal)!=null&&O.handleSubmit?s.addModal.handleSubmit(_):Promise.resolve({newObject:null})},M),F=_=>B(()=>{var O;return(O=s==null?void 0:s.editModal)!=null&&O.handleSubmit?s.editModal.handleSubmit(_,G):Promise.resolve({newObject:null,targetObject:null})},k),te=async()=>{d(!0);try{const _=await e({...v,...A});m(_.data||[]),j(_.pagination||null)}catch(_){le.enqueueSnackbar(_.message||"Failed to fetch data",{variant:"error"})}finally{d(!1)}},pe=_=>{var O;L(()=>({..._})),(O=i==null?void 0:i.filter)!=null&&O.useServerSideFilters&&I(K=>!K)},ne=(_,O)=>_.filter(K=>Object.entries(O).every(([oe,u])=>K[oe]===u)),V=b.useMemo(()=>{var _;return(_=i==null?void 0:i.filter)!=null&&_.useServerSideFilters?l:ne(l,A)},[l,A,(J=i==null?void 0:i.filter)==null?void 0:J.useServerSideFilters]),re=(xe=s==null?void 0:s.viewModal)==null?void 0:xe.component;return b.useEffect(()=>{te()},[v.search,v.rows_per_page,v.current_page,v.sort_by,v.sort_order,C]),t.jsxs("div",{children:[t.jsx(Ar,{title:a,setShowAdd:x,description:n.description,buttonText:n.buttonText,showAddButton:!!(s!=null&&s.addModal),config:{...i,pagination:{...i.pagination,...g},data:V,setServerSidePaginationData:R,onMenuAction:X,filterConfig:c,onFilterApply:pe,loading:f}}),t.jsx(Oe,{isOpen:E,onClose:()=>{p||x(!1)},icon:(ye=s==null?void 0:s.addModal)==null?void 0:ye.icon,title:((Se=s==null?void 0:s.addModal)==null?void 0:Se.title)||"Add New",size:((fe=s==null?void 0:s.addModal)==null?void 0:fe.size)||"md",onFormSubmit:()=>{var _;return(_=document.querySelector("#addForm"))==null?void 0:_.requestSubmit()},loadingBtn:p,actionButtons:((ve=s==null?void 0:s.addModal)==null?void 0:ve.actionButtons)||[],children:t.jsx(bt,{config:(s==null?void 0:s.addModal)||{},onSubmit:H,initialData:{},type:"add",loading:p})}),t.jsx(Oe,{isOpen:w,onClose:()=>{p||S(!1)},icon:(be=s==null?void 0:s.editModal)==null?void 0:be.icon,title:((we=s==null?void 0:s.editModal)==null?void 0:we.title)||"Edit",size:((ge=s==null?void 0:s.editModal)==null?void 0:ge.size)||"md",onFormSubmit:()=>{var _;return(_=document.querySelector("#editForm"))==null?void 0:_.requestSubmit()},actionButtons:((Ne=s==null?void 0:s.editModal)==null?void 0:Ne.actionButtons)||[],loadingBtn:p,children:t.jsx(bt,{config:(s==null?void 0:s.editModal)||{},onSubmit:F,initialData:G,type:"edit",loading:p,fetchRowDetails:r})}),D&&t.jsx(Oe,{isOpen:D,onClose:_=>{z(_)},icon:((Me=s==null?void 0:s.deleteModal)==null?void 0:Me.icon)||t.jsx(ce.Icon,{icon:"ph:warning-bold",className:"w-6 h-6 text-red-500"}),title:((Re=s==null?void 0:s.deleteModal)==null?void 0:Re.title)||"Confirm Delete",size:((Ce=s==null?void 0:s.deleteModal)==null?void 0:Ce.size)||"md",loading:p,actionButtons:((De=s==null?void 0:s.deleteModal)==null?void 0:De.actionButtons)||[],executeFunction:B,selectedItem:G,children:t.jsx("div",{className:"flex items-center space-x-2 py-3",children:t.jsxs("div",{children:[t.jsx("p",{className:"text-md text-gray-700 dark:text-white",children:((Ee=s==null?void 0:s.deleteModal)==null?void 0:Ee.confirmText)||"Are you sure you want to delete this item?"}),((je=s==null?void 0:s.deleteModal)==null?void 0:je.referenceKey)&&t.jsx("p",{className:"text-md font-semibold text-gray-700 dark:text-white",children:G==null?void 0:G[(_e=s==null?void 0:s.deleteModal)==null?void 0:_e.referenceKey]})]})})}),(s==null?void 0:s.viewModal)&&t.jsx(Oe,{isOpen:Y,onClose:()=>{ee(!1),N(null)},icon:(Pe=s==null?void 0:s.viewModal)==null?void 0:Pe.icon,title:((Ae=s==null?void 0:s.viewModal)==null?void 0:Ae.title)||"View Details",size:((Le=s==null?void 0:s.viewModal)==null?void 0:Le.size)||"lg",footerConfig:s==null?void 0:s.viewModal.footer,children:re?t.jsx(re,{data:G}):t.jsx(Lr,{data:G,fetchRowDetails:r,config:(s==null?void 0:s.viewModal)||{}})})]})};function Ir({children:n}){return le.useSnackbar(),n}function Tr({children:n}){try{return t.jsx(Ir,{children:n})}catch{return t.jsx(le.SnackbarProvider,{anchorOrigin:{vertical:"bottom",horizontal:"right"},action:e=>t.jsx("button",{onClick:()=>{window.dispatchEvent(new CustomEvent("closeSnackbar",{detail:e}))},className:"p-1 hover:bg-white/20 rounded-full transition-colors duration-200 text-white flex items-center justify-center",children:t.jsx(U.X,{className:"h-4 w-4"})}),maxSnack:3,autoHideDuration:3e3,children:n})}}const Or=()=>{if(typeof document>"u"||document.getElementById("react-admin-crud-manager-styles"))return;const n=document.createElement("style");n.id="react-admin-crud-manager-styles",n.textContent=`
|
|
150
150
|
.no-spinner::-webkit-outer-spin-button,
|
|
151
151
|
.no-spinner::-webkit-inner-spin-button {
|
|
152
152
|
-webkit-appearance: none;
|