3 lines
44 KiB
JavaScript
3 lines
44 KiB
JavaScript
"use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("@mantine/core"),r=require("@tabler/icons-react"),o=require("@mantine/form"),i=require("@mantine/notifications"),a=require("@mantine/modals"),s=require("axios"),c=require("@mantine/hooks"),l=function(){return l=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},l.apply(this,arguments)};function u(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function d(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}c((r=r.apply(e,t||[])).next())})}function f(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}function p(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var h={status:{active:"green",inactive:"gray",pending:"yellow",suspended:"red",enabled:"green",disabled:"gray",online:"green",offline:"gray",running:"green",stopped:"gray",paused:"yellow",failed:"red",success:"green",completed:"green",error:"red",warning:"yellow",info:"blue"},role:{admin:"red",moderator:"orange",user:"blue",viewer:"gray",owner:"purple",editor:"cyan",contributor:"teal",guest:"gray"},type:{static:"blue",user:"cyan",service:"green",application:"purple",api:"orange",web:"teal",mobile:"pink",desktop:"indigo"},runtime:{nodejs18:"green",nodejs20:"lime","python3.9":"blue","python3.11":"indigo","go1.20":"cyan","go1.21":"teal",java11:"orange",java17:"red",dotnet6:"purple",dotnet7:"violet",rust:"dark",php8:"grape"},severity:{critical:"red",high:"orange",medium:"yellow",low:"blue",info:"gray",debug:"dark"},execution:{queued:"gray",running:"blue",succeeded:"green",failed:"red",timeout:"orange",cancelled:"yellow",retrying:"cyan"}},m={status:"gray",role:"blue",runtime:"blue",type:"blue",severity:"gray",execution:"gray"},x=function(t){var r=t.value,o=t.variant,i=void 0===o?"status":o,a=t.customColorMap,s=t.size,c=void 0===s?"sm":s,d=u(t,["value","variant","customColorMap","size"]);if(!r)return e.jsx(n.Badge,l({color:"gray",size:c},d,{children:"-"}));var f=(a||h[i]||h.status)[r.toLowerCase()]||m[i],p=g(r,i);return e.jsx(n.Badge,l({color:f,size:c,variant:"filled"},d,{children:p}))},g=function(e,t){switch(t){case"runtime":if(e.startsWith("nodejs"))return"Node.js ".concat(e.replace("nodejs",""));if(e.startsWith("python"))return"Python ".concat(e.replace("python",""));if(e.startsWith("go"))return"Go ".concat(e.replace("go",""));if(e.startsWith("java"))return"Java ".concat(e.replace("java",""));if(e.startsWith("dotnet"))return".NET ".concat(e.replace("dotnet",""));break;case"type":if("api"===e)return"API";if("web"===e)return"Web App";if("mobile"===e)return"Mobile App"}return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()},v={users:r.IconUsers,applications:r.IconApps,functions:r.IconFunction,tokens:r.IconKey,executions:r.IconFunction,permissions:r.IconKey,audit:r.IconDatabase,generic:r.IconDatabase},b=function(t){var o=t.variant,i=void 0===o?"no-data":o,a=t.context,s=void 0===a?"generic":a,c=t.title,l=t.message,u=t.icon,d=t.iconSize,f=void 0===d?48:d,p=t.iconColor,h=void 0===p?"dimmed":p,m=t.actions,x=t.height,g=void 0===x?400:x,b=t.onAdd,y=t.onRefresh,j=t.onClearFilters,k=function(e,t){var n={users:"users",applications:"applications",functions:"functions",tokens:"tokens",executions:"executions",permissions:"permissions",audit:"audit events",generic:"items"}[t],r=n.charAt(0).toUpperCase()+n.slice(1);switch(e){case"no-data":return{title:"No ".concat(n," found"),message:"You haven't created any ".concat(n," yet. Get started by adding your first ").concat(n.slice(0,-1),".")};case"no-results":return{title:"No matching results",message:"No ".concat(n," match your current filters or search criteria. Try adjusting your search terms or clearing filters.")};case"error":return{title:"Something went wrong",message:"We couldn't load your ".concat(n,". Please try again or contact support if the problem persists.")};case"loading-failed":return{title:"Failed to load data",message:"There was a problem loading ".concat(n,". Check your connection and try again.")};case"access-denied":return{title:"Access denied",message:"You don't have permission to view ".concat(n,". Contact your administrator if you need access.")};case"coming-soon":return{title:"Coming soon",message:"".concat(r," functionality is being developed. Check back soon for updates.")};default:return{title:"No ".concat(n),message:"There are no ".concat(n," to display.")}}}(i,s),w=c||k.title,C=l||k.message,S=u||v[s]||function(e){switch(e){case"no-results":return r.IconSearch;case"error":case"loading-failed":case"access-denied":return r.IconAlertCircle;default:return r.IconDatabase}}(i),I=m||function(t,n,o,i,a){var s=[];switch(t){case"no-data":if(o){var c={users:{label:"Add User",onClick:o,variant:"filled",leftSection:e.jsx(r.IconPlus,{size:16})},applications:{label:"Create Application",onClick:o,variant:"filled",leftSection:e.jsx(r.IconPlus,{size:16})},functions:{label:"Create Function",onClick:o,variant:"filled",leftSection:e.jsx(r.IconPlus,{size:16})},tokens:{label:"Generate Token",onClick:o,variant:"filled",leftSection:e.jsx(r.IconPlus,{size:16})},executions:{label:"Run Function",onClick:o,variant:"filled",leftSection:e.jsx(r.IconFunction,{size:16})},permissions:{label:"Add Permission",onClick:o,variant:"filled",leftSection:e.jsx(r.IconPlus,{size:16})},audit:{label:"Refresh",onClick:o,variant:"light",leftSection:e.jsx(r.IconRefresh,{size:16})},generic:{label:"Add New",onClick:o,variant:"filled",leftSection:e.jsx(r.IconPlus,{size:16})}};s.push(c[n])}break;case"no-results":a&&s.push({label:"Clear Filters",onClick:a,variant:"light",leftSection:e.jsx(r.IconFilter,{size:16})}),i&&s.push({label:"Refresh",onClick:i,variant:"outline",leftSection:e.jsx(r.IconRefresh,{size:16})});break;case"error":case"loading-failed":i&&s.push({label:"Try Again",onClick:i,variant:"filled",leftSection:e.jsx(r.IconRefresh,{size:16})})}return s}(i,s,b,y,j);return e.jsx(n.Center,{h:g,children:e.jsxs(n.Stack,{align:"center",gap:"lg",maw:400,ta:"center",children:[e.jsx(n.Box,{c:h,children:e.jsx(S,{size:f,stroke:1.5})}),e.jsxs(n.Stack,{align:"center",gap:"xs",children:[e.jsx(n.Text,{size:"lg",fw:600,c:"dimmed",children:w}),e.jsx(n.Text,{size:"sm",c:"dimmed",lh:1.5,children:C})]}),I.length>0&&e.jsx(n.Stack,{align:"center",gap:"sm",w:"100%",children:I.map(function(t,r){return e.jsx(n.Button,{onClick:t.onClick,variant:t.variant||"filled",color:t.color,leftSection:t.leftSection,size:"sm",children:t.label},r)})})]})})},y=function(t){var o,i=t.opened,a=t.onClose,s=t.title,c=t.width,u=void 0===c?450:c,d=t.position,f=void 0===d?"right":d,p=t.headerActions,h=t.footer,m=t.children,x=t.zIndex,g=void 0===x?1e3:x,v=t.offsetTop,b=void 0===v?60:v,y=t.backgroundColor,j=void 0===y?"var(--mantine-color-body)":y,k=t.borderColor,w=void 0===k?"var(--mantine-color-gray-3)":k,C=t.animationDuration,S=void 0===C?"0.3s":C,I=t["aria-label"];return e.jsxs(n.Paper,{style:(o={position:"fixed",top:b,bottom:0,width:"".concat(u,"px"),zIndex:g,borderRadius:0,display:"flex",flexDirection:"column",backgroundColor:j,transition:"".concat(f," ").concat(S," ease")},l(l({},o),"right"===f?{right:i?0:"-".concat(u,"px"),borderLeft:"1px solid ".concat(w)}:{left:i?0:"-".concat(u,"px"),borderRight:"1px solid ".concat(w)})),role:"dialog","aria-modal":"true","aria-label":I||s,"aria-hidden":!i,children:[e.jsxs(n.Group,{justify:"space-between",p:"md",style:{borderBottom:"1px solid ".concat(w)},children:[e.jsx(n.Title,{order:4,style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s}),p&&e.jsx(n.Group,{gap:"xs",children:p}),e.jsx(n.ActionIcon,{variant:"subtle",color:"gray",onClick:a,"aria-label":"Close sidebar",ml:"xs",children:e.jsx(r.IconX,{size:18})})]}),e.jsx(n.ScrollArea,{style:{flex:1},scrollbarSize:6,children:e.jsx(n.Box,{p:"md",children:m})}),h&&e.jsxs(e.Fragment,{children:[e.jsx(n.Divider,{}),e.jsx(n.Box,{p:"md",style:{borderTop:"1px solid ".concat(w)},children:h})]})]})},j=function(e){var t=[],n=[],r=[];e.forEach(function(e){"red"===e.color||e.key.includes("delete")||e.key.includes("remove")?r.push(e):e.key.includes("edit")||e.key.includes("view")||e.key.includes("copy")?t.push(e):n.push(e)});var o=[];return t.length>0&&o.push(t),n.length>0&&o.push(n),r.length>0&&o.push(r),o},k=function(e){return{key:"view",label:"View Details",icon:r.IconEye,onClick:e}},w=function(e){return{key:"edit",label:"Edit",icon:r.IconEdit,color:"blue",onClick:e}},C=function(e){return{key:"copy",label:"Duplicate",icon:r.IconCopy,onClick:e}},S=function(e,t){return void 0===t&&(t="item"),{key:"delete",label:"Delete",icon:r.IconTrash,color:"red",onClick:e,confirm:{title:"Confirm Delete",message:"Are you sure you want to delete this ".concat(t,"? This action cannot be undone."),confirmLabel:"Delete",cancelLabel:"Cancel"}}},I=function(t){var r=t.variant,o=void 0===r?"spinner":r,i=t.size,a=void 0===i?"md":i,s=t.height,c=void 0===s?200:s,l=t.message,u=t.submessage,d=t.progress,f=t.progressLabel,p=t.rows,h=void 0===p?5:p,m=t.columns,x=void 0===m?3:m,g=t.color,v=void 0===g?"blue":g,b=t.withContainer,y=void 0===b||b,j=t.animate,k=void 0===j||j,w=function(){return{xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl"}[a]},C=function(){return e.jsxs(n.Stack,{align:"center",gap:"md",children:[e.jsx(n.Loader,{size:{xs:16,sm:24,md:32,lg:48,xl:64}[a],color:v}),l&&e.jsx(n.Text,{size:w(),c:"dimmed",ta:"center",children:l}),u&&e.jsx(n.Text,{size:"xs",c:"dimmed",ta:"center",children:u})]})},S=function(){switch(o){case"progress":return e.jsxs(n.Stack,{gap:"md",children:[(l||f)&&e.jsxs(n.Group,{justify:"space-between",children:[e.jsx(n.Text,{size:w(),children:l||"Loading..."}),f&&e.jsx(n.Text,{size:"sm",c:"dimmed",children:f})]}),e.jsx(n.Progress,{value:d||0,color:v,size:a,animated:k}),u&&e.jsx(n.Text,{size:"xs",c:"dimmed",ta:"center",children:u})]});case"skeleton-table":return e.jsxs(n.Stack,{gap:"xs",children:[e.jsx(n.Group,{gap:"md",children:Array.from({length:x}).map(function(t,r){return e.jsx(n.Skeleton,{height:20,width:"".concat(100/x,"%")},"header-".concat(r))})}),Array.from({length:h}).map(function(t,r){return e.jsx(n.Group,{gap:"md",children:Array.from({length:x}).map(function(t,o){return e.jsx(n.Skeleton,{height:16,width:"".concat(100/x,"%")},"cell-".concat(r,"-").concat(o))})},"row-".concat(r))})]});case"skeleton-cards":return e.jsx(n.SimpleGrid,{cols:{base:1,sm:2,lg:x},children:Array.from({length:h*x}).map(function(t,r){return e.jsx(n.Card,{padding:"md",withBorder:!0,children:e.jsxs(n.Stack,{gap:"xs",children:[e.jsx(n.Skeleton,{height:20,width:"70%"}),e.jsx(n.Skeleton,{height:14}),e.jsx(n.Skeleton,{height:14,width:"90%"}),e.jsxs(n.Group,{justify:"apart",mt:"md",children:[e.jsx(n.Skeleton,{height:12,width:"40%"}),e.jsx(n.Skeleton,{height:12,width:"30%"})]})]})},"card-".concat(r))})});case"skeleton-form":return e.jsxs(n.Stack,{gap:"md",children:[Array.from({length:h}).map(function(t,r){return e.jsxs(n.Box,{children:[e.jsx(n.Skeleton,{height:12,width:"30%",mb:"xs"}),e.jsx(n.Skeleton,{height:36})]},"form-field-".concat(r))}),e.jsxs(n.Group,{justify:"flex-end",mt:"xl",children:[e.jsx(n.Skeleton,{height:36,width:80}),e.jsx(n.Skeleton,{height:36,width:100})]})]});case"skeleton-text":return e.jsx(n.Stack,{gap:"xs",children:Array.from({length:h}).map(function(t,r){var o=["100%","95%","85%","90%","75%"];return e.jsx(n.Skeleton,{height:16,width:o[r%o.length]},"text-".concat(r))})});case"dots":return t=Array.from({length:3}).map(function(t,r){return e.jsx(n.Box,{w:8,h:8,bg:v,style:{borderRadius:"50%",animation:k?"loading-dots 1.4s infinite ease-in-out ".concat(.16*r,"s"):void 0}},r)}),e.jsxs(n.Stack,{align:"center",gap:"md",children:[e.jsx(n.Group,{gap:"xs",children:t}),l&&e.jsx(n.Text,{size:w(),c:"dimmed",ta:"center",children:l})]});case"overlay":return e.jsx(n.Box,{style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255, 255, 255, 0.8)",backdropFilter:"blur(2px)",zIndex:1e3},children:e.jsx(n.Center,{h:"100%",children:C()})});default:return C()}var t};if("overlay"===o)return e.jsxs(e.Fragment,{children:[S(),e.jsx("style",{children:A})]});var I=e.jsxs(e.Fragment,{children:[S(),k&&e.jsx("style",{children:A})]});return y?e.jsx(n.Center,{h:c,children:I}):I},A="\n @keyframes loading-dots {\n 0%, 80%, 100% {\n transform: scale(0);\n opacity: 0.5;\n }\n 40% {\n transform: scale(1);\n opacity: 1;\n }\n }\n",P=function(e,t){void 0===t&&(t="Success");var n={title:t,message:e,color:"green"};i.notifications.show(n)},T=function(e,t){void 0===t&&(t="Error");var n={title:t,message:e,color:"red"};i.notifications.show(n)},O={createSuccess:function(e){return"".concat(e," created successfully")},updateSuccess:function(e){return"".concat(e," updated successfully")},deleteSuccess:function(e){return"".concat(e," deleted successfully")},createError:function(e){return"Failed to create ".concat(e)},updateError:function(e){return"Failed to update ".concat(e)},deleteError:function(e){return"Failed to delete ".concat(e)},loadError:function(e){return"Failed to load ".concat(e)},networkError:"Network error occurred. Please try again.",validationError:"Please check the form for errors",requiredFieldError:function(e){return"".concat(e," is required")},authRequired:"Authentication required",permissionDenied:"Permission denied",sessionExpired:"Session expired. Please log in again.",applicationCreated:"Application created successfully",applicationUpdated:"Application updated successfully",applicationDeleted:"Application deleted successfully",tokenCreated:"Token created successfully",tokenRevoked:"Token revoked successfully",userCreated:"User created successfully",userUpdated:"User updated successfully",userDeleted:"User deleted successfully",functionCreated:"Function created successfully",functionUpdated:"Function updated successfully",functionDeleted:"Function deleted successfully",executionStarted:"Function execution started",executionCompleted:"Function execution completed",executionFailed:"Function execution failed"},z={success:function(e,t){var n=O["".concat(e,"Success")](t);P(n)},error:function(e,t,n){var r=n||O["".concat(e,"Error")](t);T(r)}},F={email:/^\S+@\S+\.\S+$/,url:/^https?:\/\/.+/,duration:/^\d+[smhd]$/,token:/^[a-zA-Z0-9_-]+$/,appId:/^[a-zA-Z0-9-_]+$/,uuid:/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i},L={required:function(e){return"".concat(e," is required")},email:"Please enter a valid email address",url:"Please enter a valid URL (http:// or https://)",duration:"Duration must be in format like 30s, 5m, 2h, 1d",minLength:function(e,t){return"".concat(e," must be at least ").concat(t," characters")},maxLength:function(e,t){return"".concat(e," must be no more than ").concat(t," characters")},pattern:function(e){return"".concat(e," format is invalid")},token:"Token can only contain letters, numbers, underscores and hyphens",appId:"App ID can only contain letters, numbers, hyphens and underscores",uuid:"Please enter a valid UUID",positiveNumber:"Must be a positive number",range:function(e,t,n){return"".concat(e," must be between ").concat(t," and ").concat(n)}};Object.defineProperty(exports,"ActionIcon",{enumerable:!0,get:function(){return n.ActionIcon}}),Object.defineProperty(exports,"Badge",{enumerable:!0,get:function(){return n.Badge}}),Object.defineProperty(exports,"Box",{enumerable:!0,get:function(){return n.Box}}),Object.defineProperty(exports,"Button",{enumerable:!0,get:function(){return n.Button}}),Object.defineProperty(exports,"Center",{enumerable:!0,get:function(){return n.Center}}),Object.defineProperty(exports,"Divider",{enumerable:!0,get:function(){return n.Divider}}),Object.defineProperty(exports,"Group",{enumerable:!0,get:function(){return n.Group}}),Object.defineProperty(exports,"JsonInput",{enumerable:!0,get:function(){return n.JsonInput}}),Object.defineProperty(exports,"LoadingOverlay",{enumerable:!0,get:function(){return n.LoadingOverlay}}),Object.defineProperty(exports,"Menu",{enumerable:!0,get:function(){return n.Menu}}),Object.defineProperty(exports,"MultiSelect",{enumerable:!0,get:function(){return n.MultiSelect}}),Object.defineProperty(exports,"NumberInput",{enumerable:!0,get:function(){return n.NumberInput}}),Object.defineProperty(exports,"Pagination",{enumerable:!0,get:function(){return n.Pagination}}),Object.defineProperty(exports,"Paper",{enumerable:!0,get:function(){return n.Paper}}),Object.defineProperty(exports,"ScrollArea",{enumerable:!0,get:function(){return n.ScrollArea}}),Object.defineProperty(exports,"Select",{enumerable:!0,get:function(){return n.Select}}),Object.defineProperty(exports,"Stack",{enumerable:!0,get:function(){return n.Stack}}),Object.defineProperty(exports,"Table",{enumerable:!0,get:function(){return n.Table}}),Object.defineProperty(exports,"Text",{enumerable:!0,get:function(){return n.Text}}),Object.defineProperty(exports,"TextInput",{enumerable:!0,get:function(){return n.TextInput}}),Object.defineProperty(exports,"Textarea",{enumerable:!0,get:function(){return n.Textarea}}),Object.defineProperty(exports,"Title",{enumerable:!0,get:function(){return n.Title}}),Object.defineProperty(exports,"IconAlertCircle",{enumerable:!0,get:function(){return r.IconAlertCircle}}),Object.defineProperty(exports,"IconCheck",{enumerable:!0,get:function(){return r.IconCheck}}),Object.defineProperty(exports,"IconChevronDown",{enumerable:!0,get:function(){return r.IconChevronDown}}),Object.defineProperty(exports,"IconChevronRight",{enumerable:!0,get:function(){return r.IconChevronRight}}),Object.defineProperty(exports,"IconCopy",{enumerable:!0,get:function(){return r.IconCopy}}),Object.defineProperty(exports,"IconDots",{enumerable:!0,get:function(){return r.IconDots}}),Object.defineProperty(exports,"IconEdit",{enumerable:!0,get:function(){return r.IconEdit}}),Object.defineProperty(exports,"IconEye",{enumerable:!0,get:function(){return r.IconEye}}),Object.defineProperty(exports,"IconEyeOff",{enumerable:!0,get:function(){return r.IconEyeOff}}),Object.defineProperty(exports,"IconFilter",{enumerable:!0,get:function(){return r.IconFilter}}),Object.defineProperty(exports,"IconInfoCircle",{enumerable:!0,get:function(){return r.IconInfoCircle}}),Object.defineProperty(exports,"IconKey",{enumerable:!0,get:function(){return r.IconKey}}),Object.defineProperty(exports,"IconPlus",{enumerable:!0,get:function(){return r.IconPlus}}),Object.defineProperty(exports,"IconRefresh",{enumerable:!0,get:function(){return r.IconRefresh}}),Object.defineProperty(exports,"IconSearch",{enumerable:!0,get:function(){return r.IconSearch}}),Object.defineProperty(exports,"IconSettings",{enumerable:!0,get:function(){return r.IconSettings}}),Object.defineProperty(exports,"IconTrash",{enumerable:!0,get:function(){return r.IconTrash}}),Object.defineProperty(exports,"IconUser",{enumerable:!0,get:function(){return r.IconUser}}),Object.defineProperty(exports,"IconUsers",{enumerable:!0,get:function(){return r.IconUsers}}),Object.defineProperty(exports,"IconX",{enumerable:!0,get:function(){return r.IconX}}),Object.defineProperty(exports,"useForm",{enumerable:!0,get:function(){return o.useForm}}),Object.defineProperty(exports,"notifications",{enumerable:!0,get:function(){return i.notifications}}),Object.defineProperty(exports,"modals",{enumerable:!0,get:function(){return a.modals}}),Object.defineProperty(exports,"useDisclosure",{enumerable:!0,get:function(){return c.useDisclosure}}),Object.defineProperty(exports,"useLocalStorage",{enumerable:!0,get:function(){return c.useLocalStorage}}),Object.defineProperty(exports,"useToggle",{enumerable:!0,get:function(){return c.useToggle}}),exports.ActionMenu=function(o){var s=o.item,c=o.actions,u=o.trigger,p=void 0===u?"dots":u,h=o.triggerLabel,m=void 0===h?"Actions":h,x=o.triggerIcon,g=void 0===x?r.IconDots:x,v=o.triggerProps,b=void 0===v?{}:v,y=o.customTrigger,k=o.position,w=void 0===k?"bottom-end":k,C=o.withArrow,S=void 0!==C&&C,I=o.withinPortal,A=void 0===I||I,P=o["aria-label"],T=c.filter(function(e){return!e.hidden&&!(e.show&&!e.show(s))}),O=j(T);if(0===T.length)return null;var z=function(t){var r=t.icon;return e.jsx(n.Menu.Item,{leftSection:r&&e.jsx(r,{size:14}),color:t.color,disabled:t.disabled,onClick:function(){return function(t){return d(void 0,void 0,void 0,function(){var r;return f(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),t.confirm?[2,new Promise(function(r){a.modals.openConfirmModal({title:t.confirm.title,children:e.jsx(n.Text,{size:"sm",children:t.confirm.message}),labels:{confirm:t.confirm.confirmLabel||"Confirm",cancel:t.confirm.cancelLabel||"Cancel"},confirmProps:{color:t.color||"red"},onConfirm:function(){return d(void 0,void 0,void 0,function(){var e;return f(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,t.onClick(s)];case 1:return n.sent(),r(),[3,3];case 2:return e=n.sent(),console.error("Action ".concat(t.key," failed:"),e),i.notifications.show({title:"Action Failed",message:"Failed to ".concat(t.label.toLowerCase()),color:"red"}),[3,3];case 3:return[2]}})})},onCancel:function(){return r()}})})]:[3,1];case 1:return[4,t.onClick(s)];case 2:o.sent(),o.label=3;case 3:return[3,5];case 4:return r=o.sent(),console.error("Action ".concat(t.key," failed:"),r),i.notifications.show({title:"Action Failed",message:"Failed to ".concat(t.label.toLowerCase()),color:"red"}),[3,5];case 5:return[2]}})})}(t)},children:t.label},t.key)};return e.jsxs(n.Menu,{position:w,withArrow:S,withinPortal:A,children:[e.jsx(n.Menu.Target,{children:y||("button"===p?e.jsx(n.Button,l({variant:"light",size:"xs",leftSection:e.jsx(g,{size:16})},b,{children:m})):e.jsx(n.ActionIcon,l({variant:"subtle",color:"gray",size:"sm","aria-label":P||"".concat(m," menu")},b,{children:e.jsx(g,{size:16})})))}),e.jsx(n.Menu.Dropdown,{children:O.map(function(r,o){return e.jsxs(t.Fragment,{children:[r.map(z),o<O.length-1&&e.jsx(n.Menu.Divider,{})]},o)})})]})},exports.ApplicationTypeBadge=function(t){return e.jsx(x,l({},t,{variant:"type"}))},exports.CardsLoadingState=function(t){var n=t.count,r=void 0===n?6:n,o=t.columns,i=void 0===o?3:o;return e.jsx(I,{variant:"skeleton-cards",rows:Math.ceil(r/i),columns:i,withContainer:!1})},exports.DataTable=function(o){var s=o.data,c=o.columns,u=o.loading,p=void 0!==u&&u,h=o.error,m=void 0===h?null:h,x=o.title,g=o.total,v=void 0===g?0:g,b=o.page,y=void 0===b?1:b,j=o.pageSize,k=void 0===j?10:j,w=o.onPageChange,C=o.onAdd,S=o.onEdit,I=o.onDelete,A=o.onRefresh,P=o.customActions,T=void 0===P?[]:P,O=o.searchable,z=void 0===O||O,F=o.filterable,L=void 0!==F&&F,E=o.filters,D=void 0===E?{}:E,R=o.onFiltersChange,B=o.withBorder,M=void 0===B||B,N=o.withColumnBorders,U=void 0!==N&&N,G=o.striped,q=void 0===G||G,V=o.highlightOnHover,W=void 0===V||V,J=o.emptyMessage,$=void 0===J?"No data available":J,X=t.useState(D),K=X[0],H=X[1];t.useEffect(function(){H(D)},[D]);var Y=function(e){!function(e,t){var n,r=l(l({},K),((n={})[e]=t,n));H(r),null==R||R(r)}("search",e)},_=function(t,r){var o=r[t.key];if(t.render)return t.render(o,r);if(null==o)return e.jsx(n.Text,{c:"dimmed",children:"-"});if("boolean"==typeof o)return e.jsx(n.Badge,{color:o?"green":"gray",size:"sm",children:o?"Yes":"No"});if("status"===t.key){return e.jsx(n.Badge,{color:{active:"green",inactive:"gray",pending:"yellow",suspended:"red",success:"green",error:"red",warning:"yellow"}[o]||"blue",size:"sm",children:o})}return e.jsx(n.Text,{children:o.toString()})},Z=function(t){var o=[];S&&o.push({key:"edit",label:"Edit",icon:e.jsx(r.IconEdit,{size:14}),onClick:S}),I&&o.push({key:"delete",label:"Delete",icon:e.jsx(r.IconTrash,{size:14}),color:"red",onClick:function(){return function(t){a.modals.openConfirmModal({title:"Confirm Delete",children:e.jsx(n.Text,{size:"sm",children:"Are you sure you want to delete this item? This action cannot be undone."}),labels:{confirm:"Delete",cancel:"Cancel"},confirmProps:{color:"red"},onConfirm:function(){return d(void 0,void 0,void 0,function(){var e;return f(this,function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),I?[4,I(t)]:[3,2];case 1:n.sent(),i.notifications.show({title:"Success",message:"Item deleted successfully",color:"green"}),n.label=2;case 2:return[3,4];case 3:return e=n.sent(),i.notifications.show({title:"Error",message:e.message||"Failed to delete item",color:"red"}),[3,4];case 4:return[2]}})})}})}(t)}}),o.push.apply(o,T);var s=o.filter(function(e){return!e.show||e.show(t)});return 0===s.length?null:e.jsxs(n.Menu,{position:"bottom-end",children:[e.jsx(n.Menu.Target,{children:e.jsx(n.ActionIcon,{variant:"subtle",color:"gray",children:e.jsx(r.IconDots,{size:16})})}),e.jsx(n.Menu.Dropdown,{children:s.map(function(r){return e.jsx(n.Menu.Item,{leftSection:r.icon,color:r.color,onClick:function(){return r.onClick(t)},children:r.label},r.key)})})]})},Q=Math.ceil(v/k);return e.jsxs(n.Stack,{gap:"md",children:[e.jsxs(n.Group,{justify:"space-between",children:[e.jsx(n.Group,{children:x&&e.jsx(n.Text,{size:"xl",fw:600,children:x})}),e.jsxs(n.Group,{children:[A&&e.jsx(n.ActionIcon,{variant:"light",onClick:A,children:e.jsx(r.IconRefresh,{size:16})}),C&&e.jsx(n.Button,{leftSection:e.jsx(r.IconPlus,{size:16}),onClick:C,children:"Add New"})]})]}),(z||L)&&e.jsxs(n.Group,{children:[z&&e.jsx(n.TextInput,{placeholder:"Search...",leftSection:e.jsx(r.IconSearch,{size:16}),value:K.search||"",onChange:function(e){return Y(e.currentTarget.value)},style:{flex:1}}),L&&e.jsx(n.Group,{children:e.jsx(n.ActionIcon,{variant:"light",children:e.jsx(r.IconFilter,{size:16})})})]}),e.jsxs(n.Paper,{withBorder:M,pos:"relative",children:[e.jsx(n.LoadingOverlay,{visible:p}),m?e.jsx(n.Center,{p:"xl",children:e.jsxs(n.Stack,{align:"center",gap:"xs",children:[e.jsx(n.Text,{c:"red",fw:500,children:"Error loading data"}),e.jsx(n.Text,{c:"dimmed",size:"sm",children:m}),A&&e.jsx(n.Button,{variant:"light",size:"sm",onClick:A,children:"Try Again"})]})}):0===s.length?e.jsx(n.Center,{p:"xl",children:e.jsxs(n.Stack,{align:"center",gap:"xs",children:[e.jsx(n.Text,{c:"dimmed",children:$}),C&&e.jsx(n.Button,{variant:"light",size:"sm",onClick:C,children:"Add First Item"})]})}):e.jsxs(n.Table,{striped:q,highlightOnHover:W,withColumnBorders:U,children:[e.jsx(n.Table.Thead,{children:e.jsxs(n.Table.Tr,{children:[c.map(function(t){return e.jsx(n.Table.Th,{style:{width:t.width},children:t.label},t.key)}),(S||I||T.length>0)&&e.jsx(n.Table.Th,{style:{width:50},children:"Actions"})]})}),e.jsx(n.Table.Tbody,{children:s.map(function(t){return e.jsxs(n.Table.Tr,{children:[c.map(function(r){return e.jsx(n.Table.Td,{children:_(r,t)},"".concat(t.id,"-").concat(r.key))}),(S||I||T.length>0)&&e.jsx(n.Table.Td,{children:Z(t)})]},t.id)})})]})]}),Q>1&&e.jsx(n.Group,{justify:"center",children:e.jsx(n.Pagination,{total:Q,value:y,onChange:w,size:"sm"})})]})},exports.DetailsSidebar=function(t){var r=t.itemName,o=t.itemType,i=void 0===o?"Item":o,a=t.editButton,s=t.deleteButton,c=t.status,d=t.children,f=u(t,["itemName","itemType","editButton","deleteButton","status","children"]),p=e.jsxs(n.Group,{gap:"xs",children:[c,a,s]});return e.jsx(y,l({},f,{title:"".concat(i,": ").concat(r),headerActions:p,children:d}))},exports.EmptyState=b,exports.ErrorState=function(t){var n=t.onRetry,r=u(t,["onRetry"]);return e.jsx(b,l({},r,{variant:"error",onRefresh:n}))},exports.ExecutionStatusBadge=function(t){return e.jsx(x,l({},t,{variant:"execution"}))},exports.FormLoadingState=function(t){var n=t.fields,r=void 0===n?4:n;return e.jsx(I,{variant:"skeleton-form",rows:r,withContainer:!1})},exports.FormSidebar=function(a){var s=a.opened,c=a.onClose,u=a.onSuccess,p=a.title,h=a.editMode,m=void 0!==h&&h,x=a.editItem,g=a.fields,v=a.onSubmit,b=a.width,y=void 0===b?450:b,j=a.initialValues,k=void 0===j?{}:j;a.validateOnSubmit;var w,C=m&&!!x,S=function(){var e={};return g.forEach(function(t){var n;e[t.name]=null!==(n=t.defaultValue)&&void 0!==n?n:"multiselect"===t.type?[]:""}),l(l({},e),k)},I=o.useForm({initialValues:S(),validate:(w={},g.forEach(function(e){w[e.name]=function(t){var n,r,o,i,a,s;return e.required&&(!t||"string"==typeof t&&""===t.trim())?"".concat(e.label," is required"):(null===(n=e.validation)||void 0===n?void 0:n.email)&&t&&!/^\S+@\S+$/.test(t)?"Invalid email format":(null===(r=e.validation)||void 0===r?void 0:r.url)&&t&&!/^https?:\/\/.+/.test(t)?"Invalid URL format":(null===(o=e.validation)||void 0===o?void 0:o.minLength)&&t&&t.length<e.validation.minLength?"".concat(e.label," must be at least ").concat(e.validation.minLength," characters"):(null===(i=e.validation)||void 0===i?void 0:i.maxLength)&&t&&t.length>e.validation.maxLength?"".concat(e.label," must be no more than ").concat(e.validation.maxLength," characters"):(null===(a=e.validation)||void 0===a?void 0:a.pattern)&&t&&!e.validation.pattern.test(t)?"".concat(e.label," format is invalid"):(null===(s=e.validation)||void 0===s?void 0:s.custom)?e.validation.custom(t):null}}),w)});t.useEffect(function(){if(C&&x){var e={};g.forEach(function(t){var n,r;e[t.name]=null!==(r=null!==(n=x[t.name])&&void 0!==n?n:t.defaultValue)&&void 0!==r?r:""}),I.setValues(e)}else C||I.setValues(S())},[x,s,C]);return e.jsxs(n.Paper,{style:{position:"fixed",top:60,right:s?0:"-".concat(y,"px"),bottom:0,width:"".concat(y,"px"),zIndex:1e3,borderRadius:0,display:"flex",flexDirection:"column",borderLeft:"1px solid var(--mantine-color-gray-3)",backgroundColor:"var(--mantine-color-body)",transition:"right 0.3s ease"},children:[e.jsxs(n.Group,{justify:"space-between",p:"md",style:{borderBottom:"1px solid var(--mantine-color-gray-3)"},children:[e.jsx(n.Title,{order:4,children:C?"Edit ".concat(p):"Create New ".concat(p)}),e.jsx(n.ActionIcon,{variant:"subtle",color:"gray",onClick:c,children:e.jsx(r.IconX,{size:18})})]}),e.jsx(n.ScrollArea,{style:{flex:1},children:e.jsx(n.Box,{p:"md",children:e.jsx("form",{onSubmit:I.onSubmit(function(e){return d(void 0,void 0,void 0,function(){var t,n,r;return f(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,v(e)];case 1:return o.sent(),t={title:"Success",message:"".concat(p," ").concat(C?"updated":"created"," successfully"),color:"green"},i.notifications.show(t),u(),c(),I.reset(),[3,3];case 2:return n=o.sent(),console.error("Error ".concat(C?"updating":"creating"," ").concat(p.toLowerCase(),":"),n),r={title:"Error",message:n.message||"Failed to ".concat(C?"update":"create"," ").concat(p.toLowerCase()),color:"red"},i.notifications.show(r),[3,3];case 3:return[2]}})})}),children:e.jsxs(n.Stack,{gap:"md",children:[g.map(function(t){var r=I.getInputProps(t.name),o=l({key:t.name,label:t.label,placeholder:t.placeholder,description:t.description,required:t.required,disabled:t.disabled||C&&"id"===t.name},r);switch(t.type){case"email":return e.jsx(n.TextInput,l({},o,{type:"email"}));case"number":return e.jsx(n.NumberInput,l({},o));case"textarea":return e.jsx(n.Textarea,l({},o,{autosize:!0,minRows:3,maxRows:6}));case"select":return e.jsx(n.Select,l({},o,{data:t.options||[]}));case"multiselect":return e.jsx(n.MultiSelect,l({},o,{data:t.options||[]}));case"json":return e.jsx(n.JsonInput,l({},o,{validationError:"Invalid JSON format",formatOnBlur:!0,autosize:!0,minRows:3}));default:return e.jsx(n.TextInput,l({},o))}}),e.jsxs(n.Group,{justify:"flex-end",mt:"md",children:[e.jsx(n.Button,{variant:"light",onClick:c,children:"Cancel"}),e.jsxs(n.Button,{type:"submit",children:[C?"Update":"Create"," ",p]})]})]})})})})]})},exports.FormSidebarWrapper=function(t){var r=t.children,o=t.cancelLabel,i=void 0===o?"Cancel":o,a=t.submitLabel,s=void 0===a?"Save":a,c=t.onCancel,d=t.onSubmit,f=t.submitDisabled,p=void 0!==f&&f,h=t.showFooterActions,m=void 0===h||h,x=t.onClose,g=u(t,["children","cancelLabel","submitLabel","onCancel","onSubmit","submitDisabled","showFooterActions","onClose"]),v=m?e.jsxs(n.Group,{justify:"flex-end",gap:"sm",children:[e.jsx(n.ActionIcon,{variant:"subtle",onClick:function(){null==c||c(),x()},size:"sm",children:i}),e.jsx(n.ActionIcon,{onClick:d,disabled:p,size:"sm",children:s})]}):void 0;return e.jsx(y,l({},g,{onClose:x,footer:v,children:r}))},exports.InlineLoadingState=function(t){var r=t.message,o=void 0===r?"Loading...":r,i=t.size,a=void 0===i?"sm":i;return e.jsxs(n.Group,{gap:"xs",children:[e.jsx(n.Loader,{size:"xs"===a?12:"sm"===a?16:20}),e.jsx(n.Text,{size:a,c:"dimmed",children:o})]})},exports.LoadingState=I,exports.NoApplicationsState=function(t){var n=t.onCreateApp,r=u(t,["onCreateApp"]);return e.jsx(b,l({},r,{variant:"no-data",context:"applications",onAdd:n}))},exports.NoFunctionsState=function(t){var n=t.onCreateFunction,r=u(t,["onCreateFunction"]);return e.jsx(b,l({},r,{variant:"no-data",context:"functions",onAdd:n}))},exports.NoSearchResults=function(t){var n=t.onClearFilters,r=t.onRefresh,o=u(t,["onClearFilters","onRefresh"]);return e.jsx(b,l({},o,{variant:"no-results",onClearFilters:n,onRefresh:r}))},exports.NoTokensState=function(t){var n=t.onGenerateToken,r=u(t,["onGenerateToken"]);return e.jsx(b,l({},r,{variant:"no-data",context:"tokens",onAdd:n}))},exports.NoUsersState=function(t){var n=t.onAddUser,r=u(t,["onAddUser"]);return e.jsx(b,l({},r,{variant:"no-data",context:"users",onAdd:n}))},exports.NotificationMessages=O,exports.PageLoadingState=function(t){var n=t.message,r=void 0===n?"Loading page...":n;return e.jsx(I,{variant:"spinner",message:r,height:"60vh",size:"lg"})},exports.QuickSidebar=function(t){var n=t.content,r=t.actions,o=u(t,["content","actions"]);return e.jsx(y,l({},o,{footer:r,children:n}))},exports.RuntimeBadge=function(t){return e.jsx(x,l({},t,{variant:"runtime"}))},exports.SeverityBadge=function(t){return e.jsx(x,l({},t,{variant:"severity"}))},exports.Sidebar=y,exports.StatusBadge=x,exports.TableLoadingState=function(t){var n=t.rows,r=void 0===n?5:n,o=t.columns,i=void 0===o?4:o;return e.jsx(I,{variant:"skeleton-table",rows:r,columns:i,withContainer:!1})},exports.UserRoleBadge=function(t){return e.jsx(x,l({},t,{variant:"role"}))},exports.ValidationMessages=L,exports.ValidationPatterns=F,exports.combineValidators=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){for(var n=0,r=e;n<r.length;n++){var o=(0,r[n])(t);if(o)return o}return null}},exports.createArchiveAction=function(e){return{key:"archive",label:"Archive",icon:r.IconArchive,color:"orange",onClick:e,confirm:{title:"Archive Item",message:"Are you sure you want to archive this item?"}}},exports.createCopyAction=C,exports.createDeleteAction=S,exports.createEditAction=w,exports.createRestoreAction=function(e){return{key:"restore",label:"Restore",icon:r.IconRestore,color:"green",onClick:e}},exports.createViewAction=k,exports.formatDuration=function(e){return e<60?"".concat(e,"s"):e<3600?"".concat(Math.floor(e/60),"m"):e<86400?"".concat(Math.floor(e/3600),"h"):"".concat(Math.floor(e/86400),"d")},exports.getApplicationActions=function(e,t,n){return p(p([w(e)],n?[{key:"configure",label:"Configure",icon:r.IconSettings,onClick:n}]:[],!0),[S(t,"application")],!1)},exports.getFunctionActions=function(e,t,n,o){return p(p(p([],n?[{key:"execute",label:"Execute",icon:r.IconPlayerPlay,color:"green",onClick:n}]:[],!0),o?[{key:"logs",label:"View Logs",icon:r.IconEye,onClick:o}]:[],!0),[w(e),S(t,"function")],!1)},exports.getTokenActions=function(e,t,n){return p(p(p([],t?[C(t)]:[],!0),n?[{key:"refresh",label:"Refresh",icon:r.IconRefresh,onClick:n}]:[],!0),[{key:"revoke",label:"Revoke",icon:r.IconPlayerStop,color:"red",onClick:e,confirm:{title:"Revoke Token",message:"Are you sure you want to revoke this token? This action cannot be undone and will immediately disable the token.",confirmLabel:"Revoke"}}],!1)},exports.getUserActions=function(e,t,n){return p(p([],n?[k(n)]:[],!0),[w(e),S(t,"user")],!1)},exports.parseDuration=function(e){var t=e.match(/^(\d+)([smhd]?)$/);if(!t)return 86400;var n=parseInt(t[1]);switch(t[2]||"h"){case"s":return n;case"m":return 60*n;case"h":default:return 3600*n;case"d":return 86400*n}},exports.showCrudNotification=z,exports.showErrorNotification=T,exports.showInfoNotification=function(e,t){void 0===t&&(t="Info");var n={title:t,message:e,color:"blue"};i.notifications.show(n)},exports.showSuccessNotification=P,exports.showWarningNotification=function(e,t){void 0===t&&(t="Warning");var n={title:t,message:e,color:"yellow"};i.notifications.show(n)},exports.useApiService=function(e,n){var r=t.useState([]),o=r[0],i=r[1],a=t.useState(!1),c=a[0],u=a[1],h=t.useState(null),m=h[0],x=h[1],g=t.useState(0),v=g[0],b=g[1],y=t.useState(!1),j=y[0],k=y[1],w=s.create({baseURL:e.baseURL,timeout:e.timeout||1e4,headers:l({"Content-Type":"application/json"},e.defaultHeaders)});w.interceptors.request.use(function(e){return e.headers["X-User-Email"]="admin@example.com",e},function(e){return Promise.reject(e)}),w.interceptors.response.use(function(e){return e},function(e){var t,n,r=(null===(n=null===(t=e.response)||void 0===t?void 0:t.data)||void 0===n?void 0:n.message)||e.message||"An error occurred";return x(r),Promise.reject(e)});var C=t.useCallback(function(){x(null)},[]),S=t.useCallback(function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return d(void 0,p([],e,!0),void 0,function(e){var t,r,o,a,s,c,l,d;return void 0===e&&(e={}),f(this,function(f){switch(f.label){case 0:u(!0),x(null),f.label=1;case 1:return f.trys.push([1,3,4,5]),t=new URLSearchParams,Object.entries(e).forEach(function(e){var n=e[0],r=e[1];null!=r&&""!==r&&t.append(n,r.toString())}),[4,w.get("".concat(n,"?").concat(t.toString()))];case 2:if("data"in(r=f.sent()).data&&Array.isArray(r.data.data))return o=r.data,i(o.data),b(o.total),k(o.has_more||!1),[2,o.data];if("data"in r.data&&Array.isArray(r.data.data))return a=r.data,i(a.data),b(a.data.length),k(!1),[2,a.data];if(Array.isArray(r.data))return i(r.data),b(r.data.length),k(!1),[2,r.data];throw new Error("Invalid response format");case 3:throw s=f.sent(),c=(null===(d=null===(l=s.response)||void 0===l?void 0:l.data)||void 0===d?void 0:d.message)||s.message||"Failed to fetch data",x(c),s;case 4:return u(!1),[7];case 5:return[2]}})})},[w,n]),I=t.useCallback(function(e){return d(void 0,void 0,void 0,function(){var t,r,o,i,a;return f(this,function(s){switch(s.label){case 0:u(!0),x(null),s.label=1;case 1:return s.trys.push([1,3,4,5]),[4,w.get("".concat(n,"/").concat(e))];case 2:return t=s.sent(),[2,"data"in t.data?t.data.data:t.data];case 3:throw r=s.sent(),o=(null===(a=null===(i=r.response)||void 0===i?void 0:i.data)||void 0===a?void 0:a.message)||r.message||"Failed to fetch item",x(o),r;case 4:return u(!1),[7];case 5:return[2]}})})},[w,n]),A=t.useCallback(function(e){return d(void 0,void 0,void 0,function(){var t,r,o,a,s,c;return f(this,function(l){switch(l.label){case 0:u(!0),x(null),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,w.post(n,e)];case 2:return t=l.sent(),r="data"in t.data?t.data.data:t.data,i(function(e){return p(p([],e,!0),[r],!1)}),b(function(e){return e+1}),[2,r];case 3:throw o=l.sent(),a=(null===(c=null===(s=o.response)||void 0===s?void 0:s.data)||void 0===c?void 0:c.message)||o.message||"Failed to create item",x(a),o;case 4:return u(!1),[7];case 5:return[2]}})})},[w,n]),P=t.useCallback(function(e,t){return d(void 0,void 0,void 0,function(){var r,o,a,s,c,l;return f(this,function(d){switch(d.label){case 0:u(!0),x(null),d.label=1;case 1:return d.trys.push([1,3,4,5]),[4,w.put("".concat(n,"/").concat(e),t)];case 2:return r=d.sent(),o="data"in r.data?r.data.data:r.data,i(function(t){return t.map(function(t){return t.id===e?o:t})}),[2,o];case 3:throw a=d.sent(),s=(null===(l=null===(c=a.response)||void 0===c?void 0:c.data)||void 0===l?void 0:l.message)||a.message||"Failed to update item",x(s),a;case 4:return u(!1),[7];case 5:return[2]}})})},[w,n]),T=t.useCallback(function(e){return d(void 0,void 0,void 0,function(){var t,r,o,a;return f(this,function(s){switch(s.label){case 0:u(!0),x(null),s.label=1;case 1:return s.trys.push([1,3,4,5]),[4,w.delete("".concat(n,"/").concat(e))];case 2:return s.sent(),i(function(t){return t.filter(function(t){return t.id!==e})}),b(function(e){return e-1}),[3,5];case 3:throw t=s.sent(),r=(null===(a=null===(o=t.response)||void 0===o?void 0:o.data)||void 0===a?void 0:a.message)||t.message||"Failed to delete item",x(r),t;case 4:return u(!1),[7];case 5:return[2]}})})},[w,n]),O=t.useCallback(function(){return d(void 0,void 0,void 0,function(){return f(this,function(e){switch(e.label){case 0:return[4,S()];case 1:return e.sent(),[2]}})})},[S]);return{data:o,loading:c,error:m,total:v,hasMore:j,client:w,getAll:S,getById:I,create:A,update:P,delete:T,clearError:C,refresh:O}},exports.useDataFilter=function(e,n){void 0===n&&(n={});var r=n.searchFields,o=void 0===r?["name","title","email","description"]:r,i=n.defaultFilters,a=void 0===i?{}:i,s=t.useState(a),c=s[0],u=s[1],d=t.useState(""),f=d[0],h=d[1],m=t.useCallback(function(e,t){"search"===e?(h(t),u(function(e){return l(l({},e),{search:t})})):u(function(n){var r;return l(l({},n),((r={})[e]=t,r))})},[]),x=t.useCallback(function(){u({}),h("")},[]),g=t.useCallback(function(){u(a),h("")},[a]),v=t.useMemo(function(){var t=p([],e,!0);if(f.trim()){var n=f.toLowerCase().trim();t=t.filter(function(e){return o.some(function(t){var r=e[t];return!!r&&r.toString().toLowerCase().includes(n)})})}return Object.entries(c).forEach(function(e){var n=e[0],r=e[1];"search"!==n&&null!=r&&""!==r&&(t=Array.isArray(r)&&r.length>0?t.filter(function(e){return r.includes(e[n])}):t.filter(function(e){var t=e[n];return null!=t&&(t.toString().toLowerCase()===r.toString().toLowerCase()||"string"==typeof t&&"string"==typeof r&&t.toLowerCase().includes(r.toLowerCase()))}))}),t},[e,f,c,o]);return{filteredData:v,filters:c,setFilter:m,clearFilters:x,resetFilters:g,searchTerm:f,setSearchTerm:h}},exports.useLoadingState=function(e){void 0===e&&(e=!1);var n=t.useState(e),r=n[0],o=n[1],i=t.useState(0),a=i[0],s=i[1];return{loading:r,progress:a,startLoading:t.useCallback(function(){return o(!0)},[]),stopLoading:t.useCallback(function(){o(!1),s(0)},[]),updateProgress:t.useCallback(function(e){s(Math.max(0,Math.min(100,e)))},[]),setLoading:o,setProgress:s}},exports.useSidebar=function(e){void 0===e&&(e=!1);var n=t.useState(e),r=n[0],o=n[1];return{opened:r,open:t.useCallback(function(){return o(!0)},[]),close:t.useCallback(function(){return o(!1)},[]),toggle:t.useCallback(function(){return o(function(e){return!e})},[]),setOpened:o}},exports.validateAppId=function(e){return e?F.appId.test(e)?null:L.appId:null},exports.validateDuration=function(e){return e?F.duration.test(e)?null:L.duration:null},exports.validateEmail=function(e){return e?F.email.test(e)?null:L.email:null},exports.validateJsonString=function(e){if(!e||""===e.trim())return null;try{return JSON.parse(e),null}catch(e){return"Invalid JSON format"}},exports.validateMaxLength=function(e,t,n){return void 0===n&&(n="Field"),e?e.length<=t?null:L.maxLength(n,t):null},exports.validateMinLength=function(e,t,n){return void 0===n&&(n="Field"),e?e.length>=t?null:L.minLength(n,t):null},exports.validatePattern=function(e,t,n){return void 0===n&&(n="Field"),e?t.test(e)?null:L.pattern(n):null},exports.validateRange=function(e,t,n,r){return void 0===r&&(r="Field"),null==e?null:e<t||e>n?L.range(r,t,n):null},exports.validateRequired=function(e){return null==e||""===e||Array.isArray(e)&&0===e.length?"This field is required":null},exports.validateToken=function(e){return e?F.token.test(e)?null:L.token:null},exports.validateUrl=function(e){return e?F.url.test(e)?null:L.url:null},exports.validateUuid=function(e){return e?F.uuid.test(e)?null:L.uuid:null};
|
|
//# sourceMappingURL=index.js.map
|