import { createContext, useState, useCallback, useMemo, useContext, useEffect, createElement, isValidElement, cloneElement } from 'react';
import Me from 'use-resize-observer';
import { debounce, isEqual } from 'lodash-es';
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import { ThemeProvider } from 'styled-components';
import { clsx } from 'clsx';
import { isValidElementType } from 'react-is';
import { Rnd } from 'react-rnd';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

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=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]=useState("desktop"),[s,h]=useState(0),[l,m]=useState(0),i=useCallback(({width:n=0,height:w=0})=>{h(n),m(w),o(te(e,n)||"");},[e]),d=useMemo(()=>debounce(i,t,{leading:!0}),[t,i]);return Me({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:jsx(H.Provider,{value:{breakpoint:r},children:e})};var ae=({theme:e,children:t})=>jsx(ThemeProvider,{theme:e||{},children:t});var ie=createContext({definitions:{},register:()=>{},unregister:()=>{}});var se=({definitions:e={},children:t})=>{let[r,o]=useState(e),s=useCallback(m=>{o(i=>isEqual(i[m.i],m)?i:p(a({},i),{[m.i]:m}));},[]),h=useCallback(m=>{o(i=>{var w;let c=i,{[w=m.i]:d}=c;return A(c,[Z(w)])});},[]),l=useMemo(()=>({definitions:r,register:s,unregister:h}),[r]);return jsx(ie.Provider,{value:l,children:t})};var K=createContext({isDraggable:!1,isResizable:!1,handleId:"",setHandleId:()=>{}}),de=()=>useContext(K);var le=({isResizable:e=!1,isDraggable:t=!1,children:r})=>{let[o,s]=useState("");return jsx(K.Provider,{value:{isDraggable:t,isResizable:e,handleId:o,setHandleId:s},children:r})};var F=createContext({layout:[],rows:12,cols:12,rowHeight:78,colWidth:0});var V=()=>useContext(H)||a({},E);function P(...e){return 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:""},$=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]=useState(()=>localStorage.getItem(r)||t);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;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 jsx($.Provider,p(a({},h),{value:w,children:e}))}var O=()=>{let e=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})=>jsx(Fragment,{children:e}),tt=({children:e,contentRef:t})=>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(),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 jsx(F.Provider,{value:{layout:T,cols:v,rows:y,colWidth:Y,rowHeight:B},children: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:[jsx(c,p(a({},g),{children:jsx(f,a({},g))})),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 jsx(oe,{breakpoints:r,children:jsx(we,p(a({},e),{children:jsx(ae,p(a({},e),{children:jsx(se,{children:jsx(le,{isDraggable:o,isResizable:s,children:t})})}))}))})};var ge=(e,t={})=>isValidElement(e)?cloneElement(e,t):isValidElementType(e)?jsx(e,a({},t)):null;var z=()=>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=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?jsx(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:jsx(z,{}),bottomRight:jsx(z,{}),bottomLeft:jsx(z,{}),topLeft: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}):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=()=>useContext(F);var mt=({children:e})=>jsx(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 jsx(Fragment,{children:l.map((d,n)=>!d.w||!d.i?null: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=useMemo(()=>t||new QueryClient({defaultOptions:{queries:{retry:!1}}}),[t]);return jsx(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"),createElement(fe,p(a({},o),{key:`themeMode-${t}-${o.themeName}`}),o.children,jsx(ve,{components:o.components,resource:o.resource,resoucreProps:o.resoucreProps||{},onLayoutChange:o.onLayoutChange}))},Pe=e=>jsx(Ce,{children:jsx(me,{themeProvider:e.themeProvider,onThemeNameChange:e.onThemeNameChange,children:jsx(bt,a({},e))})});var Go=Pe;

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