react-admin-crud-manager 1.0.28 → 1.1.0
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/README.md +36 -5
- package/dist/index.cjs.js +126 -33
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +2965 -1626
- package/dist/index.es.js.map +1 -1
- package/dist/tailwind.css +701 -396
- package/package.json +4 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1,59 +1,152 @@
|
|
|
1
|
-
"use strict";const
|
|
2
|
-
${
|
|
3
|
-
${
|
|
4
|
-
${
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),b=require("react"),U=require("lucide-react"),Ft=require("react-dom"),ce=require("@iconify/react"),It=require("@tinymce/tinymce-react"),le=require("notistack");function Tt(n){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const r=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(a,e,r.get?r:{enumerable:!0,get:()=>n[e]})}}return a.default=n,Object.freeze(a)}const ie=Tt(b),gt=(n,a="DD MMM YYYY")=>{if(!n)return"N/A";const e=new Date(n);if(isNaN(e.getTime()))return"Invalid Date";const r=i=>String(i).padStart(2,"0"),o={YYYY:e.getFullYear(),YY:String(e.getFullYear()).slice(-2),MMMM:e.toLocaleString("en-US",{month:"long"}),MMM:e.toLocaleString("en-US",{month:"short"}),MM:r(e.getMonth()+1),M:e.getMonth()+1,DD:r(e.getDate()),D:e.getDate(),dddd:e.toLocaleString("en-US",{weekday:"long"}),ddd:e.toLocaleString("en-US",{weekday:"short"}),HH:r(e.getHours()),hh:r(e.getHours()%12||12),mm:r(e.getMinutes()),ss:r(e.getSeconds()),A:e.getHours()>=12?"PM":"AM"};return a.replace(/YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|HH|hh|mm|ss|A/g,i=>String(o[i]))},Ot=(n,a,e=[])=>{if(!(a!=null&&a.trim()))return n;const r=a.toLowerCase(),o=i=>i==null?[]:typeof i=="object"?Object.values(i).flatMap(o):[String(i)];return n.filter(i=>{let s=[];return e.length>0?e.forEach(c=>{i[c]!==void 0&&s.push(...o(i[c]))}):s=o(i),s.some(c=>c.toLowerCase().includes(r))})},ae=b.forwardRef(({className:n="",variant:a="contained",color:e="default",size:r="default",fullWidth:o=!1,children:i,...s},c)=>{var g;const f="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",d={sm:"h-8 px-3 rounded-md text-sm",md:"h-9 px-4 rounded-md text-sm",lg:"h-11 px-6 rounded-md text-base",xl:"h-12 px-8 rounded-lg text-lg",default:"h-9 px-4 rounded-md text-sm"},p={primary:{contained:"bg-primary text-white hover:bg-primary-600 focus:ring-primary-500 shadow-sm",outlined:"border border-primary bg-transparent text-primary hover:bg-primary-50 focus:ring-primary-500",text:"bg-transparent text-primary hover:bg-primary-50 focus:ring-primary-500"},success:{contained:"bg-green-600 text-white hover:bg-green-700 focus:ring-green-500 shadow-sm",outlined:"border border-green-600 bg-transparent text-green-600 hover:bg-green-50 focus:ring-green-500",text:"bg-transparent text-green-600 hover:bg-green-50 focus:ring-green-500"},error:{contained:"bg-red-600 text-white hover:bg-red-700 focus:ring-red-500 shadow-sm",outlined:"border border-red-600 bg-transparent text-red-600 hover:bg-red-50 focus:ring-red-500",text:"bg-transparent text-red-600 hover:bg-red-50 focus:ring-red-500"},default:{contained:"border bg-gray-200 text-gray-800 hover:bg-gray-300 focus:ring-gray-300 shadow-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 dark:hover:bg-gray-600 dark:focus:ring-gray-600",outlined:"border border-gray-300 bg-transparent text-gray-700 hover:bg-gray-100 focus:ring-gray-300 dark:border-gray-600 dark:text-gray-200 dark:hover:bg-gray-700 dark:focus:ring-gray-500",text:"bg-transparent text-gray-700 hover:bg-gray-100 focus:ring-gray-300 dark:text-gray-200 dark:hover:bg-gray-700 dark:focus:ring-gray-500"}},h=((g=p[e])==null?void 0:g[a])||p.default.contained,l=d[r]||d.default,m=`
|
|
2
|
+
${f}
|
|
3
|
+
${h}
|
|
4
|
+
${l}
|
|
5
5
|
${o?"w-full":""}
|
|
6
6
|
${n}
|
|
7
|
-
`.trim();return
|
|
7
|
+
`.trim();return t.jsx("button",{ref:c,type:s.type||"button",className:m,...s,children:i})});ae.displayName="Button";function Q({label:n,required:a=!1,infoText:e=""}){return t.jsx(t.Fragment,{children:t.jsxs("label",{className:"flex text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:[n,a&&t.jsx("span",{className:"ml-1",children:"*"}),e&&t.jsxs("span",{className:"ml-2 relative group inline-flex items-center cursor-pointer",children:[t.jsx(U.Info,{className:"w-4 h-4 text-gray-500 dark:text-gray-400"}),t.jsx("span",{className:`absolute left-1/2 top-full mt-2\r
|
|
8
8
|
w-max max-w-xs bg-white text-black dark:bg-black dark:text-white text-xs\r
|
|
9
9
|
rounded px-2 py-1 opacity-0 shadow-lg\r
|
|
10
10
|
group-hover:opacity-100 transition-opacity\r
|
|
11
|
-
duration-200 pointer-events-none z-50`,children:
|
|
12
|
-
${
|
|
13
|
-
${
|
|
14
|
-
${C?"bottom-full mb-1":"top-full mt-1"}`,children:[
|
|
15
|
-
${
|
|
11
|
+
duration-200 pointer-events-none z-50`,children:e})]})]})})}const zt=({options:n=[],value:a="",defaultValue:e="",onChange:r,placeholder:o="Select option",className:i="",disabled:s=!1,search:c=!1,label:f="",required:d=!1,name:p="",parentClass:h="",multiple:l=!1,dropdownMaxHeight:m="",formData:g={},dependencyKey:j=""})=>{var B;const[v,R]=b.useState(!1),[A,L]=b.useState(""),[C,I]=b.useState(!0),E=b.useRef(null),x=b.useRef(null),[w,S]=b.useState([]),D=a||a===!1?a:e,P=M=>M==null||M===""?"":String(typeof M=="boolean"?M:M??"");b.useEffect(()=>{(async()=>{if(typeof n=="function"){const k=await n(g);S(k||[])}else S(n||[])})()},j?[n,g==null?void 0:g[j]]:[n]);const Y=l?(D||[]).map(P):P(D),ee=w.filter(M=>M.label.toLowerCase().includes(A.toLowerCase())),K=M=>{const k=P(M);return l?Y.includes(k):k===Y};b.useEffect(()=>{const M=k=>{E.current&&!E.current.contains(k.target)&&(R(!1),L(""))};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]),b.useEffect(()=>{if(v&&E.current){const M=E.current.getBoundingClientRect(),z=window.innerHeight-M.bottom;I(z<200)}},[v]),b.useEffect(()=>{v&&x.current&&x.current.focus()},[v]);const N=M=>{let k=M;if(M==="true"?k=!0:M==="false"&&(k=!1),l){const z=Y.includes(P(M));let H;z?H=(Array.isArray(a)?a:[]).filter(F=>P(F)!==P(M)):H=[...Array.isArray(a)?a:[],k],r==null||r(H)}else r==null||r(k),R(!1);L("")},X=l?w.filter(M=>K(M.value)).map(M=>M.label).join(", "):(B=w.find(M=>K(M.value)))==null?void 0:B.label;return b.useEffect(()=>{(D||D===!1)&&setTimeout(()=>{r==null||r(D)},100)},[]),t.jsxs("div",{className:h||"col-span-12",children:[t.jsx(Q,{label:f,required:d}),t.jsxs("div",{className:`relative ${i}`,ref:E,children:[t.jsx("select",{name:"hidden_select_for_validation",value:X||"",required:d,multiple:l,className:"absolute opacity-0 right-1/2 top-[80%] -translate-x-1/2 -translate-y-1/2 pointer-events-none h-[10px]",onChange:()=>{},children:t.jsx("option",{hidden:!0,value:X,children:X})}),t.jsxs("button",{type:"button",onClick:()=>!s&&R(!v),disabled:s,className:`w-full h-10 px-3 border border-gray-300 dark:border-gray-600 rounded-md text-left text-sm flex items-center justify-between
|
|
12
|
+
${X?"dark:text-white":"text-gray-500 dark:text-gray-400"}
|
|
13
|
+
${s?"opacity-50 cursor-not-allowed":"dark:bg-gray-700"}`,children:[t.jsx("span",{className:"truncate",children:X||o}),t.jsx(U.ChevronDown,{className:`w-4 h-4 transition-transform ${v?"rotate-180":""}`})]}),v&&t.jsxs("div",{className:`absolute z-50 w-full border rounded-md bg-white dark:bg-gray-700 shadow-lg
|
|
14
|
+
${C?"bottom-full mb-1":"top-full mt-1"}`,children:[c&&t.jsx("div",{className:"p-2 border-b border-gray-200 dark:border-gray-600",children:t.jsxs("div",{className:"relative",children:[t.jsx(U.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),t.jsx("input",{ref:x,type:"text",value:A,onChange:M=>L(M.target.value),placeholder:"Search...",className:"w-full pl-9 pr-3 py-2 text-sm border rounded-md bg-white dark:bg-gray-800 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none"})]})}),t.jsx("div",{className:"max-h-40 overflow-y-auto",style:{maxHeight:m||""},children:ee.length>0?ee.map(M=>t.jsxs("button",{type:"button",onClick:()=>N(String(M.value)),className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-gray-100 dark:hover:bg-gray-600
|
|
15
|
+
${K(M.value)?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":""}`,children:[t.jsx("span",{children:M.label}),l&&K(M.value)&&t.jsx(U.Check,{className:"w-4 h-4"})]},String(M.value))):t.jsx("div",{className:"px-3 py-2 text-sm text-gray-500 dark:text-gray-400",children:"No options found"})})]})]})]},p)},mt=b.forwardRef(({label:n,required:a,parentClass:e="col-span-12",className:r="",value:o=!1,onChange:i,disabled:s=!1,...c},f)=>t.jsxs("div",{className:`flex justify-between ${e}`,children:[n&&t.jsx(Q,{label:n,required:a}),t.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[t.jsx("input",{type:"checkbox",ref:f,className:"sr-only peer",checked:o,onChange:d=>i==null?void 0:i(d.target.checked),disabled:s,...c}),t.jsx("div",{className:`
|
|
16
16
|
w-11 h-6 bg-gray-200 peer-focus:outline-none
|
|
17
17
|
rounded-full peer dark:bg-gray-700
|
|
18
18
|
peer-checked:bg-primary-600
|
|
19
19
|
peer-disabled:opacity-50 peer-disabled:cursor-not-allowed
|
|
20
20
|
transition-colors duration-200
|
|
21
|
-
${
|
|
22
|
-
`}),
|
|
21
|
+
${r}
|
|
22
|
+
`}),t.jsx("div",{className:`\r
|
|
23
23
|
absolute left-1 top-1\r
|
|
24
24
|
w-4 h-4 bg-white rounded-full\r
|
|
25
25
|
transition-transform duration-200\r
|
|
26
26
|
peer-checked:translate-x-5\r
|
|
27
|
-
`})]})]}));Te.displayName="Switch";const ve=[{label:"Afghanistan",code:"AF",phone:"93"},{label:"Aland Islands",code:"AX",phone:"358"},{label:"Albania",code:"AL",phone:"355"},{label:"Algeria",code:"DZ",phone:"213"},{label:"American Samoa",code:"AS",phone:"1"},{label:"Andorra",code:"AD",phone:"376"},{label:"Angola",code:"AO",phone:"244"},{label:"Anguilla",code:"AI",phone:"1"},{label:"Antarctica",code:"AQ",phone:"672"},{label:"Antigua and Barbuda",code:"AG",phone:"1"},{label:"Argentina",code:"AR",phone:"54"},{label:"Armenia",code:"AM",phone:"374"},{label:"Aruba",code:"AW",phone:"297"},{label:"Australia",code:"AU",phone:"61"},{label:"Austria",code:"AT",phone:"43"},{label:"Azerbaijan",code:"AZ",phone:"994"},{label:"Bahrain",code:"BH",phone:"973"},{label:"Bangladesh",code:"BD",phone:"880"},{label:"Barbados",code:"BB",phone:"1"},{label:"Belarus",code:"BY",phone:"375"},{label:"Belgium",code:"BE",phone:"32"},{label:"Belize",code:"BZ",phone:"501"},{label:"Benin",code:"BJ",phone:"229"},{label:"Bermuda",code:"BM",phone:"1"},{label:"Bhutan",code:"BT",phone:"975"},{label:"Bolivia",code:"BO",phone:"591"},{label:"Bonaire, Sint Eustatius and Saba",code:"BQ",phone:"599"},{label:"Bosnia and Herzegovina",code:"BA",phone:"387"},{label:"Botswana",code:"BW",phone:"267"},{label:"Bouvet Island",code:"BV",phone:"0055"},{label:"Brazil",code:"BR",phone:"55"},{label:"British Indian Ocean Territory",code:"IO",phone:"246"},{label:"Brunei",code:"BN",phone:"673"},{label:"Bulgaria",code:"BG",phone:"359"},{label:"Burkina Faso",code:"BF",phone:"226"},{label:"Burundi",code:"BI",phone:"257"},{label:"Cambodia",code:"KH",phone:"855"},{label:"Cameroon",code:"CM",phone:"237"},{label:"Canada",code:"CA",phone:"1"},{label:"Cape Verde",code:"CV",phone:"238"},{label:"Cayman Islands",code:"KY",phone:"1"},{label:"Central African Republic",code:"CF",phone:"236"},{label:"Chad",code:"TD",phone:"235"},{label:"Chile",code:"CL",phone:"56"},{label:"China",code:"CN",phone:"86"},{label:"Christmas Island",code:"CX",phone:"61"},{label:"Cocos (Keeling) Islands",code:"CC",phone:"61"},{label:"Colombia",code:"CO",phone:"57"},{label:"Comoros",code:"KM",phone:"269"},{label:"Congo",code:"CG",phone:"242"},{label:"Cook Islands",code:"CK",phone:"682"},{label:"Costa Rica",code:"CR",phone:"506"},{label:"Croatia",code:"HR",phone:"385"},{label:"Cuba",code:"CU",phone:"53"},{label:"Curaçao",code:"CW",phone:"599"},{label:"Cyprus",code:"CY",phone:"357"},{label:"Czech Republic",code:"CZ",phone:"420"},{label:"Democratic Republic of the Congo",code:"CD",phone:"243"},{label:"Denmark",code:"DK",phone:"45"},{label:"Djibouti",code:"DJ",phone:"253"},{label:"Dominica",code:"DM",phone:"1"},{label:"Dominican Republic",code:"DO",phone:"1"},{label:"Ecuador",code:"EC",phone:"593"},{label:"Egypt",code:"EG",phone:"20"},{label:"El Salvador",code:"SV",phone:"503"},{label:"Equatorial Guinea",code:"GQ",phone:"240"},{label:"Eritrea",code:"ER",phone:"291"},{label:"Estonia",code:"EE",phone:"372"},{label:"Eswatini",code:"SZ",phone:"268"},{label:"Ethiopia",code:"ET",phone:"251"},{label:"Falkland Islands",code:"FK",phone:"500"},{label:"Faroe Islands",code:"FO",phone:"298"},{label:"Fiji Islands",code:"FJ",phone:"679"},{label:"Finland",code:"FI",phone:"358"},{label:"France",code:"FR",phone:"33"},{label:"French Guiana",code:"GF",phone:"594"},{label:"French Polynesia",code:"PF",phone:"689"},{label:"French Southern Territories",code:"TF",phone:"262"},{label:"Gabon",code:"GA",phone:"241"},{label:"Georgia",code:"GE",phone:"995"},{label:"Germany",code:"DE",phone:"49"},{label:"Ghana",code:"GH",phone:"233"},{label:"Gibraltar",code:"GI",phone:"350"},{label:"Greece",code:"GR",phone:"30"},{label:"Greenland",code:"GL",phone:"299"},{label:"Grenada",code:"GD",phone:"1"},{label:"Guadeloupe",code:"GP",phone:"590"},{label:"Guam",code:"GU",phone:"1"},{label:"Guatemala",code:"GT",phone:"502"},{label:"Guernsey",code:"GG",phone:"44"},{label:"Guinea",code:"GN",phone:"224"},{label:"Guinea-Bissau",code:"GW",phone:"245"},{label:"Guyana",code:"GY",phone:"592"},{label:"Haiti",code:"HT",phone:"509"},{label:"Heard Island and McDonald Islands",code:"HM",phone:"672"},{label:"Honduras",code:"HN",phone:"504"},{label:"Hong Kong S.A.R.",code:"HK",phone:"852"},{label:"Hungary",code:"HU",phone:"36"},{label:"Iceland",code:"IS",phone:"354"},{label:"India",code:"IN",phone:"91"},{label:"Indonesia",code:"ID",phone:"62"},{label:"Iran",code:"IR",phone:"98"},{label:"Iraq",code:"IQ",phone:"964"},{label:"Ireland",code:"IE",phone:"353"},{label:"Israel",code:"IL",phone:"972"},{label:"Italy",code:"IT",phone:"39"},{label:"Ivory Coast",code:"CI",phone:"225"},{label:"Jamaica",code:"JM",phone:"1"},{label:"Japan",code:"JP",phone:"81"},{label:"Jersey",code:"JE",phone:"44"},{label:"Jordan",code:"JO",phone:"962"},{label:"Kazakhstan",code:"KZ",phone:"7"},{label:"Kenya",code:"KE",phone:"254"},{label:"Kiribati",code:"KI",phone:"686"},{label:"Kosovo",code:"XK",phone:"383"},{label:"Kuwait",code:"KW",phone:"965"},{label:"Kyrgyzstan",code:"KG",phone:"996"},{label:"Laos",code:"LA",phone:"856"},{label:"Latvia",code:"LV",phone:"371"},{label:"Lebanon",code:"LB",phone:"961"},{label:"Lesotho",code:"LS",phone:"266"},{label:"Liberia",code:"LR",phone:"231"},{label:"Libya",code:"LY",phone:"218"},{label:"Liechtenstein",code:"LI",phone:"423"},{label:"Lithuania",code:"LT",phone:"370"},{label:"Luxembourg",code:"LU",phone:"352"},{label:"Macau S.A.R.",code:"MO",phone:"853"},{label:"Madagascar",code:"MG",phone:"261"},{label:"Malawi",code:"MW",phone:"265"},{label:"Malaysia",code:"MY",phone:"60"},{label:"Maldives",code:"MV",phone:"960"},{label:"Mali",code:"ML",phone:"223"},{label:"Malta",code:"MT",phone:"356"},{label:"Man (Isle of)",code:"IM",phone:"44"},{label:"Marshall Islands",code:"MH",phone:"692"},{label:"Martinique",code:"MQ",phone:"596"},{label:"Mauritania",code:"MR",phone:"222"},{label:"Mauritius",code:"MU",phone:"230"},{label:"Mayotte",code:"YT",phone:"262"},{label:"Mexico",code:"MX",phone:"52"},{label:"Micronesia",code:"FM",phone:"691"},{label:"Moldova",code:"MD",phone:"373"},{label:"Monaco",code:"MC",phone:"377"},{label:"Mongolia",code:"MN",phone:"976"},{label:"Montenegro",code:"ME",phone:"382"},{label:"Montserrat",code:"MS",phone:"1"},{label:"Morocco",code:"MA",phone:"212"},{label:"Mozambique",code:"MZ",phone:"258"},{label:"Myanmar",code:"MM",phone:"95"},{label:"Namibia",code:"NA",phone:"264"},{label:"Nauru",code:"NR",phone:"674"},{label:"Nepal",code:"NP",phone:"977"},{label:"Netherlands",code:"NL",phone:"31"},{label:"New Caledonia",code:"NC",phone:"687"},{label:"New Zealand",code:"NZ",phone:"64"},{label:"Nicaragua",code:"NI",phone:"505"},{label:"Niger",code:"NE",phone:"227"},{label:"Nigeria",code:"NG",phone:"234"},{label:"Niue",code:"NU",phone:"683"},{label:"Norfolk Island",code:"NF",phone:"672"},{label:"North Korea",code:"KP",phone:"850"},{label:"North Macedonia",code:"MK",phone:"389"},{label:"Northern Mariana Islands",code:"MP",phone:"1"},{label:"Norway",code:"NO",phone:"47"},{label:"Oman",code:"OM",phone:"968"},{label:"Pakistan",code:"PK",phone:"92"},{label:"Palau",code:"PW",phone:"680"},{label:"Palestinian Territory Occupied",code:"PS",phone:"970"},{label:"Panama",code:"PA",phone:"507"},{label:"Papua New Guinea",code:"PG",phone:"675"},{label:"Paraguay",code:"PY",phone:"595"},{label:"Peru",code:"PE",phone:"51"},{label:"Philippines",code:"PH",phone:"63"},{label:"Pitcairn Island",code:"PN",phone:"870"},{label:"Poland",code:"PL",phone:"48"},{label:"Portugal",code:"PT",phone:"351"},{label:"Puerto Rico",code:"PR",phone:"1"},{label:"Qatar",code:"QA",phone:"974"},{label:"Reunion",code:"RE",phone:"262"},{label:"Romania",code:"RO",phone:"40"},{label:"Russia",code:"RU",phone:"7"},{label:"Rwanda",code:"RW",phone:"250"},{label:"Saint Helena",code:"SH",phone:"290"},{label:"Saint Kitts and Nevis",code:"KN",phone:"1"},{label:"Saint Lucia",code:"LC",phone:"1"},{label:"Saint Pierre and Miquelon",code:"PM",phone:"508"},{label:"Saint Vincent and the Grenadines",code:"VC",phone:"1"},{label:"Saint-Barthelemy",code:"BL",phone:"590"},{label:"Saint-Martin (French part)",code:"MF",phone:"590"},{label:"Samoa",code:"WS",phone:"685"},{label:"San Marino",code:"SM",phone:"378"},{label:"Sao Tome and Principe",code:"ST",phone:"239"},{label:"Saudi Arabia",code:"SA",phone:"966"},{label:"Senegal",code:"SN",phone:"221"},{label:"Serbia",code:"RS",phone:"381"},{label:"Seychelles",code:"SC",phone:"248"},{label:"Sierra Leone",code:"SL",phone:"232"},{label:"Singapore",code:"SG",phone:"65"},{label:"Sint Maarten (Dutch part)",code:"SX",phone:"1721"},{label:"Slovakia",code:"SK",phone:"421"},{label:"Slovenia",code:"SI",phone:"386"},{label:"Solomon Islands",code:"SB",phone:"677"},{label:"Somalia",code:"SO",phone:"252"},{label:"South Africa",code:"ZA",phone:"27"},{label:"South Georgia",code:"GS",phone:"500"},{label:"South Korea",code:"KR",phone:"82"},{label:"South Sudan",code:"SS",phone:"211"},{label:"Spain",code:"ES",phone:"34"},{label:"Sri Lanka",code:"LK",phone:"94"},{label:"Sudan",code:"SD",phone:"249"},{label:"Suriname",code:"SR",phone:"597"},{label:"Svalbard and Jan Mayen Islands",code:"SJ",phone:"47"},{label:"Sweden",code:"SE",phone:"46"},{label:"Switzerland",code:"CH",phone:"41"},{label:"Syria",code:"SY",phone:"963"},{label:"Taiwan",code:"TW",phone:"886"},{label:"Tajikistan",code:"TJ",phone:"992"},{label:"Tanzania",code:"TZ",phone:"255"},{label:"Thailand",code:"TH",phone:"66"},{label:"The Bahamas",code:"BS",phone:"1"},{label:"The Gambia",code:"GM",phone:"220"},{label:"Timor-Leste",code:"TL",phone:"670"},{label:"Togo",code:"TG",phone:"228"},{label:"Tokelau",code:"TK",phone:"690"},{label:"Tonga",code:"TO",phone:"676"},{label:"Trinidad and Tobago",code:"TT",phone:"1"},{label:"Tunisia",code:"TN",phone:"216"},{label:"Turkey",code:"TR",phone:"90"},{label:"Turkmenistan",code:"TM",phone:"993"},{label:"Turks and Caicos Islands",code:"TC",phone:"1"},{label:"Tuvalu",code:"TV",phone:"688"},{label:"Uganda",code:"UG",phone:"256"},{label:"Ukraine",code:"UA",phone:"380"},{label:"United Arab Emirates",code:"AE",phone:"971"},{label:"United Kingdom",code:"GB",phone:"44"},{label:"United States",code:"US",phone:"1"},{label:"United States Minor Outlying Islands",code:"UM",phone:"1"},{label:"Uruguay",code:"UY",phone:"598"},{label:"Uzbekistan",code:"UZ",phone:"998"},{label:"Vanuatu",code:"VU",phone:"678"},{label:"Vatican City State (Holy See)",code:"VA",phone:"379"},{label:"Venezuela",code:"VE",phone:"58"},{label:"Vietnam",code:"VN",phone:"84"},{label:"Virgin Islands (British)",code:"VG",phone:"1"},{label:"Virgin Islands (US)",code:"VI",phone:"1"},{label:"Wallis and Futuna Islands",code:"WF",phone:"681"},{label:"Western Sahara",code:"EH",phone:"212"},{label:"Yemen",code:"YE",phone:"967"},{label:"Zambia",code:"ZM",phone:"260"},{label:"Zimbabwe",code:"ZW",phone:"263"}];function Ve({label:n="",value:l="",name:r="",parentClass:i="",onChange:o,disabled:d=!1,required:a=!1,placeholder:y="Phone number",search:N=!1,countriesList:c=!1,defaultCountry:b=""}){const u=L=>ve.find(D=>D.code==L),[v,m]=h.useState(u(b)||ve[0]),[g,w]=h.useState(""),[f,S]=h.useState(!1),[A,P]=h.useState(""),C=h.useRef();h.useEffect(()=>{if(typeof l=="string"&&l.startsWith("+")){const L=ve.filter(D=>l.startsWith("+"+D.phone)).sort((D,U)=>U.phone.length-D.phone.length)[0];if(L){m(L),w(l.replace("+"+L.phone,""));return}}w(l)},[l]);const R=L=>{const D=L.target.value.replace(/\D/g,"");w(D),v&&o&&o("+"+v.phone+D)},E=L=>{m(L),o&&o("+"+L.phone+g),S(!1),P("")};h.useEffect(()=>{const L=D=>{C.current&&!C.current.contains(D.target)&&S(!1)};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[]);const F=ve.filter(L=>L.label.toLowerCase().includes(A.toLowerCase())||L.phone.includes(A));if(!c){const L=D=>{const U=D.target.value.replace(/[^+\d]/g,""),G=U.startsWith("+")?"+"+U.replace(/[+]/g,"").slice(0):U;o(G)};return e.jsx(e.Fragment,{children:e.jsxs("div",{className:i||"col-span-12",children:[e.jsx(q,{label:n,required:a}),e.jsx("input",{type:"text",value:l,onChange:L,placeholder:y,disabled:d,required:a,className:`w-full h-10 px-3 text-sm border border-gray-300 dark:border-gray-600 rounded-md \r
|
|
27
|
+
`})]})]}));mt.displayName="Switch";const Ie=[{label:"Afghanistan",code:"AF",phone:"93"},{label:"Aland Islands",code:"AX",phone:"358"},{label:"Albania",code:"AL",phone:"355"},{label:"Algeria",code:"DZ",phone:"213"},{label:"American Samoa",code:"AS",phone:"1"},{label:"Andorra",code:"AD",phone:"376"},{label:"Angola",code:"AO",phone:"244"},{label:"Anguilla",code:"AI",phone:"1"},{label:"Antarctica",code:"AQ",phone:"672"},{label:"Antigua and Barbuda",code:"AG",phone:"1"},{label:"Argentina",code:"AR",phone:"54"},{label:"Armenia",code:"AM",phone:"374"},{label:"Aruba",code:"AW",phone:"297"},{label:"Australia",code:"AU",phone:"61"},{label:"Austria",code:"AT",phone:"43"},{label:"Azerbaijan",code:"AZ",phone:"994"},{label:"Bahrain",code:"BH",phone:"973"},{label:"Bangladesh",code:"BD",phone:"880"},{label:"Barbados",code:"BB",phone:"1"},{label:"Belarus",code:"BY",phone:"375"},{label:"Belgium",code:"BE",phone:"32"},{label:"Belize",code:"BZ",phone:"501"},{label:"Benin",code:"BJ",phone:"229"},{label:"Bermuda",code:"BM",phone:"1"},{label:"Bhutan",code:"BT",phone:"975"},{label:"Bolivia",code:"BO",phone:"591"},{label:"Bonaire, Sint Eustatius and Saba",code:"BQ",phone:"599"},{label:"Bosnia and Herzegovina",code:"BA",phone:"387"},{label:"Botswana",code:"BW",phone:"267"},{label:"Bouvet Island",code:"BV",phone:"0055"},{label:"Brazil",code:"BR",phone:"55"},{label:"British Indian Ocean Territory",code:"IO",phone:"246"},{label:"Brunei",code:"BN",phone:"673"},{label:"Bulgaria",code:"BG",phone:"359"},{label:"Burkina Faso",code:"BF",phone:"226"},{label:"Burundi",code:"BI",phone:"257"},{label:"Cambodia",code:"KH",phone:"855"},{label:"Cameroon",code:"CM",phone:"237"},{label:"Canada",code:"CA",phone:"1"},{label:"Cape Verde",code:"CV",phone:"238"},{label:"Cayman Islands",code:"KY",phone:"1"},{label:"Central African Republic",code:"CF",phone:"236"},{label:"Chad",code:"TD",phone:"235"},{label:"Chile",code:"CL",phone:"56"},{label:"China",code:"CN",phone:"86"},{label:"Christmas Island",code:"CX",phone:"61"},{label:"Cocos (Keeling) Islands",code:"CC",phone:"61"},{label:"Colombia",code:"CO",phone:"57"},{label:"Comoros",code:"KM",phone:"269"},{label:"Congo",code:"CG",phone:"242"},{label:"Cook Islands",code:"CK",phone:"682"},{label:"Costa Rica",code:"CR",phone:"506"},{label:"Croatia",code:"HR",phone:"385"},{label:"Cuba",code:"CU",phone:"53"},{label:"Curaçao",code:"CW",phone:"599"},{label:"Cyprus",code:"CY",phone:"357"},{label:"Czech Republic",code:"CZ",phone:"420"},{label:"Democratic Republic of the Congo",code:"CD",phone:"243"},{label:"Denmark",code:"DK",phone:"45"},{label:"Djibouti",code:"DJ",phone:"253"},{label:"Dominica",code:"DM",phone:"1"},{label:"Dominican Republic",code:"DO",phone:"1"},{label:"Ecuador",code:"EC",phone:"593"},{label:"Egypt",code:"EG",phone:"20"},{label:"El Salvador",code:"SV",phone:"503"},{label:"Equatorial Guinea",code:"GQ",phone:"240"},{label:"Eritrea",code:"ER",phone:"291"},{label:"Estonia",code:"EE",phone:"372"},{label:"Eswatini",code:"SZ",phone:"268"},{label:"Ethiopia",code:"ET",phone:"251"},{label:"Falkland Islands",code:"FK",phone:"500"},{label:"Faroe Islands",code:"FO",phone:"298"},{label:"Fiji Islands",code:"FJ",phone:"679"},{label:"Finland",code:"FI",phone:"358"},{label:"France",code:"FR",phone:"33"},{label:"French Guiana",code:"GF",phone:"594"},{label:"French Polynesia",code:"PF",phone:"689"},{label:"French Southern Territories",code:"TF",phone:"262"},{label:"Gabon",code:"GA",phone:"241"},{label:"Georgia",code:"GE",phone:"995"},{label:"Germany",code:"DE",phone:"49"},{label:"Ghana",code:"GH",phone:"233"},{label:"Gibraltar",code:"GI",phone:"350"},{label:"Greece",code:"GR",phone:"30"},{label:"Greenland",code:"GL",phone:"299"},{label:"Grenada",code:"GD",phone:"1"},{label:"Guadeloupe",code:"GP",phone:"590"},{label:"Guam",code:"GU",phone:"1"},{label:"Guatemala",code:"GT",phone:"502"},{label:"Guernsey",code:"GG",phone:"44"},{label:"Guinea",code:"GN",phone:"224"},{label:"Guinea-Bissau",code:"GW",phone:"245"},{label:"Guyana",code:"GY",phone:"592"},{label:"Haiti",code:"HT",phone:"509"},{label:"Heard Island and McDonald Islands",code:"HM",phone:"672"},{label:"Honduras",code:"HN",phone:"504"},{label:"Hong Kong S.A.R.",code:"HK",phone:"852"},{label:"Hungary",code:"HU",phone:"36"},{label:"Iceland",code:"IS",phone:"354"},{label:"India",code:"IN",phone:"91"},{label:"Indonesia",code:"ID",phone:"62"},{label:"Iran",code:"IR",phone:"98"},{label:"Iraq",code:"IQ",phone:"964"},{label:"Ireland",code:"IE",phone:"353"},{label:"Israel",code:"IL",phone:"972"},{label:"Italy",code:"IT",phone:"39"},{label:"Ivory Coast",code:"CI",phone:"225"},{label:"Jamaica",code:"JM",phone:"1"},{label:"Japan",code:"JP",phone:"81"},{label:"Jersey",code:"JE",phone:"44"},{label:"Jordan",code:"JO",phone:"962"},{label:"Kazakhstan",code:"KZ",phone:"7"},{label:"Kenya",code:"KE",phone:"254"},{label:"Kiribati",code:"KI",phone:"686"},{label:"Kosovo",code:"XK",phone:"383"},{label:"Kuwait",code:"KW",phone:"965"},{label:"Kyrgyzstan",code:"KG",phone:"996"},{label:"Laos",code:"LA",phone:"856"},{label:"Latvia",code:"LV",phone:"371"},{label:"Lebanon",code:"LB",phone:"961"},{label:"Lesotho",code:"LS",phone:"266"},{label:"Liberia",code:"LR",phone:"231"},{label:"Libya",code:"LY",phone:"218"},{label:"Liechtenstein",code:"LI",phone:"423"},{label:"Lithuania",code:"LT",phone:"370"},{label:"Luxembourg",code:"LU",phone:"352"},{label:"Macau S.A.R.",code:"MO",phone:"853"},{label:"Madagascar",code:"MG",phone:"261"},{label:"Malawi",code:"MW",phone:"265"},{label:"Malaysia",code:"MY",phone:"60"},{label:"Maldives",code:"MV",phone:"960"},{label:"Mali",code:"ML",phone:"223"},{label:"Malta",code:"MT",phone:"356"},{label:"Man (Isle of)",code:"IM",phone:"44"},{label:"Marshall Islands",code:"MH",phone:"692"},{label:"Martinique",code:"MQ",phone:"596"},{label:"Mauritania",code:"MR",phone:"222"},{label:"Mauritius",code:"MU",phone:"230"},{label:"Mayotte",code:"YT",phone:"262"},{label:"Mexico",code:"MX",phone:"52"},{label:"Micronesia",code:"FM",phone:"691"},{label:"Moldova",code:"MD",phone:"373"},{label:"Monaco",code:"MC",phone:"377"},{label:"Mongolia",code:"MN",phone:"976"},{label:"Montenegro",code:"ME",phone:"382"},{label:"Montserrat",code:"MS",phone:"1"},{label:"Morocco",code:"MA",phone:"212"},{label:"Mozambique",code:"MZ",phone:"258"},{label:"Myanmar",code:"MM",phone:"95"},{label:"Namibia",code:"NA",phone:"264"},{label:"Nauru",code:"NR",phone:"674"},{label:"Nepal",code:"NP",phone:"977"},{label:"Netherlands",code:"NL",phone:"31"},{label:"New Caledonia",code:"NC",phone:"687"},{label:"New Zealand",code:"NZ",phone:"64"},{label:"Nicaragua",code:"NI",phone:"505"},{label:"Niger",code:"NE",phone:"227"},{label:"Nigeria",code:"NG",phone:"234"},{label:"Niue",code:"NU",phone:"683"},{label:"Norfolk Island",code:"NF",phone:"672"},{label:"North Korea",code:"KP",phone:"850"},{label:"North Macedonia",code:"MK",phone:"389"},{label:"Northern Mariana Islands",code:"MP",phone:"1"},{label:"Norway",code:"NO",phone:"47"},{label:"Oman",code:"OM",phone:"968"},{label:"Pakistan",code:"PK",phone:"92"},{label:"Palau",code:"PW",phone:"680"},{label:"Palestinian Territory Occupied",code:"PS",phone:"970"},{label:"Panama",code:"PA",phone:"507"},{label:"Papua New Guinea",code:"PG",phone:"675"},{label:"Paraguay",code:"PY",phone:"595"},{label:"Peru",code:"PE",phone:"51"},{label:"Philippines",code:"PH",phone:"63"},{label:"Pitcairn Island",code:"PN",phone:"870"},{label:"Poland",code:"PL",phone:"48"},{label:"Portugal",code:"PT",phone:"351"},{label:"Puerto Rico",code:"PR",phone:"1"},{label:"Qatar",code:"QA",phone:"974"},{label:"Reunion",code:"RE",phone:"262"},{label:"Romania",code:"RO",phone:"40"},{label:"Russia",code:"RU",phone:"7"},{label:"Rwanda",code:"RW",phone:"250"},{label:"Saint Helena",code:"SH",phone:"290"},{label:"Saint Kitts and Nevis",code:"KN",phone:"1"},{label:"Saint Lucia",code:"LC",phone:"1"},{label:"Saint Pierre and Miquelon",code:"PM",phone:"508"},{label:"Saint Vincent and the Grenadines",code:"VC",phone:"1"},{label:"Saint-Barthelemy",code:"BL",phone:"590"},{label:"Saint-Martin (French part)",code:"MF",phone:"590"},{label:"Samoa",code:"WS",phone:"685"},{label:"San Marino",code:"SM",phone:"378"},{label:"Sao Tome and Principe",code:"ST",phone:"239"},{label:"Saudi Arabia",code:"SA",phone:"966"},{label:"Senegal",code:"SN",phone:"221"},{label:"Serbia",code:"RS",phone:"381"},{label:"Seychelles",code:"SC",phone:"248"},{label:"Sierra Leone",code:"SL",phone:"232"},{label:"Singapore",code:"SG",phone:"65"},{label:"Sint Maarten (Dutch part)",code:"SX",phone:"1721"},{label:"Slovakia",code:"SK",phone:"421"},{label:"Slovenia",code:"SI",phone:"386"},{label:"Solomon Islands",code:"SB",phone:"677"},{label:"Somalia",code:"SO",phone:"252"},{label:"South Africa",code:"ZA",phone:"27"},{label:"South Georgia",code:"GS",phone:"500"},{label:"South Korea",code:"KR",phone:"82"},{label:"South Sudan",code:"SS",phone:"211"},{label:"Spain",code:"ES",phone:"34"},{label:"Sri Lanka",code:"LK",phone:"94"},{label:"Sudan",code:"SD",phone:"249"},{label:"Suriname",code:"SR",phone:"597"},{label:"Svalbard and Jan Mayen Islands",code:"SJ",phone:"47"},{label:"Sweden",code:"SE",phone:"46"},{label:"Switzerland",code:"CH",phone:"41"},{label:"Syria",code:"SY",phone:"963"},{label:"Taiwan",code:"TW",phone:"886"},{label:"Tajikistan",code:"TJ",phone:"992"},{label:"Tanzania",code:"TZ",phone:"255"},{label:"Thailand",code:"TH",phone:"66"},{label:"The Bahamas",code:"BS",phone:"1"},{label:"The Gambia",code:"GM",phone:"220"},{label:"Timor-Leste",code:"TL",phone:"670"},{label:"Togo",code:"TG",phone:"228"},{label:"Tokelau",code:"TK",phone:"690"},{label:"Tonga",code:"TO",phone:"676"},{label:"Trinidad and Tobago",code:"TT",phone:"1"},{label:"Tunisia",code:"TN",phone:"216"},{label:"Turkey",code:"TR",phone:"90"},{label:"Turkmenistan",code:"TM",phone:"993"},{label:"Turks and Caicos Islands",code:"TC",phone:"1"},{label:"Tuvalu",code:"TV",phone:"688"},{label:"Uganda",code:"UG",phone:"256"},{label:"Ukraine",code:"UA",phone:"380"},{label:"United Arab Emirates",code:"AE",phone:"971"},{label:"United Kingdom",code:"GB",phone:"44"},{label:"United States",code:"US",phone:"1"},{label:"United States Minor Outlying Islands",code:"UM",phone:"1"},{label:"Uruguay",code:"UY",phone:"598"},{label:"Uzbekistan",code:"UZ",phone:"998"},{label:"Vanuatu",code:"VU",phone:"678"},{label:"Vatican City State (Holy See)",code:"VA",phone:"379"},{label:"Venezuela",code:"VE",phone:"58"},{label:"Vietnam",code:"VN",phone:"84"},{label:"Virgin Islands (British)",code:"VG",phone:"1"},{label:"Virgin Islands (US)",code:"VI",phone:"1"},{label:"Wallis and Futuna Islands",code:"WF",phone:"681"},{label:"Western Sahara",code:"EH",phone:"212"},{label:"Yemen",code:"YE",phone:"967"},{label:"Zambia",code:"ZM",phone:"260"},{label:"Zimbabwe",code:"ZW",phone:"263"}];function Bt({label:n="",value:a="",name:e="",parentClass:r="",onChange:o,disabled:i=!1,required:s=!1,placeholder:c="Phone number",search:f=!1,countriesList:d=!1,defaultCountry:p=""}){const h=w=>Ie.find(S=>S.code==w),[l,m]=b.useState(h(p)||Ie[0]),[g,j]=b.useState(""),[v,R]=b.useState(!1),[A,L]=b.useState(""),C=b.useRef(null);b.useEffect(()=>{if(typeof a=="string"&&a.startsWith("+")){const w=Ie.filter(S=>a.startsWith("+"+S.phone)).sort((S,D)=>D.phone.length-S.phone.length)[0];if(w){m(w),j(a.replace("+"+w.phone,""));return}}j(a||"")},[a]);const I=w=>{const S=w.target.value.replace(/\D/g,"");j(S),l&&o&&o("+"+l.phone+S)},E=w=>{m(w),o&&o("+"+w.phone+g),R(!1),L("")};b.useEffect(()=>{const w=S=>{C.current&&!C.current.contains(S.target)&&R(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const x=Ie.filter(w=>w.label.toLowerCase().includes(A.toLowerCase())||w.phone.includes(A));if(!d){const w=S=>{const D=S.target.value.replace(/[^+\d]/g,""),P=D.startsWith("+")?"+"+D.replace(/[+]/g,"").slice(0):D;o==null||o(P)};return t.jsx(t.Fragment,{children:t.jsxs("div",{className:r||"col-span-12",children:[t.jsx(Q,{label:n,required:s}),t.jsx("input",{type:"text",value:a,onChange:w,placeholder:c,disabled:i,required:s,className:`w-full h-10 px-3 text-sm border border-gray-300 dark:border-gray-600 rounded-md \r
|
|
28
28
|
bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none \r
|
|
29
|
-
focus:ring-1 focus:ring-blue-300 dark:focus:ring-blue-200`,inputMode:"tel",pattern:"^\\+\\d{1,15}$"})]},
|
|
30
|
-
${
|
|
31
|
-
${
|
|
29
|
+
focus:ring-1 focus:ring-blue-300 dark:focus:ring-blue-200`,inputMode:"tel",pattern:"^\\+\\d{1,15}$"})]},e)})}return t.jsx(t.Fragment,{children:t.jsxs("div",{className:r||"col-span-12",children:[t.jsx(Q,{label:n,required:s}),t.jsxs("div",{className:"relative ",ref:C,children:[t.jsxs("div",{className:`h-[40px] flex items-center border rounded-md px-2 bg-white dark:bg-gray-700 transition-all
|
|
30
|
+
${v?"ring-0.5 ring-blue-100 border-blue-300":"border-gray-300 dark:border-gray-600"}
|
|
31
|
+
${i?"opacity-60 cursor-not-allowed":""}`,children:[t.jsxs("button",{type:"button",disabled:i,onClick:()=>R(!v),className:"flex items-center gap-1 pr-2 border-r border-gray-300 dark:border-gray-700 focus:outline-none",children:[l?t.jsx("img",{src:`https://flagcdn.com/w20/${l.code.toLowerCase()}.png`,alt:l.code,className:"w-5 h-3 object-cover"}):t.jsx("span",{className:"text-gray-400 text-xs",children:"🌐"}),t.jsx(U.ChevronDown,{className:"w-3 h-3 text-gray-500"})]}),l&&t.jsxs("span",{className:"ml-2 text-sm text-gray-700 dark:text-gray-200 whitespace-nowrap",children:["+",l.phone]}),t.jsx("input",{type:"tel",value:g,onChange:I,required:s,disabled:i||!l,placeholder:l?c:"Select a country",className:"flex-1 ml-2 bg-transparent outline-none text-sm text-gray-800 dark:text-gray-100 placeholder-gray-400"}),t.jsx("input",{type:"tel",required:s,tabIndex:-1,readOnly:!0,value:l&&g?"+"+l.phone+g:"",style:{position:"absolute",opacity:0,pointerEvents:"none",height:0},onChange:()=>{}})]}),v&&t.jsxs("div",{className:"absolute top-full left-0 w-full mt-1 border border-gray-300 dark:border-gray-700 rounded-md bg-white dark:bg-gray-700 shadow-lg z-50 max-h-60 overflow-y-auto",children:[f&&t.jsx("div",{className:"p-2 border-b border-gray-200 dark:border-gray-700",children:t.jsxs("div",{className:"relative",children:[t.jsx(U.Search,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400"}),t.jsx("input",{type:"text",value:A,onChange:w=>L(w.target.value),placeholder:"Search country...",className:"w-full pl-9 pr-3 py-2 text-sm border rounded-md bg-white dark:bg-gray-800 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none "})]})}),x.map(w=>t.jsxs("button",{type:"button",onClick:()=>E(w),className:"w-full flex items-center gap-2 px-2 py-1 text-sm hover:bg-blue-50 dark:hover:bg-gray-700 text-gray-800 dark:text-gray-100",children:[t.jsx("img",{src:`https://flagcdn.com/w20/${w.code.toLowerCase()}.png`,alt:w.code,className:"w-5 h-3 object-cover"}),t.jsxs("span",{children:[w.label," (+",w.phone,")"]})]},w.code))]})]})]},e)})}const xt=b.forwardRef(({className:n="",label:a,required:e,...r},o)=>{const i=`
|
|
32
32
|
placeholder-gray-400 dark:placeholder-gray-400
|
|
33
33
|
${n}
|
|
34
|
-
`.trim();return
|
|
34
|
+
`.trim();return t.jsx(t.Fragment,{children:t.jsxs("div",{className:r.parentClass||"col-span-12",children:[t.jsx(Q,{label:a,required:e}),t.jsx("div",{className:"relative",children:t.jsx("textarea",{className:i,ref:o,required:e,...r})})]},r.name)})});xt.displayName="TextArea";var Ke=function(n,a){return Ke=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])},Ke(n,a)};function $t(n,a){if(typeof a!="function"&&a!==null)throw new TypeError("Class extends value "+String(a)+" is not a constructor or null");Ke(n,a);function e(){this.constructor=n}n.prototype=a===null?Object.create(a):(e.prototype=a.prototype,new e)}var W=function(){return W=Object.assign||function(a){for(var e,r=1,o=arguments.length;r<o;r++){e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(a[i]=e[i])}return a},W.apply(this,arguments)};function Ut(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var tt=!1,he,We,He,ze,Be,yt,$e,Ze,Ye,Ve,vt,Xe,qe,wt,jt;function q(){if(!tt){tt=!0;var n=navigator.userAgent,a=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(n),e=/(Mac OS X)|(Windows)|(Linux)/.exec(n);if(Xe=/\b(iPhone|iP[ao]d)/.exec(n),qe=/\b(iP[ao]d)/.exec(n),Ve=/Android/i.exec(n),wt=/FBAN\/\w+;/i.exec(n),jt=/Mobile/i.exec(n),vt=!!/Win64/.exec(n),a){he=a[1]?parseFloat(a[1]):a[5]?parseFloat(a[5]):NaN,he&&document&&document.documentMode&&(he=document.documentMode);var r=/(?:Trident\/(\d+.\d+))/.exec(n);yt=r?parseFloat(r[1])+4:he,We=a[2]?parseFloat(a[2]):NaN,He=a[3]?parseFloat(a[3]):NaN,ze=a[4]?parseFloat(a[4]):NaN,ze?(a=/(?:Chrome\/(\d+\.\d+))/.exec(n),Be=a&&a[1]?parseFloat(a[1]):NaN):Be=NaN}else he=We=He=Be=ze=NaN;if(e){if(e[1]){var o=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(n);$e=o?parseFloat(o[1].replace("_",".")):!0}else $e=!1;Ze=!!e[2],Ye=!!e[3]}else $e=Ze=Ye=!1}}var Je={ie:function(){return q()||he},ieCompatibilityMode:function(){return q()||yt>he},ie64:function(){return Je.ie()&&vt},firefox:function(){return q()||We},opera:function(){return q()||He},webkit:function(){return q()||ze},safari:function(){return Je.webkit()},chrome:function(){return q()||Be},windows:function(){return q()||Ze},osx:function(){return q()||$e},linux:function(){return q()||Ye},iphone:function(){return q()||Xe},mobile:function(){return q()||Xe||qe||Ve||jt},nativeApp:function(){return q()||wt},android:function(){return q()||Ve},ipad:function(){return q()||qe}},Gt=Je,Kt=!!(typeof window<"u"&&window.document&&window.document.createElement),Wt={canUseDOM:Kt},Ht=Wt,kt=Ht,St;kt.canUseDOM&&(St=document.implementation&&document.implementation.hasFeature&&document.implementation.hasFeature("","")!==!0);/**
|
|
35
|
+
* Checks if an event is supported in the current execution environment.
|
|
36
|
+
*
|
|
37
|
+
* NOTE: This will not work correctly for non-generic events such as `change`,
|
|
38
|
+
* `reset`, `load`, `error`, and `select`.
|
|
39
|
+
*
|
|
40
|
+
* Borrows from Modernizr.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} eventNameSuffix Event name, e.g. "click".
|
|
43
|
+
* @param {?boolean} capture Check if the capture phase is supported.
|
|
44
|
+
* @return {boolean} True if the event is supported.
|
|
45
|
+
* @internal
|
|
46
|
+
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
47
|
+
*/function Zt(n,a){if(!kt.canUseDOM||a&&!("addEventListener"in document))return!1;var e="on"+n,r=e in document;if(!r){var o=document.createElement("div");o.setAttribute(e,"return;"),r=typeof o[e]=="function"}return!r&&St&&n==="wheel"&&(r=document.implementation.hasFeature("Events.wheel","3.0")),r}var Yt=Zt,Vt=Gt,Xt=Yt,rt=10,at=40,nt=800;function Nt(n){var a=0,e=0,r=0,o=0;return"detail"in n&&(e=n.detail),"wheelDelta"in n&&(e=-n.wheelDelta/120),"wheelDeltaY"in n&&(e=-n.wheelDeltaY/120),"wheelDeltaX"in n&&(a=-n.wheelDeltaX/120),"axis"in n&&n.axis===n.HORIZONTAL_AXIS&&(a=e,e=0),r=a*rt,o=e*rt,"deltaY"in n&&(o=n.deltaY),"deltaX"in n&&(r=n.deltaX),(r||o)&&n.deltaMode&&(n.deltaMode==1?(r*=at,o*=at):(r*=nt,o*=nt)),r&&!a&&(a=r<1?-1:1),o&&!e&&(e=o<1?-1:1),{spinX:a,spinY:e,pixelX:r,pixelY:o}}Nt.getEventType=function(){return Vt.firefox()?"DOMMouseScroll":Xt("wheel")?"wheel":"mousewheel"};var qt=Nt,Jt=qt;const Qt=Ut(Jt);function er(n,a,e,r,o,i){i===void 0&&(i=0);var s=me(n,a,i),c=s.width,f=s.height,d=Math.min(c,e),p=Math.min(f,r);return d>p*o?{width:p*o,height:p}:{width:d,height:d/o}}function tr(n){return n.width>n.height?n.width/n.naturalWidth:n.height/n.naturalHeight}function ke(n,a,e,r,o){o===void 0&&(o=0);var i=me(a.width,a.height,o),s=i.width,c=i.height;return{x:ot(n.x,s,e.width,r),y:ot(n.y,c,e.height,r)}}function ot(n,a,e,r){var o=a*r/2-e/2;return Ue(n,-o,o)}function st(n,a){return Math.sqrt(Math.pow(n.y-a.y,2)+Math.pow(n.x-a.x,2))}function it(n,a){return Math.atan2(a.y-n.y,a.x-n.x)*180/Math.PI}function rr(n,a,e,r,o,i,s){i===void 0&&(i=0),s===void 0&&(s=!0);var c=s?ar:nr,f=me(a.width,a.height,i),d=me(a.naturalWidth,a.naturalHeight,i),p={x:c(100,((f.width-e.width/o)/2-n.x/o)/f.width*100),y:c(100,((f.height-e.height/o)/2-n.y/o)/f.height*100),width:c(100,e.width/f.width*100/o),height:c(100,e.height/f.height*100/o)},h=Math.round(c(d.width,p.width*d.width/100)),l=Math.round(c(d.height,p.height*d.height/100)),m=d.width>=d.height*r,g=m?{width:Math.round(l*r),height:l}:{width:h,height:Math.round(h/r)},j=W(W({},g),{x:Math.round(c(d.width-g.width,p.x*d.width/100)),y:Math.round(c(d.height-g.height,p.y*d.height/100))});return{croppedAreaPercentages:p,croppedAreaPixels:j}}function ar(n,a){return Math.min(n,Math.max(0,a))}function nr(n,a){return a}function or(n,a,e,r,o,i){var s=me(a.width,a.height,e),c=Ue(r.width/s.width*(100/n.width),o,i),f={x:c*s.width/2-r.width/2-s.width*c*(n.x/100),y:c*s.height/2-r.height/2-s.height*c*(n.y/100)};return{crop:f,zoom:c}}function sr(n,a,e){var r=tr(a);return e.height>e.width?e.height/(n.height*r):e.width/(n.width*r)}function ir(n,a,e,r,o,i){e===void 0&&(e=0);var s=me(a.naturalWidth,a.naturalHeight,e),c=Ue(sr(n,a,r),o,i),f=r.height>r.width?r.height/n.height:r.width/n.width,d={x:((s.width-n.width)/2-n.x)*f,y:((s.height-n.height)/2-n.y)*f};return{crop:d,zoom:c}}function lt(n,a){return{x:(a.x+n.x)/2,y:(a.y+n.y)/2}}function lr(n){return n*Math.PI/180}function me(n,a,e){var r=lr(e);return{width:Math.abs(Math.cos(r)*n)+Math.abs(Math.sin(r)*a),height:Math.abs(Math.sin(r)*n)+Math.abs(Math.cos(r)*a)}}function Ue(n,a,e){return Math.min(Math.max(n,a),e)}function Te(){for(var n=[],a=0;a<arguments.length;a++)n[a]=arguments[a];return n.filter(function(e){return typeof e=="string"&&e.length>0}).join(" ").trim()}var cr=`.reactEasyCrop_Container {
|
|
48
|
+
position: absolute;
|
|
49
|
+
top: 0;
|
|
50
|
+
left: 0;
|
|
51
|
+
right: 0;
|
|
52
|
+
bottom: 0;
|
|
53
|
+
overflow: hidden;
|
|
54
|
+
user-select: none;
|
|
55
|
+
touch-action: none;
|
|
56
|
+
cursor: move;
|
|
57
|
+
display: flex;
|
|
58
|
+
justify-content: center;
|
|
59
|
+
align-items: center;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.reactEasyCrop_Image,
|
|
63
|
+
.reactEasyCrop_Video {
|
|
64
|
+
will-change: transform; /* this improves performances and prevent painting issues on iOS Chrome */
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.reactEasyCrop_Contain {
|
|
68
|
+
max-width: 100%;
|
|
69
|
+
max-height: 100%;
|
|
70
|
+
margin: auto;
|
|
71
|
+
position: absolute;
|
|
72
|
+
top: 0;
|
|
73
|
+
bottom: 0;
|
|
74
|
+
left: 0;
|
|
75
|
+
right: 0;
|
|
76
|
+
}
|
|
77
|
+
.reactEasyCrop_Cover_Horizontal {
|
|
78
|
+
width: 100%;
|
|
79
|
+
height: auto;
|
|
80
|
+
}
|
|
81
|
+
.reactEasyCrop_Cover_Vertical {
|
|
82
|
+
width: auto;
|
|
83
|
+
height: 100%;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.reactEasyCrop_CropArea {
|
|
87
|
+
position: absolute;
|
|
88
|
+
left: 50%;
|
|
89
|
+
top: 50%;
|
|
90
|
+
transform: translate(-50%, -50%);
|
|
91
|
+
border: 1px solid rgba(255, 255, 255, 0.5);
|
|
92
|
+
box-sizing: border-box;
|
|
93
|
+
box-shadow: 0 0 0 9999em;
|
|
94
|
+
color: rgba(0, 0, 0, 0.5);
|
|
95
|
+
overflow: hidden;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.reactEasyCrop_CropAreaRound {
|
|
99
|
+
border-radius: 50%;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.reactEasyCrop_CropAreaGrid::before {
|
|
103
|
+
content: ' ';
|
|
104
|
+
box-sizing: border-box;
|
|
105
|
+
position: absolute;
|
|
106
|
+
border: 1px solid rgba(255, 255, 255, 0.5);
|
|
107
|
+
top: 0;
|
|
108
|
+
bottom: 0;
|
|
109
|
+
left: 33.33%;
|
|
110
|
+
right: 33.33%;
|
|
111
|
+
border-top: 0;
|
|
112
|
+
border-bottom: 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.reactEasyCrop_CropAreaGrid::after {
|
|
116
|
+
content: ' ';
|
|
117
|
+
box-sizing: border-box;
|
|
118
|
+
position: absolute;
|
|
119
|
+
border: 1px solid rgba(255, 255, 255, 0.5);
|
|
120
|
+
top: 33.33%;
|
|
121
|
+
bottom: 33.33%;
|
|
122
|
+
left: 0;
|
|
123
|
+
right: 0;
|
|
124
|
+
border-left: 0;
|
|
125
|
+
border-right: 0;
|
|
126
|
+
}
|
|
127
|
+
`,dr=1,ur=3,hr=1,pr=function(n){$t(a,n);function a(){var e=n!==null&&n.apply(this,arguments)||this;return e.cropperRef=ie.createRef(),e.imageRef=ie.createRef(),e.videoRef=ie.createRef(),e.containerPosition={x:0,y:0},e.containerRef=null,e.styleRef=null,e.containerRect=null,e.mediaSize={width:0,height:0,naturalWidth:0,naturalHeight:0},e.dragStartPosition={x:0,y:0},e.dragStartCrop={x:0,y:0},e.gestureZoomStart=0,e.gestureRotationStart=0,e.isTouching=!1,e.lastPinchDistance=0,e.lastPinchRotation=0,e.rafDragTimeout=null,e.rafPinchTimeout=null,e.wheelTimer=null,e.currentDoc=typeof document<"u"?document:null,e.currentWindow=typeof window<"u"?window:null,e.resizeObserver=null,e.previousCropSize=null,e.isInitialized=!1,e.state={cropSize:null,hasWheelJustStarted:!1,mediaObjectFit:void 0},e.initResizeObserver=function(){if(!(typeof window.ResizeObserver>"u"||!e.containerRef)){var r=!0;e.resizeObserver=new window.ResizeObserver(function(o){if(r){r=!1;return}e.computeSizes()}),e.resizeObserver.observe(e.containerRef)}},e.preventZoomSafari=function(r){return r.preventDefault()},e.cleanEvents=function(){e.currentDoc&&(e.currentDoc.removeEventListener("mousemove",e.onMouseMove),e.currentDoc.removeEventListener("mouseup",e.onDragStopped),e.currentDoc.removeEventListener("touchmove",e.onTouchMove),e.currentDoc.removeEventListener("touchend",e.onDragStopped),e.currentDoc.removeEventListener("gesturechange",e.onGestureChange),e.currentDoc.removeEventListener("gestureend",e.onGestureEnd),e.currentDoc.removeEventListener("scroll",e.onScroll))},e.clearScrollEvent=function(){e.containerRef&&e.containerRef.removeEventListener("wheel",e.onWheel),e.wheelTimer&&clearTimeout(e.wheelTimer)},e.onMediaLoad=function(){var r=e.computeSizes();r&&(e.previousCropSize=r,e.emitCropData(),e.setInitialCrop(r),e.isInitialized=!0),e.props.onMediaLoaded&&e.props.onMediaLoaded(e.mediaSize)},e.setInitialCrop=function(r){if(e.props.initialCroppedAreaPercentages){var o=or(e.props.initialCroppedAreaPercentages,e.mediaSize,e.props.rotation,r,e.props.minZoom,e.props.maxZoom),i=o.crop,s=o.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(s)}else if(e.props.initialCroppedAreaPixels){var c=ir(e.props.initialCroppedAreaPixels,e.mediaSize,e.props.rotation,r,e.props.minZoom,e.props.maxZoom),i=c.crop,s=c.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(s)}},e.computeSizes=function(){var r,o,i,s,c,f,d=e.imageRef.current||e.videoRef.current;if(d&&e.containerRef){e.containerRect=e.containerRef.getBoundingClientRect(),e.saveContainerPosition();var p=e.containerRect.width/e.containerRect.height,h=((r=e.imageRef.current)===null||r===void 0?void 0:r.naturalWidth)||((o=e.videoRef.current)===null||o===void 0?void 0:o.videoWidth)||0,l=((i=e.imageRef.current)===null||i===void 0?void 0:i.naturalHeight)||((s=e.videoRef.current)===null||s===void 0?void 0:s.videoHeight)||0,m=d.offsetWidth<h||d.offsetHeight<l,g=h/l,j=void 0;if(m)switch(e.state.mediaObjectFit){default:case"contain":j=p>g?{width:e.containerRect.height*g,height:e.containerRect.height}:{width:e.containerRect.width,height:e.containerRect.width/g};break;case"horizontal-cover":j={width:e.containerRect.width,height:e.containerRect.width/g};break;case"vertical-cover":j={width:e.containerRect.height*g,height:e.containerRect.height};break}else j={width:d.offsetWidth,height:d.offsetHeight};e.mediaSize=W(W({},j),{naturalWidth:h,naturalHeight:l}),e.props.setMediaSize&&e.props.setMediaSize(e.mediaSize);var v=e.props.cropSize?e.props.cropSize:er(e.mediaSize.width,e.mediaSize.height,e.containerRect.width,e.containerRect.height,e.props.aspect,e.props.rotation);return(((c=e.state.cropSize)===null||c===void 0?void 0:c.height)!==v.height||((f=e.state.cropSize)===null||f===void 0?void 0:f.width)!==v.width)&&e.props.onCropSizeChange&&e.props.onCropSizeChange(v),e.setState({cropSize:v},e.recomputeCropPosition),e.props.setCropSize&&e.props.setCropSize(v),v}},e.saveContainerPosition=function(){if(e.containerRef){var r=e.containerRef.getBoundingClientRect();e.containerPosition={x:r.left,y:r.top}}},e.onMouseDown=function(r){e.currentDoc&&(r.preventDefault(),e.currentDoc.addEventListener("mousemove",e.onMouseMove),e.currentDoc.addEventListener("mouseup",e.onDragStopped),e.saveContainerPosition(),e.onDragStart(a.getMousePoint(r)))},e.onMouseMove=function(r){return e.onDrag(a.getMousePoint(r))},e.onScroll=function(r){e.currentDoc&&(r.preventDefault(),e.saveContainerPosition())},e.onTouchStart=function(r){e.currentDoc&&(e.isTouching=!0,!(e.props.onTouchRequest&&!e.props.onTouchRequest(r))&&(e.currentDoc.addEventListener("touchmove",e.onTouchMove,{passive:!1}),e.currentDoc.addEventListener("touchend",e.onDragStopped),e.saveContainerPosition(),r.touches.length===2?e.onPinchStart(r):r.touches.length===1&&e.onDragStart(a.getTouchPoint(r.touches[0]))))},e.onTouchMove=function(r){r.preventDefault(),r.touches.length===2?e.onPinchMove(r):r.touches.length===1&&e.onDrag(a.getTouchPoint(r.touches[0]))},e.onGestureStart=function(r){e.currentDoc&&(r.preventDefault(),e.currentDoc.addEventListener("gesturechange",e.onGestureChange),e.currentDoc.addEventListener("gestureend",e.onGestureEnd),e.gestureZoomStart=e.props.zoom,e.gestureRotationStart=e.props.rotation)},e.onGestureChange=function(r){if(r.preventDefault(),!e.isTouching){var o=a.getMousePoint(r),i=e.gestureZoomStart-1+r.scale;if(e.setNewZoom(i,o,{shouldUpdatePosition:!0}),e.props.onRotationChange){var s=e.gestureRotationStart+r.rotation;e.props.onRotationChange(s)}}},e.onGestureEnd=function(r){e.cleanEvents()},e.onDragStart=function(r){var o,i,s=r.x,c=r.y;e.dragStartPosition={x:s,y:c},e.dragStartCrop=W({},e.props.crop),(i=(o=e.props).onInteractionStart)===null||i===void 0||i.call(o)},e.onDrag=function(r){var o=r.x,i=r.y;e.currentWindow&&(e.rafDragTimeout&&e.currentWindow.cancelAnimationFrame(e.rafDragTimeout),e.rafDragTimeout=e.currentWindow.requestAnimationFrame(function(){if(e.state.cropSize&&!(o===void 0||i===void 0)){var s=o-e.dragStartPosition.x,c=i-e.dragStartPosition.y,f={x:e.dragStartCrop.x+s,y:e.dragStartCrop.y+c},d=e.props.restrictPosition?ke(f,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):f;e.props.onCropChange(d)}}))},e.onDragStopped=function(){var r,o;e.isTouching=!1,e.cleanEvents(),e.emitCropData(),(o=(r=e.props).onInteractionEnd)===null||o===void 0||o.call(r)},e.onWheel=function(r){if(e.currentWindow&&!(e.props.onWheelRequest&&!e.props.onWheelRequest(r))){r.preventDefault();var o=a.getMousePoint(r),i=Qt(r).pixelY,s=e.props.zoom-i*e.props.zoomSpeed/200;e.setNewZoom(s,o,{shouldUpdatePosition:!0}),e.state.hasWheelJustStarted||e.setState({hasWheelJustStarted:!0},function(){var c,f;return(f=(c=e.props).onInteractionStart)===null||f===void 0?void 0:f.call(c)}),e.wheelTimer&&clearTimeout(e.wheelTimer),e.wheelTimer=e.currentWindow.setTimeout(function(){return e.setState({hasWheelJustStarted:!1},function(){var c,f;return(f=(c=e.props).onInteractionEnd)===null||f===void 0?void 0:f.call(c)})},250)}},e.getPointOnContainer=function(r,o){var i=r.x,s=r.y;if(!e.containerRect)throw new Error("The Cropper is not mounted");return{x:e.containerRect.width/2-(i-o.x),y:e.containerRect.height/2-(s-o.y)}},e.getPointOnMedia=function(r){var o=r.x,i=r.y,s=e.props,c=s.crop,f=s.zoom;return{x:(o+c.x)/f,y:(i+c.y)/f}},e.setNewZoom=function(r,o,i){var s=i===void 0?{}:i,c=s.shouldUpdatePosition,f=c===void 0?!0:c;if(!(!e.state.cropSize||!e.props.onZoomChange)){var d=Ue(r,e.props.minZoom,e.props.maxZoom);if(f){var p=e.getPointOnContainer(o,e.containerPosition),h=e.getPointOnMedia(p),l={x:h.x*d-p.x,y:h.y*d-p.y},m=e.props.restrictPosition?ke(l,e.mediaSize,e.state.cropSize,d,e.props.rotation):l;e.props.onCropChange(m)}e.props.onZoomChange(d)}},e.getCropData=function(){if(!e.state.cropSize)return null;var r=e.props.restrictPosition?ke(e.props.crop,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):e.props.crop;return rr(r,e.mediaSize,e.state.cropSize,e.getAspect(),e.props.zoom,e.props.rotation,e.props.restrictPosition)},e.emitCropData=function(){var r=e.getCropData();if(r){var o=r.croppedAreaPercentages,i=r.croppedAreaPixels;e.props.onCropComplete&&e.props.onCropComplete(o,i),e.props.onCropAreaChange&&e.props.onCropAreaChange(o,i)}},e.emitCropAreaChange=function(){var r=e.getCropData();if(r){var o=r.croppedAreaPercentages,i=r.croppedAreaPixels;e.props.onCropAreaChange&&e.props.onCropAreaChange(o,i)}},e.recomputeCropPosition=function(){var r,o;if(e.state.cropSize){var i=e.props.crop;if(e.isInitialized&&(!((r=e.previousCropSize)===null||r===void 0)&&r.width)&&(!((o=e.previousCropSize)===null||o===void 0)&&o.height)){var s=Math.abs(e.previousCropSize.width-e.state.cropSize.width)>1e-6||Math.abs(e.previousCropSize.height-e.state.cropSize.height)>1e-6;if(s){var c=e.state.cropSize.width/e.previousCropSize.width,f=e.state.cropSize.height/e.previousCropSize.height;i={x:e.props.crop.x*c,y:e.props.crop.y*f}}}var d=e.props.restrictPosition?ke(i,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):i;e.previousCropSize=e.state.cropSize,e.props.onCropChange(d),e.emitCropData()}},e.onKeyDown=function(r){var o,i,s=e.props,c=s.crop,f=s.onCropChange,d=s.keyboardStep,p=s.zoom,h=s.rotation,l=d;if(e.state.cropSize){r.shiftKey&&(l*=.2);var m=W({},c);switch(r.key){case"ArrowUp":m.y-=l,r.preventDefault();break;case"ArrowDown":m.y+=l,r.preventDefault();break;case"ArrowLeft":m.x-=l,r.preventDefault();break;case"ArrowRight":m.x+=l,r.preventDefault();break;default:return}e.props.restrictPosition&&(m=ke(m,e.mediaSize,e.state.cropSize,p,h)),r.repeat||(i=(o=e.props).onInteractionStart)===null||i===void 0||i.call(o),f(m)}},e.onKeyUp=function(r){var o,i;switch(r.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":r.preventDefault();break;default:return}e.emitCropData(),(i=(o=e.props).onInteractionEnd)===null||i===void 0||i.call(o)},e}return a.prototype.componentDidMount=function(){!this.currentDoc||!this.currentWindow||(this.containerRef&&(this.containerRef.ownerDocument&&(this.currentDoc=this.containerRef.ownerDocument),this.currentDoc.defaultView&&(this.currentWindow=this.currentDoc.defaultView),this.initResizeObserver(),typeof window.ResizeObserver>"u"&&this.currentWindow.addEventListener("resize",this.computeSizes),this.props.zoomWithScroll&&this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}),this.containerRef.addEventListener("gesturestart",this.onGestureStart)),this.currentDoc.addEventListener("scroll",this.onScroll),this.props.disableAutomaticStylesInjection||(this.styleRef=this.currentDoc.createElement("style"),this.styleRef.setAttribute("type","text/css"),this.props.nonce&&this.styleRef.setAttribute("nonce",this.props.nonce),this.styleRef.innerHTML=cr,this.currentDoc.head.appendChild(this.styleRef)),this.imageRef.current&&this.imageRef.current.complete&&this.onMediaLoad(),this.props.setImageRef&&this.props.setImageRef(this.imageRef),this.props.setVideoRef&&this.props.setVideoRef(this.videoRef),this.props.setCropperRef&&this.props.setCropperRef(this.cropperRef))},a.prototype.componentWillUnmount=function(){var e,r;!this.currentDoc||!this.currentWindow||(typeof window.ResizeObserver>"u"&&this.currentWindow.removeEventListener("resize",this.computeSizes),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),this.containerRef&&this.containerRef.removeEventListener("gesturestart",this.preventZoomSafari),this.styleRef&&((r=this.styleRef.parentNode)===null||r===void 0||r.removeChild(this.styleRef)),this.cleanEvents(),this.props.zoomWithScroll&&this.clearScrollEvent())},a.prototype.componentDidUpdate=function(e){var r,o,i,s,c,f,d,p,h;e.rotation!==this.props.rotation?(this.computeSizes(),this.recomputeCropPosition()):e.aspect!==this.props.aspect?this.computeSizes():e.objectFit!==this.props.objectFit?this.computeSizes():e.zoom!==this.props.zoom?this.recomputeCropPosition():((r=e.cropSize)===null||r===void 0?void 0:r.height)!==((o=this.props.cropSize)===null||o===void 0?void 0:o.height)||((i=e.cropSize)===null||i===void 0?void 0:i.width)!==((s=this.props.cropSize)===null||s===void 0?void 0:s.width)?this.computeSizes():(((c=e.crop)===null||c===void 0?void 0:c.x)!==((f=this.props.crop)===null||f===void 0?void 0:f.x)||((d=e.crop)===null||d===void 0?void 0:d.y)!==((p=this.props.crop)===null||p===void 0?void 0:p.y))&&this.emitCropAreaChange(),e.zoomWithScroll!==this.props.zoomWithScroll&&this.containerRef&&(this.props.zoomWithScroll?this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}):this.clearScrollEvent()),e.video!==this.props.video&&((h=this.videoRef.current)===null||h===void 0||h.load());var l=this.getObjectFit();l!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:l},this.computeSizes)},a.prototype.getAspect=function(){var e=this.props,r=e.cropSize,o=e.aspect;return r?r.width/r.height:o},a.prototype.getObjectFit=function(){var e,r,o,i;if(this.props.objectFit==="cover"){var s=this.imageRef.current||this.videoRef.current;if(s&&this.containerRef){this.containerRect=this.containerRef.getBoundingClientRect();var c=this.containerRect.width/this.containerRect.height,f=((e=this.imageRef.current)===null||e===void 0?void 0:e.naturalWidth)||((r=this.videoRef.current)===null||r===void 0?void 0:r.videoWidth)||0,d=((o=this.imageRef.current)===null||o===void 0?void 0:o.naturalHeight)||((i=this.videoRef.current)===null||i===void 0?void 0:i.videoHeight)||0,p=f/d;return p<c?"horizontal-cover":"vertical-cover"}return"horizontal-cover"}return this.props.objectFit},a.prototype.onPinchStart=function(e){var r=a.getTouchPoint(e.touches[0]),o=a.getTouchPoint(e.touches[1]);this.lastPinchDistance=st(r,o),this.lastPinchRotation=it(r,o),this.onDragStart(lt(r,o))},a.prototype.onPinchMove=function(e){var r=this;if(!(!this.currentDoc||!this.currentWindow)){var o=a.getTouchPoint(e.touches[0]),i=a.getTouchPoint(e.touches[1]),s=lt(o,i);this.onDrag(s),this.rafPinchTimeout&&this.currentWindow.cancelAnimationFrame(this.rafPinchTimeout),this.rafPinchTimeout=this.currentWindow.requestAnimationFrame(function(){var c=st(o,i),f=r.props.zoom*(c/r.lastPinchDistance);r.setNewZoom(f,s,{shouldUpdatePosition:!1}),r.lastPinchDistance=c;var d=it(o,i),p=r.props.rotation+(d-r.lastPinchRotation);r.props.onRotationChange&&r.props.onRotationChange(p),r.lastPinchRotation=d})}},a.prototype.render=function(){var e=this,r,o=this.props,i=o.image,s=o.video,c=o.mediaProps,f=o.cropperProps,d=o.transform,p=o.crop,h=p.x,l=p.y,m=o.rotation,g=o.zoom,j=o.cropShape,v=o.showGrid,R=o.roundCropAreaPixels,A=o.style,L=A.containerStyle,C=A.cropAreaStyle,I=A.mediaStyle,E=o.classes,x=E.containerClassName,w=E.cropAreaClassName,S=E.mediaClassName,D=(r=this.state.mediaObjectFit)!==null&&r!==void 0?r:this.getObjectFit();return ie.createElement("div",{onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart,ref:function(Y){return e.containerRef=Y},"data-testid":"container",style:L,className:Te("reactEasyCrop_Container",x)},i?ie.createElement("img",W({alt:"",className:Te("reactEasyCrop_Image",D==="contain"&&"reactEasyCrop_Contain",D==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",D==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",S)},c,{src:i,ref:this.imageRef,style:W(W({},I),{transform:d||"translate(".concat(h,"px, ").concat(l,"px) rotate(").concat(m,"deg) scale(").concat(g,")")}),onLoad:this.onMediaLoad})):s&&ie.createElement("video",W({autoPlay:!0,playsInline:!0,loop:!0,muted:!0,className:Te("reactEasyCrop_Video",D==="contain"&&"reactEasyCrop_Contain",D==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",D==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",S)},c,{ref:this.videoRef,onLoadedMetadata:this.onMediaLoad,style:W(W({},I),{transform:d||"translate(".concat(h,"px, ").concat(l,"px) rotate(").concat(m,"deg) scale(").concat(g,")")}),controls:!1}),(Array.isArray(s)?s:[{src:s}]).map(function(P){return ie.createElement("source",W({key:P.src},P))})),this.state.cropSize&&ie.createElement("div",W({ref:this.cropperRef,style:W(W({},C),{width:R?Math.round(this.state.cropSize.width):this.state.cropSize.width,height:R?Math.round(this.state.cropSize.height):this.state.cropSize.height}),tabIndex:0,onKeyDown:this.onKeyDown,onKeyUp:this.onKeyUp,"data-testid":"cropper",className:Te("reactEasyCrop_CropArea",j==="round"&&"reactEasyCrop_CropAreaRound",v&&"reactEasyCrop_CropAreaGrid",w)},f)))},a.defaultProps={zoom:1,rotation:0,aspect:4/3,maxZoom:ur,minZoom:dr,cropShape:"rect",objectFit:"contain",showGrid:!0,style:{},classes:{},mediaProps:{},cropperProps:{},zoomSpeed:1,restrictPosition:!0,zoomWithScroll:!0,keyboardStep:hr},a.getMousePoint=function(e){return{x:Number(e.clientX),y:Number(e.clientY)}},a.getTouchPoint=function(e){return{x:Number(e.clientX),y:Number(e.clientY)}},a}(ie.Component);const ct=ae,fr=n=>new Promise((a,e)=>{const r=new Image;r.addEventListener("load",()=>a(r)),r.addEventListener("error",o=>e(o)),r.setAttribute("crossOrigin","anonymous"),r.src=n}),Mt=n=>n*Math.PI/180,br=(n,a,e)=>{const r=Mt(e);return{width:Math.abs(Math.cos(r)*n)+Math.abs(Math.sin(r)*a),height:Math.abs(Math.sin(r)*n)+Math.abs(Math.cos(r)*a)}},gr=async(n,a,e="image/jpeg",r=0)=>{const o=await fr(n),i=document.createElement("canvas"),s=i.getContext("2d");if(!s)throw new Error("Canvas context is not available");const c=Mt(r),{width:f,height:d}=br(o.width,o.height,r);i.width=f,i.height=d,s.translate(f/2,d/2),s.rotate(c),s.translate(-o.width/2,-o.height/2),s.drawImage(o,0,0);const p=document.createElement("canvas"),h=p.getContext("2d");if(!h)throw new Error("Canvas context is not available");return p.width=a.width,p.height=a.height,h.drawImage(i,a.x,a.y,a.width,a.height,0,0,a.width,a.height),new Promise((l,m)=>{p.toBlob(g=>{if(!g){m(new Error("Image cropping failed"));return}l(g)},e,.95)})},mr=({isOpen:n,imageSrc:a,fileType:e="image/jpeg",fileName:r="cropped-image",aspect:o=1/1,title:i="Crop Image",onClose:s,onApply:c})=>{const[f,d]=b.useState({x:0,y:0}),[p,h]=b.useState(1),[l,m]=b.useState(null);b.useEffect(()=>{n&&(d({x:0,y:0}),h(1),m(null))},[n]);const g=b.useCallback((v,R)=>{m(R)},[]),j=async()=>{var v,R;if(!(!a||!l))try{const A=await gr(a,l,e),L=((R=(v=e==null?void 0:e.split("/"))==null?void 0:v[1])==null?void 0:R.replace("jpeg","jpg"))||"jpg",C=new File([A],`${r}.${L}`,{type:e});c==null||c(C)}catch{s==null||s()}};return n?t.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[t.jsx("div",{className:"fixed inset-0 bg-gray-500 opacity-75",onClick:s}),t.jsxs("div",{className:"relative bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col dark:bg-gray-800",children:[t.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[t.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:i}),t.jsx("button",{type:"button",onClick:s,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300","aria-label":"Close crop modal",children:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-6 h-6"})})]}),t.jsxs("div",{className:"p-4 space-y-4",children:[t.jsx("div",{className:"relative h-72 w-full bg-gray-900 rounded-md overflow-hidden",children:a&&t.jsx(pr,{image:a,crop:f,zoom:p,aspect:o,onCropChange:d,onZoomChange:h,onCropComplete:g})}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-sm text-gray-700 dark:text-gray-300",children:"Zoom"}),t.jsx("input",{type:"range",min:1,max:3,step:.1,value:p,onChange:v=>h(Number(v.target.value)),className:"w-full"})]})]}),t.jsxs("div",{className:"px-4 py-3 flex justify-end gap-3 border-t border-gray-200 dark:border-gray-700 sm:!px-6",children:[t.jsx(ct,{type:"button",onClick:s,variant:"outlined",color:"default",children:"Cancel"}),t.jsx(ct,{type:"button",onClick:j,variant:"contained",color:"primary",children:"Apply Crop"})]})]})]}):null},xr=ae,ue=n=>{typeof n=="string"&&n.startsWith("blob:")&&URL.revokeObjectURL(n)},yr=({label:n="",value:a=null,onChange:e,required:r=!1,accept:o="image/*",aspect:i="1",id:s,dragDrop:c=!1,cropImage:f=!1,name:d="",parentClass:p=""})=>{const[h,l]=b.useState(a),[m,g]=b.useState(!1),[j,v]=b.useState(!1),[R,A]=b.useState(""),[L,C]=b.useState("image/jpeg"),[I,E]=b.useState("cropped-image"),x=b.useRef(null),w=b.useRef(""),S=b.useRef("");b.useEffect(()=>{if(a instanceof File){const k=URL.createObjectURL(a);ue(S.current),S.current=k,l({file:a,preview:k})}else a&&typeof a=="object"&&"preview"in a,l(a)},[a]),b.useEffect(()=>()=>{ue(S.current),ue(w.current)},[]);const D=()=>{v(!1),ue(w.current),w.current="",A(""),x.current&&(x.current.value="")},P=k=>{const z=URL.createObjectURL(k);ue(S.current),S.current=z,l({file:k,preview:z}),e==null||e(k),D()},Y=k=>{if(!k||k.length===0)return;const z=k[0];if(f){const F=URL.createObjectURL(z);ue(w.current),w.current=F,A(F),C(z.type||"image/jpeg"),E((z.name||"cropped-image").replace(/\.[^/.]+$/,"")),v(!0);return}const H=URL.createObjectURL(z);ue(S.current),S.current=H,l({file:z,preview:H}),e==null||e(z)},ee=k=>{k&&k.stopPropagation(),ue(S.current),S.current="",l(null),e==null||e(null),x.current&&(x.current.value="")},K=k=>{c&&(k.preventDefault(),g(!0))},N=k=>{c&&(k.preventDefault(),g(!1))},X=k=>{var z,H,F,te;c&&(k.preventDefault(),g(!1),(te=(F=(H=(z=k.dataTransfer)==null?void 0:z.files)==null?void 0:H[0])==null?void 0:F.type)!=null&&te.includes("image/")&&Y(k.dataTransfer.files))},B=()=>{var k;(k=x.current)==null||k.click()},M=h&&typeof h=="object"&&"preview"in h?h.preview:typeof h=="string"?h:"";return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:p||"col-span-12",children:[t.jsx(Q,{label:n,required:r}),t.jsxs("div",{className:`relative rounded-md p-2 transition-all ${m?"border-2 border-dashed border-blue-500 bg-blue-50 dark:bg-blue-900/20":"border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800"}`,onDragOver:K,onDragLeave:N,onDrop:X,children:[t.jsx("input",{ref:x,id:s,type:"file",accept:o,onChange:k=>Y(k.target.files),required:r&&!h,className:"absolute opacity-0 right-[50%] top-[80%] -translate-y-1/2 pointer-events-none h-[10px]"}),t.jsxs("div",{className:`flex items-center space-x-4 transition-all ${m?"opacity-50":""}`,children:[h?t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:M,alt:"preview",className:"object-cover w-20 h-20 rounded-full shadow-md"}),!r&&t.jsx("button",{type:"button",onClick:ee,className:"absolute top-0 -right-2 bg-red-500 text-white rounded-full p-1 shadow-lg hover:bg-red-600 transition-colors focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2","aria-label":"Remove image",children:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-3 h-3"})})]}):t.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:t.jsx(ce.Icon,{icon:"ri:image-add-fill",className:"text-gray-400 w-10 h-10"})}),t.jsxs("div",{className:"flex flex-col items-center space-y-1",children:[t.jsx(xr,{type:"button",onClick:B,variant:"outlined",color:"default",children:h?"Change Image":"Select Image"}),c&&!h&&t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop"})]})]}),c&&m&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-md",children:t.jsx("span",{className:"text-blue-600 dark:text-blue-400 font-semibold text-lg",children:"Drop image here"})})]})]},d),t.jsx(mr,{isOpen:j,imageSrc:R,fileType:L,fileName:I,onClose:D,onApply:P,aspect:Number(i)})]})},Rt=b.forwardRef(({label:n,value:a,required:e,parentClass:r="",className:o="",type:i="text",onKeyDown:s,negativeNumberAllow:c=!0,defaultValue:f="",field:d={},onChange:p,mask:h="",maskApplyOnValue:l=!0,...m},g)=>{const[j,v]=b.useState(!1),R=C=>{if(i==="number"){if(["e","E","+"].includes(C.key)){C.preventDefault();return}if(c==!1&&C.key==="-"){C.preventDefault();return}if(["ArrowUp","ArrowDown"].includes(C.key)){C.preventDefault();return}}s==null||s(C)},A=`
|
|
35
128
|
h-10 placeholder-gray-400 dark:placeholder-gray-400
|
|
36
|
-
${
|
|
37
|
-
${
|
|
38
|
-
${
|
|
39
|
-
`.trim();
|
|
129
|
+
${i==="password"?"pr-10":""}
|
|
130
|
+
${i==="number"?"no-spinner":""}
|
|
131
|
+
${o}
|
|
132
|
+
`.trim();function L(C,I){if(!C)return C;const E=String(C).replace(/[^a-zA-Z0-9]/g,"");let x="",w=0;for(let S=0;S<(I==null?void 0:I.length)&&w<E.length;S++){const D=I[S],P=E[w];D==="9"?/\d/.test(P)?(x+=P,w++):(w++,S--):D==="A"?/[a-zA-Z]/.test(P)?(x+=P,w++):(w++,S--):D==="X"?/[a-zA-Z0-9]/.test(P)?(x+=P,w++):(w++,S--):D==="*"?(x+=P,w++):(x+=D,P===D&&w++)}return x}return b.useEffect(()=>{if(f){const C=a||f;setTimeout(()=>{p==null||p(C)},100)}},[f]),t.jsx(t.Fragment,{children:t.jsxs("div",{className:r||"col-span-12",children:[t.jsx(Q,{label:n,required:e,infoText:d==null?void 0:d.infoText}),t.jsxs("div",{className:"relative",children:[t.jsx("input",{type:i==="password"&&j?"text":i,ref:g,required:e,onKeyDown:R,className:A,value:h?L(a,h):a,onChange:C=>{p(h&&l?L(C.target.value,h):C.target.value)},...m}),i==="password"&&t.jsx("button",{type:"button",tabIndex:-1,onClick:()=>v(C=>!C),className:"absolute inset-y-0 right-3 flex items-center text-gray-400 hover:text-gray-600 dark:text-gray-400 dark:hover:text-gray-200",children:t.jsx(ce.Icon,{icon:j?"mdi:eye-outline":"mdi:eye-off-outline",className:"w-5 h-5"})})]})]},m.name)})});Rt.displayName="Input";const vr=({editorKey:n="",value:a="",onChange:e,label:r="",required:o=!1,placeholder:i="",parentClass:s="col-span-12",height:c=400,inline:f=!1,disabled:d=!1,plugins:p,toolbar:h,menubar:l=!1,fontFamily:m="Inter, sans-serif",initConfig:g={},imageUploadHandler:j})=>{const v=["advlist","autolink","lists","link","image","charmap","preview","anchor","searchreplace","visualblocks","code","fullscreen","insertdatetime","media","table","help","wordcount"],R="undo redo | blocks | bold italic underline forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media table | removeformat | code fullscreen preview",A=L=>new Promise((C,I)=>{if(!j){C(`data:${L.blob().type};base64,${L.base64()}`);return}j(L).then(E=>{E?C(E):I("Upload failed: No URL returned")}).catch(E=>{I(typeof E=="string"?E:(E==null?void 0:E.message)||"Image upload failed")})});return t.jsxs("div",{className:s,children:[r&&t.jsx(Q,{label:r,required:o}),t.jsx(It.Editor,{apiKey:n,value:a,disabled:d,init:{height:c,inline:f,menubar:l,branding:!1,statusbar:!0,automatic_uploads:!0,images_upload_handler:A,plugins:p??v,toolbar:h??R,placeholder:i,content_style:`
|
|
40
133
|
body {
|
|
41
|
-
font-family: ${
|
|
134
|
+
font-family: ${m};
|
|
42
135
|
}
|
|
43
|
-
`,...
|
|
44
|
-
backdrop-blur-sm animate-in fade-in duration-200`,onClick:o,children:[
|
|
45
|
-
hover:bg-gray-100 dark:hover:bg-gray-700 rounded-full p-2 shadow-lg transition`,children:
|
|
136
|
+
`,...g},onEditorChange:L=>{e==null||e(L)}})]})},wr=({name:n="",label:a="",options:e=[],value:r=null,onChange:o,disabled:i=!1,required:s=!1,parentClass:c="col-span-12",className:f="",multiSelect:d=!1})=>{const p=Array.isArray(e)&&e.length>0,h=g=>p?d?Array.isArray(r)&&r.includes(g):r===g:!!r,l=g=>{o==null||o(g.target.checked,n)},m=(g,j)=>{if(o)if(!d)o(j?g:"",n);else{const v=Array.isArray(r)?[...r]:[];if(j)v.includes(g)||v.push(g);else{const R=v.indexOf(g);R>-1&&v.splice(R,1)}o(v,n)}};return p?t.jsx(t.Fragment,{children:t.jsxs("div",{className:`${c}`,children:[t.jsx(Q,{label:a,required:s}),t.jsx("div",{className:"flex flex-col space-y-2",children:e.map((g,j)=>t.jsxs("div",{className:"flex items-center",children:[t.jsx("input",{type:"checkbox",name:n,value:g.value,checked:h(g.value),disabled:i||!!g.disabled,required:s&&j===0,onChange:v=>m(g.value,v.target.checked),className:`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 ${f}`},n),g.label&&t.jsx("label",{htmlFor:n,className:"ml-2 text-sm text-gray-700 dark:text-gray-200 select-none",children:g.label})]},g.value||g.label))})]})}):t.jsxs("div",{className:`flex items-center ${c}`,children:[t.jsx("input",{type:"checkbox",name:n,checked:h(),disabled:i,required:s,onChange:l,className:`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 ${f}`}),a&&t.jsx("label",{htmlFor:n,className:"ml-2 text-sm text-gray-700 dark:text-gray-200 select-none",children:a})]})},dt=ae,jr=({label:n="",value:a=null,onChange:e,required:r=!1,accept:o="audio/*",id:i,dragDrop:s=!1,name:c="",parentClass:f="",maxSize:d=0})=>{const[p,h]=b.useState(null),[l,m]=b.useState(!1),g=b.useRef(null),j=d*1024*1024;b.useEffect(()=>{if(!a){v(),h(null);return}if(a instanceof File){const x=URL.createObjectURL(a);return h({file:a,preview:x}),()=>{URL.revokeObjectURL(x)}}else typeof a=="string"?h({preview:a}):a!=null&&a.preview&&h(a)},[a]);const v=()=>{p!=null&&p.preview&&p.preview.startsWith("blob:")&&URL.revokeObjectURL(p.preview)},R=x=>{if(!x||x.length===0)return;const w=x[0];if(j&&w.size>j){le.enqueueSnackbar(`Audio is too large. Maximum allowed size is ${d} MB`,{variant:"warning"});return}const S=URL.createObjectURL(w);v(),h({file:w,preview:S}),e==null||e(w)},A=x=>{x&&x.stopPropagation(),v(),h(null),e==null||e(null),g.current&&(g.current.value="")},L=x=>{s&&(x.preventDefault(),m(!0))},C=x=>{s&&(x.preventDefault(),m(!1))},I=x=>{var w,S,D,P;s&&(x.preventDefault(),m(!1),(P=(D=(S=(w=x.dataTransfer)==null?void 0:w.files)==null?void 0:S[0])==null?void 0:D.type)!=null&&P.includes("audio/")&&R(x.dataTransfer.files))},E=()=>{var x;(x=g.current)==null||x.click()};return t.jsxs("div",{className:f||"col-span-12",children:[t.jsx(Q,{label:n,required:r}),t.jsxs("div",{className:`relative rounded-lg p-2 transition-all ${l?"border-2 border-dashed border-blue-500 bg-blue-50 dark:bg-blue-900/20":"border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800"}`,onDragOver:L,onDragLeave:C,onDrop:I,children:[t.jsx("input",{ref:g,id:i,type:"file",accept:o,onChange:x=>R(x.target.files),required:r&&!p,className:"absolute opacity-0 right-[50%] top-[80%] -translate-y-1/2 pointer-events-none h-[10px]"}),t.jsx("div",{className:`flex items-center space-x-4 transition-all ${l?"opacity-50":""}`,children:p?t.jsxs("div",{className:"flex items-center space-x-4",children:[t.jsxs("div",{className:"relative w-full",children:[!r&&t.jsx("button",{type:"button",onClick:A,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:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-3 h-3"})}),t.jsx("audio",{src:p.preview,controls:!0,controlsList:"nodownload"},p.preview)]}),t.jsx(dt,{type:"button",onClick:E,children:t.jsx("span",{children:"Change Audio File"})})]}):t.jsxs("div",{className:"flex items-center justify-center space-x-4",children:[t.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:t.jsx(ce.Icon,{icon:"mdi:music",className:"text-gray-400 w-10 h-10"})}),t.jsx(dt,{type:"button",onClick:E,variant:"outlined",children:t.jsx("span",{children:"Choose Audio File"})}),s&&t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop your audio file here"})]})}),s&&l&&!p&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-lg",children:t.jsx("span",{className:"text-blue-600 dark:text-blue-400 font-semibold text-lg bg-white dark:bg-gray-800 px-4 py-2 rounded-lg shadow-lg",children:"Drop audio here"})})]})]},c)},Qe=({src:n,alt:a="preview",isOpen:e,setIsOpen:r})=>{const o=()=>r(!1);return b.useEffect(()=>{const i=s=>{s.key==="Escape"&&o()};return e&&(document.body.style.overflow="hidden",document.addEventListener("keydown",i)),()=>{document.body.style.overflow="",document.removeEventListener("keydown",i)}},[e]),t.jsx(t.Fragment,{children:t.jsxs("div",{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 dark:bg-black/80 \r
|
|
137
|
+
backdrop-blur-sm animate-in fade-in duration-200`,onClick:o,children:[t.jsx("button",{onClick:o,className:`absolute top-4 right-4 bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200\r
|
|
138
|
+
hover:bg-gray-100 dark:hover:bg-gray-700 rounded-full p-2 shadow-lg transition`,children:t.jsx(U.X,{size:20})}),t.jsx("div",{className:"max-w-5xl w-full px-4 transform transition-all duration-200 scale-95 animate-in zoom-in-95",onClick:i=>i.stopPropagation(),children:t.jsx("img",{src:n,alt:a,className:"w-full max-h-[90vh] object-contain rounded-xl"})})]})})},Ct=({col:n,data:a})=>{const e=a[n.titleKey],r=a[n.subtitleKey],o=a[n.imageKey],i=n.fallback_icon,[s,c]=b.useState(null),[f,d]=b.useState(!1),p=h=>{let l=h;h&&h.src instanceof File&&(l={...h,src:URL.createObjectURL(h.src)}),c(l),d(!0)};return t.jsxs(t.Fragment,{children:[f&&s&&t.jsx(Qe,{src:s.src,alt:s.alt,isOpen:f,setIsOpen:d}),t.jsxs("div",{className:`col-span-12 flex items-center space-x-4 p-4 rounded-xl
|
|
46
139
|
bg-gray-100 dark:bg-gray-900
|
|
47
|
-
${n.blockClass}`,children:[o?
|
|
140
|
+
${n.blockClass}`,children:[o?t.jsx("img",{src:o instanceof File?URL.createObjectURL(o):o,alt:e,onClick:()=>p({src:o,alt:e}),className:"w-16 h-16 cursor-pointer rounded-full object-cover border-2 border-gray-200 dark:border-gray-700"}):i?i instanceof Function?i(a):i:t.jsx("div",{className:"w-16 h-16 flex items-center justify-center rounded-full border-2 border-gray-300 dark:border-gray-700 bg-gray-200 dark:bg-gray-600",children:t.jsx(U.User,{className:"w-8 h-8 text-gray-400"})}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:e}),t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:r})]})]})]})},Dt=({col:n,data:a})=>{const e=a[n.titleKey],r=a[n.subtitleKey],o=a[n.imageKey],i=n.label,s=n==null?void 0:n.icon,c=n.fallback_icon,[f,d]=b.useState(null),[p,h]=b.useState(!1),l=m=>{let g=m;m&&m.src instanceof File&&(g={...m,src:URL.createObjectURL(m.src)}),d(g),h(!0)};return t.jsxs(t.Fragment,{children:[p&&f&&t.jsx(Qe,{src:f.src,alt:f.alt,isOpen:p,setIsOpen:h}),t.jsxs("div",{className:`col-span-12 flex items-center space-x-4 p-4 rounded-xl
|
|
48
141
|
bg-gray-100 dark:bg-gray-900
|
|
49
|
-
${n.blockClass}`,children:[
|
|
50
|
-
${
|
|
51
|
-
${
|
|
52
|
-
${
|
|
53
|
-
bg-gray-100 dark:bg-gray-900 ${n.blockClass||""}`,children:[
|
|
142
|
+
${n.blockClass}`,children:[s&&t.jsx("div",{className:"flex-shrink-0",children:s}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:i}),t.jsxs("div",{className:"flex items-center",children:[o?t.jsx("img",{src:o instanceof File?URL.createObjectURL(o):o,alt:e,onClick:()=>l({src:o,alt:e}),className:"w-8 h-8 cursor-pointer rounded-full object-cover border-2 border-gray-200 dark:border-gray-700"}):c?c instanceof Function?c(a):c:t.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",children:t.jsx(U.User,{className:"w-6 h-6 text-gray-400"})}),t.jsxs("div",{className:"ml-2",children:[t.jsx("p",{className:"mb-0 text-sm text-gray-900 dark:text-white break-words",children:e}),t.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:r})]})]})]})]})]})},ut={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"}},ht={contained:"bg",outline:"border !bg-transparent",soft:"bg opacity-90"},Et=({label:n,variant:a="contained",color:e="green",className:r=""})=>{const o=ut[e]||ut.green,i=ht[a]||ht.contained,s=a==="outline"?o.border:o.bg;return t.jsx("span",{className:`inline-flex justify-center items-center rounded-sm text-xs font-semibold px-3 py-1 min-w-[78px]
|
|
143
|
+
${s}
|
|
144
|
+
${i}
|
|
145
|
+
${r}`,children:n})},_t=({col:n,data:a})=>{var f;const e=n==null?void 0:n.icon,r=n.label;let o=a[n.key];const i=n.type,s=n.variant||"outline";let c=n.defaultColor;if(i==="chip"&&((f=n.chipOptions)==null?void 0:f.length)>0){const d=n==null?void 0:n.chipOptions.find(p=>p.value==o);d&&(o=d.label,c=d.color)}return t.jsxs("div",{className:`col-span-12 flex items-center space-x-4 p-4 rounded-xl
|
|
146
|
+
bg-gray-100 dark:bg-gray-900 ${n.blockClass||""}`,children:[e&&t.jsx("div",{className:"flex-shrink-0",children:e}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:r}),i==="chip"?t.jsx(Et,{label:o,variant:s,color:c,className:"mt-1"}):i==="tinyEditor"?t.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-white break-words",dangerouslySetInnerHTML:{__html:o}}):i==="audio"?o?t.jsx("audio",{controls:!0,src:o instanceof File?URL.createObjectURL(o):o,onClick:d=>d.stopPropagation(),className:"shadow-md rounded-full mt-1"},o instanceof File?URL.createObjectURL(o):o):t.jsx("p",{className:"mt-1 text-sm text-gray-400",children:"N/A"}):t.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-white break-words",children:i=="date"?t.jsx("span",{children:gt(o,n.format||"DD MMM YYYY")}):o||"N/A"})]})]})},kr=({value:n=!0,onChange:a,text:e,options:r=[],label:o,required:i,name:s="",disabled:c=!1,parentClass:f=""})=>{const d=r.length>0?r:[{label:"Active",value:!0},{label:"Inactive",value:!1}];return t.jsx(t.Fragment,{children:t.jsxs("div",{className:f||"col-span-12",children:[t.jsx(Q,{label:o,required:i}),t.jsxs("div",{className:"flex items-center justify-between h-10 gap-4 bg-gray-100 dark:bg-gray-700 px-3 rounded-md border border-gray-100 dark:border-gray-600",children:[e&&t.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap max-w-[200px]",children:e}),t.jsx("div",{className:"flex items-center gap-6",children:d.map((p,h)=>t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"radio",name:"switch-field",required:i&&h===0,value:String(p.value),disabled:c,checked:n===p.value,onChange:()=>a==null?void 0:a(p.value),className:"w-4 h-4 border-gray-300 cursor-pointer"}),t.jsx("span",{className:"text-sm text-gray-700 dark:text-white",children:p.label})]},h))})]})]},s)})},pt=ae,Sr=({label:n="",value:a=null,onChange:e,required:r=!1,accept:o="video/*",id:i,dragDrop:s=!1,name:c="",parentClass:f="",maxSize:d=0})=>{const[p,h]=b.useState(null),[l,m]=b.useState(!1),g=b.useRef(null),j=d*1024*1024;b.useEffect(()=>{if(!a){v(),h(null);return}if(a instanceof File){const x=URL.createObjectURL(a);return h({file:a,preview:x}),()=>{URL.revokeObjectURL(x)}}else typeof a=="string"?h({preview:a}):a!=null&&a.preview&&h(a)},[a]);const v=()=>{p!=null&&p.preview&&p.preview.startsWith("blob:")&&URL.revokeObjectURL(p.preview)},R=x=>{if(!x||x.length===0)return;const w=x[0];if(j&&w.size>j){le.enqueueSnackbar(`File is too large. Maximum allowed size is ${d} MB`,{variant:"warning"});return}const S=URL.createObjectURL(w);v(),h({file:w,preview:S}),e==null||e(w)},A=x=>{x&&x.stopPropagation(),v(),h(null),e==null||e(null),g.current&&(g.current.value="")},L=x=>{s&&(x.preventDefault(),m(!0))},C=x=>{s&&(x.preventDefault(),m(!1))},I=x=>{var w,S,D,P;s&&(x.preventDefault(),m(!1),(P=(D=(S=(w=x.dataTransfer)==null?void 0:w.files)==null?void 0:S[0])==null?void 0:D.type)!=null&&P.includes("video/")&&R(x.dataTransfer.files))},E=()=>{var x;(x=g.current)==null||x.click()};return t.jsxs("div",{className:f||"col-span-12",children:[t.jsx(Q,{label:n,required:r}),t.jsxs("div",{className:`relative rounded-lg p-2 transition-all ${l?"border-2 border-dashed border-blue-500 bg-blue-50 dark:bg-blue-900/20":"border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800"}`,onDragOver:L,onDragLeave:C,onDrop:I,children:[t.jsx("input",{ref:g,id:i,type:"file",accept:o,onChange:x=>R(x.target.files),required:r&&!p,className:"absolute opacity-0 pointer-events-none h-[10px]"}),t.jsx("div",{className:`flex items-center space-x-4 transition-all ${l?"opacity-50":""}`,children:p?t.jsxs("div",{className:"flex items-center space-x-4",children:[t.jsxs("div",{className:"relative",children:[!r&&t.jsx("button",{type:"button",onClick:A,className:"absolute -top-2 -right-2 bg-red-500 text-white rounded-full p-1 shadow hover:bg-red-600 z-10",children:t.jsx(ce.Icon,{icon:"mdi:close",className:"w-3 h-3"})}),t.jsx("video",{src:p.preview,controls:!0,controlsList:"nodownload",className:"w-[260px] h-[150px] rounded-md object-cover"},p.preview)]}),t.jsx(pt,{type:"button",onClick:E,children:"Change Video File"})]}):t.jsxs("div",{className:"flex items-center justify-center space-x-4",children:[t.jsx("div",{className:"rounded-full bg-gray-100 dark:bg-gray-700 h-20 w-20 flex items-center justify-center",children:t.jsx(ce.Icon,{icon:"mdi:video",className:"text-gray-400 w-10 h-10"})}),t.jsx(pt,{type:"button",onClick:E,variant:"outlined",children:"Choose Video File"}),s&&t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"or drag and drop your video here"})]})}),s&&l&&!p&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none bg-blue-500/10 rounded-lg",children:t.jsx("span",{className:"text-blue-600 dark:text-blue-400 font-semibold text-lg bg-white dark:bg-gray-800 px-4 py-2 rounded-lg shadow-lg",children:"Drop video here"})})]})]},c)},Pt=({field:n,formData:a,handleChange:e})=>{const{key:r,label:o,type:i,options:s,placeholder:c,rows:f,inputClass:d,search:p,accept:h,text:l,required:m=!1,minLength:g,dragDrop:j,parentClass:v,countriesList:R,defaultCountry:A,multiple:L,dropdownMaxHeight:C,editorKey:I,fontFamily:E,disabled:x,negativeNumberAllow:w,defaultValue:S,renderCondition:D,pattern:P,renderType:Y,cropImage:ee,aspectRatio:K,dependencyKey:N,mask:X,maskApplyOnValue:B,maxSize:M}=n;let k=a==null?void 0:a[r];k==null&&(k="");const z=c||(i==="select"?`Select ${o}`:`Enter ${o}`),H="w-full px-3 py-2 rounded-md border border-gray-300 dark:border-gray-600 text-sm focus:outline-none focus:ring-1 focus:ring-blue-200 bg-white text-black dark:bg-gray-700 dark:text-white";if(D&&typeof D=="function"&&!D(a))return null;if(Y&&Y=="details")switch(i){case"group":return t.jsx(Ct,{col:n,data:a});case"cardGroup":return t.jsx(Dt,{col:n,data:a});default:return t.jsx(_t,{col:n,data:a})}switch(i){case"select":return t.jsx(zt,{options:s||[],value:k,formData:a,dependencyKey:N,onChange:F=>e(r,F),placeholder:z,className:d||"",search:p,required:m,defaultValue:S,label:o||"",name:r,disabled:x,parentClass:v||"",multiple:L,dropdownMaxHeight:C});case"checkbox":return t.jsx(wr,{name:r,label:o||"",options:s||[],value:k,onChange:F=>e(r,F),required:m,parentClass:v||"",className:d||"",multiSelect:L,disabled:x});case"radio":return t.jsx(kr,{value:k,onChange:F=>e(r,F),text:l,options:s||[],label:o||"",required:m,name:r,disabled:x,parentClass:v||""});case"switch":return t.jsx(mt,{value:!!k,onChange:F=>e(r,F),label:o||"",required:m,name:r,disabled:x,className:"",parentClass:v||""});case"phone":return t.jsx(Bt,{value:k,onChange:F=>e(r,F),countriesList:R,defaultCountry:A,required:m,placeholder:z,search:p,label:o||"",name:r,disabled:x,parentClass:v||""});case"textarea":return t.jsx(xt,{value:k,onChange:F=>e(r,F.target.value),placeholder:z,rows:f||3,className:`${H} ${d||""}`,required:m,name:r,label:o||"",disabled:x,parentClass:v||""});case"image":return t.jsx(yr,{value:k,onChange:F=>e(r,F),required:m,accept:h||"image/*",aspect:K,id:`file-${r}`,dragDrop:j,cropImage:ee,label:o||"",name:r,parentClass:v||""});case"audio":return t.jsx(jr,{value:k,onChange:F=>e(r,F),required:m,accept:h||"audio/*",id:`file-${r}`,dragDrop:j,label:o||"",name:r,parentClass:v||"",maxSize:M});case"video":return t.jsx(Sr,{value:k,onChange:F=>e(r,F),required:m,accept:h||"video/*",id:`file-${r}`,dragDrop:j,label:o||"",name:r,maxSize:M,parentClass:v||""});case"tinyEditor":return t.jsx(vr,{value:k,onChange:F=>e(r,F),required:m,placeholder:z,label:o||"",parentClass:v||"",fontFamily:E,editorKey:I||"",disabled:x});default:return t.jsx(Rt,{field:n,type:i||"text",defaultValue:S,value:k,onChange:F=>e(r,F),placeholder:z,className:`${H} ${d||""}`,required:m,name:r,minLength:g,label:o||"",negativeNumberAllow:w,parentClass:v||"",disabled:x,pattern:P,mask:X,maskApplyOnValue:B})}},Nr=({isOpen:n,onClose:a,config:e,onApply:r})=>{var p;const[o,i]=b.useState({}),s=(h,l)=>{i(m=>({...m,[h]:l}))},c=()=>{r(o),a()},f=()=>{i({}),r({}),a()},d=e==null?void 0:e.component;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`fixed inset-0 bg-black/50 z-40 transition-opacity duration-300 ${n?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none"}`,onClick:a}),t.jsxs("div",{className:`fixed top-0 right-0 h-full w-[28rem] bg-white dark:bg-gray-900 shadow-2xl z-50 flex flex-col border-l border-gray-200 dark:border-gray-700
|
|
54
147
|
transform transition-transform duration-300 ease-in-out
|
|
55
148
|
${n?"translate-x-0":"translate-x-full"}
|
|
56
|
-
`,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Filters"}),e.jsx("button",{onClick:l,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md transition",children:e.jsx($.X,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),n&&e.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:r!=null&&r.component?e.jsx(r.component,{filters:o,onFilterChange:a}):e.jsx("div",{className:"space-y-4",children:(c=r==null?void 0:r.fields)==null?void 0:c.map(b=>e.jsx(e.Fragment,{children:e.jsx($e,{field:b,formData:o,handleChange:a},b.key)}))})}),e.jsxs("div",{className:"flex gap-2 px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:[e.jsx(Z,{onClick:y,variant:"contained",color:"primary",fullWidth:!0,children:"Apply Filters"}),e.jsx(Z,{onClick:N,variant:"contained",className:"min-w-[150px]",children:"Reset"})]})]})]})},tt=({rows:n=5,columns:l=5})=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-full mb-6 inline-flex justify-end items-center",children:e.jsx("div",{className:"h-8 w-80 bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})}),e.jsx("div",{className:"overflow-hidden rounded-md border border-gray-200 dark:border-gray-800",children:e.jsxs("table",{className:"w-full border-collapse",children:[e.jsx("thead",{children:e.jsx("tr",{className:"bg-gray-50 dark:bg-gray-900",children:Array.from({length:l}).map((r,i)=>e.jsx("th",{className:"px-4 py-3",children:e.jsx("div",{className:"h-6 w-24 bg-gray-300 dark:bg-gray-700 rounded animate-pulse inline-flex justify-center items-center"})},i))})}),e.jsx("tbody",{children:Array.from({length:n}).map((r,i)=>e.jsx("tr",{className:"border-t border-gray-200 dark:border-gray-800",children:Array.from({length:l}).map((o,d)=>e.jsx("td",{className:"px-4 py-6",children:e.jsx("div",{className:"h-6 w-full bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})},d))},i))})]})})]}),at=({config:n,setShowAdd:l,title:r,buttonText:i,description:o,showAddButton:d})=>{const{data:a=[],table_head:y=[],loading:N=!1,search:c={enabled:!1,placeholder:"Search...",useServerSideSearch:!1},filter:b={enabled:!1,useServerSideFilters:!1},pagination:u={enabled:!1,rows_per_page:10,useServerSidePagination:!1},emptyMessage:v="No data available",onMenuAction:m,setServerSidePaginationData:g=()=>{},onFilterApply:w,filterConfig:f=null,rowClick:S=null}=n,[A,P]=h.useState(""),[C,R]=h.useState(null),[E,F]=h.useState([]),[L,D]=h.useState({}),[U,G]=h.useState(!1),[W,V]=h.useState({}),[I,K]=h.useState(null),[H,O]=h.useState(!1),k=h.useMemo(()=>!c.enabled||!A.trim()||c.useServerSideSearch?a:Ye(a,A,c.searchKeys||[]),[a,A,c]),[T,Y]=h.useState(1),[_,Q]=h.useState((u==null?void 0:u.rows_per_page)||50),[J,we]=h.useState(k.length||0),re=u!=null&&u.useServerSidePagination?u.total_pages:Math.ceil(k.length/_),ie=h.useMemo(()=>{if(u.useServerSidePagination)return k;const t=(T-1)*_;return k.slice(t,t+_)},[k,T,_]),ee=h.useRef(null),ne=h.useRef({}),te=h.useRef(null),de=t=>{P(t),Y(1),c.useServerSideSearch&&(te.current&&clearTimeout(te.current),te.current=setTimeout(async()=>{try{await g(x=>({...x,search:t,current_page:1}))}catch(x){console.error("Search error:",x)}},800))},ce=(t,x,p)=>{p.stopPropagation(),R(null),m==null||m(t.type,x)},ue=(t,x,p)=>{x.stopPropagation(),F(p);const j=x.currentTarget;ne.current[t]=j;const M=j.getBoundingClientRect(),z=192,B=p.length*40,je=window.innerWidth,Re=window.innerHeight,Ke=je-M.right<z?M.left-z+M.width:M.left,_e=Re-M.bottom<B&&M.top>B?M.top-B-2:M.bottom+2;D({top:Math.max(8,Math.min(_e,Re-B-8)),left:Math.max(8,Math.min(Ke,je-z-8))}),R(C===t?null:t)},he=t=>(T-1)*_+t+1,be=t=>{t&&t.src instanceof File&&(t={...t,src:URL.createObjectURL(t.src)}),K(t),O(!0)},se=(t,x,p,j=null,M=null)=>e.jsx(e.Fragment,{children:t?e.jsx("img",{src:t instanceof File?URL.createObjectURL(t):t,alt:x||"Avatar",onClick:z=>{z.stopPropagation(),z.preventDefault(),be({src:t,alt:x})},className:`w-10 h-10 cursor-pointer shrink-0 rounded-full object-cover border border-gray-200 dark:border-gray-700 ${p||""}`}):e.jsx(e.Fragment,{children:j?typeof j=="function"?j(M):j:e.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 ${p||""}`,children:e.jsx($.User,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),pe=(t,x)=>e.jsx(e.Fragment,{children:t?e.jsx("audio",{controls:!0,src:t instanceof File?URL.createObjectURL(t):t,onClick:p=>{p.stopPropagation()},className:`w-64 cursor-pointer ${x||""}`},t instanceof File?URL.createObjectURL(t):t):e.jsx(e.Fragment,{children:e.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 ${x||""}`,children:e.jsx($.Music,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),ge=(t,x)=>e.jsxs("div",{className:`flex items-center space-x-4 ${x.className||""}`,children:[x.imageKey?se(t[x.imageKey],t[x.titleKey],"group-avatar",x.fallback_icon,t):"",e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-gray-900 dark:text-white group-title",children:t[x.titleKey]||""}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 group-sub-title",children:t[x.subtitleKey]||""})]})]}),xe=(t,x)=>{var z;let p=String(t);const j=x.variant||"contained";let M=x.defaultColor;if(((z=x==null?void 0:x.chipOptions)==null?void 0:z.length)>0){let B=x==null?void 0:x.chipOptions.find(je=>je.value==t);B&&(p=B.label,M=B.color)}return e.jsx(Be,{label:p,variant:j,color:M,className:x.className||""})},me=(t,x,p)=>{const j=x[t.key];return t.type==="menu_actions"?e.jsx("div",{className:`text-center ${t.className||""}`,children:e.jsx("button",{ref:M=>ne.current[x.id||x._id]=M,onClick:M=>ue(x.id||x._id,M,t.menuList),className:"p-2 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-full transition text-gray-700 dark:text-gray-300",children:e.jsx($.EllipsisVertical,{className:"h-4 w-4"})})}):t.type==="index"?e.jsx("span",{className:t.className||"",children:he(p)}):t.type==="group"?ge(x,t):t.type==="chip"?e.jsx(e.Fragment,{children:xe(j,t)}):t.type==="date"?e.jsx("span",{className:t.className||"",children:Ie(j,t.format||"DD MMM YYYY")}):t.type==="avatar"?e.jsx(e.Fragment,{children:e.jsx("div",{className:"min-w-[40px]",children:se(j,t.alt,t.className,t.fallback_icon,x)})}):t.type==="audio"?e.jsx(e.Fragment,{children:pe(j,t.className)}):e.jsx("span",{className:t.className||"",children:j||"N/A"})},fe=t=>{if(typeof S=="function")return S(t);if(S)return m==null?void 0:m("view",t)},ye=(t,x)=>{if(t.onClickDetails)return m==null?void 0:m("view",x);if(typeof t.handleClick=="function")return t.handleClick(x)},le=()=>S||typeof S=="function",oe=t=>t.onClickDetails||typeof t.handleClick=="function";return h.useEffect(()=>{const t=()=>{C&&R(null)};return window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("scroll",t,!0)}},[C]),h.useEffect(()=>{const t=x=>{ee.current&&!ee.current.contains(x.target)&&R(null)};return document.addEventListener("click",t),()=>document.removeEventListener("click",t)},[]),h.useEffect(()=>{u!=null&&u.rows_per_page&&(u!=null&&u.useServerSidePagination)&&Q((u==null?void 0:u.rows_per_page)||50),u.current_page&&Y(u.current_page)},[u.rows_per_page,u==null?void 0:u.useServerSidePagination,u.current_page]),h.useEffect(()=>{we(u!=null&&u.useServerSidePagination?u.total_records:k.length),k.length<=_*(T-1)&&!(u!=null&&u.useServerSidePagination)&&Y(t=>t-1||1)},[k.length,u.total_records,u==null?void 0:u.useServerSidePagination]),e.jsxs(e.Fragment,{children:[N?e.jsx(tt,{rows:6,columns:6}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between gap-4 mb-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:r}),e.jsx("p",{className:"text-md text-gray-600 dark:text-gray-400",children:o})]}),e.jsxs("div",{className:"flex flex-col justify-end items-end gap-2",children:[d&&e.jsxs(Z,{onClick:()=>l(!0),variant:"contained",color:"primary",children:[e.jsx($.Plus,{className:"w-4 h-4 mr-2"}),i||"Add New"]}),e.jsxs("div",{className:"flex justify-end items-center gap-2",children:[c.enabled&&e.jsx("div",{className:"",children:e.jsxs("div",{className:"relative min-w-[300px]",children:[e.jsx($.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400 dark:text-gray-300"}),e.jsx("input",{type:"text",placeholder:c.placeholder||"Search...",value:A,onChange:t=>de(t.target.value),className:"w-full h-[36px] pl-9 pr-4 py-3 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-gray-50 dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-1 focus:ring-blue-300 dark:ring-blue-200 disabled:opacity-50"})]})}),f&&b.enabled&&e.jsxs("div",{className:"relative",children:[e.jsxs(Z,{onClick:()=>G(!0),variant:"contained",children:[e.jsx($.Filter,{className:"w-4 h-4 mr-2"}),"Filters"]}),Object.keys(W).length>0&&e.jsx("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]})]})]})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow overflow-hidden border border-gray-200 dark:border-gray-700",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-700/60",children:e.jsx("tr",{children:y.map(t=>e.jsx("th",{className:`px-6 py-4 text-left text-xs font-medium text-black dark:text-white uppercase tracking-wider min-w-max max-w-[180px] truncate ${t.headClass||""}`,children:t.title},t.key))})}),e.jsx("tbody",{className:"bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700",children:ie.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:y.length,className:"text-center py-10 text-gray-500 dark:text-gray-400",children:v})}):ie.map((t,x)=>e.jsx("tr",{className:`hover:bg-gray-50 dark:hover:bg-blue-800/10 transition ${le()?"cursor-pointer":""}`,onClick:p=>{le()&&fe(t)},children:y.map(p=>e.jsx("td",{className:`px-6 py-4 text-sm text-gray-900 dark:text-gray-100 min-w-max ${p.type=="audio"?"":"max-w-[300px]"} truncate ${oe(p)?"cursor-pointer":""}`,title:String(t[p.key]??""),onClick:j=>{oe(p)&&(j.stopPropagation(),j.preventDefault(),ye(p,t))},children:p.render?p.render(t,x):me(p,t,x)},p.key))},t.id||t._id||x))})]})}),(u==null?void 0:u.enabled)&&k.length>0&&e.jsxs("div",{className:" bg-gray-50 dark:bg-gray-700/60 px-6 py-3 flex flex-wrap items-center justify-between border-t border-gray-200 dark:border-gray-600 gap-3",children:[e.jsxs("div",{className:"text-sm text-gray-700 dark:text-gray-300",children:["Showing ",(T-1)*_+1," to"," ",Math.min(T*_,J)," of"," ",J," results"]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:"Rows per page:"}),e.jsx("select",{value:_,onChange:t=>{const x=Number(t.target.value);Q(x),Y(1),u.useServerSidePagination&&g(p=>({...p,current_page:1,rows_per_page:x}))},className:"border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm rounded-md px-2 py-1 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[2,10,25,50,100].map(t=>e.jsx("option",{value:t,children:t},t))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{if(T>1){const t=T-1;Y(t),u.useServerSidePagination&&g(x=>({...x,current_page:t}))}},disabled:T===1,className:"p-2 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-md transition text-gray-500 dark:text-gray-300 disabled:opacity-50",children:e.jsx($.ChevronLeft,{className:"h-4 w-4"})}),e.jsxs("span",{className:"text-sm text-gray-800 dark:text-gray-200",children:["Page ",T," of ",re]}),e.jsx("button",{onClick:()=>{if(T<re){const t=T+1;Y(t),u.useServerSidePagination&&g(x=>({...x,current_page:t}))}},disabled:T===re,className:"p-2 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-md transition text-gray-500 dark:text-gray-300 disabled:opacity-50",children:e.jsx($.ChevronRight,{className:"h-4 w-4"})})]})]})]})]})]}),C&&ze.createPortal(e.jsx("div",{ref:ee,style:{position:"fixed",top:`${L.top}px`,left:`${L.left}px`,zIndex:9999},className:"w-48 bg-white dark:bg-gray-700 rounded-md shadow-lg border border-gray-200 dark:border-gray-600",children:E.map((t,x)=>e.jsxs("button",{onClick:p=>ce(t,a.find(j=>j.id===C||j._id==C),p),className:`w-full flex items-center gap-2 px-4 py-2 text-sm text-left hover:bg-gray-100 dark:hover:bg-gray-600 ${t.variant==="danger"?"text-red-600 dark:text-red-500":"text-gray-700 dark:text-gray-200"}`,children:[t.icon&&e.jsx("span",{className:"shrink-0",children:t.icon}),t.title]},x))}),document.body),f&&e.jsx(et,{isOpen:U,onClose:()=>G(!1),config:f,onApply:t=>{V(t),w==null||w(t)}}),H&&e.jsx(Ce,{src:I.src,alt:I.alt,isOpen:H,setIsOpen:O})]})},ke=({isOpen:n,onClose:l,icon:r,title:i,children:o,size:d="md",actionButtons:a=[],actions:y,showDefaultClose:N=!0,footerConfig:c=null,hideFooter:b=!1,onFormSubmit:u=()=>{},onCancel:v,loadingBtn:m=!1,executeFunction:g=()=>{},selectedItem:w=null})=>{if(!n)return null;const f={sm:"max-w-md",md:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-full"};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-gray-500 opacity-75",onClick:()=>l()}),e.jsxs("div",{className:`relative bg-white rounded-lg shadow-xl w-full ${f[d]||f.md} max-h-[90vh] flex flex-col dark:bg-gray-800`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[r&&e.jsx("span",{children:r}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:i})]}),e.jsx("button",{onClick:()=>l(),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx($.X,{className:"w-6 h-6"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:o}),a.length>0&&e.jsx("div",{className:"px-4 py-3 flex justify-end gap-3 border-t border-gray-200 dark:border-gray-700 sm:px-6",children:a.map(S=>e.jsx(Z,{onClick:A=>{S.type=="submit"?u(A):g(()=>{var P;return(P=S==null?void 0:S.onClick)==null?void 0:P.call(S,A,w)},P=>l==null?void 0:l(P))},disabled:m||S.disabled,variant:S.variant||"contained",color:S.color||"primary",className:`min-w-[100px] ${S.className}`,type:S.type||"button",children:m?e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-2 border-t-white mr-2"}),S.label||"Submit","..."]}):S.label||"Submit"}))})]})]})},Oe=({config:n,onSubmit:l,initialData:r={},fetchRowDetails:i,type:o="add"})=>{const{formClass:d="grid grid-cols-12 gap-4",formFields:a=[]}=n||{},[y,N]=h.useState(r),[c,b]=h.useState(!0),u=async()=>{i==null||i(r).then(g=>{N(g.data)}).catch(g=>{X.enqueueSnackbar(g.message,{variant:"error"})}).finally(()=>{b(!1)})};h.useEffect(()=>{i instanceof Function?u():(N(r),b(!1))},[]);const v=(g,w)=>{N(f=>({...f,[g]:w}))},m=g=>{g.preventDefault();const w=g.target;if(!w.checkValidity()){w.reportValidity();return}l(y)};return c?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"rounded-full border-4 border-blue-500 border-t-gray-200 animate-spin w-8 h-8 border-4",style:{borderTopColor:"border-primary-500"}})}):e.jsx("form",{id:o=="add"?"addForm":o=="edit"?"editForm":"defaultForm",onSubmit:m,className:d,noValidate:!1,children:a.map(g=>e.jsx(e.Fragment,{children:e.jsx($e,{field:g,formData:y,handleChange:v},g.key)}))})};function rt({data:n,config:l,fetchRowDetails:r}){const{fields:i,containerClass:o}=l,[d,a]=h.useState(n),[y,N]=h.useState(!0),c=async()=>{r==null||r(n).then(b=>{a(b.data)}).catch(b=>{X.enqueueSnackbar(b.message,{variant:"error"})}).finally(()=>{N(!1)})};return h.useEffect(()=>{r instanceof Function?c():(a(n),N(!1))},[]),y?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"rounded-full border-4 border-blue-500 border-t-gray-200 animate-spin w-8 h-8 border-4",style:{borderTopColor:"border-primary-500"}})}):e.jsx(e.Fragment,{children:e.jsx("div",{className:`grid grid-cols-12 gap-4 ${o||""}`,children:i.map(b=>b.renderCondition&&typeof b.renderCondition=="function"&&!b.renderCondition(d)?null:b.type=="group"?e.jsx(De,{col:b,data:d}):b.type=="cardGroup"?e.jsx(Ee,{col:b,data:d}):e.jsx(Ue,{col:b,data:d}))})})}const Ge=({config:n})=>{var ee,ne,te,de,ce,ue,he,be,se,pe,ge,xe,me,fe,ye,le,oe,t,x;const{title:l,fetchData:r=async()=>{},fetchRowDetails:i=null,isStaticData:o=!1,tableConfig:d={},modalConfig:a={},filterConfig:y}=n,[N,c]=h.useState(!0),[b,u]=h.useState(!1),[v,m]=h.useState([]),[g,w]=h.useState(null),[f,S]=h.useState({search:"",rows_per_page:50,current_page:1}),[A,P]=h.useState({}),[C,R]=h.useState(!1),[E,F]=h.useState(!1),[L,D]=h.useState(!1),[U,G]=h.useState(!1),[W,V]=h.useState(!1),[I,K]=h.useState(null),H=(p,j)=>{p==="edit"?(K(j),D(!0)):p==="view"?(K(j),V(!0)):p==="delete"&&(K(j),G(!0))},O=async(p,j,M="",z="")=>{u(!0);try{const B=await(p==null?void 0:p());(M||B.message)&&X.enqueueSnackbar(M||B.message,{variant:"success"}),j==null||j(B)}catch(B){(z||B.message)&&X.enqueueSnackbar(z||B.message,{variant:"error"})}finally{u(!1)}},k=p=>{let j=p.newObject;o?(m(M=>[j,...M]),w(M=>({...M,current_page:1}))):(S(M=>({...M,current_page:1})),f.current_page==1&&J()),F(!1)},T=p=>{let j=p.newObject,M=p.targetObject;o?m(z=>z.map(B=>B.id===M.id?{...B,...j}:B)):J(),D(!1)},Y=p=>{if(!p){G(!1),K(null);return}o?m(j=>j.filter(M=>M.id!==p.targetObject.id)):v.length==1&&f.current_page>1?S(j=>({...j,current_page:j.current_page-1})):J(),G(!1),K(null)},_=p=>O(()=>{var j,M;return(M=(j=a==null?void 0:a.addModal)==null?void 0:j.handleSubmit)==null?void 0:M.call(j,p)},k),Q=p=>O(()=>{var j,M;return(M=(j=a==null?void 0:a.editModal)==null?void 0:j.handleSubmit)==null?void 0:M.call(j,p,I)},T),J=async()=>{c(!0),r==null||r({...f,...A}).then(p=>{m(p.data),w(p.pagination)}).catch(p=>{X.enqueueSnackbar(p.message,{variant:"error"})}).finally(()=>{c(!1)})},we=p=>{var j;P(M=>({...p})),(j=d==null?void 0:d.filter)!=null&&j.useServerSideFilters&&R(M=>!M)},re=(p,j)=>p.filter(M=>Object.entries(j).every(([z,B])=>M[z]===B)),ie=h.useMemo(()=>{var p;return(p=d==null?void 0:d.filter)!=null&&p.useServerSideFilters?v:re(v,A)},[v,A]);return h.useEffect(()=>{J()},[f.search,f.rows_per_page,f.current_page,C]),e.jsxs("div",{children:[e.jsx(at,{title:l,setShowAdd:F,description:n.description,buttonText:n.buttonText,showAddButton:!!a.addModal,config:{...d,pagination:{...d.pagination,...g},data:ie,setServerSidePaginationData:S,onMenuAction:H,filterConfig:y,onFilterApply:we,loading:N}}),e.jsx(ke,{isOpen:E,onClose:()=>{b||F(!1)},icon:(ee=a.addModal)==null?void 0:ee.icon,title:((ne=a.addModal)==null?void 0:ne.title)||"Add New",size:((te=a.addModal)==null?void 0:te.size)||"md",onFormSubmit:()=>{var p;return(p=document.querySelector("#addForm"))==null?void 0:p.requestSubmit()},loadingBtn:b,actionButtons:((de=a==null?void 0:a.addModal)==null?void 0:de.actionButtons)||[],children:e.jsx(Oe,{config:(a==null?void 0:a.addModal)||{},onSubmit:_,initialData:{},type:"add",loading:b})}),e.jsx(ke,{isOpen:L,onClose:()=>{b||D(!1)},icon:(ce=a.editModal)==null?void 0:ce.icon,title:((ue=a.editModal)==null?void 0:ue.title)||"Edit",size:((he=a.editModal)==null?void 0:he.size)||"md",onFormSubmit:()=>{var p;return(p=document.querySelector("#editForm"))==null?void 0:p.requestSubmit()},actionButtons:((be=a==null?void 0:a.editModal)==null?void 0:be.actionButtons)||[],loadingBtn:b,children:e.jsx(Oe,{config:a.editModal||{},onSubmit:Q,initialData:I,type:"edit",loading:b,fetchRowDetails:i})}),U&&e.jsx(ke,{isOpen:U,onClose:p=>{Y(p)},icon:((se=a.deleteModal)==null?void 0:se.icon)||e.jsx(ae.Icon,{icon:"ph:warning-bold",className:"w-6 h-6 text-red-500"}),title:((pe=a.deleteModal)==null?void 0:pe.title)||"Confirm Delete",size:((ge=a.deleteModal)==null?void 0:ge.size)||"md",loading:b,actionButtons:((xe=a==null?void 0:a.deleteModal)==null?void 0:xe.actionButtons)||[],executeFunction:O,selectedItem:I,children:e.jsx("div",{className:"flex items-center space-x-2 py-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-md text-gray-700 dark:text-white",children:((me=a.deleteModal)==null?void 0:me.confirmText)||"Are you sure you want to delete this item?"}),((fe=a.deleteModal)==null?void 0:fe.referenceKey)&&e.jsx("p",{className:"text-md font-semibold text-gray-700 dark:text-white",children:I[(ye=a.deleteModal)==null?void 0:ye.referenceKey]})]})})}),a.viewModal&&e.jsx(ke,{isOpen:W,onClose:()=>{V(!1),K(null)},icon:(le=a.viewModal)==null?void 0:le.icon,title:((oe=a.viewModal)==null?void 0:oe.title)||"View Details",size:((t=a.viewModal)==null?void 0:t.size)||"lg",footerConfig:a==null?void 0:a.viewModal.footer,children:(x=a.viewModal)!=null&&x.component?e.jsx(a.viewModal.component,{data:I}):e.jsx(rt,{data:I,fetchRowDetails:i,config:a.viewModal||{}})})]})},Me=s.shape({value:s.oneOfType([s.string,s.number,s.bool]).isRequired,label:s.string.isRequired,color:s.string}),Ne=s.shape({type:s.string.isRequired,label:s.string.isRequired,color:s.string,variant:s.string,onClick:s.func}),nt=s.shape({title:s.string.isRequired,type:s.string.isRequired,variant:s.string,icon:s.node}),st=s.shape({key:s.string.isRequired,title:s.string,type:s.string,imageKey:s.string,titleKey:s.string,subtitleKey:s.string,onClickDetails:s.bool,variant:s.string,chipOptions:s.arrayOf(Me),defaultColor:s.string,className:s.string,format:s.string,menuList:s.arrayOf(nt)}),Se=s.shape({key:s.string.isRequired,label:s.string,type:s.string.isRequired,required:s.bool,minLength:s.number,parentClass:s.string,search:s.bool,multiple:s.bool,dropdownMaxHeight:s.string,dragDrop:s.bool,countriesList:s.bool,defaultCountry:s.string,placeholder:s.string,rows:s.number,text:s.string,editorKey:s.string,options:s.arrayOf(Me)}),lt=s.shape({key:s.string,label:s.string,type:s.string,imageKey:s.string,titleKey:s.string,subtitleKey:s.string,blockClass:s.string,icon:s.node,variant:s.string,chipOptions:s.arrayOf(Me),defaultColor:s.string,className:s.string,format:s.string});Ge.propTypes={config:s.shape({title:s.string.isRequired,description:s.string,buttonText:s.string,fetchData:s.func.isRequired,isStaticData:s.bool,tableConfig:s.shape({table_head:s.arrayOf(st).isRequired,search:s.shape({enabled:s.bool,useServerSideSearch:s.bool,searchKeys:s.arrayOf(s.string)}),pagination:s.shape({enabled:s.bool,useServerSidePagination:s.bool}),filter:s.shape({enabled:s.bool,useServerSideFilters:s.bool})}).isRequired,modalConfig:s.shape({addModal:s.shape({title:s.string.isRequired,size:s.string,formClass:s.string,formFields:s.arrayOf(Se),handleSubmit:s.func.isRequired,actionButtons:s.arrayOf(Ne)}),editModal:s.shape({title:s.string.isRequired,size:s.string,formClass:s.string,formFields:s.arrayOf(Se),handleSubmit:s.func.isRequired,actionButtons:s.arrayOf(Ne)}),deleteModal:s.shape({title:s.string.isRequired,size:s.string,confirmText:s.string,referenceKey:s.string,actionButtons:s.arrayOf(Ne)}),viewModal:s.shape({title:s.string.isRequired,size:s.string,component:s.elementType,fields:s.arrayOf(lt),footer:s.shape({cancelButton:s.bool,cancelText:s.string})})}),filterConfig:s.shape({fields:s.arrayOf(Se)})}).isRequired};function ot({children:n}){return X.useSnackbar(),n}function it({children:n}){try{return e.jsx(ot,{children:n})}catch{return e.jsx(X.SnackbarProvider,{anchorOrigin:{vertical:"bottom",horizontal:"right"},action:r=>e.jsx("button",{onClick:()=>{window.dispatchEvent(new CustomEvent("closeSnackbar",{detail:r}))},className:"p-1 hover:bg-white/20 rounded-full transition-colors duration-200 text-white flex items-center justify-center",children:e.jsx($.X,{className:"h-4 w-4"})}),maxSnack:3,autoHideDuration:3e3,children:n})}}const dt=()=>{if(typeof document>"u"||document.getElementById("react-admin-crud-manager-styles"))return;const n=document.createElement("style");n.id="react-admin-crud-manager-styles",n.textContent=`
|
|
149
|
+
`,children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Filters"}),t.jsx("button",{onClick:a,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md transition",children:t.jsx(U.X,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),n&&t.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:d?t.jsx(d,{filters:o,onFilterChange:s}):t.jsx("div",{className:"space-y-4",children:(p=e==null?void 0:e.fields)==null?void 0:p.map(h=>t.jsx(Pt,{field:h,formData:o,handleChange:s},h.key))})}),t.jsxs("div",{className:"flex gap-2 px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:[t.jsx(ae,{onClick:c,variant:"contained",color:"primary",fullWidth:!0,children:"Apply Filters"}),t.jsx(ae,{onClick:f,variant:"contained",className:"min-w-[150px]",children:"Reset"})]})]})]})},Mr=({rows:n=5,columns:a=5})=>t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w-full mb-6 inline-flex justify-end items-center",children:t.jsx("div",{className:"h-8 w-80 bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})}),t.jsx("div",{className:"overflow-hidden rounded-md border border-gray-200 dark:border-gray-800",children:t.jsxs("table",{className:"w-full border-collapse",children:[t.jsx("thead",{children:t.jsx("tr",{className:"bg-gray-50 dark:bg-gray-900",children:Array.from({length:a}).map((e,r)=>t.jsx("th",{className:"px-4 py-3",children:t.jsx("div",{className:"h-6 w-24 bg-gray-300 dark:bg-gray-700 rounded animate-pulse inline-flex justify-center items-center"})},r))})}),t.jsx("tbody",{children:Array.from({length:n}).map((e,r)=>t.jsx("tr",{className:"border-t border-gray-200 dark:border-gray-800",children:Array.from({length:a}).map((o,i)=>t.jsx("td",{className:"px-4 py-6",children:t.jsx("div",{className:"h-6 w-full bg-gray-300 dark:bg-gray-700 rounded animate-pulse"})},i))},r))})]})})]}),Rr=({options:n=[],value:a="",onChange:e,clearLabel:r=""})=>{const[o,i]=b.useState(!1),s=b.useRef(null),c=!!a;b.useEffect(()=>{const d=p=>{s.current&&!s.current.contains(p.target)&&i(!1)};return document.addEventListener("click",d),()=>document.removeEventListener("click",d)},[]);const f=d=>{const p=n.find(h=>h.value===d);e(d,p||null),i(!1)};return n!=null&&n.length?t.jsxs("div",{className:"relative",ref:s,children:[t.jsxs("button",{type:"button",onClick:()=>i(d=>!d),className:"relative inline-flex items-center justify-center h-[36px] w-[36px] rounded-md border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-700 text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-600 transition","aria-label":"Open sort options",children:[t.jsx(U.ArrowUpDown,{className:"w-4 h-4"}),c&&t.jsx("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]}),o&&t.jsxs("div",{className:"absolute right-0 mt-2 z-20 min-w-[220px] max-h-[260px] overflow-auto rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-lg",children:[!!(r!=null&&r.trim())&&t.jsx("button",{type:"button",onClick:()=>f(""),className:`w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700 ${a?"text-gray-700 dark:text-gray-200":"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-white"}`,children:r}),n.map(d=>t.jsx("button",{type:"button",onClick:()=>f(d.value),className:`w-full text-left px-3 py-2 text-sm transition hover:bg-gray-100 dark:hover:bg-gray-700 ${a===d.value?"bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-white":"text-gray-700 dark:text-gray-200"}`,children:d.label},d.value))]})]}):null},Ge={enabled:!1,useServerSideSorting:!1,options:[],fields:[],defaultValue:"",autoGenerate:!0,clearLabel:"",onChange:null},Cr=n=>n===!0?{...Ge,enabled:!0}:!n||typeof n!="object"?Ge:{...Ge,...n,enabled:n.enabled??!0,autoGenerate:n.autoGenerate??!0},Dr=(n=[])=>n.filter(a=>{const e=["menu_actions","index","audio","avatar"];return a.type&&e.includes(a.type)?!1:!!(a.sortKey||(a.type==="group"?a.titleKey:a.key))}),Er=n=>{if(n.sortType)return n.sortType;if(n.type==="date")return"date";if(n.type==="number")return"number";const a=String(n.sortKey||(n.type==="group"?n.titleKey:n.key)||"").toLowerCase();return["phone","mobile","contact","tel","whatsapp"].some(r=>a.includes(r))?"phone":Array.isArray(n.chipOptions)&&n.chipOptions.length>0&&n.chipOptions.every(o=>typeof o.value=="boolean")?"boolean":"string"},ft=(n=[])=>n.flatMap(a=>{const e=a.sortKey||(a.type==="group"?a.titleKey:a.key),r=a.sortLabel||a.title||e,o=Er(a);return e?o==="number"?[{value:`${e}_asc`,label:`${r} (Low-High)`,key:e,order:"asc",type:o},{value:`${e}_desc`,label:`${r} (High-Low)`,key:e,order:"desc",type:o}]:o==="phone"?[{value:`${e}_asc`,label:`${r} (0-9)`,key:e,order:"asc",type:o},{value:`${e}_desc`,label:`${r} (9-0)`,key:e,order:"desc",type:o}]:o==="date"?[{value:`${e}_desc`,label:`${r} (Newest First)`,key:e,order:"desc",type:o},{value:`${e}_asc`,label:`${r} (Oldest First)`,key:e,order:"asc",type:o}]:o==="boolean"?[{value:`${e}_desc`,label:`${r} (True First)`,key:e,order:"desc",type:o},{value:`${e}_asc`,label:`${r} (False First)`,key:e,order:"asc",type:o}]:[{value:`${e}_asc`,label:`${r} (A-Z)`,key:e,order:"asc",type:o},{value:`${e}_desc`,label:`${r} (Z-A)`,key:e,order:"desc",type:o}]:[]}),_r=(n,a=[])=>{if(Array.isArray(n.options)&&n.options.length>0)return n.options.map(o=>({...o,type:o.type||"string",order:o.order==="desc"?"desc":"asc"}));const r=Array.isArray(n.fields)?n.fields:[];if(r.length>0){const o=r.map(i=>{const s=typeof i=="string"?i:i.key,c=a.find(f=>f.key===s||f.sortKey===s||f.type==="group"&&f.titleKey===s);return c?{...c,sortKey:typeof i=="object"&&i.key?i.key:c.sortKey,sortType:typeof i=="object"&&i.type?i.type:c.sortType,sortLabel:typeof i=="object"&&i.label?i.label:c.sortLabel}:null}).filter(i=>i!==null);return ft(o)}return n.autoGenerate?ft(a):[]},Pr=(n=[],a="",e,r=[])=>{if(!(e!=null&&e.enabled)||!a||e!=null&&e.useServerSideSorting)return n;const o=r==null?void 0:r.find(d=>d.value===a);if(!(o!=null&&o.key))return n;const i=o.order==="desc"?"desc":"asc",s=o.key,c=o.type||"string",f=d=>String(d??"").replace(/[^\d]/g,"").trim();return[...n].sort((d,p)=>{const h=d==null?void 0:d[s],l=p==null?void 0:p[s];if(h==null&&l==null)return 0;if(h==null)return i==="asc"?1:-1;if(l==null)return i==="asc"?-1:1;let m=0;return c==="number"?m=Number(h)-Number(l):c==="phone"?m=f(h).localeCompare(f(l),void 0,{numeric:!0}):c==="date"?m=new Date(h).getTime()-new Date(l).getTime():c==="boolean"?m=+!!h-+!!l:m=String(h).localeCompare(String(l)),i==="asc"?m:-m})},Ar=({config:n,setShowAdd:a,title:e,buttonText:r,description:o,showAddButton:i})=>{const{data:s=[],table_head:c=[],loading:f=!1,search:d={enabled:!1,placeholder:"Search...",useServerSideSearch:!1},filter:p={enabled:!1,useServerSideFilters:!1},sort:h={enabled:!1},pagination:l={enabled:!1,rows_per_page:10,useServerSidePagination:!1},emptyMessage:m="No data available",onMenuAction:g,setServerSidePaginationData:j=()=>{},onFilterApply:v,filterConfig:R=null,rowClick:A=null}=n,[L,C]=b.useState(""),[I,E]=b.useState(null),[x,w]=b.useState([]),[S,D]=b.useState({top:0,left:0}),[P,Y]=b.useState(!1),[ee,K]=b.useState({}),N=b.useMemo(()=>Cr(h),[h]),X=b.useMemo(()=>Dr(c),[c]),B=b.useMemo(()=>_r(N,X),[N,X]),[M,k]=b.useState((N==null?void 0:N.defaultValue)||""),[z,H]=b.useState(null),[F,te]=b.useState(!1),pe=b.useMemo(()=>!d.enabled||!L.trim()||d.useServerSideSearch?s:Ot(s,L,d.searchKeys||[]),[s,L,d]),ne=b.useMemo(()=>Pr(pe,M,N,B),[pe,M,N,B]),[V,re]=b.useState(1),[J,xe]=b.useState((l==null?void 0:l.rows_per_page)||50),[ye,Se]=b.useState(pe.length||0),fe=l!=null&&l.useServerSidePagination?l.total_pages:Math.ceil(pe.length/J),ve=b.useMemo(()=>{if(l.useServerSidePagination)return ne;const u=(V-1)*J;return ne.slice(u,u+J)},[ne,V,J,l.useServerSidePagination]),be=b.useRef(null),we=b.useRef({}),ge=b.useRef(null),Ne=u=>{C(u),re(1),d.useServerSideSearch&&(ge.current&&clearTimeout(ge.current),ge.current=setTimeout(async()=>{try{await j(y=>({...y,search:u,current_page:1}))}catch(y){console.error("Search error:",y)}},800))},Me=(u,y=null)=>{k(u),re(1);const T={value:u,option:y,key:(y==null?void 0:y.key)||"",order:(y==null?void 0:y.order)||"",type:(y==null?void 0:y.type)||""};typeof(N==null?void 0:N.onChange)=="function"&&N.onChange(T)},Re=(u,y,T)=>{T.stopPropagation(),E(null),g==null||g(u.type,y)},Ce=(u,y,T)=>{y.stopPropagation(),w(T);const $=y.currentTarget;we.current[u]=$;const Z=$.getBoundingClientRect(),se=192,de=T.length*40,Fe=window.innerWidth,et=window.innerHeight,At=Fe-Z.right<se?Z.left-se+Z.width:Z.left,Lt=et-Z.bottom<de&&Z.top>de?Z.top-de-2:Z.bottom+2;D({top:Math.max(8,Math.min(Lt,et-de-8)),left:Math.max(8,Math.min(At,Fe-se-8))}),E(I===u?null:u)},De=u=>(V-1)*J+u+1,Ee=u=>{let y=u;y&&y.src instanceof File&&(y={...y,src:URL.createObjectURL(y.src)}),H(y),te(!0)},je=(u,y,T,$=null,Z=null)=>t.jsx(t.Fragment,{children:u?t.jsx("img",{src:u instanceof File?URL.createObjectURL(u):u,alt:y||"Avatar",onClick:se=>{se.stopPropagation(),se.preventDefault(),Ee({src:u,alt:y})},className:`w-10 h-10 cursor-pointer shrink-0 rounded-full object-cover border border-gray-200 dark:border-gray-700 ${T||""}`}):t.jsx(t.Fragment,{children:$?typeof $=="function"?$(Z):$:t.jsx("div",{className:`w-10 h-10 flex items-center shrink-0 justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-gray-200 dark:bg-gray-600 ${T||""}`,children:t.jsx(U.User,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),_e=(u,y)=>t.jsx(t.Fragment,{children:u?t.jsx("audio",{controls:!0,src:u instanceof File?URL.createObjectURL(u):u,onClick:T=>{T.stopPropagation()},className:`w-64 cursor-pointer ${y||""}`},u instanceof File?URL.createObjectURL(u):u):t.jsx(t.Fragment,{children:t.jsx("div",{className:`w-12 h-12 flex items-center shrink-0 justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-gray-200 dark:bg-gray-600 ${y||""}`,children:t.jsx(U.Music,{className:"w-6 h-6 text-gray-400 dark:text-gray-400"})})})}),Pe=(u,y)=>t.jsxs("div",{className:`flex items-center space-x-4 ${y.className||""}`,children:[y.imageKey?je(u[y.imageKey],u[y.titleKey],"group-avatar",y.fallback_icon,u):"",t.jsxs("div",{children:[t.jsx("p",{className:"font-medium text-gray-900 dark:text-white group-title",children:u[y.titleKey]||""}),t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 group-sub-title",children:u[y.subtitleKey]||""})]})]}),Ae=(u,y)=>{var se;let T=String(u);const $=y.variant||"contained";let Z=y.defaultColor;if(((se=y==null?void 0:y.chipOptions)==null?void 0:se.length)>0){const de=y==null?void 0:y.chipOptions.find(Fe=>Fe.value==u);de&&(T=de.label,Z=de.color)}return t.jsx(Et,{label:T,variant:$,color:Z,className:y.className||""})},Le=(u,y,T)=>{const $=y[u.key];return u.type==="menu_actions"?t.jsx("div",{className:`text-center ${u.className||""}`,children:t.jsx("button",{ref:Z=>{we.current[y.id||y._id]=Z},onClick:Z=>Ce(y.id||y._id,Z,u.menuList),className:"p-2 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-full transition text-gray-700 dark:text-gray-300",children:t.jsx(U.EllipsisVertical,{className:"h-4 w-4"})})}):u.type==="index"?t.jsx("span",{className:u.className||"",children:De(T)}):u.type==="group"?Pe(y,u):u.type==="chip"?t.jsx(t.Fragment,{children:Ae($,u)}):u.type==="date"?t.jsx("span",{className:u.className||"",children:gt($,u.format||"DD MMM YYYY")}):u.type==="avatar"?t.jsx(t.Fragment,{children:t.jsx("div",{className:"min-w-[40px]",children:je($,u.alt,u.className,u.fallback_icon,y)})}):u.type==="audio"?t.jsx(t.Fragment,{children:_e($,u.className)}):t.jsx("span",{className:u.className||"",children:$||"N/A"})},_=u=>{if(typeof A=="function")return A(u);if(A)return g==null?void 0:g("view",u)},O=(u,y)=>{if(u.onClickDetails)return g==null?void 0:g("view",y);if(typeof u.handleClick=="function")return u.handleClick(y)},G=()=>A||typeof A=="function",oe=u=>u.onClickDetails||typeof u.handleClick=="function";return b.useEffect(()=>{const u=()=>{I&&E(null)};return window.addEventListener("scroll",u,!0),()=>{window.removeEventListener("scroll",u,!0)}},[I]),b.useEffect(()=>{const u=y=>{be.current&&!be.current.contains(y.target)&&E(null)};return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[]),b.useEffect(()=>{l!=null&&l.rows_per_page&&(l!=null&&l.useServerSidePagination)&&xe((l==null?void 0:l.rows_per_page)||50),l.current_page&&re(l.current_page)},[l.rows_per_page,l==null?void 0:l.useServerSidePagination,l.current_page]),b.useEffect(()=>{Se(l!=null&&l.useServerSidePagination?l.total_records:ne.length),ne.length<=J*(V-1)&&!(l!=null&&l.useServerSidePagination)&&re(u=>u-1||1)},[ne.length,l.total_records,l==null?void 0:l.useServerSidePagination]),b.useEffect(()=>{if(!(N!=null&&N.enabled)){k("");return}if(B.some(y=>y.value===N.defaultValue)){k(N.defaultValue);return}k("")},[N,B]),b.useEffect(()=>{if(!(N!=null&&N.enabled)||!(N!=null&&N.useServerSideSorting))return;const u=B==null?void 0:B.find(y=>y.value===M);j(y=>({...y,current_page:1,sort_by:(u==null?void 0:u.key)||"",sort_order:(u==null?void 0:u.order)||""}))},[M,N==null?void 0:N.enabled,N==null?void 0:N.useServerSideSorting,B,j]),t.jsxs(t.Fragment,{children:[f?t.jsx(Mr,{rows:6,columns:6}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col lg:!flex-row lg:!justify-between gap-4 mb-3",children:[t.jsxs("div",{className:"table-heading",children:[t.jsx("h1",{children:e}),t.jsx("p",{children:o})]}),t.jsxs("div",{className:"flex flex-col justify-end items-stretch lg:!items-end gap-2 w-full lg:!w-auto",children:[i&&t.jsxs(ae,{onClick:()=>a(!0),variant:"contained",color:"primary",children:[t.jsx(U.Plus,{className:"w-4 h-4 mr-2"}),r||"Add New"]}),t.jsxs("div",{className:"flex flex-col sm:!flex-row sm:!flex-wrap justify-end items-stretch sm:!items-center gap-2 w-full",children:[d.enabled&&t.jsx("div",{className:"w-full sm:!w-auto",children:t.jsxs("div",{className:"table-search-field",children:[t.jsx(U.Search,{className:"search-icon"}),t.jsx("input",{type:"text",placeholder:d.placeholder||"Search...",value:L,onChange:u=>Ne(u.target.value)})]})}),N!=null&&N.enabled&&(B==null?void 0:B.length)>0||R&&p.enabled?t.jsxs("div",{className:"flex items-center justify-end gap-2 w-full sm:!w-auto",children:[R&&p.enabled&&t.jsxs("div",{className:"filter-button-wrapper",children:[t.jsxs(ae,{onClick:()=>Y(!0),variant:"contained",className:"w-full sm:!w-auto",children:[t.jsx(U.Filter,{className:"w-4 h-4 mr-2"}),"Filters"]}),Object.keys(ee).length>0&&t.jsx("span",{className:"red-dot"})]}),(N==null?void 0:N.enabled)&&(B==null?void 0:B.length)>0&&t.jsx(Rr,{options:B,value:M,onChange:Me,clearLabel:N==null?void 0:N.clearLabel})]}):null]})]})]}),t.jsxs("div",{className:"table-container",children:[t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{children:[t.jsx("thead",{children:t.jsx("tr",{children:c.map(u=>t.jsx("th",{className:`table-head-data ${u.headClass||""}`,children:u.title},u.key))})}),t.jsx("tbody",{children:ve.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:c.length,className:"no-data-message",children:m})}):ve.map((u,y)=>t.jsx("tr",{className:`table-row ${G()?"cursor-pointer":""}`,onClick:()=>{G()&&_(u)},children:c.map(T=>t.jsx("td",{className:`table-data ${T.type=="audio"?"":"max-w-[300px]"} truncate ${oe(T)?"cursor-pointer":""}`,title:String(u[T.key]??""),onClick:$=>{oe(T)&&($.stopPropagation(),$.preventDefault(),O(T,u))},children:T.render?T.render(u,y):Le(T,u,y)},T.key))},u.id||u._id||y))})]})}),(l==null?void 0:l.enabled)&&ne.length>0&&t.jsxs("div",{className:"pagination-wrapper",children:[t.jsxs("span",{children:["Showing ",(V-1)*J+1," to"," ",Math.min(V*J,ye)," of"," ",ye," results"]}),t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{children:"Rows per page:"}),t.jsx("select",{value:J,onChange:u=>{const y=Number(u.target.value);xe(y),re(1),l.useServerSidePagination&&j(T=>({...T,current_page:1,rows_per_page:y}))},className:"rows-number-select",children:[10,25,50,100].map(u=>t.jsx("option",{value:u,children:u},u))})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>{if(V>1){const u=V-1;re(u),l.useServerSidePagination&&j(y=>({...y,current_page:u}))}},disabled:V===1,className:"arrow-icons",children:t.jsx(U.ChevronLeft,{className:"h-4 w-4"})}),t.jsxs("span",{children:["Page ",V," of ",fe]}),t.jsx("button",{onClick:()=>{if(V<fe){const u=V+1;re(u),l.useServerSidePagination&&j(y=>({...y,current_page:u}))}},disabled:V===fe,className:"arrow-icons",children:t.jsx(U.ChevronRight,{className:"h-4 w-4"})})]})]})]})]})]}),I&&Ft.createPortal(t.jsx("div",{ref:be,style:{position:"fixed",top:`${S.top}px`,left:`${S.left}px`,zIndex:9999},className:"w-48 bg-white dark:bg-gray-700 rounded-md shadow-lg border border-gray-200 dark:border-gray-600",children:x.map((u,y)=>t.jsxs("button",{onClick:T=>Re(u,s.find($=>$.id===I||$._id==I),T),className:`w-full flex items-center gap-2 px-4 py-2 text-sm text-left hover:bg-gray-100 dark:hover:bg-gray-600 ${u.variant==="danger"?"text-red-600 dark:text-red-500":"text-gray-700 dark:text-gray-200"}`,children:[u.icon&&t.jsx("span",{className:"shrink-0",children:u.icon}),u.title]},y))}),document.body),R&&t.jsx(Nr,{isOpen:P,onClose:()=>Y(!1),config:R,onApply:u=>{K(u),v==null||v(u)}}),F&&z&&t.jsx(Qe,{src:z.src,alt:z.alt,isOpen:F,setIsOpen:te})]})},Oe=({isOpen:n,onClose:a,icon:e,title:r,children:o,size:i="md",actionButtons:s=[],onFormSubmit:c=()=>{},loadingBtn:f=!1,executeFunction:d=()=>{},selectedItem:p=null})=>{if(!n)return null;const h={sm:"max-w-md",md:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-full"};return t.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[t.jsx("div",{className:"fixed inset-0 bg-gray-500 opacity-75",onClick:()=>a()}),t.jsxs("div",{className:`relative bg-white rounded-lg shadow-xl w-full ${h[i]||h.md} max-h-[90vh] flex flex-col dark:bg-gray-800`,children:[t.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[e&&t.jsx("span",{children:e}),t.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:r})]}),t.jsx("button",{onClick:()=>a(),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:t.jsx(U.X,{className:"w-6 h-6"})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:o}),s.length>0&&t.jsx("div",{className:"px-4 py-3 flex justify-end gap-3 border-t border-gray-200 dark:border-gray-700 sm:!px-6",children:s.map((l,m)=>t.jsx(ae,{onClick:g=>{l.type=="submit"?c(g):d(()=>{var j;return Promise.resolve((j=l==null?void 0:l.onClick)==null?void 0:j.call(l,g,p))},j=>a==null?void 0:a(j))},disabled:f||l.disabled,variant:l.variant||"contained",color:l.color||"primary",className:`min-w-[100px] ${l.className||""}`,type:l.type||"button",children:f?t.jsxs("div",{className:"flex items-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-2 border-t-white mr-2"}),l.label||"Submit","..."]}):l.label||"Submit"},`${l.label||"action"}-${m}`))})]})]})},bt=({config:n,onSubmit:a,initialData:e,fetchRowDetails:r,type:o})=>{const i=e||{},{formClass:s="grid grid-cols-12 gap-4",formFields:c=[]}=n||{},[f,d]=b.useState(i),[p,h]=b.useState(!0),l=async()=>{r==null||r(i).then(j=>{d(j.data)}).catch(j=>{le.enqueueSnackbar(j.message,{variant:"error"})}).finally(()=>{h(!1)})};b.useEffect(()=>{r instanceof Function?l():(d(i),h(!1))},[]);const m=(j,v)=>{d(R=>({...R,[j]:v}))},g=j=>{j.preventDefault();const v=j.currentTarget;if(!v.checkValidity()){v.reportValidity();return}a(f)};return p?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsx("div",{className:"rounded-full border-4 border-blue-500 border-t-gray-200 animate-spin w-8 h-8",style:{borderTopColor:"border-primary-500"}})}):t.jsx("form",{id:o==="add"?"addForm":o==="edit"?"editForm":"defaultForm",onSubmit:g,className:s,noValidate:!1,children:c.map(j=>t.jsx(Pt,{field:j,formData:f,handleChange:m},j.key))})};function Lr({data:n,config:a,fetchRowDetails:e}){const{fields:r=[],containerClass:o}=a||{},i=n||{},[s,c]=b.useState(i),[f,d]=b.useState(!0),p=async()=>{e==null||e(i).then(h=>{c(h.data)}).catch(h=>{le.enqueueSnackbar(h.message,{variant:"error"})}).finally(()=>{d(!1)})};return b.useEffect(()=>{e instanceof Function?p():(c(i),d(!1))},[]),f?t.jsx("div",{className:"flex items-center justify-center h-64",children:t.jsx("div",{className:"rounded-full border-4 border-blue-500 border-t-gray-200 animate-spin w-8 h-8",style:{borderTopColor:"border-primary-500"}})}):t.jsx(t.Fragment,{children:t.jsx("div",{className:`grid grid-cols-12 gap-4 ${o||""}`,children:r.map(h=>h.renderCondition&&typeof h.renderCondition=="function"&&!h.renderCondition(s)?null:h.type=="group"?t.jsx(Ct,{col:h,data:s},h.key||h.titleKey):h.type=="cardGroup"?t.jsx(Dt,{col:h,data:s},h.key||h.titleKey):t.jsx(_t,{col:h,data:s},h.key||h.label))})})}const Fr=({config:n})=>{var J,xe,ye,Se,fe,ve,be,we,ge,Ne,Me,Re,Ce,De,Ee,je,_e,Pe,Ae,Le;const{title:a,fetchData:e,fetchRowDetails:r,isStaticData:o=!1,tableConfig:i,modalConfig:s,filterConfig:c}=n,[f,d]=b.useState(!0),[p,h]=b.useState(!1),[l,m]=b.useState([]),[g,j]=b.useState(null),[v,R]=b.useState({search:"",rows_per_page:50,current_page:1,sort_by:"",sort_order:""}),[A,L]=b.useState({}),[C,I]=b.useState(!1),[E,x]=b.useState(!1),[w,S]=b.useState(!1),[D,P]=b.useState(!1),[Y,ee]=b.useState(!1),[K,N]=b.useState(null),X=(_,O)=>{_==="edit"?(N(O),S(!0)):_==="view"?(N(O),ee(!0)):_==="delete"&&(N(O),P(!0))},B=async(_,O,G="",oe="")=>{h(!0);try{if(!_)return;const u=await _();(G||u!=null&&u.message)&&le.enqueueSnackbar(G||u.message||"Success",{variant:"success"}),O==null||O(u)}catch(u){(oe||u!=null&&u.message)&&le.enqueueSnackbar(oe||u.message||"Error occurred",{variant:"error"})}finally{h(!1)}},M=_=>{const O=_.newObject;o?(m(G=>[O,...G]),j(G=>({...G,current_page:1}))):(R(G=>({...G,current_page:1})),v.current_page===1&&te()),x(!1)},k=_=>{const{newObject:O,targetObject:G}=_;o?m(oe=>oe.map(u=>u.id===G.id?{...u,...O}:u)):te(),S(!1)},z=_=>{if(!_){P(!1),N(null);return}o?m(O=>O.filter(G=>G.id!==_.targetObject.id)):l.length===1&&v.current_page>1?R(O=>({...O,current_page:O.current_page-1})):te(),P(!1),N(null)},H=_=>B(()=>{var O;return(O=s==null?void 0:s.addModal)!=null&&O.handleSubmit?s.addModal.handleSubmit(_):Promise.resolve({newObject:null})},M),F=_=>B(()=>{var O;return(O=s==null?void 0:s.editModal)!=null&&O.handleSubmit?s.editModal.handleSubmit(_,K):Promise.resolve({newObject:null,targetObject:null})},k),te=async()=>{d(!0);try{const _=await e({...v,...A});m(_.data||[]),j(_.pagination||null)}catch(_){le.enqueueSnackbar(_.message||"Failed to fetch data",{variant:"error"})}finally{d(!1)}},pe=_=>{var O;L(G=>({..._})),(O=i==null?void 0:i.filter)!=null&&O.useServerSideFilters&&I(G=>!G)},ne=(_,O)=>_.filter(G=>Object.entries(O).every(([oe,u])=>G[oe]===u)),V=b.useMemo(()=>{var _;return(_=i==null?void 0:i.filter)!=null&&_.useServerSideFilters?l:ne(l,A)},[l,A,(J=i==null?void 0:i.filter)==null?void 0:J.useServerSideFilters]),re=(xe=s==null?void 0:s.viewModal)==null?void 0:xe.component;return b.useEffect(()=>{te()},[v.search,v.rows_per_page,v.current_page,v.sort_by,v.sort_order,C]),t.jsxs("div",{children:[t.jsx(Ar,{title:a,setShowAdd:x,description:n.description,buttonText:n.buttonText,showAddButton:!!(s!=null&&s.addModal),config:{...i,pagination:{...i.pagination,...g},data:V,setServerSidePaginationData:R,onMenuAction:X,filterConfig:c,onFilterApply:pe,loading:f}}),t.jsx(Oe,{isOpen:E,onClose:()=>{p||x(!1)},icon:(ye=s==null?void 0:s.addModal)==null?void 0:ye.icon,title:((Se=s==null?void 0:s.addModal)==null?void 0:Se.title)||"Add New",size:((fe=s==null?void 0:s.addModal)==null?void 0:fe.size)||"md",onFormSubmit:()=>{var _;return(_=document.querySelector("#addForm"))==null?void 0:_.requestSubmit()},loadingBtn:p,actionButtons:((ve=s==null?void 0:s.addModal)==null?void 0:ve.actionButtons)||[],children:t.jsx(bt,{config:(s==null?void 0:s.addModal)||{},onSubmit:H,initialData:{},type:"add",loading:p})}),t.jsx(Oe,{isOpen:w,onClose:()=>{p||S(!1)},icon:(be=s==null?void 0:s.editModal)==null?void 0:be.icon,title:((we=s==null?void 0:s.editModal)==null?void 0:we.title)||"Edit",size:((ge=s==null?void 0:s.editModal)==null?void 0:ge.size)||"md",onFormSubmit:()=>{var _;return(_=document.querySelector("#editForm"))==null?void 0:_.requestSubmit()},actionButtons:((Ne=s==null?void 0:s.editModal)==null?void 0:Ne.actionButtons)||[],loadingBtn:p,children:t.jsx(bt,{config:(s==null?void 0:s.editModal)||{},onSubmit:F,initialData:K,type:"edit",loading:p,fetchRowDetails:r})}),D&&t.jsx(Oe,{isOpen:D,onClose:_=>{z(_)},icon:((Me=s==null?void 0:s.deleteModal)==null?void 0:Me.icon)||t.jsx(ce.Icon,{icon:"ph:warning-bold",className:"w-6 h-6 text-red-500"}),title:((Re=s==null?void 0:s.deleteModal)==null?void 0:Re.title)||"Confirm Delete",size:((Ce=s==null?void 0:s.deleteModal)==null?void 0:Ce.size)||"md",loading:p,actionButtons:((De=s==null?void 0:s.deleteModal)==null?void 0:De.actionButtons)||[],executeFunction:B,selectedItem:K,children:t.jsx("div",{className:"flex items-center space-x-2 py-3",children:t.jsxs("div",{children:[t.jsx("p",{className:"text-md text-gray-700 dark:text-white",children:((Ee=s==null?void 0:s.deleteModal)==null?void 0:Ee.confirmText)||"Are you sure you want to delete this item?"}),((je=s==null?void 0:s.deleteModal)==null?void 0:je.referenceKey)&&t.jsx("p",{className:"text-md font-semibold text-gray-700 dark:text-white",children:K==null?void 0:K[(_e=s==null?void 0:s.deleteModal)==null?void 0:_e.referenceKey]})]})})}),(s==null?void 0:s.viewModal)&&t.jsx(Oe,{isOpen:Y,onClose:()=>{ee(!1),N(null)},icon:(Pe=s==null?void 0:s.viewModal)==null?void 0:Pe.icon,title:((Ae=s==null?void 0:s.viewModal)==null?void 0:Ae.title)||"View Details",size:((Le=s==null?void 0:s.viewModal)==null?void 0:Le.size)||"lg",footerConfig:s==null?void 0:s.viewModal.footer,children:re?t.jsx(re,{data:K}):t.jsx(Lr,{data:K,fetchRowDetails:r,config:(s==null?void 0:s.viewModal)||{}})})]})};function Ir({children:n}){return le.useSnackbar(),n}function Tr({children:n}){try{return t.jsx(Ir,{children:n})}catch{return t.jsx(le.SnackbarProvider,{anchorOrigin:{vertical:"bottom",horizontal:"right"},action:e=>t.jsx("button",{onClick:()=>{window.dispatchEvent(new CustomEvent("closeSnackbar",{detail:e}))},className:"p-1 hover:bg-white/20 rounded-full transition-colors duration-200 text-white flex items-center justify-center",children:t.jsx(U.X,{className:"h-4 w-4"})}),maxSnack:3,autoHideDuration:3e3,children:n})}}const Or=()=>{if(typeof document>"u"||document.getElementById("react-admin-crud-manager-styles"))return;const n=document.createElement("style");n.id="react-admin-crud-manager-styles",n.textContent=`
|
|
57
150
|
.no-spinner::-webkit-outer-spin-button,
|
|
58
151
|
.no-spinner::-webkit-inner-spin-button {
|
|
59
152
|
-webkit-appearance: none;
|
|
@@ -68,5 +161,5 @@
|
|
|
68
161
|
border: 0 !important;
|
|
69
162
|
box-shadow: none !important;
|
|
70
163
|
}
|
|
71
|
-
`,document.head.appendChild(n)};function
|
|
164
|
+
`,document.head.appendChild(n)};function zr({config:n}){return b.useEffect(()=>{Or()},[]),t.jsx(Tr,{children:t.jsx(Fr,{config:n})})}module.exports=zr;
|
|
72
165
|
//# sourceMappingURL=index.cjs.js.map
|