react-admin-crud-manager 1.2.7 → 1.2.8

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 CHANGED
@@ -124,6 +124,6 @@
124
124
  }
125
125
  `,...w},onEditorChange:I=>{t==null||t(I)}}),j&&r.jsx("span",{className:v(x.field.error,"text-red-500 text-xs mt-1"),children:j})]})},Et=({name:a="",label:o="",options:e=[],value:t=null,onChange:n,disabled:s=!1,required:i=!1,parentClass:l="col-span-12",className:h="",errorMessage:d="",multiSelect:m=!1})=>{const u=Array.isArray(e)&&e.length>0,c=w=>u?m?Array.isArray(t)&&t.includes(w):t===w:!!t,g=w=>{n==null||n(w.target.checked,a)},f=(w,N)=>{if(n)if(!m)n(N?w:"",a);else{const j=Array.isArray(t)?[...t]:[];if(N)j.includes(w)||j.push(w);else{const S=j.indexOf(w);S>-1&&j.splice(S,1)}n(j,a)}};return b.useEffect(()=>{let w;u?m?w=Array.isArray(t)?t:[]:w=t||"":w=!!t,setTimeout(()=>{n==null||n(w,a)},100)},[]),u?r.jsx(r.Fragment,{children:r.jsxs("div",{className:v(x.field.wrapper,l),children:[r.jsx(he,{label:o,required:i}),r.jsx("div",{className:"flex flex-col space-y-2",children:e.map((w,N)=>r.jsxs("div",{className:"flex items-center",children:[r.jsx("input",{type:"checkbox",name:a,id:`field-${a}`,value:w.value,checked:c(w.value),disabled:s||!!w.disabled,required:i&&N===0,onChange:j=>f(w.value,j.target.checked),className:v(x.field.input,"h-4 w-4 cursor-pointer text-blue-600 border-gray-300 rounded focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400",h)},a),w.label&&r.jsx("label",{htmlFor:a,className:"ml-2 text-sm text-gray-700 dark:text-gray-200 select-none",children:w.label})]},w.value||w.label))}),d&&r.jsx("span",{className:v(x.field.error,"text-red-500 text-xs mt-1"),children:d})]})}):r.jsxs("div",{className:v(x.field.wrapper,"flex items-center",l),children:[r.jsx("input",{type:"checkbox",name:a,checked:c(),disabled:s,required:i,onChange:g,className:v(x.field.input,"h-4 w-4 text-blue-600 cursor-pointer border-gray-300 rounded focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400",h)}),o&&r.jsx("label",{htmlFor:a,className:"ml-2 text-sm text-gray-700 dark:text-gray-200 select-none",children:o})]})},Nr=ue,At=({label:a="",value:o=null,onChange:e,required:t=!1,accept:n="audio/*",id:s,dragDrop:i=!1,name:l="",parentClass:h="",errorMessage:d="",maxSize:m=0})=>{const[u,c]=b.useState(null),[g,f]=b.useState(!1),w=b.useRef(null),N=m*1024*1024;b.useEffect(()=>{if(!o){j(),c(null);return}if(o instanceof File){const y=URL.createObjectURL(o);return c({file:o,preview:y}),()=>{URL.revokeObjectURL(y)}}else typeof o=="string"?c({preview:o}):o!=null&&o.preview&&c(o)},[o]);const j=()=>{u!=null&&u.preview&&u.preview.startsWith("blob:")&&URL.revokeObjectURL(u.preview)},S=y=>{if(!y||y.length===0)return;const A=y[0];if(N&&A.size>N){ke.enqueueSnackbar(`Audio is too large. Maximum allowed size is ${m} MB`,{variant:"warning"});return}const M=URL.createObjectURL(A);j(),c({file:A,preview:M}),e==null||e(A)},P=y=>{y&&y.stopPropagation(),j(),c(null),e==null||e(null),w.current&&(w.current.value="")},T=y=>{i&&(y.preventDefault(),f(!0))},I=y=>{i&&(y.preventDefault(),f(!1))},L=y=>{var A,M,z,H;i&&(y.preventDefault(),f(!1),(H=(z=(M=(A=y.dataTransfer)==null?void 0:A.files)==null?void 0:M[0])==null?void 0:z.type)!=null&&H.includes("audio/")&&S(y.dataTransfer.files))},U=()=>{var y;(y=w.current)==null||y.click()};return r.jsxs("div",{className:v(x.mediaPicker.audio,x.field.wrapper,h||"col-span-12"),children:[r.jsx(he,{label:a,required:t}),r.jsxs("div",{className:v(x.mediaPicker.dropzone,"relative rounded-lg p-2 transition-all",g?"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",d?"border-red-500":""),onDragOver:T,onDragLeave:I,onDrop:L,id:`field-${l}`,children:[r.jsx("input",{ref:w,id:s,type:"file",accept:n,onChange:y=>S(y.target.files),required:t&&!u,className:"absolute opacity-0 right-[50%] top-[80%] -translate-y-1/2 pointer-events-none h-[10px]"}),r.jsx("div",{className:`flex items-center space-x-4 transition-all ${g?"opacity-50":""}`,children:u?r.jsxs("div",{className:"flex items-center space-x-4",children:[r.jsxs("div",{className:"relative w-full",children:[!t&&r.jsx("button",{type:"button",onClick:P,className:"absolute top-0 -right-2 bg-red-500 text-white rounded-full p-1 shadow-lg hover:bg-red-600 transition-colors z-10 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 dark:focus:ring-offset-gray-800","aria-label":"Remove audio",children:r.jsx(me.Icon,{icon:"mdi:close",className:"w-3 h-3"})}),r.jsx("audio",{src:u.preview,controls:!0,controlsList:"nodownload"},u.preview)]}),r.jsx(Nr,{type:"button",onClick:U,children:r.jsx("span",{children:"Change Audio File"})})]}):r.jsxs("div",{className:"flex items-center justify-center space-x-4",children:[r.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:r.jsx(me.Icon,{icon:"mdi:music",className:"text-gray-400 w-10 h-10"})}),r.jsxs("div",{className:"flex flex-col items-center space-y-1",children:[r.jsx(Nr,{type:"button",onClick:U,variant:"outlined",children:r.jsx("span",{children:"Choose Audio File"})}),i&&r.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop your audio file here"})]})]})}),i&&g&&!u&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-lg",children:r.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 audio here"})})]}),d&&r.jsx("span",{className:v(x.field.error,"text-red-500 text-xs mt-1"),children:d})]},l)},Sr=ue,Ft=a=>{if(!a)return null;if(a instanceof File){const o=URL.createObjectURL(a);return{id:`${Date.now()}-${Math.random()}`,file:a,preview:o,createdBlobUrl:o}}if(typeof a=="string")return{id:`${Date.now()}-${Math.random()}`,file:null,preview:a};if(typeof a=="object"){if(a.preview)return{id:`${Date.now()}-${Math.random()}`,file:a.file||null,preview:a.preview};if(a.file){const o=URL.createObjectURL(a.file);return{id:`${Date.now()}-${Math.random()}`,file:a.file,preview:o,createdBlobUrl:o}}}return null},zt=({label:a="",value:o=[],onChange:e,required:t=!1,accept:n="image/*",aspect:s="1",id:i,dragDrop:l=!1,cropImage:h=!1,name:d="",parentClass:m="",maxImages:u,errorMessage:c=""})=>{const[g,f]=b.useState([]),[w,N]=b.useState(!1),[j,S]=b.useState(!1),[P,T]=b.useState(""),[I,L]=b.useState("image/jpeg"),[U,y]=b.useState("cropped-image"),[A,M]=b.useState(null),z=b.useRef(null),H=b.useRef(null),V=b.useRef(""),ee=b.useRef([]);b.useEffect(()=>{ee.current=g},[g]),b.useEffect(()=>()=>{ee.current.forEach(R=>{R.createdBlobUrl&&URL.revokeObjectURL(R.createdBlobUrl)}),V.current&&URL.revokeObjectURL(V.current)},[]),b.useEffect(()=>{if(!Array.isArray(o)){f([]);return}const R=o.map(O=>Ft(O)).filter(Boolean);f(O=>(O.forEach(q=>{q.createdBlobUrl&&URL.revokeObjectURL(q.createdBlobUrl)}),R))},[o]);const ae=typeof u=="number"&&u>0?Math.max(u-g.length,0):Number.POSITIVE_INFINITY,D=()=>{S(!1),V.current&&(URL.revokeObjectURL(V.current),V.current=""),T(""),M(null),z.current&&(z.current.value="")},C=R=>{var O,q;T(R.preview),L(((O=R.file)==null?void 0:O.type)||"image/jpeg"),y((((q=R.file)==null?void 0:q.name)||"cropped-image").replace(/\.[^/.]+$/,"")),M(R.id),S(!0)},F=R=>{const O=URL.createObjectURL(R);f(q=>{const J=q.map(Z=>Z.id!==A?Z:(Z.createdBlobUrl&&URL.revokeObjectURL(Z.createdBlobUrl),{...Z,file:R,preview:O,createdBlobUrl:O}));return e==null||e(J.map(Z=>Z.file?Z.file:Z.preview)),J}),D()},Y=R=>{if(!R||R.length===0||ae===0)return;const O=Array.from(R).filter(J=>J.type.includes("image/")).slice(0,ae);if(O.length===0)return;const q=O.map(J=>{const Z=URL.createObjectURL(J);return{id:`${Date.now()}-${Math.random()}`,file:J,preview:Z,createdBlobUrl:Z}});f(J=>{const Z=[...J,...q];return e==null||e(Z.map(oe=>oe.file?oe.file:oe.preview)),Z}),z.current&&(z.current.value="")},$=R=>{f(O=>{const q=O.find(Z=>Z.id===R);q!=null&&q.createdBlobUrl&&URL.revokeObjectURL(q.createdBlobUrl);const J=O.filter(Z=>Z.id!==R);return e==null||e(J.map(Z=>Z.file?Z.file:Z.preview)),J}),z.current&&(z.current.value="")},K=R=>{var O;M(R),(O=H.current)==null||O.click()},ce=R=>{if(!R||R.length===0||!A)return;const O=Array.from(R).find(J=>J.type.includes("image/"));if(!O)return;const q=URL.createObjectURL(O);f(J=>{const Z=J.map(oe=>oe.id!==A?oe:(oe.createdBlobUrl&&URL.revokeObjectURL(oe.createdBlobUrl),{...oe,file:O,preview:q,createdBlobUrl:q}));return e==null||e(Z.map(oe=>oe.file?oe.file:oe.preview)),Z}),M(null),H.current&&(H.current.value="")},E=R=>{l&&(R.preventDefault(),N(!0))},be=R=>{l&&(R.preventDefault(),N(!1))},we=R=>{var O;l&&(R.preventDefault(),N(!1),Y(((O=R.dataTransfer)==null?void 0:O.files)||null))},_=()=>{var R;(R=z.current)==null||R.click()},B=typeof u=="number"&&u>0?g.length<u:!0;return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:v(x.mediaPicker.multiImage,x.field.wrapper,m||"col-span-12"),children:[r.jsx(he,{label:a,required:t}),r.jsxs("div",{className:v(x.mediaPicker.dropzone,"relative rounded-md p-2 transition-all",w?"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",c?"border-red-500":""),onDragOver:E,onDragLeave:be,onDrop:we,id:`field-${d}`,children:[r.jsx("input",{ref:z,id:i,type:"file",accept:n,multiple:!0,onChange:R=>Y(R.target.files),required:t&&g.length===0,className:"absolute opacity-0 pointer-events-none h-1 w-1"}),r.jsx("input",{ref:H,type:"file",accept:n,onChange:R=>ce(R.target.files),className:"absolute opacity-0 pointer-events-none h-1 w-1"}),g.length===0?r.jsxs("div",{className:"flex items-center space-x-4",children:[r.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:r.jsx(me.Icon,{icon:"ri:multi-image-fill",className:"text-gray-400 w-10 h-10"})}),r.jsxs("div",{className:"flex flex-col items-center space-y-1",children:[r.jsx(Sr,{type:"button",onClick:_,variant:"outlined",color:"default",children:r.jsx("span",{className:"text-sm font-medium",children:"Choose Images"})}),l&&r.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop your images here"})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-3",children:[r.jsx(Sr,{type:"button",onClick:_,disabled:!B,variant:"outlined",color:"default",children:r.jsx("span",{className:"text-sm font-medium",children:"Upload Images"})}),r.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:u?`${g.length}/${u}`:`${g.length} selected`})]}),r.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3",children:g.map(R=>r.jsxs("div",{className:"relative group rounded-md overflow-hidden border border-gray-200 dark:border-gray-700",children:[r.jsx("img",{src:R.preview,alt:"preview",className:"w-full h-28 object-cover"}),r.jsxs("div",{className:"absolute top-2 right-2 flex items-center gap-1.5 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",children:[r.jsx("button",{type:"button",onClick:()=>K(R.id),className:"w-7 h-7 rounded-full bg-white/90 text-gray-800 hover:bg-white flex items-center justify-center shadow","aria-label":"Replace image",children:r.jsx(me.Icon,{icon:"solar:refresh-bold",className:"w-4 h-4"})}),h&&r.jsx("button",{type:"button",onClick:()=>C(R),className:"w-7 h-7 rounded-full bg-white/90 text-gray-800 hover:bg-white flex items-center justify-center shadow","aria-label":"Crop image",children:r.jsx(me.Icon,{icon:"solar:crop-bold",className:"w-4 h-4"})}),r.jsx("button",{type:"button",onClick:()=>$(R.id),className:"w-7 h-7 rounded-full bg-red-500/95 text-white hover:bg-red-600 flex items-center justify-center shadow","aria-label":"Delete image",children:r.jsx(me.Icon,{icon:"solar:trash-bin-trash-bold",className:"w-4 h-4"})})]})]},R.id))})]}),l&&w&&g.length===0&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-lg",children:r.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 images here"})})]}),c&&r.jsx("span",{className:v(x.field.error,"text-red-500 text-xs mt-1"),children:c})]},d),r.jsx(Tr,{isOpen:j,imageSrc:P,fileType:I,fileName:U,onClose:D,onApply:F,aspect:Number(s)})]})},xe=({src:a,alt:o="preview",isOpen:e,setIsOpen:t})=>{const n=()=>t(!1);return b.useEffect(()=>{const s=i=>{i.key==="Escape"&&n()};return e&&(document.body.style.overflow="hidden",document.addEventListener("keydown",s)),()=>{document.body.style.overflow="",document.removeEventListener("keydown",s)}},[e]),r.jsx(r.Fragment,{children:r.jsxs("div",{className:v(x.imagePreview.root,"fixed inset-0 z-50 flex items-center justify-center bg-black/70 dark:bg-black/80 backdrop-blur-sm animate-in fade-in duration-200"),onClick:n,children:[r.jsx("button",{onClick:n,className:`absolute top-4 right-4 bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200\r
