'use strict';

var react = require('react');
var Me = require('use-resize-observer');
var lodashEs = require('lodash-es');
var jsxRuntime = require('react/jsx-runtime');
var styledComponents = require('styled-components');
var clsx = require('clsx');
var reactIs = require('react-is');
var reactRnd = require('react-rnd');
var reactQuery = require('@tanstack/react-query');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var Me__default = /*#__PURE__*/_interopDefault(Me);

var Re=Object.defineProperty,ze=Object.defineProperties;var De=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var G=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var j=(e,t,r)=>t in e?Re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,a=(e,t)=>{for(var r in t||(t={}))G.call(t,r)&&j(e,r,t[r]);if(W)for(var r of W(t))J.call(t,r)&&j(e,r,t[r]);return e},p=(e,t)=>ze(e,De(t));var Z=e=>typeof e=="symbol"?e:e+"",A=(e,t)=>{var r={};for(var o in e)G.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(e!=null&&W)for(var o of W(e))t.indexOf(o)<0&&J.call(e,o)&&(r[o]=e[o]);return r};var E={breakpoint:"desktop"},H=react.createContext(a({},E));var ee={showroom:2600,desktop:1300,tablet:500,mobile:0};function Se(e){return Object.keys(e).sort(function(r,o){return e[r]-e[o]})}function te(e,t){if(!t)return "desktop";let r=Se(e),o=r[0];if(!o)return "desktop";for(let s=1,h=r.length;s<h;s++){let l=r[s];t>e[l]&&(o=l);}return o}var re=(e=ee,t=800)=>{let[r,o]=react.useState("desktop"),[s,h]=react.useState(0),[l,m]=react.useState(0),i=react.useCallback(({width:n=0,height:w=0})=>{h(n),m(w),o(te(e,n)||"");},[e]),d=react.useMemo(()=>lodashEs.debounce(i,t,{leading:!0}),[t,i]);return Me__default.default({ref:document.body,onResize:d}),{breakpoint:r,width:s,height:l}};var oe=({children:e,breakpoints:t})=>{let{breakpoint:r,width:o}=re(t);return o<=0?null:jsxRuntime.jsx(H.Provider,{value:{breakpoint:r},children:e})};var ae=({theme:e,children:t})=>jsxRuntime.jsx(styledComponents.ThemeProvider,{theme:e||{},children:t});var ie=react.createContext({definitions:{},register:()=>{},unregister:()=>{}});var se=({definitions:e={},children:t})=>{let[r,o]=react.useState(e),s=react.useCallback(m=>{o(i=>lodashEs.isEqual(i[m.i],m)?i:p(a({},i),{[m.i]:m}));},[]),h=react.useCallback(m=>{o(i=>{var w;let c=i,{[w=m.i]:d}=c;return A(c,[Z(w)])});},[]),l=react.useMemo(()=>({definitions:r,register:s,unregister:h}),[r]);return jsxRuntime.jsx(ie.Provider,{value:l,children:t})};var K=react.createContext({isDraggable:!1,isResizable:!1,handleId:"",setHandleId:()=>{}}),de=()=>react.useContext(K);var le=({isResizable:e=!1,isDraggable:t=!1,children:r})=>{let[o,s]=react.useState("");return jsxRuntime.jsx(K.Provider,{value:{isDraggable:t,isResizable:e,handleId:o,setHandleId:s},children:r})};var F=react.createContext({layout:[],rows:12,cols:12,rowHeight:78,colWidth:0});var V=()=>react.useContext(H)||a({},E);function P(...e){return clsx.clsx(e)}var Q=e=>{try{document.documentElement.style.colorScheme=e,document.documentElement.setAttribute("data-theme",e);}catch(t){console.log(t);}},ce=(e="")=>{console.log(e,"name");try{document.documentElement.setAttribute("data-theme-name",e);}catch(t){console.log(t);}};var Ge={isDarkTheme:()=>!0,themeMode:"system",setThemeMode:()=>null,setThemeName:()=>null,themeName:""},$=react.createContext(Ge);function me(l){var m=l,{children:e,defaultTheme:t="system",storageKey:r="vite-ui-theme",themeProvider:o,onThemeNameChange:s}=m,h=A(m,["children","defaultTheme","storageKey","themeProvider","onThemeNameChange"]);let[i,d]=react.useState(()=>localStorage.getItem(r)||t);react.useEffect(()=>{let c=window.document.documentElement;if(c.classList.remove("light","dark"),i==="system"){let f=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";c.classList.add(f),Q(f);return}c.classList.add(i),Q(i);},[i]);let n=typeof o=="function"?o({themeMode:i}):o;react.useEffect(()=>{window.document.documentElement.classList.remove("jfDarkTheme","jfLightTheme"),ce(n==null?void 0:n.themeName);},[n==null?void 0:n.themeName]);let w={themeName:(n==null?void 0:n.themeName)||"",setThemeName:(c="")=>{c&&(localStorage.setItem("vite-ui-theme-name",c),s&&s(c));},isDarkTheme:()=>i!=="light",themeMode:i,setThemeMode:c=>{c&&(localStorage.setItem(r,c),d(c));}};return jsxRuntime.jsx($.Provider,p(a({},h),{value:w,children:e}))}var O=()=>{let e=react.useContext($);if(e===void 0)throw new Error("useTheme must be used within a ThemeProvider");return e};var he=e=>e.map(t=>(t.y||0)+(t.h||0)).sort((t,r)=>r-t)[0];var u=e=>{if(isNaN(e))return 0;let t=e.toFixed(2);return parseFloat(t)};var ue=({children:e})=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:e}),tt=({children:e,contentRef:t})=>jsxRuntime.jsx("div",{ref:t,style:{width:"100%",height:"100%"},children:e}),we=({children:e,components:t,themeName:r,minHeight:o=861,layout:s,cols:h=12,rowHeight:l=78,resource:m={},wrapperStyle:i,wrapperProps:d})=>{let{breakpoint:n}=V(),{themeMode:w}=O(),c=(t==null?void 0:t.headerWrapper)||ue,f=(t==null?void 0:t.headerInner)||ue,D=(t==null?void 0:t.content)||tt,g={breakpoint:n,themeName:r},T=(typeof s=="function"?s({breakpoint:n,themeMode:w,themeName:r}):s||[]).filter(k=>m[k.i]),v=typeof h=="function"?h({breakpoint:n}):h,y=he(T),{ref:X,height:S=0,width:L=0}=Me__default.default(),B=n==="desktop"||n==="showroom"?u(S/y):typeof l=="function"?l({breakpoint:n,themeMode:w,themeName:r}):l,Y=v?u(L/v):0;return jsxRuntime.jsx(F.Provider,{value:{layout:T,cols:v,rows:y,colWidth:Y,rowHeight:B},children:jsxRuntime.jsxs("div",p(a({},d),{className:P("dashboardAppResponsive",r,d==null?void 0:d.className,n),style:a({width:"100%",height:"100%",position:"relative",minHeight:o},i),children:[jsxRuntime.jsx(c,p(a({},g),{children:jsxRuntime.jsx(f,a({},g))})),jsxRuntime.jsx(D,p(a({},g),{contentRef:X,children:e}))]}))})};var fe=e=>{let{children:t,breakpoints:r,isDraggable:o=!1,isResizable:s=!1}=e;return jsxRuntime.jsx(oe,{breakpoints:r,children:jsxRuntime.jsx(we,p(a({},e),{children:jsxRuntime.jsx(ae,p(a({},e),{children:jsxRuntime.jsx(se,{children:jsxRuntime.jsx(le,{isDraggable:o,isResizable:s,children:t})})}))}))})};var ge=(e,t={})=>react.isValidElement(e)?react.cloneElement(e,t):reactIs.isValidElementType(e)?jsxRuntime.jsx(e,a({},t)):null;var z=()=>jsxRuntime.jsx("div",{className:"resizable-handle-component"});var be=e=>{let{h:t=0,i:r="",w:o=0,x:s=0,y:h=0,padding:l=12,matchBreak:m,colWidth:i=0,rowHeight:d=0,style:n,isDraggable:w=!0,isResizable:c=!0,zIndex:f,children:D,onLayoutChange:g}=e,{isDraggable:T,isResizable:v,handleId:y,setHandleId:X}=de(),S=react.useMemo(()=>{let C=a({},n);return l&&(C.padding=Array.isArray(l)?l.map(M=>(M||0)+"px").join(" "):l),f&&(C.zIndex=f),C},[l,n,f]),L=w===!1||T===!1,B=c!==!1&&v!==!1,Y=B||!L,k=!!(r&&y&&y===r),q=u(o*i),_=u(t*d);return Y?jsxRuntime.jsx(reactRnd.Rnd,{bounds:"parent",className:P("item-Rnd",k?"resizeActive":""),dragGrid:[i/4,d/4],resizeGrid:[i/4,d/4],onMouseDown:()=>{X(r||"");},position:{x:u(s*i),y:u(h*d)},size:{width:q,height:_},style:{zIndex:f,padding:S.padding,borderWidth:"2px",borderStyle:"solid",borderColor:k?"#2f54eb":"transparent"},resizeHandleStyles:{topRight:{width:10,height:10,right:-5,top:-5},topLeft:{width:10,height:10,left:-5,top:-5},bottomRight:{width:10,height:10,right:-5,bottom:-5},bottomLeft:{width:10,height:10,left:-5,bottom:-5}},resizeHandleComponent:{topRight:jsxRuntime.jsx(z,{}),bottomRight:jsxRuntime.jsx(z,{}),bottomLeft:jsxRuntime.jsx(z,{}),topLeft:jsxRuntime.jsx(z,{})},disableDragging:L,enableResizing:B&&k?{bottomRight:!0,right:!0,bottom:!0}:!1,onDragStop:(C,{x:M,y:I})=>{g&&g(r||"",{x:u(M/i),y:u(I/d)});},onResizeStop:(C,M,I)=>{g&&g(r||"",{w:u(parseInt(I.style.width||0,10)/i),h:u(parseInt(I.style.height||0,10)/d)});},children:D}):jsxRuntime.jsx("div",{className:P("dashboardItem",m),style:p(a({},S),{position:"absolute",left:0,top:0,width:q,height:_,transform:`translate( ${u(s*i)}px ,${u(h*d)}px )`}),children:D})};var xe=()=>react.useContext(F);var mt=({children:e})=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:e}),ve=({resource:e={},resoucreProps:t,onLayoutChange:r,components:o})=>{let s=(o==null?void 0:o.containerWrapper)||mt,{breakpoint:h}=V(),{layout:l,colWidth:m,rowHeight:i}=xe();return jsxRuntime.jsx(jsxRuntime.Fragment,{children:l.map((d,n)=>!d.w||!d.i?null:react.createElement(be,p(a({zIndex:n+3,onLayoutChange:r},d),{matchBreak:h,colWidth:m,rowHeight:i,key:`DashboardItem-${d.i}`}),ge(e[d.i],p(a({},t),{breakpoint:h,colWidth:m,rowHeight:i,containerWrapper:s,nodeContentRenderer:s}))))})};var Ce=({children:e,queryClient:t})=>{let r=react.useMemo(()=>t||new reactQuery.QueryClient({defaultOptions:{queries:{retry:!1}}}),[t]);return jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:r,children:e})};var bt=e=>{let{themeMode:t}=O(),r=typeof e.themeProvider=="function"?e.themeProvider({themeMode:t}):e.themeProvider,o=p(a(a({},r),e),{components:a(a({},e.components),r==null?void 0:r.components)});return console.log(o,"props"),react.createElement(fe,p(a({},o),{key:`themeMode-${t}-${o.themeName}`}),o.children,jsxRuntime.jsx(ve,{components:o.components,resource:o.resource,resoucreProps:o.resoucreProps||{},onLayoutChange:o.onLayoutChange}))},Pe=e=>jsxRuntime.jsx(Ce,{children:jsxRuntime.jsx(me,{themeProvider:e.themeProvider,onThemeNameChange:e.onThemeNameChange,children:jsxRuntime.jsx(bt,a({},e))})});var Go=Pe;

exports.BreakpointContext = H;
exports.CoreContext = fe;
exports.CoreDashboardAppResponsive = Pe;
exports.CoreDashboardAppResponsiveInner = bt;
exports.DashboardAppResponsive = Go;
exports.DashboardItem = be;
exports.QueryClientProvider = Ce;
exports.ThemeModeProvider = me;
exports.ThemeProviderContext = $;
exports.cn = P;
exports.defaultBreakpointContextValue = E;
exports.useBreakpointContext = V;
exports.useBreakpoints = re;
exports.useThemeMode = O;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.cjs.map