realtimex-crm 0.7.11 → 0.7.13

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.
@@ -148,6 +148,6 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
148
148
  L`+r+" "+r+`
149
149
  L0 `+r+`
150
150
  L`+r/2+` 0
151
- `,fill:a,opacity:s,strokeWidth:d,stroke:c===void 0?"transparent":c,style:{pointerEvents:"none"}})})},"y");function Zl(){return Zl=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Zl.apply(null,arguments)}o(Zl,"b");var xi={translateX:0,translateY:0,padding:0,itemsSpacing:0,itemDirection:"left-to-right",justify:!1,symbolShape:"square",symbolSize:16,symbolSpacing:8},t9e={top:0,right:0,bottom:0,left:0},m3=o(function(e){var t,n=e.direction,r=e.itemsSpacing,a=e.padding,i=e.itemCount,s=e.itemWidth,l=e.itemHeight;if(typeof a!="number"&&(typeof(t=a)!="object"||Array.isArray(t)||t===null))throw new Error("Invalid property padding, must be one of: number, object");var d=typeof a=="number"?{top:a,right:a,bottom:a,left:a}:Zl({},t9e,a),c=d.left+d.right,p=d.top+d.bottom,m=s+c,g=l+p,x=(i-1)*r;return n==="row"?m=s*i+x+c:n==="column"&&(g=l*i+x+p),{width:m,height:g,padding:d}},"A"),jae=o(function(e){var t=e.anchor,n=e.translateX,r=e.translateY,a=e.containerWidth,i=e.containerHeight,s=e.width,l=e.height,d=n,c=r;switch(t){case"top":d+=(a-s)/2;break;case"top-right":d+=a-s;break;case"right":d+=a-s,c+=(i-l)/2;break;case"bottom-right":d+=a-s,c+=i-l;break;case"bottom":d+=(a-s)/2,c+=i-l;break;case"bottom-left":c+=i-l;break;case"left":c+=(i-l)/2;break;case"center":d+=(a-s)/2,c+=(i-l)/2}return{x:d,y:c}},"C"),Oae=o(function(e){var t,n,r,a,i,s,l=e.direction,d=e.justify,c=e.symbolSize,p=e.symbolSpacing,m=e.width,g=e.height;switch(l){case"left-to-right":t=0,n=(g-c)/2,a=g/2,s="central",d?(r=m,i="end"):(r=c+p,i="start");break;case"right-to-left":t=m-c,n=(g-c)/2,a=g/2,s="central",d?(r=0,i="start"):(r=m-c-p,i="end");break;case"top-to-bottom":t=(m-c)/2,n=0,r=m/2,i="middle",d?(a=g,s="alphabetic"):(a=c+p,s="text-before-edge");break;case"bottom-to-top":t=(m-c)/2,n=g-c,r=m/2,i="middle",d?(a=0,s="text-before-edge"):(a=g-c-p,s="alphabetic")}return{symbolX:t,symbolY:n,labelX:r,labelY:a,labelAnchor:i,labelAlignment:s}},"z"),n9e={circle:X$e,diamond:Z$e,square:J$e,triangle:e9e},r9e=o(function(e){var t,n,r,a,i,s,l,d,c,p,m,g=e.x,x=e.y,w=e.width,S=e.height,_=e.data,E=e.direction,C=E===void 0?xi.itemDirection:E,O=e.justify,j=O===void 0?xi.justify:O,T=e.textColor,k=e.background,A=k===void 0?"transparent":k,P=e.opacity,M=P===void 0?1:P,D=e.symbolShape,I=D===void 0?xi.symbolShape:D,L=e.symbolSize,F=L===void 0?xi.symbolSize:L,q=e.symbolSpacing,U=q===void 0?xi.symbolSpacing:q,$=e.symbolBorderWidth,H=$===void 0?0:$,z=e.symbolBorderColor,W=z===void 0?"transparent":z,V=e.onClick,Q=e.onMouseEnter,K=e.onMouseLeave,Y=e.toggleSerie,ee=e.effects,te=y.useState({}),oe=te[0],ne=te[1],fe=Tr(),re=y.useCallback((function(X){if(ee){var se=ee.filter((function(me){return me.on==="hover"})).reduce((function(me,Te){return Zl({},me,Te.style)}),{});ne(se)}Q?.(_,X)}),[Q,_,ee]),ce=y.useCallback((function(X){if(ee){var se=ee.filter((function(me){return me.on!=="hover"})).reduce((function(me,Te){return Zl({},me,Te.style)}),{});ne(se)}K?.(_,X)}),[K,_,ee]),he=Oae({direction:C,justify:j,symbolSize:(t=oe.symbolSize)!=null?t:F,symbolSpacing:U,width:w,height:S}),J=he.symbolX,De=he.symbolY,we=he.labelX,Ce=he.labelY,ke=he.labelAnchor,Re=he.labelAlignment,Pe=[V,Q,K,Y].some((function(X){return X!==void 0})),ze=typeof I=="function"?I:n9e[I];return h.jsxs("g",{transform:"translate("+g+","+x+")",style:{opacity:(n=oe.itemOpacity)!=null?n:M},children:[h.jsx("rect",{width:w,height:S,fill:(r=oe.itemBackground)!=null?r:A,style:{cursor:Pe?"pointer":"auto"},onClick:o(function(X){V?.(_,X),Y?.(_.id)},"onClick"),onMouseEnter:re,onMouseLeave:ce}),y.createElement(ze,Zl({id:_.id,x:J,y:De,size:(a=oe.symbolSize)!=null?a:F,fill:(i=(s=_.fill)!=null?s:_.color)!=null?i:"black",borderWidth:(l=oe.symbolBorderWidth)!=null?l:H,borderColor:(d=oe.symbolBorderColor)!=null?d:W},_.hidden?fe.legends.hidden.symbol:void 0)),h.jsx(R_,{textAnchor:ke,style:Zl({},fe.legends.text,{fill:(c=(p=(m=oe.itemTextColor)!=null?m:T)!=null?p:fe.legends.text.fill)!=null?c:"black",dominantBaseline:Re,pointerEvents:"none",userSelect:"none"},_.hidden?fe.legends.hidden.text:void 0),x:we,y:Ce,children:_.label})]})},"B"),a9e=o(function(e){var t=e.data,n=e.x,r=e.y,a=e.direction,i=e.padding,s=i===void 0?xi.padding:i,l=e.justify,d=e.effects,c=e.itemWidth,p=e.itemHeight,m=e.itemDirection,g=m===void 0?xi.itemDirection:m,x=e.itemsSpacing,w=x===void 0?xi.itemsSpacing:x,S=e.itemTextColor,_=e.itemBackground,E=_===void 0?"transparent":_,C=e.itemOpacity,O=C===void 0?1:C,j=e.symbolShape,T=e.symbolSize,k=e.symbolSpacing,A=e.symbolBorderWidth,P=e.symbolBorderColor,M=e.onClick,D=e.onMouseEnter,I=e.onMouseLeave,L=e.toggleSerie,F=m3({itemCount:t.length,itemWidth:c,itemHeight:p,itemsSpacing:w,direction:a,padding:s}).padding,q=a==="row"?c+w:0,U=a==="column"?p+w:0;return h.jsx("g",{transform:"translate("+n+","+r+")",children:t.map((function($,H){return h.jsx(r9e,{data:$,x:H*q+F.left,y:H*U+F.top,width:c,height:p,direction:g,justify:l,effects:d,textColor:S,background:E,opacity:O,symbolShape:j,symbolSize:T,symbolSpacing:k,symbolBorderWidth:A,symbolBorderColor:P,onClick:M,onMouseEnter:D,onMouseLeave:I,toggleSerie:L},H)}))})},"H"),i9e=o(function(e){var t=e.data,n=e.containerWidth,r=e.containerHeight,a=e.translateX,i=a===void 0?xi.translateX:a,s=e.translateY,l=s===void 0?xi.translateY:s,d=e.anchor,c=e.direction,p=e.padding,m=p===void 0?xi.padding:p,g=e.justify,x=e.itemsSpacing,w=x===void 0?xi.itemsSpacing:x,S=e.itemWidth,_=e.itemHeight,E=e.itemDirection,C=e.itemTextColor,O=e.itemBackground,j=e.itemOpacity,T=e.symbolShape,k=e.symbolSize,A=e.symbolSpacing,P=e.symbolBorderWidth,M=e.symbolBorderColor,D=e.onClick,I=e.onMouseEnter,L=e.onMouseLeave,F=e.toggleSerie,q=e.effects,U=m3({itemCount:t.length,itemsSpacing:w,itemWidth:S,itemHeight:_,direction:c,padding:m}),$=U.width,H=U.height,z=jae({anchor:d,translateX:i,translateY:l,containerWidth:n,containerHeight:r,width:$,height:H}),W=z.x,V=z.y;return h.jsx(a9e,{data:t,x:W,y:V,direction:c,padding:m,justify:g,effects:q,itemsSpacing:w,itemWidth:S,itemHeight:_,itemDirection:E,itemTextColor:C,itemBackground:O,itemOpacity:j,symbolShape:T,symbolSize:k,symbolSpacing:A,symbolBorderWidth:P,symbolBorderColor:M,onClick:D,onMouseEnter:I,onMouseLeave:L,toggleSerie:typeof F=="boolean"?void 0:F})},"E"),o9e={start:"left",middle:"center",end:"right"},s9e=o(function(e,t){var n=t.data,r=t.containerWidth,a=t.containerHeight,i=t.translateX,s=i===void 0?0:i,l=t.translateY,d=l===void 0?0:l,c=t.anchor,p=t.direction,m=t.padding,g=m===void 0?0:m,x=t.justify,w=x!==void 0&&x,S=t.itemsSpacing,_=S===void 0?0:S,E=t.itemWidth,C=t.itemHeight,O=t.itemDirection,j=O===void 0?"left-to-right":O,T=t.itemTextColor,k=t.symbolSize,A=k===void 0?16:k,P=t.symbolSpacing,M=P===void 0?8:P,D=t.theme,I=m3({itemCount:n.length,itemWidth:E,itemHeight:C,itemsSpacing:_,direction:p,padding:g}),L=I.width,F=I.height,q=I.padding,U=jae({anchor:c,translateX:s,translateY:d,containerWidth:r,containerHeight:a,width:L,height:F}),$=U.x,H=U.y,z=p==="row"?E+_:0,W=p==="column"?C+_:0;e.save(),e.translate($,H),wg(e,D.legends.text),n.forEach((function(V,Q){var K,Y=Q*z+q.left,ee=Q*W+q.top,te=Oae({direction:j,justify:w,symbolSize:A,symbolSpacing:M,width:E,height:C}),oe=te.symbolX,ne=te.symbolY,fe=te.labelX,re=te.labelY,ce=te.labelAnchor,he=te.labelAlignment;e.fillStyle=(K=V.color)!=null?K:"black",e.fillRect(Y+oe,ee+ne,A,A),e.textAlign=o9e[ce],he==="central"&&(e.textBaseline="middle"),_g(e,Zl({},D.legends.text,{fill:T??D.legends.text.fill}),String(V.label),Y+fe,ee+re)})),e.restore()},"L"),l9e=o(function(e,t,n,r,a,i){i>0?(e.moveTo(t+i,n),e.lineTo(t+r-i,n),e.quadraticCurveTo(t+r,n,t+r,n+i),e.lineTo(t+r,n+a-i),e.quadraticCurveTo(t+r,n+a,t+r-i,n+a),e.lineTo(t+i,n+a),e.quadraticCurveTo(t,n+a,t,n+a-i),e.lineTo(t,n+i),e.quadraticCurveTo(t,n,t+i,n),e.closePath()):e.rect(t,n,r,a)},"o");function pn(){return pn=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},pn.apply(null,arguments)}o(pn,"Q");function Rc(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}o(Rc,"U");var HV,c9e=o(function(e){var t=e.bars,n=e.annotations,r=_ae({data:t,annotations:n,getPosition:o(function(a){return{x:a.x+a.width/2,y:a.y+a.height/2}},"getPosition"),getDimensions:o(function(a){var i=a.height,s=a.width;return{width:s,height:i,size:Math.max(s,i)}},"getDimensions")});return h.jsx(h.Fragment,{children:r.map((function(a,i){return h.jsx(M$e,pn({},a),i)}))})},"$"),u9e=o(function(e){var t=e.width,n=e.height,r=e.legends,a=e.toggleSerie;return h.jsx(h.Fragment,{children:r.map((function(i,s){var l,d=i[0],c=i[1];return h.jsx(i9e,pn({},d,{containerWidth:t,containerHeight:n,data:(l=d.data)!=null?l:c,toggleSerie:d.toggleSerie&&d.dataFrom==="keys"?a:void 0}),s)}))})},"ee"),d9e=["data"],f9e=o(function(e){var t,n=e.bar,r=n.data,a=Rc(n,d9e),i=e.style,s=i.borderColor,l=i.color,d=i.height,c=i.labelColor,p=i.labelOpacity,m=i.labelX,g=i.labelY,x=i.transform,w=i.width,S=i.textAnchor,_=e.borderRadius,E=e.borderWidth,C=e.label,O=e.shouldRenderLabel,j=e.isInteractive,T=e.onClick,k=e.onMouseEnter,A=e.onMouseLeave,P=e.tooltip,M=e.isFocusable,D=e.ariaLabel,I=e.ariaLabelledBy,L=e.ariaDescribedBy,F=e.ariaDisabled,q=e.ariaHidden,U=Tr(),$=tre(),H=$.showTooltipFromEvent,z=$.showTooltipAt,W=$.hideTooltip,V=y.useMemo((function(){return function(){return y.createElement(P,pn({},a,r))}}),[P,a,r]),Q=y.useCallback((function(ne){T?.(pn({color:a.color},r),ne)}),[a,r,T]),K=y.useCallback((function(ne){return H(V(),ne)}),[H,V]),Y=y.useCallback((function(ne){k?.(r,ne),H(V(),ne)}),[r,k,H,V]),ee=y.useCallback((function(ne){A?.(r,ne),W()}),[r,W,A]),te=y.useCallback((function(){z(V(),[a.absX+a.width/2,a.absY])}),[z,V,a]),oe=y.useCallback((function(){W()}),[W]);return h.jsxs(ur.g,{transform:x,children:[h.jsx(ur.rect,{width:ON(w,(function(ne){return Math.max(ne,0)})),height:ON(d,(function(ne){return Math.max(ne,0)})),rx:_,ry:_,fill:(t=r.fill)!=null?t:l,strokeWidth:E,stroke:s,focusable:M,tabIndex:M?0:void 0,"aria-label":D?D(r):void 0,"aria-labelledby":I?I(r):void 0,"aria-describedby":L?L(r):void 0,"aria-disabled":F?F(r):void 0,"aria-hidden":q?q(r):void 0,onMouseEnter:j?Y:void 0,onMouseMove:j?K:void 0,onMouseLeave:j?ee:void 0,onClick:j?Q:void 0,onFocus:j&&M?te:void 0,onBlur:j&&M?oe:void 0,"data-testid":"bar.item."+r.id+"."+r.index}),O&&h.jsx(R_,{x:m,y:g,textAnchor:S,dominantBaseline:"central",fillOpacity:p,style:pn({},U.labels.text,{pointerEvents:"none",fill:c}),children:C})]})},"ae"),h9e=["color","label"],p9e=o(function(e){var t=e.color,n=e.label,r=Rc(e,h9e);return h.jsx(M6e,{id:n,value:r.formattedValue,enableChip:!0,color:t})},"ne"),Mn={indexBy:"id",keys:["value"],groupMode:"stacked",layout:"vertical",valueScale:{type:"linear",nice:!0,round:!1},indexScale:{type:"band",round:!1},padding:.1,innerPadding:0,enableGridX:!1,enableGridY:!0,enableLabel:!0,label:"formattedValue",labelPosition:"middle",labelOffset:0,labelSkipWidth:0,labelSkipHeight:0,labelTextColor:{theme:"labels.text.fill"},colorBy:"id",colors:{scheme:"nivo"},borderRadius:0,borderWidth:0,borderColor:{from:"color"},isInteractive:!0,tooltip:p9e,tooltipLabel:o(function(e){return e.id+" - "+e.indexValue},"tooltipLabel"),legends:[],initialHiddenIds:[],annotations:[],enableTotals:!1,totalsOffset:10},Nn=pn({},Mn,{layers:["grid","axes","bars","totals","markers","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},barComponent:f9e,defs:[],fill:[],markers:[],animate:!0,animateOnMount:!1,motionConfig:"default",role:"img",isFocusable:!1}),pr=pn({},Mn,{layers:["grid","axes","bars","totals","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},renderBar:o(function(e,t){var n=t.bar,r=n.color,a=n.height,i=n.width,s=n.x,l=n.y,d=t.borderColor,c=t.borderRadius,p=t.borderWidth,m=t.label,g=t.shouldRenderLabel,x=t.labelStyle,w=t.labelX,S=t.labelY,_=t.textAnchor;e.fillStyle=r,p>0&&(e.strokeStyle=d,e.lineWidth=p),e.beginPath(),l9e(e,s,l,i,a,Math.min(c,a)),e.fill(),p>0&&e.stroke(),g&&(e.textBaseline="middle",e.textAlign=_==="middle"?"center":_,_g(e,x,m,s+w,l+S))},"renderBar"),pixelRatio:typeof window<"u"&&(HV=window.devicePixelRatio)!=null?HV:1}),Rae=o(function(e,t,n,r,a,i){return p3(r,{all:e.map(t),min:0,max:0},a,i).padding(n)},"de"),kae=o(function(e,t){return e.map((function(n){return pn({},t.reduce((function(r,a){return r[a]=null,r}),{}),n)}))},"ue"),k_=o(function(e){return Object.keys(e).reduce((function(t,n){return e[n]&&(t[n]=e[n]),t}),{})},"se"),A_=o(function(e){return[e,Number(e)]},"ce");function Aae(e,t,n,r){return e===void 0&&(e=Mn.layout),n===void 0&&(n=Mn.labelPosition),r===void 0&&(r=Mn.labelOffset),function(a,i){var s=r*(t?-1:1);if(e==="horizontal"){var l=a/2;return n==="start"?l=t?a:0:n==="end"&&(l=t?0:a),{labelX:l+s,labelY:i/2,textAnchor:n==="middle"?"middle":t?"end":"start"}}var d=i/2;return n==="start"?d=t?0:i:n==="end"&&(d=t?i:0),{labelX:a/2,labelY:d-s,textAnchor:"middle"}}}o(Aae,"he");var m9e=["layout","width","height","padding","innerPadding","valueScale","indexScale","hiddenIds"],v3=o(function(e,t){return e>t},"be"),Tae=o(function(e,t){return e<t},"ge"),Pae=o(function(e,t){return Array.from(" ".repeat(t-e),(function(n,r){return e+r}))},"ve"),v9e=o(function(e){return v3(e,0)?0:e},"me"),g9e=o(function(e,t,n,r){var a=e.data,i=e.formatValue,s=e.getColor,l=e.getIndex,d=e.getTooltipLabel,c=e.innerPadding,p=c===void 0?0:c,m=e.keys,g=e.xScale,x=e.yScale,w=e.margin,S=n?Tae:v3,_=a.map(k_),E=[];return m.forEach((function(C,O){return Pae(0,g.domain().length).forEach((function(j){var T,k,A,P=A_(a[j][C]),M=P[0],D=P[1],I=l(a[j]),L=((T=g(I))!=null?T:0)+t*O+p*O,F=S(k=D,0)?(A=x(k))!=null?A:0:r,q=(function($,H){var z;return S($,0)?r-H:((z=x($))!=null?z:0)-r})(D,F),U={id:C,value:M===null?M:D,formattedValue:i(D),hidden:!1,index:j,indexValue:I,data:_[j]};E.push({key:C+"."+U.indexValue,index:E.length,data:U,x:L,y:F,absX:w.left+L,absY:w.top+F,width:t,height:q,color:s(U),label:d(U)})}))})),E},"pe"),y9e=o(function(e,t,n,r){var a=e.data,i=e.formatValue,s=e.getIndex,l=e.getColor,d=e.getTooltipLabel,c=e.keys,p=e.innerPadding,m=p===void 0?0:p,g=e.xScale,x=e.yScale,w=e.margin,S=n?Tae:v3,_=a.map(k_),E=[];return c.forEach((function(C,O){return Pae(0,x.domain().length).forEach((function(j){var T,k,A,P=A_(a[j][C]),M=P[0],D=P[1],I=s(a[j]),L=S(k=D,0)?r:(A=g(k))!=null?A:0,F=((T=x(I))!=null?T:0)+t*O+m*O,q=(function($,H){var z;return S($,0)?((z=g($))!=null?z:0)-r:r-H})(D,L),U={id:C,value:M===null?M:D,formattedValue:i(D),hidden:!1,index:j,indexValue:I,data:_[j]};E.push({key:C+"."+U.indexValue,index:E.length,data:U,x:L,y:F,absX:w.left+L,absY:w.top+F,width:q,height:t,color:l(U),label:d(U)})}))})),E},"ye"),b9e=o(function(e){var t,n,r,a=e.layout,i=e.width,s=e.height,l=e.padding,d=l===void 0?0:l,c=e.innerPadding,p=c===void 0?0:c,m=e.valueScale,g=e.indexScale,x=e.hiddenIds,w=x===void 0?[]:x,S=Rc(e,m9e),_=S.keys.filter((function(H){return!w.includes(H)})),E=kae(S.data,_),C=a==="vertical"?["y","x",i]:["x","y",s],O=C[0],j=C[1],T=C[2],k=Rae(E,S.getIndex,d,g,T,j),A=m.min==="auto"?v9e:function(H){return H},P=E.reduce((function(H,z){return[].concat(H,_.map((function(W){return z[W]})))}),[]).filter(Boolean),M=A(Math.min.apply(Math,P)),D=(r=Math.max.apply(Math,P),isFinite(r)?r:0),I=p3(m,{all:P,min:M,max:D},O==="x"?i:s,O),L=a==="vertical"?[k,I]:[I,k],F=L[0],q=L[1],U=(k.bandwidth()-p*(_.length-1))/_.length,$=[pn({},S,{data:E,keys:_,innerPadding:p,xScale:F,yScale:q}),U,(t=m.reverse)!=null&&t,(n=I(0))!=null?n:0];return{xScale:F,yScale:q,bars:U>0?a==="vertical"?g9e.apply(void 0,$):y9e.apply(void 0,$):[]}},"xe"),x9e=["data","layout","width","height","padding","valueScale","indexScale","hiddenIds"],Nae=o(function(e){var t;return e.some(Array.isArray)?Nae((t=[]).concat.apply(t,e)):e},"ke"),w9e=o(function(e,t,n){var r=e.formatValue,a=e.getColor,i=e.getIndex,s=e.getTooltipLabel,l=e.innerPadding,d=e.stackedData,c=e.xScale,p=e.yScale,m=e.margin,g=[];return d.forEach((function(x){return c.domain().forEach((function(w,S){var _,E,C=x[S],O=(_=c(i(C.data)))!=null?_:0,j=((E=(function(D){return p(D[n?0:1])})(C))!=null?E:0)+.5*l,T=(function(D,I){var L;return((L=p(D[n?1:0]))!=null?L:0)-I})(C,j)-l,k=A_(C.data[x.key]),A=k[0],P=k[1],M={id:x.key,value:A===null?A:P,formattedValue:r(P),hidden:!1,index:S,indexValue:w,data:k_(C.data)};g.push({key:x.key+"."+w,index:g.length,data:M,x:O,y:j,absX:m.left+O,absY:m.top+j,width:t,height:T,color:a(M),label:s(M)})}))})),g},"we"),_9e=o(function(e,t,n){var r=e.formatValue,a=e.getColor,i=e.getIndex,s=e.getTooltipLabel,l=e.innerPadding,d=e.stackedData,c=e.xScale,p=e.yScale,m=e.margin,g=[];return d.forEach((function(x){return p.domain().forEach((function(w,S){var _,E,C=x[S],O=(_=p(i(C.data)))!=null?_:0,j=((E=(function(D){return c(D[n?1:0])})(C))!=null?E:0)+.5*l,T=(function(D,I){var L;return((L=c(D[n?0:1]))!=null?L:0)-I})(C,j)-l,k=A_(C.data[x.key]),A=k[0],P=k[1],M={id:x.key,value:A===null?A:P,formattedValue:r(P),hidden:!1,index:S,indexValue:w,data:k_(C.data)};g.push({key:x.key+"."+w,index:g.length,data:M,x:j,y:O,absX:m.left+j,absY:m.top+O,width:T,height:t,color:a(M),label:s(M)})}))})),g},"Le"),S9e=o(function(e){var t,n,r=e.data,a=e.layout,i=e.width,s=e.height,l=e.padding,d=l===void 0?0:l,c=e.valueScale,p=e.indexScale,m=e.hiddenIds,g=m===void 0?[]:m,x=Rc(e,x9e),w=x.keys.filter((function(U){return!g.includes(U)})),S=G8e().keys(w).offset(Y8e)(kae(r,w)),_=a==="vertical"?["y","x",i]:["x","y",s],E=_[0],C=_[1],O=_[2],j=Rae(r,x.getIndex,d,p,O,C),T=(n=Nae(S),c.type==="log"?n.filter((function(U){return U!==0})):n),k=Math.min.apply(Math,T),A=Math.max.apply(Math,T),P=p3(c,{all:T,min:k,max:A},E==="x"?i:s,E),M=a==="vertical"?[j,P]:[P,j],D=M[0],I=M[1],L=x.innerPadding>0?x.innerPadding:0,F=j.bandwidth(),q=[pn({},x,{innerPadding:L,stackedData:S,xScale:D,yScale:I}),F,(t=c.reverse)!=null&&t];return{xScale:D,yScale:I,bars:F>0?a==="vertical"?w9e.apply(void 0,q):_9e.apply(void 0,q):[]}},"Ce"),E9e=o(function(e){var t=e.bars,n=e.direction,r=e.from,a=e.groupMode,i=e.layout,s=e.legendLabel,l=e.reverse,d=fae(s??(r==="indexes"?"indexValue":"id"));return r==="indexes"?(function(c,p,m){var g=gV(c.map((function(x){var w,S;return{id:(w=x.data.indexValue)!=null?w:"",label:m(x.data),hidden:x.data.hidden,color:(S=x.color)!=null?S:"#000"}})),(function(x){return x.id}));return p==="horizontal"&&g.reverse(),g})(t,i,d):(function(c,p,m,g,x,w){var S=gV(c.map((function(_){var E;return{id:_.data.id,label:w(_.data),hidden:_.data.hidden,color:(E=_.color)!=null?E:"#000"}})),(function(_){return _.id}));return(p==="vertical"&&g==="stacked"&&m==="column"&&x!==!0||p==="horizontal"&&g==="stacked"&&x===!0)&&S.reverse(),S})(t,i,n,a,l,d)},"We"),VV=o(function(e,t,n){var r=e.get(t)||0;e.set(t,r+n)},"Me"),C9e=o(function(e,t,n){var r=e.get(t)||0;e.set(t,r+(n>0?n:0))},"Be"),j9e=o(function(e,t,n){var r=e.get(t)||0;e.set(t,Math.max(r,Number(n)))},"Re"),O9e=o(function(e,t){var n=e.get(t)||0;e.set(t,n+1)},"Oe"),Mae=o(function(e){var t,n=e.indexBy,r=n===void 0?Mn.indexBy:n,a=e.keys,i=a===void 0?Mn.keys:a,s=e.label,l=s===void 0?Mn.label:s,d=e.tooltipLabel,c=d===void 0?Mn.tooltipLabel:d,p=e.valueFormat,m=e.colors,g=m===void 0?Mn.colors:m,x=e.colorBy,w=x===void 0?Mn.colorBy:x,S=e.borderColor,_=S===void 0?Mn.borderColor:S,E=e.labelTextColor,C=E===void 0?Mn.labelTextColor:E,O=e.groupMode,j=O===void 0?Mn.groupMode:O,T=e.layout,k=T===void 0?Mn.layout:T,A=e.data,P=e.margin,M=e.width,D=e.height,I=e.padding,L=I===void 0?Mn.padding:I,F=e.innerPadding,q=F===void 0?Mn.innerPadding:F,U=e.valueScale,$=U===void 0?Mn.valueScale:U,H=e.indexScale,z=H===void 0?Mn.indexScale:H,W=e.initialHiddenIds,V=W===void 0?Mn.initialHiddenIds:W,Q=e.enableLabel,K=Q===void 0?Mn.enableLabel:Q,Y=e.labelSkipWidth,ee=Y===void 0?Mn.labelSkipWidth:Y,te=e.labelSkipHeight,oe=te===void 0?Mn.labelSkipHeight:te,ne=e.legends,fe=ne===void 0?Mn.legends:ne,re=e.legendLabel,ce=e.totalsOffset,he=ce===void 0?Mn.totalsOffset:ce,J=y.useState(V??[]),De=J[0],we=J[1],Ce=y.useCallback((function(We){we((function(pt){return pt.indexOf(We)>-1?pt.filter((function(ge){return ge!==We})):[].concat(pt,[We])}))}),[]),ke=jA(r),Re=jA(l),Pe=jA(c),ze=h3(p),X=Tr(),se=Q$e(g,w),me=BV(_,X),Te=BV(C,X),de=(j==="grouped"?b9e:S9e)({layout:k,data:A,getIndex:ke,keys:i,width:M,height:D,getColor:se,padding:L,innerPadding:q,valueScale:$,indexScale:z,hiddenIds:De,formatValue:ze,getTooltipLabel:Pe,margin:P}),ue=de.bars,Ae=de.xScale,Ne=de.yScale,Le=y.useMemo((function(){return ue.filter((function(We){return We.data.value!==null})).map((function(We,pt){return pn({},We,{index:pt})}))}),[ue]),Ze=y.useCallback((function(We){var pt=We.width,ge=We.height;return!!K&&!(ee>0&&pt<ee)&&!(oe>0&&ge<oe)}),[K,ee,oe]),Pt=y.useMemo((function(){return i.map((function(We){var pt=ue.find((function(ge){return ge.data.id===We}));return pn({},pt,{data:pn({id:We},pt?.data,{hidden:De.includes(We)})})}))}),[De,i,ue]),$t=(t=$.reverse)!=null&&t,kt=y.useMemo((function(){return fe.map((function(We){return[We,E9e({bars:We.dataFrom==="keys"?Pt:ue,direction:We.direction,from:We.dataFrom,groupMode:j,layout:k,legendLabel:re,reverse:$t})]}))}),[fe,Pt,ue,j,k,re,$t]),qt=y.useMemo((function(){return(function(We,pt,ge,ye,ct,Fe,Qe){ye===void 0&&(ye=Mn.layout),ct===void 0&&(ct=Mn.groupMode);var Ve=[];if(We.length===0)return Ve;var Je=new Map,Et=We[0].width,Ye=We[0].height;if(ct==="stacked"){var mt=new Map;We.forEach((function(At){var _t=At.data,vt=_t.indexValue,jt=_t.value;VV(Je,vt,Number(jt)),C9e(mt,vt,Number(jt))})),mt.forEach((function(At,_t){var vt,jt,Z,pe=Je.get(_t)||0;ye==="vertical"?(vt=pt(_t),jt=ge(At),Z=ge(At/2)):(vt=pt(At),jt=ge(_t),Z=pt(At/2)),vt+=ye==="vertical"?Et/2:Fe,jt+=ye==="vertical"?-Fe:Ye/2,Ve.push({key:"total_"+_t,x:vt,y:jt,value:pe,formattedValue:Qe(pe),animationOffset:Z})}))}else if(ct==="grouped"){var Lt=new Map,Nt=new Map;We.forEach((function(At){var _t=At.data,vt=_t.indexValue,jt=_t.value;VV(Je,vt,Number(jt)),j9e(Lt,vt,Number(jt)),O9e(Nt,vt)})),Lt.forEach((function(At,_t){var vt,jt,Z,pe=Je.get(_t)||0,_e=Nt.get(_t);ye==="vertical"?(vt=pt(_t),jt=ge(At),Z=ge(At/2)):(vt=pt(At),jt=ge(_t),Z=pt(At/2)),vt+=ye==="vertical"?_e*Et/2:Fe,jt+=ye==="vertical"?-Fe:_e*Ye/2,Ve.push({key:"total_"+_t,x:vt,y:jt,value:pe,formattedValue:Qe(pe),animationOffset:Z})}))}return Ve})(ue,Ae,Ne,k,j,he,ze)}),[ue,Ae,Ne,k,j,he,ze]);return{bars:ue,barsWithValue:Le,xScale:Ae,yScale:Ne,getIndex:ke,getLabel:Re,getTooltipLabel:Pe,formatValue:ze,getColor:se,getBorderColor:me,getLabelColor:Te,shouldRenderBarLabel:Ze,hiddenIds:De,toggleSerie:Ce,legendsWithData:kt,barTotals:qt}},"Ie"),R9e=o(function(e){var t=e.data,n=e.springConfig,r=e.animate,a=e.layout,i=a===void 0?Nn.layout:a,s=Tr();return H1(t,{keys:o(function(l){return l.key},"keys"),from:o(function(l){return{x:i==="vertical"?l.x:l.animationOffset,y:i==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"from"),enter:o(function(l){return{x:l.x,y:l.y,labelOpacity:1}},"enter"),update:o(function(l){return{x:l.x,y:l.y,labelOpacity:1}},"update"),leave:o(function(l){return{x:i==="vertical"?l.x:l.animationOffset,y:i==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"leave"),config:n,immediate:!r,initial:r?void 0:null})((function(l,d){return h.jsx(ur.text,{x:l.x,y:l.y,fillOpacity:l.labelOpacity,style:pn({},s.labels.text,{pointerEvents:"none"}),fontWeight:"bold",fontSize:s.labels.text.fontSize,fontFamily:s.labels.text.fontFamily,textAnchor:i==="vertical"?"middle":"start",alignmentBaseline:i==="vertical"?"alphabetic":"middle",children:d.formattedValue},d.key)}))},"Ve"),k9e=["isInteractive","animate","motionConfig","theme","renderWrapper"],A9e=o(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,i=e.margin,s=e.width,l=e.height,d=e.groupMode,c=e.layout,p=e.valueScale,m=e.indexScale,g=e.padding,x=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,E=_===void 0?Nn.axisBottom:_,C=e.axisLeft,O=C===void 0?Nn.axisLeft:C,j=e.enableGridX,T=j===void 0?Nn.enableGridX:j,k=e.enableGridY,A=k===void 0?Nn.enableGridY:k,P=e.gridXValues,M=e.gridYValues,D=e.layers,I=D===void 0?Nn.layers:D,L=e.barComponent,F=L===void 0?Nn.barComponent:L,q=e.enableLabel,U=q===void 0?Nn.enableLabel:q,$=e.label,H=e.labelSkipWidth,z=H===void 0?Nn.labelSkipWidth:H,W=e.labelSkipHeight,V=W===void 0?Nn.labelSkipHeight:W,Q=e.labelTextColor,K=e.labelPosition,Y=K===void 0?Nn.labelPosition:K,ee=e.labelOffset,te=ee===void 0?Nn.labelOffset:ee,oe=e.markers,ne=oe===void 0?Nn.markers:oe,fe=e.colorBy,re=e.colors,ce=e.defs,he=ce===void 0?Nn.defs:ce,J=e.fill,De=J===void 0?Nn.fill:J,we=e.borderRadius,Ce=we===void 0?Nn.borderRadius:we,ke=e.borderWidth,Re=ke===void 0?Nn.borderWidth:ke,Pe=e.borderColor,ze=e.annotations,X=ze===void 0?Nn.annotations:ze,se=e.legendLabel,me=e.tooltipLabel,Te=e.valueFormat,de=e.isInteractive,ue=de===void 0?Nn.isInteractive:de,Ae=e.tooltip,Ne=Ae===void 0?Nn.tooltip:Ae,Le=e.onClick,Ze=e.onMouseEnter,Pt=e.onMouseLeave,$t=e.legends,kt=e.role,qt=kt===void 0?Nn.role:kt,We=e.ariaLabel,pt=e.ariaLabelledBy,ge=e.ariaDescribedBy,ye=e.isFocusable,ct=ye===void 0?Nn.isFocusable:ye,Fe=e.barAriaLabel,Qe=e.barAriaLabelledBy,Ve=e.barAriaDescribedBy,Je=e.barAriaHidden,Et=e.barAriaDisabled,Ye=e.initialHiddenIds,mt=e.enableTotals,Lt=mt===void 0?Nn.enableTotals:mt,Nt=e.totalsOffset,At=Nt===void 0?Nn.totalsOffset:Nt,_t=e.forwardedRef,vt=lo(),jt=vt.animate,Z=vt.config,pe=dae(s,l,i),_e=pe.outerWidth,$e=pe.outerHeight,Be=pe.margin,rt=pe.innerWidth,nt=pe.innerHeight,Ke=Mae({indexBy:r,label:$,tooltipLabel:me,valueFormat:Te,colors:re,colorBy:fe,borderColor:Pe,labelTextColor:Q,groupMode:d,layout:c,data:n,keys:a,margin:Be,width:rt,height:nt,padding:g,innerPadding:x,valueScale:p,indexScale:m,enableLabel:U,labelSkipWidth:z,labelSkipHeight:V,legends:$t,legendLabel:se,initialHiddenIds:Ye,totalsOffset:At}),ot=Ke.bars,ut=Ke.barsWithValue,st=Ke.xScale,lt=Ke.yScale,gt=Ke.getLabel,at=Ke.getTooltipLabel,Rt=Ke.getBorderColor,bt=Ke.getLabelColor,Ft=Ke.shouldRenderBarLabel,Dt=Ke.toggleSerie,Nr=Ke.legendsWithData,ba=Ke.barTotals,ni=Ke.getColor,ar=Aae(c,(t=p?.reverse)!=null&&t,Y,te),co=H1(ut,{keys:o(function(He){return He.key},"keys"),from:o(function(He){return pn({borderColor:Rt(He),color:He.color,height:0,labelColor:bt(He),labelOpacity:0},ar(He.width,He.height),{transform:"translate("+He.x+", "+(He.y+He.height)+")",width:He.width},c==="vertical"?{}:{height:He.height,transform:"translate("+He.x+", "+He.y+")",width:0})},"from"),enter:o(function(He){return pn({borderColor:Rt(He),color:He.color,height:He.height,labelColor:bt(He),labelOpacity:1},ar(He.width,He.height),{transform:"translate("+He.x+", "+He.y+")",width:He.width})},"enter"),update:o(function(He){return pn({borderColor:Rt(He),color:He.color,height:He.height,labelColor:bt(He),labelOpacity:1},ar(He.width,He.height),{transform:"translate("+He.x+", "+He.y+")",width:He.width})},"update"),leave:o(function(He){return pn({borderColor:Rt(He),color:He.color,height:0,labelColor:bt(He),labelOpacity:0},ar(He.width,He.height),{labelY:0,transform:"translate("+He.x+", "+(He.y+He.height)+")",width:He.width},c==="vertical"?{}:pn({},ar(He.width,He.height),{labelX:0,height:He.height,transform:"translate("+He.x+", "+He.y+")",width:0}))},"leave"),config:Z,immediate:!jt,initial:jt?void 0:null}),Mr=y.useMemo((function(){return{borderRadius:Ce,borderWidth:Re,enableLabel:U,isInteractive:ue,labelSkipWidth:z,labelSkipHeight:V,onClick:Le,onMouseEnter:Ze,onMouseLeave:Pt,getTooltipLabel:at,tooltip:Ne,isFocusable:ct,ariaLabel:Fe,ariaLabelledBy:Qe,ariaDescribedBy:Ve,ariaHidden:Je,ariaDisabled:Et}}),[Ce,Re,U,at,ue,V,z,Le,Ze,Pt,Ne,ct,Fe,Qe,Ve,Je,Et]),La=O7e(he,ot,De,{dataKey:"data",targetKey:"data.fill"}),Hr={annotations:null,axes:null,bars:null,grid:null,legends:null,markers:null,totals:null};I.includes("annotations")&&(Hr.annotations=h.jsx(c9e,{bars:ot,annotations:X},"annotations")),I.includes("axes")&&(Hr.axes=h.jsx(s$e,{xScale:st,yScale:lt,width:rt,height:nt,top:w,right:S,bottom:E,left:O},"axes")),I.includes("bars")&&(Hr.bars=h.jsx(y.Fragment,{children:co((function(He,In){return y.createElement(F,pn({},Mr,{bar:In,style:He,shouldRenderLabel:Ft(In),label:gt(In.data)}))}))},"bars")),I.includes("grid")&&(Hr.grid=h.jsx(c$e,{width:rt,height:nt,xScale:T?st:null,yScale:A?lt:null,xValues:P,yValues:M},"grid")),I.includes("legends")&&(Hr.legends=h.jsx(u9e,{width:rt,height:nt,legends:Nr,toggleSerie:Dt},"legends")),I.includes("markers")&&(Hr.markers=h.jsx(g7e,{markers:ne,width:rt,height:nt,xScale:st,yScale:lt},"markers")),I.includes("totals")&&Lt&&(Hr.totals=h.jsx(R9e,{data:ba,springConfig:Z,animate:jt,layout:c},"totals"));var Fa=pn({},Mr,{margin:Be,width:s,height:l,innerWidth:rt,innerHeight:nt,bars:ot,legendData:Nr,enableLabel:U,xScale:st,yScale:lt,tooltip:Ne,getTooltipLabel:at,onClick:Le,onMouseEnter:Ze,onMouseLeave:Pt,getColor:ni});return h.jsx(p7e,{width:_e,height:$e,margin:Be,defs:La,role:qt,ariaLabel:We,ariaLabelledBy:pt,ariaDescribedBy:ge,isFocusable:ct,ref:_t,children:I.map((function(He,In){var Pi;return typeof He=="function"?h.jsx(y.Fragment,{children:y.createElement(He,Fa)},In):(Pi=Hr?.[He])!=null?Pi:null}))})},"He"),T9e=y.forwardRef((function(e,t){var n=e.isInteractive,r=n===void 0?Nn.isInteractive:n,a=e.animate,i=a===void 0?Nn.animate:a,s=e.motionConfig,l=s===void 0?Nn.motionConfig:s,d=e.theme,c=e.renderWrapper,p=Rc(e,k9e);return h.jsx(oae,{animate:i,isInteractive:r,motionConfig:l,renderWrapper:c,theme:d,children:h.jsx(A9e,pn({},p,{isInteractive:r,forwardedRef:t}))})})),P9e=["isInteractive","renderWrapper","theme"],QA=o(function(e,t,n,r){return e.find((function(a){return S7e(a.x+t.left,a.y+t.top,a.width,a.height,n,r)}))},"Fe"),N9e=o(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,i=e.margin,s=e.width,l=e.height,d=e.groupMode,c=e.layout,p=e.valueScale,m=e.indexScale,g=e.padding,x=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,E=_===void 0?pr.axisBottom:_,C=e.axisLeft,O=C===void 0?pr.axisLeft:C,j=e.enableGridX,T=j===void 0?pr.enableGridX:j,k=e.enableGridY,A=k===void 0?pr.enableGridY:k,P=e.gridXValues,M=e.gridYValues,D=e.labelPosition,I=D===void 0?pr.labelPosition:D,L=e.labelOffset,F=L===void 0?pr.labelOffset:L,q=e.layers,U=q===void 0?pr.layers:q,$=e.renderBar,H=$===void 0?pr.renderBar:$,z=e.enableLabel,W=z===void 0?pr.enableLabel:z,V=e.label,Q=e.labelSkipWidth,K=Q===void 0?pr.labelSkipWidth:Q,Y=e.labelSkipHeight,ee=Y===void 0?pr.labelSkipHeight:Y,te=e.labelTextColor,oe=e.colorBy,ne=e.colors,fe=e.borderRadius,re=fe===void 0?pr.borderRadius:fe,ce=e.borderWidth,he=ce===void 0?pr.borderWidth:ce,J=e.borderColor,De=e.annotations,we=De===void 0?pr.annotations:De,Ce=e.legendLabel,ke=e.tooltipLabel,Re=e.valueFormat,Pe=e.isInteractive,ze=Pe===void 0?pr.isInteractive:Pe,X=e.tooltip,se=X===void 0?pr.tooltip:X,me=e.onClick,Te=e.onMouseEnter,de=e.onMouseLeave,ue=e.legends,Ae=e.pixelRatio,Ne=Ae===void 0?pr.pixelRatio:Ae,Le=e.role,Ze=e.forwardedRef,Pt=e.enableTotals,$t=Pt===void 0?pr.enableTotals:Pt,kt=e.totalsOffset,qt=kt===void 0?pr.totalsOffset:kt,We=y.useRef(null),pt=Tr(),ge=dae(s,l,i),ye=ge.margin,ct=ge.innerWidth,Fe=ge.innerHeight,Qe=ge.outerWidth,Ve=ge.outerHeight,Je=Mae({indexBy:r,label:V,tooltipLabel:ke,valueFormat:Re,colors:ne,colorBy:oe,borderColor:J,labelTextColor:te,groupMode:d,layout:c,data:n,keys:a,margin:ye,width:ct,height:Fe,padding:g,innerPadding:x,valueScale:p,indexScale:m,enableLabel:W,labelSkipWidth:K,labelSkipHeight:ee,legends:ue,legendLabel:Ce,totalsOffset:qt}),Et=Je.bars,Ye=Je.barsWithValue,mt=Je.xScale,Lt=Je.yScale,Nt=Je.getLabel,At=Je.getTooltipLabel,_t=Je.getBorderColor,vt=Je.getLabelColor,jt=Je.shouldRenderBarLabel,Z=Je.legendsWithData,pe=Je.barTotals,_e=Je.getColor,$e=tre(),Be=$e.showTooltipFromEvent,rt=$e.hideTooltip,nt=R$e({annotations:_ae({data:Et,annotations:we,getPosition:o(function(at){return{x:at.x,y:at.y}},"getPosition"),getDimensions:o(function(at){var Rt=at.width,bt=at.height;return{width:Rt,height:bt,size:Math.max(Rt,bt)}},"getDimensions")})}),Ke=y.useMemo((function(){return{borderRadius:re,borderWidth:he,isInteractive:ze,isFocusable:!1,labelSkipWidth:K,labelSkipHeight:ee,margin:ye,width:s,height:l,innerWidth:ct,innerHeight:Fe,bars:Et,legendData:Z,enableLabel:W,xScale:mt,yScale:Lt,tooltip:se,getTooltipLabel:At,onClick:me,onMouseEnter:Te,onMouseLeave:de,getColor:_e}}),[re,he,ze,K,ee,ye,s,l,ct,Fe,Et,Z,W,mt,Lt,se,At,me,Te,de,_e]),ot=h3(Re),ut=Aae(c,(t=p?.reverse)!=null&&t,I,F);y.useEffect((function(){if(We.current){We.current.width=Qe*Ne,We.current.height=Ve*Ne;var at=We.current.getContext("2d");at.scale(Ne,Ne),at.fillStyle=pt.background,at.fillRect(0,0,Qe,Ve),at.translate(ye.left,ye.top),U.forEach((function(Rt){Rt==="grid"?typeof pt.grid.line.strokeWidth=="number"&&pt.grid.line.strokeWidth>0&&(at.lineWidth=pt.grid.line.strokeWidth,at.strokeStyle=pt.grid.line.stroke,T&&AV(at,{width:ct,height:Fe,scale:mt,axis:"x",values:P}),A&&AV(at,{width:ct,height:Fe,scale:Lt,axis:"y",values:M})):Rt==="axes"?d$e(at,{xScale:mt,yScale:Lt,width:ct,height:Fe,top:w,right:S,bottom:E,left:O,theme:pt}):Rt==="bars"?(wg(at,pt.text),Ye.forEach((function(bt){H(at,pn({bar:bt,borderColor:_t(bt),borderRadius:re,borderWidth:he,label:Nt(bt.data),shouldRenderLabel:jt(bt),labelStyle:pn({},pt.labels.text,{fill:vt(bt)})},ut(bt.width,bt.height)))}))):Rt==="legends"?Z.forEach((function(bt){var Ft=bt[0],Dt=bt[1];s9e(at,pn({},Ft,{data:Dt,containerWidth:ct,containerHeight:Fe,theme:pt}))})):Rt==="annotations"?D$e(at,{annotations:nt,theme:pt}):Rt==="totals"&&$t?(function(bt,Ft,Dt,Nr){Nr===void 0&&(Nr=pr.layout),wg(bt,Dt.labels.text),bt.textBaseline=Nr==="vertical"?"alphabetic":"middle",bt.textAlign=Nr==="vertical"?"center":"start",Ft.forEach((function(ba){_g(bt,Dt.labels.text,ba.formattedValue,ba.x,ba.y)}))})(at,pe,pt,c):typeof Rt=="function"&&Rt(at,Ke)})),at.save()}}),[E,O,S,w,Ye,re,he,nt,T,A,_t,Nt,vt,P,M,d,l,Fe,ct,Ke,U,c,Z,ye.left,ye.top,Ve,Qe,Ne,H,mt,Lt,jt,pt,s,pe,$t,ot,ut]);var st=y.useCallback((function(at){if(Et&&We.current){var Rt=OA(We.current,at),bt=Rt[0],Ft=Rt[1],Dt=QA(Et,ye,bt,Ft);Dt!==void 0?(Be(y.createElement(se,pn({},Dt.data,{color:Dt.color,label:Dt.label,value:Number(Dt.data.value)})),at),at.type==="mouseenter"&&Te?.(Dt.data,at)):rt()}}),[rt,ye,Te,Et,Be,se]),lt=y.useCallback((function(at){if(Et&&We.current){rt();var Rt=OA(We.current,at),bt=Rt[0],Ft=Rt[1],Dt=QA(Et,ye,bt,Ft);Dt&&de?.(Dt.data,at)}}),[rt,ye,de,Et]),gt=y.useCallback((function(at){if(Et&&We.current){var Rt=OA(We.current,at),bt=Rt[0],Ft=Rt[1],Dt=QA(Et,ye,bt,Ft);Dt!==void 0&&me?.(pn({},Dt.data,{color:Dt.color}),at)}}),[ye,me,Et]);return h.jsx("canvas",{ref:R7e(We,Ze),width:Qe*Ne,height:Ve*Ne,style:{width:Qe,height:Ve,cursor:ze?"auto":"normal"},onMouseEnter:ze?st:void 0,onMouseMove:ze?st:void 0,onMouseLeave:ze?lt:void 0,onClick:ze?gt:void 0,role:Le})},"ze"),M9e=y.forwardRef((function(e,t){var n=e.isInteractive,r=e.renderWrapper,a=e.theme,i=Rc(e,P9e);return h.jsx(oae,{isInteractive:n,renderWrapper:r,theme:a,animate:!1,children:h.jsx(N9e,pn({},i,{isInteractive:n,forwardedRef:t}))})})),D9e=["defaultWidth","defaultHeight","onResize","debounceResize"],I9e=y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,i=e.debounceResize,s=Rc(e,D9e);return h.jsx(sae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:i,children:o(function(l){var d=l.width,c=l.height;return h.jsx(T9e,pn({},s,{width:d,height:c,ref:t}))},"children")})})),L9e=["defaultWidth","defaultHeight","onResize","debounceResize"];y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,i=e.debounceResize,s=Rc(e,L9e);return h.jsx(sae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:i,children:o(function(l){var d=l.width,c=l.height;return h.jsx(M9e,pn({},s,{width:d,height:c,ref:t}))},"children")})}));const F9e={opportunity:.2,"proposal-sent":.5,"in-negociation":.8,delayed:.3},$9e=new Date(new Date().setMonth(new Date().getMonth()-6)).toISOString(),WV="en-US",q9e="USD",z9e=y.memo(()=>{const e=navigator?navigator.languages||[navigator.language]:[WV],{data:t,isPending:n}=Xa("deals",{pagination:{perPage:100,page:1},sort:{field:"created_at",order:"ASC"},filter:{"created_at@gte":$9e}}),r=y.useMemo(()=>{if(!t)return[];const i=t.reduce((l,d)=>{const c=GT(d.created_at??new Date).toISOString();return l[c]||(l[c]=[]),l[c].push(d),l},{});return Object.keys(i).map(l=>({date:SK(l,"MMM"),won:i[l].filter(d=>d.stage==="won").reduce((d,c)=>(d+=c.amount,d),0),pending:i[l].filter(d=>!["won","lost"].includes(d.stage)).reduce((d,c)=>(d+=c.amount*F9e[c.stage],d),0),lost:i[l].filter(d=>d.stage==="lost").reduce((d,c)=>(d-=c.amount,d),0)}))},[t]);if(n)return null;const a=r.reduce((i,s)=>(i.min=Math.min(i.min,s.lost),i.max=Math.max(i.max,s.won+s.pending),i),{min:0,max:0});return h.jsxs("div",{className:"flex flex-col",children:[h.jsxs("div",{className:"flex items-center mb-4",children:[h.jsx("div",{className:"mr-3 flex",children:h.jsx(rQ,{className:"text-muted-foreground w-6 h-6"})}),h.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Upcoming Deal Revenue"})]}),h.jsx("div",{className:"h-[400px]",children:h.jsx(I9e,{data:r,indexBy:"date",keys:["won","pending","lost"],colors:["#61cdbb","#97e3d5","#e25c3b"],margin:{top:30,right:50,bottom:30,left:0},padding:.3,valueScale:{type:"linear",min:a.min*1.2,max:a.max*1.2},indexScale:{type:"band",round:!0},enableGridX:!0,enableGridY:!1,enableLabel:!1,tooltip:o(({value:i,indexValue:s})=>h.jsxs("div",{className:"p-2 bg-secondary rounded shadow inline-flex items-center gap-1 text-secondary-foreground",children:[h.jsxs("strong",{children:[s,": "]})," ",i>0?"+":"",i.toLocaleString(e.at(0)??WV,{style:"currency",currency:q9e})]}),"tooltip"),axisTop:{tickSize:0,tickPadding:12,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},axisBottom:{legendPosition:"middle",legendOffset:50,tickSize:0,tickPadding:12,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},axisLeft:null,axisRight:{format:o(i=>`${Math.abs(i/1e3)}k`,"format"),tickValues:8,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},markers:[{axis:"y",value:0,lineStyle:{strokeOpacity:0},textStyle:{fill:"#2ebca6"},legend:"Won",legendPosition:"top-left",legendOrientation:"vertical"},{axis:"y",value:0,lineStyle:{stroke:"#f47560",strokeWidth:1},textStyle:{fill:"#e25c3b"},legend:"Lost",legendPosition:"bottom-left",legendOrientation:"vertical"}]})})]})}),U9e=o(e=>{const t=xt(),n=Ht(e),{filterValues:r,setFilters:a}=_w(e),i=td();if(!n)throw new Error("<ListNoResults> must be used inside a <List> component");return h.jsx("div",{className:"p-6",children:h.jsx("p",{className:"text-sm text-muted-foreground",children:r&&a&&Object.keys(r).length>0?h.jsxs(h.Fragment,{children:[t("ra.navigation.no_filtered_results",{resource:n,name:i(n,0),_:"No results found with the current filters."})," ",h.jsx(Ge,{variant:"outline",size:"sm",onClick:o(()=>a({},[]),"onClick"),children:t("ra.navigation.clear_filters",{_:"Clear filters"})})]}):t("ra.navigation.no_results",{resource:n,name:i(n,0),_:"No results found."})})})},"ListNoResults"),B9e=o(e=>{const{children:t,linkType:n,rowClick:r,style:a}=e,i=Ht(e),s=Vt(e),l=pa(),d=typeof n=="function"||typeof r=="function",c=OG({link:d?!1:n??r,resource:i}),p=AG(),m=Ct(async()=>{if(!d||!s)return;const g=typeof n=="function"?n(s,s.id):typeof r=="function"?(w,S)=>r(w.id,S,w):!1,x=await p({record:s,resource:i,link:g});x===!1||x==null||l(x)});return s?d?h.jsx("li",{className:"w-full",children:h.jsx("button",{onClick:m,style:a,className:"w-full text-left hover:bg-muted focus: bg-muted focus:outline-none",children:t})}):c?h.jsx("li",{className:"w-full",children:h.jsx(xn,{to:c,style:a,className:"block w-full hover:bg-muted focus:bg-muted focus:outline-none",children:t})}):h.jsx("li",{className:"w-full",children:t}):null},"SimpleListItem"),XA=o(({className:e})=>h.jsx("span",{className:Ee("bg-gray-300 flex",e),children:" "}),"ListPlaceholder"),H9e=o(e=>{const{className:t,hasLeftAvatarOrIcon:n,hasRightAvatarOrIcon:r,hasSecondaryText:a,hasTertiaryText:i,nbFakeLines:s=5,...l}=e;return oY(1e3)?h.jsx("ul",{className:t,...l,children:V9e(s,c=>h.jsxs("li",{className:"flex items-center space-x-3 p-3",children:[n&&h.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"mb-1",children:[h.jsx(XA,{className:"w-1/3 inline-block mb-1"}),i&&h.jsx("span",{className:"float-right opacity-55 min-w-[10vw]",children:h.jsx(XA,{})})]}),a&&h.jsx(XA,{className:"w-1/4"})]}),r&&h.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "})]},c))}):null},"SimpleListLoading"),V9e=o((e,t)=>Array.from({length:e},(n,r)=>t(r)),"times"),W9e=o(e=>{const{className:t,empty:n=Y9e,leftAvatar:r,leftIcon:a,linkType:i,rowClick:s,primaryText:l,rightAvatar:d,rightIcon:c,secondaryText:p,tertiaryText:m,resource:g,...x}=e,{data:w,isPending:S,total:_}=_w(e);return S===!0?h.jsx(H9e,{className:t,hasLeftAvatarOrIcon:!!a||!!r,hasRightAvatarOrIcon:!!c||!!d,hasSecondaryText:!!p,hasTertiaryText:!!m}):w==null||w.length===0||_===0?n||null:h.jsx("ul",{className:t,...Ape(x),children:h.jsx(Lpe,{data:w,total:_,render:o((E,C)=>h.jsx(B9e,{rowIndex:C,linkType:i,rowClick:s,resource:g,children:h.jsx(G9e,{leftAvatar:r,leftIcon:a,primaryText:l,rightAvatar:d,rightIcon:c,secondaryText:p,tertiaryText:m,rowIndex:C})},E.id),"render")})})},"SimpleList"),G9e=o(e=>{const{leftAvatar:t,leftIcon:n,primaryText:r,rightAvatar:a,rightIcon:i,secondaryText:s,tertiaryText:l}=e,d=Ht(e),c=Vt(e),p=gc(d),m=xt(),g=o((x,w)=>{const S=w(x,x.id);return typeof S=="string"&&(S.startsWith("http")||S.startsWith("data:"))?h.jsx("img",{src:S,alt:"",className:"w-10 h-10 rounded-full object-cover"}):h.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-sm",children:S})},"renderAvatar");return c?h.jsxs("div",{className:"flex items-center space-x-3 p-3",children:[n&&h.jsx("div",{className:"flex-shrink-0",children:n(c,c.id)}),t&&h.jsx("div",{className:"flex-shrink-0",children:g(c,t)}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("div",{className:"text-sm font-medium truncate",children:r?typeof r=="string"?m(r,{...c,_:r}):y.isValidElement(r)?r:r(c,c.id):p(c)}),!!l&&h.jsx("div",{className:"text-xs text-muted-foreground ml-2",children:typeof l=="string"?m(l,{...c,_:l}):y.isValidElement(l)?l:l(c,c.id)})]}),!!s&&h.jsx("div",{className:"text-sm text-muted-foreground truncate",children:typeof s=="string"?m(s,{...c,_:s}):y.isValidElement(s)?s:s(c,c.id)})]}),(a||i)&&h.jsxs("div",{className:"flex-shrink-0 flex items-center space-x-2",children:[a&&g(c,a),i&&i(c,c.id)]})]}):null},"SimpleListItemContent"),Y9e=h.jsx(U9e,{}),K9e=o(()=>{const{identity:e}=wr(),{data:t,total:n,isPending:r}=Xa("contacts",{pagination:{page:1,perPage:10},sort:{field:"last_seen",order:"DESC"},filter:{status:"hot",sales_id:e?.id}},{enabled:Number.isInteger(e?.id)});return h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsxs("div",{className:"flex items-center",children:[h.jsx("div",{className:"mr-3 flex",children:h.jsx(gD,{className:"text-muted-foreground w-6 h-6"})}),h.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Hot Contacts"}),h.jsx(ji,{children:h.jsxs(eo,{children:[h.jsx(to,{asChild:!0,children:h.jsx(Ge,{variant:"ghost",size:"sm",className:"ml-auto text-muted-foreground",asChild:!0,children:h.jsx(xn,{to:"/contacts/create",children:h.jsx($v,{className:"w-4 h-4 text-primary"})})})}),h.jsx(no,{children:"Create contact"})]})})]}),h.jsx(rr,{className:"py-0",children:h.jsx(W9e,{linkType:"show",data:t,total:n,isPending:r,resource:"contacts",className:"[&>li:first-child>a]:rounded-t-xl [&>li:last-child>a]:rounded-b-xl",primaryText:o(a=>`${a.first_name} ${a.last_name}`,"primaryText"),secondaryText:o(a=>h.jsxs(h.Fragment,{children:[a.title," at ",a.company_name]}),"secondaryText"),leftAvatar:o(a=>h.jsx(Qo,{record:a}),"leftAvatar"),empty:h.jsxs("div",{className:"p-4",children:[h.jsx("p",{className:"text-sm mb-4",children:'Contacts with a "hot" status will appear here.'}),h.jsx("p",{className:"text-sm",children:'Change the status of a contact by adding a note to that contact and clicking on "show options".'})]})})})]})},"HotContacts"),Q9e=o(()=>{const{identity:e}=wr(),{total:t}=Xa("tasks",{pagination:{page:1,perPage:1},filter:{sales_id:e?.id}},{enabled:!!e});return t?null:h.jsx("p",{className:"text-sm",children:"Tasks added to your contacts will appear here."})},"TasksListEmpty"),Zm=o(({title:e,filter:t})=>{const{identity:n}=wr(),{data:r,total:a,isPending:i}=Xa("tasks",{pagination:{page:1,perPage:100},sort:{field:"due_date",order:"ASC"},filter:{...t,sales_id:n?.id}},{enabled:!!n}),s=Sw({data:r,isPending:i,resource:"tasks",perPage:5});return i||!r||!a?null:h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium mb-2",children:e}),h.jsx(ed,{value:"tasks",children:h.jsx(zg,{value:s,children:h.jsx(ine,{showContact:!0})})}),a>s.perPage&&h.jsx("div",{className:"flex justify-center",children:h.jsx("a",{href:"#",onClick:o(l=>{s.setPerPage(s.perPage+10),l.preventDefault()},"onClick"),className:"text-sm underline hover:no-underline",children:"Load more"})})]})},"TasksListFilter"),Dae=new Date,X9e=h0e(Dae),Z9e=X9e<5,GV=m0e().toISOString(),YV=hye().toISOString(),KV=pye().toISOString(),QV=fye(Dae,{weekStartsOn:0}).toISOString(),Jm={overdue:{"done_date@is":null,"due_date@lt":GV},today:{"done_date@is":null,"due_date@gte":GV,"due_date@lte":YV},tomorrow:{"done_date@is":null,"due_date@gt":YV,"due_date@lt":KV},thisWeek:{"done_date@is":null,"due_date@gte":KV,"due_date@lte":QV},later:{"done_date@is":null,"due_date@gt":QV}},J9e=o(()=>h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsxs("div",{className:"flex items-center",children:[h.jsx("div",{className:"mr-3 flex",children:h.jsx(lQ,{className:"text-muted-foreground w-6 h-6"})}),h.jsx("h2",{className:"text-xl font-semibold text-muted-foreground flex-1",children:"Upcoming Tasks"}),h.jsx(ane,{display:"icon",selectContact:!0})]}),h.jsx(rr,{className:"p-4 mb-2",children:h.jsxs("div",{className:"flex flex-col gap-4",children:[h.jsx(Q9e,{}),h.jsx(Zm,{title:"Overdue",filter:Jm.overdue}),h.jsx(Zm,{title:"Today",filter:Jm.today}),h.jsx(Zm,{title:"Tomorrow",filter:Jm.tomorrow}),Z9e&&h.jsx(Zm,{title:"This week",filter:Jm.thisWeek}),h.jsx(Zm,{title:"Later",filter:Jm.later})]})})]}),"TasksList"),eqe=o(()=>{const{data:e,total:t,isPending:n}=Xa("contacts",{pagination:{page:1,perPage:1}}),{total:r,isPending:a}=Xa("contactNotes",{pagination:{page:1,perPage:1}}),{total:i,isPending:s}=Xa("deals",{pagination:{page:1,perPage:1}});return n||a||s?null:t?r?h.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-6 mt-1",children:[h.jsx("div",{className:"md:col-span-3",children:h.jsxs("div",{className:"flex flex-col gap-4",children:[null,h.jsx(K9e,{})]})}),h.jsx("div",{className:"md:col-span-6",children:h.jsxs("div",{className:"flex flex-col gap-6",children:[i?h.jsx(z9e,{}):null,h.jsx(X3e,{})]})}),h.jsx("div",{className:"md:col-span-3",children:h.jsx(J9e,{})})]}):h.jsx(QB,{step:2,contactId:e?.[0]?.id}):h.jsx(QB,{step:1})},"Dashboard"),tqe=y.lazy(()=>jp(()=>import("./DealList-B1Rhf5RN.js"),[],import.meta.url)),nqe={list:tqe},rqe=y.createContext(void 0),g3=o(()=>y.useContext(rqe),"useUserMenu"),aqe=o(()=>{const{darkModeLogo:e,lightModeLogo:t,title:n}=Ia(),r=Ar(),i=[{path:"/",pattern:"/"},{path:"/contacts",pattern:"/contacts/*"},{path:"/companies",pattern:"/companies/*"},{path:"/deals",pattern:"/deals/*"}].find(s=>Uh(s.pattern,r.pathname))?.path||!1;return h.jsx("header",{className:"bg-secondary sticky top-0 z-50 border-b border-border",children:h.jsx("div",{className:"px-4",children:h.jsxs("div",{className:"flex justify-between items-center flex-1",children:[h.jsx(iqe,{darkLogo:e,lightLogo:t,title:n}),h.jsxs("nav",{className:"flex","aria-label":"Main navigation",children:[h.jsx(ib,{label:"Dashboard",to:"/",isActive:i==="/"}),h.jsx(ib,{label:"Contacts",to:"/contacts",isActive:i==="/contacts"}),h.jsx(ib,{label:"Companies",to:"/companies",isActive:i==="/companies"}),h.jsx(ib,{label:"Deals",to:"/deals",isActive:i==="/deals"})]}),h.jsxs("div",{className:"flex items-center",children:[h.jsx(fZ,{}),h.jsx(hZ,{}),h.jsxs(cZ,{children:[h.jsx(sqe,{}),h.jsx(lqe,{}),h.jsx(Jve,{resource:"sales",action:"list",children:h.jsx(oqe,{})}),h.jsx(Vv,{}),h.jsx(WD,{className:"font-normal",children:h.jsxs("div",{className:"text-xs text-muted-foreground",children:["Version ","0.7.11"]})})]})]})]})})})},"Header"),iqe=o(({darkLogo:e,lightLogo:t,title:n})=>h.jsxs(xn,{to:"/",className:"flex items-center gap-2 text-secondary-foreground no-underline hover:opacity-80 transition-opacity",children:[h.jsx("img",{className:"[.light_&]:hidden h-6",src:e,alt:`${n} logo`}),h.jsx("img",{className:"[.dark_&]:hidden h-6",src:t,alt:`${n} logo`}),h.jsx("h1",{className:"text-xl font-semibold",children:n})]}),"Logo"),ib=o(({label:e,to:t,isActive:n})=>h.jsx(xn,{to:t,className:`px-6 py-3 text-sm font-medium transition-colors border-b-2 ${n?"text-secondary-foreground border-secondary-foreground":"text-secondary-foreground/70 border-transparent hover:text-secondary-foreground/80"}`,children:e}),"NavigationTab"),oqe=o(()=>{const{onClose:e}=g3()??{};return h.jsx(cr,{asChild:!0,onClick:e,children:h.jsxs(xn,{to:"/sales",className:"flex items-center gap-2",children:[h.jsx(l1e,{className:"h-4 w-4"}),"Users"]})})},"UsersMenu"),sqe=o(()=>{const{onClose:e}=g3()??{};return h.jsx(cr,{asChild:!0,onClick:e,children:h.jsxs(xn,{to:"/settings",className:"flex items-center gap-2",children:[h.jsx(QT,{className:"h-4 w-4"}),"My info"]})})},"ConfigurationMenu"),lqe=o(()=>{const{onClose:e}=g3()??{};return h.jsx(cr,{asChild:!0,onClick:e,children:h.jsxs(xn,{to:"/database",className:"flex items-center gap-2",children:[h.jsx(Fv,{className:"h-4 w-4"}),"Database"]})})},"DatabaseMenu"),cqe=o(({children:e})=>h.jsxs(h.Fragment,{children:[h.jsx(aqe,{}),h.jsx("main",{className:"max-w-screen-xl mx-auto pt-4 px-4",id:"main-content",children:h.jsx(Gb,{FallbackComponent:pZ,children:h.jsx(y.Suspense,{fallback:h.jsx(fn,{className:"h-12 w-12 rounded-full"}),children:e})})}),h.jsx(h1,{})]}),"Layout"),Iae=o(()=>h.jsx("div",{className:"max-w-screen-xl mx-auto h-screen pt-8",children:h.jsx("div",{className:"h-full",children:h.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-8",children:[h.jsx(fn,{className:"w-full h-[100px]"}),h.jsx(fn,{className:"w-4/5 h-[50px]"}),h.jsx(fn,{className:"w-full h-9"}),h.jsx(fn,{className:"w-full h-9"}),h.jsx(fn,{className:"w-full h-9"}),h.jsx(fn,{className:"w-2/5 h-9"})]})})}),"LoginSkeleton"),BN=o(()=>{const e=dr(),t=Vn(),{darkModeLogo:n,title:r}=Ia(),{data:a,isPending:i}=Ma({queryKey:["init"],queryFn:o(async()=>t.isInitialized(),"queryFn")}),{isPending:s,mutate:l}=Ki({mutationKey:["signup"],mutationFn:o(async w=>t.signUp(w),"mutationFn"),onSuccess:o(w=>{d({email:w.email,password:w.password,redirectTo:"/contacts"}).then(()=>{c("Initial user successfully created"),e.invalidateQueries({queryKey:["auth","canAccess"]})})},"onSuccess"),onError:o(()=>{c("An error occurred. Please try again.")},"onError")}),d=XY(),c=dn(),{register:p,handleSubmit:m,formState:{isValid:g}}=XM({mode:"onChange"});if(i)return h.jsx(Iae,{});if(a)return h.jsx(Jx,{to:"/login"});const x=o(async w=>{l(w)},"onSubmit");return h.jsxs("div",{className:"h-screen p-8",children:[h.jsxs("div",{className:"flex items-center gap-4",children:[h.jsx("img",{src:n,alt:r,width:24,className:"filter brightness-0 invert"}),h.jsx("h1",{className:"text-xl font-semibold",children:r})]}),h.jsx("div",{className:"h-full",children:h.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-4",children:[h.jsx("h1",{className:"text-2xl font-bold mb-4",children:"Welcome to CRM"}),h.jsx("p",{className:"text-base mb-4",children:"Create the first user account to complete the setup."}),h.jsxs("form",{onSubmit:m(x),className:"space-y-4",children:[h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx(wi,{htmlFor:"first_name",children:"First name"}),h.jsx(Qa,{...p("first_name",{required:!0}),id:"first_name",type:"text",required:!0})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx(wi,{htmlFor:"last_name",children:"Last name"}),h.jsx(Qa,{...p("last_name",{required:!0}),id:"last_name",type:"text",required:!0})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx(wi,{htmlFor:"email",children:"Email"}),h.jsx(Qa,{...p("email",{required:!0}),id:"email",type:"email",required:!0})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx(wi,{htmlFor:"password",children:"Password"}),h.jsx(Qa,{...p("password",{required:!0}),id:"password",type:"password",required:!0})]}),h.jsx("div",{className:"flex justify-between items-center mt-8",children:h.jsx(Ge,{type:"submit",disabled:!g||s,className:"w-full",children:s?h.jsxs(h.Fragment,{children:[h.jsx(yp,{className:"w-4 h-4 animate-spin mr-2"}),"Creating..."]}):"Create account"})})]})]})})]})},"SignupPage");BN.path="/sign-up";const uqe=o((e,t)=>e==="admin"?!0:t.resource!=="sales","canAccess"),ZA=nke(Qn,{getIdentity:o(async()=>{const e=await Lae();if(e==null)throw new Error;return{id:e.id,fullName:`${e.first_name} ${e.last_name}`,avatar:e.avatar?.src}},"getIdentity")});async function Fs(){if(Fs._is_initialized_cache==null){const{data:e}=await Qn.from("init_state").select("is_initialized");Fs._is_initialized_cache=e?.at(0)?.is_initialized>0}return Fs._is_initialized_cache}o(Fs,"getIsInitialized");(e=>{e._is_initialized_cache=null})(Fs||(Fs={}));const dqe={...ZA,login:o(async e=>{const t=await ZA.login(e);return xb=void 0,t},"login"),checkAuth:o(async e=>{if(window.location.pathname==="/set-password"||window.location.hash.includes("#/set-password")||window.location.pathname==="/forgot-password"||window.location.hash.includes("#/forgot-password")||window.location.pathname==="/change-password"||window.location.hash.includes("#/change-password")||window.location.pathname==="/otp-login"||window.location.hash.includes("#/otp-login")||window.location.pathname==="/sign-up"||window.location.hash.includes("#/sign-up"))return;if(!await Fs())throw await Qn.auth.signOut(),{redirectTo:"/sign-up",message:!1};return ZA.checkAuth(e)},"checkAuth"),canAccess:o(async e=>{if(!await Fs())return!1;const n=await Lae();if(n==null)return!1;const r=n.administrator?"admin":"user";return uqe(r,e)},"canAccess")};let xb;const Lae=o(async()=>{if(xb!=null)return xb;const{data:e,error:t}=await Qn.auth.getSession();if(e?.session?.user==null||t)return;const{data:n,error:r}=await Qn.from("sales").select("id, first_name, last_name, avatar, administrator").match({user_id:e?.session?.user.id}).single();if(!(n==null||r))return xb=n,n},"getSaleFromCache");async function fqe(e,t,n){const r={};t&&(r.id=t);const a={};t&&(a.company_id=t);const[i,s,l]=await Promise.all([hqe(e,r),pqe(e,a),mqe(e,a)]);return[...i,...s,...l].sort((d,c)=>d.date&&c.date?d.date.localeCompare(c.date)*-1:0).slice(0,250)}o(fqe,"getActivityLog");const hqe=o(async(e,t)=>{const{data:n}=await e.getList("companies",{filter:t,pagination:{page:1,perPage:250},sort:{field:"created_at",order:"DESC"}});return n.map(r=>({id:`company.${r.id}.created`,type:ite,company_id:r.id,company:r,sales_id:r.sales_id,date:r.created_at}))},"getNewCompanies");async function pqe(e,t){const{data:n}=await e.getList("contacts",{filter:t,pagination:{page:1,perPage:250},sort:{field:"first_seen",order:"DESC"}}),r={};if(t.sales_id&&(r.sales_id=t.sales_id),t.company_id){const l=n.map(d=>d.id).join(",");r["contact_id@in"]=`(${l})`}const{data:a}=await e.getList("contactNotes",{filter:r,pagination:{page:1,perPage:250},sort:{field:"date",order:"DESC"}}),i=n.map(l=>({id:`contact.${l.id}.created`,type:ote,company_id:l.company_id,sales_id:l.sales_id,contact:l,date:l.first_seen})),s=a.map(l=>({id:`contactNote.${l.id}.created`,type:ste,sales_id:l.sales_id,contactNote:l,date:l.date}));return[...i,...s]}o(pqe,"getNewContactsAndNotes");async function mqe(e,t){const{data:n}=await e.getList("deals",{filter:t,pagination:{page:1,perPage:250},sort:{field:"created_at",order:"DESC"}}),r={};if(t.sales_id&&(r.sales_id=t.sales_id),t.company_id){const l=n.map(d=>d.id).join(",");r["deal_id@in"]=`(${l})`}const{data:a}=await e.getList("dealNotes",{filter:r,pagination:{page:1,perPage:250},sort:{field:"date",order:"DESC"}}),i=n.map(l=>({id:`deal.${l.id}.created`,type:lte,company_id:l.company_id,sales_id:l.sales_id,deal:l,date:l.created_at})),s=a.map(l=>({id:`dealNote.${l.id}.created`,type:cte,sales_id:l.sales_id,dealNote:l,date:l.date}));return[...i,...s]}o(mqe,"getNewDealsAndNotes");async function vqe(e){return e.website?{src:`https://favicon.show/${e.website.replace(/^https?:\/\//,"").replace(/\/$/,"")}`,title:"Company favicon"}:null}o(vqe,"getCompanyAvatar");async function gqe(e,t={}){const{timeout:n=2e3}=t,r=new AbortController,a=setTimeout(()=>r.abort(),n),i=await fetch(e,{...t,signal:r.signal});return clearTimeout(a),i}o(gqe,"fetchWithTimeout");const yqe=["gmail.com","yahoo.com","hotmail.com","aol.com","hotmail.co.uk","hotmail.fr","msn.com","yahoo.fr","wanadoo.fr","orange.fr","comcast.net","yahoo.co.uk","yahoo.com.br","yahoo.co.in","live.com","rediffmail.com","free.fr","gmx.de","web.de","yandex.ru","ymail.com","libero.it","outlook.com","uol.com.br","bol.com.br","mail.ru","cox.net","hotmail.it","sbcglobal.net","sfr.fr","live.fr","verizon.net","live.co.uk","googlemail.com","yahoo.es","ig.com.br","live.nl","bigpond.com","terra.com.br","yahoo.it","neuf.fr","yahoo.de","alice.it","rocketmail.com","att.net","laposte.net","facebook.com","bellsouth.net","yahoo.in","hotmail.es","charter.net","yahoo.ca","yahoo.com.au","rambler.ru","hotmail.de","tiscali.it","shaw.ca","yahoo.co.jp","sky.com","earthlink.net","optonline.net","freenet.de","t-online.de","aliceadsl.fr","virgilio.it","home.nl","qq.com","telenet.be","me.com","yahoo.com.ar","tiscali.co.uk","yahoo.com.mx","voila.fr","gmx.net","mail.com","planet.nl","tin.it","live.it","ntlworld.com","arcor.de","yahoo.co.id","frontiernet.net","hetnet.nl","live.com.au","yahoo.com.sg","zonnet.nl","club-internet.fr","juno.com","optusnet.com.au","blueyonder.co.uk","bluewin.ch","skynet.be","sympatico.ca","windstream.net","mac.com","centurytel.net","chello.nl","live.ca","aim.com","bigpond.net.au","online.de","apple.com"];async function bqe(e){const t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(i=>i.toString(16).padStart(2,"0")).join("")}o(bqe,"hash");async function xqe(e){return`https://www.gravatar.com/avatar/${await bqe(e)}?d=404`}o(xqe,"getGravatarUrl");async function wqe(e){if(yqe.includes(e))return null;try{const t=`https://${e}/favicon.ico`;if((await gqe(t)).ok)return t}catch{return null}return null}o(wqe,"getFaviconUrl");async function _qe(e){if(!e.email_jsonb||!e.email_jsonb.length)return null;for(const{email:t}of e.email_jsonb){const n=await xqe(t);try{if((await fetch(n)).ok)return n}catch{}const r=t.split("@")[1],a=await wqe(r);if(a)return a}return null}o(_qe,"getContactAvatar");const XV=iy()||{url:"https://placeholder.supabase.co",anonKey:"placeholder-key"},bo=xke({instanceUrl:XV.url,apiKey:XV.anonKey,supabaseClient:Qn,sortOrder:"asc,desc.nullslast"}),ZV=o(async e=>{let t=e.data.logo;return typeof t!="object"||t===null||!t.src?t=await vqe(e.data):t.rawFile instanceof File&&await wb(t),{...e,data:{...e.data,logo:t}}},"processCompanyLogo");async function JV(e){const{data:t}=e;if(t.avatar?.src||!t.email_jsonb||!t.email_jsonb.length)return e;const n=await _qe(t),r={...t,avatar:{src:n||void 0}};return{...e,data:r}}o(JV,"processContactAvatar");const Sqe={...bo,async getList(e,t){return e==="companies"?bo.getList("companies_summary",t):e==="contacts"?bo.getList("contacts_summary",t):bo.getList(e,t)},async getOne(e,t){return e==="companies"?bo.getOne("companies_summary",t):e==="contacts"?bo.getOne("contacts_summary",t):bo.getOne(e,t)},async signUp({email:e,password:t,first_name:n,last_name:r}){const{data:a,error:i}=await Qn.functions.invoke("setup",{method:"POST",body:{email:e,password:t,first_name:n,last_name:r}});if(!a||i)throw console.error("signUp.error",i),new Error("Failed to create account");return Fs._is_initialized_cache=!0,{id:a.data.id,email:e,password:t}},async salesCreate(e){const{data:t,error:n}=await Qn.functions.invoke("users",{method:"POST",body:e});if(!t||n)throw console.error("salesCreate.error",n),new Error("Failed to create account manager");return t},async salesUpdate(e,t){const{email:n,first_name:r,last_name:a,administrator:i,avatar:s,disabled:l}=t,{data:d,error:c}=await Qn.functions.invoke("users",{method:"PATCH",body:{sales_id:e,email:n,first_name:r,last_name:a,administrator:i,disabled:l,avatar:s}});if(!d||c)throw console.error("salesCreate.error",c),new Error("Failed to update account manager");return t},async resendInvite(e){const{data:t,error:n}=await Qn.functions.invoke("users",{method:"PUT",body:{sales_id:e,action:"invite"}});if(!t||n)throw console.error("resendInvite.error",n),new Error("Failed to resend invitation");return t},async resetPassword(e){const{data:t,error:n}=await Qn.functions.invoke("users",{method:"PUT",body:{sales_id:e,action:"reset"}});if(!t||n)throw console.error("resetPassword.error",n),new Error("Failed to send password reset");return t},async updatePassword(e){const{data:t,error:n}=await Qn.functions.invoke("updatePassword",{method:"PATCH",body:{sales_id:e}});if(!t||n)throw console.error("passwordUpdate.error",n),new Error("Failed to update password");return t},async unarchiveDeal(e){const{data:t}=await bo.getList("deals",{filter:{stage:e.stage},pagination:{page:1,perPage:1e3},sort:{field:"index",order:"ASC"}}),n=t.map((r,a)=>({...r,index:r.id===e.id?0:a+1,archived_at:r.id===e.id?null:r.archived_at}));return await Promise.all(n.map(r=>bo.update("deals",{id:r.id,data:r,previousData:t.find(a=>a.id===r.id)})))},async getActivityLog(e){return fqe(bo,e)},async isInitialized(){return Fs()},async mergeContacts(e,t){const{data:n,error:r}=await Qn.functions.invoke("mergeContacts",{method:"POST",body:{loserId:e,winnerId:t}});if(r)throw console.error("mergeContacts.error",r),new Error("Failed to merge contacts");return n}},Eqe=qfe(Sqe,[{resource:"contactNotes",beforeSave:o(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await wb(r);return e},"beforeSave")},{resource:"dealNotes",beforeSave:o(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await wb(r);return e},"beforeSave")},{resource:"sales",beforeSave:o(async(e,t,n)=>(e.avatar&&await wb(e.avatar),e),"beforeSave")},{resource:"contacts",beforeCreate:o(async e=>JV(e),"beforeCreate"),beforeUpdate:o(async e=>JV(e),"beforeUpdate"),beforeGetList:o(async e=>ob(["first_name","last_name","company_name","title","email","phone","background"])(e),"beforeGetList")},{resource:"companies",beforeGetList:o(async e=>ob(["name","phone_number","website","zipcode","city","stateAbbr"])(e),"beforeGetList"),beforeCreate:o(async e=>{const t=await ZV(e);return{...t,data:{...t.data,created_at:new Date().toISOString()}}},"beforeCreate"),beforeUpdate:o(async e=>await ZV(e),"beforeUpdate")},{resource:"contacts_summary",beforeGetList:o(async e=>ob(["first_name","last_name"])(e),"beforeGetList")},{resource:"deals",beforeGetList:o(async e=>ob(["name","type","description"])(e),"beforeGetList")}]),ob=o(e=>t=>{if(!t.filter?.q)return t;const{q:n,...r}=t.filter;return{...t,filter:{...r,"@or":e.reduce((a,i)=>i==="email"?{...a,"email_fts@ilike":n}:i==="phone"?{...a,"phone_fts@ilike":n}:{...a,[`${i}@ilike`]:n},{})}}},"applyFullTextSearch"),wb=o(async e=>{if(!e.src.startsWith("blob:")&&!e.src.startsWith("data:")&&e.path){const{error:c}=await Qn.storage.from("attachments").createSignedUrl(e.path,60);if(!c)return}const t=e.src?await fetch(e.src).then(c=>c.blob()):e.rawFile,n=e.rawFile,r=n.name.split(".").pop(),i=`${`${Math.random()}.${r}`}`,{error:s}=await Qn.storage.from("attachments").upload(i,t);if(s)throw console.error("uploadError",s),new Error("Failed to upload attachment");const{data:l}=Qn.storage.from("attachments").getPublicUrl(i);e.path=i,e.src=l.publicUrl;const d=n.type;return e.type=d,e},"uploadToBucket");function Fae(){const{identity:e}=wr(),t=Vt();return h.jsxs("div",{className:"space-y-4 w-full",children:[h.jsx(on,{source:"first_name",validate:Xn(),helperText:!1}),h.jsx(on,{source:"last_name",validate:Xn(),helperText:!1}),h.jsx(on,{source:"email",validate:[Xn(),AY()],helperText:!1}),h.jsx(dN,{source:"administrator",readOnly:t?.id===e?.id,helperText:!1}),h.jsx(dN,{source:"disabled",readOnly:t?.id===e?.id,helperText:!1})]})}o(Fae,"SalesInputs");function Cqe(){const e=Vn(),t=dn(),n=Yo(),{mutate:r}=Ki({mutationKey:["signup"],mutationFn:o(async i=>e.salesCreate(i),"mutationFn"),onSuccess:o(()=>{t("User created. They will soon receive an email to set their password."),n("/sales")},"onSuccess"),onError:o(()=>{t("An error occurred while creating the user.",{type:"error"})},"onError")}),a=o(async i=>{r(i)},"onSubmit");return h.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:h.jsxs(rr,{children:[h.jsx(yx,{children:h.jsx(bx,{children:"Create a new user"})}),h.jsx(ei,{children:h.jsx(XJ,{onSubmit:a,children:h.jsx(Fae,{})})})]})})}o(Cqe,"SalesCreate");function jqe(){return h.jsxs("div",{className:"flex justify-end gap-4",children:[h.jsx(S1,{}),h.jsx(sd,{})]})}o(jqe,"EditToolbar");function Oqe(){const{record:e}=nY(),t=Vn(),n=dn(),r=Yo(),{mutate:a}=Ki({mutationKey:["signup"],mutationFn:o(async s=>{if(!e)throw new Error("Record not found");return t.salesUpdate(e.id,s)},"mutationFn"),onSuccess:o(()=>{r("/sales"),n("User updated successfully")},"onSuccess"),onError:o(()=>{n("An error occurred. Please try again.")},"onError")}),i=o(async s=>{a(s)},"onSubmit");return h.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:h.jsx(rr,{children:h.jsx(ei,{children:h.jsxs(XJ,{toolbar:h.jsx(jqe,{}),onSubmit:i,record:e,children:[h.jsx(Rqe,{}),h.jsx(Fae,{})]})})})})}o(Oqe,"SalesEdit");const Rqe=o(()=>{const e=Vt();return e?h.jsxs("h2",{className:"text-lg font-semibold mb-4",children:["Edit ",e?.first_name," ",e?.last_name]}):null},"SaleEditTitle"),kqe=o(()=>h.jsxs(i4,{children:[h.jsx(v1,{}),h.jsx(Sc,{label:"New user"})]}),"SalesListActions"),Aqe=[h.jsx(o4,{source:"q",alwaysOn:!0})],Tqe=o(e=>{const t=Vt();return t?h.jsxs("div",{className:"flex flex-row gap-1",children:[t.administrator&&h.jsx(Kh,{variant:"outline",className:"border-blue-300 dark:border-blue-700",children:"Admin"}),t.disabled&&h.jsx(Kh,{variant:"outline",className:"border-orange-300 dark:border-orange-700",children:"Disabled"})]}):null},"OptionsField"),Pqe=o(()=>{const e=Vt(),t=Vn(),n=dn(),r=mw(),[a,i]=y.useState(!1),[s,l]=y.useState(!1),{mutate:d,isPending:c}=Ki({mutationFn:o(async()=>t.resendInvite(e.id),"mutationFn"),onSuccess:o(()=>{n("Invitation email resent successfully"),i(!1),r()},"onSuccess"),onError:o(()=>{n("Failed to resend invitation email",{type:"error"}),i(!1)},"onError")}),{mutate:p,isPending:m}=Ki({mutationFn:o(async()=>t.resetPassword(e.id),"mutationFn"),onSuccess:o(()=>{n("Password reset email sent successfully"),l(!1),r()},"onSuccess"),onError:o(()=>{n("Failed to send password reset email",{type:"error"}),l(!1)},"onError")});if(!e)return null;const g=e.email_confirmed_at!==null,x=e.disabled===!0;return console.log("[RowActions] Record:",{email:e.email,email_confirmed_at:e.email_confirmed_at,isConfirmed:g,isDisabled:x,inviteDialogOpen:a,resetDialogOpen:s}),h.jsxs(h.Fragment,{children:[h.jsxs(wc,{children:[h.jsx(Bs,{asChild:!0,children:h.jsxs(Ge,{variant:"ghost",className:"h-8 w-8 p-0",children:[h.jsx("span",{className:"sr-only",children:"Open menu"}),h.jsx(pD,{className:"h-4 w-4"})]})}),h.jsxs(_c,{align:"end",children:[h.jsx(WD,{children:"Email Actions"}),h.jsx(Vv,{}),!g&&h.jsxs(cr,{onClick:o(w=>{w.preventDefault(),w.stopPropagation(),console.log("[Menu] Clicked Resend Invite"),i(!0)},"onClick"),children:[h.jsx(Nwe,{className:"mr-2 h-4 w-4"}),"Resend Invite"]}),g&&!x&&h.jsxs(cr,{onClick:o(()=>l(!0),"onClick"),children:[h.jsx(swe,{className:"mr-2 h-4 w-4"}),"Send Password Reset"]})]})]}),h.jsx(Oi,{open:a,onOpenChange:i,children:h.jsxs(Ri,{onClick:o(w=>w.stopPropagation(),"onClick"),onPointerDown:o(w=>w.stopPropagation(),"onPointerDown"),children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Resend Invitation"}),h.jsxs(Ds,{children:["Send a new invitation email to ",h.jsx("strong",{children:e.email}),"?",h.jsx("br",{}),h.jsx("br",{}),"This will send them a fresh invitation link to set up their account."]})]}),h.jsxs(Vs,{children:[h.jsx(Ge,{variant:"outline",onClick:o(w=>{w.stopPropagation(),i(!1)},"onClick"),disabled:c,children:"Cancel"}),h.jsx(Ge,{onClick:o(w=>{w.stopPropagation(),d()},"onClick"),disabled:c,children:c?"Sending...":"Send Invitation"})]})]})}),h.jsx(Oi,{open:s,onOpenChange:l,children:h.jsxs(Ri,{onClick:o(w=>w.stopPropagation(),"onClick"),onPointerDown:o(w=>w.stopPropagation(),"onPointerDown"),children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Send Password Reset"}),h.jsxs(Ds,{children:["Send a password reset email to ",h.jsx("strong",{children:e.email}),"?",h.jsx("br",{}),h.jsx("br",{}),"This will send them a link to reset their password."]})]}),h.jsxs(Vs,{children:[h.jsx(Ge,{variant:"outline",onClick:o(w=>{w.stopPropagation(),l(!1)},"onClick"),disabled:m,children:"Cancel"}),h.jsx(Ge,{onClick:o(w=>{w.stopPropagation(),p()},"onClick"),disabled:m,children:m?"Sending...":"Send Reset Link"})]})]})})]})},"RowActions");function Nqe(){return h.jsx(r4,{filters:Aqe,actions:h.jsx(kqe,{}),sort:{field:"first_name",order:"ASC"},children:h.jsx(Mqe,{})})}o(Nqe,"SalesList");const Mqe=o(()=>{const{data:e,isPending:t,filterValues:n}=zn(),{identity:r}=wr(),a=n&&Object.keys(n).length>0;return!r||t?h.jsx(rr,{className:"p-4",children:h.jsxs("div",{className:"space-y-3",children:[h.jsx(fn,{className:"h-12 w-full"}),h.jsx(fn,{className:"h-12 w-full"}),h.jsx(fn,{className:"h-12 w-full"}),h.jsx(fn,{className:"h-12 w-full"}),h.jsx(fn,{className:"h-12 w-full"})]})}):!e?.length&&!a?h.jsx(Dqe,{}):h.jsxs(Rs,{children:[h.jsx(Rs.Col,{source:"first_name"}),h.jsx(Rs.Col,{source:"last_name"}),h.jsx(Rs.Col,{source:"email"}),h.jsx(Rs.Col,{label:!1,children:h.jsx(Tqe,{})}),h.jsx(Rs.Col,{label:!1,children:h.jsx(Pqe,{})})]})},"SalesListLayout"),Dqe=o(()=>{const e=w1();return h.jsxs("div",{className:"flex flex-col justify-center items-center gap-3",style:{height:`calc(100dvh - ${e}px)`},children:[h.jsx("img",{src:"./img/empty.svg",alt:"No users found"}),h.jsxs("div",{className:"flex flex-col gap-0 items-center",children:[h.jsx("h6",{className:"text-lg font-bold",children:"No users found"}),h.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"It seems your user list is empty."})]}),h.jsx("div",{className:"flex flex-row gap-2",children:h.jsx(Sc,{label:"New user"})})]})},"SalesEmpty"),Iqe={list:Nqe,create:Cqe,edit:Oqe,recordRepresentation:o(e=>`${e.first_name} ${e.last_name}`,"recordRepresentation")};function $ae({open:e,onComplete:t,canClose:n=!1}){const[r,a]=y.useState("welcome"),[i,s]=y.useState(""),[l,d]=y.useState(""),[c,p]=y.useState(null),m=o(async()=>{p(null),a("validating");const x=await ZRe(i,l);x.valid?(KRe({url:i,anonKey:l}),a("success"),setTimeout(()=>{window.location.href=window.location.origin},1500)):(p(x.error||"Connection failed"),a("credentials"))},"handleValidateAndSave"),g=o(()=>{n&&t()},"handleClose");return h.jsx(Oi,{open:e,onOpenChange:n?g:void 0,children:h.jsxs(Ri,{className:"sm:max-w-md",onPointerDownOutside:o(x=>!n&&x.preventDefault(),"onPointerDownOutside"),onEscapeKeyDown:o(x=>!n&&x.preventDefault(),"onEscapeKeyDown"),children:[r==="welcome"&&h.jsxs(h.Fragment,{children:[h.jsxs(ca,{children:[h.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[h.jsx(Fv,{className:"h-6 w-6 text-primary"}),h.jsx(ua,{children:"Welcome to CRM"})]}),h.jsx(Ds,{children:"To get started, you'll need to connect to a Supabase database."})]}),h.jsxs("div",{className:"space-y-4 py-4",children:[h.jsx(_i,{children:h.jsxs(Wi,{children:[h.jsx("strong",{children:"Don't have a Supabase project?"}),h.jsx("br",{}),"Create one for free at"," ",h.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline text-primary",children:"supabase.com"})]})}),h.jsxs("div",{className:"space-y-2",children:[h.jsx("h4",{className:"font-medium text-sm",children:"What you'll need:"}),h.jsxs("ul",{className:"list-disc list-inside text-sm text-muted-foreground space-y-1",children:[h.jsx("li",{children:"Your Supabase project URL"}),h.jsx("li",{children:"Your anonymous (anon) API key"})]})]}),h.jsx(Ge,{onClick:o(()=>a("credentials"),"onClick"),className:"w-full",children:"Continue"})]})]}),r==="credentials"&&h.jsxs(h.Fragment,{children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Connect to Supabase"}),h.jsx(Ds,{children:"Enter your Supabase project credentials"})]}),h.jsxs("div",{className:"space-y-4 py-4",children:[c&&h.jsxs(_i,{variant:"destructive",children:[h.jsx(Gg,{className:"h-4 w-4"}),h.jsx(Wi,{children:c})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx(wi,{htmlFor:"supabase-url",children:"Supabase URL"}),h.jsx(Qa,{id:"supabase-url",placeholder:"https://xxxxx.supabase.co",value:i,onChange:o(x=>s(x.target.value),"onChange")}),h.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in Project Settings → API"})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx(wi,{htmlFor:"anon-key",children:"Anonymous Key"}),h.jsx(Qa,{id:"anon-key",type:"password",placeholder:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",value:l,onChange:o(x=>d(x.target.value),"onChange")}),h.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in Project Settings → API → Project API keys"})]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx(Ge,{variant:"outline",onClick:o(()=>a("welcome"),"onClick"),className:"flex-1",children:"Back"}),h.jsx(Ge,{onClick:m,disabled:!i||!l,className:"flex-1",children:"Connect"})]})]})]}),r==="validating"&&h.jsxs(h.Fragment,{children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Validating Connection"}),h.jsx(Ds,{children:"Testing your Supabase credentials..."})]}),h.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[h.jsx(yp,{className:"h-12 w-12 animate-spin text-primary mb-4"}),h.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait..."})]})]}),r==="success"&&h.jsxs(h.Fragment,{children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Connection Successful!"}),h.jsx(Ds,{children:"Your Supabase database is now connected"})]}),h.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[h.jsx(nc,{className:"h-12 w-12 text-green-500 mb-4"}),h.jsx("p",{className:"text-sm text-muted-foreground",children:"Reloading application..."})]})]})]})})}o($ae,"SupabaseSetupWizard");function Lqe(){const[e,t]=y.useState(!1),n=iy(),r=JRe(),a=o(()=>{confirm("Are you sure you want to clear the database configuration? The app will need to be reconfigured on next launch.")&&(QRe(),window.location.reload())},"handleClearConfig");return h.jsxs(h.Fragment,{children:[h.jsxs(rr,{children:[h.jsxs(yx,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Fv,{className:"h-5 w-5"}),h.jsx(bx,{children:"Database Connection"})]}),h.jsx(VJ,{children:"Manage your Supabase database connection settings"})]}),h.jsx(ei,{className:"space-y-4",children:n?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-start gap-3 p-4 border rounded-lg",children:[h.jsx(nc,{className:"h-5 w-5 text-green-500 mt-0.5"}),h.jsxs("div",{className:"flex-1 space-y-1",children:[h.jsx("p",{className:"font-medium",children:"Connected"}),h.jsx("p",{className:"text-sm text-muted-foreground",children:n.url}),n.configuredAt&&h.jsxs("p",{className:"text-xs text-muted-foreground",children:["Configured on"," ",new Date(n.configuredAt).toLocaleDateString()]})]})]}),r==="env"&&h.jsxs(_i,{children:[h.jsx(QT,{className:"h-4 w-4"}),h.jsx(Wi,{children:"Using configuration from environment variables. You can override this by setting up a new connection via the UI."})]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsxs(Ge,{variant:"outline",onClick:o(()=>t(!0),"onClick"),className:"flex-1",children:[h.jsx(QT,{className:"h-4 w-4 mr-2"}),"Change Connection"]}),r==="ui"&&h.jsxs(Ge,{variant:"destructive",onClick:a,className:"flex-1",children:[h.jsx(uQ,{className:"h-4 w-4 mr-2"}),"Clear Configuration"]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx(Fqe,{className:"text-sm font-medium",children:"Anonymous Key"}),h.jsxs("div",{className:"font-mono text-sm p-2 bg-muted rounded",children:[n.anonKey.substring(0,20),"...",n.anonKey.substring(n.anonKey.length-10)]})]})]}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-start gap-3 p-4 border border-dashed rounded-lg",children:[h.jsx(bc,{className:"h-5 w-5 text-destructive mt-0.5"}),h.jsxs("div",{className:"flex-1 space-y-1",children:[h.jsx("p",{className:"font-medium",children:"Not Connected"}),h.jsx("p",{className:"text-sm text-muted-foreground",children:"No Supabase database is configured"})]})]}),h.jsx(_i,{children:h.jsxs(Wi,{children:["Connect to a Supabase database to start using Atomic CRM. You can create a free project at"," ",h.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"supabase.com"})]})}),h.jsxs(Ge,{onClick:o(()=>t(!0),"onClick"),className:"w-full",children:[h.jsx(Fv,{className:"h-4 w-4 mr-2"}),"Connect to Supabase"]})]})})]}),h.jsx($ae,{open:e,onComplete:o(()=>t(!1),"onComplete"),canClose:!0})]})}o(Lqe,"DatabaseSettings");function Fqe({children:e,className:t}){return h.jsx("label",{className:t,children:e})}o(Fqe,"Label");const HN=o(()=>h.jsx("div",{className:"max-w-lg mx-auto mt-8",children:h.jsx(Lqe,{})}),"DatabasePage");HN.path="/database";const VN=o(()=>{const[e,t]=y.useState(!1),{identity:n,refetch:r}=wr(),{data:a,refetch:i}=vw("sales",{id:n?.id}),s=dn(),l=Vn(),{mutate:d}=Ki({mutationKey:["signup"],mutationFn:o(async p=>{if(!n)throw new Error("Record not found");return l.salesUpdate(n.id,p)},"mutationFn"),onSuccess:o(()=>{r(),i(),t(!1),s("Your profile has been updated")},"onSuccess"),onError:o(p=>{s("An error occurred. Please try again",{type:"error"})},"onError")});if(!n)return null;const c=o(async p=>{d(p)},"handleOnSubmit");return h.jsx("div",{className:"max-w-lg mx-auto mt-8",children:h.jsx(Kr,{onSubmit:c,record:a,children:h.jsx($qe,{isEditMode:e,setEditMode:t})})})},"SettingsPage"),$qe=o(({isEditMode:e,setEditMode:t})=>{const n=dn(),r=pa(),a=Vt(),{identity:i,refetch:s}=wr(),{isDirty:l}=Bg(),d=Vn(),{mutate:c}=Ki({mutationKey:["signup"],mutationFn:o(async g=>{if(!a)throw new Error("Record not found");return d.salesUpdate(a.id,g)},"mutationFn"),onSuccess:o(()=>{s(),n("Your profile has been updated")},"onSuccess"),onError:o(()=>{n("An error occurred. Please try again.")},"onError")});if(!i)return null;const p=o(()=>{r("/forgot-password")},"handleClickOpenPasswordChange"),m=o(async g=>{c(g)},"handleAvatarUpdate");return h.jsxs("div",{className:"space-y-4",children:[h.jsx(rr,{children:h.jsxs(ei,{children:[h.jsx("div",{className:"mb-4 flex flex-row justify-between",children:h.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"My info"})}),h.jsxs("div",{className:"space-y-4 mb-4",children:[h.jsx(Bee,{source:"avatar",type:"avatar",onSave:m,linkPosition:"right"}),h.jsx(JA,{source:"first_name",isEditMode:e}),h.jsx(JA,{source:"last_name",isEditMode:e}),h.jsx(JA,{source:"email",isEditMode:e})]}),h.jsxs("div",{className:"flex flex-row justify-end gap-2",children:[!e&&h.jsx(h.Fragment,{children:h.jsx(Ge,{variant:"outline",type:"button",onClick:p,children:"Change password"})}),h.jsxs(Ge,{type:"button",variant:e?"ghost":"outline",onClick:o(()=>t(!e),"onClick"),className:"flex items-center",children:[e?h.jsx(bc,{}):h.jsx(oQ,{}),e?"Cancel":"Edit"]}),e&&h.jsxs(Ge,{type:"submit",disabled:!l,variant:"outline",children:[h.jsx(zw,{}),"Save"]})]})]})}),void 0]})},"SettingsForm"),JA=o(({source:e,isEditMode:t})=>t?h.jsx(on,{source:e,helperText:!1}):h.jsx("div",{className:"m-2",children:h.jsx(d3e,{source:e})}),"TextRender");VN.path="/settings";var qqe={"ra-supabase":{auth:{email:"Email",confirm_password:"Confirm password",sign_in_with:"Sign in with %{provider}",forgot_password:"Forgot password?",reset_password:"Reset password",password_reset:"Your password has been reset. You will receive an email containing a link to log in.",missing_tokens:"Access and refresh tokens are missing",back_to_login:"Back to login"},reset_password:{forgot_password:"Forgot password?",forgot_password_details:"Enter your email for instructions."},set_password:{new_password:"Choose your password"},validation:{password_mismatch:"Passwords do not match"}}};const zqe={"ra-supabase":{auth:{password_reset:"Check your emails for a Reset Password message."}}},Uqe=$K(()=>Cde(jK,qqe,zqe),"en",[{locale:"en",name:"English"}],{allowMissing:!0}),Bqe=o(()=>{const e=Vn(),{data:t,error:n,isPending:r}=Ma({queryKey:["init"],queryFn:o(async()=>e.isInitialized(),"queryFn")});return r?h.jsx(Iae,{}):n?h.jsx(nx,{}):t?h.jsx(nx,{}):h.jsx(Jx,{to:"/sign-up"})},"StartPage");async function Hqe(e){const t=["contacts","companies","deals","contactNotes","dealNotes","tasks","sales","tags"],n=[];try{for(const r of t)try{await e.getList(r,{pagination:{page:1,perPage:1},sort:{field:"id",order:"ASC"},filter:{}})}catch(a){(a?.message?.includes("Could not find the table")||a?.message?.includes("relation")||a?.message?.includes("does not exist"))&&n.push(r)}return{isHealthy:n.length===0,missingTables:n}}catch(r){return{isHealthy:!1,missingTables:t,error:r?.message||"Unknown error"}}}o(Hqe,"checkDatabaseHealth");function Vqe({missingTables:e,supabaseUrl:t}){const n=t.match(/https:\/\/([^.]+)\.supabase\.co/)?.[1];return h.jsxs("div",{className:"max-w-2xl mx-auto mt-8 space-y-4",children:[h.jsxs(_i,{variant:"destructive",children:[h.jsx(Gg,{className:"h-4 w-4"}),h.jsx(rte,{children:"Database Schema Not Configured"}),h.jsx(Wi,{children:"Your Supabase database is connected, but the CRM schema hasn't been set up yet."})]}),h.jsxs(rr,{children:[h.jsxs(yx,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Fv,{className:"h-5 w-5"}),h.jsx(bx,{children:"Setup Instructions"})]}),h.jsx(VJ,{children:"Follow these steps to set up your database schema"})]}),h.jsxs(ei,{className:"space-y-6",children:[h.jsxs("div",{children:[h.jsx("h3",{className:"font-semibold mb-2",children:"Missing Tables:"}),h.jsx("div",{className:"flex flex-wrap gap-2",children:e.map(r=>h.jsx("span",{className:"px-2 py-1 bg-destructive/10 text-destructive text-sm rounded",children:r},r))})]}),h.jsxs("div",{className:"space-y-3",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-primary text-primary-foreground text-sm font-bold",children:"1"}),h.jsx("h3",{className:"font-semibold",children:"Using Supabase CLI (Recommended)"})]}),h.jsxs("div",{className:"ml-8 space-y-3",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Install Supabase CLI:"}),h.jsx("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:"npm install -g supabase"})]}),h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Clone the RealTimeX CRM repository to get migrations:"}),h.jsxs("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:["git clone https://github.com/therealtimex/realtimex-crm.git",`
151
+ `,fill:a,opacity:s,strokeWidth:d,stroke:c===void 0?"transparent":c,style:{pointerEvents:"none"}})})},"y");function Zl(){return Zl=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Zl.apply(null,arguments)}o(Zl,"b");var xi={translateX:0,translateY:0,padding:0,itemsSpacing:0,itemDirection:"left-to-right",justify:!1,symbolShape:"square",symbolSize:16,symbolSpacing:8},t9e={top:0,right:0,bottom:0,left:0},m3=o(function(e){var t,n=e.direction,r=e.itemsSpacing,a=e.padding,i=e.itemCount,s=e.itemWidth,l=e.itemHeight;if(typeof a!="number"&&(typeof(t=a)!="object"||Array.isArray(t)||t===null))throw new Error("Invalid property padding, must be one of: number, object");var d=typeof a=="number"?{top:a,right:a,bottom:a,left:a}:Zl({},t9e,a),c=d.left+d.right,p=d.top+d.bottom,m=s+c,g=l+p,x=(i-1)*r;return n==="row"?m=s*i+x+c:n==="column"&&(g=l*i+x+p),{width:m,height:g,padding:d}},"A"),jae=o(function(e){var t=e.anchor,n=e.translateX,r=e.translateY,a=e.containerWidth,i=e.containerHeight,s=e.width,l=e.height,d=n,c=r;switch(t){case"top":d+=(a-s)/2;break;case"top-right":d+=a-s;break;case"right":d+=a-s,c+=(i-l)/2;break;case"bottom-right":d+=a-s,c+=i-l;break;case"bottom":d+=(a-s)/2,c+=i-l;break;case"bottom-left":c+=i-l;break;case"left":c+=(i-l)/2;break;case"center":d+=(a-s)/2,c+=(i-l)/2}return{x:d,y:c}},"C"),Oae=o(function(e){var t,n,r,a,i,s,l=e.direction,d=e.justify,c=e.symbolSize,p=e.symbolSpacing,m=e.width,g=e.height;switch(l){case"left-to-right":t=0,n=(g-c)/2,a=g/2,s="central",d?(r=m,i="end"):(r=c+p,i="start");break;case"right-to-left":t=m-c,n=(g-c)/2,a=g/2,s="central",d?(r=0,i="start"):(r=m-c-p,i="end");break;case"top-to-bottom":t=(m-c)/2,n=0,r=m/2,i="middle",d?(a=g,s="alphabetic"):(a=c+p,s="text-before-edge");break;case"bottom-to-top":t=(m-c)/2,n=g-c,r=m/2,i="middle",d?(a=0,s="text-before-edge"):(a=g-c-p,s="alphabetic")}return{symbolX:t,symbolY:n,labelX:r,labelY:a,labelAnchor:i,labelAlignment:s}},"z"),n9e={circle:X$e,diamond:Z$e,square:J$e,triangle:e9e},r9e=o(function(e){var t,n,r,a,i,s,l,d,c,p,m,g=e.x,x=e.y,w=e.width,S=e.height,_=e.data,E=e.direction,C=E===void 0?xi.itemDirection:E,O=e.justify,j=O===void 0?xi.justify:O,T=e.textColor,k=e.background,A=k===void 0?"transparent":k,P=e.opacity,M=P===void 0?1:P,D=e.symbolShape,I=D===void 0?xi.symbolShape:D,L=e.symbolSize,F=L===void 0?xi.symbolSize:L,q=e.symbolSpacing,U=q===void 0?xi.symbolSpacing:q,$=e.symbolBorderWidth,H=$===void 0?0:$,z=e.symbolBorderColor,W=z===void 0?"transparent":z,V=e.onClick,Q=e.onMouseEnter,K=e.onMouseLeave,Y=e.toggleSerie,ee=e.effects,te=y.useState({}),oe=te[0],ne=te[1],fe=Tr(),re=y.useCallback((function(X){if(ee){var se=ee.filter((function(me){return me.on==="hover"})).reduce((function(me,Te){return Zl({},me,Te.style)}),{});ne(se)}Q?.(_,X)}),[Q,_,ee]),ce=y.useCallback((function(X){if(ee){var se=ee.filter((function(me){return me.on!=="hover"})).reduce((function(me,Te){return Zl({},me,Te.style)}),{});ne(se)}K?.(_,X)}),[K,_,ee]),he=Oae({direction:C,justify:j,symbolSize:(t=oe.symbolSize)!=null?t:F,symbolSpacing:U,width:w,height:S}),J=he.symbolX,De=he.symbolY,we=he.labelX,Ce=he.labelY,ke=he.labelAnchor,Re=he.labelAlignment,Pe=[V,Q,K,Y].some((function(X){return X!==void 0})),ze=typeof I=="function"?I:n9e[I];return h.jsxs("g",{transform:"translate("+g+","+x+")",style:{opacity:(n=oe.itemOpacity)!=null?n:M},children:[h.jsx("rect",{width:w,height:S,fill:(r=oe.itemBackground)!=null?r:A,style:{cursor:Pe?"pointer":"auto"},onClick:o(function(X){V?.(_,X),Y?.(_.id)},"onClick"),onMouseEnter:re,onMouseLeave:ce}),y.createElement(ze,Zl({id:_.id,x:J,y:De,size:(a=oe.symbolSize)!=null?a:F,fill:(i=(s=_.fill)!=null?s:_.color)!=null?i:"black",borderWidth:(l=oe.symbolBorderWidth)!=null?l:H,borderColor:(d=oe.symbolBorderColor)!=null?d:W},_.hidden?fe.legends.hidden.symbol:void 0)),h.jsx(R_,{textAnchor:ke,style:Zl({},fe.legends.text,{fill:(c=(p=(m=oe.itemTextColor)!=null?m:T)!=null?p:fe.legends.text.fill)!=null?c:"black",dominantBaseline:Re,pointerEvents:"none",userSelect:"none"},_.hidden?fe.legends.hidden.text:void 0),x:we,y:Ce,children:_.label})]})},"B"),a9e=o(function(e){var t=e.data,n=e.x,r=e.y,a=e.direction,i=e.padding,s=i===void 0?xi.padding:i,l=e.justify,d=e.effects,c=e.itemWidth,p=e.itemHeight,m=e.itemDirection,g=m===void 0?xi.itemDirection:m,x=e.itemsSpacing,w=x===void 0?xi.itemsSpacing:x,S=e.itemTextColor,_=e.itemBackground,E=_===void 0?"transparent":_,C=e.itemOpacity,O=C===void 0?1:C,j=e.symbolShape,T=e.symbolSize,k=e.symbolSpacing,A=e.symbolBorderWidth,P=e.symbolBorderColor,M=e.onClick,D=e.onMouseEnter,I=e.onMouseLeave,L=e.toggleSerie,F=m3({itemCount:t.length,itemWidth:c,itemHeight:p,itemsSpacing:w,direction:a,padding:s}).padding,q=a==="row"?c+w:0,U=a==="column"?p+w:0;return h.jsx("g",{transform:"translate("+n+","+r+")",children:t.map((function($,H){return h.jsx(r9e,{data:$,x:H*q+F.left,y:H*U+F.top,width:c,height:p,direction:g,justify:l,effects:d,textColor:S,background:E,opacity:O,symbolShape:j,symbolSize:T,symbolSpacing:k,symbolBorderWidth:A,symbolBorderColor:P,onClick:M,onMouseEnter:D,onMouseLeave:I,toggleSerie:L},H)}))})},"H"),i9e=o(function(e){var t=e.data,n=e.containerWidth,r=e.containerHeight,a=e.translateX,i=a===void 0?xi.translateX:a,s=e.translateY,l=s===void 0?xi.translateY:s,d=e.anchor,c=e.direction,p=e.padding,m=p===void 0?xi.padding:p,g=e.justify,x=e.itemsSpacing,w=x===void 0?xi.itemsSpacing:x,S=e.itemWidth,_=e.itemHeight,E=e.itemDirection,C=e.itemTextColor,O=e.itemBackground,j=e.itemOpacity,T=e.symbolShape,k=e.symbolSize,A=e.symbolSpacing,P=e.symbolBorderWidth,M=e.symbolBorderColor,D=e.onClick,I=e.onMouseEnter,L=e.onMouseLeave,F=e.toggleSerie,q=e.effects,U=m3({itemCount:t.length,itemsSpacing:w,itemWidth:S,itemHeight:_,direction:c,padding:m}),$=U.width,H=U.height,z=jae({anchor:d,translateX:i,translateY:l,containerWidth:n,containerHeight:r,width:$,height:H}),W=z.x,V=z.y;return h.jsx(a9e,{data:t,x:W,y:V,direction:c,padding:m,justify:g,effects:q,itemsSpacing:w,itemWidth:S,itemHeight:_,itemDirection:E,itemTextColor:C,itemBackground:O,itemOpacity:j,symbolShape:T,symbolSize:k,symbolSpacing:A,symbolBorderWidth:P,symbolBorderColor:M,onClick:D,onMouseEnter:I,onMouseLeave:L,toggleSerie:typeof F=="boolean"?void 0:F})},"E"),o9e={start:"left",middle:"center",end:"right"},s9e=o(function(e,t){var n=t.data,r=t.containerWidth,a=t.containerHeight,i=t.translateX,s=i===void 0?0:i,l=t.translateY,d=l===void 0?0:l,c=t.anchor,p=t.direction,m=t.padding,g=m===void 0?0:m,x=t.justify,w=x!==void 0&&x,S=t.itemsSpacing,_=S===void 0?0:S,E=t.itemWidth,C=t.itemHeight,O=t.itemDirection,j=O===void 0?"left-to-right":O,T=t.itemTextColor,k=t.symbolSize,A=k===void 0?16:k,P=t.symbolSpacing,M=P===void 0?8:P,D=t.theme,I=m3({itemCount:n.length,itemWidth:E,itemHeight:C,itemsSpacing:_,direction:p,padding:g}),L=I.width,F=I.height,q=I.padding,U=jae({anchor:c,translateX:s,translateY:d,containerWidth:r,containerHeight:a,width:L,height:F}),$=U.x,H=U.y,z=p==="row"?E+_:0,W=p==="column"?C+_:0;e.save(),e.translate($,H),wg(e,D.legends.text),n.forEach((function(V,Q){var K,Y=Q*z+q.left,ee=Q*W+q.top,te=Oae({direction:j,justify:w,symbolSize:A,symbolSpacing:M,width:E,height:C}),oe=te.symbolX,ne=te.symbolY,fe=te.labelX,re=te.labelY,ce=te.labelAnchor,he=te.labelAlignment;e.fillStyle=(K=V.color)!=null?K:"black",e.fillRect(Y+oe,ee+ne,A,A),e.textAlign=o9e[ce],he==="central"&&(e.textBaseline="middle"),_g(e,Zl({},D.legends.text,{fill:T??D.legends.text.fill}),String(V.label),Y+fe,ee+re)})),e.restore()},"L"),l9e=o(function(e,t,n,r,a,i){i>0?(e.moveTo(t+i,n),e.lineTo(t+r-i,n),e.quadraticCurveTo(t+r,n,t+r,n+i),e.lineTo(t+r,n+a-i),e.quadraticCurveTo(t+r,n+a,t+r-i,n+a),e.lineTo(t+i,n+a),e.quadraticCurveTo(t,n+a,t,n+a-i),e.lineTo(t,n+i),e.quadraticCurveTo(t,n,t+i,n),e.closePath()):e.rect(t,n,r,a)},"o");function pn(){return pn=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},pn.apply(null,arguments)}o(pn,"Q");function Rc(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}o(Rc,"U");var HV,c9e=o(function(e){var t=e.bars,n=e.annotations,r=_ae({data:t,annotations:n,getPosition:o(function(a){return{x:a.x+a.width/2,y:a.y+a.height/2}},"getPosition"),getDimensions:o(function(a){var i=a.height,s=a.width;return{width:s,height:i,size:Math.max(s,i)}},"getDimensions")});return h.jsx(h.Fragment,{children:r.map((function(a,i){return h.jsx(M$e,pn({},a),i)}))})},"$"),u9e=o(function(e){var t=e.width,n=e.height,r=e.legends,a=e.toggleSerie;return h.jsx(h.Fragment,{children:r.map((function(i,s){var l,d=i[0],c=i[1];return h.jsx(i9e,pn({},d,{containerWidth:t,containerHeight:n,data:(l=d.data)!=null?l:c,toggleSerie:d.toggleSerie&&d.dataFrom==="keys"?a:void 0}),s)}))})},"ee"),d9e=["data"],f9e=o(function(e){var t,n=e.bar,r=n.data,a=Rc(n,d9e),i=e.style,s=i.borderColor,l=i.color,d=i.height,c=i.labelColor,p=i.labelOpacity,m=i.labelX,g=i.labelY,x=i.transform,w=i.width,S=i.textAnchor,_=e.borderRadius,E=e.borderWidth,C=e.label,O=e.shouldRenderLabel,j=e.isInteractive,T=e.onClick,k=e.onMouseEnter,A=e.onMouseLeave,P=e.tooltip,M=e.isFocusable,D=e.ariaLabel,I=e.ariaLabelledBy,L=e.ariaDescribedBy,F=e.ariaDisabled,q=e.ariaHidden,U=Tr(),$=tre(),H=$.showTooltipFromEvent,z=$.showTooltipAt,W=$.hideTooltip,V=y.useMemo((function(){return function(){return y.createElement(P,pn({},a,r))}}),[P,a,r]),Q=y.useCallback((function(ne){T?.(pn({color:a.color},r),ne)}),[a,r,T]),K=y.useCallback((function(ne){return H(V(),ne)}),[H,V]),Y=y.useCallback((function(ne){k?.(r,ne),H(V(),ne)}),[r,k,H,V]),ee=y.useCallback((function(ne){A?.(r,ne),W()}),[r,W,A]),te=y.useCallback((function(){z(V(),[a.absX+a.width/2,a.absY])}),[z,V,a]),oe=y.useCallback((function(){W()}),[W]);return h.jsxs(ur.g,{transform:x,children:[h.jsx(ur.rect,{width:ON(w,(function(ne){return Math.max(ne,0)})),height:ON(d,(function(ne){return Math.max(ne,0)})),rx:_,ry:_,fill:(t=r.fill)!=null?t:l,strokeWidth:E,stroke:s,focusable:M,tabIndex:M?0:void 0,"aria-label":D?D(r):void 0,"aria-labelledby":I?I(r):void 0,"aria-describedby":L?L(r):void 0,"aria-disabled":F?F(r):void 0,"aria-hidden":q?q(r):void 0,onMouseEnter:j?Y:void 0,onMouseMove:j?K:void 0,onMouseLeave:j?ee:void 0,onClick:j?Q:void 0,onFocus:j&&M?te:void 0,onBlur:j&&M?oe:void 0,"data-testid":"bar.item."+r.id+"."+r.index}),O&&h.jsx(R_,{x:m,y:g,textAnchor:S,dominantBaseline:"central",fillOpacity:p,style:pn({},U.labels.text,{pointerEvents:"none",fill:c}),children:C})]})},"ae"),h9e=["color","label"],p9e=o(function(e){var t=e.color,n=e.label,r=Rc(e,h9e);return h.jsx(M6e,{id:n,value:r.formattedValue,enableChip:!0,color:t})},"ne"),Mn={indexBy:"id",keys:["value"],groupMode:"stacked",layout:"vertical",valueScale:{type:"linear",nice:!0,round:!1},indexScale:{type:"band",round:!1},padding:.1,innerPadding:0,enableGridX:!1,enableGridY:!0,enableLabel:!0,label:"formattedValue",labelPosition:"middle",labelOffset:0,labelSkipWidth:0,labelSkipHeight:0,labelTextColor:{theme:"labels.text.fill"},colorBy:"id",colors:{scheme:"nivo"},borderRadius:0,borderWidth:0,borderColor:{from:"color"},isInteractive:!0,tooltip:p9e,tooltipLabel:o(function(e){return e.id+" - "+e.indexValue},"tooltipLabel"),legends:[],initialHiddenIds:[],annotations:[],enableTotals:!1,totalsOffset:10},Nn=pn({},Mn,{layers:["grid","axes","bars","totals","markers","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},barComponent:f9e,defs:[],fill:[],markers:[],animate:!0,animateOnMount:!1,motionConfig:"default",role:"img",isFocusable:!1}),pr=pn({},Mn,{layers:["grid","axes","bars","totals","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},renderBar:o(function(e,t){var n=t.bar,r=n.color,a=n.height,i=n.width,s=n.x,l=n.y,d=t.borderColor,c=t.borderRadius,p=t.borderWidth,m=t.label,g=t.shouldRenderLabel,x=t.labelStyle,w=t.labelX,S=t.labelY,_=t.textAnchor;e.fillStyle=r,p>0&&(e.strokeStyle=d,e.lineWidth=p),e.beginPath(),l9e(e,s,l,i,a,Math.min(c,a)),e.fill(),p>0&&e.stroke(),g&&(e.textBaseline="middle",e.textAlign=_==="middle"?"center":_,_g(e,x,m,s+w,l+S))},"renderBar"),pixelRatio:typeof window<"u"&&(HV=window.devicePixelRatio)!=null?HV:1}),Rae=o(function(e,t,n,r,a,i){return p3(r,{all:e.map(t),min:0,max:0},a,i).padding(n)},"de"),kae=o(function(e,t){return e.map((function(n){return pn({},t.reduce((function(r,a){return r[a]=null,r}),{}),n)}))},"ue"),k_=o(function(e){return Object.keys(e).reduce((function(t,n){return e[n]&&(t[n]=e[n]),t}),{})},"se"),A_=o(function(e){return[e,Number(e)]},"ce");function Aae(e,t,n,r){return e===void 0&&(e=Mn.layout),n===void 0&&(n=Mn.labelPosition),r===void 0&&(r=Mn.labelOffset),function(a,i){var s=r*(t?-1:1);if(e==="horizontal"){var l=a/2;return n==="start"?l=t?a:0:n==="end"&&(l=t?0:a),{labelX:l+s,labelY:i/2,textAnchor:n==="middle"?"middle":t?"end":"start"}}var d=i/2;return n==="start"?d=t?0:i:n==="end"&&(d=t?i:0),{labelX:a/2,labelY:d-s,textAnchor:"middle"}}}o(Aae,"he");var m9e=["layout","width","height","padding","innerPadding","valueScale","indexScale","hiddenIds"],v3=o(function(e,t){return e>t},"be"),Tae=o(function(e,t){return e<t},"ge"),Pae=o(function(e,t){return Array.from(" ".repeat(t-e),(function(n,r){return e+r}))},"ve"),v9e=o(function(e){return v3(e,0)?0:e},"me"),g9e=o(function(e,t,n,r){var a=e.data,i=e.formatValue,s=e.getColor,l=e.getIndex,d=e.getTooltipLabel,c=e.innerPadding,p=c===void 0?0:c,m=e.keys,g=e.xScale,x=e.yScale,w=e.margin,S=n?Tae:v3,_=a.map(k_),E=[];return m.forEach((function(C,O){return Pae(0,g.domain().length).forEach((function(j){var T,k,A,P=A_(a[j][C]),M=P[0],D=P[1],I=l(a[j]),L=((T=g(I))!=null?T:0)+t*O+p*O,F=S(k=D,0)?(A=x(k))!=null?A:0:r,q=(function($,H){var z;return S($,0)?r-H:((z=x($))!=null?z:0)-r})(D,F),U={id:C,value:M===null?M:D,formattedValue:i(D),hidden:!1,index:j,indexValue:I,data:_[j]};E.push({key:C+"."+U.indexValue,index:E.length,data:U,x:L,y:F,absX:w.left+L,absY:w.top+F,width:t,height:q,color:s(U),label:d(U)})}))})),E},"pe"),y9e=o(function(e,t,n,r){var a=e.data,i=e.formatValue,s=e.getIndex,l=e.getColor,d=e.getTooltipLabel,c=e.keys,p=e.innerPadding,m=p===void 0?0:p,g=e.xScale,x=e.yScale,w=e.margin,S=n?Tae:v3,_=a.map(k_),E=[];return c.forEach((function(C,O){return Pae(0,x.domain().length).forEach((function(j){var T,k,A,P=A_(a[j][C]),M=P[0],D=P[1],I=s(a[j]),L=S(k=D,0)?r:(A=g(k))!=null?A:0,F=((T=x(I))!=null?T:0)+t*O+m*O,q=(function($,H){var z;return S($,0)?((z=g($))!=null?z:0)-r:r-H})(D,L),U={id:C,value:M===null?M:D,formattedValue:i(D),hidden:!1,index:j,indexValue:I,data:_[j]};E.push({key:C+"."+U.indexValue,index:E.length,data:U,x:L,y:F,absX:w.left+L,absY:w.top+F,width:q,height:t,color:l(U),label:d(U)})}))})),E},"ye"),b9e=o(function(e){var t,n,r,a=e.layout,i=e.width,s=e.height,l=e.padding,d=l===void 0?0:l,c=e.innerPadding,p=c===void 0?0:c,m=e.valueScale,g=e.indexScale,x=e.hiddenIds,w=x===void 0?[]:x,S=Rc(e,m9e),_=S.keys.filter((function(H){return!w.includes(H)})),E=kae(S.data,_),C=a==="vertical"?["y","x",i]:["x","y",s],O=C[0],j=C[1],T=C[2],k=Rae(E,S.getIndex,d,g,T,j),A=m.min==="auto"?v9e:function(H){return H},P=E.reduce((function(H,z){return[].concat(H,_.map((function(W){return z[W]})))}),[]).filter(Boolean),M=A(Math.min.apply(Math,P)),D=(r=Math.max.apply(Math,P),isFinite(r)?r:0),I=p3(m,{all:P,min:M,max:D},O==="x"?i:s,O),L=a==="vertical"?[k,I]:[I,k],F=L[0],q=L[1],U=(k.bandwidth()-p*(_.length-1))/_.length,$=[pn({},S,{data:E,keys:_,innerPadding:p,xScale:F,yScale:q}),U,(t=m.reverse)!=null&&t,(n=I(0))!=null?n:0];return{xScale:F,yScale:q,bars:U>0?a==="vertical"?g9e.apply(void 0,$):y9e.apply(void 0,$):[]}},"xe"),x9e=["data","layout","width","height","padding","valueScale","indexScale","hiddenIds"],Nae=o(function(e){var t;return e.some(Array.isArray)?Nae((t=[]).concat.apply(t,e)):e},"ke"),w9e=o(function(e,t,n){var r=e.formatValue,a=e.getColor,i=e.getIndex,s=e.getTooltipLabel,l=e.innerPadding,d=e.stackedData,c=e.xScale,p=e.yScale,m=e.margin,g=[];return d.forEach((function(x){return c.domain().forEach((function(w,S){var _,E,C=x[S],O=(_=c(i(C.data)))!=null?_:0,j=((E=(function(D){return p(D[n?0:1])})(C))!=null?E:0)+.5*l,T=(function(D,I){var L;return((L=p(D[n?1:0]))!=null?L:0)-I})(C,j)-l,k=A_(C.data[x.key]),A=k[0],P=k[1],M={id:x.key,value:A===null?A:P,formattedValue:r(P),hidden:!1,index:S,indexValue:w,data:k_(C.data)};g.push({key:x.key+"."+w,index:g.length,data:M,x:O,y:j,absX:m.left+O,absY:m.top+j,width:t,height:T,color:a(M),label:s(M)})}))})),g},"we"),_9e=o(function(e,t,n){var r=e.formatValue,a=e.getColor,i=e.getIndex,s=e.getTooltipLabel,l=e.innerPadding,d=e.stackedData,c=e.xScale,p=e.yScale,m=e.margin,g=[];return d.forEach((function(x){return p.domain().forEach((function(w,S){var _,E,C=x[S],O=(_=p(i(C.data)))!=null?_:0,j=((E=(function(D){return c(D[n?1:0])})(C))!=null?E:0)+.5*l,T=(function(D,I){var L;return((L=c(D[n?0:1]))!=null?L:0)-I})(C,j)-l,k=A_(C.data[x.key]),A=k[0],P=k[1],M={id:x.key,value:A===null?A:P,formattedValue:r(P),hidden:!1,index:S,indexValue:w,data:k_(C.data)};g.push({key:x.key+"."+w,index:g.length,data:M,x:j,y:O,absX:m.left+j,absY:m.top+O,width:T,height:t,color:a(M),label:s(M)})}))})),g},"Le"),S9e=o(function(e){var t,n,r=e.data,a=e.layout,i=e.width,s=e.height,l=e.padding,d=l===void 0?0:l,c=e.valueScale,p=e.indexScale,m=e.hiddenIds,g=m===void 0?[]:m,x=Rc(e,x9e),w=x.keys.filter((function(U){return!g.includes(U)})),S=G8e().keys(w).offset(Y8e)(kae(r,w)),_=a==="vertical"?["y","x",i]:["x","y",s],E=_[0],C=_[1],O=_[2],j=Rae(r,x.getIndex,d,p,O,C),T=(n=Nae(S),c.type==="log"?n.filter((function(U){return U!==0})):n),k=Math.min.apply(Math,T),A=Math.max.apply(Math,T),P=p3(c,{all:T,min:k,max:A},E==="x"?i:s,E),M=a==="vertical"?[j,P]:[P,j],D=M[0],I=M[1],L=x.innerPadding>0?x.innerPadding:0,F=j.bandwidth(),q=[pn({},x,{innerPadding:L,stackedData:S,xScale:D,yScale:I}),F,(t=c.reverse)!=null&&t];return{xScale:D,yScale:I,bars:F>0?a==="vertical"?w9e.apply(void 0,q):_9e.apply(void 0,q):[]}},"Ce"),E9e=o(function(e){var t=e.bars,n=e.direction,r=e.from,a=e.groupMode,i=e.layout,s=e.legendLabel,l=e.reverse,d=fae(s??(r==="indexes"?"indexValue":"id"));return r==="indexes"?(function(c,p,m){var g=gV(c.map((function(x){var w,S;return{id:(w=x.data.indexValue)!=null?w:"",label:m(x.data),hidden:x.data.hidden,color:(S=x.color)!=null?S:"#000"}})),(function(x){return x.id}));return p==="horizontal"&&g.reverse(),g})(t,i,d):(function(c,p,m,g,x,w){var S=gV(c.map((function(_){var E;return{id:_.data.id,label:w(_.data),hidden:_.data.hidden,color:(E=_.color)!=null?E:"#000"}})),(function(_){return _.id}));return(p==="vertical"&&g==="stacked"&&m==="column"&&x!==!0||p==="horizontal"&&g==="stacked"&&x===!0)&&S.reverse(),S})(t,i,n,a,l,d)},"We"),VV=o(function(e,t,n){var r=e.get(t)||0;e.set(t,r+n)},"Me"),C9e=o(function(e,t,n){var r=e.get(t)||0;e.set(t,r+(n>0?n:0))},"Be"),j9e=o(function(e,t,n){var r=e.get(t)||0;e.set(t,Math.max(r,Number(n)))},"Re"),O9e=o(function(e,t){var n=e.get(t)||0;e.set(t,n+1)},"Oe"),Mae=o(function(e){var t,n=e.indexBy,r=n===void 0?Mn.indexBy:n,a=e.keys,i=a===void 0?Mn.keys:a,s=e.label,l=s===void 0?Mn.label:s,d=e.tooltipLabel,c=d===void 0?Mn.tooltipLabel:d,p=e.valueFormat,m=e.colors,g=m===void 0?Mn.colors:m,x=e.colorBy,w=x===void 0?Mn.colorBy:x,S=e.borderColor,_=S===void 0?Mn.borderColor:S,E=e.labelTextColor,C=E===void 0?Mn.labelTextColor:E,O=e.groupMode,j=O===void 0?Mn.groupMode:O,T=e.layout,k=T===void 0?Mn.layout:T,A=e.data,P=e.margin,M=e.width,D=e.height,I=e.padding,L=I===void 0?Mn.padding:I,F=e.innerPadding,q=F===void 0?Mn.innerPadding:F,U=e.valueScale,$=U===void 0?Mn.valueScale:U,H=e.indexScale,z=H===void 0?Mn.indexScale:H,W=e.initialHiddenIds,V=W===void 0?Mn.initialHiddenIds:W,Q=e.enableLabel,K=Q===void 0?Mn.enableLabel:Q,Y=e.labelSkipWidth,ee=Y===void 0?Mn.labelSkipWidth:Y,te=e.labelSkipHeight,oe=te===void 0?Mn.labelSkipHeight:te,ne=e.legends,fe=ne===void 0?Mn.legends:ne,re=e.legendLabel,ce=e.totalsOffset,he=ce===void 0?Mn.totalsOffset:ce,J=y.useState(V??[]),De=J[0],we=J[1],Ce=y.useCallback((function(We){we((function(pt){return pt.indexOf(We)>-1?pt.filter((function(ge){return ge!==We})):[].concat(pt,[We])}))}),[]),ke=jA(r),Re=jA(l),Pe=jA(c),ze=h3(p),X=Tr(),se=Q$e(g,w),me=BV(_,X),Te=BV(C,X),de=(j==="grouped"?b9e:S9e)({layout:k,data:A,getIndex:ke,keys:i,width:M,height:D,getColor:se,padding:L,innerPadding:q,valueScale:$,indexScale:z,hiddenIds:De,formatValue:ze,getTooltipLabel:Pe,margin:P}),ue=de.bars,Ae=de.xScale,Ne=de.yScale,Le=y.useMemo((function(){return ue.filter((function(We){return We.data.value!==null})).map((function(We,pt){return pn({},We,{index:pt})}))}),[ue]),Ze=y.useCallback((function(We){var pt=We.width,ge=We.height;return!!K&&!(ee>0&&pt<ee)&&!(oe>0&&ge<oe)}),[K,ee,oe]),Pt=y.useMemo((function(){return i.map((function(We){var pt=ue.find((function(ge){return ge.data.id===We}));return pn({},pt,{data:pn({id:We},pt?.data,{hidden:De.includes(We)})})}))}),[De,i,ue]),$t=(t=$.reverse)!=null&&t,kt=y.useMemo((function(){return fe.map((function(We){return[We,E9e({bars:We.dataFrom==="keys"?Pt:ue,direction:We.direction,from:We.dataFrom,groupMode:j,layout:k,legendLabel:re,reverse:$t})]}))}),[fe,Pt,ue,j,k,re,$t]),qt=y.useMemo((function(){return(function(We,pt,ge,ye,ct,Fe,Qe){ye===void 0&&(ye=Mn.layout),ct===void 0&&(ct=Mn.groupMode);var Ve=[];if(We.length===0)return Ve;var Je=new Map,Et=We[0].width,Ye=We[0].height;if(ct==="stacked"){var mt=new Map;We.forEach((function(At){var _t=At.data,vt=_t.indexValue,jt=_t.value;VV(Je,vt,Number(jt)),C9e(mt,vt,Number(jt))})),mt.forEach((function(At,_t){var vt,jt,Z,pe=Je.get(_t)||0;ye==="vertical"?(vt=pt(_t),jt=ge(At),Z=ge(At/2)):(vt=pt(At),jt=ge(_t),Z=pt(At/2)),vt+=ye==="vertical"?Et/2:Fe,jt+=ye==="vertical"?-Fe:Ye/2,Ve.push({key:"total_"+_t,x:vt,y:jt,value:pe,formattedValue:Qe(pe),animationOffset:Z})}))}else if(ct==="grouped"){var Lt=new Map,Nt=new Map;We.forEach((function(At){var _t=At.data,vt=_t.indexValue,jt=_t.value;VV(Je,vt,Number(jt)),j9e(Lt,vt,Number(jt)),O9e(Nt,vt)})),Lt.forEach((function(At,_t){var vt,jt,Z,pe=Je.get(_t)||0,_e=Nt.get(_t);ye==="vertical"?(vt=pt(_t),jt=ge(At),Z=ge(At/2)):(vt=pt(At),jt=ge(_t),Z=pt(At/2)),vt+=ye==="vertical"?_e*Et/2:Fe,jt+=ye==="vertical"?-Fe:_e*Ye/2,Ve.push({key:"total_"+_t,x:vt,y:jt,value:pe,formattedValue:Qe(pe),animationOffset:Z})}))}return Ve})(ue,Ae,Ne,k,j,he,ze)}),[ue,Ae,Ne,k,j,he,ze]);return{bars:ue,barsWithValue:Le,xScale:Ae,yScale:Ne,getIndex:ke,getLabel:Re,getTooltipLabel:Pe,formatValue:ze,getColor:se,getBorderColor:me,getLabelColor:Te,shouldRenderBarLabel:Ze,hiddenIds:De,toggleSerie:Ce,legendsWithData:kt,barTotals:qt}},"Ie"),R9e=o(function(e){var t=e.data,n=e.springConfig,r=e.animate,a=e.layout,i=a===void 0?Nn.layout:a,s=Tr();return H1(t,{keys:o(function(l){return l.key},"keys"),from:o(function(l){return{x:i==="vertical"?l.x:l.animationOffset,y:i==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"from"),enter:o(function(l){return{x:l.x,y:l.y,labelOpacity:1}},"enter"),update:o(function(l){return{x:l.x,y:l.y,labelOpacity:1}},"update"),leave:o(function(l){return{x:i==="vertical"?l.x:l.animationOffset,y:i==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"leave"),config:n,immediate:!r,initial:r?void 0:null})((function(l,d){return h.jsx(ur.text,{x:l.x,y:l.y,fillOpacity:l.labelOpacity,style:pn({},s.labels.text,{pointerEvents:"none"}),fontWeight:"bold",fontSize:s.labels.text.fontSize,fontFamily:s.labels.text.fontFamily,textAnchor:i==="vertical"?"middle":"start",alignmentBaseline:i==="vertical"?"alphabetic":"middle",children:d.formattedValue},d.key)}))},"Ve"),k9e=["isInteractive","animate","motionConfig","theme","renderWrapper"],A9e=o(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,i=e.margin,s=e.width,l=e.height,d=e.groupMode,c=e.layout,p=e.valueScale,m=e.indexScale,g=e.padding,x=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,E=_===void 0?Nn.axisBottom:_,C=e.axisLeft,O=C===void 0?Nn.axisLeft:C,j=e.enableGridX,T=j===void 0?Nn.enableGridX:j,k=e.enableGridY,A=k===void 0?Nn.enableGridY:k,P=e.gridXValues,M=e.gridYValues,D=e.layers,I=D===void 0?Nn.layers:D,L=e.barComponent,F=L===void 0?Nn.barComponent:L,q=e.enableLabel,U=q===void 0?Nn.enableLabel:q,$=e.label,H=e.labelSkipWidth,z=H===void 0?Nn.labelSkipWidth:H,W=e.labelSkipHeight,V=W===void 0?Nn.labelSkipHeight:W,Q=e.labelTextColor,K=e.labelPosition,Y=K===void 0?Nn.labelPosition:K,ee=e.labelOffset,te=ee===void 0?Nn.labelOffset:ee,oe=e.markers,ne=oe===void 0?Nn.markers:oe,fe=e.colorBy,re=e.colors,ce=e.defs,he=ce===void 0?Nn.defs:ce,J=e.fill,De=J===void 0?Nn.fill:J,we=e.borderRadius,Ce=we===void 0?Nn.borderRadius:we,ke=e.borderWidth,Re=ke===void 0?Nn.borderWidth:ke,Pe=e.borderColor,ze=e.annotations,X=ze===void 0?Nn.annotations:ze,se=e.legendLabel,me=e.tooltipLabel,Te=e.valueFormat,de=e.isInteractive,ue=de===void 0?Nn.isInteractive:de,Ae=e.tooltip,Ne=Ae===void 0?Nn.tooltip:Ae,Le=e.onClick,Ze=e.onMouseEnter,Pt=e.onMouseLeave,$t=e.legends,kt=e.role,qt=kt===void 0?Nn.role:kt,We=e.ariaLabel,pt=e.ariaLabelledBy,ge=e.ariaDescribedBy,ye=e.isFocusable,ct=ye===void 0?Nn.isFocusable:ye,Fe=e.barAriaLabel,Qe=e.barAriaLabelledBy,Ve=e.barAriaDescribedBy,Je=e.barAriaHidden,Et=e.barAriaDisabled,Ye=e.initialHiddenIds,mt=e.enableTotals,Lt=mt===void 0?Nn.enableTotals:mt,Nt=e.totalsOffset,At=Nt===void 0?Nn.totalsOffset:Nt,_t=e.forwardedRef,vt=lo(),jt=vt.animate,Z=vt.config,pe=dae(s,l,i),_e=pe.outerWidth,$e=pe.outerHeight,Be=pe.margin,rt=pe.innerWidth,nt=pe.innerHeight,Ke=Mae({indexBy:r,label:$,tooltipLabel:me,valueFormat:Te,colors:re,colorBy:fe,borderColor:Pe,labelTextColor:Q,groupMode:d,layout:c,data:n,keys:a,margin:Be,width:rt,height:nt,padding:g,innerPadding:x,valueScale:p,indexScale:m,enableLabel:U,labelSkipWidth:z,labelSkipHeight:V,legends:$t,legendLabel:se,initialHiddenIds:Ye,totalsOffset:At}),ot=Ke.bars,ut=Ke.barsWithValue,st=Ke.xScale,lt=Ke.yScale,gt=Ke.getLabel,at=Ke.getTooltipLabel,Rt=Ke.getBorderColor,bt=Ke.getLabelColor,Ft=Ke.shouldRenderBarLabel,Dt=Ke.toggleSerie,Nr=Ke.legendsWithData,ba=Ke.barTotals,ni=Ke.getColor,ar=Aae(c,(t=p?.reverse)!=null&&t,Y,te),co=H1(ut,{keys:o(function(He){return He.key},"keys"),from:o(function(He){return pn({borderColor:Rt(He),color:He.color,height:0,labelColor:bt(He),labelOpacity:0},ar(He.width,He.height),{transform:"translate("+He.x+", "+(He.y+He.height)+")",width:He.width},c==="vertical"?{}:{height:He.height,transform:"translate("+He.x+", "+He.y+")",width:0})},"from"),enter:o(function(He){return pn({borderColor:Rt(He),color:He.color,height:He.height,labelColor:bt(He),labelOpacity:1},ar(He.width,He.height),{transform:"translate("+He.x+", "+He.y+")",width:He.width})},"enter"),update:o(function(He){return pn({borderColor:Rt(He),color:He.color,height:He.height,labelColor:bt(He),labelOpacity:1},ar(He.width,He.height),{transform:"translate("+He.x+", "+He.y+")",width:He.width})},"update"),leave:o(function(He){return pn({borderColor:Rt(He),color:He.color,height:0,labelColor:bt(He),labelOpacity:0},ar(He.width,He.height),{labelY:0,transform:"translate("+He.x+", "+(He.y+He.height)+")",width:He.width},c==="vertical"?{}:pn({},ar(He.width,He.height),{labelX:0,height:He.height,transform:"translate("+He.x+", "+He.y+")",width:0}))},"leave"),config:Z,immediate:!jt,initial:jt?void 0:null}),Mr=y.useMemo((function(){return{borderRadius:Ce,borderWidth:Re,enableLabel:U,isInteractive:ue,labelSkipWidth:z,labelSkipHeight:V,onClick:Le,onMouseEnter:Ze,onMouseLeave:Pt,getTooltipLabel:at,tooltip:Ne,isFocusable:ct,ariaLabel:Fe,ariaLabelledBy:Qe,ariaDescribedBy:Ve,ariaHidden:Je,ariaDisabled:Et}}),[Ce,Re,U,at,ue,V,z,Le,Ze,Pt,Ne,ct,Fe,Qe,Ve,Je,Et]),La=O7e(he,ot,De,{dataKey:"data",targetKey:"data.fill"}),Hr={annotations:null,axes:null,bars:null,grid:null,legends:null,markers:null,totals:null};I.includes("annotations")&&(Hr.annotations=h.jsx(c9e,{bars:ot,annotations:X},"annotations")),I.includes("axes")&&(Hr.axes=h.jsx(s$e,{xScale:st,yScale:lt,width:rt,height:nt,top:w,right:S,bottom:E,left:O},"axes")),I.includes("bars")&&(Hr.bars=h.jsx(y.Fragment,{children:co((function(He,In){return y.createElement(F,pn({},Mr,{bar:In,style:He,shouldRenderLabel:Ft(In),label:gt(In.data)}))}))},"bars")),I.includes("grid")&&(Hr.grid=h.jsx(c$e,{width:rt,height:nt,xScale:T?st:null,yScale:A?lt:null,xValues:P,yValues:M},"grid")),I.includes("legends")&&(Hr.legends=h.jsx(u9e,{width:rt,height:nt,legends:Nr,toggleSerie:Dt},"legends")),I.includes("markers")&&(Hr.markers=h.jsx(g7e,{markers:ne,width:rt,height:nt,xScale:st,yScale:lt},"markers")),I.includes("totals")&&Lt&&(Hr.totals=h.jsx(R9e,{data:ba,springConfig:Z,animate:jt,layout:c},"totals"));var Fa=pn({},Mr,{margin:Be,width:s,height:l,innerWidth:rt,innerHeight:nt,bars:ot,legendData:Nr,enableLabel:U,xScale:st,yScale:lt,tooltip:Ne,getTooltipLabel:at,onClick:Le,onMouseEnter:Ze,onMouseLeave:Pt,getColor:ni});return h.jsx(p7e,{width:_e,height:$e,margin:Be,defs:La,role:qt,ariaLabel:We,ariaLabelledBy:pt,ariaDescribedBy:ge,isFocusable:ct,ref:_t,children:I.map((function(He,In){var Pi;return typeof He=="function"?h.jsx(y.Fragment,{children:y.createElement(He,Fa)},In):(Pi=Hr?.[He])!=null?Pi:null}))})},"He"),T9e=y.forwardRef((function(e,t){var n=e.isInteractive,r=n===void 0?Nn.isInteractive:n,a=e.animate,i=a===void 0?Nn.animate:a,s=e.motionConfig,l=s===void 0?Nn.motionConfig:s,d=e.theme,c=e.renderWrapper,p=Rc(e,k9e);return h.jsx(oae,{animate:i,isInteractive:r,motionConfig:l,renderWrapper:c,theme:d,children:h.jsx(A9e,pn({},p,{isInteractive:r,forwardedRef:t}))})})),P9e=["isInteractive","renderWrapper","theme"],QA=o(function(e,t,n,r){return e.find((function(a){return S7e(a.x+t.left,a.y+t.top,a.width,a.height,n,r)}))},"Fe"),N9e=o(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,i=e.margin,s=e.width,l=e.height,d=e.groupMode,c=e.layout,p=e.valueScale,m=e.indexScale,g=e.padding,x=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,E=_===void 0?pr.axisBottom:_,C=e.axisLeft,O=C===void 0?pr.axisLeft:C,j=e.enableGridX,T=j===void 0?pr.enableGridX:j,k=e.enableGridY,A=k===void 0?pr.enableGridY:k,P=e.gridXValues,M=e.gridYValues,D=e.labelPosition,I=D===void 0?pr.labelPosition:D,L=e.labelOffset,F=L===void 0?pr.labelOffset:L,q=e.layers,U=q===void 0?pr.layers:q,$=e.renderBar,H=$===void 0?pr.renderBar:$,z=e.enableLabel,W=z===void 0?pr.enableLabel:z,V=e.label,Q=e.labelSkipWidth,K=Q===void 0?pr.labelSkipWidth:Q,Y=e.labelSkipHeight,ee=Y===void 0?pr.labelSkipHeight:Y,te=e.labelTextColor,oe=e.colorBy,ne=e.colors,fe=e.borderRadius,re=fe===void 0?pr.borderRadius:fe,ce=e.borderWidth,he=ce===void 0?pr.borderWidth:ce,J=e.borderColor,De=e.annotations,we=De===void 0?pr.annotations:De,Ce=e.legendLabel,ke=e.tooltipLabel,Re=e.valueFormat,Pe=e.isInteractive,ze=Pe===void 0?pr.isInteractive:Pe,X=e.tooltip,se=X===void 0?pr.tooltip:X,me=e.onClick,Te=e.onMouseEnter,de=e.onMouseLeave,ue=e.legends,Ae=e.pixelRatio,Ne=Ae===void 0?pr.pixelRatio:Ae,Le=e.role,Ze=e.forwardedRef,Pt=e.enableTotals,$t=Pt===void 0?pr.enableTotals:Pt,kt=e.totalsOffset,qt=kt===void 0?pr.totalsOffset:kt,We=y.useRef(null),pt=Tr(),ge=dae(s,l,i),ye=ge.margin,ct=ge.innerWidth,Fe=ge.innerHeight,Qe=ge.outerWidth,Ve=ge.outerHeight,Je=Mae({indexBy:r,label:V,tooltipLabel:ke,valueFormat:Re,colors:ne,colorBy:oe,borderColor:J,labelTextColor:te,groupMode:d,layout:c,data:n,keys:a,margin:ye,width:ct,height:Fe,padding:g,innerPadding:x,valueScale:p,indexScale:m,enableLabel:W,labelSkipWidth:K,labelSkipHeight:ee,legends:ue,legendLabel:Ce,totalsOffset:qt}),Et=Je.bars,Ye=Je.barsWithValue,mt=Je.xScale,Lt=Je.yScale,Nt=Je.getLabel,At=Je.getTooltipLabel,_t=Je.getBorderColor,vt=Je.getLabelColor,jt=Je.shouldRenderBarLabel,Z=Je.legendsWithData,pe=Je.barTotals,_e=Je.getColor,$e=tre(),Be=$e.showTooltipFromEvent,rt=$e.hideTooltip,nt=R$e({annotations:_ae({data:Et,annotations:we,getPosition:o(function(at){return{x:at.x,y:at.y}},"getPosition"),getDimensions:o(function(at){var Rt=at.width,bt=at.height;return{width:Rt,height:bt,size:Math.max(Rt,bt)}},"getDimensions")})}),Ke=y.useMemo((function(){return{borderRadius:re,borderWidth:he,isInteractive:ze,isFocusable:!1,labelSkipWidth:K,labelSkipHeight:ee,margin:ye,width:s,height:l,innerWidth:ct,innerHeight:Fe,bars:Et,legendData:Z,enableLabel:W,xScale:mt,yScale:Lt,tooltip:se,getTooltipLabel:At,onClick:me,onMouseEnter:Te,onMouseLeave:de,getColor:_e}}),[re,he,ze,K,ee,ye,s,l,ct,Fe,Et,Z,W,mt,Lt,se,At,me,Te,de,_e]),ot=h3(Re),ut=Aae(c,(t=p?.reverse)!=null&&t,I,F);y.useEffect((function(){if(We.current){We.current.width=Qe*Ne,We.current.height=Ve*Ne;var at=We.current.getContext("2d");at.scale(Ne,Ne),at.fillStyle=pt.background,at.fillRect(0,0,Qe,Ve),at.translate(ye.left,ye.top),U.forEach((function(Rt){Rt==="grid"?typeof pt.grid.line.strokeWidth=="number"&&pt.grid.line.strokeWidth>0&&(at.lineWidth=pt.grid.line.strokeWidth,at.strokeStyle=pt.grid.line.stroke,T&&AV(at,{width:ct,height:Fe,scale:mt,axis:"x",values:P}),A&&AV(at,{width:ct,height:Fe,scale:Lt,axis:"y",values:M})):Rt==="axes"?d$e(at,{xScale:mt,yScale:Lt,width:ct,height:Fe,top:w,right:S,bottom:E,left:O,theme:pt}):Rt==="bars"?(wg(at,pt.text),Ye.forEach((function(bt){H(at,pn({bar:bt,borderColor:_t(bt),borderRadius:re,borderWidth:he,label:Nt(bt.data),shouldRenderLabel:jt(bt),labelStyle:pn({},pt.labels.text,{fill:vt(bt)})},ut(bt.width,bt.height)))}))):Rt==="legends"?Z.forEach((function(bt){var Ft=bt[0],Dt=bt[1];s9e(at,pn({},Ft,{data:Dt,containerWidth:ct,containerHeight:Fe,theme:pt}))})):Rt==="annotations"?D$e(at,{annotations:nt,theme:pt}):Rt==="totals"&&$t?(function(bt,Ft,Dt,Nr){Nr===void 0&&(Nr=pr.layout),wg(bt,Dt.labels.text),bt.textBaseline=Nr==="vertical"?"alphabetic":"middle",bt.textAlign=Nr==="vertical"?"center":"start",Ft.forEach((function(ba){_g(bt,Dt.labels.text,ba.formattedValue,ba.x,ba.y)}))})(at,pe,pt,c):typeof Rt=="function"&&Rt(at,Ke)})),at.save()}}),[E,O,S,w,Ye,re,he,nt,T,A,_t,Nt,vt,P,M,d,l,Fe,ct,Ke,U,c,Z,ye.left,ye.top,Ve,Qe,Ne,H,mt,Lt,jt,pt,s,pe,$t,ot,ut]);var st=y.useCallback((function(at){if(Et&&We.current){var Rt=OA(We.current,at),bt=Rt[0],Ft=Rt[1],Dt=QA(Et,ye,bt,Ft);Dt!==void 0?(Be(y.createElement(se,pn({},Dt.data,{color:Dt.color,label:Dt.label,value:Number(Dt.data.value)})),at),at.type==="mouseenter"&&Te?.(Dt.data,at)):rt()}}),[rt,ye,Te,Et,Be,se]),lt=y.useCallback((function(at){if(Et&&We.current){rt();var Rt=OA(We.current,at),bt=Rt[0],Ft=Rt[1],Dt=QA(Et,ye,bt,Ft);Dt&&de?.(Dt.data,at)}}),[rt,ye,de,Et]),gt=y.useCallback((function(at){if(Et&&We.current){var Rt=OA(We.current,at),bt=Rt[0],Ft=Rt[1],Dt=QA(Et,ye,bt,Ft);Dt!==void 0&&me?.(pn({},Dt.data,{color:Dt.color}),at)}}),[ye,me,Et]);return h.jsx("canvas",{ref:R7e(We,Ze),width:Qe*Ne,height:Ve*Ne,style:{width:Qe,height:Ve,cursor:ze?"auto":"normal"},onMouseEnter:ze?st:void 0,onMouseMove:ze?st:void 0,onMouseLeave:ze?lt:void 0,onClick:ze?gt:void 0,role:Le})},"ze"),M9e=y.forwardRef((function(e,t){var n=e.isInteractive,r=e.renderWrapper,a=e.theme,i=Rc(e,P9e);return h.jsx(oae,{isInteractive:n,renderWrapper:r,theme:a,animate:!1,children:h.jsx(N9e,pn({},i,{isInteractive:n,forwardedRef:t}))})})),D9e=["defaultWidth","defaultHeight","onResize","debounceResize"],I9e=y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,i=e.debounceResize,s=Rc(e,D9e);return h.jsx(sae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:i,children:o(function(l){var d=l.width,c=l.height;return h.jsx(T9e,pn({},s,{width:d,height:c,ref:t}))},"children")})})),L9e=["defaultWidth","defaultHeight","onResize","debounceResize"];y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,i=e.debounceResize,s=Rc(e,L9e);return h.jsx(sae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:i,children:o(function(l){var d=l.width,c=l.height;return h.jsx(M9e,pn({},s,{width:d,height:c,ref:t}))},"children")})}));const F9e={opportunity:.2,"proposal-sent":.5,"in-negociation":.8,delayed:.3},$9e=new Date(new Date().setMonth(new Date().getMonth()-6)).toISOString(),WV="en-US",q9e="USD",z9e=y.memo(()=>{const e=navigator?navigator.languages||[navigator.language]:[WV],{data:t,isPending:n}=Xa("deals",{pagination:{perPage:100,page:1},sort:{field:"created_at",order:"ASC"},filter:{"created_at@gte":$9e}}),r=y.useMemo(()=>{if(!t)return[];const i=t.reduce((l,d)=>{const c=GT(d.created_at??new Date).toISOString();return l[c]||(l[c]=[]),l[c].push(d),l},{});return Object.keys(i).map(l=>({date:SK(l,"MMM"),won:i[l].filter(d=>d.stage==="won").reduce((d,c)=>(d+=c.amount,d),0),pending:i[l].filter(d=>!["won","lost"].includes(d.stage)).reduce((d,c)=>(d+=c.amount*F9e[c.stage],d),0),lost:i[l].filter(d=>d.stage==="lost").reduce((d,c)=>(d-=c.amount,d),0)}))},[t]);if(n)return null;const a=r.reduce((i,s)=>(i.min=Math.min(i.min,s.lost),i.max=Math.max(i.max,s.won+s.pending),i),{min:0,max:0});return h.jsxs("div",{className:"flex flex-col",children:[h.jsxs("div",{className:"flex items-center mb-4",children:[h.jsx("div",{className:"mr-3 flex",children:h.jsx(rQ,{className:"text-muted-foreground w-6 h-6"})}),h.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Upcoming Deal Revenue"})]}),h.jsx("div",{className:"h-[400px]",children:h.jsx(I9e,{data:r,indexBy:"date",keys:["won","pending","lost"],colors:["#61cdbb","#97e3d5","#e25c3b"],margin:{top:30,right:50,bottom:30,left:0},padding:.3,valueScale:{type:"linear",min:a.min*1.2,max:a.max*1.2},indexScale:{type:"band",round:!0},enableGridX:!0,enableGridY:!1,enableLabel:!1,tooltip:o(({value:i,indexValue:s})=>h.jsxs("div",{className:"p-2 bg-secondary rounded shadow inline-flex items-center gap-1 text-secondary-foreground",children:[h.jsxs("strong",{children:[s,": "]})," ",i>0?"+":"",i.toLocaleString(e.at(0)??WV,{style:"currency",currency:q9e})]}),"tooltip"),axisTop:{tickSize:0,tickPadding:12,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},axisBottom:{legendPosition:"middle",legendOffset:50,tickSize:0,tickPadding:12,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},axisLeft:null,axisRight:{format:o(i=>`${Math.abs(i/1e3)}k`,"format"),tickValues:8,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},markers:[{axis:"y",value:0,lineStyle:{strokeOpacity:0},textStyle:{fill:"#2ebca6"},legend:"Won",legendPosition:"top-left",legendOrientation:"vertical"},{axis:"y",value:0,lineStyle:{stroke:"#f47560",strokeWidth:1},textStyle:{fill:"#e25c3b"},legend:"Lost",legendPosition:"bottom-left",legendOrientation:"vertical"}]})})]})}),U9e=o(e=>{const t=xt(),n=Ht(e),{filterValues:r,setFilters:a}=_w(e),i=td();if(!n)throw new Error("<ListNoResults> must be used inside a <List> component");return h.jsx("div",{className:"p-6",children:h.jsx("p",{className:"text-sm text-muted-foreground",children:r&&a&&Object.keys(r).length>0?h.jsxs(h.Fragment,{children:[t("ra.navigation.no_filtered_results",{resource:n,name:i(n,0),_:"No results found with the current filters."})," ",h.jsx(Ge,{variant:"outline",size:"sm",onClick:o(()=>a({},[]),"onClick"),children:t("ra.navigation.clear_filters",{_:"Clear filters"})})]}):t("ra.navigation.no_results",{resource:n,name:i(n,0),_:"No results found."})})})},"ListNoResults"),B9e=o(e=>{const{children:t,linkType:n,rowClick:r,style:a}=e,i=Ht(e),s=Vt(e),l=pa(),d=typeof n=="function"||typeof r=="function",c=OG({link:d?!1:n??r,resource:i}),p=AG(),m=Ct(async()=>{if(!d||!s)return;const g=typeof n=="function"?n(s,s.id):typeof r=="function"?(w,S)=>r(w.id,S,w):!1,x=await p({record:s,resource:i,link:g});x===!1||x==null||l(x)});return s?d?h.jsx("li",{className:"w-full",children:h.jsx("button",{onClick:m,style:a,className:"w-full text-left hover:bg-muted focus: bg-muted focus:outline-none",children:t})}):c?h.jsx("li",{className:"w-full",children:h.jsx(xn,{to:c,style:a,className:"block w-full hover:bg-muted focus:bg-muted focus:outline-none",children:t})}):h.jsx("li",{className:"w-full",children:t}):null},"SimpleListItem"),XA=o(({className:e})=>h.jsx("span",{className:Ee("bg-gray-300 flex",e),children:" "}),"ListPlaceholder"),H9e=o(e=>{const{className:t,hasLeftAvatarOrIcon:n,hasRightAvatarOrIcon:r,hasSecondaryText:a,hasTertiaryText:i,nbFakeLines:s=5,...l}=e;return oY(1e3)?h.jsx("ul",{className:t,...l,children:V9e(s,c=>h.jsxs("li",{className:"flex items-center space-x-3 p-3",children:[n&&h.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"mb-1",children:[h.jsx(XA,{className:"w-1/3 inline-block mb-1"}),i&&h.jsx("span",{className:"float-right opacity-55 min-w-[10vw]",children:h.jsx(XA,{})})]}),a&&h.jsx(XA,{className:"w-1/4"})]}),r&&h.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "})]},c))}):null},"SimpleListLoading"),V9e=o((e,t)=>Array.from({length:e},(n,r)=>t(r)),"times"),W9e=o(e=>{const{className:t,empty:n=Y9e,leftAvatar:r,leftIcon:a,linkType:i,rowClick:s,primaryText:l,rightAvatar:d,rightIcon:c,secondaryText:p,tertiaryText:m,resource:g,...x}=e,{data:w,isPending:S,total:_}=_w(e);return S===!0?h.jsx(H9e,{className:t,hasLeftAvatarOrIcon:!!a||!!r,hasRightAvatarOrIcon:!!c||!!d,hasSecondaryText:!!p,hasTertiaryText:!!m}):w==null||w.length===0||_===0?n||null:h.jsx("ul",{className:t,...Ape(x),children:h.jsx(Lpe,{data:w,total:_,render:o((E,C)=>h.jsx(B9e,{rowIndex:C,linkType:i,rowClick:s,resource:g,children:h.jsx(G9e,{leftAvatar:r,leftIcon:a,primaryText:l,rightAvatar:d,rightIcon:c,secondaryText:p,tertiaryText:m,rowIndex:C})},E.id),"render")})})},"SimpleList"),G9e=o(e=>{const{leftAvatar:t,leftIcon:n,primaryText:r,rightAvatar:a,rightIcon:i,secondaryText:s,tertiaryText:l}=e,d=Ht(e),c=Vt(e),p=gc(d),m=xt(),g=o((x,w)=>{const S=w(x,x.id);return typeof S=="string"&&(S.startsWith("http")||S.startsWith("data:"))?h.jsx("img",{src:S,alt:"",className:"w-10 h-10 rounded-full object-cover"}):h.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-sm",children:S})},"renderAvatar");return c?h.jsxs("div",{className:"flex items-center space-x-3 p-3",children:[n&&h.jsx("div",{className:"flex-shrink-0",children:n(c,c.id)}),t&&h.jsx("div",{className:"flex-shrink-0",children:g(c,t)}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("div",{className:"text-sm font-medium truncate",children:r?typeof r=="string"?m(r,{...c,_:r}):y.isValidElement(r)?r:r(c,c.id):p(c)}),!!l&&h.jsx("div",{className:"text-xs text-muted-foreground ml-2",children:typeof l=="string"?m(l,{...c,_:l}):y.isValidElement(l)?l:l(c,c.id)})]}),!!s&&h.jsx("div",{className:"text-sm text-muted-foreground truncate",children:typeof s=="string"?m(s,{...c,_:s}):y.isValidElement(s)?s:s(c,c.id)})]}),(a||i)&&h.jsxs("div",{className:"flex-shrink-0 flex items-center space-x-2",children:[a&&g(c,a),i&&i(c,c.id)]})]}):null},"SimpleListItemContent"),Y9e=h.jsx(U9e,{}),K9e=o(()=>{const{identity:e}=wr(),{data:t,total:n,isPending:r}=Xa("contacts",{pagination:{page:1,perPage:10},sort:{field:"last_seen",order:"DESC"},filter:{status:"hot",sales_id:e?.id}},{enabled:Number.isInteger(e?.id)});return h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsxs("div",{className:"flex items-center",children:[h.jsx("div",{className:"mr-3 flex",children:h.jsx(gD,{className:"text-muted-foreground w-6 h-6"})}),h.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Hot Contacts"}),h.jsx(ji,{children:h.jsxs(eo,{children:[h.jsx(to,{asChild:!0,children:h.jsx(Ge,{variant:"ghost",size:"sm",className:"ml-auto text-muted-foreground",asChild:!0,children:h.jsx(xn,{to:"/contacts/create",children:h.jsx($v,{className:"w-4 h-4 text-primary"})})})}),h.jsx(no,{children:"Create contact"})]})})]}),h.jsx(rr,{className:"py-0",children:h.jsx(W9e,{linkType:"show",data:t,total:n,isPending:r,resource:"contacts",className:"[&>li:first-child>a]:rounded-t-xl [&>li:last-child>a]:rounded-b-xl",primaryText:o(a=>`${a.first_name} ${a.last_name}`,"primaryText"),secondaryText:o(a=>h.jsxs(h.Fragment,{children:[a.title," at ",a.company_name]}),"secondaryText"),leftAvatar:o(a=>h.jsx(Qo,{record:a}),"leftAvatar"),empty:h.jsxs("div",{className:"p-4",children:[h.jsx("p",{className:"text-sm mb-4",children:'Contacts with a "hot" status will appear here.'}),h.jsx("p",{className:"text-sm",children:'Change the status of a contact by adding a note to that contact and clicking on "show options".'})]})})})]})},"HotContacts"),Q9e=o(()=>{const{identity:e}=wr(),{total:t}=Xa("tasks",{pagination:{page:1,perPage:1},filter:{sales_id:e?.id}},{enabled:!!e});return t?null:h.jsx("p",{className:"text-sm",children:"Tasks added to your contacts will appear here."})},"TasksListEmpty"),Zm=o(({title:e,filter:t})=>{const{identity:n}=wr(),{data:r,total:a,isPending:i}=Xa("tasks",{pagination:{page:1,perPage:100},sort:{field:"due_date",order:"ASC"},filter:{...t,sales_id:n?.id}},{enabled:!!n}),s=Sw({data:r,isPending:i,resource:"tasks",perPage:5});return i||!r||!a?null:h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium mb-2",children:e}),h.jsx(ed,{value:"tasks",children:h.jsx(zg,{value:s,children:h.jsx(ine,{showContact:!0})})}),a>s.perPage&&h.jsx("div",{className:"flex justify-center",children:h.jsx("a",{href:"#",onClick:o(l=>{s.setPerPage(s.perPage+10),l.preventDefault()},"onClick"),className:"text-sm underline hover:no-underline",children:"Load more"})})]})},"TasksListFilter"),Dae=new Date,X9e=h0e(Dae),Z9e=X9e<5,GV=m0e().toISOString(),YV=hye().toISOString(),KV=pye().toISOString(),QV=fye(Dae,{weekStartsOn:0}).toISOString(),Jm={overdue:{"done_date@is":null,"due_date@lt":GV},today:{"done_date@is":null,"due_date@gte":GV,"due_date@lte":YV},tomorrow:{"done_date@is":null,"due_date@gt":YV,"due_date@lt":KV},thisWeek:{"done_date@is":null,"due_date@gte":KV,"due_date@lte":QV},later:{"done_date@is":null,"due_date@gt":QV}},J9e=o(()=>h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsxs("div",{className:"flex items-center",children:[h.jsx("div",{className:"mr-3 flex",children:h.jsx(lQ,{className:"text-muted-foreground w-6 h-6"})}),h.jsx("h2",{className:"text-xl font-semibold text-muted-foreground flex-1",children:"Upcoming Tasks"}),h.jsx(ane,{display:"icon",selectContact:!0})]}),h.jsx(rr,{className:"p-4 mb-2",children:h.jsxs("div",{className:"flex flex-col gap-4",children:[h.jsx(Q9e,{}),h.jsx(Zm,{title:"Overdue",filter:Jm.overdue}),h.jsx(Zm,{title:"Today",filter:Jm.today}),h.jsx(Zm,{title:"Tomorrow",filter:Jm.tomorrow}),Z9e&&h.jsx(Zm,{title:"This week",filter:Jm.thisWeek}),h.jsx(Zm,{title:"Later",filter:Jm.later})]})})]}),"TasksList"),eqe=o(()=>{const{data:e,total:t,isPending:n}=Xa("contacts",{pagination:{page:1,perPage:1}}),{total:r,isPending:a}=Xa("contactNotes",{pagination:{page:1,perPage:1}}),{total:i,isPending:s}=Xa("deals",{pagination:{page:1,perPage:1}});return n||a||s?null:t?r?h.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-6 mt-1",children:[h.jsx("div",{className:"md:col-span-3",children:h.jsxs("div",{className:"flex flex-col gap-4",children:[null,h.jsx(K9e,{})]})}),h.jsx("div",{className:"md:col-span-6",children:h.jsxs("div",{className:"flex flex-col gap-6",children:[i?h.jsx(z9e,{}):null,h.jsx(X3e,{})]})}),h.jsx("div",{className:"md:col-span-3",children:h.jsx(J9e,{})})]}):h.jsx(QB,{step:2,contactId:e?.[0]?.id}):h.jsx(QB,{step:1})},"Dashboard"),tqe=y.lazy(()=>jp(()=>import("./DealList-KrnFWRm0.js"),[],import.meta.url)),nqe={list:tqe},rqe=y.createContext(void 0),g3=o(()=>y.useContext(rqe),"useUserMenu"),aqe=o(()=>{const{darkModeLogo:e,lightModeLogo:t,title:n}=Ia(),r=Ar(),i=[{path:"/",pattern:"/"},{path:"/contacts",pattern:"/contacts/*"},{path:"/companies",pattern:"/companies/*"},{path:"/deals",pattern:"/deals/*"}].find(s=>Uh(s.pattern,r.pathname))?.path||!1;return h.jsx("header",{className:"bg-secondary fixed top-0 left-0 right-0 z-50 border-b border-border",children:h.jsx("div",{className:"px-4",children:h.jsxs("div",{className:"flex justify-between items-center flex-1",children:[h.jsx(iqe,{darkLogo:e,lightLogo:t,title:n}),h.jsxs("nav",{className:"flex","aria-label":"Main navigation",children:[h.jsx(ib,{label:"Dashboard",to:"/",isActive:i==="/"}),h.jsx(ib,{label:"Contacts",to:"/contacts",isActive:i==="/contacts"}),h.jsx(ib,{label:"Companies",to:"/companies",isActive:i==="/companies"}),h.jsx(ib,{label:"Deals",to:"/deals",isActive:i==="/deals"})]}),h.jsxs("div",{className:"flex items-center",children:[h.jsx(fZ,{}),h.jsx(hZ,{}),h.jsxs(cZ,{children:[h.jsx(sqe,{}),h.jsx(lqe,{}),h.jsx(Jve,{resource:"sales",action:"list",children:h.jsx(oqe,{})}),h.jsx(Vv,{}),h.jsx(WD,{className:"font-normal",children:h.jsxs("div",{className:"text-xs text-muted-foreground",children:["Version ","0.7.13"]})})]})]})]})})})},"Header"),iqe=o(({darkLogo:e,lightLogo:t,title:n})=>h.jsxs(xn,{to:"/",className:"flex items-center gap-2 text-secondary-foreground no-underline hover:opacity-80 transition-opacity",children:[h.jsx("img",{className:"[.light_&]:hidden h-6",src:e,alt:`${n} logo`}),h.jsx("img",{className:"[.dark_&]:hidden h-6",src:t,alt:`${n} logo`}),h.jsx("h1",{className:"text-xl font-semibold",children:n})]}),"Logo"),ib=o(({label:e,to:t,isActive:n})=>h.jsx(xn,{to:t,className:`px-6 py-3 text-sm font-medium transition-colors border-b-2 ${n?"text-secondary-foreground border-secondary-foreground":"text-secondary-foreground/70 border-transparent hover:text-secondary-foreground/80"}`,children:e}),"NavigationTab"),oqe=o(()=>{const{onClose:e}=g3()??{};return h.jsx(cr,{asChild:!0,onClick:e,children:h.jsxs(xn,{to:"/sales",className:"flex items-center gap-2",children:[h.jsx(l1e,{className:"h-4 w-4"}),"Users"]})})},"UsersMenu"),sqe=o(()=>{const{onClose:e}=g3()??{};return h.jsx(cr,{asChild:!0,onClick:e,children:h.jsxs(xn,{to:"/settings",className:"flex items-center gap-2",children:[h.jsx(QT,{className:"h-4 w-4"}),"My info"]})})},"ConfigurationMenu"),lqe=o(()=>{const{onClose:e}=g3()??{};return h.jsx(cr,{asChild:!0,onClick:e,children:h.jsxs(xn,{to:"/database",className:"flex items-center gap-2",children:[h.jsx(Fv,{className:"h-4 w-4"}),"Database"]})})},"DatabaseMenu"),cqe=o(({children:e})=>h.jsxs(h.Fragment,{children:[h.jsx(aqe,{}),h.jsx("main",{className:"max-w-screen-xl mx-auto pt-20 px-4",id:"main-content",children:h.jsx(Gb,{FallbackComponent:pZ,children:h.jsx(y.Suspense,{fallback:h.jsx(fn,{className:"h-12 w-12 rounded-full"}),children:e})})}),h.jsx(h1,{})]}),"Layout"),Iae=o(()=>h.jsx("div",{className:"max-w-screen-xl mx-auto h-screen pt-8",children:h.jsx("div",{className:"h-full",children:h.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-8",children:[h.jsx(fn,{className:"w-full h-[100px]"}),h.jsx(fn,{className:"w-4/5 h-[50px]"}),h.jsx(fn,{className:"w-full h-9"}),h.jsx(fn,{className:"w-full h-9"}),h.jsx(fn,{className:"w-full h-9"}),h.jsx(fn,{className:"w-2/5 h-9"})]})})}),"LoginSkeleton"),BN=o(()=>{const e=dr(),t=Vn(),{darkModeLogo:n,title:r}=Ia(),{data:a,isPending:i}=Ma({queryKey:["init"],queryFn:o(async()=>t.isInitialized(),"queryFn")}),{isPending:s,mutate:l}=Ki({mutationKey:["signup"],mutationFn:o(async w=>t.signUp(w),"mutationFn"),onSuccess:o(w=>{d({email:w.email,password:w.password,redirectTo:"/contacts"}).then(()=>{c("Initial user successfully created"),e.invalidateQueries({queryKey:["auth","canAccess"]})})},"onSuccess"),onError:o(()=>{c("An error occurred. Please try again.")},"onError")}),d=XY(),c=dn(),{register:p,handleSubmit:m,formState:{isValid:g}}=XM({mode:"onChange"});if(i)return h.jsx(Iae,{});if(a)return h.jsx(Jx,{to:"/login"});const x=o(async w=>{l(w)},"onSubmit");return h.jsxs("div",{className:"h-screen p-8",children:[h.jsxs("div",{className:"flex items-center gap-4",children:[h.jsx("img",{src:n,alt:r,width:24,className:"filter brightness-0 invert"}),h.jsx("h1",{className:"text-xl font-semibold",children:r})]}),h.jsx("div",{className:"h-full",children:h.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-4",children:[h.jsx("h1",{className:"text-2xl font-bold mb-4",children:"Welcome to CRM"}),h.jsx("p",{className:"text-base mb-4",children:"Create the first user account to complete the setup."}),h.jsxs("form",{onSubmit:m(x),className:"space-y-4",children:[h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx(wi,{htmlFor:"first_name",children:"First name"}),h.jsx(Qa,{...p("first_name",{required:!0}),id:"first_name",type:"text",required:!0})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx(wi,{htmlFor:"last_name",children:"Last name"}),h.jsx(Qa,{...p("last_name",{required:!0}),id:"last_name",type:"text",required:!0})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx(wi,{htmlFor:"email",children:"Email"}),h.jsx(Qa,{...p("email",{required:!0}),id:"email",type:"email",required:!0})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx(wi,{htmlFor:"password",children:"Password"}),h.jsx(Qa,{...p("password",{required:!0}),id:"password",type:"password",required:!0})]}),h.jsx("div",{className:"flex justify-between items-center mt-8",children:h.jsx(Ge,{type:"submit",disabled:!g||s,className:"w-full",children:s?h.jsxs(h.Fragment,{children:[h.jsx(yp,{className:"w-4 h-4 animate-spin mr-2"}),"Creating..."]}):"Create account"})})]})]})})]})},"SignupPage");BN.path="/sign-up";const uqe=o((e,t)=>e==="admin"?!0:t.resource!=="sales","canAccess"),ZA=nke(Qn,{getIdentity:o(async()=>{const e=await Lae();if(e==null)throw new Error;return{id:e.id,fullName:`${e.first_name} ${e.last_name}`,avatar:e.avatar?.src}},"getIdentity")});async function Fs(){if(Fs._is_initialized_cache==null){const{data:e}=await Qn.from("init_state").select("is_initialized");Fs._is_initialized_cache=e?.at(0)?.is_initialized>0}return Fs._is_initialized_cache}o(Fs,"getIsInitialized");(e=>{e._is_initialized_cache=null})(Fs||(Fs={}));const dqe={...ZA,login:o(async e=>{const t=await ZA.login(e);return xb=void 0,t},"login"),checkAuth:o(async e=>{if(window.location.pathname==="/set-password"||window.location.hash.includes("#/set-password")||window.location.pathname==="/forgot-password"||window.location.hash.includes("#/forgot-password")||window.location.pathname==="/change-password"||window.location.hash.includes("#/change-password")||window.location.pathname==="/otp-login"||window.location.hash.includes("#/otp-login")||window.location.pathname==="/sign-up"||window.location.hash.includes("#/sign-up"))return;if(!await Fs())throw await Qn.auth.signOut(),{redirectTo:"/sign-up",message:!1};return ZA.checkAuth(e)},"checkAuth"),canAccess:o(async e=>{if(!await Fs())return!1;const n=await Lae();if(n==null)return!1;const r=n.administrator?"admin":"user";return uqe(r,e)},"canAccess")};let xb;const Lae=o(async()=>{if(xb!=null)return xb;const{data:e,error:t}=await Qn.auth.getSession();if(e?.session?.user==null||t)return;const{data:n,error:r}=await Qn.from("sales").select("id, first_name, last_name, avatar, administrator").match({user_id:e?.session?.user.id}).single();if(!(n==null||r))return xb=n,n},"getSaleFromCache");async function fqe(e,t,n){const r={};t&&(r.id=t);const a={};t&&(a.company_id=t);const[i,s,l]=await Promise.all([hqe(e,r),pqe(e,a),mqe(e,a)]);return[...i,...s,...l].sort((d,c)=>d.date&&c.date?d.date.localeCompare(c.date)*-1:0).slice(0,250)}o(fqe,"getActivityLog");const hqe=o(async(e,t)=>{const{data:n}=await e.getList("companies",{filter:t,pagination:{page:1,perPage:250},sort:{field:"created_at",order:"DESC"}});return n.map(r=>({id:`company.${r.id}.created`,type:ite,company_id:r.id,company:r,sales_id:r.sales_id,date:r.created_at}))},"getNewCompanies");async function pqe(e,t){const{data:n}=await e.getList("contacts",{filter:t,pagination:{page:1,perPage:250},sort:{field:"first_seen",order:"DESC"}}),r={};if(t.sales_id&&(r.sales_id=t.sales_id),t.company_id){const l=n.map(d=>d.id).join(",");r["contact_id@in"]=`(${l})`}const{data:a}=await e.getList("contactNotes",{filter:r,pagination:{page:1,perPage:250},sort:{field:"date",order:"DESC"}}),i=n.map(l=>({id:`contact.${l.id}.created`,type:ote,company_id:l.company_id,sales_id:l.sales_id,contact:l,date:l.first_seen})),s=a.map(l=>({id:`contactNote.${l.id}.created`,type:ste,sales_id:l.sales_id,contactNote:l,date:l.date}));return[...i,...s]}o(pqe,"getNewContactsAndNotes");async function mqe(e,t){const{data:n}=await e.getList("deals",{filter:t,pagination:{page:1,perPage:250},sort:{field:"created_at",order:"DESC"}}),r={};if(t.sales_id&&(r.sales_id=t.sales_id),t.company_id){const l=n.map(d=>d.id).join(",");r["deal_id@in"]=`(${l})`}const{data:a}=await e.getList("dealNotes",{filter:r,pagination:{page:1,perPage:250},sort:{field:"date",order:"DESC"}}),i=n.map(l=>({id:`deal.${l.id}.created`,type:lte,company_id:l.company_id,sales_id:l.sales_id,deal:l,date:l.created_at})),s=a.map(l=>({id:`dealNote.${l.id}.created`,type:cte,sales_id:l.sales_id,dealNote:l,date:l.date}));return[...i,...s]}o(mqe,"getNewDealsAndNotes");async function vqe(e){return e.website?{src:`https://favicon.show/${e.website.replace(/^https?:\/\//,"").replace(/\/$/,"")}`,title:"Company favicon"}:null}o(vqe,"getCompanyAvatar");async function gqe(e,t={}){const{timeout:n=2e3}=t,r=new AbortController,a=setTimeout(()=>r.abort(),n),i=await fetch(e,{...t,signal:r.signal});return clearTimeout(a),i}o(gqe,"fetchWithTimeout");const yqe=["gmail.com","yahoo.com","hotmail.com","aol.com","hotmail.co.uk","hotmail.fr","msn.com","yahoo.fr","wanadoo.fr","orange.fr","comcast.net","yahoo.co.uk","yahoo.com.br","yahoo.co.in","live.com","rediffmail.com","free.fr","gmx.de","web.de","yandex.ru","ymail.com","libero.it","outlook.com","uol.com.br","bol.com.br","mail.ru","cox.net","hotmail.it","sbcglobal.net","sfr.fr","live.fr","verizon.net","live.co.uk","googlemail.com","yahoo.es","ig.com.br","live.nl","bigpond.com","terra.com.br","yahoo.it","neuf.fr","yahoo.de","alice.it","rocketmail.com","att.net","laposte.net","facebook.com","bellsouth.net","yahoo.in","hotmail.es","charter.net","yahoo.ca","yahoo.com.au","rambler.ru","hotmail.de","tiscali.it","shaw.ca","yahoo.co.jp","sky.com","earthlink.net","optonline.net","freenet.de","t-online.de","aliceadsl.fr","virgilio.it","home.nl","qq.com","telenet.be","me.com","yahoo.com.ar","tiscali.co.uk","yahoo.com.mx","voila.fr","gmx.net","mail.com","planet.nl","tin.it","live.it","ntlworld.com","arcor.de","yahoo.co.id","frontiernet.net","hetnet.nl","live.com.au","yahoo.com.sg","zonnet.nl","club-internet.fr","juno.com","optusnet.com.au","blueyonder.co.uk","bluewin.ch","skynet.be","sympatico.ca","windstream.net","mac.com","centurytel.net","chello.nl","live.ca","aim.com","bigpond.net.au","online.de","apple.com"];async function bqe(e){const t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(i=>i.toString(16).padStart(2,"0")).join("")}o(bqe,"hash");async function xqe(e){return`https://www.gravatar.com/avatar/${await bqe(e)}?d=404`}o(xqe,"getGravatarUrl");async function wqe(e){if(yqe.includes(e))return null;try{const t=`https://${e}/favicon.ico`;if((await gqe(t)).ok)return t}catch{return null}return null}o(wqe,"getFaviconUrl");async function _qe(e){if(!e.email_jsonb||!e.email_jsonb.length)return null;for(const{email:t}of e.email_jsonb){const n=await xqe(t);try{if((await fetch(n)).ok)return n}catch{}const r=t.split("@")[1],a=await wqe(r);if(a)return a}return null}o(_qe,"getContactAvatar");const XV=iy()||{url:"https://placeholder.supabase.co",anonKey:"placeholder-key"},bo=xke({instanceUrl:XV.url,apiKey:XV.anonKey,supabaseClient:Qn,sortOrder:"asc,desc.nullslast"}),ZV=o(async e=>{let t=e.data.logo;return typeof t!="object"||t===null||!t.src?t=await vqe(e.data):t.rawFile instanceof File&&await wb(t),{...e,data:{...e.data,logo:t}}},"processCompanyLogo");async function JV(e){const{data:t}=e;if(t.avatar?.src||!t.email_jsonb||!t.email_jsonb.length)return e;const n=await _qe(t),r={...t,avatar:{src:n||void 0}};return{...e,data:r}}o(JV,"processContactAvatar");const Sqe={...bo,async getList(e,t){return e==="companies"?bo.getList("companies_summary",t):e==="contacts"?bo.getList("contacts_summary",t):bo.getList(e,t)},async getOne(e,t){return e==="companies"?bo.getOne("companies_summary",t):e==="contacts"?bo.getOne("contacts_summary",t):bo.getOne(e,t)},async signUp({email:e,password:t,first_name:n,last_name:r}){const{data:a,error:i}=await Qn.functions.invoke("setup",{method:"POST",body:{email:e,password:t,first_name:n,last_name:r}});if(!a||i)throw console.error("signUp.error",i),new Error("Failed to create account");return Fs._is_initialized_cache=!0,{id:a.data.id,email:e,password:t}},async salesCreate(e){const{data:t,error:n}=await Qn.functions.invoke("users",{method:"POST",body:e});if(!t||n)throw console.error("salesCreate.error",n),new Error("Failed to create account manager");return t},async salesUpdate(e,t){const{email:n,first_name:r,last_name:a,administrator:i,avatar:s,disabled:l}=t,{data:d,error:c}=await Qn.functions.invoke("users",{method:"PATCH",body:{sales_id:e,email:n,first_name:r,last_name:a,administrator:i,disabled:l,avatar:s}});if(!d||c)throw console.error("salesCreate.error",c),new Error("Failed to update account manager");return t},async resendInvite(e){const{data:t,error:n}=await Qn.functions.invoke("users",{method:"PUT",body:{sales_id:e,action:"invite"}});if(!t||n)throw console.error("resendInvite.error",n),new Error("Failed to resend invitation");return t},async resetPassword(e){const{data:t,error:n}=await Qn.functions.invoke("users",{method:"PUT",body:{sales_id:e,action:"reset"}});if(!t||n)throw console.error("resetPassword.error",n),new Error("Failed to send password reset");return t},async updatePassword(e){const{data:t,error:n}=await Qn.functions.invoke("updatePassword",{method:"PATCH",body:{sales_id:e}});if(!t||n)throw console.error("passwordUpdate.error",n),new Error("Failed to update password");return t},async unarchiveDeal(e){const{data:t}=await bo.getList("deals",{filter:{stage:e.stage},pagination:{page:1,perPage:1e3},sort:{field:"index",order:"ASC"}}),n=t.map((r,a)=>({...r,index:r.id===e.id?0:a+1,archived_at:r.id===e.id?null:r.archived_at}));return await Promise.all(n.map(r=>bo.update("deals",{id:r.id,data:r,previousData:t.find(a=>a.id===r.id)})))},async getActivityLog(e){return fqe(bo,e)},async isInitialized(){return Fs()},async mergeContacts(e,t){const{data:n,error:r}=await Qn.functions.invoke("mergeContacts",{method:"POST",body:{loserId:e,winnerId:t}});if(r)throw console.error("mergeContacts.error",r),new Error("Failed to merge contacts");return n}},Eqe=qfe(Sqe,[{resource:"contactNotes",beforeSave:o(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await wb(r);return e},"beforeSave")},{resource:"dealNotes",beforeSave:o(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await wb(r);return e},"beforeSave")},{resource:"sales",beforeSave:o(async(e,t,n)=>(e.avatar&&await wb(e.avatar),e),"beforeSave")},{resource:"contacts",beforeCreate:o(async e=>JV(e),"beforeCreate"),beforeUpdate:o(async e=>JV(e),"beforeUpdate"),beforeGetList:o(async e=>ob(["first_name","last_name","company_name","title","email","phone","background"])(e),"beforeGetList")},{resource:"companies",beforeGetList:o(async e=>ob(["name","phone_number","website","zipcode","city","stateAbbr"])(e),"beforeGetList"),beforeCreate:o(async e=>{const t=await ZV(e);return{...t,data:{...t.data,created_at:new Date().toISOString()}}},"beforeCreate"),beforeUpdate:o(async e=>await ZV(e),"beforeUpdate")},{resource:"contacts_summary",beforeGetList:o(async e=>ob(["first_name","last_name"])(e),"beforeGetList")},{resource:"deals",beforeGetList:o(async e=>ob(["name","type","description"])(e),"beforeGetList")}]),ob=o(e=>t=>{if(!t.filter?.q)return t;const{q:n,...r}=t.filter;return{...t,filter:{...r,"@or":e.reduce((a,i)=>i==="email"?{...a,"email_fts@ilike":n}:i==="phone"?{...a,"phone_fts@ilike":n}:{...a,[`${i}@ilike`]:n},{})}}},"applyFullTextSearch"),wb=o(async e=>{if(!e.src.startsWith("blob:")&&!e.src.startsWith("data:")&&e.path){const{error:c}=await Qn.storage.from("attachments").createSignedUrl(e.path,60);if(!c)return}const t=e.src?await fetch(e.src).then(c=>c.blob()):e.rawFile,n=e.rawFile,r=n.name.split(".").pop(),i=`${`${Math.random()}.${r}`}`,{error:s}=await Qn.storage.from("attachments").upload(i,t);if(s)throw console.error("uploadError",s),new Error("Failed to upload attachment");const{data:l}=Qn.storage.from("attachments").getPublicUrl(i);e.path=i,e.src=l.publicUrl;const d=n.type;return e.type=d,e},"uploadToBucket");function Fae(){const{identity:e}=wr(),t=Vt();return h.jsxs("div",{className:"space-y-4 w-full",children:[h.jsx(on,{source:"first_name",validate:Xn(),helperText:!1}),h.jsx(on,{source:"last_name",validate:Xn(),helperText:!1}),h.jsx(on,{source:"email",validate:[Xn(),AY()],helperText:!1}),h.jsx(dN,{source:"administrator",readOnly:t?.id===e?.id,helperText:!1}),h.jsx(dN,{source:"disabled",readOnly:t?.id===e?.id,helperText:!1})]})}o(Fae,"SalesInputs");function Cqe(){const e=Vn(),t=dn(),n=Yo(),{mutate:r}=Ki({mutationKey:["signup"],mutationFn:o(async i=>e.salesCreate(i),"mutationFn"),onSuccess:o(()=>{t("User created. They will soon receive an email to set their password."),n("/sales")},"onSuccess"),onError:o(()=>{t("An error occurred while creating the user.",{type:"error"})},"onError")}),a=o(async i=>{r(i)},"onSubmit");return h.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:h.jsxs(rr,{children:[h.jsx(yx,{children:h.jsx(bx,{children:"Create a new user"})}),h.jsx(ei,{children:h.jsx(XJ,{onSubmit:a,children:h.jsx(Fae,{})})})]})})}o(Cqe,"SalesCreate");function jqe(){return h.jsxs("div",{className:"flex justify-end gap-4",children:[h.jsx(S1,{}),h.jsx(sd,{})]})}o(jqe,"EditToolbar");function Oqe(){const{record:e}=nY(),t=Vn(),n=dn(),r=Yo(),{mutate:a}=Ki({mutationKey:["signup"],mutationFn:o(async s=>{if(!e)throw new Error("Record not found");return t.salesUpdate(e.id,s)},"mutationFn"),onSuccess:o(()=>{r("/sales"),n("User updated successfully")},"onSuccess"),onError:o(()=>{n("An error occurred. Please try again.")},"onError")}),i=o(async s=>{a(s)},"onSubmit");return h.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:h.jsx(rr,{children:h.jsx(ei,{children:h.jsxs(XJ,{toolbar:h.jsx(jqe,{}),onSubmit:i,record:e,children:[h.jsx(Rqe,{}),h.jsx(Fae,{})]})})})})}o(Oqe,"SalesEdit");const Rqe=o(()=>{const e=Vt();return e?h.jsxs("h2",{className:"text-lg font-semibold mb-4",children:["Edit ",e?.first_name," ",e?.last_name]}):null},"SaleEditTitle"),kqe=o(()=>h.jsxs(i4,{children:[h.jsx(v1,{}),h.jsx(Sc,{label:"New user"})]}),"SalesListActions"),Aqe=[h.jsx(o4,{source:"q",alwaysOn:!0})],Tqe=o(e=>{const t=Vt();return t?h.jsxs("div",{className:"flex flex-row gap-1",children:[t.administrator&&h.jsx(Kh,{variant:"outline",className:"border-blue-300 dark:border-blue-700",children:"Admin"}),t.disabled&&h.jsx(Kh,{variant:"outline",className:"border-orange-300 dark:border-orange-700",children:"Disabled"})]}):null},"OptionsField"),Pqe=o(()=>{const e=Vt(),t=Vn(),n=dn(),r=mw(),[a,i]=y.useState(!1),[s,l]=y.useState(!1),{mutate:d,isPending:c}=Ki({mutationFn:o(async()=>t.resendInvite(e.id),"mutationFn"),onSuccess:o(()=>{n("Invitation email resent successfully"),i(!1),r()},"onSuccess"),onError:o(()=>{n("Failed to resend invitation email",{type:"error"}),i(!1)},"onError")}),{mutate:p,isPending:m}=Ki({mutationFn:o(async()=>t.resetPassword(e.id),"mutationFn"),onSuccess:o(()=>{n("Password reset email sent successfully"),l(!1),r()},"onSuccess"),onError:o(()=>{n("Failed to send password reset email",{type:"error"}),l(!1)},"onError")});if(!e)return null;const g=e.email_confirmed_at!==null,x=e.disabled===!0;return console.log("[RowActions] Record:",{email:e.email,email_confirmed_at:e.email_confirmed_at,isConfirmed:g,isDisabled:x,inviteDialogOpen:a,resetDialogOpen:s}),h.jsxs(h.Fragment,{children:[h.jsxs(wc,{children:[h.jsx(Bs,{asChild:!0,children:h.jsxs(Ge,{variant:"ghost",className:"h-8 w-8 p-0",children:[h.jsx("span",{className:"sr-only",children:"Open menu"}),h.jsx(pD,{className:"h-4 w-4"})]})}),h.jsxs(_c,{align:"end",children:[h.jsx(WD,{children:"Email Actions"}),h.jsx(Vv,{}),!g&&h.jsxs(cr,{onClick:o(w=>{w.preventDefault(),w.stopPropagation(),console.log("[Menu] Clicked Resend Invite"),i(!0)},"onClick"),children:[h.jsx(Nwe,{className:"mr-2 h-4 w-4"}),"Resend Invite"]}),g&&!x&&h.jsxs(cr,{onClick:o(()=>l(!0),"onClick"),children:[h.jsx(swe,{className:"mr-2 h-4 w-4"}),"Send Password Reset"]})]})]}),h.jsx(Oi,{open:a,onOpenChange:i,children:h.jsxs(Ri,{onClick:o(w=>w.stopPropagation(),"onClick"),onPointerDown:o(w=>w.stopPropagation(),"onPointerDown"),children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Resend Invitation"}),h.jsxs(Ds,{children:["Send a new invitation email to ",h.jsx("strong",{children:e.email}),"?",h.jsx("br",{}),h.jsx("br",{}),"This will send them a fresh invitation link to set up their account."]})]}),h.jsxs(Vs,{children:[h.jsx(Ge,{variant:"outline",onClick:o(w=>{w.stopPropagation(),i(!1)},"onClick"),disabled:c,children:"Cancel"}),h.jsx(Ge,{onClick:o(w=>{w.stopPropagation(),d()},"onClick"),disabled:c,children:c?"Sending...":"Send Invitation"})]})]})}),h.jsx(Oi,{open:s,onOpenChange:l,children:h.jsxs(Ri,{onClick:o(w=>w.stopPropagation(),"onClick"),onPointerDown:o(w=>w.stopPropagation(),"onPointerDown"),children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Send Password Reset"}),h.jsxs(Ds,{children:["Send a password reset email to ",h.jsx("strong",{children:e.email}),"?",h.jsx("br",{}),h.jsx("br",{}),"This will send them a link to reset their password."]})]}),h.jsxs(Vs,{children:[h.jsx(Ge,{variant:"outline",onClick:o(w=>{w.stopPropagation(),l(!1)},"onClick"),disabled:m,children:"Cancel"}),h.jsx(Ge,{onClick:o(w=>{w.stopPropagation(),p()},"onClick"),disabled:m,children:m?"Sending...":"Send Reset Link"})]})]})})]})},"RowActions");function Nqe(){return h.jsx(r4,{filters:Aqe,actions:h.jsx(kqe,{}),sort:{field:"first_name",order:"ASC"},children:h.jsx(Mqe,{})})}o(Nqe,"SalesList");const Mqe=o(()=>{const{data:e,isPending:t,filterValues:n}=zn(),{identity:r}=wr(),a=n&&Object.keys(n).length>0;return!r||t?h.jsx(rr,{className:"p-4",children:h.jsxs("div",{className:"space-y-3",children:[h.jsx(fn,{className:"h-12 w-full"}),h.jsx(fn,{className:"h-12 w-full"}),h.jsx(fn,{className:"h-12 w-full"}),h.jsx(fn,{className:"h-12 w-full"}),h.jsx(fn,{className:"h-12 w-full"})]})}):!e?.length&&!a?h.jsx(Dqe,{}):h.jsxs(Rs,{children:[h.jsx(Rs.Col,{source:"first_name"}),h.jsx(Rs.Col,{source:"last_name"}),h.jsx(Rs.Col,{source:"email"}),h.jsx(Rs.Col,{label:!1,children:h.jsx(Tqe,{})}),h.jsx(Rs.Col,{label:!1,children:h.jsx(Pqe,{})})]})},"SalesListLayout"),Dqe=o(()=>{const e=w1();return h.jsxs("div",{className:"flex flex-col justify-center items-center gap-3",style:{height:`calc(100dvh - ${e}px)`},children:[h.jsx("img",{src:"./img/empty.svg",alt:"No users found"}),h.jsxs("div",{className:"flex flex-col gap-0 items-center",children:[h.jsx("h6",{className:"text-lg font-bold",children:"No users found"}),h.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"It seems your user list is empty."})]}),h.jsx("div",{className:"flex flex-row gap-2",children:h.jsx(Sc,{label:"New user"})})]})},"SalesEmpty"),Iqe={list:Nqe,create:Cqe,edit:Oqe,recordRepresentation:o(e=>`${e.first_name} ${e.last_name}`,"recordRepresentation")};function $ae({open:e,onComplete:t,canClose:n=!1}){const[r,a]=y.useState("welcome"),[i,s]=y.useState(""),[l,d]=y.useState(""),[c,p]=y.useState(null),m=o(async()=>{p(null),a("validating");const x=await ZRe(i,l);x.valid?(KRe({url:i,anonKey:l}),a("success"),setTimeout(()=>{window.location.href=window.location.origin},1500)):(p(x.error||"Connection failed"),a("credentials"))},"handleValidateAndSave"),g=o(()=>{n&&t()},"handleClose");return h.jsx(Oi,{open:e,onOpenChange:n?g:void 0,children:h.jsxs(Ri,{className:"sm:max-w-md",onPointerDownOutside:o(x=>!n&&x.preventDefault(),"onPointerDownOutside"),onEscapeKeyDown:o(x=>!n&&x.preventDefault(),"onEscapeKeyDown"),children:[r==="welcome"&&h.jsxs(h.Fragment,{children:[h.jsxs(ca,{children:[h.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[h.jsx(Fv,{className:"h-6 w-6 text-primary"}),h.jsx(ua,{children:"Welcome to CRM"})]}),h.jsx(Ds,{children:"To get started, you'll need to connect to a Supabase database."})]}),h.jsxs("div",{className:"space-y-4 py-4",children:[h.jsx(_i,{children:h.jsxs(Wi,{children:[h.jsx("strong",{children:"Don't have a Supabase project?"}),h.jsx("br",{}),"Create one for free at"," ",h.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline text-primary",children:"supabase.com"})]})}),h.jsxs("div",{className:"space-y-2",children:[h.jsx("h4",{className:"font-medium text-sm",children:"What you'll need:"}),h.jsxs("ul",{className:"list-disc list-inside text-sm text-muted-foreground space-y-1",children:[h.jsx("li",{children:"Your Supabase project URL"}),h.jsx("li",{children:"Your anonymous (anon) API key"})]})]}),h.jsx(Ge,{onClick:o(()=>a("credentials"),"onClick"),className:"w-full",children:"Continue"})]})]}),r==="credentials"&&h.jsxs(h.Fragment,{children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Connect to Supabase"}),h.jsx(Ds,{children:"Enter your Supabase project credentials"})]}),h.jsxs("div",{className:"space-y-4 py-4",children:[c&&h.jsxs(_i,{variant:"destructive",children:[h.jsx(Gg,{className:"h-4 w-4"}),h.jsx(Wi,{children:c})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx(wi,{htmlFor:"supabase-url",children:"Supabase URL"}),h.jsx(Qa,{id:"supabase-url",placeholder:"https://xxxxx.supabase.co",value:i,onChange:o(x=>s(x.target.value),"onChange")}),h.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in Project Settings → API"})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx(wi,{htmlFor:"anon-key",children:"Anonymous Key"}),h.jsx(Qa,{id:"anon-key",type:"password",placeholder:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",value:l,onChange:o(x=>d(x.target.value),"onChange")}),h.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in Project Settings → API → Project API keys"})]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx(Ge,{variant:"outline",onClick:o(()=>a("welcome"),"onClick"),className:"flex-1",children:"Back"}),h.jsx(Ge,{onClick:m,disabled:!i||!l,className:"flex-1",children:"Connect"})]})]})]}),r==="validating"&&h.jsxs(h.Fragment,{children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Validating Connection"}),h.jsx(Ds,{children:"Testing your Supabase credentials..."})]}),h.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[h.jsx(yp,{className:"h-12 w-12 animate-spin text-primary mb-4"}),h.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait..."})]})]}),r==="success"&&h.jsxs(h.Fragment,{children:[h.jsxs(ca,{children:[h.jsx(ua,{children:"Connection Successful!"}),h.jsx(Ds,{children:"Your Supabase database is now connected"})]}),h.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[h.jsx(nc,{className:"h-12 w-12 text-green-500 mb-4"}),h.jsx("p",{className:"text-sm text-muted-foreground",children:"Reloading application..."})]})]})]})})}o($ae,"SupabaseSetupWizard");function Lqe(){const[e,t]=y.useState(!1),n=iy(),r=JRe(),a=o(()=>{confirm("Are you sure you want to clear the database configuration? The app will need to be reconfigured on next launch.")&&(QRe(),window.location.reload())},"handleClearConfig");return h.jsxs(h.Fragment,{children:[h.jsxs(rr,{children:[h.jsxs(yx,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Fv,{className:"h-5 w-5"}),h.jsx(bx,{children:"Database Connection"})]}),h.jsx(VJ,{children:"Manage your Supabase database connection settings"})]}),h.jsx(ei,{className:"space-y-4",children:n?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-start gap-3 p-4 border rounded-lg",children:[h.jsx(nc,{className:"h-5 w-5 text-green-500 mt-0.5"}),h.jsxs("div",{className:"flex-1 space-y-1",children:[h.jsx("p",{className:"font-medium",children:"Connected"}),h.jsx("p",{className:"text-sm text-muted-foreground",children:n.url}),n.configuredAt&&h.jsxs("p",{className:"text-xs text-muted-foreground",children:["Configured on"," ",new Date(n.configuredAt).toLocaleDateString()]})]})]}),r==="env"&&h.jsxs(_i,{children:[h.jsx(QT,{className:"h-4 w-4"}),h.jsx(Wi,{children:"Using configuration from environment variables. You can override this by setting up a new connection via the UI."})]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsxs(Ge,{variant:"outline",onClick:o(()=>t(!0),"onClick"),className:"flex-1",children:[h.jsx(QT,{className:"h-4 w-4 mr-2"}),"Change Connection"]}),r==="ui"&&h.jsxs(Ge,{variant:"destructive",onClick:a,className:"flex-1",children:[h.jsx(uQ,{className:"h-4 w-4 mr-2"}),"Clear Configuration"]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx(Fqe,{className:"text-sm font-medium",children:"Anonymous Key"}),h.jsxs("div",{className:"font-mono text-sm p-2 bg-muted rounded",children:[n.anonKey.substring(0,20),"...",n.anonKey.substring(n.anonKey.length-10)]})]})]}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-start gap-3 p-4 border border-dashed rounded-lg",children:[h.jsx(bc,{className:"h-5 w-5 text-destructive mt-0.5"}),h.jsxs("div",{className:"flex-1 space-y-1",children:[h.jsx("p",{className:"font-medium",children:"Not Connected"}),h.jsx("p",{className:"text-sm text-muted-foreground",children:"No Supabase database is configured"})]})]}),h.jsx(_i,{children:h.jsxs(Wi,{children:["Connect to a Supabase database to start using Atomic CRM. You can create a free project at"," ",h.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"supabase.com"})]})}),h.jsxs(Ge,{onClick:o(()=>t(!0),"onClick"),className:"w-full",children:[h.jsx(Fv,{className:"h-4 w-4 mr-2"}),"Connect to Supabase"]})]})})]}),h.jsx($ae,{open:e,onComplete:o(()=>t(!1),"onComplete"),canClose:!0})]})}o(Lqe,"DatabaseSettings");function Fqe({children:e,className:t}){return h.jsx("label",{className:t,children:e})}o(Fqe,"Label");const HN=o(()=>h.jsx("div",{className:"max-w-lg mx-auto mt-8",children:h.jsx(Lqe,{})}),"DatabasePage");HN.path="/database";const VN=o(()=>{const[e,t]=y.useState(!1),{identity:n,refetch:r}=wr(),{data:a,refetch:i}=vw("sales",{id:n?.id}),s=dn(),l=Vn(),{mutate:d}=Ki({mutationKey:["signup"],mutationFn:o(async p=>{if(!n)throw new Error("Record not found");return l.salesUpdate(n.id,p)},"mutationFn"),onSuccess:o(()=>{r(),i(),t(!1),s("Your profile has been updated")},"onSuccess"),onError:o(p=>{s("An error occurred. Please try again",{type:"error"})},"onError")});if(!n)return null;const c=o(async p=>{d(p)},"handleOnSubmit");return h.jsx("div",{className:"max-w-lg mx-auto mt-8",children:h.jsx(Kr,{onSubmit:c,record:a,children:h.jsx($qe,{isEditMode:e,setEditMode:t})})})},"SettingsPage"),$qe=o(({isEditMode:e,setEditMode:t})=>{const n=dn(),r=pa(),a=Vt(),{identity:i,refetch:s}=wr(),{isDirty:l}=Bg(),d=Vn(),{mutate:c}=Ki({mutationKey:["signup"],mutationFn:o(async g=>{if(!a)throw new Error("Record not found");return d.salesUpdate(a.id,g)},"mutationFn"),onSuccess:o(()=>{s(),n("Your profile has been updated")},"onSuccess"),onError:o(()=>{n("An error occurred. Please try again.")},"onError")});if(!i)return null;const p=o(()=>{r("/forgot-password")},"handleClickOpenPasswordChange"),m=o(async g=>{c(g)},"handleAvatarUpdate");return h.jsxs("div",{className:"space-y-4",children:[h.jsx(rr,{children:h.jsxs(ei,{children:[h.jsx("div",{className:"mb-4 flex flex-row justify-between",children:h.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"My info"})}),h.jsxs("div",{className:"space-y-4 mb-4",children:[h.jsx(Bee,{source:"avatar",type:"avatar",onSave:m,linkPosition:"right"}),h.jsx(JA,{source:"first_name",isEditMode:e}),h.jsx(JA,{source:"last_name",isEditMode:e}),h.jsx(JA,{source:"email",isEditMode:e})]}),h.jsxs("div",{className:"flex flex-row justify-end gap-2",children:[!e&&h.jsx(h.Fragment,{children:h.jsx(Ge,{variant:"outline",type:"button",onClick:p,children:"Change password"})}),h.jsxs(Ge,{type:"button",variant:e?"ghost":"outline",onClick:o(()=>t(!e),"onClick"),className:"flex items-center",children:[e?h.jsx(bc,{}):h.jsx(oQ,{}),e?"Cancel":"Edit"]}),e&&h.jsxs(Ge,{type:"submit",disabled:!l,variant:"outline",children:[h.jsx(zw,{}),"Save"]})]})]})}),void 0]})},"SettingsForm"),JA=o(({source:e,isEditMode:t})=>t?h.jsx(on,{source:e,helperText:!1}):h.jsx("div",{className:"m-2",children:h.jsx(d3e,{source:e})}),"TextRender");VN.path="/settings";var qqe={"ra-supabase":{auth:{email:"Email",confirm_password:"Confirm password",sign_in_with:"Sign in with %{provider}",forgot_password:"Forgot password?",reset_password:"Reset password",password_reset:"Your password has been reset. You will receive an email containing a link to log in.",missing_tokens:"Access and refresh tokens are missing",back_to_login:"Back to login"},reset_password:{forgot_password:"Forgot password?",forgot_password_details:"Enter your email for instructions."},set_password:{new_password:"Choose your password"},validation:{password_mismatch:"Passwords do not match"}}};const zqe={"ra-supabase":{auth:{password_reset:"Check your emails for a Reset Password message."}}},Uqe=$K(()=>Cde(jK,qqe,zqe),"en",[{locale:"en",name:"English"}],{allowMissing:!0}),Bqe=o(()=>{const e=Vn(),{data:t,error:n,isPending:r}=Ma({queryKey:["init"],queryFn:o(async()=>e.isInitialized(),"queryFn")});return r?h.jsx(Iae,{}):n?h.jsx(nx,{}):t?h.jsx(nx,{}):h.jsx(Jx,{to:"/sign-up"})},"StartPage");async function Hqe(e){const t=["contacts","companies","deals","contactNotes","dealNotes","tasks","sales","tags"],n=[];try{for(const r of t)try{await e.getList(r,{pagination:{page:1,perPage:1},sort:{field:"id",order:"ASC"},filter:{}})}catch(a){(a?.message?.includes("Could not find the table")||a?.message?.includes("relation")||a?.message?.includes("does not exist"))&&n.push(r)}return{isHealthy:n.length===0,missingTables:n}}catch(r){return{isHealthy:!1,missingTables:t,error:r?.message||"Unknown error"}}}o(Hqe,"checkDatabaseHealth");function Vqe({missingTables:e,supabaseUrl:t}){const n=t.match(/https:\/\/([^.]+)\.supabase\.co/)?.[1];return h.jsxs("div",{className:"max-w-2xl mx-auto mt-8 space-y-4",children:[h.jsxs(_i,{variant:"destructive",children:[h.jsx(Gg,{className:"h-4 w-4"}),h.jsx(rte,{children:"Database Schema Not Configured"}),h.jsx(Wi,{children:"Your Supabase database is connected, but the CRM schema hasn't been set up yet."})]}),h.jsxs(rr,{children:[h.jsxs(yx,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Fv,{className:"h-5 w-5"}),h.jsx(bx,{children:"Setup Instructions"})]}),h.jsx(VJ,{children:"Follow these steps to set up your database schema"})]}),h.jsxs(ei,{className:"space-y-6",children:[h.jsxs("div",{children:[h.jsx("h3",{className:"font-semibold mb-2",children:"Missing Tables:"}),h.jsx("div",{className:"flex flex-wrap gap-2",children:e.map(r=>h.jsx("span",{className:"px-2 py-1 bg-destructive/10 text-destructive text-sm rounded",children:r},r))})]}),h.jsxs("div",{className:"space-y-3",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-primary text-primary-foreground text-sm font-bold",children:"1"}),h.jsx("h3",{className:"font-semibold",children:"Using Supabase CLI (Recommended)"})]}),h.jsxs("div",{className:"ml-8 space-y-3",children:[h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Install Supabase CLI:"}),h.jsx("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:"npm install -g supabase"})]}),h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Clone the RealTimeX CRM repository to get migrations:"}),h.jsxs("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:["git clone https://github.com/therealtimex/realtimex-crm.git",`
152
152
  `,"cd realtimex-crm"]})]}),h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Link to your Supabase project:"}),h.jsxs("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:["supabase link --project-ref ",n||"YOUR_PROJECT_REF"]})]}),h.jsxs("div",{children:[h.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Push the migrations:"}),h.jsx("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:"supabase db push"})]}),h.jsx("div",{children:h.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Reload this page after migrations are complete."})})]})]}),h.jsxs("div",{className:"space-y-3",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-primary text-primary-foreground text-sm font-bold",children:"2"}),h.jsx("h3",{className:"font-semibold",children:"Using Supabase SQL Editor"})]}),h.jsxs("div",{className:"ml-8 space-y-3",children:[h.jsx("p",{className:"text-sm text-muted-foreground",children:"Manually run the SQL migrations in your Supabase SQL Editor:"}),h.jsxs("ol",{className:"list-decimal list-inside space-y-2 text-sm text-muted-foreground",children:[h.jsxs("li",{children:["Download migrations from"," ",h.jsxs("a",{href:"https://github.com/therealtimex/realtimex-crm/tree/main/supabase/migrations",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline inline-flex items-center gap-1",children:["GitHub",h.jsx(Zd,{className:"h-3 w-3"})]})]}),h.jsxs("li",{children:["Open your"," ",h.jsxs("a",{href:`https://supabase.com/dashboard/project/${n}/sql/new`,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline inline-flex items-center gap-1",children:["Supabase SQL Editor",h.jsx(Zd,{className:"h-3 w-3"})]})]}),h.jsx("li",{children:"Run each migration file in order (by date in filename)"}),h.jsx("li",{children:"Reload this page after all migrations are complete"})]}),n&&h.jsx(Ge,{asChild:!0,variant:"outline",className:"w-full",children:h.jsxs("a",{href:`https://supabase.com/dashboard/project/${n}/sql/new`,target:"_blank",rel:"noopener noreferrer",children:[h.jsx(Zd,{className:"h-4 w-4 mr-2"}),"Open SQL Editor"]})})]})]}),h.jsxs("div",{className:"space-y-3 pt-4 border-t",children:[h.jsx("h3",{className:"font-semibold",children:"After Setup"}),h.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx(nc,{className:"h-4 w-4 mt-0.5 text-green-500"}),h.jsx("span",{children:"All tables will be created with proper schemas and relationships"})]}),h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx(nc,{className:"h-4 w-4 mt-0.5 text-green-500"}),h.jsx("span",{children:"Row Level Security (RLS) policies will be configured"})]}),h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx(nc,{className:"h-4 w-4 mt-0.5 text-green-500"}),h.jsx("span",{children:"Database triggers and functions will be set up"})]})]}),h.jsx(Ge,{onClick:o(()=>window.location.reload(),"onClick"),className:"w-full mt-4",children:"Reload Page"})]})]})]}),h.jsxs(rr,{children:[h.jsx(yx,{children:h.jsx(bx,{className:"text-base",children:"Need Help?"})}),h.jsxs(ei,{className:"space-y-2 text-sm",children:[h.jsxs("a",{href:"https://github.com/therealtimex/realtimex-crm#installation",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 text-primary hover:underline",children:[h.jsx(Zd,{className:"h-4 w-4"}),"View Full Setup Guide"]}),h.jsxs("a",{href:"https://github.com/therealtimex/realtimex-crm/issues",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 text-primary hover:underline",children:[h.jsx(Zd,{className:"h-4 w-4"}),"Report an Issue"]}),h.jsxs("a",{href:"https://supabase.com/docs/guides/cli",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 text-primary hover:underline",children:[h.jsx(Zd,{className:"h-4 w-4"}),"Supabase CLI Documentation"]})]})]})]})}o(Vqe,"DatabaseSetupGuide");function Wqe({children:e,dataProvider:t}){const[n,r]=y.useState(null),[a,i]=y.useState(!0);if(y.useEffect(()=>{let s=!1;async function l(){try{const d=await Hqe(t);s||(r(d),i(!1))}catch(d){console.error("[DatabaseHealthCheck] Failed to check database health:",d),s||i(!1)}}return o(l,"checkHealth"),l(),()=>{s=!0}},[t]),a)return h.jsx("div",{className:"flex items-center justify-center min-h-screen",children:h.jsxs("div",{className:"text-center space-y-4",children:[h.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto"}),h.jsx("p",{className:"text-muted-foreground",children:"Checking database connection..."})]})});if(n&&!n.isHealthy){const s=iy();if(s)return h.jsx(Vqe,{missingTables:n.missingTables,supabaseUrl:s.url})}return h.jsx(h.Fragment,{children:e})}o(Wqe,"DatabaseHealthCheck");const Gqe=o(({contactGender:e=RZ,companySectors:t=_Z,dealCategories:n=CZ,dealPipelineStatuses:r=EZ,dealStages:a=SZ,darkModeLogo:i=bZ,lightModeLogo:s=xZ,noteStatuses:l=jZ,taskTypes:d=OZ,title:c=wZ,dataProvider:p=Eqe,authProvider:m=dqe,disableTelemetry:g,...x})=>(y.useEffect(()=>{if(g||typeof window>"u"||typeof window.location>"u"||typeof Image>"u")return;const w=new Image;w.src=`https://atomic-crm-telemetry.marmelab.com/atomic-crm-telemetry?domain=${window.location.hostname}`},[g]),h.jsx(nOe,{contactGender:e,companySectors:t,dealCategories:n,dealPipelineStatuses:r,dealStages:a,darkModeLogo:i,lightModeLogo:s,noteStatuses:l,taskTypes:d,title:c,children:h.jsx(Wqe,{dataProvider:p,children:h.jsxs(sOe,{dataProvider:p,authProvider:m,store:VW(void 0,"CRM"),layout:cqe,loginPage:Bqe,i18nProvider:Uqe,dashboard:eqe,requireAuth:!0,disableTelemetry:!0,...x,children:[h.jsxs($T,{noLayout:!0,children:[h.jsx(Kn,{path:BN.path,element:h.jsx(BN,{})}),h.jsx(Kn,{path:IP.path,element:h.jsx(IP,{})}),h.jsx(Kn,{path:NP.path,element:h.jsx(NP,{})}),h.jsx(Kn,{path:LP.path,element:h.jsx(LP,{})}),h.jsx(Kn,{path:FP.path,element:h.jsx(FP,{})})]}),h.jsxs($T,{children:[h.jsx(Kn,{path:VN.path,element:h.jsx(VN,{})}),h.jsx(Kn,{path:HN.path,element:h.jsx(HN,{})})]}),h.jsx(_o,{name:"deals",...nqe}),h.jsx(_o,{name:"contacts",...Q3e}),h.jsx(_o,{name:"companies",...YDe}),h.jsx(_o,{name:"contactNotes"}),h.jsx(_o,{name:"dealNotes"}),h.jsx(_o,{name:"tasks"}),h.jsx(_o,{name:"sales",...Iqe}),h.jsx(_o,{name:"tags"})]})})})),"CRM"),Yqe=o(()=>{const[e,t]=y.useState(()=>!XRe());return e?h.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:h.jsx($ae,{open:!0,onComplete:o(()=>{t(!1)},"onComplete"),canClose:!1})}):h.jsx(Gqe,{})},"App");ese.createRoot(document.getElementById("root")).render(h.jsx(y.StrictMode,{children:h.jsx(Yqe,{})}));export{wr as $,Qs as A,Kh as B,tY as C,WY as D,JD as E,qo as F,XD as G,xn as H,zo as I,eJ as J,Ee as K,sY as L,xme as M,Qa as N,Gx as O,ie as P,HW as Q,ed as R,Ys as S,nr as T,Yo as U,rr as V,ei as W,bp as X,Rr as Y,kp as Z,Ap as _,Hg as a,Ge as a0,Oi as a1,Ri as a2,ua as a3,nd as a4,rd as a5,on as a6,Xn as a7,cy as a8,v4e as a9,rye as aA,ODe as aB,eg as aC,G3e as aD,une as aE,mw as aF,Ki as aG,Ju as aH,Cte as aI,wi as aJ,o4 as aK,O1 as aL,r4 as aM,fn as aN,i4 as aO,pTe as aP,v1 as aQ,hN as aa,Ia as ab,Ws as ac,Jte as ad,Vn as ae,zn as af,dr as ag,Kr as ah,E1 as ai,sd as aj,dn as ak,UM as al,bte as am,Vt as an,y4 as ao,Ar as ap,Uh as aq,w1 as ar,o5e as as,Sc as at,PDe as au,Yi as av,Qo as aw,$Y as ax,hte as ay,SK as az,YM as b,qG as c,fme as d,Xa as e,tt as f,rD as g,yc as h,xt as i,gc as j,Dw as k,Ct as l,h as m,Hs as n,ta as o,ry as p,yPe as q,y as r,xPe as s,_Pe as t,na as u,SPe as v,Zs as w,xw as x,Ht as y,td as z};
153
- //# sourceMappingURL=index-DcaCqEK_.js.map
153
+ //# sourceMappingURL=index-2BRppCGo.js.map