126
126
  hover:bg-gray-100 dark:hover:bg-gray-700 rounded-full p-2 shadow-lg transition`,children:r.jsx(te.X,{size:20})}),r.jsx("div",{className:v(x.imagePreview.container,"max-w-5xl w-full px-4 transform transition-all duration-200 scale-95 animate-in zoom-in-95"),onClick:s=>s.stopPropagation(),children:r.jsx("img",{src:a,alt:o,className:v(x.imagePreview.image,"w-full max-h-[90vh] object-contain rounded-xl")})})]})})},Gr=({col:a,data:o,uiVariant:e="default",styleConfig:t={}})=>{const n=o[a.titleKey],s=o[a.subtitleKey],i=o[a.imageKey],l=a.fallback_icon,[h,d]=b.useState(null),[m,u]=b.useState(!1),c=f=>{let w=f;f&&f.src instanceof File&&(w={...f,src:URL.createObjectURL(f.src)}),d(w),u(!0)},g=f=>{const N={sm:{img:"w-8 h-8",wrap:"w-8 h-8",icon:"w-4 h-4"},md:{img:"w-12 h-12",wrap:"w-12 h-12",icon:"w-6 h-6"},lg:{img:"w-16 h-16",wrap:"w-16 h-16",icon:"w-8 h-8"}}[f];return i?r.jsx("img",{src:i instanceof File?URL.createObjectURL(i):i,alt:n,onClick:()=>c({src:i,alt:n}),className:`${N.img} cursor-pointer rounded-full object-cover border-2 border-white dark:border-gray-700 shadow flex-shrink-0`}):l?l instanceof Function?l(o):l:r.jsx("div",{className:`${N.wrap} flex items-center justify-center rounded-full border-2 border-gray-300 dark:border-gray-600 bg-gray-200 dark:bg-gray-600 flex-shrink-0`,children:r.jsx(te.User,{className:`${N.icon} text-gray-400`})})};return e==="card"?r.jsxs(r.Fragment,{children:[m&&h&&r.jsx(xe,{src:h.src,alt:h.alt,isOpen:m,setIsOpen:u}),r.jsxs("div",{className:v(x.details.row,"col-span-12 relative overflow-hidden rounded-xl bg-gradient-to-r from-primary/10 via-primary/5 to-transparent dark:from-primary/20 dark:via-primary/10 border border-primary/20 dark:border-primary/30 p-5 flex items-center gap-4",t.rowClass||"",t.groupClass||"",a.blockClass||""),children:[r.jsx("div",{className:"pointer-events-none absolute -right-6 -top-6 w-32 h-32 rounded-full bg-primary/8 dark:bg-primary/12"}),r.jsx("div",{className:"pointer-events-none absolute -right-2 -bottom-4 w-20 h-20 rounded-full bg-primary/5"}),g("lg"),r.jsxs("div",{className:"min-w-0 z-10",children:[r.jsx("h3",{className:`text-lg font-bold text-gray-900 dark:text-white truncate ${t.valueClass||""}`,children:n}),r.jsx("p",{className:`text-sm text-primary/70 dark:text-primary/60 font-medium truncate ${t.labelClass||""}`,children:s})]})]})]}):e==="split"?r.jsxs(r.Fragment,{children:[m&&h&&r.jsx(xe,{src:h.src,alt:h.alt,isOpen:m,setIsOpen:u}),r.jsxs("div",{className:v(x.details.row,"flex items-center gap-3 px-5 py-4 bg-gradient-to-r from-primary/8 via-primary/4 to-transparent dark:from-primary/15 dark:via-primary/8",t.rowClass||"",t.groupClass||"",a.blockClass||""),children:[g("md"),r.jsxs("div",{className:"min-w-0",children:[r.jsx("h3",{className:`text-base font-bold text-gray-900 dark:text-white truncate ${t.valueClass||""}`,children:n}),r.jsx("p",{className:`text-xs font-semibold text-primary/70 dark:text-primary/60 truncate ${t.labelClass||""}`,children:s})]})]})]}):r.jsxs(r.Fragment,{children:[m&&h&&r.jsx(xe,{src:h.src,alt:h.alt,isOpen:m,setIsOpen:u}),r.jsxs("div",{className:v(x.details.row,"col-span-12 flex items-center space-x-4 p-4 rounded-xl bg-gray-100 dark:bg-gray-900",t.rowClass||"",t.groupClass||"",a.blockClass||""),children:[g("lg"),r.jsxs("div",{children:[r.jsx("h3",{className:`text-xl font-semibold text-gray-900 dark:text-white ${t.valueClass||""}`,children:n}),r.jsx("p",{className:`text-sm text-gray-500 dark:text-gray-400 ${t.labelClass||""}`,children:s})]})]})]})},Yr=({col:a,data:o,uiVariant:e="default",styleConfig:t={}})=>{const n=o[a.titleKey],s=o[a.subtitleKey],i=o[a.imageKey],l=a.label,h=a==null?void 0:a.icon,d=a.fallback_icon,[m,u]=b.useState(null),[c,g]=b.useState(!1),f=N=>{let j=N;N&&N.src instanceof File&&(j={...N,src:URL.createObjectURL(N.src)}),u(j),g(!0)},w=()=>i?r.jsx("img",{src:i instanceof File?URL.createObjectURL(i):i,alt:n,onClick:()=>f({src:i,alt:n}),className:"w-8 h-8 cursor-pointer rounded-full object-cover border-2 border-gray-200 dark:border-gray-700 flex-shrink-0"}):d?d instanceof Function?d(o):d:r.jsx("div",{className:"w-8 h-8 flex items-center justify-center rounded-full border-2 border-gray-300 dark:border-gray-700 bg-gray-200 dark:bg-gray-600 flex-shrink-0",children:r.jsx(te.User,{className:"w-5 h-5 text-gray-400"})});return e==="card"?r.jsxs(r.Fragment,{children:[c&&m&&r.jsx(xe,{src:m.src,alt:m.alt,isOpen:c,setIsOpen:g}),r.jsxs("div",{className:v(x.details.row,a.blockClass||"col-span-6","group bg-white dark:bg-gray-800 rounded-xl border border-gray-100 dark:border-gray-700/60 shadow-sm hover:shadow-md hover:-translate-y-0.5 transition-all duration-200 p-4 flex flex-col gap-2.5",t.rowClass||"",t.cardGroupClass||""),children:[h&&r.jsx("div",{className:`w-8 h-8 rounded-lg bg-primary/10 dark:bg-primary/20 flex items-center justify-center text-primary flex-shrink-0 [&>svg]:w-4 [&>svg]:h-4 ${t.iconClass||""}`,children:h}),r.jsx("p",{className:`text-xs font-semibold uppercase tracking-wider text-gray-400 dark:text-gray-500 leading-none ${t.labelClass||""}`,children:l}),r.jsxs("div",{className:"flex items-center gap-2 mt-auto",children:[w(),r.jsxs("div",{className:"min-w-0",children:[r.jsx("p",{className:`text-sm font-semibold text-gray-800 dark:text-gray-100 truncate ${t.valueClass||""}`,children:n}),s&&r.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 truncate",children:s})]})]})]})]}):e==="split"?r.jsxs(r.Fragment,{children:[c&&m&&r.jsx(xe,{src:m.src,alt:m.alt,isOpen:c,setIsOpen:g}),r.jsxs("div",{className:v(x.details.row,"flex items-stretch min-h-[52px]",t.rowClass||"",t.cardGroupClass||"",a.blockClass||""),children:[r.jsxs("div",{className:"w-[42%] flex-shrink-0 flex items-center gap-2 px-4 py-3 bg-gray-50 dark:bg-gray-800/80 border-r border-gray-200 dark:border-gray-700",children:[h&&r.jsx("span",{className:`text-primary/60 dark:text-primary/50 flex-shrink-0 [&>svg]:w-3.5 [&>svg]:h-3.5 ${t.iconClass||""}`,children:h}),r.jsx("p",{className:`text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400 leading-tight ${t.labelClass||""}`,children:l})]}),r.jsxs("div",{className:"flex-1 flex items-center gap-2.5 px-4 py-3 bg-white dark:bg-gray-900",children:[w(),r.jsxs("div",{className:"min-w-0",children:[r.jsx("p",{className:`text-sm text-gray-800 dark:text-gray-100 break-words ${t.valueClass||""}`,children:n}),s&&r.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 truncate",children:s})]})]})]})]}):r.jsxs(r.Fragment,{children:[c&&m&&r.jsx(xe,{src:m.src,alt:m.alt,isOpen:c,setIsOpen:g}),r.jsxs("div",{className:v(x.details.row,"col-span-12 flex items-center space-x-4 p-4 rounded-xl bg-gray-100 dark:bg-gray-900",t.rowClass||"",t.cardGroupClass||"",a.blockClass||""),children:[h&&r.jsx("div",{className:`flex-shrink-0 ${t.iconClass||""}`,children:h}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:`text-sm font-medium text-gray-500 dark:text-gray-400 ${t.labelClass||""}`,children:l}),r.jsxs("div",{className:"flex items-center mt-1",children:[w(),r.jsxs("div",{className:"ml-2",children:[r.jsx("p",{className:`mb-0 text-sm text-gray-900 dark:text-white break-words ${t.valueClass||""}`,children:n}),r.jsx("p",{className:`text-xs text-gray-500 dark:text-gray-400 ${t.labelClass||""}`,children:s})]})]})]})]})]})},$r={blue:{bg:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300",border:"border border-blue-300 text-blue-700 dark:border-blue-700 dark:text-blue-300"},teal:{bg:"bg-teal-100 text-teal-800 dark:bg-teal-900/30 dark:text-teal-300",border:"border border-teal-300 text-teal-700 dark:border-teal-700 dark:text-teal-300"},purple:{bg:"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300",border:"border border-purple-300 text-purple-700 dark:border-purple-700 dark:text-purple-300"},yellow:{bg:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300",border:"border border-yellow-300 text-yellow-700 dark:border-yellow-700 dark:text-yellow-300"},green:{bg:"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300",border:"border border-green-300 text-green-700 dark:border-green-700 dark:text-green-300"},red:{bg:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300",border:"border border-red-300 text-red-700 dark:border-red-700 dark:text-red-300"},gray:{bg:"bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-300",border:"border border-gray-300 text-gray-700 dark:border-gray-700 dark:text-gray-300"}},_r={contained:"bg",outline:"border !bg-transparent",soft:"bg opacity-90"},Kr=({label:a,variant:o="contained",color:e="green",className:t=""})=>{const n=$r[e]||$r.green,s=_r[o]||_r.contained,i=o==="outline"?n.border:n.bg;return r.jsx("span",{className:v(x.chip.root,"inline-flex justify-center items-center rounded-sm text-xs font-semibold px-3 py-1 min-w-[78px]",i,s,t),children:a})},Wr=({col:a,data:o,uiVariant:e="default",styleConfig:t={}})=>{var j;const[n,s]=b.useState(null),[i,l]=b.useState(!1),h=a==null?void 0:a.icon,d=a.label;let m=o[a.key];const u=a.type,c=a.variant||"outline";let g=a.defaultColor;if(u==="chip"&&((j=a.chipOptions)==null?void 0:j.length)>0){const S=a==null?void 0:a.chipOptions.find(P=>P.value==m);S&&(m=S.label,g=S.color)}const f=S=>{if(!S)return"";if(typeof S=="string")return S;if(S instanceof File)return URL.createObjectURL(S);if(typeof S=="object"){if(typeof S.preview=="string")return S.preview;if(typeof S.src=="string")return S.src;if(S.src instanceof File)return URL.createObjectURL(S.src);if(S.file instanceof File)return URL.createObjectURL(S.file)}return""},w=(S,P)=>{s({src:S,alt:P}),l(!0)},N=(S="text-sm text-gray-900 dark:text-white break-words")=>u==="chip"?r.jsx(Kr,{label:m,variant:c,color:g,className:"mt-1"}):u==="tinyEditor"?r.jsx("p",{className:`${S} ${t.valueClass||""}`,dangerouslySetInnerHTML:{__html:m}}):u==="video"?m?r.jsx("video",{controls:!0,src:m instanceof File?URL.createObjectURL(m):m,onClick:P=>P.stopPropagation(),className:"shadow-sm mt-1 w-full max-w-xs max-h-[250px] rounded-md "},m instanceof File?URL.createObjectURL(m):m):r.jsx("p",{className:"text-sm text-gray-400",children:"N/A"}):u==="audio"?m?r.jsx("audio",{controls:!0,src:m instanceof File?URL.createObjectURL(m):m,onClick:P=>P.stopPropagation(),className:"shadow-sm rounded-full mt-1 w-full max-w-xs"},m instanceof File?URL.createObjectURL(m):m):r.jsx("p",{className:"text-sm text-gray-400",children:"N/A"}):u==="multiImage"?Array.isArray(m)&&m.length>0?r.jsx("div",{className:`mt-1 grid grid-cols-3 sm:grid-cols-4 gap-2 ${t.mediaGridClass||""}`,children:m.map((P,T)=>{const I=f(P);return I?r.jsx("button",{type:"button",onClick:()=>w(I,`Gallery ${T+1}`),className:"w-full h-16 rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700 hover:border-primary/50 transition-colors",children:r.jsx("img",{src:I,alt:`gallery-${T+1}`,className:"w-full h-full object-cover"})},`${I}-${T}`):null})}):r.jsx("p",{className:"text-sm text-gray-400",children:"N/A"}):r.jsx("p",{className:`${S} ${t.valueClass||""}`,children:u==="date"?r.jsx("span",{children:er(m,a.format||"DD MMM YYYY")}):r.jsx("span",{children:m||"N/A"})});return e==="card"?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:v(x.details.row,a.blockClass||"col-span-6","group bg-white dark:bg-gray-800 rounded-xl border border-gray-100 dark:border-gray-700/60 shadow-sm hover:shadow-md hover:-translate-y-0.5 transition-all duration-200 p-4 flex flex-col gap-2.5",t.rowClass||""),children:[h&&r.jsx("div",{className:`w-8 h-8 rounded-lg bg-primary/10 dark:bg-primary/20 flex items-center justify-center text-primary flex-shrink-0 [&>svg]:w-4 [&>svg]:h-4 ${t.iconClass||""}`,children:h}),r.jsx("p",{className:`text-xs font-semibold uppercase tracking-wider text-gray-400 dark:text-gray-500 leading-none ${t.labelClass||""}`,children:d}),r.jsx("div",{className:"mt-auto",children:N("text-sm font-semibold text-gray-800 dark:text-gray-100 break-words leading-snug")})]}),i&&n&&r.jsx(xe,{src:n.src,alt:n.alt,isOpen:i,setIsOpen:l})]}):e==="split"?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:v(x.details.row,"flex items-stretch min-h-[52px]",t.rowClass||"",a.blockClass||""),children:[r.jsxs("div",{className:"w-[42%] flex-shrink-0 flex items-center gap-2 px-4 py-3 bg-gray-50 dark:bg-gray-800/80 border-r border-gray-200 dark:border-gray-700",children:[h&&r.jsx("span",{className:`text-primary/60 dark:text-primary/50 flex-shrink-0 [&>svg]:w-3.5 [&>svg]:h-3.5 ${t.iconClass||""}`,children:h}),r.jsx("p",{className:`text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400 leading-tight ${t.labelClass||""}`,children:d})]}),r.jsx("div",{className:"flex-1 flex items-center px-4 py-3 bg-white dark:bg-gray-900",children:N("text-sm text-gray-800 dark:text-gray-100 break-words")})]}),i&&n&&r.jsx(xe,{src:n.src,alt:n.alt,isOpen:i,setIsOpen:l})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:v(x.details.row,"col-span-12 flex items-center space-x-4 p-4 rounded-xl bg-gray-100 dark:bg-gray-900",t.rowClass||"",a.blockClass||""),children:[h&&r.jsx("div",{className:`flex-shrink-0 ${t.iconClass||""}`,children:h}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:`text-sm font-medium text-gray-500 dark:text-gray-400 ${t.labelClass||""}`,children:d}),N("mt-1 text-sm text-gray-900 dark:text-white break-words")]})]}),i&&n&&r.jsx(xe,{src:n.src,alt:n.alt,isOpen:i,setIsOpen:l})]})},It=({value:a=!0,onChange:o,text:e,options:t=[],label:n,required:s,name:i="",disabled:l=!1,parentClass:h="",errorMessage:d=""})=>{const m=t.length>0?t:[{label:"Active",value:!0},{label:"Inactive",value:!1}];return r.jsx(r.Fragment,{children:r.jsxs("div",{className:v(x.field.wrapper,h||"col-span-12"),children:[r.jsx(he,{label:n,required:s}),r.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
127
- ${d?"border-red-500":""}`,children:[e&&r.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}),r.jsx("div",{className:"flex items-center gap-6",children:m.map((u,c)=>r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[r.jsx("input",{type:"radio",name:"switch-field",required:s&&c===0,value:String(u.value),disabled:l,id:`field-${i}`,checked:a===u.value,onChange:()=>o==null?void 0:o(u.value),className:v(x.field.input,"w-4 h-4 border-gray-300 cursor-pointer")}),r.jsx("span",{className:"text-sm text-gray-700 dark:text-white",children:u.label})]},c))})]}),d&&r.jsx("span",{className:v(x.field.error,"text-red-500 text-xs mt-1"),children:d})]},i)})},Rr=ue,Ut=({label:a="",value:o=null,onChange:e,required:t=!1,accept:n="video/*",id:s,dragDrop:i=!1,name:l="",parentClass:h="",maxSize:d=0,errorMessage:m=""})=>{const[u,c]=b.useState(null),[g,f]=b.useState(!1),w=b.useRef(null),N=d*1024*1024;b.useEffect(()=>{if(!o){j(),c(null);return}if(o instanceof File){const y=URL.createObjectURL(o);return c({file:o,preview:y}),()=>{URL.revokeObjectURL(y)}}else typeof o=="string"?c({preview:o}):o!=null&&o.preview&&c(o)},[o]);const j=()=>{u!=null&&u.preview&&u.preview.startsWith("blob:")&&URL.revokeObjectURL(u.preview)},S=y=>{if(!y||y.length===0)return;const A=y[0];if(N&&A.size>N){ke.enqueueSnackbar(`File is too large. Maximum allowed size is ${d} MB`,{variant:"warning"});return}const M=URL.createObjectURL(A);j(),c({file:A,preview:M}),e==null||e(A)},P=y=>{y&&y.stopPropagation(),j(),c(null),e==null||e(null),w.current&&(w.current.value="")},T=y=>{i&&(y.preventDefault(),f(!0))},I=y=>{i&&(y.preventDefault(),f(!1))},L=y=>{var A,M,z,H;i&&(y.preventDefault(),f(!1),(H=(z=(M=(A=y.dataTransfer)==null?void 0:A.files)==null?void 0:M[0])==null?void 0:z.type)!=null&&H.includes("video/")&&S(y.dataTransfer.files))},U=()=>{var y;(y=w.current)==null||y.click()};return r.jsxs("div",{className:v(x.mediaPicker.video,x.field.wrapper,h||"col-span-12"),children:[r.jsx(he,{label:a,required:t}),r.jsxs("div",{className:v(x.mediaPicker.dropzone,"relative rounded-lg p-2 transition-all",g?"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",m?"border-red-500":""),onDragOver:T,onDragLeave:I,onDrop:L,id:`field-${l}`,children:[r.jsx("input",{ref:w,id:s,type:"file",accept:n,onChange:y=>S(y.target.files),required:t&&!u,className:"absolute opacity-0 pointer-events-none h-[10px]"}),r.jsx("div",{className:`flex items-center space-x-4 transition-all ${g?"opacity-50":""}`,children:u?r.jsxs("div",{className:"flex items-center space-x-4",children:[r.jsxs("div",{className:"relative",children:[!t&&r.jsx("button",{type:"button",onClick:P,className:"absolute -top-2 -right-2 bg-red-500 text-white rounded-full p-1 shadow hover:bg-red-600 z-10",children:r.jsx(me.Icon,{icon:"mdi:close",className:"w-3 h-3"})}),r.jsx("video",{src:u.preview,controls:!0,controlsList:"nodownload",className:"w-[260px] h-[150px] rounded-md object-cover"},u.preview)]}),r.jsx(Rr,{type:"button",onClick:U,children:"Change Video File"})]}):r.jsxs("div",{className:"flex items-center justify-center space-x-4",children:[r.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:r.jsx(me.Icon,{icon:"mdi:video",className:"text-gray-400 w-10 h-10"})}),r.jsxs("div",{className:"flex flex-col items-center space-y-1",children:[r.jsx(Rr,{type:"button",onClick:U,variant:"outlined",children:"Choose Video File"}),i&&r.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop your video here"})]})]})}),i&&g&&!u&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-lg",children:r.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"})})]}),m&&r.jsx("span",{className:v(x.field.error,"text-red-500 text-xs mt-1"),children:m})]},l)},Hr=({field:a,formData:o,handleChange:e,errorMessage:t})=>{const{key:n,label:s,type:i,options:l,placeholder:h,rows:d,inputClass:m,search:u,accept:c,text:g,required:f=!1,minLength:w,dragDrop:N,parentClass:j,countriesList:S,defaultCountry:P,multiple:T,dropdownMaxHeight:I,editorKey:L,fontFamily:U,disabled:y,negativeNumberAllow:A,defaultValue:M,renderCondition:z,pattern:H,renderType:V,cropImage:ee,aspectRatio:ae,dependencyKey:D,mask:C,maskApplyOnValue:F,maxSize:Y}=a;let $=o==null?void 0:o[n];$==null&&($="");const K=h||(i==="select"?`Select ${s}`:`Enter ${s}`),ce="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(z&&typeof z=="function"&&!z(o))return null;if(V&&V=="details")switch(i){case"group":return r.jsx(Gr,{col:a,data:o});case"cardGroup":return r.jsx(Yr,{col:a,data:o});default:return r.jsx(Wr,{col:a,data:o})}switch(i){case"select":return r.jsx(Qr,{options:l||[],value:$,formData:o,dependencyKey:D,onChange:E=>e(n,E),placeholder:K,className:m||"",search:u,required:f,defaultValue:M,label:s||"",name:n,countriesList:S,disabled:y,parentClass:j||"",multiple:T,dropdownMaxHeight:I,errorMessage:t});case"checkbox":return r.jsx(r.Fragment,{children:r.jsx(Et,{name:n,label:s||"",options:l||[],value:$,onChange:E=>e(n,E),required:f,parentClass:j||"",className:m||"",multiSelect:T,disabled:y,errorMessage:t})});case"radio":return r.jsx(It,{value:$,onChange:E=>e(n,E),text:g,options:l||[],label:s||"",required:f,name:n,disabled:y,parentClass:j||"",errorMessage:t});case"switch":return r.jsx(Dr,{value:!!$,onChange:E=>e(n,E),label:s||"",required:f,name:n,disabled:y,className:"",parentClass:j||"",errorMessage:t});case"phone":return r.jsx(et,{value:$,onChange:E=>e(n,E),countriesList:S,defaultCountry:P,required:f,placeholder:K,search:u,label:s||"",name:n,disabled:y,errorMessage:t,parentClass:j||""});case"textarea":return r.jsx(Pr,{value:$,onChange:E=>e(n,E.target.value),placeholder:K,rows:d||3,className:`${ce} ${m||""}`,required:f,name:n,label:s||"",disabled:y,parentClass:j||"",errorMessage:t});case"image":case"multiImage":return T||i==="multiImage"?r.jsx(zt,{value:Array.isArray($)?$:[],onChange:E=>e(n,E),required:f,accept:c||"image/*",aspect:ae,id:`file-${n}`,dragDrop:N,cropImage:ee,label:s||"",name:n,parentClass:j||"",maxImages:a.maxImages,errorMessage:t}):r.jsx(Pt,{value:$,onChange:E=>e(n,E),required:f,accept:c||"image/*",aspect:ae,id:`file-${n}`,dragDrop:N,cropImage:ee,label:s||"",name:n,parentClass:j||"",errorMessage:t});case"audio":return r.jsx(At,{value:$,onChange:E=>e(n,E),required:f,accept:c||"audio/*",id:`file-${n}`,dragDrop:N,label:s||"",name:n,parentClass:j||"",maxSize:Y,errorMessage:t});case"video":return r.jsx(Ut,{value:$,onChange:E=>e(n,E),required:f,accept:c||"video/*",id:`file-${n}`,dragDrop:N,label:s||"",name:n,maxSize:Y,parentClass:j||"",errorMessage:t});case"tinyEditor":return r.jsx(Lt,{value:$,name:n,onChange:E=>e(n,E),required:f,placeholder:K,label:s||"",parentClass:j||"",fontFamily:U,editorKey:L||"",disabled:y,errorMessage:t});default:return r.jsx(Br,{field:a,type:i||"text",defaultValue:M,value:$,onChange:E=>e(n,E),placeholder:K,className:`${ce} ${m||""}`,required:f,name:n,minLength:w,label:s||"",negativeNumberAllow:A,parentClass:j||"",disabled:y,pattern:H,mask:C,errorMessage:t,maskApplyOnValue:F})}},Ot=({isOpen:a,onClose:o,config:e,onApply:t})=>{var m;const[n,s]=b.useState({}),i=(u,c)=>{s(g=>({...g,[u]:c}))},l=()=>{t(n),o()},h=()=>{s({}),t({}),o()},d=e==null?void 0:e.component;return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:v(x.filterDrawer.overlay,"fixed inset-0 bg-black/50 z-40 transition-opacity duration-300",a?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none")}),r.jsxs("div",{className:v(x.filterDrawer.panel,"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 transform transition-transform duration-300 ease-in-out",a?"translate-x-0":"translate-x-full"),children:[r.jsxs("div",{className:v(x.filterDrawer.header,"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700"),children:[r.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Filters"}),r.jsx("button",{onClick:o,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md transition",children:r.jsx(te.X,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),a&&r.jsx("div",{className:v(x.filterDrawer.body,"flex-1 overflow-y-auto px-4 py-3"),children:d?r.jsx(d,{filters:n,onFilterChange:i}):r.jsx("div",{className:"space-y-4",children:(m=e==null?void 0:e.fields)==null?void 0:m.map(u=>r.jsx(Hr,{field:u,formData:n,handleChange:i},u.key))})}),r.jsxs("div",{className:v(x.filterDrawer.footer,"flex gap-2 px-4 py-3 border-t border-gray-200 dark:border-gray-700"),children:[r.jsx(ue,{onClick:l,variant:"contained",color:"primary",fullWidth:!0,children:"Apply Filters"}),r.jsx(ue,{onClick:h,variant:"contained",className:"min-w-[150px]",children:"Reset"})]})]})]})},Tt=({rows:a=5,columns:o=5})=>r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"w-full mb-6 inline-flex justify-end items-center",children:r.jsx("div",{className:"h-8 w-80 bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})}),r.jsx("div",{className:"overflow-hidden rounded-md border border-gray-200 dark:border-gray-800",children:r.jsxs("table",{className:v(x.tableSkeleton.root,x.tableSkeleton.table,"w-full border-collapse"),children:[r.jsx("thead",{children:r.jsx("tr",{className:"bg-gray-50 dark:bg-gray-900",children:Array.from({length:o}).map((e,t)=>r.jsx("th",{className:"px-4 py-3",children:r.jsx("div",{className:"h-6 w-24 bg-gray-300 dark:bg-gray-700 rounded animate-pulse inline-flex justify-center items-center"})},t))})}),r.jsx("tbody",{children:Array.from({length:a}).map((e,t)=>r.jsx("tr",{className:"border-t border-gray-200 dark:border-gray-800",children:Array.from({length:o}).map((n,s)=>r.jsx("td",{className:"px-4 py-6",children:r.jsx("div",{className:"h-6 w-full bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})},s))},t))})]})})]}),Bt=({options:a=[],value:o="",onChange:e,clearLabel:t=""})=>{const[n,s]=b.useState(!1),i=b.useRef(null),l=!!o;b.useEffect(()=>{const d=m=>{i.current&&!i.current.contains(m.target)&&s(!1)};return document.addEventListener("click",d),()=>document.removeEventListener("click",d)},[]);const h=d=>{const m=a.find(u=>u.value===d);e(d,m||null),s(!1)};return a!=null&&a.length?r.jsxs("div",{className:v(x.sortDropdown.root,"relative"),ref:i,children:[r.jsxs("button",{type:"button",onClick:()=>s(d=>!d),className:v(x.sortDropdown.trigger,"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:[r.jsx(te.ArrowUpDown,{className:"w-4 h-4"}),l&&r.jsx("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]}),n&&r.jsxs("div",{className:v(x.sortDropdown.menu,"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:[!!(t!=null&&t.trim())&&r.jsx("button",{type:"button",onClick:()=>h(""),className:v(x.sortDropdown.item,"w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700",o?"text-gray-700 dark:text-gray-200":"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-white"),children:t}),a.map(d=>r.jsx("button",{type:"button",onClick:()=>h(d.value),className:v(x.sortDropdown.item,"w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700",o===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},Qe={enabled:!1,useServerSideSorting:!1,options:[],fields:[],defaultValue:"",autoGenerate:!0,clearLabel:"",onChange:null},Gt=a=>a===!0?{...Qe,enabled:!0}:!a||typeof a!="object"?Qe:{...Qe,...a,enabled:a.enabled??!0,autoGenerate:a.autoGenerate??!0},Yt=(a=[])=>a.filter(o=>{const e=["menu_actions","index","audio","avatar"];return o.type&&e.includes(o.type)?!1:!!(o.sortKey||(o.type==="group"?o.titleKey:o.key))}),Kt=a=>{if(a.sortType)return a.sortType;if(a.type==="date")return"date";if(a.type==="number")return"number";const o=String(a.sortKey||(a.type==="group"?a.titleKey:a.key)||"").toLowerCase();return["phone","mobile","contact","tel","whatsapp"].some(t=>o.includes(t))?"phone":Array.isArray(a.chipOptions)&&a.chipOptions.length>0&&a.chipOptions.every(n=>typeof n.value=="boolean")?"boolean":"string"},Mr=(a=[])=>a.flatMap(o=>{const e=o.sortKey||(o.type==="group"?o.titleKey:o.key),t=o.sortLabel||o.title||e,n=Kt(o);return e?n==="number"?[{value:`${e}_asc`,label:`${t} (Low-High)`,key:e,order:"asc",type:n},{value:`${e}_desc`,label:`${t} (High-Low)`,key:e,order:"desc",type:n}]:n==="phone"?[{value:`${e}_asc`,label:`${t} (0-9)`,key:e,order:"asc",type:n},{value:`${e}_desc`,label:`${t} (9-0)`,key:e,order:"desc",type:n}]:n==="date"?[{value:`${e}_desc`,label:`${t} (Newest First)`,key:e,order:"desc",type:n},{value:`${e}_asc`,label:`${t} (Oldest First)`,key:e,order:"asc",type:n}]:n==="boolean"?[{value:`${e}_desc`,label:`${t} (True First)`,key:e,order:"desc",type:n},{value:`${e}_asc`,label:`${t} (False First)`,key:e,order:"asc",type:n}]:[{value:`${e}_asc`,label:`${t} (A-Z)`,key:e,order:"asc",type:n},{value:`${e}_desc`,label:`${t} (Z-A)`,key:e,order:"desc",type:n}]:[]}),Wt=(a,o=[])=>{if(Array.isArray(a.options)&&a.options.length>0)return a.options.map(n=>({...n,type:n.type||"string",order:n.order==="desc"?"desc":"asc"}));const t=Array.isArray(a.fields)?a.fields:[];if(t.length>0){const n=t.map(s=>{const i=typeof s=="string"?s:s.key,l=o.find(h=>h.key===i||h.sortKey===i||h.type==="group"&&h.titleKey===i);return l?{...l,sortKey:typeof s=="object"&&s.key?s.key:l.sortKey,sortType:typeof s=="object"&&s.type?s.type:l.sortType,sortLabel:typeof s=="object"&&s.label?s.label:l.sortLabel}:null}).filter(s=>s!==null);return Mr(n)}return a.autoGenerate?Mr(o):[]},Ht=(a=[],o="",e,t=[])=>{if(!(e!=null&&e.enabled)||!o||e!=null&&e.useServerSideSorting)return a;const n=t==null?void 0:t.find(d=>d.value===o);if(!(n!=null&&n.key))return a;const s=n.order==="desc"?"desc":"asc",i=n.key,l=n.type||"string",h=d=>String(d??"").replace(/[^\d]/g,"").trim();return[...a].sort((d,m)=>{const u=d==null?void 0:d[i],c=m==null?void 0:m[i];if(u==null&&c==null)return 0;if(u==null)return s==="asc"?1:-1;if(c==null)return s==="asc"?-1:1;let g=0;return l==="number"?g=Number(u)-Number(c):l==="phone"?g=h(u).localeCompare(h(c),void 0,{numeric:!0}):l==="date"?g=new Date(u).getTime()-new Date(c).getTime():l==="boolean"?g=+!!u-+!!c:g=String(u).localeCompare(String(c)),s==="asc"?g:-g})},Vt=({config:a,setShowAdd:o,title:e,buttonText:t,description:n,showAddButton:s})=>{var ur;const{data:i=[],table_head:l=[],loading:h=!1,search:d={enabled:!1,placeholder:"Search...",useServerSideSearch:!1},filter:m={enabled:!1,useServerSideFilters:!1},sort:u={enabled:!1},pagination:c={enabled:!1,rows_per_page:10,useServerSidePagination:!1},exportCSV:g={enabled:!1,fileName:"",fields:[]},emptyMessage:f="No data available",onMenuAction:w,setServerSidePaginationData:N=()=>{},onFilterApply:j,filterConfig:S=null,rowClick:P=null}=a,[T,I]=b.useState(""),[L,U]=b.useState(null),[y,A]=b.useState([]),[M,z]=b.useState({top:0,left:0}),[H,V]=b.useState(!1),[ee,ae]=b.useState({}),D=b.useMemo(()=>Gt(u),[u]),C=b.useMemo(()=>Yt(l),[l]),F=b.useMemo(()=>Wt(D,C),[D,C]),[Y,$]=b.useState((D==null?void 0:D.defaultValue)||""),[K,ce]=b.useState(null),[E,be]=b.useState(!1),we=b.useMemo(()=>!d.enabled||!T.trim()||d.useServerSideSearch?i:Jr(i,T,d.searchKeys||[]),[i,T,d]),_=b.useMemo(()=>Ht(we,Y,D,F),[we,Y,D,F]),[B,R]=b.useState(1),[O,q]=b.useState((c==null?void 0:c.rows_per_page)||50),[J,Z]=b.useState(we.length||0),oe=c!=null&&c.useServerSidePagination?c.total_pages:Math.ceil(we.length/O),$e=b.useMemo(()=>{if(c.useServerSidePagination)return _;const p=(B-1)*O;return _.slice(p,p+O)},[_,B,O,c.useServerSidePagination]),_e=b.useRef(null),Ce=b.useRef(null),De=b.useRef({}),Re=b.useRef(null),Pe=typeof document<"u"?((ur=Ce.current)==null?void 0:ur.closest(".racm-root"))||document.body:null,Ue=p=>{I(p),R(1),d.useServerSideSearch&&(Re.current&&clearTimeout(Re.current),Re.current=setTimeout(async()=>{try{await N(k=>({...k,search:p,current_page:1}))}catch(k){console.error("Search error:",k)}},800))},Oe=(p,k=null)=>{$(p),R(1);const W={value:p,option:k,key:(k==null?void 0:k.key)||"",order:(k==null?void 0:k.order)||"",type:(k==null?void 0:k.type)||""};typeof(D==null?void 0:D.onChange)=="function"&&D.onChange(W)},Te=(p,k,W)=>{W.stopPropagation(),U(null),w==null||w(p.type,k)},Be=(p,k,W)=>{k.stopPropagation(),A(W);const Q=k.currentTarget;De.current[p]=Q;const re=Q.getBoundingClientRect(),le=192,ge=W.length*40,de=window.innerWidth,fe=window.innerHeight,ye=de-re.right<le?re.left-le+re.width:re.left,Fe=fe-re.bottom<ge&&re.top>ge?re.top-ge-2:re.bottom+2;z({top:Math.max(8,Math.min(Fe,fe-ge-8)),left:Math.max(8,Math.min(ye,de-le-8))}),U(L===p?null:p)},Ge=p=>(B-1)*O+p+1,Le=p=>{let k=p;k&&k.src instanceof File&&(k={...k,src:URL.createObjectURL(k.src)}),ce(k),be(!0)},Ye=p=>{if(!p)return"";if(typeof p=="string")return p;if(p instanceof File)return URL.createObjectURL(p);if(typeof p=="object"){if(typeof p.preview=="string")return p.preview;if(typeof p.src=="string")return p.src;if(p.src instanceof File)return URL.createObjectURL(p.src);if(p.file instanceof File)return URL.createObjectURL(p.file)}return""},Ke=(p,k)=>{const W=Array.isArray(p)?p:[];if(W.length===0)return r.jsx("span",{className:k.className||"",children:"N/A"});const Q=k.maxPreview||3,re=W.slice(0,Q),le=W.length-re.length;return r.jsxs("div",{className:"flex items-center",children:[r.jsx("div",{className:"flex -space-x-2",children:re.map((ge,de)=>{const fe=Ye(ge);return fe?r.jsx("button",{type:"button",onClick:Ae=>{Ae.stopPropagation(),Le({src:fe,alt:`Gallery ${de+1}`})},className:"w-8 h-8 rounded-full border-2 border-white dark:border-gray-800 overflow-hidden",children:r.jsx("img",{src:fe,alt:`gallery-${de+1}`,className:"w-full h-full object-cover"})},`${fe}-${de}`):null})}),le>0&&r.jsxs("span",{className:"ml-2 text-xs font-medium text-gray-600 dark:text-gray-300",children:["+",le]})]})},Ee=(p,k,W,Q=null,re=null)=>r.jsx(r.Fragment,{children:p?r.jsx("img",{src:p instanceof File?URL.createObjectURL(p):p,alt:k||"Avatar",onClick:le=>{le.stopPropagation(),le.preventDefault(),Le({src:p,alt:k})},className:`w-10 h-10 cursor-pointer shrink-0 rounded-full object-cover border border-gray-200 dark:border-gray-700 ${W||""}`}):r.jsx(r.Fragment,{children:Q?typeof Q=="function"?Q(re):Q:r.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 ${W||""}`,children:r.jsx(te.User,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),We=(p,k)=>r.jsx(r.Fragment,{children:p?r.jsx("audio",{controls:!0,src:p instanceof File?URL.createObjectURL(p):p,onClick:W=>{W.stopPropagation()},className:`w-64 cursor-pointer ${k||""}`},p instanceof File?URL.createObjectURL(p):p):r.jsx(r.Fragment,{children:r.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 ${k||""}`,children:r.jsx(te.Music,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),G=(p,k)=>r.jsxs("div",{className:`flex items-center space-x-4 ${k.className||""}`,children:[k.imageKey?Ee(p[k.imageKey],p[k.titleKey],"group-avatar",k.fallback_icon,p):"",r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-gray-900 dark:text-white group-title",children:p[k.titleKey]||""}),r.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 group-sub-title",children:p[k.subtitleKey]||""})]})]}),X=(p,k)=>{var le;let W=String(p);const Q=k.variant||"contained";let re=k.defaultColor;if(((le=k==null?void 0:k.chipOptions)==null?void 0:le.length)>0){const ge=k==null?void 0:k.chipOptions.find(de=>de.value==p);ge&&(W=ge.label,re=ge.color)}return r.jsx(Kr,{label:W,variant:Q,color:re,className:k.className||""})},ne=(p,k,W)=>{const Q=k[p.key];return p.type==="menu_actions"?r.jsx("div",{className:`text-center ${p.className||""}`,children:r.jsx("button",{ref:re=>{De.current[k.id||k._id]=re},onClick:re=>Be(k.id||k._id,re,p.menuList),className:v(x.table.actionButton,"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:r.jsx(te.EllipsisVertical,{className:"h-4 w-4"})})}):p.type==="index"?r.jsx("span",{className:p.className||"",children:Ge(W)}):p.type==="group"?G(k,p):p.type==="chip"?r.jsx(r.Fragment,{children:X(Q,p)}):p.type==="date"?r.jsx("span",{className:p.className||"",children:er(Q,p.format||"DD MMM YYYY")}):p.type==="avatar"?r.jsx(r.Fragment,{children:r.jsx("div",{className:"min-w-[40px]",children:Ee(Q,p.alt,p.className,p.fallback_icon,k)})}):p.type==="audio"?r.jsx(r.Fragment,{children:We(Q,p.className)}):p.type==="multiImage"?r.jsx(r.Fragment,{children:Ke(Q,p)}):r.jsx("span",{className:p.className||"",children:Q||"N/A"})},je=p=>{if(typeof P=="function")return P(p);if(P)return w==null?void 0:w("view",p)},ie=(p,k)=>{if(p.onClickDetails)return w==null?void 0:w("view",k);if(typeof p.handleClick=="function")return p.handleClick(k)},pr=()=>P||typeof P=="function",mr=p=>p.onClickDetails||typeof p.handleClick=="function",Vr=()=>{var Ae;if(!(i!=null&&i.length)||!((Ae=g==null?void 0:g.fields)!=null&&Ae.length))return;const p=g.fields.map(ye=>ye.label),k=$e.map(ye=>g.fields.map(hr=>{const Fe=ye==null?void 0:ye[hr.key];return`"${Fe??""}"`})),W=[p.join(","),...k.map(ye=>ye.join(","))].join(`
128
- `),re=`export-${er(new Date,"YYYY-MM-DD_HH-mm-ss")}.csv`,le=g.fileName||re,ge=new Blob([W],{type:"text/csv;charset=utf-8;"}),de=document.createElement("a"),fe=URL.createObjectURL(ge);de.href=fe,de.download=le,document.body.appendChild(de),de.click(),document.body.removeChild(de),URL.revokeObjectURL(fe)};return b.useEffect(()=>{const p=()=>{L&&U(null)};return window.addEventListener("scroll",p,!0),()=>{window.removeEventListener("scroll",p,!0)}},[L]),b.useEffect(()=>{const p=k=>{_e.current&&!_e.current.contains(k.target)&&U(null)};return document.addEventListener("click",p),()=>document.removeEventListener("click",p)},[]),b.useEffect(()=>{c!=null&&c.rows_per_page&&(c!=null&&c.useServerSidePagination)&&q((c==null?void 0:c.rows_per_page)||50),c.current_page&&R(c.current_page)},[c.rows_per_page,c==null?void 0:c.useServerSidePagination,c.current_page]),b.useEffect(()=>{Z(c!=null&&c.useServerSidePagination?c.total_records:_.length),_.length<=O*(B-1)&&!(c!=null&&c.useServerSidePagination)&&R(p=>p-1||1)},[_.length,c.total_records,c==null?void 0:c.useServerSidePagination]),b.useEffect(()=>{if(!(D!=null&&D.enabled)){$("");return}if(F.some(k=>k.value===D.defaultValue)){$(D.defaultValue);return}$("")},[D,F]),b.useEffect(()=>{if(!(D!=null&&D.enabled)||!(D!=null&&D.useServerSideSorting))return;const p=F==null?void 0:F.find(k=>k.value===Y);N(k=>({...k,current_page:1,sort_by:(p==null?void 0:p.key)||"",sort_order:(p==null?void 0:p.order)||""}))},[Y,D==null?void 0:D.enabled,D==null?void 0:D.useServerSideSorting,F,N]),r.jsxs("div",{ref:Ce,children:[h?r.jsx(Tt,{rows:6,columns:6}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:v(x.table.toolbar,"flex flex-col lg:!flex-row lg:!justify-between gap-4 mb-3"),children:[r.jsxs("div",{className:"table-heading",children:[r.jsx("h1",{children:e}),r.jsx("p",{children:n})]}),r.jsxs("div",{className:"flex flex-col justify-end items-stretch lg:!items-end gap-2 w-full lg:!w-auto",children:[s&&r.jsxs(ue,{onClick:()=>o(!0),variant:"contained",color:"primary",children:[r.jsx(te.Plus,{className:"w-4 h-4 mr-2"}),t||"Add New"]}),r.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&&r.jsx("div",{className:"w-full sm:!w-auto",children:r.jsxs("div",{className:v(x.table.searchField,"table-search-field"),children:[r.jsx(te.Search,{className:"search-icon"}),r.jsx("input",{type:"text",placeholder:d.placeholder||"Search...",value:T,onChange:p=>Ue(p.target.value),className:x.table.searchInput})]})}),D!=null&&D.enabled&&(F==null?void 0:F.length)>0||S&&m.enabled||g&&g.enabled?r.jsxs("div",{className:"flex items-center justify-end gap-2 w-full sm:!w-auto",children:[S&&m.enabled&&r.jsxs("div",{className:"filter-button-wrapper",children:[r.jsxs(ue,{onClick:()=>V(!0),variant:"contained",className:"w-full sm:!w-auto",children:[r.jsx(te.Filter,{className:"w-4 h-4 mr-2"}),"Filters"]}),Object.keys(ee).length>0&&r.jsx("span",{className:"red-dot"})]}),g&&g.enabled&&r.jsx("div",{className:"filter-button-wrapper",children:r.jsxs(ue,{onClick:()=>Vr(),variant:"contained",className:"w-full sm:!w-auto",children:[r.jsx(te.Download,{className:"w-4 h-4 mr-2"}),"Export CSV"]})}),(D==null?void 0:D.enabled)&&(F==null?void 0:F.length)>0&&r.jsx(Bt,{options:F,value:Y,onChange:Oe,clearLabel:D==null?void 0:D.clearLabel})]}):null]})]})]}),r.jsxs("div",{className:v(x.table.root,x.table.container,"table-container"),children:[r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:x.table.element,children:[r.jsx("thead",{className:x.table.head,children:r.jsx("tr",{className:x.table.headRow,children:l.map(p=>r.jsx("th",{className:v(x.table.headCell,"table-head-data",p.headClass||""),children:p.title},p.key))})}),r.jsx("tbody",{className:x.table.body,children:$e.length===0?r.jsx("tr",{children:r.jsx("td",{colSpan:l.length,className:v(x.table.noData,"no-data-message"),children:f})}):$e.map((p,k)=>r.jsx("tr",{className:v(x.table.row,"table-row",pr()?"cursor-pointer":""),onClick:()=>{pr()&&je(p)},children:l.map(W=>r.jsx("td",{className:v(x.table.cell,"table-data",W.type=="audio"?"":"max-w-[300px]","truncate",mr(W)?"cursor-pointer":""),title:String(p[W.key]??""),onClick:Q=>{mr(W)&&(Q.stopPropagation(),Q.preventDefault(),ie(W,p))},children:W.render?W.render(p,k):ne(W,p,k)},W.key))},p.id||p._id||k))})]})}),(c==null?void 0:c.enabled)&&_.length>0&&r.jsxs("div",{className:v(x.table.pagination,"pagination-wrapper"),children:[r.jsxs("span",{children:["Showing ",(B-1)*O+1," to"," ",Math.min(B*O,J)," of"," ",J," results"]}),r.jsxs("div",{className:"flex items-center gap-4",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{children:"Rows per page:"}),r.jsx("select",{value:O,onChange:p=>{const k=Number(p.target.value);q(k),R(1),c.useServerSidePagination&&N(W=>({...W,current_page:1,rows_per_page:k}))},className:"rows-number-select",children:[10,25,50,100].map(p=>r.jsx("option",{value:p,children:p},p))})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:()=>{if(B>1){const p=B-1;R(p),c.useServerSidePagination&&N(k=>({...k,current_page:p}))}},disabled:B===1,className:"arrow-icons",children:r.jsx(te.ChevronLeft,{className:"h-4 w-4"})}),r.jsxs("span",{children:["Page ",B," of ",oe]}),r.jsx("button",{onClick:()=>{if(B<oe){const p=B+1;R(p),c.useServerSidePagination&&N(k=>({...k,current_page:p}))}},disabled:B===oe,className:"arrow-icons",children:r.jsx(te.ChevronRight,{className:"h-4 w-4"})})]})]})]})]})]}),L&&Pe&&dr.createPortal(r.jsx("div",{ref:_e,style:{position:"fixed",top:`${M.top}px`,left:`${M.left}px`,zIndex:9999},className:v(x.table.menu,"w-48 bg-white dark:bg-gray-700 rounded-md shadow-lg border border-gray-200 dark:border-gray-600"),children:y.map((p,k)=>r.jsxs("button",{onClick:W=>Te(p,i.find(Q=>Q.id===L||Q._id==L),W),className:v(x.table.menuItem,"w-full flex items-center gap-2 px-4 py-2 text-sm text-left hover:bg-gray-100 dark:hover:bg-gray-600",p.variant==="danger"?"text-red-600 dark:text-red-500":"text-gray-700 dark:text-gray-200"),children:[p.icon&&r.jsx("span",{className:"shrink-0",children:p.icon}),p.title]},k))}),Pe),S&&H&&r.jsx(Ot,{isOpen:H,onClose:()=>V(!1),config:S,onApply:p=>{ae(p),j==null||j(p)}}),E&&K&&r.jsx(xe,{src:K.src,alt:K.alt,isOpen:E,setIsOpen:be})]})},Ve=({isOpen:a,onClose:o,icon:e,title:t,children:n,size:s="md",actionButtons:i=[],onFormSubmit:l=()=>{},loadingBtn:h=!1,executeFunction:d=()=>{},selectedItem:m=null,footerConfig:u,classNames:c})=>{if(!a)return null;const g={sm:"max-w-md",md:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-full"},f=i.length>0||!!(u!=null&&u.cancelButton);return r.jsxs("div",{className:v(x.modal.root,"fixed inset-0 z-50 flex items-center justify-center p-4"),children:[r.jsx("div",{className:v(x.modal.overlay,"fixed inset-0 bg-gray-500 opacity-75",c==null?void 0:c.overlay)}),r.jsxs("div",{className:v(x.modal.container,"relative bg-white rounded-lg shadow-xl w-full max-h-[90vh] flex flex-col dark:bg-gray-800",g[s]||g.md,c==null?void 0:c.container),children:[r.jsxs("div",{className:v(x.modal.header,"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",c==null?void 0:c.header),children:[r.jsxs("div",{className:"flex items-center gap-1",children:[e&&r.jsx("span",{children:e}),r.jsx("h3",{className:v(x.modal.title,"text-lg font-medium text-gray-900 dark:text-white",c==null?void 0:c.title),children:t})]}),r.jsx("button",{onClick:()=>o(),className:v(x.modal.closeButton,"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",c==null?void 0:c.closeButton),children:r.jsx(te.X,{className:"w-6 h-6"})})]}),r.jsx("div",{className:v(x.modal.body,"flex-1 overflow-y-auto p-4",c==null?void 0:c.body),children:n}),f&&r.jsxs("div",{className:v(x.modal.footer,"px-4 py-3 flex justify-end gap-3 border-t border-gray-200 dark:border-gray-700 sm:!px-6",c==null?void 0:c.footer),children:[(u==null?void 0:u.cancelButton)&&r.jsx(ue,{onClick:()=>o(),variant:"outlined",color:"default",className:v(x.modal.actionButton,"min-w-[100px]"),type:"button",children:(u==null?void 0:u.cancelText)||"Cancel"}),i.map((w,N)=>r.jsx(ue,{onClick:j=>{w.type=="submit"?l(j):d(()=>{var S;return Promise.resolve((S=w==null?void 0:w.onClick)==null?void 0:S.call(w,j,m))},S=>o==null?void 0:o(S))},disabled:h||w.disabled,variant:w.variant||"contained",color:w.color||"primary",className:v(x.modal.actionButton,"min-w-[100px]",w.className||""),type:w.type||"button",children:h?r.jsxs("div",{className:v(x.modal.loadingIndicator,"flex items-center"),children:[r.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-2 border-t-white mr-2"}),w.label||"Submit","..."]}):w.label||"Submit"},`${w.label||"action"}-${N}`))]})]})]})},Cr=({config:a,onSubmit:o,initialData:e,fetchRowDetails:t,type:n})=>{const s=e||{},{formClass:i="grid grid-cols-12 gap-4",formFields:l=[]}=a||{},[h,d]=b.useState(s),[m,u]=b.useState(!0),[c,g]=b.useState({}),f=async()=>{t==null||t(s).then(j=>{d(j.data)}).catch(j=>{ke.enqueueSnackbar(j.message,{variant:"error"})}).finally(()=>{u(!1)})};b.useEffect(()=>{t instanceof Function?f():(d(s),u(!1))},[]);const w=(j,S)=>{d(P=>({...P,[j]:S})),g(P=>({...P,[j]:""}))},N=j=>{j.preventDefault();const S=j.currentTarget;if(!S.checkValidity()){S.reportValidity();return}const P={};let T=!1;for(const I of l){const L=h[I.key]||"";if(I.customValidation){const U=I.customValidation(L);if(U!==!1&&(P[I.key]=U,!T)){const y=S.querySelector(`[id="field-${I.key}"]`);y==null||y.focus(),T=!0}}}g(P),!(Object.keys(P).length>0)&&o(h)};return m?r.jsx("div",{className:v(x.form.loading,"flex items-center justify-center h-64"),children:r.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"}})}):r.jsx("form",{id:n==="add"?"addForm":n==="edit"?"editForm":"defaultForm",onSubmit:N,className:v(x.form.root,i),noValidate:!1,children:l.map(j=>r.jsx(Hr,{field:j,formData:h,errorMessage:c[j.key]||"",handleChange:w},j.key))})};function Zt({data:a,config:o,fetchRowDetails:e}){const{fields:t=[],containerClass:n,variant:s="default",styles:i={}}=o||{},l=a||{},[h,d]=b.useState(l),[m,u]=b.useState(!0),c=async()=>{e==null||e(l).then(f=>{d(f.data)}).catch(f=>{ke.enqueueSnackbar(f.message,{variant:"error"})}).finally(()=>{u(!1)})};if(b.useEffect(()=>{e instanceof Function?c():(d(l),u(!1))},[]),m)return r.jsx("div",{className:v(x.form.loading,"flex items-center justify-center h-64"),children:r.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"}})});const g={default:"grid grid-cols-12 gap-4",card:"grid grid-cols-12 gap-3",split:"rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden divide-y divide-gray-100 dark:divide-gray-800"};return r.jsx(r.Fragment,{children:r.jsx("div",{className:v(x.details.root,x.details.container,g[s]||g.default,n||"",i.containerClass||""),children:t.map(f=>f.renderCondition&&typeof f.renderCondition=="function"&&!f.renderCondition(h)?null:f.type=="group"?r.jsx(Gr,{col:f,data:h,uiVariant:s,styleConfig:i},f.key||f.titleKey):f.type=="cardGroup"?r.jsx(Yr,{col:f,data:h,uiVariant:s,styleConfig:i},f.key||f.titleKey):r.jsx(Wr,{col:f,data:h,uiVariant:s,styleConfig:i},f.key||f.label))})})}const Xt=({config:a})=>{var R,O,q,J,Z,oe,$e,_e,Ce,De,Re,Pe,Ue,Oe,Te,Be,Ge,Le,Ye,Ke,Ee,We;const{title:o,fetchData:e,fetchRowDetails:t,isStaticData:n=!1,tableConfig:s,modalConfig:i,filterConfig:l}=a,[h,d]=b.useState(!0),[m,u]=b.useState(!1),[c,g]=b.useState([]),[f,w]=b.useState(null),[N,j]=b.useState({search:"",rows_per_page:50,current_page:1,sort_by:"",sort_order:""}),[S,P]=b.useState({}),[T,I]=b.useState(!1),[L,U]=b.useState(!1),[y,A]=b.useState(!1),[M,z]=b.useState(!1),[H,V]=b.useState(!1),[ee,ae]=b.useState(null),D=(G,X)=>{G==="edit"?(ae(X),A(!0)):G==="view"?(ae(X),V(!0)):G==="delete"&&(ae(X),z(!0))},C=async(G,X,ne="",je="")=>{u(!0);try{if(!G)return;const ie=await G();(ne||ie!=null&&ie.message)&&ke.enqueueSnackbar(ne||ie.message||"Success",{variant:"success"}),X==null||X(ie)}catch(ie){(je||ie!=null&&ie.message)&&ke.enqueueSnackbar(je||ie.message||"Error occurred",{variant:"error"})}finally{u(!1)}},F=G=>{const X=G.newObject;n?(g(ne=>[X,...ne]),w(ne=>({...ne,current_page:1}))):(j(ne=>({...ne,current_page:1})),N.current_page===1&&E()),U(!1)},Y=G=>{const{newObject:X,targetObject:ne}=G;n?g(je=>je.map(ie=>ie.id===ne.id?{...ie,...X}:ie)):E(),A(!1)},$=G=>{if(!G){z(!1),ae(null);return}n?g(X=>X.filter(ne=>ne.id!==G.targetObject.id)):c.length===1&&N.current_page>1?j(X=>({...X,current_page:X.current_page-1})):E(),z(!1),ae(null)},K=G=>C(()=>{var X;return(X=i==null?void 0:i.addModal)!=null&&X.handleSubmit?i.addModal.handleSubmit(G):Promise.resolve({newObject:null})},F),ce=G=>C(()=>{var X;return(X=i==null?void 0:i.editModal)!=null&&X.handleSubmit?i.editModal.handleSubmit(G,ee):Promise.resolve({newObject:null,targetObject:null})},Y),E=async()=>{d(!0);try{const G=await e({...N,...S});g(G.data||[]),w(G.pagination||null)}catch(G){ke.enqueueSnackbar(G.message||"Failed to fetch data",{variant:"error"})}finally{d(!1)}},be=G=>{var X;P(ne=>({...G})),(X=s==null?void 0:s.filter)!=null&&X.useServerSideFilters&&I(ne=>!ne)},we=(G,X)=>G.filter(ne=>Object.entries(X).every(([je,ie])=>ne[je]===ie)),_=b.useMemo(()=>{var G;return(G=s==null?void 0:s.filter)!=null&&G.useServerSideFilters?c:we(c,S)},[c,S,(R=s==null?void 0:s.filter)==null?void 0:R.useServerSideFilters]),B=(O=i==null?void 0:i.viewModal)==null?void 0:O.component;return b.useEffect(()=>{E()},[N.search,N.rows_per_page,N.current_page,N.sort_by,N.sort_order,T]),r.jsxs("div",{className:x.crudPage.root,children:[r.jsx(Vt,{title:o,setShowAdd:U,description:a.description,buttonText:a.buttonText,showAddButton:!!(i!=null&&i.addModal),config:{...s,pagination:{...s.pagination,...f},data:_,setServerSidePaginationData:j,onMenuAction:D,filterConfig:l,onFilterApply:be,loading:h}}),L&&r.jsx(Ve,{isOpen:L,onClose:()=>{m||U(!1)},icon:(q=i==null?void 0:i.addModal)==null?void 0:q.icon,title:((J=i==null?void 0:i.addModal)==null?void 0:J.title)||"Add New",size:((Z=i==null?void 0:i.addModal)==null?void 0:Z.size)||"md",onFormSubmit:()=>{var G;return(G=document.querySelector("#addForm"))==null?void 0:G.requestSubmit()},loadingBtn:m,actionButtons:((oe=i==null?void 0:i.addModal)==null?void 0:oe.actionButtons)||[],children:r.jsx(Cr,{config:(i==null?void 0:i.addModal)||{},onSubmit:K,initialData:{},type:"add",loading:m})}),y&&r.jsx(Ve,{isOpen:y,onClose:()=>{m||A(!1)},icon:($e=i==null?void 0:i.editModal)==null?void 0:$e.icon,title:((_e=i==null?void 0:i.editModal)==null?void 0:_e.title)||"Edit",size:((Ce=i==null?void 0:i.editModal)==null?void 0:Ce.size)||"md",onFormSubmit:()=>{var G;return(G=document.querySelector("#editForm"))==null?void 0:G.requestSubmit()},actionButtons:((De=i==null?void 0:i.editModal)==null?void 0:De.actionButtons)||[],loadingBtn:m,children:r.jsx(Cr,{config:(i==null?void 0:i.editModal)||{},onSubmit:ce,initialData:ee,type:"edit",loading:m,fetchRowDetails:t})}),M&&r.jsx(Ve,{isOpen:M,onClose:G=>{$(G)},icon:((Re=i==null?void 0:i.deleteModal)==null?void 0:Re.icon)||r.jsx(me.Icon,{icon:"ph:warning-bold",className:"w-6 h-6 text-red-500"}),title:((Pe=i==null?void 0:i.deleteModal)==null?void 0:Pe.title)||"Confirm Delete",size:((Ue=i==null?void 0:i.deleteModal)==null?void 0:Ue.size)||"md",loading:m,actionButtons:((Oe=i==null?void 0:i.deleteModal)==null?void 0:Oe.actionButtons)||[],executeFunction:C,selectedItem:ee,children:r.jsx("div",{className:v(x.crudPage.deleteContent,"flex items-center space-x-2 py-3"),children:r.jsxs("div",{children:[r.jsx("p",{className:"text-md text-gray-700 dark:text-white",children:((Te=i==null?void 0:i.deleteModal)==null?void 0:Te.confirmText)||"Are you sure you want to delete this item?"}),((Be=i==null?void 0:i.deleteModal)==null?void 0:Be.referenceKey)&&r.jsx("p",{className:"text-md font-semibold text-gray-700 dark:text-white",children:ee==null?void 0:ee[(Ge=i==null?void 0:i.deleteModal)==null?void 0:Ge.referenceKey]})]})})}),(i==null?void 0:i.viewModal)&&r.jsx(Ve,{isOpen:H,onClose:()=>{V(!1),ae(null)},icon:(Le=i==null?void 0:i.viewModal)==null?void 0:Le.icon,title:((Ye=i==null?void 0:i.viewModal)==null?void 0:Ye.title)||"View Details",size:((Ke=i==null?void 0:i.viewModal)==null?void 0:Ke.size)||"lg",footerConfig:(Ee=i==null?void 0:i.viewModal)==null?void 0:Ee.footer,classNames:(We=i==null?void 0:i.viewModal)==null?void 0:We.modalClassNames,children:B?r.jsx(B,{data:ee}):r.jsx(Zt,{data:ee,fetchRowDetails:t,config:(i==null?void 0:i.viewModal)||{}})})]})};function qt({children:a}){return ke.useSnackbar(),a}function Jt({children:a}){try{return r.jsx(qt,{children:a})}catch{return r.jsx(ke.SnackbarProvider,{anchorOrigin:{vertical:"bottom",horizontal:"right"},action:e=>r.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:r.jsx(te.X,{className:"h-4 w-4"})}),maxSnack:3,autoHideDuration:3e3,children:a})}}const Qt=()=>{if(typeof document>"u"||document.getElementById("react-admin-crud-manager-styles"))return;const a=document.createElement("style");a.id="react-admin-crud-manager-styles",a.textContent=qr,document.head.appendChild(a)};function ea({config:a}){return b.useEffect(()=>{Qt()},[]),r.jsx("div",{className:"racm-root",children:r.jsx(Jt,{children:r.jsx(Xt,{config:a})})})}module.exports=ea;
127
+ ${d?"border-red-500":""}`,children:[e&&r.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}),r.jsx("div",{className:"flex items-center gap-6",children:m.map((u,c)=>r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[r.jsx("input",{type:"radio",name:"switch-field",required:s&&c===0,value:String(u.value),disabled:l,id:`field-${i}`,checked:a===u.value,onChange:()=>o==null?void 0:o(u.value),className:v(x.field.input,"w-4 h-4 border-gray-300 cursor-pointer")}),r.jsx("span",{className:"text-sm text-gray-700 dark:text-white",children:u.label})]},c))})]}),d&&r.jsx("span",{className:v(x.field.error,"text-red-500 text-xs mt-1"),children:d})]},i)})},Rr=ue,Ut=({label:a="",value:o=null,onChange:e,required:t=!1,accept:n="video/*",id:s,dragDrop:i=!1,name:l="",parentClass:h="",maxSize:d=0,errorMessage:m=""})=>{const[u,c]=b.useState(null),[g,f]=b.useState(!1),w=b.useRef(null),N=d*1024*1024;b.useEffect(()=>{if(!o){j(),c(null);return}if(o instanceof File){const y=URL.createObjectURL(o);return c({file:o,preview:y}),()=>{URL.revokeObjectURL(y)}}else typeof o=="string"?c({preview:o}):o!=null&&o.preview&&c(o)},[o]);const j=()=>{u!=null&&u.preview&&u.preview.startsWith("blob:")&&URL.revokeObjectURL(u.preview)},S=y=>{if(!y||y.length===0)return;const A=y[0];if(N&&A.size>N){ke.enqueueSnackbar(`File is too large. Maximum allowed size is ${d} MB`,{variant:"warning"});return}const M=URL.createObjectURL(A);j(),c({file:A,preview:M}),e==null||e(A)},P=y=>{y&&y.stopPropagation(),j(),c(null),e==null||e(null),w.current&&(w.current.value="")},T=y=>{i&&(y.preventDefault(),f(!0))},I=y=>{i&&(y.preventDefault(),f(!1))},L=y=>{var A,M,z,H;i&&(y.preventDefault(),f(!1),(H=(z=(M=(A=y.dataTransfer)==null?void 0:A.files)==null?void 0:M[0])==null?void 0:z.type)!=null&&H.includes("video/")&&S(y.dataTransfer.files))},U=()=>{var y;(y=w.current)==null||y.click()};return r.jsxs("div",{className:v(x.mediaPicker.video,x.field.wrapper,h||"col-span-12"),children:[r.jsx(he,{label:a,required:t}),r.jsxs("div",{className:v(x.mediaPicker.dropzone,"relative rounded-lg p-2 transition-all",g?"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",m?"border-red-500":""),onDragOver:T,onDragLeave:I,onDrop:L,id:`field-${l}`,children:[r.jsx("input",{ref:w,id:s,type:"file",accept:n,onChange:y=>S(y.target.files),required:t&&!u,className:"absolute opacity-0 pointer-events-none h-[10px]"}),r.jsx("div",{className:`flex items-center space-x-4 transition-all ${g?"opacity-50":""}`,children:u?r.jsxs("div",{className:"flex items-center space-x-4",children:[r.jsxs("div",{className:"relative",children:[!t&&r.jsx("button",{type:"button",onClick:P,className:"absolute -top-2 -right-2 bg-red-500 text-white rounded-full p-1 shadow hover:bg-red-600 z-10",children:r.jsx(me.Icon,{icon:"mdi:close",className:"w-3 h-3"})}),r.jsx("video",{src:u.preview,controls:!0,controlsList:"nodownload",className:"w-[260px] h-[150px] rounded-md object-cover"},u.preview)]}),r.jsx(Rr,{type:"button",onClick:U,children:"Change Video File"})]}):r.jsxs("div",{className:"flex items-center justify-center space-x-4",children:[r.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:r.jsx(me.Icon,{icon:"mdi:video",className:"text-gray-400 w-10 h-10"})}),r.jsxs("div",{className:"flex flex-col items-center space-y-1",children:[r.jsx(Rr,{type:"button",onClick:U,variant:"outlined",children:"Choose Video File"}),i&&r.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop your video here"})]})]})}),i&&g&&!u&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-lg",children:r.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"})})]}),m&&r.jsx("span",{className:v(x.field.error,"text-red-500 text-xs mt-1"),children:m})]},l)},Hr=({field:a,formData:o,handleChange:e,errorMessage:t})=>{const{key:n,label:s,type:i,options:l,placeholder:h,rows:d,inputClass:m,search:u,accept:c,text:g,required:f=!1,minLength:w,dragDrop:N,parentClass:j,countriesList:S,defaultCountry:P,multiple:T,dropdownMaxHeight:I,editorKey:L,fontFamily:U,disabled:y,negativeNumberAllow:A,defaultValue:M,renderCondition:z,pattern:H,renderType:V,cropImage:ee,aspectRatio:ae,dependencyKey:D,mask:C,maskApplyOnValue:F,maxSize:Y}=a;let $=o==null?void 0:o[n];$==null&&($="");const K=h||(i==="select"?`Select ${s}`:`Enter ${s}`),ce="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(z&&typeof z=="function"&&!z(o))return null;if(V&&V=="details")switch(i){case"group":return r.jsx(Gr,{col:a,data:o});case"cardGroup":return r.jsx(Yr,{col:a,data:o});default:return r.jsx(Wr,{col:a,data:o})}switch(i){case"select":return r.jsx(Qr,{options:l||[],value:$,formData:o,dependencyKey:D,onChange:E=>e(n,E),placeholder:K,className:m||"",search:u,required:f,defaultValue:M,label:s||"",name:n,countriesList:S,disabled:y,parentClass:j||"",multiple:T,dropdownMaxHeight:I,errorMessage:t});case"checkbox":return r.jsx(r.Fragment,{children:r.jsx(Et,{name:n,label:s||"",options:l||[],value:$,onChange:E=>e(n,E),required:f,parentClass:j||"",className:m||"",multiSelect:T,disabled:y,errorMessage:t})});case"radio":return r.jsx(It,{value:$,onChange:E=>e(n,E),text:g,options:l||[],label:s||"",required:f,name:n,disabled:y,parentClass:j||"",errorMessage:t});case"switch":return r.jsx(Dr,{value:!!$,onChange:E=>e(n,E),label:s||"",required:f,name:n,disabled:y,className:"",parentClass:j||"",errorMessage:t});case"phone":return r.jsx(et,{value:$,onChange:E=>e(n,E),countriesList:S,defaultCountry:P,required:f,placeholder:K,search:u,label:s||"",name:n,disabled:y,errorMessage:t,parentClass:j||""});case"textarea":return r.jsx(Pr,{value:$,onChange:E=>e(n,E.target.value),placeholder:K,rows:d||3,className:`${ce} ${m||""}`,required:f,name:n,label:s||"",disabled:y,parentClass:j||"",errorMessage:t});case"image":case"multiImage":return T||i==="multiImage"?r.jsx(zt,{value:Array.isArray($)?$:[],onChange:E=>e(n,E),required:f,accept:c||"image/*",aspect:ae,id:`file-${n}`,dragDrop:N,cropImage:ee,label:s||"",name:n,parentClass:j||"",maxImages:a.maxImages,errorMessage:t}):r.jsx(Pt,{value:$,onChange:E=>e(n,E),required:f,accept:c||"image/*",aspect:ae,id:`file-${n}`,dragDrop:N,cropImage:ee,label:s||"",name:n,parentClass:j||"",errorMessage:t});case"audio":return r.jsx(At,{value:$,onChange:E=>e(n,E),required:f,accept:c||"audio/*",id:`file-${n}`,dragDrop:N,label:s||"",name:n,parentClass:j||"",maxSize:Y,errorMessage:t});case"video":return r.jsx(Ut,{value:$,onChange:E=>e(n,E),required:f,accept:c||"video/*",id:`file-${n}`,dragDrop:N,label:s||"",name:n,maxSize:Y,parentClass:j||"",errorMessage:t});case"tinyEditor":return r.jsx(Lt,{value:$,name:n,onChange:E=>e(n,E),required:f,placeholder:K,label:s||"",parentClass:j||"",fontFamily:U,editorKey:L||"",disabled:y,errorMessage:t});default:return r.jsx(Br,{field:a,type:i||"text",defaultValue:M,value:$,onChange:E=>e(n,E),placeholder:K,className:`${ce} ${m||""}`,required:f,name:n,minLength:w,label:s||"",negativeNumberAllow:A,parentClass:j||"",disabled:y,pattern:H,mask:C,errorMessage:t,maskApplyOnValue:F})}},Ot=({isOpen:a,onClose:o,config:e,onApply:t})=>{var m;const[n,s]=b.useState({}),i=(u,c)=>{s(g=>({...g,[u]:c}))},l=()=>{t(n),o()},h=()=>{s({}),t({}),o()},d=e==null?void 0:e.component;return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:v(x.filterDrawer.overlay,"fixed inset-0 bg-black/50 z-40 transition-opacity duration-300",a?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none"),onClick:o}),r.jsxs("div",{className:v(x.filterDrawer.panel,"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 transform transition-all duration-300 ease-in-out",a?"opacity-100 translate-x-0":"opacity-0 translate-x-full"),children:[r.jsxs("div",{className:v(x.filterDrawer.header,"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700"),children:[r.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Filters"}),r.jsx("button",{onClick:o,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md transition",children:r.jsx(te.X,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),a&&r.jsx("div",{className:v(x.filterDrawer.body,"flex-1 overflow-y-auto px-4 py-3"),children:d?r.jsx(d,{filters:n,onFilterChange:i}):r.jsx("div",{className:"space-y-4",children:(m=e==null?void 0:e.fields)==null?void 0:m.map(u=>r.jsx(Hr,{field:u,formData:n,handleChange:i},u.key))})}),r.jsxs("div",{className:v(x.filterDrawer.footer,"flex gap-2 px-4 py-3 border-t border-gray-200 dark:border-gray-700"),children:[r.jsx(ue,{onClick:l,variant:"contained",color:"primary",fullWidth:!0,children:"Apply Filters"}),r.jsx(ue,{onClick:h,variant:"contained",className:"min-w-[150px]",children:"Reset"})]})]})]})},Tt=({rows:a=5,columns:o=5})=>r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"w-full mb-6 inline-flex justify-end items-center",children:r.jsx("div",{className:"h-8 w-80 bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})}),r.jsx("div",{className:"overflow-hidden rounded-md border border-gray-200 dark:border-gray-800",children:r.jsxs("table",{className:v(x.tableSkeleton.root,x.tableSkeleton.table,"w-full border-collapse"),children:[r.jsx("thead",{children:r.jsx("tr",{className:"bg-gray-50 dark:bg-gray-900",children:Array.from({length:o}).map((e,t)=>r.jsx("th",{className:"px-4 py-3",children:r.jsx("div",{className:"h-6 w-24 bg-gray-300 dark:bg-gray-700 rounded animate-pulse inline-flex justify-center items-center"})},t))})}),r.jsx("tbody",{children:Array.from({length:a}).map((e,t)=>r.jsx("tr",{className:"border-t border-gray-200 dark:border-gray-800",children:Array.from({length:o}).map((n,s)=>r.jsx("td",{className:"px-4 py-6",children:r.jsx("div",{className:"h-6 w-full bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})},s))},t))})]})})]}),Bt=({options:a=[],value:o="",onChange:e,clearLabel:t=""})=>{const[n,s]=b.useState(!1),i=b.useRef(null),l=!!o;b.useEffect(()=>{const d=m=>{i.current&&!i.current.contains(m.target)&&s(!1)};return document.addEventListener("click",d),()=>document.removeEventListener("click",d)},[]);const h=d=>{const m=a.find(u=>u.value===d);e(d,m||null),s(!1)};return a!=null&&a.length?r.jsxs("div",{className:v(x.sortDropdown.root,"relative"),ref:i,children:[r.jsxs("button",{type:"button",onClick:()=>s(d=>!d),className:v(x.sortDropdown.trigger,"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:[r.jsx(te.ArrowUpDown,{className:"w-4 h-4"}),l&&r.jsx("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]}),n&&r.jsxs("div",{className:v(x.sortDropdown.menu,"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:[!!(t!=null&&t.trim())&&r.jsx("button",{type:"button",onClick:()=>h(""),className:v(x.sortDropdown.item,"w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700",o?"text-gray-700 dark:text-gray-200":"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-white"),children:t}),a.map(d=>r.jsx("button",{type:"button",onClick:()=>h(d.value),className:v(x.sortDropdown.item,"w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700",o===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},Qe={enabled:!1,useServerSideSorting:!1,options:[],fields:[],defaultValue:"",autoGenerate:!0,clearLabel:"",onChange:null},Gt=a=>a===!0?{...Qe,enabled:!0}:!a||typeof a!="object"?Qe:{...Qe,...a,enabled:a.enabled??!0,autoGenerate:a.autoGenerate??!0},Yt=(a=[])=>a.filter(o=>{const e=["menu_actions","index","audio","avatar"];return o.type&&e.includes(o.type)?!1:!!(o.sortKey||(o.type==="group"?o.titleKey:o.key))}),Kt=a=>{if(a.sortType)return a.sortType;if(a.type==="date")return"date";if(a.type==="number")return"number";const o=String(a.sortKey||(a.type==="group"?a.titleKey:a.key)||"").toLowerCase();return["phone","mobile","contact","tel","whatsapp"].some(t=>o.includes(t))?"phone":Array.isArray(a.chipOptions)&&a.chipOptions.length>0&&a.chipOptions.every(n=>typeof n.value=="boolean")?"boolean":"string"},Mr=(a=[])=>a.flatMap(o=>{const e=o.sortKey||(o.type==="group"?o.titleKey:o.key),t=o.sortLabel||o.title||e,n=Kt(o);return e?n==="number"?[{value:`${e}_asc`,label:`${t} (Low-High)`,key:e,order:"asc",type:n},{value:`${e}_desc`,label:`${t} (High-Low)`,key:e,order:"desc",type:n}]:n==="phone"?[{value:`${e}_asc`,label:`${t} (0-9)`,key:e,order:"asc",type:n},{value:`${e}_desc`,label:`${t} (9-0)`,key:e,order:"desc",type:n}]:n==="date"?[{value:`${e}_desc`,label:`${t} (Newest First)`,key:e,order:"desc",type:n},{value:`${e}_asc`,label:`${t} (Oldest First)`,key:e,order:"asc",type:n}]:n==="boolean"?[{value:`${e}_desc`,label:`${t} (True First)`,key:e,order:"desc",type:n},{value:`${e}_asc`,label:`${t} (False First)`,key:e,order:"asc",type:n}]:[{value:`${e}_asc`,label:`${t} (A-Z)`,key:e,order:"asc",type:n},{value:`${e}_desc`,label:`${t} (Z-A)`,key:e,order:"desc",type:n}]:[]}),Wt=(a,o=[])=>{if(Array.isArray(a.options)&&a.options.length>0)return a.options.map(n=>({...n,type:n.type||"string",order:n.order==="desc"?"desc":"asc"}));const t=Array.isArray(a.fields)?a.fields:[];if(t.length>0){const n=t.map(s=>{const i=typeof s=="string"?s:s.key,l=o.find(h=>h.key===i||h.sortKey===i||h.type==="group"&&h.titleKey===i);return l?{...l,sortKey:typeof s=="object"&&s.key?s.key:l.sortKey,sortType:typeof s=="object"&&s.type?s.type:l.sortType,sortLabel:typeof s=="object"&&s.label?s.label:l.sortLabel}:null}).filter(s=>s!==null);return Mr(n)}return a.autoGenerate?Mr(o):[]},Ht=(a=[],o="",e,t=[])=>{if(!(e!=null&&e.enabled)||!o||e!=null&&e.useServerSideSorting)return a;const n=t==null?void 0:t.find(d=>d.value===o);if(!(n!=null&&n.key))return a;const s=n.order==="desc"?"desc":"asc",i=n.key,l=n.type||"string",h=d=>String(d??"").replace(/[^\d]/g,"").trim();return[...a].sort((d,m)=>{const u=d==null?void 0:d[i],c=m==null?void 0:m[i];if(u==null&&c==null)return 0;if(u==null)return s==="asc"?1:-1;if(c==null)return s==="asc"?-1:1;let g=0;return l==="number"?g=Number(u)-Number(c):l==="phone"?g=h(u).localeCompare(h(c),void 0,{numeric:!0}):l==="date"?g=new Date(u).getTime()-new Date(c).getTime():l==="boolean"?g=+!!u-+!!c:g=String(u).localeCompare(String(c)),s==="asc"?g:-g})},Vt=({config:a,setShowAdd:o,title:e,buttonText:t,description:n,showAddButton:s})=>{var ur;const{data:i=[],table_head:l=[],loading:h=!1,search:d={enabled:!1,placeholder:"Search...",useServerSideSearch:!1},filter:m={enabled:!1,useServerSideFilters:!1},sort:u={enabled:!1},pagination:c={enabled:!1,rows_per_page:10,useServerSidePagination:!1},exportCSV:g={enabled:!1,fileName:"",fields:[]},emptyMessage:f="No data available",onMenuAction:w,setServerSidePaginationData:N=()=>{},onFilterApply:j,filterConfig:S=null,rowClick:P=null}=a,[T,I]=b.useState(""),[L,U]=b.useState(null),[y,A]=b.useState([]),[M,z]=b.useState({top:0,left:0}),[H,V]=b.useState(!1),[ee,ae]=b.useState({}),D=b.useMemo(()=>Gt(u),[u]),C=b.useMemo(()=>Yt(l),[l]),F=b.useMemo(()=>Wt(D,C),[D,C]),[Y,$]=b.useState((D==null?void 0:D.defaultValue)||""),[K,ce]=b.useState(null),[E,be]=b.useState(!1),we=b.useMemo(()=>!d.enabled||!T.trim()||d.useServerSideSearch?i:Jr(i,T,d.searchKeys||[]),[i,T,d]),_=b.useMemo(()=>Ht(we,Y,D,F),[we,Y,D,F]),[B,R]=b.useState(1),[O,q]=b.useState((c==null?void 0:c.rows_per_page)||50),[J,Z]=b.useState(we.length||0),oe=c!=null&&c.useServerSidePagination?c.total_pages:Math.ceil(we.length/O),$e=b.useMemo(()=>{if(c.useServerSidePagination)return _;const p=(B-1)*O;return _.slice(p,p+O)},[_,B,O,c.useServerSidePagination]),_e=b.useRef(null),Ce=b.useRef(null),De=b.useRef({}),Re=b.useRef(null),Pe=typeof document<"u"?((ur=Ce.current)==null?void 0:ur.closest(".racm-root"))||document.body:null,Ue=p=>{I(p),R(1),d.useServerSideSearch&&(Re.current&&clearTimeout(Re.current),Re.current=setTimeout(async()=>{try{await N(k=>({...k,search:p,current_page:1}))}catch(k){console.error("Search error:",k)}},800))},Oe=(p,k=null)=>{$(p),R(1);const W={value:p,option:k,key:(k==null?void 0:k.key)||"",order:(k==null?void 0:k.order)||"",type:(k==null?void 0:k.type)||""};typeof(D==null?void 0:D.onChange)=="function"&&D.onChange(W)},Te=(p,k,W)=>{W.stopPropagation(),U(null),w==null||w(p.type,k)},Be=(p,k,W)=>{k.stopPropagation(),A(W);const Q=k.currentTarget;De.current[p]=Q;const re=Q.getBoundingClientRect(),le=192,ge=W.length*40,de=window.innerWidth,fe=window.innerHeight,ye=de-re.right<le?re.left-le+re.width:re.left,Fe=fe-re.bottom<ge&&re.top>ge?re.top-ge-2:re.bottom+2;z({top:Math.max(8,Math.min(Fe,fe-ge-8)),left:Math.max(8,Math.min(ye,de-le-8))}),U(L===p?null:p)},Ge=p=>(B-1)*O+p+1,Le=p=>{let k=p;k&&k.src instanceof File&&(k={...k,src:URL.createObjectURL(k.src)}),ce(k),be(!0)},Ye=p=>{if(!p)return"";if(typeof p=="string")return p;if(p instanceof File)return URL.createObjectURL(p);if(typeof p=="object"){if(typeof p.preview=="string")return p.preview;if(typeof p.src=="string")return p.src;if(p.src instanceof File)return URL.createObjectURL(p.src);if(p.file instanceof File)return URL.createObjectURL(p.file)}return""},Ke=(p,k)=>{const W=Array.isArray(p)?p:[];if(W.length===0)return r.jsx("span",{className:k.className||"",children:"N/A"});const Q=k.maxPreview||3,re=W.slice(0,Q),le=W.length-re.length;return r.jsxs("div",{className:"flex items-center",children:[r.jsx("div",{className:"flex -space-x-2",children:re.map((ge,de)=>{const fe=Ye(ge);return fe?r.jsx("button",{type:"button",onClick:Ae=>{Ae.stopPropagation(),Le({src:fe,alt:`Gallery ${de+1}`})},className:"w-8 h-8 rounded-full border-2 border-white dark:border-gray-800 overflow-hidden",children:r.jsx("img",{src:fe,alt:`gallery-${de+1}`,className:"w-full h-full object-cover"})},`${fe}-${de}`):null})}),le>0&&r.jsxs("span",{className:"ml-2 text-xs font-medium text-gray-600 dark:text-gray-300",children:["+",le]})]})},Ee=(p,k,W,Q=null,re=null)=>r.jsx(r.Fragment,{children:p?r.jsx("img",{src:p instanceof File?URL.createObjectURL(p):p,alt:k||"Avatar",onClick:le=>{le.stopPropagation(),le.preventDefault(),Le({src:p,alt:k})},className:`w-10 h-10 cursor-pointer shrink-0 rounded-full object-cover border border-gray-200 dark:border-gray-700 ${W||""}`}):r.jsx(r.Fragment,{children:Q?typeof Q=="function"?Q(re):Q:r.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 ${W||""}`,children:r.jsx(te.User,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),We=(p,k)=>r.jsx(r.Fragment,{children:p?r.jsx("audio",{controls:!0,src:p instanceof File?URL.createObjectURL(p):p,onClick:W=>{W.stopPropagation()},className:`w-64 cursor-pointer ${k||""}`},p instanceof File?URL.createObjectURL(p):p):r.jsx(r.Fragment,{children:r.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 ${k||""}`,children:r.jsx(te.Music,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),G=(p,k)=>r.jsxs("div",{className:`flex items-center space-x-4 ${k.className||""}`,children:[k.imageKey?Ee(p[k.imageKey],p[k.titleKey],"group-avatar",k.fallback_icon,p):"",r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-gray-900 dark:text-white group-title",children:p[k.titleKey]||""}),r.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 group-sub-title",children:p[k.subtitleKey]||""})]})]}),X=(p,k)=>{var le;let W=String(p);const Q=k.variant||"contained";let re=k.defaultColor;if(((le=k==null?void 0:k.chipOptions)==null?void 0:le.length)>0){const ge=k==null?void 0:k.chipOptions.find(de=>de.value==p);ge&&(W=ge.label,re=ge.color)}return r.jsx(Kr,{label:W,variant:Q,color:re,className:k.className||""})},ne=(p,k,W)=>{const Q=k[p.key];return p.type==="menu_actions"?r.jsx("div",{className:`text-center ${p.className||""}`,children:r.jsx("button",{ref:re=>{De.current[k.id||k._id]=re},onClick:re=>Be(k.id||k._id,re,p.menuList),className:v(x.table.actionButton,"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:r.jsx(te.EllipsisVertical,{className:"h-4 w-4"})})}):p.type==="index"?r.jsx("span",{className:p.className||"",children:Ge(W)}):p.type==="group"?G(k,p):p.type==="chip"?r.jsx(r.Fragment,{children:X(Q,p)}):p.type==="date"?r.jsx("span",{className:p.className||"",children:er(Q,p.format||"DD MMM YYYY")}):p.type==="avatar"?r.jsx(r.Fragment,{children:r.jsx("div",{className:"min-w-[40px]",children:Ee(Q,p.alt,p.className,p.fallback_icon,k)})}):p.type==="audio"?r.jsx(r.Fragment,{children:We(Q,p.className)}):p.type==="multiImage"?r.jsx(r.Fragment,{children:Ke(Q,p)}):r.jsx("span",{className:p.className||"",children:Q||"N/A"})},je=p=>{if(typeof P=="function")return P(p);if(P)return w==null?void 0:w("view",p)},ie=(p,k)=>{if(p.onClickDetails)return w==null?void 0:w("view",k);if(typeof p.handleClick=="function")return p.handleClick(k)},pr=()=>P||typeof P=="function",mr=p=>p.onClickDetails||typeof p.handleClick=="function",Vr=()=>{var Ae;if(!(i!=null&&i.length)||!((Ae=g==null?void 0:g.fields)!=null&&Ae.length))return;const p=g.fields.map(ye=>ye.label),k=$e.map(ye=>g.fields.map(hr=>{const Fe=ye==null?void 0:ye[hr.key];return`"${Fe??""}"`})),W=[p.join(","),...k.map(ye=>ye.join(","))].join(`
128
+ `),re=`export-${er(new Date,"YYYY-MM-DD_HH-mm-ss")}.csv`,le=g.fileName||re,ge=new Blob([W],{type:"text/csv;charset=utf-8;"}),de=document.createElement("a"),fe=URL.createObjectURL(ge);de.href=fe,de.download=le,document.body.appendChild(de),de.click(),document.body.removeChild(de),URL.revokeObjectURL(fe)};return b.useEffect(()=>{const p=()=>{L&&U(null)};return window.addEventListener("scroll",p,!0),()=>{window.removeEventListener("scroll",p,!0)}},[L]),b.useEffect(()=>{const p=k=>{_e.current&&!_e.current.contains(k.target)&&U(null)};return document.addEventListener("click",p),()=>document.removeEventListener("click",p)},[]),b.useEffect(()=>{c!=null&&c.rows_per_page&&(c!=null&&c.useServerSidePagination)&&q((c==null?void 0:c.rows_per_page)||50),c.current_page&&R(c.current_page)},[c.rows_per_page,c==null?void 0:c.useServerSidePagination,c.current_page]),b.useEffect(()=>{Z(c!=null&&c.useServerSidePagination?c.total_records:_.length),_.length<=O*(B-1)&&!(c!=null&&c.useServerSidePagination)&&R(p=>p-1||1)},[_.length,c.total_records,c==null?void 0:c.useServerSidePagination]),b.useEffect(()=>{if(!(D!=null&&D.enabled)){$("");return}if(F.some(k=>k.value===D.defaultValue)){$(D.defaultValue);return}$("")},[D,F]),b.useEffect(()=>{if(!(D!=null&&D.enabled)||!(D!=null&&D.useServerSideSorting))return;const p=F==null?void 0:F.find(k=>k.value===Y);N(k=>({...k,current_page:1,sort_by:(p==null?void 0:p.key)||"",sort_order:(p==null?void 0:p.order)||""}))},[Y,D==null?void 0:D.enabled,D==null?void 0:D.useServerSideSorting,F,N]),r.jsxs("div",{ref:Ce,children:[h?r.jsx(Tt,{rows:6,columns:6}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:v(x.table.toolbar,"flex flex-col lg:!flex-row lg:!justify-between gap-4 mb-3"),children:[r.jsxs("div",{className:"table-heading",children:[r.jsx("h1",{children:e}),r.jsx("p",{children:n})]}),r.jsxs("div",{className:"flex flex-col justify-end items-stretch lg:!items-end gap-2 w-full lg:!w-auto",children:[s&&r.jsxs(ue,{onClick:()=>o(!0),variant:"contained",color:"primary",children:[r.jsx(te.Plus,{className:"w-4 h-4 mr-2"}),t||"Add New"]}),r.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&&r.jsx("div",{className:"w-full sm:!w-auto",children:r.jsxs("div",{className:v(x.table.searchField,"table-search-field"),children:[r.jsx(te.Search,{className:"search-icon"}),r.jsx("input",{type:"text",placeholder:d.placeholder||"Search...",value:T,onChange:p=>Ue(p.target.value),className:x.table.searchInput})]})}),D!=null&&D.enabled&&(F==null?void 0:F.length)>0||S&&m.enabled||g&&g.enabled?r.jsxs("div",{className:"flex items-center justify-end gap-2 w-full sm:!w-auto",children:[S&&m.enabled&&r.jsxs("div",{className:"filter-button-wrapper",children:[r.jsxs(ue,{onClick:()=>V(!0),variant:"contained",className:"w-full sm:!w-auto",children:[r.jsx(te.Filter,{className:"w-4 h-4 mr-2"}),"Filters"]}),Object.keys(ee).length>0&&r.jsx("span",{className:"red-dot"})]}),g&&g.enabled&&r.jsx("div",{className:"filter-button-wrapper",children:r.jsxs(ue,{onClick:()=>Vr(),variant:"contained",className:"w-full sm:!w-auto",children:[r.jsx(te.Download,{className:"w-4 h-4 mr-2"}),"Export CSV"]})}),(D==null?void 0:D.enabled)&&(F==null?void 0:F.length)>0&&r.jsx(Bt,{options:F,value:Y,onChange:Oe,clearLabel:D==null?void 0:D.clearLabel})]}):null]})]})]}),r.jsxs("div",{className:v(x.table.root,x.table.container,"table-container"),children:[r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:x.table.element,children:[r.jsx("thead",{className:x.table.head,children:r.jsx("tr",{className:x.table.headRow,children:l.map(p=>r.jsx("th",{className:v(x.table.headCell,"table-head-data",p.headClass||""),children:p.title},p.key))})}),r.jsx("tbody",{className:x.table.body,children:$e.length===0?r.jsx("tr",{children:r.jsx("td",{colSpan:l.length,className:v(x.table.noData,"no-data-message"),children:f})}):$e.map((p,k)=>r.jsx("tr",{className:v(x.table.row,"table-row",pr()?"cursor-pointer":""),onClick:()=>{pr()&&je(p)},children:l.map(W=>r.jsx("td",{className:v(x.table.cell,"table-data",W.type=="audio"?"":"max-w-[300px]","truncate",mr(W)?"cursor-pointer":""),title:String(p[W.key]??""),onClick:Q=>{mr(W)&&(Q.stopPropagation(),Q.preventDefault(),ie(W,p))},children:W.render?W.render(p,k):ne(W,p,k)},W.key))},p.id||p._id||k))})]})}),(c==null?void 0:c.enabled)&&_.length>0&&r.jsxs("div",{className:v(x.table.pagination,"pagination-wrapper"),children:[r.jsxs("span",{children:["Showing ",(B-1)*O+1," to"," ",Math.min(B*O,J)," of"," ",J," results"]}),r.jsxs("div",{className:"flex items-center gap-4",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{children:"Rows per page:"}),r.jsx("select",{value:O,onChange:p=>{const k=Number(p.target.value);q(k),R(1),c.useServerSidePagination&&N(W=>({...W,current_page:1,rows_per_page:k}))},className:"rows-number-select",children:[10,25,50,100].map(p=>r.jsx("option",{value:p,children:p},p))})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:()=>{if(B>1){const p=B-1;R(p),c.useServerSidePagination&&N(k=>({...k,current_page:p}))}},disabled:B===1,className:"arrow-icons",children:r.jsx(te.ChevronLeft,{className:"h-4 w-4"})}),r.jsxs("span",{children:["Page ",B," of ",oe]}),r.jsx("button",{onClick:()=>{if(B<oe){const p=B+1;R(p),c.useServerSidePagination&&N(k=>({...k,current_page:p}))}},disabled:B===oe,className:"arrow-icons",children:r.jsx(te.ChevronRight,{className:"h-4 w-4"})})]})]})]})]})]}),L&&Pe&&dr.createPortal(r.jsx("div",{ref:_e,style:{position:"fixed",top:`${M.top}px`,left:`${M.left}px`,zIndex:9999},className:v(x.table.menu,"w-48 bg-white dark:bg-gray-700 rounded-md shadow-lg border border-gray-200 dark:border-gray-600"),children:y.map((p,k)=>r.jsxs("button",{onClick:W=>Te(p,i.find(Q=>Q.id===L||Q._id==L),W),className:v(x.table.menuItem,"w-full flex items-center gap-2 px-4 py-2 text-sm text-left hover:bg-gray-100 dark:hover:bg-gray-600",p.variant==="danger"?"text-red-600 dark:text-red-500":"text-gray-700 dark:text-gray-200"),children:[p.icon&&r.jsx("span",{className:"shrink-0",children:p.icon}),p.title]},k))}),Pe),S&&r.jsx(Ot,{isOpen:H,onClose:()=>V(!1),config:S,onApply:p=>{ae(p),j==null||j(p)}}),E&&K&&r.jsx(xe,{src:K.src,alt:K.alt,isOpen:E,setIsOpen:be})]})},Ve=({isOpen:a,onClose:o,icon:e,title:t,children:n,size:s="md",actionButtons:i=[],onFormSubmit:l=()=>{},loadingBtn:h=!1,executeFunction:d=()=>{},selectedItem:m=null,footerConfig:u,classNames:c})=>{if(!a)return null;const g={sm:"max-w-md",md:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-full"},f=i.length>0||!!(u!=null&&u.cancelButton);return r.jsxs("div",{className:v(x.modal.root,"fixed inset-0 z-50 flex items-center justify-center p-4"),children:[r.jsx("div",{className:v(x.modal.overlay,"fixed inset-0 bg-gray-500 opacity-75",c==null?void 0:c.overlay)}),r.jsxs("div",{className:v(x.modal.container,"relative bg-white rounded-lg shadow-xl w-full max-h-[90vh] flex flex-col dark:bg-gray-800",g[s]||g.md,c==null?void 0:c.container),children:[r.jsxs("div",{className:v(x.modal.header,"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",c==null?void 0:c.header),children:[r.jsxs("div",{className:"flex items-center gap-1",children:[e&&r.jsx("span",{children:e}),r.jsx("h3",{className:v(x.modal.title,"text-lg font-medium text-gray-900 dark:text-white",c==null?void 0:c.title),children:t})]}),r.jsx("button",{onClick:()=>o(),className:v(x.modal.closeButton,"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",c==null?void 0:c.closeButton),children:r.jsx(te.X,{className:"w-6 h-6"})})]}),r.jsx("div",{className:v(x.modal.body,"flex-1 overflow-y-auto p-4",c==null?void 0:c.body),children:n}),f&&r.jsxs("div",{className:v(x.modal.footer,"px-4 py-3 flex justify-end gap-3 border-t border-gray-200 dark:border-gray-700 sm:!px-6",c==null?void 0:c.footer),children:[(u==null?void 0:u.cancelButton)&&r.jsx(ue,{onClick:()=>o(),variant:"outlined",color:"default",className:v(x.modal.actionButton,"min-w-[100px]"),type:"button",children:(u==null?void 0:u.cancelText)||"Cancel"}),i.map((w,N)=>r.jsx(ue,{onClick:j=>{w.type=="submit"?l(j):d(()=>{var S;return Promise.resolve((S=w==null?void 0:w.onClick)==null?void 0:S.call(w,j,m))},S=>o==null?void 0:o(S))},disabled:h||w.disabled,variant:w.variant||"contained",color:w.color||"primary",className:v(x.modal.actionButton,"min-w-[100px]",w.className||""),type:w.type||"button",children:h?r.jsxs("div",{className:v(x.modal.loadingIndicator,"flex items-center"),children:[r.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-2 border-t-white mr-2"}),w.label||"Submit","..."]}):w.label||"Submit"},`${w.label||"action"}-${N}`))]})]})]})},Cr=({config:a,onSubmit:o,initialData:e,fetchRowDetails:t,type:n})=>{const s=e||{},{formClass:i="grid grid-cols-12 gap-4",formFields:l=[]}=a||{},[h,d]=b.useState(s),[m,u]=b.useState(!0),[c,g]=b.useState({}),f=async()=>{t==null||t(s).then(j=>{d(j.data)}).catch(j=>{ke.enqueueSnackbar(j.message,{variant:"error"})}).finally(()=>{u(!1)})};b.useEffect(()=>{t instanceof Function?f():(d(s),u(!1))},[]);const w=(j,S)=>{d(P=>({...P,[j]:S})),g(P=>({...P,[j]:""}))},N=j=>{j.preventDefault();const S=j.currentTarget;if(!S.checkValidity()){S.reportValidity();return}const P={};let T=!1;for(const I of l){const L=h[I.key]||"";if(I.customValidation){const U=I.customValidation(L);if(U!==!1&&(P[I.key]=U,!T)){const y=S.querySelector(`[id="field-${I.key}"]`);y==null||y.focus(),T=!0}}}g(P),!(Object.keys(P).length>0)&&o(h)};return m?r.jsx("div",{className:v(x.form.loading,"flex items-center justify-center h-64"),children:r.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"}})}):r.jsx("form",{id:n==="add"?"addForm":n==="edit"?"editForm":"defaultForm",onSubmit:N,className:v(x.form.root,i),noValidate:!1,children:l.map(j=>r.jsx(Hr,{field:j,formData:h,errorMessage:c[j.key]||"",handleChange:w},j.key))})};function Zt({data:a,config:o,fetchRowDetails:e}){const{fields:t=[],containerClass:n,variant:s="default",styles:i={}}=o||{},l=a||{},[h,d]=b.useState(l),[m,u]=b.useState(!0),c=async()=>{e==null||e(l).then(f=>{d(f.data)}).catch(f=>{ke.enqueueSnackbar(f.message,{variant:"error"})}).finally(()=>{u(!1)})};if(b.useEffect(()=>{e instanceof Function?c():(d(l),u(!1))},[]),m)return r.jsx("div",{className:v(x.form.loading,"flex items-center justify-center h-64"),children:r.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"}})});const g={default:"grid grid-cols-12 gap-4",card:"grid grid-cols-12 gap-3",split:"rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden divide-y divide-gray-100 dark:divide-gray-800"};return r.jsx(r.Fragment,{children:r.jsx("div",{className:v(x.details.root,x.details.container,g[s]||g.default,n||"",i.containerClass||""),children:t.map(f=>f.renderCondition&&typeof f.renderCondition=="function"&&!f.renderCondition(h)?null:f.type=="group"?r.jsx(Gr,{col:f,data:h,uiVariant:s,styleConfig:i},f.key||f.titleKey):f.type=="cardGroup"?r.jsx(Yr,{col:f,data:h,uiVariant:s,styleConfig:i},f.key||f.titleKey):r.jsx(Wr,{col:f,data:h,uiVariant:s,styleConfig:i},f.key||f.label))})})}const Xt=({config:a})=>{var R,O,q,J,Z,oe,$e,_e,Ce,De,Re,Pe,Ue,Oe,Te,Be,Ge,Le,Ye,Ke,Ee,We;const{title:o,fetchData:e,fetchRowDetails:t,isStaticData:n=!1,tableConfig:s,modalConfig:i,filterConfig:l}=a,[h,d]=b.useState(!0),[m,u]=b.useState(!1),[c,g]=b.useState([]),[f,w]=b.useState(null),[N,j]=b.useState({search:"",rows_per_page:50,current_page:1,sort_by:"",sort_order:""}),[S,P]=b.useState({}),[T,I]=b.useState(!1),[L,U]=b.useState(!1),[y,A]=b.useState(!1),[M,z]=b.useState(!1),[H,V]=b.useState(!1),[ee,ae]=b.useState(null),D=(G,X)=>{G==="edit"?(ae(X),A(!0)):G==="view"?(ae(X),V(!0)):G==="delete"&&(ae(X),z(!0))},C=async(G,X,ne="",je="")=>{u(!0);try{if(!G)return;const ie=await G();(ne||ie!=null&&ie.message)&&ke.enqueueSnackbar(ne||ie.message||"Success",{variant:"success"}),X==null||X(ie)}catch(ie){(je||ie!=null&&ie.message)&&ke.enqueueSnackbar(je||ie.message||"Error occurred",{variant:"error"})}finally{u(!1)}},F=G=>{const X=G.newObject;n?(g(ne=>[X,...ne]),w(ne=>({...ne,current_page:1}))):(j(ne=>({...ne,current_page:1})),N.current_page===1&&E()),U(!1)},Y=G=>{const{newObject:X,targetObject:ne}=G;n?g(je=>je.map(ie=>ie.id===ne.id?{...ie,...X}:ie)):E(),A(!1)},$=G=>{if(!G){z(!1),ae(null);return}n?g(X=>X.filter(ne=>ne.id!==G.targetObject.id)):c.length===1&&N.current_page>1?j(X=>({...X,current_page:X.current_page-1})):E(),z(!1),ae(null)},K=G=>C(()=>{var X;return(X=i==null?void 0:i.addModal)!=null&&X.handleSubmit?i.addModal.handleSubmit(G):Promise.resolve({newObject:null})},F),ce=G=>C(()=>{var X;return(X=i==null?void 0:i.editModal)!=null&&X.handleSubmit?i.editModal.handleSubmit(G,ee):Promise.resolve({newObject:null,targetObject:null})},Y),E=async()=>{d(!0);try{const G=await e({...N,...S});g(G.data||[]),w(G.pagination||null)}catch(G){ke.enqueueSnackbar(G.message||"Failed to fetch data",{variant:"error"})}finally{d(!1)}},be=G=>{var X;P(ne=>({...G})),(X=s==null?void 0:s.filter)!=null&&X.useServerSideFilters&&I(ne=>!ne)},we=(G,X)=>G.filter(ne=>Object.entries(X).every(([je,ie])=>ne[je]===ie)),_=b.useMemo(()=>{var G;return(G=s==null?void 0:s.filter)!=null&&G.useServerSideFilters?c:we(c,S)},[c,S,(R=s==null?void 0:s.filter)==null?void 0:R.useServerSideFilters]),B=(O=i==null?void 0:i.viewModal)==null?void 0:O.component;return b.useEffect(()=>{E()},[N.search,N.rows_per_page,N.current_page,N.sort_by,N.sort_order,T]),r.jsxs("div",{className:x.crudPage.root,children:[r.jsx(Vt,{title:o,setShowAdd:U,description:a.description,buttonText:a.buttonText,showAddButton:!!(i!=null&&i.addModal),config:{...s,pagination:{...s.pagination,...f},data:_,setServerSidePaginationData:j,onMenuAction:D,filterConfig:l,onFilterApply:be,loading:h}}),L&&r.jsx(Ve,{isOpen:L,onClose:()=>{m||U(!1)},icon:(q=i==null?void 0:i.addModal)==null?void 0:q.icon,title:((J=i==null?void 0:i.addModal)==null?void 0:J.title)||"Add New",size:((Z=i==null?void 0:i.addModal)==null?void 0:Z.size)||"md",onFormSubmit:()=>{var G;return(G=document.querySelector("#addForm"))==null?void 0:G.requestSubmit()},loadingBtn:m,actionButtons:((oe=i==null?void 0:i.addModal)==null?void 0:oe.actionButtons)||[],children:r.jsx(Cr,{config:(i==null?void 0:i.addModal)||{},onSubmit:K,initialData:{},type:"add",loading:m})}),y&&r.jsx(Ve,{isOpen:y,onClose:()=>{m||A(!1)},icon:($e=i==null?void 0:i.editModal)==null?void 0:$e.icon,title:((_e=i==null?void 0:i.editModal)==null?void 0:_e.title)||"Edit",size:((Ce=i==null?void 0:i.editModal)==null?void 0:Ce.size)||"md",onFormSubmit:()=>{var G;return(G=document.querySelector("#editForm"))==null?void 0:G.requestSubmit()},actionButtons:((De=i==null?void 0:i.editModal)==null?void 0:De.actionButtons)||[],loadingBtn:m,children:r.jsx(Cr,{config:(i==null?void 0:i.editModal)||{},onSubmit:ce,initialData:ee,type:"edit",loading:m,fetchRowDetails:t})}),M&&r.jsx(Ve,{isOpen:M,onClose:G=>{$(G)},icon:((Re=i==null?void 0:i.deleteModal)==null?void 0:Re.icon)||r.jsx(me.Icon,{icon:"ph:warning-bold",className:"w-6 h-6 text-red-500"}),title:((Pe=i==null?void 0:i.deleteModal)==null?void 0:Pe.title)||"Confirm Delete",size:((Ue=i==null?void 0:i.deleteModal)==null?void 0:Ue.size)||"md",loading:m,actionButtons:((Oe=i==null?void 0:i.deleteModal)==null?void 0:Oe.actionButtons)||[],executeFunction:C,selectedItem:ee,children:r.jsx("div",{className:v(x.crudPage.deleteContent,"flex items-center space-x-2 py-3"),children:r.jsxs("div",{children:[r.jsx("p",{className:"text-md text-gray-700 dark:text-white",children:((Te=i==null?void 0:i.deleteModal)==null?void 0:Te.confirmText)||"Are you sure you want to delete this item?"}),((Be=i==null?void 0:i.deleteModal)==null?void 0:Be.referenceKey)&&r.jsx("p",{className:"text-md font-semibold text-gray-700 dark:text-white",children:ee==null?void 0:ee[(Ge=i==null?void 0:i.deleteModal)==null?void 0:Ge.referenceKey]})]})})}),(i==null?void 0:i.viewModal)&&r.jsx(Ve,{isOpen:H,onClose:()=>{V(!1),ae(null)},icon:(Le=i==null?void 0:i.viewModal)==null?void 0:Le.icon,title:((Ye=i==null?void 0:i.viewModal)==null?void 0:Ye.title)||"View Details",size:((Ke=i==null?void 0:i.viewModal)==null?void 0:Ke.size)||"lg",footerConfig:(Ee=i==null?void 0:i.viewModal)==null?void 0:Ee.footer,classNames:(We=i==null?void 0:i.viewModal)==null?void 0:We.modalClassNames,children:B?r.jsx(B,{data:ee}):r.jsx(Zt,{data:ee,fetchRowDetails:t,config:(i==null?void 0:i.viewModal)||{}})})]})};function qt({children:a}){return ke.useSnackbar(),a}function Jt({children:a}){try{return r.jsx(qt,{children:a})}catch{return r.jsx(ke.SnackbarProvider,{anchorOrigin:{vertical:"bottom",horizontal:"right"},action:e=>r.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:r.jsx(te.X,{className:"h-4 w-4"})}),maxSnack:3,autoHideDuration:3e3,children:a})}}const Qt=()=>{if(typeof document>"u"||document.getElementById("react-admin-crud-manager-styles"))return;const a=document.createElement("style");a.id="react-admin-crud-manager-styles",a.textContent=qr,document.head.appendChild(a)};function ea({config:a}){return b.useEffect(()=>{Qt()},[]),r.jsx("div",{className:"racm-root",children:r.jsx(Jt,{children:r.jsx(Xt,{config:a})})})}module.exports=ea;
129
129
  //# sourceMappingURL=index.cjs.js.map