realtimex-crm 0.9.2 → 0.9.8

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.
@@ -151,7 +151,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
151
151
  L`+r+" "+r+`
152
152
  L0 `+r+`
153
153
  L`+r/2+` 0
154
- `,fill:a,opacity:s,strokeWidth:f,stroke:c===void 0?"transparent":c,style:{pointerEvents:"none"}})})},"y");function oc(){return oc=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},oc.apply(null,arguments)}i(oc,"b");var Ci={translateX:0,translateY:0,padding:0,itemsSpacing:0,itemDirection:"left-to-right",justify:!1,symbolShape:"square",symbolSize:16,symbolSpacing:8},tqe={top:0,right:0,bottom:0,left:0},T3=i(function(e){var t,n=e.direction,r=e.itemsSpacing,a=e.padding,o=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 f=typeof a=="number"?{top:a,right:a,bottom:a,left:a}:oc({},tqe,a),c=f.left+f.right,p=f.top+f.bottom,m=s+c,g=l+p,b=(o-1)*r;return n==="row"?m=s*o+b+c:n==="column"&&(g=l*o+b+p),{width:m,height:g,padding:f}},"A"),Wae=i(function(e){var t=e.anchor,n=e.translateX,r=e.translateY,a=e.containerWidth,o=e.containerHeight,s=e.width,l=e.height,f=n,c=r;switch(t){case"top":f+=(a-s)/2;break;case"top-right":f+=a-s;break;case"right":f+=a-s,c+=(o-l)/2;break;case"bottom-right":f+=a-s,c+=o-l;break;case"bottom":f+=(a-s)/2,c+=o-l;break;case"bottom-left":c+=o-l;break;case"left":c+=(o-l)/2;break;case"center":f+=(a-s)/2,c+=(o-l)/2}return{x:f,y:c}},"C"),Gae=i(function(e){var t,n,r,a,o,s,l=e.direction,f=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",f?(r=m,o="end"):(r=c+p,o="start");break;case"right-to-left":t=m-c,n=(g-c)/2,a=g/2,s="central",f?(r=0,o="start"):(r=m-c-p,o="end");break;case"top-to-bottom":t=(m-c)/2,n=0,r=m/2,o="middle",f?(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,o="middle",f?(a=0,s="text-before-edge"):(a=g-c-p,s="alphabetic")}return{symbolX:t,symbolY:n,labelX:r,labelY:a,labelAnchor:o,labelAlignment:s}},"z"),nqe={circle:X9e,diamond:Z9e,square:J9e,triangle:eqe},rqe=i(function(e){var t,n,r,a,o,s,l,f,c,p,m,g=e.x,b=e.y,w=e.width,S=e.height,_=e.data,j=e.direction,E=j===void 0?Ci.itemDirection:j,O=e.justify,C=O===void 0?Ci.justify:O,T=e.textColor,R=e.background,A=R===void 0?"transparent":R,P=e.opacity,D=P===void 0?1:P,M=e.symbolShape,I=M===void 0?Ci.symbolShape:M,F=e.symbolSize,L=F===void 0?Ci.symbolSize:F,q=e.symbolSpacing,U=q===void 0?Ci.symbolSpacing:q,$=e.symbolBorderWidth,V=$===void 0?0:$,z=e.symbolBorderColor,W=z===void 0?"transparent":z,H=e.onClick,Q=e.onMouseEnter,Y=e.onMouseLeave,K=e.toggleSerie,ee=e.effects,te=y.useState({}),oe=te[0],ne=te[1],fe=Mr(),re=y.useCallback((function(X){if(ee){var se=ee.filter((function(me){return me.on==="hover"})).reduce((function(me,Te){return oc({},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 oc({},me,Te.style)}),{});ne(se)}Y?.(_,X)}),[Y,_,ee]),he=Gae({direction:E,justify:C,symbolSize:(t=oe.symbolSize)!=null?t:L,symbolSpacing:U,width:w,height:S}),J=he.symbolX,Me=he.symbolY,we=he.labelX,Ee=he.labelY,Re=he.labelAnchor,ke=he.labelAlignment,Pe=[H,Q,Y,K].some((function(X){return X!==void 0})),Ue=typeof I=="function"?I:nqe[I];return d.jsxs("g",{transform:"translate("+g+","+b+")",style:{opacity:(n=oe.itemOpacity)!=null?n:D},children:[d.jsx("rect",{width:w,height:S,fill:(r=oe.itemBackground)!=null?r:A,style:{cursor:Pe?"pointer":"auto"},onClick:i(function(X){H?.(_,X),K?.(_.id)},"onClick"),onMouseEnter:re,onMouseLeave:ce}),y.createElement(Ue,oc({id:_.id,x:J,y:Me,size:(a=oe.symbolSize)!=null?a:L,fill:(o=(s=_.fill)!=null?s:_.color)!=null?o:"black",borderWidth:(l=oe.symbolBorderWidth)!=null?l:V,borderColor:(f=oe.symbolBorderColor)!=null?f:W},_.hidden?fe.legends.hidden.symbol:void 0)),d.jsx(V_,{textAnchor:Re,style:oc({},fe.legends.text,{fill:(c=(p=(m=oe.itemTextColor)!=null?m:T)!=null?p:fe.legends.text.fill)!=null?c:"black",dominantBaseline:ke,pointerEvents:"none",userSelect:"none"},_.hidden?fe.legends.hidden.text:void 0),x:we,y:Ee,children:_.label})]})},"B"),aqe=i(function(e){var t=e.data,n=e.x,r=e.y,a=e.direction,o=e.padding,s=o===void 0?Ci.padding:o,l=e.justify,f=e.effects,c=e.itemWidth,p=e.itemHeight,m=e.itemDirection,g=m===void 0?Ci.itemDirection:m,b=e.itemsSpacing,w=b===void 0?Ci.itemsSpacing:b,S=e.itemTextColor,_=e.itemBackground,j=_===void 0?"transparent":_,E=e.itemOpacity,O=E===void 0?1:E,C=e.symbolShape,T=e.symbolSize,R=e.symbolSpacing,A=e.symbolBorderWidth,P=e.symbolBorderColor,D=e.onClick,M=e.onMouseEnter,I=e.onMouseLeave,F=e.toggleSerie,L=T3({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 d.jsx("g",{transform:"translate("+n+","+r+")",children:t.map((function($,V){return d.jsx(rqe,{data:$,x:V*q+L.left,y:V*U+L.top,width:c,height:p,direction:g,justify:l,effects:f,textColor:S,background:j,opacity:O,symbolShape:C,symbolSize:T,symbolSpacing:R,symbolBorderWidth:A,symbolBorderColor:P,onClick:D,onMouseEnter:M,onMouseLeave:I,toggleSerie:F},V)}))})},"H"),iqe=i(function(e){var t=e.data,n=e.containerWidth,r=e.containerHeight,a=e.translateX,o=a===void 0?Ci.translateX:a,s=e.translateY,l=s===void 0?Ci.translateY:s,f=e.anchor,c=e.direction,p=e.padding,m=p===void 0?Ci.padding:p,g=e.justify,b=e.itemsSpacing,w=b===void 0?Ci.itemsSpacing:b,S=e.itemWidth,_=e.itemHeight,j=e.itemDirection,E=e.itemTextColor,O=e.itemBackground,C=e.itemOpacity,T=e.symbolShape,R=e.symbolSize,A=e.symbolSpacing,P=e.symbolBorderWidth,D=e.symbolBorderColor,M=e.onClick,I=e.onMouseEnter,F=e.onMouseLeave,L=e.toggleSerie,q=e.effects,U=T3({itemCount:t.length,itemsSpacing:w,itemWidth:S,itemHeight:_,direction:c,padding:m}),$=U.width,V=U.height,z=Wae({anchor:f,translateX:o,translateY:l,containerWidth:n,containerHeight:r,width:$,height:V}),W=z.x,H=z.y;return d.jsx(aqe,{data:t,x:W,y:H,direction:c,padding:m,justify:g,effects:q,itemsSpacing:w,itemWidth:S,itemHeight:_,itemDirection:j,itemTextColor:E,itemBackground:O,itemOpacity:C,symbolShape:T,symbolSize:R,symbolSpacing:A,symbolBorderWidth:P,symbolBorderColor:D,onClick:M,onMouseEnter:I,onMouseLeave:F,toggleSerie:typeof L=="boolean"?void 0:L})},"E"),oqe={start:"left",middle:"center",end:"right"},sqe=i(function(e,t){var n=t.data,r=t.containerWidth,a=t.containerHeight,o=t.translateX,s=o===void 0?0:o,l=t.translateY,f=l===void 0?0:l,c=t.anchor,p=t.direction,m=t.padding,g=m===void 0?0:m,b=t.justify,w=b!==void 0&&b,S=t.itemsSpacing,_=S===void 0?0:S,j=t.itemWidth,E=t.itemHeight,O=t.itemDirection,C=O===void 0?"left-to-right":O,T=t.itemTextColor,R=t.symbolSize,A=R===void 0?16:R,P=t.symbolSpacing,D=P===void 0?8:P,M=t.theme,I=T3({itemCount:n.length,itemWidth:j,itemHeight:E,itemsSpacing:_,direction:p,padding:g}),F=I.width,L=I.height,q=I.padding,U=Wae({anchor:c,translateX:s,translateY:f,containerWidth:r,containerHeight:a,width:F,height:L}),$=U.x,V=U.y,z=p==="row"?j+_:0,W=p==="column"?E+_:0;e.save(),e.translate($,V),Ig(e,M.legends.text),n.forEach((function(H,Q){var Y,K=Q*z+q.left,ee=Q*W+q.top,te=Gae({direction:C,justify:w,symbolSize:A,symbolSpacing:D,width:j,height:E}),oe=te.symbolX,ne=te.symbolY,fe=te.labelX,re=te.labelY,ce=te.labelAnchor,he=te.labelAlignment;e.fillStyle=(Y=H.color)!=null?Y:"black",e.fillRect(K+oe,ee+ne,A,A),e.textAlign=oqe[ce],he==="central"&&(e.textBaseline="middle"),Fg(e,oc({},M.legends.text,{fill:T??M.legends.text.fill}),String(H.label),K+fe,ee+re)})),e.restore()},"L"),lqe=i(function(e,t,n,r,a,o){o>0?(e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.quadraticCurveTo(t+r,n,t+r,n+o),e.lineTo(t+r,n+a-o),e.quadraticCurveTo(t+r,n+a,t+r-o,n+a),e.lineTo(t+o,n+a),e.quadraticCurveTo(t,n+a,t,n+a-o),e.lineTo(t,n+o),e.quadraticCurveTo(t,n,t+o,n),e.closePath()):e.rect(t,n,r,a)},"o");function vn(){return vn=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},vn.apply(null,arguments)}i(vn,"Q");function Fc(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}i(Fc,"U");var hW,cqe=i(function(e){var t=e.bars,n=e.annotations,r=Uae({data:t,annotations:n,getPosition:i(function(a){return{x:a.x+a.width/2,y:a.y+a.height/2}},"getPosition"),getDimensions:i(function(a){var o=a.height,s=a.width;return{width:s,height:o,size:Math.max(s,o)}},"getDimensions")});return d.jsx(d.Fragment,{children:r.map((function(a,o){return d.jsx(D9e,vn({},a),o)}))})},"$"),uqe=i(function(e){var t=e.width,n=e.height,r=e.legends,a=e.toggleSerie;return d.jsx(d.Fragment,{children:r.map((function(o,s){var l,f=o[0],c=o[1];return d.jsx(iqe,vn({},f,{containerWidth:t,containerHeight:n,data:(l=f.data)!=null?l:c,toggleSerie:f.toggleSerie&&f.dataFrom==="keys"?a:void 0}),s)}))})},"ee"),dqe=["data"],fqe=i(function(e){var t,n=e.bar,r=n.data,a=Fc(n,dqe),o=e.style,s=o.borderColor,l=o.color,f=o.height,c=o.labelColor,p=o.labelOpacity,m=o.labelX,g=o.labelY,b=o.transform,w=o.width,S=o.textAnchor,_=e.borderRadius,j=e.borderWidth,E=e.label,O=e.shouldRenderLabel,C=e.isInteractive,T=e.onClick,R=e.onMouseEnter,A=e.onMouseLeave,P=e.tooltip,D=e.isFocusable,M=e.ariaLabel,I=e.ariaLabelledBy,F=e.ariaDescribedBy,L=e.ariaDisabled,q=e.ariaHidden,U=Mr(),$=wre(),V=$.showTooltipFromEvent,z=$.showTooltipAt,W=$.hideTooltip,H=y.useMemo((function(){return function(){return y.createElement(P,vn({},a,r))}}),[P,a,r]),Q=y.useCallback((function(ne){T?.(vn({color:a.color},r),ne)}),[a,r,T]),Y=y.useCallback((function(ne){return V(H(),ne)}),[V,H]),K=y.useCallback((function(ne){R?.(r,ne),V(H(),ne)}),[r,R,V,H]),ee=y.useCallback((function(ne){A?.(r,ne),W()}),[r,W,A]),te=y.useCallback((function(){z(H(),[a.absX+a.width/2,a.absY])}),[z,H,a]),oe=y.useCallback((function(){W()}),[W]);return d.jsxs(pr.g,{transform:b,children:[d.jsx(pr.rect,{width:UN(w,(function(ne){return Math.max(ne,0)})),height:UN(f,(function(ne){return Math.max(ne,0)})),rx:_,ry:_,fill:(t=r.fill)!=null?t:l,strokeWidth:j,stroke:s,focusable:D,tabIndex:D?0:void 0,"aria-label":M?M(r):void 0,"aria-labelledby":I?I(r):void 0,"aria-describedby":F?F(r):void 0,"aria-disabled":L?L(r):void 0,"aria-hidden":q?q(r):void 0,onMouseEnter:C?K:void 0,onMouseMove:C?Y:void 0,onMouseLeave:C?ee:void 0,onClick:C?Q:void 0,onFocus:C&&D?te:void 0,onBlur:C&&D?oe:void 0,"data-testid":"bar.item."+r.id+"."+r.index}),O&&d.jsx(V_,{x:m,y:g,textAnchor:S,dominantBaseline:"central",fillOpacity:p,style:vn({},U.labels.text,{pointerEvents:"none",fill:c}),children:E})]})},"ae"),hqe=["color","label"],pqe=i(function(e){var t=e.color,n=e.label,r=Fc(e,hqe);return d.jsx(D8e,{id:n,value:r.formattedValue,enableChip:!0,color:t})},"ne"),Fn={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:pqe,tooltipLabel:i(function(e){return e.id+" - "+e.indexValue},"tooltipLabel"),legends:[],initialHiddenIds:[],annotations:[],enableTotals:!1,totalsOffset:10},In=vn({},Fn,{layers:["grid","axes","bars","totals","markers","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},barComponent:fqe,defs:[],fill:[],markers:[],animate:!0,animateOnMount:!1,motionConfig:"default",role:"img",isFocusable:!1}),gr=vn({},Fn,{layers:["grid","axes","bars","totals","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},renderBar:i(function(e,t){var n=t.bar,r=n.color,a=n.height,o=n.width,s=n.x,l=n.y,f=t.borderColor,c=t.borderRadius,p=t.borderWidth,m=t.label,g=t.shouldRenderLabel,b=t.labelStyle,w=t.labelX,S=t.labelY,_=t.textAnchor;e.fillStyle=r,p>0&&(e.strokeStyle=f,e.lineWidth=p),e.beginPath(),lqe(e,s,l,o,a,Math.min(c,a)),e.fill(),p>0&&e.stroke(),g&&(e.textBaseline="middle",e.textAlign=_==="middle"?"center":_,Fg(e,b,m,s+w,l+S))},"renderBar"),pixelRatio:typeof window<"u"&&(hW=window.devicePixelRatio)!=null?hW:1}),Kae=i(function(e,t,n,r,a,o){return A3(r,{all:e.map(t),min:0,max:0},a,o).padding(n)},"de"),Yae=i(function(e,t){return e.map((function(n){return vn({},t.reduce((function(r,a){return r[a]=null,r}),{}),n)}))},"ue"),H_=i(function(e){return Object.keys(e).reduce((function(t,n){return e[n]&&(t[n]=e[n]),t}),{})},"se"),W_=i(function(e){return[e,Number(e)]},"ce");function Qae(e,t,n,r){return e===void 0&&(e=Fn.layout),n===void 0&&(n=Fn.labelPosition),r===void 0&&(r=Fn.labelOffset),function(a,o){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:o/2,textAnchor:n==="middle"?"middle":t?"end":"start"}}var f=o/2;return n==="start"?f=t?0:o:n==="end"&&(f=t?o:0),{labelX:a/2,labelY:f-s,textAnchor:"middle"}}}i(Qae,"he");var mqe=["layout","width","height","padding","innerPadding","valueScale","indexScale","hiddenIds"],P3=i(function(e,t){return e>t},"be"),Xae=i(function(e,t){return e<t},"ge"),Zae=i(function(e,t){return Array.from(" ".repeat(t-e),(function(n,r){return e+r}))},"ve"),vqe=i(function(e){return P3(e,0)?0:e},"me"),gqe=i(function(e,t,n,r){var a=e.data,o=e.formatValue,s=e.getColor,l=e.getIndex,f=e.getTooltipLabel,c=e.innerPadding,p=c===void 0?0:c,m=e.keys,g=e.xScale,b=e.yScale,w=e.margin,S=n?Xae:P3,_=a.map(H_),j=[];return m.forEach((function(E,O){return Zae(0,g.domain().length).forEach((function(C){var T,R,A,P=W_(a[C][E]),D=P[0],M=P[1],I=l(a[C]),F=((T=g(I))!=null?T:0)+t*O+p*O,L=S(R=M,0)?(A=b(R))!=null?A:0:r,q=(function($,V){var z;return S($,0)?r-V:((z=b($))!=null?z:0)-r})(M,L),U={id:E,value:D===null?D:M,formattedValue:o(M),hidden:!1,index:C,indexValue:I,data:_[C]};j.push({key:E+"."+U.indexValue,index:j.length,data:U,x:F,y:L,absX:w.left+F,absY:w.top+L,width:t,height:q,color:s(U),label:f(U)})}))})),j},"pe"),yqe=i(function(e,t,n,r){var a=e.data,o=e.formatValue,s=e.getIndex,l=e.getColor,f=e.getTooltipLabel,c=e.keys,p=e.innerPadding,m=p===void 0?0:p,g=e.xScale,b=e.yScale,w=e.margin,S=n?Xae:P3,_=a.map(H_),j=[];return c.forEach((function(E,O){return Zae(0,b.domain().length).forEach((function(C){var T,R,A,P=W_(a[C][E]),D=P[0],M=P[1],I=s(a[C]),F=S(R=M,0)?r:(A=g(R))!=null?A:0,L=((T=b(I))!=null?T:0)+t*O+m*O,q=(function($,V){var z;return S($,0)?((z=g($))!=null?z:0)-r:r-V})(M,F),U={id:E,value:D===null?D:M,formattedValue:o(M),hidden:!1,index:C,indexValue:I,data:_[C]};j.push({key:E+"."+U.indexValue,index:j.length,data:U,x:F,y:L,absX:w.left+F,absY:w.top+L,width:q,height:t,color:l(U),label:f(U)})}))})),j},"ye"),bqe=i(function(e){var t,n,r,a=e.layout,o=e.width,s=e.height,l=e.padding,f=l===void 0?0:l,c=e.innerPadding,p=c===void 0?0:c,m=e.valueScale,g=e.indexScale,b=e.hiddenIds,w=b===void 0?[]:b,S=Fc(e,mqe),_=S.keys.filter((function(V){return!w.includes(V)})),j=Yae(S.data,_),E=a==="vertical"?["y","x",o]:["x","y",s],O=E[0],C=E[1],T=E[2],R=Kae(j,S.getIndex,f,g,T,C),A=m.min==="auto"?vqe:function(V){return V},P=j.reduce((function(V,z){return[].concat(V,_.map((function(W){return z[W]})))}),[]).filter(Boolean),D=A(Math.min.apply(Math,P)),M=(r=Math.max.apply(Math,P),isFinite(r)?r:0),I=A3(m,{all:P,min:D,max:M},O==="x"?o:s,O),F=a==="vertical"?[R,I]:[I,R],L=F[0],q=F[1],U=(R.bandwidth()-p*(_.length-1))/_.length,$=[vn({},S,{data:j,keys:_,innerPadding:p,xScale:L,yScale:q}),U,(t=m.reverse)!=null&&t,(n=I(0))!=null?n:0];return{xScale:L,yScale:q,bars:U>0?a==="vertical"?gqe.apply(void 0,$):yqe.apply(void 0,$):[]}},"xe"),xqe=["data","layout","width","height","padding","valueScale","indexScale","hiddenIds"],Jae=i(function(e){var t;return e.some(Array.isArray)?Jae((t=[]).concat.apply(t,e)):e},"ke"),wqe=i(function(e,t,n){var r=e.formatValue,a=e.getColor,o=e.getIndex,s=e.getTooltipLabel,l=e.innerPadding,f=e.stackedData,c=e.xScale,p=e.yScale,m=e.margin,g=[];return f.forEach((function(b){return c.domain().forEach((function(w,S){var _,j,E=b[S],O=(_=c(o(E.data)))!=null?_:0,C=((j=(function(M){return p(M[n?0:1])})(E))!=null?j:0)+.5*l,T=(function(M,I){var F;return((F=p(M[n?1:0]))!=null?F:0)-I})(E,C)-l,R=W_(E.data[b.key]),A=R[0],P=R[1],D={id:b.key,value:A===null?A:P,formattedValue:r(P),hidden:!1,index:S,indexValue:w,data:H_(E.data)};g.push({key:b.key+"."+w,index:g.length,data:D,x:O,y:C,absX:m.left+O,absY:m.top+C,width:t,height:T,color:a(D),label:s(D)})}))})),g},"we"),_qe=i(function(e,t,n){var r=e.formatValue,a=e.getColor,o=e.getIndex,s=e.getTooltipLabel,l=e.innerPadding,f=e.stackedData,c=e.xScale,p=e.yScale,m=e.margin,g=[];return f.forEach((function(b){return p.domain().forEach((function(w,S){var _,j,E=b[S],O=(_=p(o(E.data)))!=null?_:0,C=((j=(function(M){return c(M[n?1:0])})(E))!=null?j:0)+.5*l,T=(function(M,I){var F;return((F=c(M[n?0:1]))!=null?F:0)-I})(E,C)-l,R=W_(E.data[b.key]),A=R[0],P=R[1],D={id:b.key,value:A===null?A:P,formattedValue:r(P),hidden:!1,index:S,indexValue:w,data:H_(E.data)};g.push({key:b.key+"."+w,index:g.length,data:D,x:C,y:O,absX:m.left+C,absY:m.top+O,width:T,height:t,color:a(D),label:s(D)})}))})),g},"Le"),Sqe=i(function(e){var t,n,r=e.data,a=e.layout,o=e.width,s=e.height,l=e.padding,f=l===void 0?0:l,c=e.valueScale,p=e.indexScale,m=e.hiddenIds,g=m===void 0?[]:m,b=Fc(e,xqe),w=b.keys.filter((function(U){return!g.includes(U)})),S=GIe().keys(w).offset(KIe)(Yae(r,w)),_=a==="vertical"?["y","x",o]:["x","y",s],j=_[0],E=_[1],O=_[2],C=Kae(r,b.getIndex,f,p,O,E),T=(n=Jae(S),c.type==="log"?n.filter((function(U){return U!==0})):n),R=Math.min.apply(Math,T),A=Math.max.apply(Math,T),P=A3(c,{all:T,min:R,max:A},j==="x"?o:s,j),D=a==="vertical"?[C,P]:[P,C],M=D[0],I=D[1],F=b.innerPadding>0?b.innerPadding:0,L=C.bandwidth(),q=[vn({},b,{innerPadding:F,stackedData:S,xScale:M,yScale:I}),L,(t=c.reverse)!=null&&t];return{xScale:M,yScale:I,bars:L>0?a==="vertical"?wqe.apply(void 0,q):_qe.apply(void 0,q):[]}},"Ce"),jqe=i(function(e){var t=e.bars,n=e.direction,r=e.from,a=e.groupMode,o=e.layout,s=e.legendLabel,l=e.reverse,f=Pae(s??(r==="indexes"?"indexValue":"id"));return r==="indexes"?(function(c,p,m){var g=qH(c.map((function(b){var w,S;return{id:(w=b.data.indexValue)!=null?w:"",label:m(b.data),hidden:b.data.hidden,color:(S=b.color)!=null?S:"#000"}})),(function(b){return b.id}));return p==="horizontal"&&g.reverse(),g})(t,o,f):(function(c,p,m,g,b,w){var S=qH(c.map((function(_){var j;return{id:_.data.id,label:w(_.data),hidden:_.data.hidden,color:(j=_.color)!=null?j:"#000"}})),(function(_){return _.id}));return(p==="vertical"&&g==="stacked"&&m==="column"&&b!==!0||p==="horizontal"&&g==="stacked"&&b===!0)&&S.reverse(),S})(t,o,n,a,l,f)},"We"),pW=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+n)},"Me"),Eqe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+(n>0?n:0))},"Be"),Cqe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,Math.max(r,Number(n)))},"Re"),Oqe=i(function(e,t){var n=e.get(t)||0;e.set(t,n+1)},"Oe"),eie=i(function(e){var t,n=e.indexBy,r=n===void 0?Fn.indexBy:n,a=e.keys,o=a===void 0?Fn.keys:a,s=e.label,l=s===void 0?Fn.label:s,f=e.tooltipLabel,c=f===void 0?Fn.tooltipLabel:f,p=e.valueFormat,m=e.colors,g=m===void 0?Fn.colors:m,b=e.colorBy,w=b===void 0?Fn.colorBy:b,S=e.borderColor,_=S===void 0?Fn.borderColor:S,j=e.labelTextColor,E=j===void 0?Fn.labelTextColor:j,O=e.groupMode,C=O===void 0?Fn.groupMode:O,T=e.layout,R=T===void 0?Fn.layout:T,A=e.data,P=e.margin,D=e.width,M=e.height,I=e.padding,F=I===void 0?Fn.padding:I,L=e.innerPadding,q=L===void 0?Fn.innerPadding:L,U=e.valueScale,$=U===void 0?Fn.valueScale:U,V=e.indexScale,z=V===void 0?Fn.indexScale:V,W=e.initialHiddenIds,H=W===void 0?Fn.initialHiddenIds:W,Q=e.enableLabel,Y=Q===void 0?Fn.enableLabel:Q,K=e.labelSkipWidth,ee=K===void 0?Fn.labelSkipWidth:K,te=e.labelSkipHeight,oe=te===void 0?Fn.labelSkipHeight:te,ne=e.legends,fe=ne===void 0?Fn.legends:ne,re=e.legendLabel,ce=e.totalsOffset,he=ce===void 0?Fn.totalsOffset:ce,J=y.useState(H??[]),Me=J[0],we=J[1],Ee=y.useCallback((function(Ke){we((function(pt){return pt.indexOf(Ke)>-1?pt.filter((function(ge){return ge!==Ke})):[].concat(pt,[Ke])}))}),[]),Re=zA(r),ke=zA(l),Pe=zA(c),Ue=R3(p),X=Mr(),se=Q9e(g,w),me=fW(_,X),Te=fW(E,X),de=(C==="grouped"?bqe:Sqe)({layout:R,data:A,getIndex:Re,keys:o,width:D,height:M,getColor:se,padding:F,innerPadding:q,valueScale:$,indexScale:z,hiddenIds:Me,formatValue:Ue,getTooltipLabel:Pe,margin:P}),ue=de.bars,Ae=de.xScale,Ne=de.yScale,Fe=y.useMemo((function(){return ue.filter((function(Ke){return Ke.data.value!==null})).map((function(Ke,pt){return vn({},Ke,{index:pt})}))}),[ue]),Je=y.useCallback((function(Ke){var pt=Ke.width,ge=Ke.height;return!!Y&&!(ee>0&&pt<ee)&&!(oe>0&&ge<oe)}),[Y,ee,oe]),Pt=y.useMemo((function(){return o.map((function(Ke){var pt=ue.find((function(ge){return ge.data.id===Ke}));return vn({},pt,{data:vn({id:Ke},pt?.data,{hidden:Me.includes(Ke)})})}))}),[Me,o,ue]),$t=(t=$.reverse)!=null&&t,Rt=y.useMemo((function(){return fe.map((function(Ke){return[Ke,jqe({bars:Ke.dataFrom==="keys"?Pt:ue,direction:Ke.direction,from:Ke.dataFrom,groupMode:C,layout:R,legendLabel:re,reverse:$t})]}))}),[fe,Pt,ue,C,R,re,$t]),qt=y.useMemo((function(){return(function(Ke,pt,ge,ye,ct,Le,Xe){ye===void 0&&(ye=Fn.layout),ct===void 0&&(ct=Fn.groupMode);var We=[];if(Ke.length===0)return We;var et=new Map,jt=Ke[0].width,Ye=Ke[0].height;if(ct==="stacked"){var mt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Ct=_t.value;pW(et,vt,Number(Ct)),Eqe(mt,vt,Number(Ct))})),mt.forEach((function(At,_t){var vt,Ct,Z,pe=et.get(_t)||0;ye==="vertical"?(vt=pt(_t),Ct=ge(At),Z=ge(At/2)):(vt=pt(At),Ct=ge(_t),Z=pt(At/2)),vt+=ye==="vertical"?jt/2:Le,Ct+=ye==="vertical"?-Le:Ye/2,We.push({key:"total_"+_t,x:vt,y:Ct,value:pe,formattedValue:Xe(pe),animationOffset:Z})}))}else if(ct==="grouped"){var Ft=new Map,Nt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Ct=_t.value;pW(et,vt,Number(Ct)),Cqe(Ft,vt,Number(Ct)),Oqe(Nt,vt)})),Ft.forEach((function(At,_t){var vt,Ct,Z,pe=et.get(_t)||0,_e=Nt.get(_t);ye==="vertical"?(vt=pt(_t),Ct=ge(At),Z=ge(At/2)):(vt=pt(At),Ct=ge(_t),Z=pt(At/2)),vt+=ye==="vertical"?_e*jt/2:Le,Ct+=ye==="vertical"?-Le:_e*Ye/2,We.push({key:"total_"+_t,x:vt,y:Ct,value:pe,formattedValue:Xe(pe),animationOffset:Z})}))}return We})(ue,Ae,Ne,R,C,he,Ue)}),[ue,Ae,Ne,R,C,he,Ue]);return{bars:ue,barsWithValue:Fe,xScale:Ae,yScale:Ne,getIndex:Re,getLabel:ke,getTooltipLabel:Pe,formatValue:Ue,getColor:se,getBorderColor:me,getLabelColor:Te,shouldRenderBarLabel:Je,hiddenIds:Me,toggleSerie:Ee,legendsWithData:Rt,barTotals:qt}},"Ie"),kqe=i(function(e){var t=e.data,n=e.springConfig,r=e.animate,a=e.layout,o=a===void 0?In.layout:a,s=Mr();return o_(t,{keys:i(function(l){return l.key},"keys"),from:i(function(l){return{x:o==="vertical"?l.x:l.animationOffset,y:o==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"from"),enter:i(function(l){return{x:l.x,y:l.y,labelOpacity:1}},"enter"),update:i(function(l){return{x:l.x,y:l.y,labelOpacity:1}},"update"),leave:i(function(l){return{x:o==="vertical"?l.x:l.animationOffset,y:o==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"leave"),config:n,immediate:!r,initial:r?void 0:null})((function(l,f){return d.jsx(pr.text,{x:l.x,y:l.y,fillOpacity:l.labelOpacity,style:vn({},s.labels.text,{pointerEvents:"none"}),fontWeight:"bold",fontSize:s.labels.text.fontSize,fontFamily:s.labels.text.fontFamily,textAnchor:o==="vertical"?"middle":"start",alignmentBaseline:o==="vertical"?"alphabetic":"middle",children:f.formattedValue},f.key)}))},"Ve"),Rqe=["isInteractive","animate","motionConfig","theme","renderWrapper"],Aqe=i(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,o=e.margin,s=e.width,l=e.height,f=e.groupMode,c=e.layout,p=e.valueScale,m=e.indexScale,g=e.padding,b=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,j=_===void 0?In.axisBottom:_,E=e.axisLeft,O=E===void 0?In.axisLeft:E,C=e.enableGridX,T=C===void 0?In.enableGridX:C,R=e.enableGridY,A=R===void 0?In.enableGridY:R,P=e.gridXValues,D=e.gridYValues,M=e.layers,I=M===void 0?In.layers:M,F=e.barComponent,L=F===void 0?In.barComponent:F,q=e.enableLabel,U=q===void 0?In.enableLabel:q,$=e.label,V=e.labelSkipWidth,z=V===void 0?In.labelSkipWidth:V,W=e.labelSkipHeight,H=W===void 0?In.labelSkipHeight:W,Q=e.labelTextColor,Y=e.labelPosition,K=Y===void 0?In.labelPosition:Y,ee=e.labelOffset,te=ee===void 0?In.labelOffset:ee,oe=e.markers,ne=oe===void 0?In.markers:oe,fe=e.colorBy,re=e.colors,ce=e.defs,he=ce===void 0?In.defs:ce,J=e.fill,Me=J===void 0?In.fill:J,we=e.borderRadius,Ee=we===void 0?In.borderRadius:we,Re=e.borderWidth,ke=Re===void 0?In.borderWidth:Re,Pe=e.borderColor,Ue=e.annotations,X=Ue===void 0?In.annotations:Ue,se=e.legendLabel,me=e.tooltipLabel,Te=e.valueFormat,de=e.isInteractive,ue=de===void 0?In.isInteractive:de,Ae=e.tooltip,Ne=Ae===void 0?In.tooltip:Ae,Fe=e.onClick,Je=e.onMouseEnter,Pt=e.onMouseLeave,$t=e.legends,Rt=e.role,qt=Rt===void 0?In.role:Rt,Ke=e.ariaLabel,pt=e.ariaLabelledBy,ge=e.ariaDescribedBy,ye=e.isFocusable,ct=ye===void 0?In.isFocusable:ye,Le=e.barAriaLabel,Xe=e.barAriaLabelledBy,We=e.barAriaDescribedBy,et=e.barAriaHidden,jt=e.barAriaDisabled,Ye=e.initialHiddenIds,mt=e.enableTotals,Ft=mt===void 0?In.enableTotals:mt,Nt=e.totalsOffset,At=Nt===void 0?In.totalsOffset:Nt,_t=e.forwardedRef,vt=ho(),Ct=vt.animate,Z=vt.config,pe=Tae(s,l,o),_e=pe.outerWidth,$e=pe.outerHeight,Ve=pe.margin,rt=pe.innerWidth,nt=pe.innerHeight,Qe=eie({indexBy:r,label:$,tooltipLabel:me,valueFormat:Te,colors:re,colorBy:fe,borderColor:Pe,labelTextColor:Q,groupMode:f,layout:c,data:n,keys:a,margin:Ve,width:rt,height:nt,padding:g,innerPadding:b,valueScale:p,indexScale:m,enableLabel:U,labelSkipWidth:z,labelSkipHeight:H,legends:$t,legendLabel:se,initialHiddenIds:Ye,totalsOffset:At}),ot=Qe.bars,ut=Qe.barsWithValue,st=Qe.xScale,lt=Qe.yScale,gt=Qe.getLabel,at=Qe.getTooltipLabel,kt=Qe.getBorderColor,bt=Qe.getLabelColor,Lt=Qe.shouldRenderBarLabel,Mt=Qe.toggleSerie,Fr=Qe.legendsWithData,Oa=Qe.barTotals,li=Qe.getColor,cr=Qae(c,(t=p?.reverse)!=null&&t,K,te),po=o_(ut,{keys:i(function(He){return He.key},"keys"),from:i(function(He){return vn({borderColor:kt(He),color:He.color,height:0,labelColor:bt(He),labelOpacity:0},cr(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:i(function(He){return vn({borderColor:kt(He),color:He.color,height:He.height,labelColor:bt(He),labelOpacity:1},cr(He.width,He.height),{transform:"translate("+He.x+", "+He.y+")",width:He.width})},"enter"),update:i(function(He){return vn({borderColor:kt(He),color:He.color,height:He.height,labelColor:bt(He),labelOpacity:1},cr(He.width,He.height),{transform:"translate("+He.x+", "+He.y+")",width:He.width})},"update"),leave:i(function(He){return vn({borderColor:kt(He),color:He.color,height:0,labelColor:bt(He),labelOpacity:0},cr(He.width,He.height),{labelY:0,transform:"translate("+He.x+", "+(He.y+He.height)+")",width:He.width},c==="vertical"?{}:vn({},cr(He.width,He.height),{labelX:0,height:He.height,transform:"translate("+He.x+", "+He.y+")",width:0}))},"leave"),config:Z,immediate:!Ct,initial:Ct?void 0:null}),Lr=y.useMemo((function(){return{borderRadius:Ee,borderWidth:ke,enableLabel:U,isInteractive:ue,labelSkipWidth:z,labelSkipHeight:H,onClick:Fe,onMouseEnter:Je,onMouseLeave:Pt,getTooltipLabel:at,tooltip:Ne,isFocusable:ct,ariaLabel:Le,ariaLabelledBy:Xe,ariaDescribedBy:We,ariaHidden:et,ariaDisabled:jt}}),[Ee,ke,U,at,ue,H,z,Fe,Je,Pt,Ne,ct,Le,Xe,We,et,jt]),Ha=O7e(he,ot,Me,{dataKey:"data",targetKey:"data.fill"}),Zr={annotations:null,axes:null,bars:null,grid:null,legends:null,markers:null,totals:null};I.includes("annotations")&&(Zr.annotations=d.jsx(cqe,{bars:ot,annotations:X},"annotations")),I.includes("axes")&&(Zr.axes=d.jsx(s9e,{xScale:st,yScale:lt,width:rt,height:nt,top:w,right:S,bottom:j,left:O},"axes")),I.includes("bars")&&(Zr.bars=d.jsx(y.Fragment,{children:po((function(He,$n){return y.createElement(L,vn({},Lr,{bar:$n,style:He,shouldRenderLabel:Lt($n),label:gt($n.data)}))}))},"bars")),I.includes("grid")&&(Zr.grid=d.jsx(c9e,{width:rt,height:nt,xScale:T?st:null,yScale:A?lt:null,xValues:P,yValues:D},"grid")),I.includes("legends")&&(Zr.legends=d.jsx(uqe,{width:rt,height:nt,legends:Fr,toggleSerie:Mt},"legends")),I.includes("markers")&&(Zr.markers=d.jsx(g7e,{markers:ne,width:rt,height:nt,xScale:st,yScale:lt},"markers")),I.includes("totals")&&Ft&&(Zr.totals=d.jsx(kqe,{data:Oa,springConfig:Z,animate:Ct,layout:c},"totals"));var Wa=vn({},Lr,{margin:Ve,width:s,height:l,innerWidth:rt,innerHeight:nt,bars:ot,legendData:Fr,enableLabel:U,xScale:st,yScale:lt,tooltip:Ne,getTooltipLabel:at,onClick:Fe,onMouseEnter:Je,onMouseLeave:Pt,getColor:li});return d.jsx(p7e,{width:_e,height:$e,margin:Ve,defs:Ha,role:qt,ariaLabel:Ke,ariaLabelledBy:pt,ariaDescribedBy:ge,isFocusable:ct,ref:_t,children:I.map((function(He,$n){var Ii;return typeof He=="function"?d.jsx(y.Fragment,{children:y.createElement(He,Wa)},$n):(Ii=Zr?.[He])!=null?Ii:null}))})},"He"),Tqe=y.forwardRef((function(e,t){var n=e.isInteractive,r=n===void 0?In.isInteractive:n,a=e.animate,o=a===void 0?In.animate:a,s=e.motionConfig,l=s===void 0?In.motionConfig:s,f=e.theme,c=e.renderWrapper,p=Fc(e,Rqe);return d.jsx(Cae,{animate:o,isInteractive:r,motionConfig:l,renderWrapper:c,theme:f,children:d.jsx(Aqe,vn({},p,{isInteractive:r,forwardedRef:t}))})})),Pqe=["isInteractive","renderWrapper","theme"],dT=i(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"),Nqe=i(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,o=e.margin,s=e.width,l=e.height,f=e.groupMode,c=e.layout,p=e.valueScale,m=e.indexScale,g=e.padding,b=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,j=_===void 0?gr.axisBottom:_,E=e.axisLeft,O=E===void 0?gr.axisLeft:E,C=e.enableGridX,T=C===void 0?gr.enableGridX:C,R=e.enableGridY,A=R===void 0?gr.enableGridY:R,P=e.gridXValues,D=e.gridYValues,M=e.labelPosition,I=M===void 0?gr.labelPosition:M,F=e.labelOffset,L=F===void 0?gr.labelOffset:F,q=e.layers,U=q===void 0?gr.layers:q,$=e.renderBar,V=$===void 0?gr.renderBar:$,z=e.enableLabel,W=z===void 0?gr.enableLabel:z,H=e.label,Q=e.labelSkipWidth,Y=Q===void 0?gr.labelSkipWidth:Q,K=e.labelSkipHeight,ee=K===void 0?gr.labelSkipHeight:K,te=e.labelTextColor,oe=e.colorBy,ne=e.colors,fe=e.borderRadius,re=fe===void 0?gr.borderRadius:fe,ce=e.borderWidth,he=ce===void 0?gr.borderWidth:ce,J=e.borderColor,Me=e.annotations,we=Me===void 0?gr.annotations:Me,Ee=e.legendLabel,Re=e.tooltipLabel,ke=e.valueFormat,Pe=e.isInteractive,Ue=Pe===void 0?gr.isInteractive:Pe,X=e.tooltip,se=X===void 0?gr.tooltip:X,me=e.onClick,Te=e.onMouseEnter,de=e.onMouseLeave,ue=e.legends,Ae=e.pixelRatio,Ne=Ae===void 0?gr.pixelRatio:Ae,Fe=e.role,Je=e.forwardedRef,Pt=e.enableTotals,$t=Pt===void 0?gr.enableTotals:Pt,Rt=e.totalsOffset,qt=Rt===void 0?gr.totalsOffset:Rt,Ke=y.useRef(null),pt=Mr(),ge=Tae(s,l,o),ye=ge.margin,ct=ge.innerWidth,Le=ge.innerHeight,Xe=ge.outerWidth,We=ge.outerHeight,et=eie({indexBy:r,label:H,tooltipLabel:Re,valueFormat:ke,colors:ne,colorBy:oe,borderColor:J,labelTextColor:te,groupMode:f,layout:c,data:n,keys:a,margin:ye,width:ct,height:Le,padding:g,innerPadding:b,valueScale:p,indexScale:m,enableLabel:W,labelSkipWidth:Y,labelSkipHeight:ee,legends:ue,legendLabel:Ee,totalsOffset:qt}),jt=et.bars,Ye=et.barsWithValue,mt=et.xScale,Ft=et.yScale,Nt=et.getLabel,At=et.getTooltipLabel,_t=et.getBorderColor,vt=et.getLabelColor,Ct=et.shouldRenderBarLabel,Z=et.legendsWithData,pe=et.barTotals,_e=et.getColor,$e=wre(),Ve=$e.showTooltipFromEvent,rt=$e.hideTooltip,nt=k9e({annotations:Uae({data:jt,annotations:we,getPosition:i(function(at){return{x:at.x,y:at.y}},"getPosition"),getDimensions:i(function(at){var kt=at.width,bt=at.height;return{width:kt,height:bt,size:Math.max(kt,bt)}},"getDimensions")})}),Qe=y.useMemo((function(){return{borderRadius:re,borderWidth:he,isInteractive:Ue,isFocusable:!1,labelSkipWidth:Y,labelSkipHeight:ee,margin:ye,width:s,height:l,innerWidth:ct,innerHeight:Le,bars:jt,legendData:Z,enableLabel:W,xScale:mt,yScale:Ft,tooltip:se,getTooltipLabel:At,onClick:me,onMouseEnter:Te,onMouseLeave:de,getColor:_e}}),[re,he,Ue,Y,ee,ye,s,l,ct,Le,jt,Z,W,mt,Ft,se,At,me,Te,de,_e]),ot=R3(ke),ut=Qae(c,(t=p?.reverse)!=null&&t,I,L);y.useEffect((function(){if(Ke.current){Ke.current.width=Xe*Ne,Ke.current.height=We*Ne;var at=Ke.current.getContext("2d");at.scale(Ne,Ne),at.fillStyle=pt.background,at.fillRect(0,0,Xe,We),at.translate(ye.left,ye.top),U.forEach((function(kt){kt==="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&&JH(at,{width:ct,height:Le,scale:mt,axis:"x",values:P}),A&&JH(at,{width:ct,height:Le,scale:Ft,axis:"y",values:D})):kt==="axes"?d9e(at,{xScale:mt,yScale:Ft,width:ct,height:Le,top:w,right:S,bottom:j,left:O,theme:pt}):kt==="bars"?(Ig(at,pt.text),Ye.forEach((function(bt){V(at,vn({bar:bt,borderColor:_t(bt),borderRadius:re,borderWidth:he,label:Nt(bt.data),shouldRenderLabel:Ct(bt),labelStyle:vn({},pt.labels.text,{fill:vt(bt)})},ut(bt.width,bt.height)))}))):kt==="legends"?Z.forEach((function(bt){var Lt=bt[0],Mt=bt[1];sqe(at,vn({},Lt,{data:Mt,containerWidth:ct,containerHeight:Le,theme:pt}))})):kt==="annotations"?M9e(at,{annotations:nt,theme:pt}):kt==="totals"&&$t?(function(bt,Lt,Mt,Fr){Fr===void 0&&(Fr=gr.layout),Ig(bt,Mt.labels.text),bt.textBaseline=Fr==="vertical"?"alphabetic":"middle",bt.textAlign=Fr==="vertical"?"center":"start",Lt.forEach((function(Oa){Fg(bt,Mt.labels.text,Oa.formattedValue,Oa.x,Oa.y)}))})(at,pe,pt,c):typeof kt=="function"&&kt(at,Qe)})),at.save()}}),[j,O,S,w,Ye,re,he,nt,T,A,_t,Nt,vt,P,D,f,l,Le,ct,Qe,U,c,Z,ye.left,ye.top,We,Xe,Ne,V,mt,Ft,Ct,pt,s,pe,$t,ot,ut]);var st=y.useCallback((function(at){if(jt&&Ke.current){var kt=UA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=dT(jt,ye,bt,Lt);Mt!==void 0?(Ve(y.createElement(se,vn({},Mt.data,{color:Mt.color,label:Mt.label,value:Number(Mt.data.value)})),at),at.type==="mouseenter"&&Te?.(Mt.data,at)):rt()}}),[rt,ye,Te,jt,Ve,se]),lt=y.useCallback((function(at){if(jt&&Ke.current){rt();var kt=UA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=dT(jt,ye,bt,Lt);Mt&&de?.(Mt.data,at)}}),[rt,ye,de,jt]),gt=y.useCallback((function(at){if(jt&&Ke.current){var kt=UA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=dT(jt,ye,bt,Lt);Mt!==void 0&&me?.(vn({},Mt.data,{color:Mt.color}),at)}}),[ye,me,jt]);return d.jsx("canvas",{ref:k7e(Ke,Je),width:Xe*Ne,height:We*Ne,style:{width:Xe,height:We,cursor:Ue?"auto":"normal"},onMouseEnter:Ue?st:void 0,onMouseMove:Ue?st:void 0,onMouseLeave:Ue?lt:void 0,onClick:Ue?gt:void 0,role:Fe})},"ze"),Dqe=y.forwardRef((function(e,t){var n=e.isInteractive,r=e.renderWrapper,a=e.theme,o=Fc(e,Pqe);return d.jsx(Cae,{isInteractive:n,renderWrapper:r,theme:a,animate:!1,children:d.jsx(Nqe,vn({},o,{isInteractive:n,forwardedRef:t}))})})),Mqe=["defaultWidth","defaultHeight","onResize","debounceResize"],Iqe=y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,o=e.debounceResize,s=Fc(e,Mqe);return d.jsx(Oae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:o,children:i(function(l){var f=l.width,c=l.height;return d.jsx(Tqe,vn({},s,{width:f,height:c,ref:t}))},"children")})})),Fqe=["defaultWidth","defaultHeight","onResize","debounceResize"];y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,o=e.debounceResize,s=Fc(e,Fqe);return d.jsx(Oae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:o,children:i(function(l){var f=l.width,c=l.height;return d.jsx(Dqe,vn({},s,{width:f,height:c,ref:t}))},"children")})}));const Lqe={opportunity:.2,"proposal-sent":.5,"in-negociation":.8,delayed:.3},$qe=new Date(new Date().setMonth(new Date().getMonth()-6)).toISOString(),mW="en-US",qqe="USD",zqe=y.memo(()=>{const e=navigator?navigator.languages||[navigator.language]:[mW],{data:t,isPending:n}=za("deals",{pagination:{perPage:100,page:1},sort:{field:"created_at",order:"ASC"},filter:{"created_at@gte":$qe}}),r=y.useMemo(()=>{if(!t)return[];const o=t.reduce((l,f)=>{const c=lP(f.created_at??new Date).toISOString();return l[c]||(l[c]=[]),l[c].push(f),l},{});return Object.keys(o).map(l=>({date:cc(l,"MMM"),won:o[l].filter(f=>f.stage==="won").reduce((f,c)=>(f+=c.amount,f),0),pending:o[l].filter(f=>!["won","lost"].includes(f.stage)).reduce((f,c)=>(f+=c.amount*Lqe[c.stage],f),0),lost:o[l].filter(f=>f.stage==="lost").reduce((f,c)=>(f-=c.amount,f),0)}))},[t]);if(n)return null;const a=r.reduce((o,s)=>(o.min=Math.min(o.min,s.lost),o.max=Math.max(o.max,s.won+s.pending),o),{min:0,max:0});return d.jsxs("div",{className:"flex flex-col",children:[d.jsxs("div",{className:"flex items-center mb-4",children:[d.jsx("div",{className:"mr-3 flex",children:d.jsx(SQ,{className:"text-muted-foreground w-6 h-6"})}),d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Upcoming Deal Revenue"})]}),d.jsx("div",{className:"h-[400px]",children:d.jsx(Iqe,{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:i(({value:o,indexValue:s})=>d.jsxs("div",{className:"p-2 bg-secondary rounded shadow inline-flex items-center gap-1 text-secondary-foreground",children:[d.jsxs("strong",{children:[s,": "]})," ",o>0?"+":"",o.toLocaleString(e.at(0)??mW,{style:"currency",currency:qqe})]}),"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:i(o=>`${Math.abs(o/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"}]})})]})}),Uqe=i(e=>{const t=xt(),n=Ht(e),{filterValues:r,setFilters:a}=qw(e),o=fd();if(!n)throw new Error("<ListNoResults> must be used inside a <List> component");return d.jsx("div",{className:"p-6",children:d.jsx("p",{className:"text-sm text-muted-foreground",children:r&&a&&Object.keys(r).length>0?d.jsxs(d.Fragment,{children:[t("ra.navigation.no_filtered_results",{resource:n,name:o(n,0),_:"No results found with the current filters."})," ",d.jsx(ze,{variant:"outline",size:"sm",onClick:i(()=>a({},[]),"onClick"),children:t("ra.navigation.clear_filters",{_:"Clear filters"})})]}):t("ra.navigation.no_results",{resource:n,name:o(n,0),_:"No results found."})})})},"ListNoResults"),Bqe=i(e=>{const{children:t,linkType:n,rowClick:r,style:a}=e,o=Ht(e),s=Wt(e),l=Sa(),f=typeof n=="function"||typeof r=="function",c=QG({link:f?!1:n??r,resource:o}),p=JG(),m=Et(async()=>{if(!f||!s)return;const g=typeof n=="function"?n(s,s.id):typeof r=="function"?(w,S)=>r(w.id,S,w):!1,b=await p({record:s,resource:o,link:g});b===!1||b==null||l(b)});return s?f?d.jsx("li",{className:"w-full",children:d.jsx("button",{onClick:m,style:a,className:"w-full text-left hover:bg-muted focus: bg-muted focus:outline-none",children:t})}):c?d.jsx("li",{className:"w-full",children:d.jsx(fn,{to:c,style:a,className:"block w-full hover:bg-muted focus:bg-muted focus:outline-none",children:t})}):d.jsx("li",{className:"w-full",children:t}):null},"SimpleListItem"),fT=i(({className:e})=>d.jsx("span",{className:Se("bg-gray-300 flex",e),children:" "}),"ListPlaceholder"),Vqe=i(e=>{const{className:t,hasLeftAvatarOrIcon:n,hasRightAvatarOrIcon:r,hasSecondaryText:a,hasTertiaryText:o,nbFakeLines:s=5,...l}=e;return RK(1e3)?d.jsx("ul",{className:t,...l,children:Hqe(s,c=>d.jsxs("li",{className:"flex items-center space-x-3 p-3",children:[n&&d.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"mb-1",children:[d.jsx(fT,{className:"w-1/3 inline-block mb-1"}),o&&d.jsx("span",{className:"float-right opacity-55 min-w-[10vw]",children:d.jsx(fT,{})})]}),a&&d.jsx(fT,{className:"w-1/4"})]}),r&&d.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "})]},c))}):null},"SimpleListLoading"),Hqe=i((e,t)=>Array.from({length:e},(n,r)=>t(r)),"times"),Wqe=i(e=>{const{className:t,empty:n=Kqe,leftAvatar:r,leftIcon:a,linkType:o,rowClick:s,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,resource:g,...b}=e,{data:w,isPending:S,total:_}=qw(e);return S===!0?d.jsx(Vqe,{className:t,hasLeftAvatarOrIcon:!!a||!!r,hasRightAvatarOrIcon:!!c||!!f,hasSecondaryText:!!p,hasTertiaryText:!!m}):w==null||w.length===0||_===0?n||null:d.jsx("ul",{className:t,...cme(b),children:d.jsx(vme,{data:w,total:_,render:i((j,E)=>d.jsx(Bqe,{rowIndex:E,linkType:o,rowClick:s,resource:g,children:d.jsx(Gqe,{leftAvatar:r,leftIcon:a,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,rowIndex:E})},j.id),"render")})})},"SimpleList"),Gqe=i(e=>{const{leftAvatar:t,leftIcon:n,primaryText:r,rightAvatar:a,rightIcon:o,secondaryText:s,tertiaryText:l}=e,f=Ht(e),c=Wt(e),p=Ec(f),m=xt(),g=i((b,w)=>{const S=w(b,b.id);return typeof S=="string"&&(S.startsWith("http")||S.startsWith("data:"))?d.jsx("img",{src:S,alt:"",className:"w-10 h-10 rounded-full object-cover"}):d.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-sm",children:S})},"renderAvatar");return c?d.jsxs("div",{className:"flex items-center space-x-3 p-3",children:[n&&d.jsx("div",{className:"flex-shrink-0",children:n(c,c.id)}),t&&d.jsx("div",{className:"flex-shrink-0",children:g(c,t)}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.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&&d.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&&d.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||o)&&d.jsxs("div",{className:"flex-shrink-0 flex items-center space-x-2",children:[a&&g(c,a),o&&o(c,c.id)]})]}):null},"SimpleListItemContent"),Kqe=d.jsx(Uqe,{}),Yqe=i(()=>{const{identity:e}=Zn(),{data:t,total:n,isPending:r}=za("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 d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("div",{className:"flex items-center",children:[d.jsx("div",{className:"mr-3 flex",children:d.jsx(IM,{className:"text-muted-foreground w-6 h-6"})}),d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Hot Contacts"}),d.jsx(Pi,{children:d.jsxs(ao,{children:[d.jsx(io,{asChild:!0,children:d.jsx(ze,{variant:"ghost",size:"sm",className:"ml-auto text-muted-foreground",asChild:!0,children:d.jsx(fn,{to:"/contacts/create",children:d.jsx(Ji,{className:"w-4 h-4 text-primary"})})})}),d.jsx(oo,{children:"Create contact"})]})})]}),d.jsx(pn,{className:"py-0",children:d.jsx(Wqe,{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:i(a=>`${a.first_name} ${a.last_name}`,"primaryText"),secondaryText:i(a=>d.jsxs(d.Fragment,{children:[a.title," at ",a.company_name]}),"secondaryText"),leftAvatar:i(a=>d.jsx(is,{record:a}),"leftAvatar"),empty:d.jsxs("div",{className:"p-4",children:[d.jsx("p",{className:"text-sm mb-4",children:'Contacts with a "hot" status will appear here.'}),d.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"),Qqe=i(()=>{const{identity:e}=Zn(),{total:t}=za("tasks",{pagination:{page:1,perPage:1},filter:{sales_id:e?.id}},{enabled:!!e});return t?null:d.jsx("p",{className:"text-sm",children:"Tasks added to your contacts will appear here."})},"TasksListEmpty"),uv=i(({title:e,filter:t})=>{const{identity:n}=Zn(),{data:r,total:a,isPending:o}=za("tasks",{pagination:{page:1,perPage:100},sort:{field:"due_date",order:"ASC"},filter:{...t,sales_id:n?.id}},{enabled:!!n}),s=zw({data:r,isPending:o,resource:"tasks",perPage:5});return o||!r||!a?null:d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium mb-2",children:e}),d.jsx(dd,{value:"tasks",children:d.jsx(ny,{value:s,children:d.jsx(jne,{showContact:!0})})}),a>s.perPage&&d.jsx("div",{className:"flex justify-center",children:d.jsx("a",{href:"#",onClick:i(l=>{s.setPerPage(s.perPage+10),l.preventDefault()},"onClick"),className:"text-sm underline hover:no-underline",children:"Load more"})})]})},"TasksListFilter"),tie=new Date,Xqe=K0e(tie),Zqe=Xqe<5,vW=Q0e().toISOString(),gW=Gye().toISOString(),yW=Kye().toISOString(),bW=Wye(tie,{weekStartsOn:0}).toISOString(),dv={overdue:{"done_date@is":null,"due_date@lt":vW},today:{"done_date@is":null,"due_date@gte":vW,"due_date@lte":gW},tomorrow:{"done_date@is":null,"due_date@gt":gW,"due_date@lt":yW},thisWeek:{"done_date@is":null,"due_date@gte":yW,"due_date@lte":bW},later:{"done_date@is":null,"due_date@gt":bW}},Jqe=i(()=>d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("div",{className:"flex items-center",children:[d.jsx("div",{className:"mr-3 flex",children:d.jsx(kQ,{className:"text-muted-foreground w-6 h-6"})}),d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground flex-1",children:"Upcoming Tasks"}),d.jsx(Sne,{display:"icon",selectContact:!0})]}),d.jsx(pn,{className:"p-4 mb-2",children:d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsx(Qqe,{}),d.jsx(uv,{title:"Overdue",filter:dv.overdue}),d.jsx(uv,{title:"Today",filter:dv.today}),d.jsx(uv,{title:"Tomorrow",filter:dv.tomorrow}),Zqe&&d.jsx(uv,{title:"This week",filter:dv.thisWeek}),d.jsx(uv,{title:"Later",filter:dv.later})]})})]}),"TasksList"),eze=i(()=>{const{data:e,total:t,isPending:n}=za("contacts",{pagination:{page:1,perPage:1}}),{total:r,isPending:a}=za("contactNotes",{pagination:{page:1,perPage:1}}),{total:o,isPending:s}=za("deals",{pagination:{page:1,perPage:1}});return n||a||s?null:t?r?d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-6 mt-1",children:[d.jsx("div",{className:"md:col-span-3",children:d.jsxs("div",{className:"flex flex-col gap-4",children:[null,d.jsx(Yqe,{})]})}),d.jsx("div",{className:"md:col-span-6",children:d.jsxs("div",{className:"flex flex-col gap-6",children:[o?d.jsx(zqe,{}):null,d.jsx(Z5e,{})]})}),d.jsx("div",{className:"md:col-span-3",children:d.jsx(Jqe,{})})]}):d.jsx(bV,{step:2,contactId:e?.[0]?.id}):d.jsx(bV,{step:1})},"Dashboard"),tze=y.lazy(()=>Fp(()=>import("./DealList-DbwJCRGl.js"),[],import.meta.url)),nze={list:tze},rze=y.createContext(void 0),G_=i(()=>y.useContext(rze),"useUserMenu"),aze=i(()=>{const{darkModeLogo:e,lightModeLogo:t,title:n}=Va(),r=Dr(),o=[{path:"/",pattern:"/"},{path:"/contacts",pattern:"/contacts/*"},{path:"/companies",pattern:"/companies/*"},{path:"/deals",pattern:"/deals/*"}].find(s=>tp(s.pattern,r.pathname))?.path||!1;return d.jsx("header",{className:"bg-secondary fixed top-0 left-0 right-0 z-50 border-b border-border",children:d.jsx("div",{className:"px-4",children:d.jsxs("div",{className:"flex justify-between items-center flex-1",children:[d.jsx(ize,{darkLogo:e,lightLogo:t,title:n}),d.jsxs("nav",{className:"flex","aria-label":"Main navigation",children:[d.jsx(Eb,{label:"Dashboard",to:"/",isActive:o==="/"}),d.jsx(Eb,{label:"Contacts",to:"/contacts",isActive:o==="/contacts"}),d.jsx(Eb,{label:"Companies",to:"/companies",isActive:o==="/companies"}),d.jsx(Eb,{label:"Deals",to:"/deals",isActive:o==="/deals"})]}),d.jsxs("div",{className:"flex items-center",children:[d.jsx(MZ,{}),d.jsx(IZ,{}),d.jsxs(PZ,{children:[d.jsx(sze,{}),d.jsx(lze,{}),d.jsx(cze,{}),d.jsx(Pge,{resource:"sales",action:"list",children:d.jsx(oze,{})}),d.jsx(ng,{}),d.jsx(l4,{className:"font-normal",children:d.jsxs("div",{className:"text-xs text-muted-foreground",children:["Version ","0.9.2"]})})]})]})]})})})},"Header"),ize=i(({darkLogo:e,lightLogo:t,title:n})=>d.jsxs(fn,{to:"/",className:"flex items-center gap-2 text-secondary-foreground no-underline hover:opacity-80 transition-opacity",children:[d.jsx("img",{className:"[.light_&]:hidden h-6",src:e,alt:`${n} logo`}),d.jsx("img",{className:"[.dark_&]:hidden h-6",src:t,alt:`${n} logo`}),d.jsx("h1",{className:"text-xl font-semibold",children:n})]}),"Logo"),Eb=i(({label:e,to:t,isActive:n})=>d.jsx(fn,{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"),oze=i(()=>{const{onClose:e}=G_()??{};return d.jsx(sr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/sales",className:"flex items-center gap-2",children:[d.jsx(TQ,{className:"h-4 w-4"}),"Users"]})})},"UsersMenu"),sze=i(()=>{const{onClose:e}=G_()??{};return d.jsx(sr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/settings",className:"flex items-center gap-2",children:[d.jsx(dP,{className:"h-4 w-4"}),"My info"]})})},"ConfigurationMenu"),lze=i(()=>{const{onClose:e}=G_()??{};return d.jsx(sr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/database",className:"flex items-center gap-2",children:[d.jsx(Qv,{className:"h-4 w-4"}),"Database"]})})},"DatabaseMenu"),cze=i(()=>{const{onClose:e}=G_()??{};return d.jsx(sr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/integrations",className:"flex items-center gap-2",children:[d.jsx(u_e,{className:"h-4 w-4"}),"Integrations"]})})},"IntegrationsMenu"),uze=i(({children:e})=>d.jsxs(d.Fragment,{children:[d.jsx(aze,{}),d.jsx("main",{className:"max-w-screen-xl mx-auto pt-20 px-4",id:"main-content",children:d.jsx(hx,{FallbackComponent:FZ,children:d.jsx(y.Suspense,{fallback:d.jsx(sn,{className:"h-12 w-12 rounded-full"}),children:e})})}),d.jsx(R1,{})]}),"Layout"),nie=i(()=>d.jsx("div",{className:"max-w-screen-xl mx-auto h-screen pt-8",children:d.jsx("div",{className:"h-full",children:d.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-8",children:[d.jsx(sn,{className:"w-full h-[100px]"}),d.jsx(sn,{className:"w-4/5 h-[50px]"}),d.jsx(sn,{className:"w-full h-9"}),d.jsx(sn,{className:"w-full h-9"}),d.jsx(sn,{className:"w-full h-9"}),d.jsx(sn,{className:"w-2/5 h-9"})]})})}),"LoginSkeleton"),aD=i(()=>{const e=Pn(),t=_n(),{darkModeLogo:n,title:r}=Va(),{data:a,isPending:o}=Qr({queryKey:["init"],queryFn:i(async()=>t.isInitialized(),"queryFn")}),{isPending:s,mutate:l}=Yr({mutationKey:["signup"],mutationFn:i(async w=>t.signUp(w),"mutationFn"),onSuccess:i(w=>{f({email:w.email,password:w.password,redirectTo:"/contacts"}).then(()=>{c("Initial user successfully created"),e.invalidateQueries({queryKey:["auth","canAccess"]})})},"onSuccess"),onError:i(()=>{c("An error occurred. Please try again.")},"onError")}),f=xY(),c=Vt(),{register:p,handleSubmit:m,formState:{isValid:g}}=iy({mode:"onChange"});if(o)return d.jsx(nie,{});if(a)return d.jsx(gw,{to:"/login"});const b=i(async w=>{l(w)},"onSubmit");return d.jsxs("div",{className:"h-screen p-8",children:[d.jsxs("div",{className:"flex items-center gap-4",children:[d.jsx("img",{src:n,alt:r,width:24,className:"filter brightness-0 invert"}),d.jsx("h1",{className:"text-xl font-semibold",children:r})]}),d.jsx("div",{className:"h-full",children:d.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-4",children:[d.jsx("h1",{className:"text-2xl font-bold mb-4",children:"Welcome to CRM"}),d.jsx("p",{className:"text-base mb-4",children:"Create the first user account to complete the setup."}),d.jsxs("form",{onSubmit:m(b),className:"space-y-4",children:[d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Hn,{htmlFor:"first_name",children:"First name"}),d.jsx(_r,{...p("first_name",{required:!0}),id:"first_name",type:"text",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Hn,{htmlFor:"last_name",children:"Last name"}),d.jsx(_r,{...p("last_name",{required:!0}),id:"last_name",type:"text",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Hn,{htmlFor:"email",children:"Email"}),d.jsx(_r,{...p("email",{required:!0}),id:"email",type:"email",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Hn,{htmlFor:"password",children:"Password"}),d.jsx(_r,{...p("password",{required:!0}),id:"password",type:"password",required:!0})]}),d.jsx("div",{className:"flex justify-between items-center mt-8",children:d.jsx(ze,{type:"submit",disabled:!g||s,className:"w-full",children:s?d.jsxs(d.Fragment,{children:[d.jsx(Oc,{className:"w-4 h-4 animate-spin mr-2"}),"Creating..."]}):"Create account"})})]})]})})]})},"SignupPage");aD.path="/sign-up";const dze=i((e,t)=>e==="admin"?!0:t.resource!=="sales","canAccess"),hT=tAe(Bn,{getIdentity:i(async()=>{const e=await rie();if(e==null)throw new Error;return{id:e.id,fullName:`${e.first_name} ${e.last_name}`,avatar:e.avatar?.src}},"getIdentity")});async function Ws(){if(Ws._is_initialized_cache==null){const{data:e}=await Bn.from("init_state").select("is_initialized");Ws._is_initialized_cache=e?.at(0)?.is_initialized>0}return Ws._is_initialized_cache}i(Ws,"getIsInitialized");(e=>{e._is_initialized_cache=null})(Ws||(Ws={}));const fze={...hT,login:i(async e=>{const t=await hT.login(e);return qb=void 0,t},"login"),checkAuth:i(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 Ws())throw await Bn.auth.signOut(),{redirectTo:"/sign-up",message:!1};return hT.checkAuth(e)},"checkAuth"),canAccess:i(async e=>{if(!await Ws())return!1;const n=await rie();if(n==null)return!1;const r=n.administrator?"admin":"user";return dze(r,e)},"canAccess")};let qb;const rie=i(async()=>{if(qb!=null)return qb;const{data:e,error:t}=await Bn.auth.getSession();if(e?.session?.user==null||t)return;const{data:n,error:r}=await Bn.from("sales").select("id, first_name, last_name, avatar, administrator").match({user_id:e?.session?.user.id}).single();if(!(n==null||r))return qb=n,n},"getSaleFromCache");async function hze(e,t,n){const r={};t&&(r.id=t);const a={};t&&(a.company_id=t);const[o,s,l]=await Promise.all([pze(e,r),mze(e,a),vze(e,a)]);return[...o,...s,...l].sort((f,c)=>f.date&&c.date?f.date.localeCompare(c.date)*-1:0).slice(0,250)}i(hze,"getActivityLog");const pze=i(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:jte,company_id:r.id,company:r,sales_id:r.sales_id,date:r.created_at}))},"getNewCompanies");async function mze(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(f=>f.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"}}),o=n.map(l=>({id:`contact.${l.id}.created`,type:Ete,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:Cte,sales_id:l.sales_id,contactNote:l,date:l.date}));return[...o,...s]}i(mze,"getNewContactsAndNotes");async function vze(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(f=>f.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"}}),o=n.map(l=>({id:`deal.${l.id}.created`,type:Ote,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:kte,sales_id:l.sales_id,dealNote:l,date:l.date}));return[...o,...s]}i(vze,"getNewDealsAndNotes");async function gze(e){return e.website?{src:`https://favicon.show/${e.website.replace(/^https?:\/\//,"").replace(/\/$/,"")}`,title:"Company favicon"}:null}i(gze,"getCompanyAvatar");async function yze(e,t={}){const{timeout:n=2e3}=t,r=new AbortController,a=setTimeout(()=>r.abort(),n),o=await fetch(e,{...t,signal:r.signal});return clearTimeout(a),o}i(yze,"fetchWithTimeout");const bze=["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 xze(e){const t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(o=>o.toString(16).padStart(2,"0")).join("")}i(xze,"hash");async function wze(e){return`https://www.gravatar.com/avatar/${await xze(e)}?d=404`}i(wze,"getGravatarUrl");async function _ze(e){if(bze.includes(e))return null;try{const t=`https://${e}/favicon.ico`;if((await yze(t)).ok)return t}catch{return null}return null}i(_ze,"getFaviconUrl");async function Sze(e){if(!e.email_jsonb||!e.email_jsonb.length)return null;for(const{email:t}of e.email_jsonb){const n=await wze(t);try{if((await fetch(n)).ok)return n}catch{}const r=t.split("@")[1],a=await _ze(r);if(a)return a}return null}i(Sze,"getContactAvatar");const xW=xd()||{url:"https://placeholder.supabase.co",anonKey:"placeholder-key"},So=bAe({instanceUrl:xW.url,apiKey:xW.anonKey,supabaseClient:Bn,sortOrder:"asc,desc.nullslast"}),wW=i(async e=>{let t=e.data.logo;return typeof t!="object"||t===null||!t.src?t=await gze(e.data):t.rawFile instanceof File&&await zb(t),{...e,data:{...e.data,logo:t}}},"processCompanyLogo");async function _W(e){const{data:t}=e;if(t.avatar?.src||!t.email_jsonb||!t.email_jsonb.length)return e;const n=await Sze(t),r={...t,avatar:{src:n||void 0}};return{...e,data:r}}i(_W,"processContactAvatar");const jze={...So,async getList(e,t){return e==="companies"?So.getList("companies_summary",t):e==="contacts"?So.getList("contacts_summary",t):So.getList(e,t)},async getOne(e,t){return e==="companies"?So.getOne("companies_summary",t):e==="contacts"?So.getOne("contacts_summary",t):So.getOne(e,t)},async signUp({email:e,password:t,first_name:n,last_name:r}){const{data:a,error:o}=await Bn.functions.invoke("setup",{method:"POST",body:{email:e,password:t,first_name:n,last_name:r}});if(!a||o)throw console.error("signUp.error",o),new Error("Failed to create account");return Ws._is_initialized_cache=!0,{id:a.data.id,email:e,password:t}},async salesCreate(e){const{data:t,error:n}=await Bn.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:o,avatar:s,disabled:l}=t,{data:f,error:c}=await Bn.functions.invoke("users",{method:"PATCH",body:{sales_id:e,email:n,first_name:r,last_name:a,administrator:o,disabled:l,avatar:s}});if(!f||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 Bn.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 Bn.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 Bn.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 So.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=>So.update("deals",{id:r.id,data:r,previousData:t.find(a=>a.id===r.id)})))},async getActivityLog(e){return hze(So,e)},async isInitialized(){return Ws()},async mergeContacts(e,t){const{data:n,error:r}=await Bn.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}},Eze=bhe(jze,[{resource:"contactNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await zb(r);return e},"beforeSave")},{resource:"dealNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await zb(r);return e},"beforeSave")},{resource:"sales",beforeSave:i(async(e,t,n)=>(e.avatar&&await zb(e.avatar),e),"beforeSave")},{resource:"contacts",beforeCreate:i(async e=>_W(e),"beforeCreate"),beforeUpdate:i(async e=>_W(e),"beforeUpdate"),beforeGetList:i(async e=>Cb(["first_name","last_name","company_name","title","email","phone","background"])(e),"beforeGetList")},{resource:"companies",beforeGetList:i(async e=>Cb(["name","phone_number","website","zipcode","city","stateAbbr"])(e),"beforeGetList"),beforeCreate:i(async e=>{const t=await wW(e);return{...t,data:{...t.data,created_at:new Date().toISOString()}}},"beforeCreate"),beforeUpdate:i(async e=>await wW(e),"beforeUpdate")},{resource:"contacts_summary",beforeGetList:i(async e=>Cb(["first_name","last_name"])(e),"beforeGetList")},{resource:"deals",beforeGetList:i(async e=>Cb(["name","type","description"])(e),"beforeGetList")}]),Cb=i(e=>t=>{if(!t.filter?.q)return t;const{q:n,...r}=t.filter;return{...t,filter:{...r,"@or":e.reduce((a,o)=>o==="email"?{...a,"email_fts@ilike":n}:o==="phone"?{...a,"phone_fts@ilike":n}:{...a,[`${o}@ilike`]:n},{})}}},"applyFullTextSearch"),zb=i(async e=>{if(!e.src.startsWith("blob:")&&!e.src.startsWith("data:")&&e.path){const{error:c}=await Bn.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(),o=`${`${Math.random()}.${r}`}`,{error:s}=await Bn.storage.from("attachments").upload(o,t);if(s)throw console.error("uploadError",s),new Error("Failed to upload attachment");const{data:l}=Bn.storage.from("attachments").getPublicUrl(o);e.path=o,e.src=l.publicUrl;const f=n.type;return e.type=f,e},"uploadToBucket");function aie(){const{identity:e}=Zn(),t=Wt();return d.jsxs("div",{className:"space-y-4 w-full",children:[d.jsx(ln,{source:"first_name",validate:nr(),helperText:!1}),d.jsx(ln,{source:"last_name",validate:nr(),helperText:!1}),d.jsx(ln,{source:"email",validate:[nr(),JK()],helperText:!1}),d.jsx(CN,{source:"administrator",readOnly:t?.id===e?.id,helperText:!1}),d.jsx(CN,{source:"disabled",readOnly:t?.id===e?.id,helperText:!1})]})}i(aie,"SalesInputs");function Cze(){const e=_n(),t=Vt(),n=rs(),{mutate:r}=Yr({mutationKey:["signup"],mutationFn:i(async o=>e.salesCreate(o),"mutationFn"),onSuccess:i(()=>{t("User created. They will soon receive an email to set their password."),n("/sales")},"onSuccess"),onError:i(()=>{t("An error occurred while creating the user.",{type:"error"})},"onError")}),a=i(async o=>{r(o)},"onSubmit");return d.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:d.jsxs(pn,{children:[d.jsx(Qo,{children:d.jsx(Xo,{children:"Create a new user"})}),d.jsx(Wn,{children:d.jsx(pee,{onSubmit:a,children:d.jsx(aie,{})})})]})})}i(Cze,"SalesCreate");function Oze(){return d.jsxs("div",{className:"flex justify-end gap-4",children:[d.jsx($1,{}),d.jsx(yd,{})]})}i(Oze,"EditToolbar");function kze(){const{record:e}=EK(),t=_n(),n=Vt(),r=rs(),{mutate:a}=Yr({mutationKey:["signup"],mutationFn:i(async s=>{if(!e)throw new Error("Record not found");return t.salesUpdate(e.id,s)},"mutationFn"),onSuccess:i(()=>{r("/sales"),n("User updated successfully")},"onSuccess"),onError:i(()=>{n("An error occurred. Please try again.")},"onError")}),o=i(async s=>{a(s)},"onSubmit");return d.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:d.jsx(pn,{children:d.jsx(Wn,{children:d.jsxs(pee,{toolbar:d.jsx(Oze,{}),onSubmit:o,record:e,children:[d.jsx(Rze,{}),d.jsx(aie,{})]})})})})}i(kze,"SalesEdit");const Rze=i(()=>{const e=Wt();return e?d.jsxs("h2",{className:"text-lg font-semibold mb-4",children:["Edit ",e?.first_name," ",e?.last_name]}):null},"SaleEditTitle"),Aze=i(()=>d.jsxs(_4,{children:[d.jsx(P1,{}),d.jsx(Pc,{label:"New user"})]}),"SalesListActions"),Tze=[d.jsx(S4,{source:"q",alwaysOn:!0})],Pze=i(e=>{const t=Wt();return t?d.jsxs("div",{className:"flex flex-row gap-1",children:[t.administrator&&d.jsx(Pr,{variant:"outline",className:"border-blue-300 dark:border-blue-700",children:"Admin"}),t.disabled&&d.jsx(Pr,{variant:"outline",className:"border-orange-300 dark:border-orange-700",children:"Disabled"})]}):null},"OptionsField"),Nze=i(()=>{const e=Wt(),t=_n(),n=Vt(),r=Nw(),[a,o]=y.useState(!1),[s,l]=y.useState(!1),{mutate:f,isPending:c}=Yr({mutationFn:i(async()=>t.resendInvite(e.id),"mutationFn"),onSuccess:i(()=>{n("Invitation email resent successfully"),o(!1),r()},"onSuccess"),onError:i(()=>{n("Failed to resend invitation email",{type:"error"}),o(!1)},"onError")}),{mutate:p,isPending:m}=Yr({mutationFn:i(async()=>t.resetPassword(e.id),"mutationFn"),onSuccess:i(()=>{n("Password reset email sent successfully"),l(!1),r()},"onSuccess"),onError:i(()=>{n("Failed to send password reset email",{type:"error"}),l(!1)},"onError")});if(!e)return null;const g=e.email_confirmed_at!==null,b=e.disabled===!0;return console.log("[RowActions] Record:",{email:e.email,email_confirmed_at:e.email_confirmed_at,isConfirmed:g,isDisabled:b,inviteDialogOpen:a,resetDialogOpen:s}),d.jsxs(d.Fragment,{children:[d.jsxs(Ac,{children:[d.jsx(Qs,{asChild:!0,children:d.jsxs(ze,{variant:"ghost",className:"h-8 w-8 p-0",children:[d.jsx("span",{className:"sr-only",children:"Open menu"}),d.jsx(PM,{className:"h-4 w-4"})]})}),d.jsxs(Tc,{align:"end",children:[d.jsx(l4,{children:"Email Actions"}),d.jsx(ng,{}),!g&&d.jsxs(sr,{onClick:i(w=>{w.preventDefault(),w.stopPropagation(),console.log("[Menu] Clicked Resend Invite"),o(!0)},"onClick"),children:[d.jsx(A1e,{className:"mr-2 h-4 w-4"}),"Resend Invite"]}),g&&!b&&d.jsxs(sr,{onClick:i(()=>l(!0),"onClick"),children:[d.jsx(Xwe,{className:"mr-2 h-4 w-4"}),"Send Password Reset"]})]})]}),d.jsx(wa,{open:a,onOpenChange:o,children:d.jsxs(_a,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Resend Invitation"}),d.jsxs(Oi,{children:["Send a new invitation email to ",d.jsx("strong",{children:e.email}),"?",d.jsx("br",{}),d.jsx("br",{}),"This will send them a fresh invitation link to set up their account."]})]}),d.jsxs(Yo,{children:[d.jsx(ze,{variant:"outline",onClick:i(w=>{w.stopPropagation(),o(!1)},"onClick"),disabled:c,children:"Cancel"}),d.jsx(ze,{onClick:i(w=>{w.stopPropagation(),f()},"onClick"),disabled:c,children:c?"Sending...":"Send Invitation"})]})]})}),d.jsx(wa,{open:s,onOpenChange:l,children:d.jsxs(_a,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Send Password Reset"}),d.jsxs(Oi,{children:["Send a password reset email to ",d.jsx("strong",{children:e.email}),"?",d.jsx("br",{}),d.jsx("br",{}),"This will send them a link to reset their password."]})]}),d.jsxs(Yo,{children:[d.jsx(ze,{variant:"outline",onClick:i(w=>{w.stopPropagation(),l(!1)},"onClick"),disabled:m,children:"Cancel"}),d.jsx(ze,{onClick:i(w=>{w.stopPropagation(),p()},"onClick"),disabled:m,children:m?"Sending...":"Send Reset Link"})]})]})})]})},"RowActions");function Dze(){return d.jsx(b4,{filters:Tze,actions:d.jsx(Aze,{}),sort:{field:"first_name",order:"ASC"},children:d.jsx(Mze,{})})}i(Dze,"SalesList");const Mze=i(()=>{const{data:e,isPending:t,filterValues:n}=Gn(),{identity:r}=Zn(),a=n&&Object.keys(n).length>0;return!r||t?d.jsx(pn,{className:"p-4",children:d.jsxs("div",{className:"space-y-3",children:[d.jsx(sn,{className:"h-12 w-full"}),d.jsx(sn,{className:"h-12 w-full"}),d.jsx(sn,{className:"h-12 w-full"}),d.jsx(sn,{className:"h-12 w-full"}),d.jsx(sn,{className:"h-12 w-full"})]})}):!e?.length&&!a?d.jsx(Ize,{}):d.jsxs(Fs,{children:[d.jsx(Fs.Col,{source:"first_name"}),d.jsx(Fs.Col,{source:"last_name"}),d.jsx(Fs.Col,{source:"email"}),d.jsx(Fs.Col,{label:!1,children:d.jsx(Pze,{})}),d.jsx(Fs.Col,{label:!1,children:d.jsx(Nze,{})})]})},"SalesListLayout"),Ize=i(()=>{const e=F1();return d.jsxs("div",{className:"flex flex-col justify-center items-center gap-3",style:{height:`calc(100dvh - ${e}px)`},children:[d.jsx("img",{src:"./img/empty.svg",alt:"No users found"}),d.jsxs("div",{className:"flex flex-col gap-0 items-center",children:[d.jsx("h6",{className:"text-lg font-bold",children:"No users found"}),d.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"It seems your user list is empty."})]}),d.jsx("div",{className:"flex flex-row gap-2",children:d.jsx(Pc,{label:"New user"})})]})},"SalesEmpty"),Fze={list:Dze,create:Cze,edit:kze,recordRepresentation:i(e=>`${e.first_name} ${e.last_name}`,"recordRepresentation")};function iie({open:e,onComplete:t,canClose:n=!1}){const[r,a]=y.useState("welcome"),[o,s]=y.useState(""),[l,f]=y.useState(""),[c,p]=y.useState(null),m=i(async()=>{p(null),a("validating");const b=await XRe(o,l);b.valid?(KRe({url:o,anonKey:l}),a("success"),setTimeout(()=>{window.location.href=window.location.origin},1500)):(p(b.error||"Connection failed"),a("credentials"))},"handleValidateAndSave"),g=i(()=>{n&&t()},"handleClose");return d.jsx(wa,{open:e,onOpenChange:n?g:void 0,children:d.jsxs(_a,{className:"sm:max-w-md",onPointerDownOutside:i(b=>!n&&b.preventDefault(),"onPointerDownOutside"),onEscapeKeyDown:i(b=>!n&&b.preventDefault(),"onEscapeKeyDown"),children:[r==="welcome"&&d.jsxs(d.Fragment,{children:[d.jsxs(Wr,{children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d.jsx(Qv,{className:"h-6 w-6 text-primary"}),d.jsx(Gr,{children:"Welcome to CRM"})]}),d.jsx(Oi,{children:"To get started, you'll need to connect to a Supabase database."})]}),d.jsxs("div",{className:"space-y-4 py-4",children:[d.jsx(ai,{children:d.jsxs(ki,{children:[d.jsx("strong",{children:"Don't have a Supabase project?"}),d.jsx("br",{}),"Create one for free at"," ",d.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline text-primary",children:"supabase.com"})]})}),d.jsxs("div",{className:"space-y-2",children:[d.jsx("h4",{className:"font-medium text-sm",children:"What you'll need:"}),d.jsxs("ul",{className:"list-disc list-inside text-sm text-muted-foreground space-y-1",children:[d.jsx("li",{children:"Your Supabase project URL"}),d.jsx("li",{children:"Your anonymous (anon) API key"})]})]}),d.jsx(ze,{onClick:i(()=>a("credentials"),"onClick"),className:"w-full",children:"Continue"})]})]}),r==="credentials"&&d.jsxs(d.Fragment,{children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Connect to Supabase"}),d.jsx(Oi,{children:"Enter your Supabase project credentials"})]}),d.jsxs("div",{className:"space-y-4 py-4",children:[c&&d.jsxs(ai,{variant:"destructive",children:[d.jsx(Ap,{className:"h-4 w-4"}),d.jsx(ki,{children:c})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{htmlFor:"supabase-url",children:"Supabase URL"}),d.jsx(_r,{id:"supabase-url",placeholder:"https://xxxxx.supabase.co",value:o,onChange:i(b=>s(b.target.value),"onChange")}),d.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in Project Settings → API"})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{htmlFor:"anon-key",children:"Anonymous Key"}),d.jsx(_r,{id:"anon-key",type:"password",placeholder:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",value:l,onChange:i(b=>f(b.target.value),"onChange")}),d.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in Project Settings → API → Project API keys"})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(ze,{variant:"outline",onClick:i(()=>a("welcome"),"onClick"),className:"flex-1",children:"Back"}),d.jsx(ze,{onClick:m,disabled:!o||!l,className:"flex-1",children:"Connect"})]})]})]}),r==="validating"&&d.jsxs(d.Fragment,{children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Validating Connection"}),d.jsx(Oi,{children:"Testing your Supabase credentials..."})]}),d.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[d.jsx(Oc,{className:"h-12 w-12 animate-spin text-primary mb-4"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait..."})]})]}),r==="success"&&d.jsxs(d.Fragment,{children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Connection Successful!"}),d.jsx(Oi,{children:"Your Supabase database is now connected"})]}),d.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[d.jsx(Fo,{className:"h-12 w-12 text-green-500 mb-4"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Reloading application..."})]})]})]})})}i(iie,"SupabaseSetupWizard");function Lze(){const[e,t]=y.useState(!1),n=xd(),r=ZRe(),a=i(()=>{confirm("Are you sure you want to clear the database configuration? The app will need to be reconfigured on next launch.")&&(YRe(),window.location.reload())},"handleClearConfig");return d.jsxs(d.Fragment,{children:[d.jsxs(pn,{children:[d.jsxs(Qo,{children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(Qv,{className:"h-5 w-5"}),d.jsx(Xo,{children:"Database Connection"})]}),d.jsx(w4,{children:"Manage your Supabase database connection settings"})]}),d.jsx(Wn,{className:"space-y-4",children:n?d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-start gap-3 p-4 border rounded-lg",children:[d.jsx(Fo,{className:"h-5 w-5 text-green-500 mt-0.5"}),d.jsxs("div",{className:"flex-1 space-y-1",children:[d.jsx("p",{className:"font-medium",children:"Connected"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:n.url}),n.configuredAt&&d.jsxs("p",{className:"text-xs text-muted-foreground",children:["Configured on"," ",new Date(n.configuredAt).toLocaleDateString()]})]})]}),r==="env"&&d.jsxs(ai,{children:[d.jsx(dP,{className:"h-4 w-4"}),d.jsx(ki,{children:"Using configuration from environment variables. You can override this by setting up a new connection via the UI."})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsxs(ze,{variant:"outline",onClick:i(()=>t(!0),"onClick"),className:"flex-1",children:[d.jsx(dP,{className:"h-4 w-4 mr-2"}),"Change Connection"]}),r==="ui"&&d.jsxs(ze,{variant:"destructive",onClick:a,className:"flex-1",children:[d.jsx(cy,{className:"h-4 w-4 mr-2"}),"Clear Configuration"]})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx($ze,{className:"text-sm font-medium",children:"Anonymous Key"}),d.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)]})]})]}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-start gap-3 p-4 border border-dashed rounded-lg",children:[d.jsx(al,{className:"h-5 w-5 text-destructive mt-0.5"}),d.jsxs("div",{className:"flex-1 space-y-1",children:[d.jsx("p",{className:"font-medium",children:"Not Connected"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"No Supabase database is configured"})]})]}),d.jsx(ai,{children:d.jsxs(ki,{children:["Connect to a Supabase database to start using Atomic CRM. You can create a free project at"," ",d.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"supabase.com"})]})}),d.jsxs(ze,{onClick:i(()=>t(!0),"onClick"),className:"w-full",children:[d.jsx(Qv,{className:"h-4 w-4 mr-2"}),"Connect to Supabase"]})]})})]}),d.jsx(iie,{open:e,onComplete:i(()=>t(!1),"onComplete"),canClose:!0})]})}i(Lze,"DatabaseSettings");function $ze({children:e,className:t}){return d.jsx("label",{className:t,children:e})}i($ze,"Label");const iD=i(()=>d.jsx("div",{className:"max-w-lg mx-auto mt-8",children:d.jsx(Lze,{})}),"DatabasePage");iD.path="/database";const oD=i(()=>{const[e,t]=y.useState(!1),{identity:n,refetch:r}=Zn(),{data:a,refetch:o}=Dw("sales",{id:n?.id}),s=Vt(),l=_n(),{mutate:f}=Yr({mutationKey:["signup"],mutationFn:i(async p=>{if(!n)throw new Error("Record not found");return l.salesUpdate(n.id,p)},"mutationFn"),onSuccess:i(()=>{r(),o(),t(!1),s("Your profile has been updated")},"onSuccess"),onError:i(p=>{s("An error occurred. Please try again",{type:"error"})},"onError")});if(!n)return null;const c=i(async p=>{f(p)},"handleOnSubmit");return d.jsx("div",{className:"max-w-lg mx-auto mt-8",children:d.jsx(ra,{onSubmit:c,record:a,children:d.jsx(qze,{isEditMode:e,setEditMode:t})})})},"SettingsPage"),qze=i(({isEditMode:e,setEditMode:t})=>{const n=Vt(),r=Sa(),a=Wt(),{identity:o,refetch:s}=Zn(),{isDirty:l}=ay(),f=_n(),{mutate:c}=Yr({mutationKey:["signup"],mutationFn:i(async g=>{if(!a)throw new Error("Record not found");return f.salesUpdate(a.id,g)},"mutationFn"),onSuccess:i(()=>{s(),n("Your profile has been updated")},"onSuccess"),onError:i(()=>{n("An error occurred. Please try again.")},"onError")});if(!o)return null;const p=i(()=>{r("/change-password")},"handleClickOpenPasswordChange"),m=i(async g=>{c(g)},"handleAvatarUpdate");return d.jsxs("div",{className:"space-y-4",children:[d.jsx(pn,{children:d.jsxs(Wn,{children:[d.jsx("div",{className:"mb-4 flex flex-row justify-between",children:d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"My info"})}),d.jsxs("div",{className:"space-y-4 mb-4",children:[d.jsx(ote,{source:"avatar",type:"avatar",onSave:m,linkPosition:"right"}),d.jsx(pT,{source:"first_name",isEditMode:e}),d.jsx(pT,{source:"last_name",isEditMode:e}),d.jsx(pT,{source:"email",isEditMode:e})]}),d.jsxs("div",{className:"flex flex-row justify-end gap-2",children:[!e&&d.jsx(d.Fragment,{children:d.jsx(ze,{variant:"outline",type:"button",onClick:p,children:"Change password"})}),d.jsxs(ze,{type:"button",variant:e?"ghost":"outline",onClick:i(()=>t(!e),"onClick"),className:"flex items-center",children:[e?d.jsx(al,{}):d.jsx(OQ,{}),e?"Cancel":"Edit"]}),e&&d.jsxs(ze,{type:"submit",disabled:!l,variant:"outline",children:[d.jsx(i1,{}),"Save"]})]})]})}),void 0]})},"SettingsForm"),pT=i(({source:e,isEditMode:t})=>t?d.jsx(ln,{source:e,helperText:!1}):d.jsx("div",{className:"m-2",children:d.jsx(l5e,{source:e})}),"TextRender");oD.path="/settings";function oie(){const e=new Uint8Array(16);return crypto.getRandomValues(e),`ak_live_${Array.from(e).map(n=>n.toString(16).padStart(2,"0")).join("")}`}i(oie,"generateApiKey");async function zze(e){const n=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(r)).map(o=>o.toString(16).padStart(2,"0")).join("")}i(zze,"hashApiKey");const Uze=[{value:"contacts:read",label:"Contacts: Read"},{value:"contacts:write",label:"Contacts: Write"},{value:"companies:read",label:"Companies: Read"},{value:"companies:write",label:"Companies: Write"},{value:"deals:read",label:"Deals: Read"},{value:"deals:write",label:"Deals: Write"},{value:"activities:write",label:"Activities: Write"}],Bze=i(({open:e,onClose:t})=>{const[n,r]=y.useState(null),[a,o]=y.useState(!1),s=_n(),l=Vt(),f=Pn(),{identity:c}=Zn(),{register:p,handleSubmit:m,watch:g,setValue:b,reset:w}=iy({defaultValues:{name:"",scopes:[],expires_at:""}}),S=Yr({mutationFn:i(async O=>{const C=oie(),T=await zze(C),R=C.substring(0,12),{data:A}=await s.create("api_keys",{data:{name:O.name,key_hash:T,key_prefix:R,scopes:O.scopes,is_active:!0,expires_at:O.expires_at||null,sales_id:c?.id,created_by_sales_id:c?.id}});return{data:A,apiKey:C}},"mutationFn"),onSuccess:i(({apiKey:O})=>{r(O),f.invalidateQueries({queryKey:["api_keys"]}),l("API key created successfully")},"onSuccess"),onError:i(()=>{l("Failed to create API key",{type:"error"})},"onError")}),_=i(()=>{r(null),o(!1),w(),t()},"handleClose"),j=i(()=>{n&&(navigator.clipboard.writeText(n),o(!0),setTimeout(()=>o(!1),2e3))},"copyApiKey"),E=i(O=>{const C=g("scopes");C.includes(O)?b("scopes",C.filter(T=>T!==O)):b("scopes",[...C,O])},"toggleScope");return d.jsx(wa,{open:e,onOpenChange:_,children:d.jsxs(_a,{className:"sm:max-w-[500px]",children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:n?"API Key Created":"Create API Key"}),d.jsx(Oi,{children:n?"Copy this key now - it won't be shown again!":"Create a new API key to access the CRM API"})]}),n?d.jsxs("div",{className:"space-y-4",children:[d.jsx(ai,{children:d.jsx(ki,{children:"Make sure to copy your API key now. You won't be able to see it again!"})}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{children:"Your API Key"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(_r,{value:n,readOnly:!0,className:"font-mono text-sm"}),d.jsx(ze,{type:"button",variant:"outline",size:"icon",onClick:j,children:a?d.jsx(Fo,{className:"h-4 w-4 text-green-500"}):d.jsx(AM,{className:"h-4 w-4"})})]})]}),d.jsx("div",{className:"flex justify-end",children:d.jsx(ze,{onClick:_,children:"Done"})})]}):d.jsx("form",{onSubmit:m(O=>S.mutate(O)),children:d.jsxs("div",{className:"space-y-4",children:[d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{htmlFor:"name",children:"Name"}),d.jsx(_r,{id:"name",placeholder:"e.g., Production API Key",...p("name",{required:!0})})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{children:"Scopes"}),d.jsx("div",{className:"space-y-2",children:Uze.map(O=>d.jsxs("div",{className:"flex items-center space-x-2",children:[d.jsx(Up,{id:O.value,checked:g("scopes").includes(O.value),onCheckedChange:i(()=>E(O.value),"onCheckedChange")}),d.jsx("label",{htmlFor:O.value,className:"text-sm cursor-pointer",children:O.label})]},O.value))})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{htmlFor:"expires_at",children:"Expiration (optional)"}),d.jsx(_r,{id:"expires_at",type:"date",...p("expires_at")})]}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(ze,{type:"button",variant:"outline",onClick:_,children:"Cancel"}),d.jsx(ze,{type:"submit",disabled:S.isPending,children:"Create"})]})]})})]})})},"CreateApiKeyDialog");var Vze=Symbol("radix.slottable");function Hze(e){const t=i(({children:n})=>d.jsx(d.Fragment,{children:n}),"Slottable2");return t.displayName=`${e}.Slottable`,t.__radixId=Vze,t}i(Hze,"createSlottable");var sie="AlertDialog",[Wze,KUe]=da(sie,[WQ]),sl=WQ(),lie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=sl(t);return d.jsx(fy,{...r,...n,modal:!0})},"AlertDialog$1");lie.displayName=sie;var Gze="AlertDialogTrigger",Kze=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(lX,{...a,...r,ref:t})});Kze.displayName=Gze;var Yze="AlertDialogPortal",cie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=sl(t);return d.jsx(hy,{...r,...n})},"AlertDialogPortal$1");cie.displayName=Yze;var Qze="AlertDialogOverlay",uie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(py,{...a,...r,ref:t})});uie.displayName=Qze;var uh="AlertDialogContent",[Xze,Zze]=Wze(uh),Jze=Hze("AlertDialogContent"),die=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,children:r,...a}=e,o=sl(n),s=y.useRef(null),l=Zt(t,s),f=y.useRef(null);return d.jsx(KSe,{contentName:uh,titleName:fie,docsSlug:"alert-dialog",children:d.jsx(Xze,{scope:n,cancelRef:f,children:d.jsxs(my,{role:"alertdialog",...o,...a,ref:l,onOpenAutoFocus:tt(a.onOpenAutoFocus,c=>{c.preventDefault(),f.current?.focus({preventScroll:!0})}),onPointerDownOutside:i(c=>c.preventDefault(),"onPointerDownOutside"),onInteractOutside:i(c=>c.preventDefault(),"onInteractOutside"),children:[d.jsx(Jze,{children:r}),d.jsx(tUe,{contentRef:s})]})})})});die.displayName=uh;var fie="AlertDialogTitle",hie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(u1,{...a,...r,ref:t})});hie.displayName=fie;var pie="AlertDialogDescription",mie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(d1,{...a,...r,ref:t})});mie.displayName=pie;var eUe="AlertDialogAction",vie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(vy,{...a,...r,ref:t})});vie.displayName=eUe;var gie="AlertDialogCancel",yie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,{cancelRef:a}=Zze(gie,n),o=sl(n),s=Zt(t,a);return d.jsx(vy,{...o,...r,ref:s})});yie.displayName=gie;var tUe=i(({contentRef:e})=>{const t=`\`${uh}\` requires a description for the component to be accessible for screen reader users.
154
+ `,fill:a,opacity:s,strokeWidth:f,stroke:c===void 0?"transparent":c,style:{pointerEvents:"none"}})})},"y");function oc(){return oc=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},oc.apply(null,arguments)}i(oc,"b");var Ci={translateX:0,translateY:0,padding:0,itemsSpacing:0,itemDirection:"left-to-right",justify:!1,symbolShape:"square",symbolSize:16,symbolSpacing:8},tqe={top:0,right:0,bottom:0,left:0},T3=i(function(e){var t,n=e.direction,r=e.itemsSpacing,a=e.padding,o=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 f=typeof a=="number"?{top:a,right:a,bottom:a,left:a}:oc({},tqe,a),c=f.left+f.right,p=f.top+f.bottom,m=s+c,g=l+p,b=(o-1)*r;return n==="row"?m=s*o+b+c:n==="column"&&(g=l*o+b+p),{width:m,height:g,padding:f}},"A"),Wae=i(function(e){var t=e.anchor,n=e.translateX,r=e.translateY,a=e.containerWidth,o=e.containerHeight,s=e.width,l=e.height,f=n,c=r;switch(t){case"top":f+=(a-s)/2;break;case"top-right":f+=a-s;break;case"right":f+=a-s,c+=(o-l)/2;break;case"bottom-right":f+=a-s,c+=o-l;break;case"bottom":f+=(a-s)/2,c+=o-l;break;case"bottom-left":c+=o-l;break;case"left":c+=(o-l)/2;break;case"center":f+=(a-s)/2,c+=(o-l)/2}return{x:f,y:c}},"C"),Gae=i(function(e){var t,n,r,a,o,s,l=e.direction,f=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",f?(r=m,o="end"):(r=c+p,o="start");break;case"right-to-left":t=m-c,n=(g-c)/2,a=g/2,s="central",f?(r=0,o="start"):(r=m-c-p,o="end");break;case"top-to-bottom":t=(m-c)/2,n=0,r=m/2,o="middle",f?(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,o="middle",f?(a=0,s="text-before-edge"):(a=g-c-p,s="alphabetic")}return{symbolX:t,symbolY:n,labelX:r,labelY:a,labelAnchor:o,labelAlignment:s}},"z"),nqe={circle:X9e,diamond:Z9e,square:J9e,triangle:eqe},rqe=i(function(e){var t,n,r,a,o,s,l,f,c,p,m,g=e.x,b=e.y,w=e.width,S=e.height,_=e.data,j=e.direction,E=j===void 0?Ci.itemDirection:j,O=e.justify,C=O===void 0?Ci.justify:O,T=e.textColor,R=e.background,A=R===void 0?"transparent":R,P=e.opacity,D=P===void 0?1:P,M=e.symbolShape,I=M===void 0?Ci.symbolShape:M,F=e.symbolSize,L=F===void 0?Ci.symbolSize:F,q=e.symbolSpacing,U=q===void 0?Ci.symbolSpacing:q,$=e.symbolBorderWidth,V=$===void 0?0:$,z=e.symbolBorderColor,W=z===void 0?"transparent":z,H=e.onClick,Q=e.onMouseEnter,Y=e.onMouseLeave,K=e.toggleSerie,ee=e.effects,te=y.useState({}),oe=te[0],ne=te[1],fe=Mr(),re=y.useCallback((function(X){if(ee){var se=ee.filter((function(me){return me.on==="hover"})).reduce((function(me,Te){return oc({},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 oc({},me,Te.style)}),{});ne(se)}Y?.(_,X)}),[Y,_,ee]),he=Gae({direction:E,justify:C,symbolSize:(t=oe.symbolSize)!=null?t:L,symbolSpacing:U,width:w,height:S}),J=he.symbolX,Me=he.symbolY,we=he.labelX,Ee=he.labelY,Re=he.labelAnchor,ke=he.labelAlignment,Pe=[H,Q,Y,K].some((function(X){return X!==void 0})),Ue=typeof I=="function"?I:nqe[I];return d.jsxs("g",{transform:"translate("+g+","+b+")",style:{opacity:(n=oe.itemOpacity)!=null?n:D},children:[d.jsx("rect",{width:w,height:S,fill:(r=oe.itemBackground)!=null?r:A,style:{cursor:Pe?"pointer":"auto"},onClick:i(function(X){H?.(_,X),K?.(_.id)},"onClick"),onMouseEnter:re,onMouseLeave:ce}),y.createElement(Ue,oc({id:_.id,x:J,y:Me,size:(a=oe.symbolSize)!=null?a:L,fill:(o=(s=_.fill)!=null?s:_.color)!=null?o:"black",borderWidth:(l=oe.symbolBorderWidth)!=null?l:V,borderColor:(f=oe.symbolBorderColor)!=null?f:W},_.hidden?fe.legends.hidden.symbol:void 0)),d.jsx(V_,{textAnchor:Re,style:oc({},fe.legends.text,{fill:(c=(p=(m=oe.itemTextColor)!=null?m:T)!=null?p:fe.legends.text.fill)!=null?c:"black",dominantBaseline:ke,pointerEvents:"none",userSelect:"none"},_.hidden?fe.legends.hidden.text:void 0),x:we,y:Ee,children:_.label})]})},"B"),aqe=i(function(e){var t=e.data,n=e.x,r=e.y,a=e.direction,o=e.padding,s=o===void 0?Ci.padding:o,l=e.justify,f=e.effects,c=e.itemWidth,p=e.itemHeight,m=e.itemDirection,g=m===void 0?Ci.itemDirection:m,b=e.itemsSpacing,w=b===void 0?Ci.itemsSpacing:b,S=e.itemTextColor,_=e.itemBackground,j=_===void 0?"transparent":_,E=e.itemOpacity,O=E===void 0?1:E,C=e.symbolShape,T=e.symbolSize,R=e.symbolSpacing,A=e.symbolBorderWidth,P=e.symbolBorderColor,D=e.onClick,M=e.onMouseEnter,I=e.onMouseLeave,F=e.toggleSerie,L=T3({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 d.jsx("g",{transform:"translate("+n+","+r+")",children:t.map((function($,V){return d.jsx(rqe,{data:$,x:V*q+L.left,y:V*U+L.top,width:c,height:p,direction:g,justify:l,effects:f,textColor:S,background:j,opacity:O,symbolShape:C,symbolSize:T,symbolSpacing:R,symbolBorderWidth:A,symbolBorderColor:P,onClick:D,onMouseEnter:M,onMouseLeave:I,toggleSerie:F},V)}))})},"H"),iqe=i(function(e){var t=e.data,n=e.containerWidth,r=e.containerHeight,a=e.translateX,o=a===void 0?Ci.translateX:a,s=e.translateY,l=s===void 0?Ci.translateY:s,f=e.anchor,c=e.direction,p=e.padding,m=p===void 0?Ci.padding:p,g=e.justify,b=e.itemsSpacing,w=b===void 0?Ci.itemsSpacing:b,S=e.itemWidth,_=e.itemHeight,j=e.itemDirection,E=e.itemTextColor,O=e.itemBackground,C=e.itemOpacity,T=e.symbolShape,R=e.symbolSize,A=e.symbolSpacing,P=e.symbolBorderWidth,D=e.symbolBorderColor,M=e.onClick,I=e.onMouseEnter,F=e.onMouseLeave,L=e.toggleSerie,q=e.effects,U=T3({itemCount:t.length,itemsSpacing:w,itemWidth:S,itemHeight:_,direction:c,padding:m}),$=U.width,V=U.height,z=Wae({anchor:f,translateX:o,translateY:l,containerWidth:n,containerHeight:r,width:$,height:V}),W=z.x,H=z.y;return d.jsx(aqe,{data:t,x:W,y:H,direction:c,padding:m,justify:g,effects:q,itemsSpacing:w,itemWidth:S,itemHeight:_,itemDirection:j,itemTextColor:E,itemBackground:O,itemOpacity:C,symbolShape:T,symbolSize:R,symbolSpacing:A,symbolBorderWidth:P,symbolBorderColor:D,onClick:M,onMouseEnter:I,onMouseLeave:F,toggleSerie:typeof L=="boolean"?void 0:L})},"E"),oqe={start:"left",middle:"center",end:"right"},sqe=i(function(e,t){var n=t.data,r=t.containerWidth,a=t.containerHeight,o=t.translateX,s=o===void 0?0:o,l=t.translateY,f=l===void 0?0:l,c=t.anchor,p=t.direction,m=t.padding,g=m===void 0?0:m,b=t.justify,w=b!==void 0&&b,S=t.itemsSpacing,_=S===void 0?0:S,j=t.itemWidth,E=t.itemHeight,O=t.itemDirection,C=O===void 0?"left-to-right":O,T=t.itemTextColor,R=t.symbolSize,A=R===void 0?16:R,P=t.symbolSpacing,D=P===void 0?8:P,M=t.theme,I=T3({itemCount:n.length,itemWidth:j,itemHeight:E,itemsSpacing:_,direction:p,padding:g}),F=I.width,L=I.height,q=I.padding,U=Wae({anchor:c,translateX:s,translateY:f,containerWidth:r,containerHeight:a,width:F,height:L}),$=U.x,V=U.y,z=p==="row"?j+_:0,W=p==="column"?E+_:0;e.save(),e.translate($,V),Ig(e,M.legends.text),n.forEach((function(H,Q){var Y,K=Q*z+q.left,ee=Q*W+q.top,te=Gae({direction:C,justify:w,symbolSize:A,symbolSpacing:D,width:j,height:E}),oe=te.symbolX,ne=te.symbolY,fe=te.labelX,re=te.labelY,ce=te.labelAnchor,he=te.labelAlignment;e.fillStyle=(Y=H.color)!=null?Y:"black",e.fillRect(K+oe,ee+ne,A,A),e.textAlign=oqe[ce],he==="central"&&(e.textBaseline="middle"),Fg(e,oc({},M.legends.text,{fill:T??M.legends.text.fill}),String(H.label),K+fe,ee+re)})),e.restore()},"L"),lqe=i(function(e,t,n,r,a,o){o>0?(e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.quadraticCurveTo(t+r,n,t+r,n+o),e.lineTo(t+r,n+a-o),e.quadraticCurveTo(t+r,n+a,t+r-o,n+a),e.lineTo(t+o,n+a),e.quadraticCurveTo(t,n+a,t,n+a-o),e.lineTo(t,n+o),e.quadraticCurveTo(t,n,t+o,n),e.closePath()):e.rect(t,n,r,a)},"o");function vn(){return vn=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},vn.apply(null,arguments)}i(vn,"Q");function Fc(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}i(Fc,"U");var hW,cqe=i(function(e){var t=e.bars,n=e.annotations,r=Uae({data:t,annotations:n,getPosition:i(function(a){return{x:a.x+a.width/2,y:a.y+a.height/2}},"getPosition"),getDimensions:i(function(a){var o=a.height,s=a.width;return{width:s,height:o,size:Math.max(s,o)}},"getDimensions")});return d.jsx(d.Fragment,{children:r.map((function(a,o){return d.jsx(D9e,vn({},a),o)}))})},"$"),uqe=i(function(e){var t=e.width,n=e.height,r=e.legends,a=e.toggleSerie;return d.jsx(d.Fragment,{children:r.map((function(o,s){var l,f=o[0],c=o[1];return d.jsx(iqe,vn({},f,{containerWidth:t,containerHeight:n,data:(l=f.data)!=null?l:c,toggleSerie:f.toggleSerie&&f.dataFrom==="keys"?a:void 0}),s)}))})},"ee"),dqe=["data"],fqe=i(function(e){var t,n=e.bar,r=n.data,a=Fc(n,dqe),o=e.style,s=o.borderColor,l=o.color,f=o.height,c=o.labelColor,p=o.labelOpacity,m=o.labelX,g=o.labelY,b=o.transform,w=o.width,S=o.textAnchor,_=e.borderRadius,j=e.borderWidth,E=e.label,O=e.shouldRenderLabel,C=e.isInteractive,T=e.onClick,R=e.onMouseEnter,A=e.onMouseLeave,P=e.tooltip,D=e.isFocusable,M=e.ariaLabel,I=e.ariaLabelledBy,F=e.ariaDescribedBy,L=e.ariaDisabled,q=e.ariaHidden,U=Mr(),$=wre(),V=$.showTooltipFromEvent,z=$.showTooltipAt,W=$.hideTooltip,H=y.useMemo((function(){return function(){return y.createElement(P,vn({},a,r))}}),[P,a,r]),Q=y.useCallback((function(ne){T?.(vn({color:a.color},r),ne)}),[a,r,T]),Y=y.useCallback((function(ne){return V(H(),ne)}),[V,H]),K=y.useCallback((function(ne){R?.(r,ne),V(H(),ne)}),[r,R,V,H]),ee=y.useCallback((function(ne){A?.(r,ne),W()}),[r,W,A]),te=y.useCallback((function(){z(H(),[a.absX+a.width/2,a.absY])}),[z,H,a]),oe=y.useCallback((function(){W()}),[W]);return d.jsxs(pr.g,{transform:b,children:[d.jsx(pr.rect,{width:UN(w,(function(ne){return Math.max(ne,0)})),height:UN(f,(function(ne){return Math.max(ne,0)})),rx:_,ry:_,fill:(t=r.fill)!=null?t:l,strokeWidth:j,stroke:s,focusable:D,tabIndex:D?0:void 0,"aria-label":M?M(r):void 0,"aria-labelledby":I?I(r):void 0,"aria-describedby":F?F(r):void 0,"aria-disabled":L?L(r):void 0,"aria-hidden":q?q(r):void 0,onMouseEnter:C?K:void 0,onMouseMove:C?Y:void 0,onMouseLeave:C?ee:void 0,onClick:C?Q:void 0,onFocus:C&&D?te:void 0,onBlur:C&&D?oe:void 0,"data-testid":"bar.item."+r.id+"."+r.index}),O&&d.jsx(V_,{x:m,y:g,textAnchor:S,dominantBaseline:"central",fillOpacity:p,style:vn({},U.labels.text,{pointerEvents:"none",fill:c}),children:E})]})},"ae"),hqe=["color","label"],pqe=i(function(e){var t=e.color,n=e.label,r=Fc(e,hqe);return d.jsx(D8e,{id:n,value:r.formattedValue,enableChip:!0,color:t})},"ne"),Fn={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:pqe,tooltipLabel:i(function(e){return e.id+" - "+e.indexValue},"tooltipLabel"),legends:[],initialHiddenIds:[],annotations:[],enableTotals:!1,totalsOffset:10},In=vn({},Fn,{layers:["grid","axes","bars","totals","markers","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},barComponent:fqe,defs:[],fill:[],markers:[],animate:!0,animateOnMount:!1,motionConfig:"default",role:"img",isFocusable:!1}),gr=vn({},Fn,{layers:["grid","axes","bars","totals","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},renderBar:i(function(e,t){var n=t.bar,r=n.color,a=n.height,o=n.width,s=n.x,l=n.y,f=t.borderColor,c=t.borderRadius,p=t.borderWidth,m=t.label,g=t.shouldRenderLabel,b=t.labelStyle,w=t.labelX,S=t.labelY,_=t.textAnchor;e.fillStyle=r,p>0&&(e.strokeStyle=f,e.lineWidth=p),e.beginPath(),lqe(e,s,l,o,a,Math.min(c,a)),e.fill(),p>0&&e.stroke(),g&&(e.textBaseline="middle",e.textAlign=_==="middle"?"center":_,Fg(e,b,m,s+w,l+S))},"renderBar"),pixelRatio:typeof window<"u"&&(hW=window.devicePixelRatio)!=null?hW:1}),Kae=i(function(e,t,n,r,a,o){return A3(r,{all:e.map(t),min:0,max:0},a,o).padding(n)},"de"),Yae=i(function(e,t){return e.map((function(n){return vn({},t.reduce((function(r,a){return r[a]=null,r}),{}),n)}))},"ue"),H_=i(function(e){return Object.keys(e).reduce((function(t,n){return e[n]&&(t[n]=e[n]),t}),{})},"se"),W_=i(function(e){return[e,Number(e)]},"ce");function Qae(e,t,n,r){return e===void 0&&(e=Fn.layout),n===void 0&&(n=Fn.labelPosition),r===void 0&&(r=Fn.labelOffset),function(a,o){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:o/2,textAnchor:n==="middle"?"middle":t?"end":"start"}}var f=o/2;return n==="start"?f=t?0:o:n==="end"&&(f=t?o:0),{labelX:a/2,labelY:f-s,textAnchor:"middle"}}}i(Qae,"he");var mqe=["layout","width","height","padding","innerPadding","valueScale","indexScale","hiddenIds"],P3=i(function(e,t){return e>t},"be"),Xae=i(function(e,t){return e<t},"ge"),Zae=i(function(e,t){return Array.from(" ".repeat(t-e),(function(n,r){return e+r}))},"ve"),vqe=i(function(e){return P3(e,0)?0:e},"me"),gqe=i(function(e,t,n,r){var a=e.data,o=e.formatValue,s=e.getColor,l=e.getIndex,f=e.getTooltipLabel,c=e.innerPadding,p=c===void 0?0:c,m=e.keys,g=e.xScale,b=e.yScale,w=e.margin,S=n?Xae:P3,_=a.map(H_),j=[];return m.forEach((function(E,O){return Zae(0,g.domain().length).forEach((function(C){var T,R,A,P=W_(a[C][E]),D=P[0],M=P[1],I=l(a[C]),F=((T=g(I))!=null?T:0)+t*O+p*O,L=S(R=M,0)?(A=b(R))!=null?A:0:r,q=(function($,V){var z;return S($,0)?r-V:((z=b($))!=null?z:0)-r})(M,L),U={id:E,value:D===null?D:M,formattedValue:o(M),hidden:!1,index:C,indexValue:I,data:_[C]};j.push({key:E+"."+U.indexValue,index:j.length,data:U,x:F,y:L,absX:w.left+F,absY:w.top+L,width:t,height:q,color:s(U),label:f(U)})}))})),j},"pe"),yqe=i(function(e,t,n,r){var a=e.data,o=e.formatValue,s=e.getIndex,l=e.getColor,f=e.getTooltipLabel,c=e.keys,p=e.innerPadding,m=p===void 0?0:p,g=e.xScale,b=e.yScale,w=e.margin,S=n?Xae:P3,_=a.map(H_),j=[];return c.forEach((function(E,O){return Zae(0,b.domain().length).forEach((function(C){var T,R,A,P=W_(a[C][E]),D=P[0],M=P[1],I=s(a[C]),F=S(R=M,0)?r:(A=g(R))!=null?A:0,L=((T=b(I))!=null?T:0)+t*O+m*O,q=(function($,V){var z;return S($,0)?((z=g($))!=null?z:0)-r:r-V})(M,F),U={id:E,value:D===null?D:M,formattedValue:o(M),hidden:!1,index:C,indexValue:I,data:_[C]};j.push({key:E+"."+U.indexValue,index:j.length,data:U,x:F,y:L,absX:w.left+F,absY:w.top+L,width:q,height:t,color:l(U),label:f(U)})}))})),j},"ye"),bqe=i(function(e){var t,n,r,a=e.layout,o=e.width,s=e.height,l=e.padding,f=l===void 0?0:l,c=e.innerPadding,p=c===void 0?0:c,m=e.valueScale,g=e.indexScale,b=e.hiddenIds,w=b===void 0?[]:b,S=Fc(e,mqe),_=S.keys.filter((function(V){return!w.includes(V)})),j=Yae(S.data,_),E=a==="vertical"?["y","x",o]:["x","y",s],O=E[0],C=E[1],T=E[2],R=Kae(j,S.getIndex,f,g,T,C),A=m.min==="auto"?vqe:function(V){return V},P=j.reduce((function(V,z){return[].concat(V,_.map((function(W){return z[W]})))}),[]).filter(Boolean),D=A(Math.min.apply(Math,P)),M=(r=Math.max.apply(Math,P),isFinite(r)?r:0),I=A3(m,{all:P,min:D,max:M},O==="x"?o:s,O),F=a==="vertical"?[R,I]:[I,R],L=F[0],q=F[1],U=(R.bandwidth()-p*(_.length-1))/_.length,$=[vn({},S,{data:j,keys:_,innerPadding:p,xScale:L,yScale:q}),U,(t=m.reverse)!=null&&t,(n=I(0))!=null?n:0];return{xScale:L,yScale:q,bars:U>0?a==="vertical"?gqe.apply(void 0,$):yqe.apply(void 0,$):[]}},"xe"),xqe=["data","layout","width","height","padding","valueScale","indexScale","hiddenIds"],Jae=i(function(e){var t;return e.some(Array.isArray)?Jae((t=[]).concat.apply(t,e)):e},"ke"),wqe=i(function(e,t,n){var r=e.formatValue,a=e.getColor,o=e.getIndex,s=e.getTooltipLabel,l=e.innerPadding,f=e.stackedData,c=e.xScale,p=e.yScale,m=e.margin,g=[];return f.forEach((function(b){return c.domain().forEach((function(w,S){var _,j,E=b[S],O=(_=c(o(E.data)))!=null?_:0,C=((j=(function(M){return p(M[n?0:1])})(E))!=null?j:0)+.5*l,T=(function(M,I){var F;return((F=p(M[n?1:0]))!=null?F:0)-I})(E,C)-l,R=W_(E.data[b.key]),A=R[0],P=R[1],D={id:b.key,value:A===null?A:P,formattedValue:r(P),hidden:!1,index:S,indexValue:w,data:H_(E.data)};g.push({key:b.key+"."+w,index:g.length,data:D,x:O,y:C,absX:m.left+O,absY:m.top+C,width:t,height:T,color:a(D),label:s(D)})}))})),g},"we"),_qe=i(function(e,t,n){var r=e.formatValue,a=e.getColor,o=e.getIndex,s=e.getTooltipLabel,l=e.innerPadding,f=e.stackedData,c=e.xScale,p=e.yScale,m=e.margin,g=[];return f.forEach((function(b){return p.domain().forEach((function(w,S){var _,j,E=b[S],O=(_=p(o(E.data)))!=null?_:0,C=((j=(function(M){return c(M[n?1:0])})(E))!=null?j:0)+.5*l,T=(function(M,I){var F;return((F=c(M[n?0:1]))!=null?F:0)-I})(E,C)-l,R=W_(E.data[b.key]),A=R[0],P=R[1],D={id:b.key,value:A===null?A:P,formattedValue:r(P),hidden:!1,index:S,indexValue:w,data:H_(E.data)};g.push({key:b.key+"."+w,index:g.length,data:D,x:C,y:O,absX:m.left+C,absY:m.top+O,width:T,height:t,color:a(D),label:s(D)})}))})),g},"Le"),Sqe=i(function(e){var t,n,r=e.data,a=e.layout,o=e.width,s=e.height,l=e.padding,f=l===void 0?0:l,c=e.valueScale,p=e.indexScale,m=e.hiddenIds,g=m===void 0?[]:m,b=Fc(e,xqe),w=b.keys.filter((function(U){return!g.includes(U)})),S=GIe().keys(w).offset(KIe)(Yae(r,w)),_=a==="vertical"?["y","x",o]:["x","y",s],j=_[0],E=_[1],O=_[2],C=Kae(r,b.getIndex,f,p,O,E),T=(n=Jae(S),c.type==="log"?n.filter((function(U){return U!==0})):n),R=Math.min.apply(Math,T),A=Math.max.apply(Math,T),P=A3(c,{all:T,min:R,max:A},j==="x"?o:s,j),D=a==="vertical"?[C,P]:[P,C],M=D[0],I=D[1],F=b.innerPadding>0?b.innerPadding:0,L=C.bandwidth(),q=[vn({},b,{innerPadding:F,stackedData:S,xScale:M,yScale:I}),L,(t=c.reverse)!=null&&t];return{xScale:M,yScale:I,bars:L>0?a==="vertical"?wqe.apply(void 0,q):_qe.apply(void 0,q):[]}},"Ce"),jqe=i(function(e){var t=e.bars,n=e.direction,r=e.from,a=e.groupMode,o=e.layout,s=e.legendLabel,l=e.reverse,f=Pae(s??(r==="indexes"?"indexValue":"id"));return r==="indexes"?(function(c,p,m){var g=qH(c.map((function(b){var w,S;return{id:(w=b.data.indexValue)!=null?w:"",label:m(b.data),hidden:b.data.hidden,color:(S=b.color)!=null?S:"#000"}})),(function(b){return b.id}));return p==="horizontal"&&g.reverse(),g})(t,o,f):(function(c,p,m,g,b,w){var S=qH(c.map((function(_){var j;return{id:_.data.id,label:w(_.data),hidden:_.data.hidden,color:(j=_.color)!=null?j:"#000"}})),(function(_){return _.id}));return(p==="vertical"&&g==="stacked"&&m==="column"&&b!==!0||p==="horizontal"&&g==="stacked"&&b===!0)&&S.reverse(),S})(t,o,n,a,l,f)},"We"),pW=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+n)},"Me"),Eqe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+(n>0?n:0))},"Be"),Cqe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,Math.max(r,Number(n)))},"Re"),Oqe=i(function(e,t){var n=e.get(t)||0;e.set(t,n+1)},"Oe"),eie=i(function(e){var t,n=e.indexBy,r=n===void 0?Fn.indexBy:n,a=e.keys,o=a===void 0?Fn.keys:a,s=e.label,l=s===void 0?Fn.label:s,f=e.tooltipLabel,c=f===void 0?Fn.tooltipLabel:f,p=e.valueFormat,m=e.colors,g=m===void 0?Fn.colors:m,b=e.colorBy,w=b===void 0?Fn.colorBy:b,S=e.borderColor,_=S===void 0?Fn.borderColor:S,j=e.labelTextColor,E=j===void 0?Fn.labelTextColor:j,O=e.groupMode,C=O===void 0?Fn.groupMode:O,T=e.layout,R=T===void 0?Fn.layout:T,A=e.data,P=e.margin,D=e.width,M=e.height,I=e.padding,F=I===void 0?Fn.padding:I,L=e.innerPadding,q=L===void 0?Fn.innerPadding:L,U=e.valueScale,$=U===void 0?Fn.valueScale:U,V=e.indexScale,z=V===void 0?Fn.indexScale:V,W=e.initialHiddenIds,H=W===void 0?Fn.initialHiddenIds:W,Q=e.enableLabel,Y=Q===void 0?Fn.enableLabel:Q,K=e.labelSkipWidth,ee=K===void 0?Fn.labelSkipWidth:K,te=e.labelSkipHeight,oe=te===void 0?Fn.labelSkipHeight:te,ne=e.legends,fe=ne===void 0?Fn.legends:ne,re=e.legendLabel,ce=e.totalsOffset,he=ce===void 0?Fn.totalsOffset:ce,J=y.useState(H??[]),Me=J[0],we=J[1],Ee=y.useCallback((function(Ke){we((function(pt){return pt.indexOf(Ke)>-1?pt.filter((function(ge){return ge!==Ke})):[].concat(pt,[Ke])}))}),[]),Re=zA(r),ke=zA(l),Pe=zA(c),Ue=R3(p),X=Mr(),se=Q9e(g,w),me=fW(_,X),Te=fW(E,X),de=(C==="grouped"?bqe:Sqe)({layout:R,data:A,getIndex:Re,keys:o,width:D,height:M,getColor:se,padding:F,innerPadding:q,valueScale:$,indexScale:z,hiddenIds:Me,formatValue:Ue,getTooltipLabel:Pe,margin:P}),ue=de.bars,Ae=de.xScale,Ne=de.yScale,Fe=y.useMemo((function(){return ue.filter((function(Ke){return Ke.data.value!==null})).map((function(Ke,pt){return vn({},Ke,{index:pt})}))}),[ue]),Je=y.useCallback((function(Ke){var pt=Ke.width,ge=Ke.height;return!!Y&&!(ee>0&&pt<ee)&&!(oe>0&&ge<oe)}),[Y,ee,oe]),Pt=y.useMemo((function(){return o.map((function(Ke){var pt=ue.find((function(ge){return ge.data.id===Ke}));return vn({},pt,{data:vn({id:Ke},pt?.data,{hidden:Me.includes(Ke)})})}))}),[Me,o,ue]),$t=(t=$.reverse)!=null&&t,Rt=y.useMemo((function(){return fe.map((function(Ke){return[Ke,jqe({bars:Ke.dataFrom==="keys"?Pt:ue,direction:Ke.direction,from:Ke.dataFrom,groupMode:C,layout:R,legendLabel:re,reverse:$t})]}))}),[fe,Pt,ue,C,R,re,$t]),qt=y.useMemo((function(){return(function(Ke,pt,ge,ye,ct,Le,Xe){ye===void 0&&(ye=Fn.layout),ct===void 0&&(ct=Fn.groupMode);var We=[];if(Ke.length===0)return We;var et=new Map,jt=Ke[0].width,Ye=Ke[0].height;if(ct==="stacked"){var mt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Ct=_t.value;pW(et,vt,Number(Ct)),Eqe(mt,vt,Number(Ct))})),mt.forEach((function(At,_t){var vt,Ct,Z,pe=et.get(_t)||0;ye==="vertical"?(vt=pt(_t),Ct=ge(At),Z=ge(At/2)):(vt=pt(At),Ct=ge(_t),Z=pt(At/2)),vt+=ye==="vertical"?jt/2:Le,Ct+=ye==="vertical"?-Le:Ye/2,We.push({key:"total_"+_t,x:vt,y:Ct,value:pe,formattedValue:Xe(pe),animationOffset:Z})}))}else if(ct==="grouped"){var Ft=new Map,Nt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Ct=_t.value;pW(et,vt,Number(Ct)),Cqe(Ft,vt,Number(Ct)),Oqe(Nt,vt)})),Ft.forEach((function(At,_t){var vt,Ct,Z,pe=et.get(_t)||0,_e=Nt.get(_t);ye==="vertical"?(vt=pt(_t),Ct=ge(At),Z=ge(At/2)):(vt=pt(At),Ct=ge(_t),Z=pt(At/2)),vt+=ye==="vertical"?_e*jt/2:Le,Ct+=ye==="vertical"?-Le:_e*Ye/2,We.push({key:"total_"+_t,x:vt,y:Ct,value:pe,formattedValue:Xe(pe),animationOffset:Z})}))}return We})(ue,Ae,Ne,R,C,he,Ue)}),[ue,Ae,Ne,R,C,he,Ue]);return{bars:ue,barsWithValue:Fe,xScale:Ae,yScale:Ne,getIndex:Re,getLabel:ke,getTooltipLabel:Pe,formatValue:Ue,getColor:se,getBorderColor:me,getLabelColor:Te,shouldRenderBarLabel:Je,hiddenIds:Me,toggleSerie:Ee,legendsWithData:Rt,barTotals:qt}},"Ie"),kqe=i(function(e){var t=e.data,n=e.springConfig,r=e.animate,a=e.layout,o=a===void 0?In.layout:a,s=Mr();return o_(t,{keys:i(function(l){return l.key},"keys"),from:i(function(l){return{x:o==="vertical"?l.x:l.animationOffset,y:o==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"from"),enter:i(function(l){return{x:l.x,y:l.y,labelOpacity:1}},"enter"),update:i(function(l){return{x:l.x,y:l.y,labelOpacity:1}},"update"),leave:i(function(l){return{x:o==="vertical"?l.x:l.animationOffset,y:o==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"leave"),config:n,immediate:!r,initial:r?void 0:null})((function(l,f){return d.jsx(pr.text,{x:l.x,y:l.y,fillOpacity:l.labelOpacity,style:vn({},s.labels.text,{pointerEvents:"none"}),fontWeight:"bold",fontSize:s.labels.text.fontSize,fontFamily:s.labels.text.fontFamily,textAnchor:o==="vertical"?"middle":"start",alignmentBaseline:o==="vertical"?"alphabetic":"middle",children:f.formattedValue},f.key)}))},"Ve"),Rqe=["isInteractive","animate","motionConfig","theme","renderWrapper"],Aqe=i(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,o=e.margin,s=e.width,l=e.height,f=e.groupMode,c=e.layout,p=e.valueScale,m=e.indexScale,g=e.padding,b=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,j=_===void 0?In.axisBottom:_,E=e.axisLeft,O=E===void 0?In.axisLeft:E,C=e.enableGridX,T=C===void 0?In.enableGridX:C,R=e.enableGridY,A=R===void 0?In.enableGridY:R,P=e.gridXValues,D=e.gridYValues,M=e.layers,I=M===void 0?In.layers:M,F=e.barComponent,L=F===void 0?In.barComponent:F,q=e.enableLabel,U=q===void 0?In.enableLabel:q,$=e.label,V=e.labelSkipWidth,z=V===void 0?In.labelSkipWidth:V,W=e.labelSkipHeight,H=W===void 0?In.labelSkipHeight:W,Q=e.labelTextColor,Y=e.labelPosition,K=Y===void 0?In.labelPosition:Y,ee=e.labelOffset,te=ee===void 0?In.labelOffset:ee,oe=e.markers,ne=oe===void 0?In.markers:oe,fe=e.colorBy,re=e.colors,ce=e.defs,he=ce===void 0?In.defs:ce,J=e.fill,Me=J===void 0?In.fill:J,we=e.borderRadius,Ee=we===void 0?In.borderRadius:we,Re=e.borderWidth,ke=Re===void 0?In.borderWidth:Re,Pe=e.borderColor,Ue=e.annotations,X=Ue===void 0?In.annotations:Ue,se=e.legendLabel,me=e.tooltipLabel,Te=e.valueFormat,de=e.isInteractive,ue=de===void 0?In.isInteractive:de,Ae=e.tooltip,Ne=Ae===void 0?In.tooltip:Ae,Fe=e.onClick,Je=e.onMouseEnter,Pt=e.onMouseLeave,$t=e.legends,Rt=e.role,qt=Rt===void 0?In.role:Rt,Ke=e.ariaLabel,pt=e.ariaLabelledBy,ge=e.ariaDescribedBy,ye=e.isFocusable,ct=ye===void 0?In.isFocusable:ye,Le=e.barAriaLabel,Xe=e.barAriaLabelledBy,We=e.barAriaDescribedBy,et=e.barAriaHidden,jt=e.barAriaDisabled,Ye=e.initialHiddenIds,mt=e.enableTotals,Ft=mt===void 0?In.enableTotals:mt,Nt=e.totalsOffset,At=Nt===void 0?In.totalsOffset:Nt,_t=e.forwardedRef,vt=ho(),Ct=vt.animate,Z=vt.config,pe=Tae(s,l,o),_e=pe.outerWidth,$e=pe.outerHeight,Ve=pe.margin,rt=pe.innerWidth,nt=pe.innerHeight,Qe=eie({indexBy:r,label:$,tooltipLabel:me,valueFormat:Te,colors:re,colorBy:fe,borderColor:Pe,labelTextColor:Q,groupMode:f,layout:c,data:n,keys:a,margin:Ve,width:rt,height:nt,padding:g,innerPadding:b,valueScale:p,indexScale:m,enableLabel:U,labelSkipWidth:z,labelSkipHeight:H,legends:$t,legendLabel:se,initialHiddenIds:Ye,totalsOffset:At}),ot=Qe.bars,ut=Qe.barsWithValue,st=Qe.xScale,lt=Qe.yScale,gt=Qe.getLabel,at=Qe.getTooltipLabel,kt=Qe.getBorderColor,bt=Qe.getLabelColor,Lt=Qe.shouldRenderBarLabel,Mt=Qe.toggleSerie,Fr=Qe.legendsWithData,Oa=Qe.barTotals,li=Qe.getColor,cr=Qae(c,(t=p?.reverse)!=null&&t,K,te),po=o_(ut,{keys:i(function(He){return He.key},"keys"),from:i(function(He){return vn({borderColor:kt(He),color:He.color,height:0,labelColor:bt(He),labelOpacity:0},cr(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:i(function(He){return vn({borderColor:kt(He),color:He.color,height:He.height,labelColor:bt(He),labelOpacity:1},cr(He.width,He.height),{transform:"translate("+He.x+", "+He.y+")",width:He.width})},"enter"),update:i(function(He){return vn({borderColor:kt(He),color:He.color,height:He.height,labelColor:bt(He),labelOpacity:1},cr(He.width,He.height),{transform:"translate("+He.x+", "+He.y+")",width:He.width})},"update"),leave:i(function(He){return vn({borderColor:kt(He),color:He.color,height:0,labelColor:bt(He),labelOpacity:0},cr(He.width,He.height),{labelY:0,transform:"translate("+He.x+", "+(He.y+He.height)+")",width:He.width},c==="vertical"?{}:vn({},cr(He.width,He.height),{labelX:0,height:He.height,transform:"translate("+He.x+", "+He.y+")",width:0}))},"leave"),config:Z,immediate:!Ct,initial:Ct?void 0:null}),Lr=y.useMemo((function(){return{borderRadius:Ee,borderWidth:ke,enableLabel:U,isInteractive:ue,labelSkipWidth:z,labelSkipHeight:H,onClick:Fe,onMouseEnter:Je,onMouseLeave:Pt,getTooltipLabel:at,tooltip:Ne,isFocusable:ct,ariaLabel:Le,ariaLabelledBy:Xe,ariaDescribedBy:We,ariaHidden:et,ariaDisabled:jt}}),[Ee,ke,U,at,ue,H,z,Fe,Je,Pt,Ne,ct,Le,Xe,We,et,jt]),Ha=O7e(he,ot,Me,{dataKey:"data",targetKey:"data.fill"}),Zr={annotations:null,axes:null,bars:null,grid:null,legends:null,markers:null,totals:null};I.includes("annotations")&&(Zr.annotations=d.jsx(cqe,{bars:ot,annotations:X},"annotations")),I.includes("axes")&&(Zr.axes=d.jsx(s9e,{xScale:st,yScale:lt,width:rt,height:nt,top:w,right:S,bottom:j,left:O},"axes")),I.includes("bars")&&(Zr.bars=d.jsx(y.Fragment,{children:po((function(He,$n){return y.createElement(L,vn({},Lr,{bar:$n,style:He,shouldRenderLabel:Lt($n),label:gt($n.data)}))}))},"bars")),I.includes("grid")&&(Zr.grid=d.jsx(c9e,{width:rt,height:nt,xScale:T?st:null,yScale:A?lt:null,xValues:P,yValues:D},"grid")),I.includes("legends")&&(Zr.legends=d.jsx(uqe,{width:rt,height:nt,legends:Fr,toggleSerie:Mt},"legends")),I.includes("markers")&&(Zr.markers=d.jsx(g7e,{markers:ne,width:rt,height:nt,xScale:st,yScale:lt},"markers")),I.includes("totals")&&Ft&&(Zr.totals=d.jsx(kqe,{data:Oa,springConfig:Z,animate:Ct,layout:c},"totals"));var Wa=vn({},Lr,{margin:Ve,width:s,height:l,innerWidth:rt,innerHeight:nt,bars:ot,legendData:Fr,enableLabel:U,xScale:st,yScale:lt,tooltip:Ne,getTooltipLabel:at,onClick:Fe,onMouseEnter:Je,onMouseLeave:Pt,getColor:li});return d.jsx(p7e,{width:_e,height:$e,margin:Ve,defs:Ha,role:qt,ariaLabel:Ke,ariaLabelledBy:pt,ariaDescribedBy:ge,isFocusable:ct,ref:_t,children:I.map((function(He,$n){var Ii;return typeof He=="function"?d.jsx(y.Fragment,{children:y.createElement(He,Wa)},$n):(Ii=Zr?.[He])!=null?Ii:null}))})},"He"),Tqe=y.forwardRef((function(e,t){var n=e.isInteractive,r=n===void 0?In.isInteractive:n,a=e.animate,o=a===void 0?In.animate:a,s=e.motionConfig,l=s===void 0?In.motionConfig:s,f=e.theme,c=e.renderWrapper,p=Fc(e,Rqe);return d.jsx(Cae,{animate:o,isInteractive:r,motionConfig:l,renderWrapper:c,theme:f,children:d.jsx(Aqe,vn({},p,{isInteractive:r,forwardedRef:t}))})})),Pqe=["isInteractive","renderWrapper","theme"],dT=i(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"),Nqe=i(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,o=e.margin,s=e.width,l=e.height,f=e.groupMode,c=e.layout,p=e.valueScale,m=e.indexScale,g=e.padding,b=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,j=_===void 0?gr.axisBottom:_,E=e.axisLeft,O=E===void 0?gr.axisLeft:E,C=e.enableGridX,T=C===void 0?gr.enableGridX:C,R=e.enableGridY,A=R===void 0?gr.enableGridY:R,P=e.gridXValues,D=e.gridYValues,M=e.labelPosition,I=M===void 0?gr.labelPosition:M,F=e.labelOffset,L=F===void 0?gr.labelOffset:F,q=e.layers,U=q===void 0?gr.layers:q,$=e.renderBar,V=$===void 0?gr.renderBar:$,z=e.enableLabel,W=z===void 0?gr.enableLabel:z,H=e.label,Q=e.labelSkipWidth,Y=Q===void 0?gr.labelSkipWidth:Q,K=e.labelSkipHeight,ee=K===void 0?gr.labelSkipHeight:K,te=e.labelTextColor,oe=e.colorBy,ne=e.colors,fe=e.borderRadius,re=fe===void 0?gr.borderRadius:fe,ce=e.borderWidth,he=ce===void 0?gr.borderWidth:ce,J=e.borderColor,Me=e.annotations,we=Me===void 0?gr.annotations:Me,Ee=e.legendLabel,Re=e.tooltipLabel,ke=e.valueFormat,Pe=e.isInteractive,Ue=Pe===void 0?gr.isInteractive:Pe,X=e.tooltip,se=X===void 0?gr.tooltip:X,me=e.onClick,Te=e.onMouseEnter,de=e.onMouseLeave,ue=e.legends,Ae=e.pixelRatio,Ne=Ae===void 0?gr.pixelRatio:Ae,Fe=e.role,Je=e.forwardedRef,Pt=e.enableTotals,$t=Pt===void 0?gr.enableTotals:Pt,Rt=e.totalsOffset,qt=Rt===void 0?gr.totalsOffset:Rt,Ke=y.useRef(null),pt=Mr(),ge=Tae(s,l,o),ye=ge.margin,ct=ge.innerWidth,Le=ge.innerHeight,Xe=ge.outerWidth,We=ge.outerHeight,et=eie({indexBy:r,label:H,tooltipLabel:Re,valueFormat:ke,colors:ne,colorBy:oe,borderColor:J,labelTextColor:te,groupMode:f,layout:c,data:n,keys:a,margin:ye,width:ct,height:Le,padding:g,innerPadding:b,valueScale:p,indexScale:m,enableLabel:W,labelSkipWidth:Y,labelSkipHeight:ee,legends:ue,legendLabel:Ee,totalsOffset:qt}),jt=et.bars,Ye=et.barsWithValue,mt=et.xScale,Ft=et.yScale,Nt=et.getLabel,At=et.getTooltipLabel,_t=et.getBorderColor,vt=et.getLabelColor,Ct=et.shouldRenderBarLabel,Z=et.legendsWithData,pe=et.barTotals,_e=et.getColor,$e=wre(),Ve=$e.showTooltipFromEvent,rt=$e.hideTooltip,nt=k9e({annotations:Uae({data:jt,annotations:we,getPosition:i(function(at){return{x:at.x,y:at.y}},"getPosition"),getDimensions:i(function(at){var kt=at.width,bt=at.height;return{width:kt,height:bt,size:Math.max(kt,bt)}},"getDimensions")})}),Qe=y.useMemo((function(){return{borderRadius:re,borderWidth:he,isInteractive:Ue,isFocusable:!1,labelSkipWidth:Y,labelSkipHeight:ee,margin:ye,width:s,height:l,innerWidth:ct,innerHeight:Le,bars:jt,legendData:Z,enableLabel:W,xScale:mt,yScale:Ft,tooltip:se,getTooltipLabel:At,onClick:me,onMouseEnter:Te,onMouseLeave:de,getColor:_e}}),[re,he,Ue,Y,ee,ye,s,l,ct,Le,jt,Z,W,mt,Ft,se,At,me,Te,de,_e]),ot=R3(ke),ut=Qae(c,(t=p?.reverse)!=null&&t,I,L);y.useEffect((function(){if(Ke.current){Ke.current.width=Xe*Ne,Ke.current.height=We*Ne;var at=Ke.current.getContext("2d");at.scale(Ne,Ne),at.fillStyle=pt.background,at.fillRect(0,0,Xe,We),at.translate(ye.left,ye.top),U.forEach((function(kt){kt==="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&&JH(at,{width:ct,height:Le,scale:mt,axis:"x",values:P}),A&&JH(at,{width:ct,height:Le,scale:Ft,axis:"y",values:D})):kt==="axes"?d9e(at,{xScale:mt,yScale:Ft,width:ct,height:Le,top:w,right:S,bottom:j,left:O,theme:pt}):kt==="bars"?(Ig(at,pt.text),Ye.forEach((function(bt){V(at,vn({bar:bt,borderColor:_t(bt),borderRadius:re,borderWidth:he,label:Nt(bt.data),shouldRenderLabel:Ct(bt),labelStyle:vn({},pt.labels.text,{fill:vt(bt)})},ut(bt.width,bt.height)))}))):kt==="legends"?Z.forEach((function(bt){var Lt=bt[0],Mt=bt[1];sqe(at,vn({},Lt,{data:Mt,containerWidth:ct,containerHeight:Le,theme:pt}))})):kt==="annotations"?M9e(at,{annotations:nt,theme:pt}):kt==="totals"&&$t?(function(bt,Lt,Mt,Fr){Fr===void 0&&(Fr=gr.layout),Ig(bt,Mt.labels.text),bt.textBaseline=Fr==="vertical"?"alphabetic":"middle",bt.textAlign=Fr==="vertical"?"center":"start",Lt.forEach((function(Oa){Fg(bt,Mt.labels.text,Oa.formattedValue,Oa.x,Oa.y)}))})(at,pe,pt,c):typeof kt=="function"&&kt(at,Qe)})),at.save()}}),[j,O,S,w,Ye,re,he,nt,T,A,_t,Nt,vt,P,D,f,l,Le,ct,Qe,U,c,Z,ye.left,ye.top,We,Xe,Ne,V,mt,Ft,Ct,pt,s,pe,$t,ot,ut]);var st=y.useCallback((function(at){if(jt&&Ke.current){var kt=UA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=dT(jt,ye,bt,Lt);Mt!==void 0?(Ve(y.createElement(se,vn({},Mt.data,{color:Mt.color,label:Mt.label,value:Number(Mt.data.value)})),at),at.type==="mouseenter"&&Te?.(Mt.data,at)):rt()}}),[rt,ye,Te,jt,Ve,se]),lt=y.useCallback((function(at){if(jt&&Ke.current){rt();var kt=UA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=dT(jt,ye,bt,Lt);Mt&&de?.(Mt.data,at)}}),[rt,ye,de,jt]),gt=y.useCallback((function(at){if(jt&&Ke.current){var kt=UA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=dT(jt,ye,bt,Lt);Mt!==void 0&&me?.(vn({},Mt.data,{color:Mt.color}),at)}}),[ye,me,jt]);return d.jsx("canvas",{ref:k7e(Ke,Je),width:Xe*Ne,height:We*Ne,style:{width:Xe,height:We,cursor:Ue?"auto":"normal"},onMouseEnter:Ue?st:void 0,onMouseMove:Ue?st:void 0,onMouseLeave:Ue?lt:void 0,onClick:Ue?gt:void 0,role:Fe})},"ze"),Dqe=y.forwardRef((function(e,t){var n=e.isInteractive,r=e.renderWrapper,a=e.theme,o=Fc(e,Pqe);return d.jsx(Cae,{isInteractive:n,renderWrapper:r,theme:a,animate:!1,children:d.jsx(Nqe,vn({},o,{isInteractive:n,forwardedRef:t}))})})),Mqe=["defaultWidth","defaultHeight","onResize","debounceResize"],Iqe=y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,o=e.debounceResize,s=Fc(e,Mqe);return d.jsx(Oae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:o,children:i(function(l){var f=l.width,c=l.height;return d.jsx(Tqe,vn({},s,{width:f,height:c,ref:t}))},"children")})})),Fqe=["defaultWidth","defaultHeight","onResize","debounceResize"];y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,o=e.debounceResize,s=Fc(e,Fqe);return d.jsx(Oae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:o,children:i(function(l){var f=l.width,c=l.height;return d.jsx(Dqe,vn({},s,{width:f,height:c,ref:t}))},"children")})}));const Lqe={opportunity:.2,"proposal-sent":.5,"in-negociation":.8,delayed:.3},$qe=new Date(new Date().setMonth(new Date().getMonth()-6)).toISOString(),mW="en-US",qqe="USD",zqe=y.memo(()=>{const e=navigator?navigator.languages||[navigator.language]:[mW],{data:t,isPending:n}=za("deals",{pagination:{perPage:100,page:1},sort:{field:"created_at",order:"ASC"},filter:{"created_at@gte":$qe}}),r=y.useMemo(()=>{if(!t)return[];const o=t.reduce((l,f)=>{const c=lP(f.created_at??new Date).toISOString();return l[c]||(l[c]=[]),l[c].push(f),l},{});return Object.keys(o).map(l=>({date:cc(l,"MMM"),won:o[l].filter(f=>f.stage==="won").reduce((f,c)=>(f+=c.amount,f),0),pending:o[l].filter(f=>!["won","lost"].includes(f.stage)).reduce((f,c)=>(f+=c.amount*Lqe[c.stage],f),0),lost:o[l].filter(f=>f.stage==="lost").reduce((f,c)=>(f-=c.amount,f),0)}))},[t]);if(n)return null;const a=r.reduce((o,s)=>(o.min=Math.min(o.min,s.lost),o.max=Math.max(o.max,s.won+s.pending),o),{min:0,max:0});return d.jsxs("div",{className:"flex flex-col",children:[d.jsxs("div",{className:"flex items-center mb-4",children:[d.jsx("div",{className:"mr-3 flex",children:d.jsx(SQ,{className:"text-muted-foreground w-6 h-6"})}),d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Upcoming Deal Revenue"})]}),d.jsx("div",{className:"h-[400px]",children:d.jsx(Iqe,{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:i(({value:o,indexValue:s})=>d.jsxs("div",{className:"p-2 bg-secondary rounded shadow inline-flex items-center gap-1 text-secondary-foreground",children:[d.jsxs("strong",{children:[s,": "]})," ",o>0?"+":"",o.toLocaleString(e.at(0)??mW,{style:"currency",currency:qqe})]}),"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:i(o=>`${Math.abs(o/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"}]})})]})}),Uqe=i(e=>{const t=xt(),n=Ht(e),{filterValues:r,setFilters:a}=qw(e),o=fd();if(!n)throw new Error("<ListNoResults> must be used inside a <List> component");return d.jsx("div",{className:"p-6",children:d.jsx("p",{className:"text-sm text-muted-foreground",children:r&&a&&Object.keys(r).length>0?d.jsxs(d.Fragment,{children:[t("ra.navigation.no_filtered_results",{resource:n,name:o(n,0),_:"No results found with the current filters."})," ",d.jsx(ze,{variant:"outline",size:"sm",onClick:i(()=>a({},[]),"onClick"),children:t("ra.navigation.clear_filters",{_:"Clear filters"})})]}):t("ra.navigation.no_results",{resource:n,name:o(n,0),_:"No results found."})})})},"ListNoResults"),Bqe=i(e=>{const{children:t,linkType:n,rowClick:r,style:a}=e,o=Ht(e),s=Wt(e),l=Sa(),f=typeof n=="function"||typeof r=="function",c=QG({link:f?!1:n??r,resource:o}),p=JG(),m=Et(async()=>{if(!f||!s)return;const g=typeof n=="function"?n(s,s.id):typeof r=="function"?(w,S)=>r(w.id,S,w):!1,b=await p({record:s,resource:o,link:g});b===!1||b==null||l(b)});return s?f?d.jsx("li",{className:"w-full",children:d.jsx("button",{onClick:m,style:a,className:"w-full text-left hover:bg-muted focus: bg-muted focus:outline-none",children:t})}):c?d.jsx("li",{className:"w-full",children:d.jsx(fn,{to:c,style:a,className:"block w-full hover:bg-muted focus:bg-muted focus:outline-none",children:t})}):d.jsx("li",{className:"w-full",children:t}):null},"SimpleListItem"),fT=i(({className:e})=>d.jsx("span",{className:Se("bg-gray-300 flex",e),children:" "}),"ListPlaceholder"),Vqe=i(e=>{const{className:t,hasLeftAvatarOrIcon:n,hasRightAvatarOrIcon:r,hasSecondaryText:a,hasTertiaryText:o,nbFakeLines:s=5,...l}=e;return RK(1e3)?d.jsx("ul",{className:t,...l,children:Hqe(s,c=>d.jsxs("li",{className:"flex items-center space-x-3 p-3",children:[n&&d.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"mb-1",children:[d.jsx(fT,{className:"w-1/3 inline-block mb-1"}),o&&d.jsx("span",{className:"float-right opacity-55 min-w-[10vw]",children:d.jsx(fT,{})})]}),a&&d.jsx(fT,{className:"w-1/4"})]}),r&&d.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "})]},c))}):null},"SimpleListLoading"),Hqe=i((e,t)=>Array.from({length:e},(n,r)=>t(r)),"times"),Wqe=i(e=>{const{className:t,empty:n=Kqe,leftAvatar:r,leftIcon:a,linkType:o,rowClick:s,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,resource:g,...b}=e,{data:w,isPending:S,total:_}=qw(e);return S===!0?d.jsx(Vqe,{className:t,hasLeftAvatarOrIcon:!!a||!!r,hasRightAvatarOrIcon:!!c||!!f,hasSecondaryText:!!p,hasTertiaryText:!!m}):w==null||w.length===0||_===0?n||null:d.jsx("ul",{className:t,...cme(b),children:d.jsx(vme,{data:w,total:_,render:i((j,E)=>d.jsx(Bqe,{rowIndex:E,linkType:o,rowClick:s,resource:g,children:d.jsx(Gqe,{leftAvatar:r,leftIcon:a,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,rowIndex:E})},j.id),"render")})})},"SimpleList"),Gqe=i(e=>{const{leftAvatar:t,leftIcon:n,primaryText:r,rightAvatar:a,rightIcon:o,secondaryText:s,tertiaryText:l}=e,f=Ht(e),c=Wt(e),p=Ec(f),m=xt(),g=i((b,w)=>{const S=w(b,b.id);return typeof S=="string"&&(S.startsWith("http")||S.startsWith("data:"))?d.jsx("img",{src:S,alt:"",className:"w-10 h-10 rounded-full object-cover"}):d.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-sm",children:S})},"renderAvatar");return c?d.jsxs("div",{className:"flex items-center space-x-3 p-3",children:[n&&d.jsx("div",{className:"flex-shrink-0",children:n(c,c.id)}),t&&d.jsx("div",{className:"flex-shrink-0",children:g(c,t)}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.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&&d.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&&d.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||o)&&d.jsxs("div",{className:"flex-shrink-0 flex items-center space-x-2",children:[a&&g(c,a),o&&o(c,c.id)]})]}):null},"SimpleListItemContent"),Kqe=d.jsx(Uqe,{}),Yqe=i(()=>{const{identity:e}=Zn(),{data:t,total:n,isPending:r}=za("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 d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("div",{className:"flex items-center",children:[d.jsx("div",{className:"mr-3 flex",children:d.jsx(IM,{className:"text-muted-foreground w-6 h-6"})}),d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Hot Contacts"}),d.jsx(Pi,{children:d.jsxs(ao,{children:[d.jsx(io,{asChild:!0,children:d.jsx(ze,{variant:"ghost",size:"sm",className:"ml-auto text-muted-foreground",asChild:!0,children:d.jsx(fn,{to:"/contacts/create",children:d.jsx(Ji,{className:"w-4 h-4 text-primary"})})})}),d.jsx(oo,{children:"Create contact"})]})})]}),d.jsx(pn,{className:"py-0",children:d.jsx(Wqe,{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:i(a=>`${a.first_name} ${a.last_name}`,"primaryText"),secondaryText:i(a=>d.jsxs(d.Fragment,{children:[a.title," at ",a.company_name]}),"secondaryText"),leftAvatar:i(a=>d.jsx(is,{record:a}),"leftAvatar"),empty:d.jsxs("div",{className:"p-4",children:[d.jsx("p",{className:"text-sm mb-4",children:'Contacts with a "hot" status will appear here.'}),d.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"),Qqe=i(()=>{const{identity:e}=Zn(),{total:t}=za("tasks",{pagination:{page:1,perPage:1},filter:{sales_id:e?.id}},{enabled:!!e});return t?null:d.jsx("p",{className:"text-sm",children:"Tasks added to your contacts will appear here."})},"TasksListEmpty"),uv=i(({title:e,filter:t})=>{const{identity:n}=Zn(),{data:r,total:a,isPending:o}=za("tasks",{pagination:{page:1,perPage:100},sort:{field:"due_date",order:"ASC"},filter:{...t,sales_id:n?.id}},{enabled:!!n}),s=zw({data:r,isPending:o,resource:"tasks",perPage:5});return o||!r||!a?null:d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium mb-2",children:e}),d.jsx(dd,{value:"tasks",children:d.jsx(ny,{value:s,children:d.jsx(jne,{showContact:!0})})}),a>s.perPage&&d.jsx("div",{className:"flex justify-center",children:d.jsx("a",{href:"#",onClick:i(l=>{s.setPerPage(s.perPage+10),l.preventDefault()},"onClick"),className:"text-sm underline hover:no-underline",children:"Load more"})})]})},"TasksListFilter"),tie=new Date,Xqe=K0e(tie),Zqe=Xqe<5,vW=Q0e().toISOString(),gW=Gye().toISOString(),yW=Kye().toISOString(),bW=Wye(tie,{weekStartsOn:0}).toISOString(),dv={overdue:{"done_date@is":null,"due_date@lt":vW},today:{"done_date@is":null,"due_date@gte":vW,"due_date@lte":gW},tomorrow:{"done_date@is":null,"due_date@gt":gW,"due_date@lt":yW},thisWeek:{"done_date@is":null,"due_date@gte":yW,"due_date@lte":bW},later:{"done_date@is":null,"due_date@gt":bW}},Jqe=i(()=>d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("div",{className:"flex items-center",children:[d.jsx("div",{className:"mr-3 flex",children:d.jsx(kQ,{className:"text-muted-foreground w-6 h-6"})}),d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground flex-1",children:"Upcoming Tasks"}),d.jsx(Sne,{display:"icon",selectContact:!0})]}),d.jsx(pn,{className:"p-4 mb-2",children:d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsx(Qqe,{}),d.jsx(uv,{title:"Overdue",filter:dv.overdue}),d.jsx(uv,{title:"Today",filter:dv.today}),d.jsx(uv,{title:"Tomorrow",filter:dv.tomorrow}),Zqe&&d.jsx(uv,{title:"This week",filter:dv.thisWeek}),d.jsx(uv,{title:"Later",filter:dv.later})]})})]}),"TasksList"),eze=i(()=>{const{data:e,total:t,isPending:n}=za("contacts",{pagination:{page:1,perPage:1}}),{total:r,isPending:a}=za("contactNotes",{pagination:{page:1,perPage:1}}),{total:o,isPending:s}=za("deals",{pagination:{page:1,perPage:1}});return n||a||s?null:t?r?d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-6 mt-1",children:[d.jsx("div",{className:"md:col-span-3",children:d.jsxs("div",{className:"flex flex-col gap-4",children:[null,d.jsx(Yqe,{})]})}),d.jsx("div",{className:"md:col-span-6",children:d.jsxs("div",{className:"flex flex-col gap-6",children:[o?d.jsx(zqe,{}):null,d.jsx(Z5e,{})]})}),d.jsx("div",{className:"md:col-span-3",children:d.jsx(Jqe,{})})]}):d.jsx(bV,{step:2,contactId:e?.[0]?.id}):d.jsx(bV,{step:1})},"Dashboard"),tze=y.lazy(()=>Fp(()=>import("./DealList-Dxd6Tt9n.js"),[],import.meta.url)),nze={list:tze},rze=y.createContext(void 0),G_=i(()=>y.useContext(rze),"useUserMenu"),aze=i(()=>{const{darkModeLogo:e,lightModeLogo:t,title:n}=Va(),r=Dr(),o=[{path:"/",pattern:"/"},{path:"/contacts",pattern:"/contacts/*"},{path:"/companies",pattern:"/companies/*"},{path:"/deals",pattern:"/deals/*"}].find(s=>tp(s.pattern,r.pathname))?.path||!1;return d.jsx("header",{className:"bg-secondary fixed top-0 left-0 right-0 z-50 border-b border-border",children:d.jsx("div",{className:"px-4",children:d.jsxs("div",{className:"flex justify-between items-center flex-1",children:[d.jsx(ize,{darkLogo:e,lightLogo:t,title:n}),d.jsxs("nav",{className:"flex","aria-label":"Main navigation",children:[d.jsx(Eb,{label:"Dashboard",to:"/",isActive:o==="/"}),d.jsx(Eb,{label:"Contacts",to:"/contacts",isActive:o==="/contacts"}),d.jsx(Eb,{label:"Companies",to:"/companies",isActive:o==="/companies"}),d.jsx(Eb,{label:"Deals",to:"/deals",isActive:o==="/deals"})]}),d.jsxs("div",{className:"flex items-center",children:[d.jsx(MZ,{}),d.jsx(IZ,{}),d.jsxs(PZ,{children:[d.jsx(sze,{}),d.jsx(lze,{}),d.jsx(cze,{}),d.jsx(Pge,{resource:"sales",action:"list",children:d.jsx(oze,{})}),d.jsx(ng,{}),d.jsx(l4,{className:"font-normal",children:d.jsxs("div",{className:"text-xs text-muted-foreground",children:["Version ","0.9.8"]})})]})]})]})})})},"Header"),ize=i(({darkLogo:e,lightLogo:t,title:n})=>d.jsxs(fn,{to:"/",className:"flex items-center gap-2 text-secondary-foreground no-underline hover:opacity-80 transition-opacity",children:[d.jsx("img",{className:"[.light_&]:hidden h-6",src:e,alt:`${n} logo`}),d.jsx("img",{className:"[.dark_&]:hidden h-6",src:t,alt:`${n} logo`}),d.jsx("h1",{className:"text-xl font-semibold",children:n})]}),"Logo"),Eb=i(({label:e,to:t,isActive:n})=>d.jsx(fn,{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"),oze=i(()=>{const{onClose:e}=G_()??{};return d.jsx(sr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/sales",className:"flex items-center gap-2",children:[d.jsx(TQ,{className:"h-4 w-4"}),"Users"]})})},"UsersMenu"),sze=i(()=>{const{onClose:e}=G_()??{};return d.jsx(sr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/settings",className:"flex items-center gap-2",children:[d.jsx(dP,{className:"h-4 w-4"}),"My info"]})})},"ConfigurationMenu"),lze=i(()=>{const{onClose:e}=G_()??{};return d.jsx(sr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/database",className:"flex items-center gap-2",children:[d.jsx(Qv,{className:"h-4 w-4"}),"Database"]})})},"DatabaseMenu"),cze=i(()=>{const{onClose:e}=G_()??{};return d.jsx(sr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/integrations",className:"flex items-center gap-2",children:[d.jsx(u_e,{className:"h-4 w-4"}),"Integrations"]})})},"IntegrationsMenu"),uze=i(({children:e})=>d.jsxs(d.Fragment,{children:[d.jsx(aze,{}),d.jsx("main",{className:"max-w-screen-xl mx-auto pt-20 px-4",id:"main-content",children:d.jsx(hx,{FallbackComponent:FZ,children:d.jsx(y.Suspense,{fallback:d.jsx(sn,{className:"h-12 w-12 rounded-full"}),children:e})})}),d.jsx(R1,{})]}),"Layout"),nie=i(()=>d.jsx("div",{className:"max-w-screen-xl mx-auto h-screen pt-8",children:d.jsx("div",{className:"h-full",children:d.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-8",children:[d.jsx(sn,{className:"w-full h-[100px]"}),d.jsx(sn,{className:"w-4/5 h-[50px]"}),d.jsx(sn,{className:"w-full h-9"}),d.jsx(sn,{className:"w-full h-9"}),d.jsx(sn,{className:"w-full h-9"}),d.jsx(sn,{className:"w-2/5 h-9"})]})})}),"LoginSkeleton"),aD=i(()=>{const e=Pn(),t=_n(),{darkModeLogo:n,title:r}=Va(),{data:a,isPending:o}=Qr({queryKey:["init"],queryFn:i(async()=>t.isInitialized(),"queryFn")}),{isPending:s,mutate:l}=Yr({mutationKey:["signup"],mutationFn:i(async w=>t.signUp(w),"mutationFn"),onSuccess:i(w=>{f({email:w.email,password:w.password,redirectTo:"/contacts"}).then(()=>{c("Initial user successfully created"),e.invalidateQueries({queryKey:["auth","canAccess"]})})},"onSuccess"),onError:i(()=>{c("An error occurred. Please try again.")},"onError")}),f=xY(),c=Vt(),{register:p,handleSubmit:m,formState:{isValid:g}}=iy({mode:"onChange"});if(o)return d.jsx(nie,{});if(a)return d.jsx(gw,{to:"/login"});const b=i(async w=>{l(w)},"onSubmit");return d.jsxs("div",{className:"h-screen p-8",children:[d.jsxs("div",{className:"flex items-center gap-4",children:[d.jsx("img",{src:n,alt:r,width:24,className:"filter brightness-0 invert"}),d.jsx("h1",{className:"text-xl font-semibold",children:r})]}),d.jsx("div",{className:"h-full",children:d.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-4",children:[d.jsx("h1",{className:"text-2xl font-bold mb-4",children:"Welcome to CRM"}),d.jsx("p",{className:"text-base mb-4",children:"Create the first user account to complete the setup."}),d.jsxs("form",{onSubmit:m(b),className:"space-y-4",children:[d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Hn,{htmlFor:"first_name",children:"First name"}),d.jsx(_r,{...p("first_name",{required:!0}),id:"first_name",type:"text",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Hn,{htmlFor:"last_name",children:"Last name"}),d.jsx(_r,{...p("last_name",{required:!0}),id:"last_name",type:"text",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Hn,{htmlFor:"email",children:"Email"}),d.jsx(_r,{...p("email",{required:!0}),id:"email",type:"email",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Hn,{htmlFor:"password",children:"Password"}),d.jsx(_r,{...p("password",{required:!0}),id:"password",type:"password",required:!0})]}),d.jsx("div",{className:"flex justify-between items-center mt-8",children:d.jsx(ze,{type:"submit",disabled:!g||s,className:"w-full",children:s?d.jsxs(d.Fragment,{children:[d.jsx(Oc,{className:"w-4 h-4 animate-spin mr-2"}),"Creating..."]}):"Create account"})})]})]})})]})},"SignupPage");aD.path="/sign-up";const dze=i((e,t)=>e==="admin"?!0:t.resource!=="sales","canAccess"),hT=tAe(Bn,{getIdentity:i(async()=>{const e=await rie();if(e==null)throw new Error;return{id:e.id,fullName:`${e.first_name} ${e.last_name}`,avatar:e.avatar?.src}},"getIdentity")});async function Ws(){if(Ws._is_initialized_cache==null){const{data:e}=await Bn.from("init_state").select("is_initialized");Ws._is_initialized_cache=e?.at(0)?.is_initialized>0}return Ws._is_initialized_cache}i(Ws,"getIsInitialized");(e=>{e._is_initialized_cache=null})(Ws||(Ws={}));const fze={...hT,login:i(async e=>{const t=await hT.login(e);return qb=void 0,t},"login"),checkAuth:i(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 Ws())throw await Bn.auth.signOut(),{redirectTo:"/sign-up",message:!1};return hT.checkAuth(e)},"checkAuth"),canAccess:i(async e=>{if(!await Ws())return!1;const n=await rie();if(n==null)return!1;const r=n.administrator?"admin":"user";return dze(r,e)},"canAccess")};let qb;const rie=i(async()=>{if(qb!=null)return qb;const{data:e,error:t}=await Bn.auth.getSession();if(e?.session?.user==null||t)return;const{data:n,error:r}=await Bn.from("sales").select("id, first_name, last_name, avatar, administrator").match({user_id:e?.session?.user.id}).single();if(!(n==null||r))return qb=n,n},"getSaleFromCache");async function hze(e,t,n){const r={};t&&(r.id=t);const a={};t&&(a.company_id=t);const[o,s,l]=await Promise.all([pze(e,r),mze(e,a),vze(e,a)]);return[...o,...s,...l].sort((f,c)=>f.date&&c.date?f.date.localeCompare(c.date)*-1:0).slice(0,250)}i(hze,"getActivityLog");const pze=i(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:jte,company_id:r.id,company:r,sales_id:r.sales_id,date:r.created_at}))},"getNewCompanies");async function mze(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(f=>f.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"}}),o=n.map(l=>({id:`contact.${l.id}.created`,type:Ete,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:Cte,sales_id:l.sales_id,contactNote:l,date:l.date}));return[...o,...s]}i(mze,"getNewContactsAndNotes");async function vze(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(f=>f.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"}}),o=n.map(l=>({id:`deal.${l.id}.created`,type:Ote,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:kte,sales_id:l.sales_id,dealNote:l,date:l.date}));return[...o,...s]}i(vze,"getNewDealsAndNotes");async function gze(e){return e.website?{src:`https://favicon.show/${e.website.replace(/^https?:\/\//,"").replace(/\/$/,"")}`,title:"Company favicon"}:null}i(gze,"getCompanyAvatar");async function yze(e,t={}){const{timeout:n=2e3}=t,r=new AbortController,a=setTimeout(()=>r.abort(),n),o=await fetch(e,{...t,signal:r.signal});return clearTimeout(a),o}i(yze,"fetchWithTimeout");const bze=["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 xze(e){const t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(o=>o.toString(16).padStart(2,"0")).join("")}i(xze,"hash");async function wze(e){return`https://www.gravatar.com/avatar/${await xze(e)}?d=404`}i(wze,"getGravatarUrl");async function _ze(e){if(bze.includes(e))return null;try{const t=`https://${e}/favicon.ico`;if((await yze(t)).ok)return t}catch{return null}return null}i(_ze,"getFaviconUrl");async function Sze(e){if(!e.email_jsonb||!e.email_jsonb.length)return null;for(const{email:t}of e.email_jsonb){const n=await wze(t);try{if((await fetch(n)).ok)return n}catch{}const r=t.split("@")[1],a=await _ze(r);if(a)return a}return null}i(Sze,"getContactAvatar");const xW=xd()||{url:"https://placeholder.supabase.co",anonKey:"placeholder-key"},So=bAe({instanceUrl:xW.url,apiKey:xW.anonKey,supabaseClient:Bn,sortOrder:"asc,desc.nullslast"}),wW=i(async e=>{let t=e.data.logo;return typeof t!="object"||t===null||!t.src?t=await gze(e.data):t.rawFile instanceof File&&await zb(t),{...e,data:{...e.data,logo:t}}},"processCompanyLogo");async function _W(e){const{data:t}=e;if(t.avatar?.src||!t.email_jsonb||!t.email_jsonb.length)return e;const n=await Sze(t),r={...t,avatar:{src:n||void 0}};return{...e,data:r}}i(_W,"processContactAvatar");const jze={...So,async getList(e,t){return e==="companies"?So.getList("companies_summary",t):e==="contacts"?So.getList("contacts_summary",t):So.getList(e,t)},async getOne(e,t){return e==="companies"?So.getOne("companies_summary",t):e==="contacts"?So.getOne("contacts_summary",t):So.getOne(e,t)},async signUp({email:e,password:t,first_name:n,last_name:r}){const{data:a,error:o}=await Bn.functions.invoke("setup",{method:"POST",body:{email:e,password:t,first_name:n,last_name:r}});if(!a||o)throw console.error("signUp.error",o),new Error("Failed to create account");return Ws._is_initialized_cache=!0,{id:a.data.id,email:e,password:t}},async salesCreate(e){const{data:t,error:n}=await Bn.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:o,avatar:s,disabled:l}=t,{data:f,error:c}=await Bn.functions.invoke("users",{method:"PATCH",body:{sales_id:e,email:n,first_name:r,last_name:a,administrator:o,disabled:l,avatar:s}});if(!f||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 Bn.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 Bn.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 Bn.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 So.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=>So.update("deals",{id:r.id,data:r,previousData:t.find(a=>a.id===r.id)})))},async getActivityLog(e){return hze(So,e)},async isInitialized(){return Ws()},async mergeContacts(e,t){const{data:n,error:r}=await Bn.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}},Eze=bhe(jze,[{resource:"contactNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await zb(r);return e},"beforeSave")},{resource:"dealNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await zb(r);return e},"beforeSave")},{resource:"sales",beforeSave:i(async(e,t,n)=>(e.avatar&&await zb(e.avatar),e),"beforeSave")},{resource:"contacts",beforeCreate:i(async e=>_W(e),"beforeCreate"),beforeUpdate:i(async e=>_W(e),"beforeUpdate"),beforeGetList:i(async e=>Cb(["first_name","last_name","company_name","title","email","phone","background"])(e),"beforeGetList")},{resource:"companies",beforeGetList:i(async e=>Cb(["name","phone_number","website","zipcode","city","stateAbbr"])(e),"beforeGetList"),beforeCreate:i(async e=>{const t=await wW(e);return{...t,data:{...t.data,created_at:new Date().toISOString()}}},"beforeCreate"),beforeUpdate:i(async e=>await wW(e),"beforeUpdate")},{resource:"contacts_summary",beforeGetList:i(async e=>Cb(["first_name","last_name"])(e),"beforeGetList")},{resource:"deals",beforeGetList:i(async e=>Cb(["name","type","description"])(e),"beforeGetList")}]),Cb=i(e=>t=>{if(!t.filter?.q)return t;const{q:n,...r}=t.filter;return{...t,filter:{...r,"@or":e.reduce((a,o)=>o==="email"?{...a,"email_fts@ilike":n}:o==="phone"?{...a,"phone_fts@ilike":n}:{...a,[`${o}@ilike`]:n},{})}}},"applyFullTextSearch"),zb=i(async e=>{if(!e.src.startsWith("blob:")&&!e.src.startsWith("data:")&&e.path){const{error:c}=await Bn.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(),o=`${`${Math.random()}.${r}`}`,{error:s}=await Bn.storage.from("attachments").upload(o,t);if(s)throw console.error("uploadError",s),new Error("Failed to upload attachment");const{data:l}=Bn.storage.from("attachments").getPublicUrl(o);e.path=o,e.src=l.publicUrl;const f=n.type;return e.type=f,e},"uploadToBucket");function aie(){const{identity:e}=Zn(),t=Wt();return d.jsxs("div",{className:"space-y-4 w-full",children:[d.jsx(ln,{source:"first_name",validate:nr(),helperText:!1}),d.jsx(ln,{source:"last_name",validate:nr(),helperText:!1}),d.jsx(ln,{source:"email",validate:[nr(),JK()],helperText:!1}),d.jsx(CN,{source:"administrator",readOnly:t?.id===e?.id,helperText:!1}),d.jsx(CN,{source:"disabled",readOnly:t?.id===e?.id,helperText:!1})]})}i(aie,"SalesInputs");function Cze(){const e=_n(),t=Vt(),n=rs(),{mutate:r}=Yr({mutationKey:["signup"],mutationFn:i(async o=>e.salesCreate(o),"mutationFn"),onSuccess:i(()=>{t("User created. They will soon receive an email to set their password."),n("/sales")},"onSuccess"),onError:i(()=>{t("An error occurred while creating the user.",{type:"error"})},"onError")}),a=i(async o=>{r(o)},"onSubmit");return d.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:d.jsxs(pn,{children:[d.jsx(Qo,{children:d.jsx(Xo,{children:"Create a new user"})}),d.jsx(Wn,{children:d.jsx(pee,{onSubmit:a,children:d.jsx(aie,{})})})]})})}i(Cze,"SalesCreate");function Oze(){return d.jsxs("div",{className:"flex justify-end gap-4",children:[d.jsx($1,{}),d.jsx(yd,{})]})}i(Oze,"EditToolbar");function kze(){const{record:e}=EK(),t=_n(),n=Vt(),r=rs(),{mutate:a}=Yr({mutationKey:["signup"],mutationFn:i(async s=>{if(!e)throw new Error("Record not found");return t.salesUpdate(e.id,s)},"mutationFn"),onSuccess:i(()=>{r("/sales"),n("User updated successfully")},"onSuccess"),onError:i(()=>{n("An error occurred. Please try again.")},"onError")}),o=i(async s=>{a(s)},"onSubmit");return d.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:d.jsx(pn,{children:d.jsx(Wn,{children:d.jsxs(pee,{toolbar:d.jsx(Oze,{}),onSubmit:o,record:e,children:[d.jsx(Rze,{}),d.jsx(aie,{})]})})})})}i(kze,"SalesEdit");const Rze=i(()=>{const e=Wt();return e?d.jsxs("h2",{className:"text-lg font-semibold mb-4",children:["Edit ",e?.first_name," ",e?.last_name]}):null},"SaleEditTitle"),Aze=i(()=>d.jsxs(_4,{children:[d.jsx(P1,{}),d.jsx(Pc,{label:"New user"})]}),"SalesListActions"),Tze=[d.jsx(S4,{source:"q",alwaysOn:!0})],Pze=i(e=>{const t=Wt();return t?d.jsxs("div",{className:"flex flex-row gap-1",children:[t.administrator&&d.jsx(Pr,{variant:"outline",className:"border-blue-300 dark:border-blue-700",children:"Admin"}),t.disabled&&d.jsx(Pr,{variant:"outline",className:"border-orange-300 dark:border-orange-700",children:"Disabled"})]}):null},"OptionsField"),Nze=i(()=>{const e=Wt(),t=_n(),n=Vt(),r=Nw(),[a,o]=y.useState(!1),[s,l]=y.useState(!1),{mutate:f,isPending:c}=Yr({mutationFn:i(async()=>t.resendInvite(e.id),"mutationFn"),onSuccess:i(()=>{n("Invitation email resent successfully"),o(!1),r()},"onSuccess"),onError:i(()=>{n("Failed to resend invitation email",{type:"error"}),o(!1)},"onError")}),{mutate:p,isPending:m}=Yr({mutationFn:i(async()=>t.resetPassword(e.id),"mutationFn"),onSuccess:i(()=>{n("Password reset email sent successfully"),l(!1),r()},"onSuccess"),onError:i(()=>{n("Failed to send password reset email",{type:"error"}),l(!1)},"onError")});if(!e)return null;const g=e.email_confirmed_at!==null,b=e.disabled===!0;return console.log("[RowActions] Record:",{email:e.email,email_confirmed_at:e.email_confirmed_at,isConfirmed:g,isDisabled:b,inviteDialogOpen:a,resetDialogOpen:s}),d.jsxs(d.Fragment,{children:[d.jsxs(Ac,{children:[d.jsx(Qs,{asChild:!0,children:d.jsxs(ze,{variant:"ghost",className:"h-8 w-8 p-0",children:[d.jsx("span",{className:"sr-only",children:"Open menu"}),d.jsx(PM,{className:"h-4 w-4"})]})}),d.jsxs(Tc,{align:"end",children:[d.jsx(l4,{children:"Email Actions"}),d.jsx(ng,{}),!g&&d.jsxs(sr,{onClick:i(w=>{w.preventDefault(),w.stopPropagation(),console.log("[Menu] Clicked Resend Invite"),o(!0)},"onClick"),children:[d.jsx(A1e,{className:"mr-2 h-4 w-4"}),"Resend Invite"]}),g&&!b&&d.jsxs(sr,{onClick:i(()=>l(!0),"onClick"),children:[d.jsx(Xwe,{className:"mr-2 h-4 w-4"}),"Send Password Reset"]})]})]}),d.jsx(wa,{open:a,onOpenChange:o,children:d.jsxs(_a,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Resend Invitation"}),d.jsxs(Oi,{children:["Send a new invitation email to ",d.jsx("strong",{children:e.email}),"?",d.jsx("br",{}),d.jsx("br",{}),"This will send them a fresh invitation link to set up their account."]})]}),d.jsxs(Yo,{children:[d.jsx(ze,{variant:"outline",onClick:i(w=>{w.stopPropagation(),o(!1)},"onClick"),disabled:c,children:"Cancel"}),d.jsx(ze,{onClick:i(w=>{w.stopPropagation(),f()},"onClick"),disabled:c,children:c?"Sending...":"Send Invitation"})]})]})}),d.jsx(wa,{open:s,onOpenChange:l,children:d.jsxs(_a,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Send Password Reset"}),d.jsxs(Oi,{children:["Send a password reset email to ",d.jsx("strong",{children:e.email}),"?",d.jsx("br",{}),d.jsx("br",{}),"This will send them a link to reset their password."]})]}),d.jsxs(Yo,{children:[d.jsx(ze,{variant:"outline",onClick:i(w=>{w.stopPropagation(),l(!1)},"onClick"),disabled:m,children:"Cancel"}),d.jsx(ze,{onClick:i(w=>{w.stopPropagation(),p()},"onClick"),disabled:m,children:m?"Sending...":"Send Reset Link"})]})]})})]})},"RowActions");function Dze(){return d.jsx(b4,{filters:Tze,actions:d.jsx(Aze,{}),sort:{field:"first_name",order:"ASC"},children:d.jsx(Mze,{})})}i(Dze,"SalesList");const Mze=i(()=>{const{data:e,isPending:t,filterValues:n}=Gn(),{identity:r}=Zn(),a=n&&Object.keys(n).length>0;return!r||t?d.jsx(pn,{className:"p-4",children:d.jsxs("div",{className:"space-y-3",children:[d.jsx(sn,{className:"h-12 w-full"}),d.jsx(sn,{className:"h-12 w-full"}),d.jsx(sn,{className:"h-12 w-full"}),d.jsx(sn,{className:"h-12 w-full"}),d.jsx(sn,{className:"h-12 w-full"})]})}):!e?.length&&!a?d.jsx(Ize,{}):d.jsxs(Fs,{children:[d.jsx(Fs.Col,{source:"first_name"}),d.jsx(Fs.Col,{source:"last_name"}),d.jsx(Fs.Col,{source:"email"}),d.jsx(Fs.Col,{label:!1,children:d.jsx(Pze,{})}),d.jsx(Fs.Col,{label:!1,children:d.jsx(Nze,{})})]})},"SalesListLayout"),Ize=i(()=>{const e=F1();return d.jsxs("div",{className:"flex flex-col justify-center items-center gap-3",style:{height:`calc(100dvh - ${e}px)`},children:[d.jsx("img",{src:"./img/empty.svg",alt:"No users found"}),d.jsxs("div",{className:"flex flex-col gap-0 items-center",children:[d.jsx("h6",{className:"text-lg font-bold",children:"No users found"}),d.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"It seems your user list is empty."})]}),d.jsx("div",{className:"flex flex-row gap-2",children:d.jsx(Pc,{label:"New user"})})]})},"SalesEmpty"),Fze={list:Dze,create:Cze,edit:kze,recordRepresentation:i(e=>`${e.first_name} ${e.last_name}`,"recordRepresentation")};function iie({open:e,onComplete:t,canClose:n=!1}){const[r,a]=y.useState("welcome"),[o,s]=y.useState(""),[l,f]=y.useState(""),[c,p]=y.useState(null),m=i(async()=>{p(null),a("validating");const b=await XRe(o,l);b.valid?(KRe({url:o,anonKey:l}),a("success"),setTimeout(()=>{window.location.href=window.location.origin},1500)):(p(b.error||"Connection failed"),a("credentials"))},"handleValidateAndSave"),g=i(()=>{n&&t()},"handleClose");return d.jsx(wa,{open:e,onOpenChange:n?g:void 0,children:d.jsxs(_a,{className:"sm:max-w-md",onPointerDownOutside:i(b=>!n&&b.preventDefault(),"onPointerDownOutside"),onEscapeKeyDown:i(b=>!n&&b.preventDefault(),"onEscapeKeyDown"),children:[r==="welcome"&&d.jsxs(d.Fragment,{children:[d.jsxs(Wr,{children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d.jsx(Qv,{className:"h-6 w-6 text-primary"}),d.jsx(Gr,{children:"Welcome to CRM"})]}),d.jsx(Oi,{children:"To get started, you'll need to connect to a Supabase database."})]}),d.jsxs("div",{className:"space-y-4 py-4",children:[d.jsx(ai,{children:d.jsxs(ki,{children:[d.jsx("strong",{children:"Don't have a Supabase project?"}),d.jsx("br",{}),"Create one for free at"," ",d.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline text-primary",children:"supabase.com"})]})}),d.jsxs("div",{className:"space-y-2",children:[d.jsx("h4",{className:"font-medium text-sm",children:"What you'll need:"}),d.jsxs("ul",{className:"list-disc list-inside text-sm text-muted-foreground space-y-1",children:[d.jsx("li",{children:"Your Supabase project URL"}),d.jsx("li",{children:"Your anonymous (anon) API key"})]})]}),d.jsx(ze,{onClick:i(()=>a("credentials"),"onClick"),className:"w-full",children:"Continue"})]})]}),r==="credentials"&&d.jsxs(d.Fragment,{children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Connect to Supabase"}),d.jsx(Oi,{children:"Enter your Supabase project credentials"})]}),d.jsxs("div",{className:"space-y-4 py-4",children:[c&&d.jsxs(ai,{variant:"destructive",children:[d.jsx(Ap,{className:"h-4 w-4"}),d.jsx(ki,{children:c})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{htmlFor:"supabase-url",children:"Supabase URL"}),d.jsx(_r,{id:"supabase-url",placeholder:"https://xxxxx.supabase.co",value:o,onChange:i(b=>s(b.target.value),"onChange")}),d.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in Project Settings → API"})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{htmlFor:"anon-key",children:"Anonymous Key"}),d.jsx(_r,{id:"anon-key",type:"password",placeholder:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",value:l,onChange:i(b=>f(b.target.value),"onChange")}),d.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in Project Settings → API → Project API keys"})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(ze,{variant:"outline",onClick:i(()=>a("welcome"),"onClick"),className:"flex-1",children:"Back"}),d.jsx(ze,{onClick:m,disabled:!o||!l,className:"flex-1",children:"Connect"})]})]})]}),r==="validating"&&d.jsxs(d.Fragment,{children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Validating Connection"}),d.jsx(Oi,{children:"Testing your Supabase credentials..."})]}),d.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[d.jsx(Oc,{className:"h-12 w-12 animate-spin text-primary mb-4"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait..."})]})]}),r==="success"&&d.jsxs(d.Fragment,{children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:"Connection Successful!"}),d.jsx(Oi,{children:"Your Supabase database is now connected"})]}),d.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[d.jsx(Fo,{className:"h-12 w-12 text-green-500 mb-4"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Reloading application..."})]})]})]})})}i(iie,"SupabaseSetupWizard");function Lze(){const[e,t]=y.useState(!1),n=xd(),r=ZRe(),a=i(()=>{confirm("Are you sure you want to clear the database configuration? The app will need to be reconfigured on next launch.")&&(YRe(),window.location.reload())},"handleClearConfig");return d.jsxs(d.Fragment,{children:[d.jsxs(pn,{children:[d.jsxs(Qo,{children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(Qv,{className:"h-5 w-5"}),d.jsx(Xo,{children:"Database Connection"})]}),d.jsx(w4,{children:"Manage your Supabase database connection settings"})]}),d.jsx(Wn,{className:"space-y-4",children:n?d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-start gap-3 p-4 border rounded-lg",children:[d.jsx(Fo,{className:"h-5 w-5 text-green-500 mt-0.5"}),d.jsxs("div",{className:"flex-1 space-y-1",children:[d.jsx("p",{className:"font-medium",children:"Connected"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:n.url}),n.configuredAt&&d.jsxs("p",{className:"text-xs text-muted-foreground",children:["Configured on"," ",new Date(n.configuredAt).toLocaleDateString()]})]})]}),r==="env"&&d.jsxs(ai,{children:[d.jsx(dP,{className:"h-4 w-4"}),d.jsx(ki,{children:"Using configuration from environment variables. You can override this by setting up a new connection via the UI."})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsxs(ze,{variant:"outline",onClick:i(()=>t(!0),"onClick"),className:"flex-1",children:[d.jsx(dP,{className:"h-4 w-4 mr-2"}),"Change Connection"]}),r==="ui"&&d.jsxs(ze,{variant:"destructive",onClick:a,className:"flex-1",children:[d.jsx(cy,{className:"h-4 w-4 mr-2"}),"Clear Configuration"]})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx($ze,{className:"text-sm font-medium",children:"Anonymous Key"}),d.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)]})]})]}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-start gap-3 p-4 border border-dashed rounded-lg",children:[d.jsx(al,{className:"h-5 w-5 text-destructive mt-0.5"}),d.jsxs("div",{className:"flex-1 space-y-1",children:[d.jsx("p",{className:"font-medium",children:"Not Connected"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"No Supabase database is configured"})]})]}),d.jsx(ai,{children:d.jsxs(ki,{children:["Connect to a Supabase database to start using Atomic CRM. You can create a free project at"," ",d.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"supabase.com"})]})}),d.jsxs(ze,{onClick:i(()=>t(!0),"onClick"),className:"w-full",children:[d.jsx(Qv,{className:"h-4 w-4 mr-2"}),"Connect to Supabase"]})]})})]}),d.jsx(iie,{open:e,onComplete:i(()=>t(!1),"onComplete"),canClose:!0})]})}i(Lze,"DatabaseSettings");function $ze({children:e,className:t}){return d.jsx("label",{className:t,children:e})}i($ze,"Label");const iD=i(()=>d.jsx("div",{className:"max-w-lg mx-auto mt-8",children:d.jsx(Lze,{})}),"DatabasePage");iD.path="/database";const oD=i(()=>{const[e,t]=y.useState(!1),{identity:n,refetch:r}=Zn(),{data:a,refetch:o}=Dw("sales",{id:n?.id}),s=Vt(),l=_n(),{mutate:f}=Yr({mutationKey:["signup"],mutationFn:i(async p=>{if(!n)throw new Error("Record not found");return l.salesUpdate(n.id,p)},"mutationFn"),onSuccess:i(()=>{r(),o(),t(!1),s("Your profile has been updated")},"onSuccess"),onError:i(p=>{s("An error occurred. Please try again",{type:"error"})},"onError")});if(!n)return null;const c=i(async p=>{f(p)},"handleOnSubmit");return d.jsx("div",{className:"max-w-lg mx-auto mt-8",children:d.jsx(ra,{onSubmit:c,record:a,children:d.jsx(qze,{isEditMode:e,setEditMode:t})})})},"SettingsPage"),qze=i(({isEditMode:e,setEditMode:t})=>{const n=Vt(),r=Sa(),a=Wt(),{identity:o,refetch:s}=Zn(),{isDirty:l}=ay(),f=_n(),{mutate:c}=Yr({mutationKey:["signup"],mutationFn:i(async g=>{if(!a)throw new Error("Record not found");return f.salesUpdate(a.id,g)},"mutationFn"),onSuccess:i(()=>{s(),n("Your profile has been updated")},"onSuccess"),onError:i(()=>{n("An error occurred. Please try again.")},"onError")});if(!o)return null;const p=i(()=>{r("/change-password")},"handleClickOpenPasswordChange"),m=i(async g=>{c(g)},"handleAvatarUpdate");return d.jsxs("div",{className:"space-y-4",children:[d.jsx(pn,{children:d.jsxs(Wn,{children:[d.jsx("div",{className:"mb-4 flex flex-row justify-between",children:d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"My info"})}),d.jsxs("div",{className:"space-y-4 mb-4",children:[d.jsx(ote,{source:"avatar",type:"avatar",onSave:m,linkPosition:"right"}),d.jsx(pT,{source:"first_name",isEditMode:e}),d.jsx(pT,{source:"last_name",isEditMode:e}),d.jsx(pT,{source:"email",isEditMode:e})]}),d.jsxs("div",{className:"flex flex-row justify-end gap-2",children:[!e&&d.jsx(d.Fragment,{children:d.jsx(ze,{variant:"outline",type:"button",onClick:p,children:"Change password"})}),d.jsxs(ze,{type:"button",variant:e?"ghost":"outline",onClick:i(()=>t(!e),"onClick"),className:"flex items-center",children:[e?d.jsx(al,{}):d.jsx(OQ,{}),e?"Cancel":"Edit"]}),e&&d.jsxs(ze,{type:"submit",disabled:!l,variant:"outline",children:[d.jsx(i1,{}),"Save"]})]})]})}),void 0]})},"SettingsForm"),pT=i(({source:e,isEditMode:t})=>t?d.jsx(ln,{source:e,helperText:!1}):d.jsx("div",{className:"m-2",children:d.jsx(l5e,{source:e})}),"TextRender");oD.path="/settings";function oie(){const e=new Uint8Array(16);return crypto.getRandomValues(e),`ak_live_${Array.from(e).map(n=>n.toString(16).padStart(2,"0")).join("")}`}i(oie,"generateApiKey");async function zze(e){const n=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(r)).map(o=>o.toString(16).padStart(2,"0")).join("")}i(zze,"hashApiKey");const Uze=[{value:"contacts:read",label:"Contacts: Read"},{value:"contacts:write",label:"Contacts: Write"},{value:"companies:read",label:"Companies: Read"},{value:"companies:write",label:"Companies: Write"},{value:"deals:read",label:"Deals: Read"},{value:"deals:write",label:"Deals: Write"},{value:"activities:write",label:"Activities: Write"}],Bze=i(({open:e,onClose:t})=>{const[n,r]=y.useState(null),[a,o]=y.useState(!1),s=_n(),l=Vt(),f=Pn(),{identity:c}=Zn(),{register:p,handleSubmit:m,watch:g,setValue:b,reset:w}=iy({defaultValues:{name:"",scopes:[],expires_at:""}}),S=Yr({mutationFn:i(async O=>{const C=oie(),T=await zze(C),R=C.substring(0,12),{data:A}=await s.create("api_keys",{data:{name:O.name,key_hash:T,key_prefix:R,scopes:O.scopes,is_active:!0,expires_at:O.expires_at||null,sales_id:c?.id,created_by_sales_id:c?.id}});return{data:A,apiKey:C}},"mutationFn"),onSuccess:i(({apiKey:O})=>{r(O),f.invalidateQueries({queryKey:["api_keys"]}),l("API key created successfully")},"onSuccess"),onError:i(()=>{l("Failed to create API key",{type:"error"})},"onError")}),_=i(()=>{r(null),o(!1),w(),t()},"handleClose"),j=i(()=>{n&&(navigator.clipboard.writeText(n),o(!0),setTimeout(()=>o(!1),2e3))},"copyApiKey"),E=i(O=>{const C=g("scopes");C.includes(O)?b("scopes",C.filter(T=>T!==O)):b("scopes",[...C,O])},"toggleScope");return d.jsx(wa,{open:e,onOpenChange:_,children:d.jsxs(_a,{className:"sm:max-w-[500px]",children:[d.jsxs(Wr,{children:[d.jsx(Gr,{children:n?"API Key Created":"Create API Key"}),d.jsx(Oi,{children:n?"Copy this key now - it won't be shown again!":"Create a new API key to access the CRM API"})]}),n?d.jsxs("div",{className:"space-y-4",children:[d.jsx(ai,{children:d.jsx(ki,{children:"Make sure to copy your API key now. You won't be able to see it again!"})}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{children:"Your API Key"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(_r,{value:n,readOnly:!0,className:"font-mono text-sm"}),d.jsx(ze,{type:"button",variant:"outline",size:"icon",onClick:j,children:a?d.jsx(Fo,{className:"h-4 w-4 text-green-500"}):d.jsx(AM,{className:"h-4 w-4"})})]})]}),d.jsx("div",{className:"flex justify-end",children:d.jsx(ze,{onClick:_,children:"Done"})})]}):d.jsx("form",{onSubmit:m(O=>S.mutate(O)),children:d.jsxs("div",{className:"space-y-4",children:[d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{htmlFor:"name",children:"Name"}),d.jsx(_r,{id:"name",placeholder:"e.g., Production API Key",...p("name",{required:!0})})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{children:"Scopes"}),d.jsx("div",{className:"space-y-2",children:Uze.map(O=>d.jsxs("div",{className:"flex items-center space-x-2",children:[d.jsx(Up,{id:O.value,checked:g("scopes").includes(O.value),onCheckedChange:i(()=>E(O.value),"onCheckedChange")}),d.jsx("label",{htmlFor:O.value,className:"text-sm cursor-pointer",children:O.label})]},O.value))})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Hn,{htmlFor:"expires_at",children:"Expiration (optional)"}),d.jsx(_r,{id:"expires_at",type:"date",...p("expires_at")})]}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(ze,{type:"button",variant:"outline",onClick:_,children:"Cancel"}),d.jsx(ze,{type:"submit",disabled:S.isPending,children:"Create"})]})]})})]})})},"CreateApiKeyDialog");var Vze=Symbol("radix.slottable");function Hze(e){const t=i(({children:n})=>d.jsx(d.Fragment,{children:n}),"Slottable2");return t.displayName=`${e}.Slottable`,t.__radixId=Vze,t}i(Hze,"createSlottable");var sie="AlertDialog",[Wze,KUe]=da(sie,[WQ]),sl=WQ(),lie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=sl(t);return d.jsx(fy,{...r,...n,modal:!0})},"AlertDialog$1");lie.displayName=sie;var Gze="AlertDialogTrigger",Kze=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(lX,{...a,...r,ref:t})});Kze.displayName=Gze;var Yze="AlertDialogPortal",cie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=sl(t);return d.jsx(hy,{...r,...n})},"AlertDialogPortal$1");cie.displayName=Yze;var Qze="AlertDialogOverlay",uie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(py,{...a,...r,ref:t})});uie.displayName=Qze;var uh="AlertDialogContent",[Xze,Zze]=Wze(uh),Jze=Hze("AlertDialogContent"),die=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,children:r,...a}=e,o=sl(n),s=y.useRef(null),l=Zt(t,s),f=y.useRef(null);return d.jsx(KSe,{contentName:uh,titleName:fie,docsSlug:"alert-dialog",children:d.jsx(Xze,{scope:n,cancelRef:f,children:d.jsxs(my,{role:"alertdialog",...o,...a,ref:l,onOpenAutoFocus:tt(a.onOpenAutoFocus,c=>{c.preventDefault(),f.current?.focus({preventScroll:!0})}),onPointerDownOutside:i(c=>c.preventDefault(),"onPointerDownOutside"),onInteractOutside:i(c=>c.preventDefault(),"onInteractOutside"),children:[d.jsx(Jze,{children:r}),d.jsx(tUe,{contentRef:s})]})})})});die.displayName=uh;var fie="AlertDialogTitle",hie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(u1,{...a,...r,ref:t})});hie.displayName=fie;var pie="AlertDialogDescription",mie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(d1,{...a,...r,ref:t})});mie.displayName=pie;var eUe="AlertDialogAction",vie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=sl(n);return d.jsx(vy,{...a,...r,ref:t})});vie.displayName=eUe;var gie="AlertDialogCancel",yie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,{cancelRef:a}=Zze(gie,n),o=sl(n),s=Zt(t,a);return d.jsx(vy,{...o,...r,ref:s})});yie.displayName=gie;var tUe=i(({contentRef:e})=>{const t=`\`${uh}\` requires a description for the component to be accessible for screen reader users.
155
155
 
156
156
  You can add a description to the \`${uh}\` by passing a \`${pie}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
157
157
 
@@ -163,4 +163,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/alert-
163
163
  ${g?"border-green-500 bg-green-50 scale-[1.02] shadow-lg":"border-gray-300 hover:border-primary/50 hover:bg-gray-50"}
164
164
  `,children:[d.jsx("input",{...m()}),d.jsx(AQ,{className:"w-12 h-12 mx-auto mb-4 text-gray-400"}),g?d.jsx("p",{className:"text-lg font-medium",children:"Drop files here..."}):d.jsxs(d.Fragment,{children:[d.jsx("p",{className:"text-lg font-medium mb-2",children:"Drag & drop files here, or click to select"}),d.jsx("p",{className:"text-sm text-gray-500",children:"Supports all file types (executables blocked for security)"})]})]}),e.length>0&&d.jsxs("div",{className:"space-y-2",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("h3",{className:"font-medium",children:["Files (",e.length,")"]}),d.jsxs("div",{className:"space-x-2",children:[d.jsx(ze,{size:"sm",onClick:w,disabled:!e.some(j=>j.status==="pending"),children:"Upload All"}),d.jsx(ze,{size:"sm",variant:"outline",onClick:S,disabled:!e.some(j=>j.status==="success"),children:"Clear Completed"})]})]}),d.jsx("div",{className:"space-y-2",children:e.map((j,E)=>d.jsxs("div",{className:"border rounded-lg p-4 space-y-2",children:[d.jsxs("div",{className:"flex items-start justify-between gap-4",children:[d.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[d.jsx(Fwe,{className:"w-5 h-5 mt-0.5 flex-shrink-0 text-gray-400"}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsx("p",{className:"font-medium truncate",children:j.file.name}),d.jsxs("p",{className:"text-sm text-gray-500",children:[_(j.file.size),j.activityId&&d.jsxs("span",{className:"ml-2 text-xs",children:["ID: ",j.activityId.substring(0,8),"..."]})]})]})]}),d.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[j.status==="pending"&&d.jsx(ze,{size:"sm",onClick:i(()=>b(E),"onClick"),children:"Upload"}),j.status==="uploading"&&d.jsx(Oc,{className:"w-5 h-5 animate-spin text-primary"}),j.status==="success"&&d.jsx(Fo,{className:"w-5 h-5 text-green-500"}),j.status==="error"&&d.jsx(al,{className:"w-5 h-5 text-red-500"})]})]}),j.status==="uploading"&&d.jsx(Dne,{value:j.progress,className:"h-1"}),j.status==="error"&&j.error&&d.jsxs("p",{className:"text-sm text-red-500",children:["Error: ",j.error]})]},E))})]})]})]}),d.jsxs(pn,{children:[d.jsx(Qo,{children:d.jsx(Xo,{className:"text-base",children:"How it works"})}),d.jsxs(Wn,{className:"text-sm text-gray-600 space-y-2",children:[d.jsx("p",{children:"• Files are uploaded directly to secure storage (no database bloat)"}),d.jsx("p",{children:"• Each file creates an activity record for tracking and search"}),d.jsx("p",{children:"• Large files are handled automatically (no size limits)"}),d.jsx("p",{children:"• Files are linked to your selected ingestion channel"}),d.jsx("p",{children:"• Activities appear in the Activity Feed immediately"})]})]})]})},"FileUpload"),sD=i(()=>d.jsxs("div",{className:"max-w-6xl mx-auto mt-8 px-4",children:[d.jsxs("div",{className:"mb-6",children:[d.jsx("h1",{className:"text-3xl font-bold",children:"Integrations"}),d.jsx("p",{className:"text-muted-foreground mt-2",children:"Manage API keys, webhooks, and ingestion channels to integrate Atomic CRM with external systems."})]}),d.jsxs(xte,{defaultValue:"ingestion",children:[d.jsxs(wte,{className:"mb-4",children:[d.jsx(Cu,{value:"ingestion",children:"Ingestion Channels"}),d.jsx(Cu,{value:"file-upload",children:"File Upload"}),d.jsx(Cu,{value:"api-keys",children:"API Keys"}),d.jsx(Cu,{value:"webhooks",children:"Webhooks (Outbound)"})]}),d.jsx(Ou,{value:"ingestion",children:d.jsx(bUe,{})}),d.jsx(Ou,{value:"file-upload",children:d.jsx(wUe,{})}),d.jsx(Ou,{value:"api-keys",children:d.jsx(fUe,{})}),d.jsx(Ou,{value:"webhooks",children:d.jsx(mUe,{})})]})]}),"IntegrationsPage");sD.path="/integrations";var _Ue={"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 SUe={"ra-supabase":{auth:{password_reset:"Check your emails for a Reset Password message."}}},jUe=oQ(()=>afe(GY,_Ue,SUe),"en",[{locale:"en",name:"English"}],{allowMissing:!0}),EUe=i(()=>{const e=_n(),{data:t,error:n,isPending:r}=Qr({queryKey:["init"],queryFn:i(async()=>e.isInitialized(),"queryFn")});return r?d.jsx(nie,{}):n?d.jsx(_x,{}):t?d.jsx(_x,{}):d.jsx(gw,{to:"/sign-up"})},"StartPage");async function CUe(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"}}}i(CUe,"checkDatabaseHealth");function OUe({missingTables:e,supabaseUrl:t}){const n=t.match(/https:\/\/([^.]+)\.supabase\.co/)?.[1];return d.jsxs("div",{className:"max-w-2xl mx-auto mt-8 space-y-4",children:[d.jsxs(ai,{variant:"destructive",children:[d.jsx(Ap,{className:"h-4 w-4"}),d.jsx(_te,{children:"Database Schema Not Configured"}),d.jsx(ki,{children:"Your Supabase database is connected, but the CRM schema hasn't been set up yet."})]}),d.jsxs(pn,{children:[d.jsxs(Qo,{children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(Qv,{className:"h-5 w-5"}),d.jsx(Xo,{children:"Setup Instructions"})]}),d.jsx(w4,{children:"Follow these steps to set up your database schema"})]}),d.jsxs(Wn,{className:"space-y-6",children:[d.jsxs("div",{children:[d.jsx("h3",{className:"font-semibold mb-2",children:"Missing Tables:"}),d.jsx("div",{className:"flex flex-wrap gap-2",children:e.map(r=>d.jsx("span",{className:"px-2 py-1 bg-destructive/10 text-destructive text-sm rounded",children:r},r))})]}),d.jsxs("div",{className:"space-y-3",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.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"}),d.jsx("h3",{className:"font-semibold",children:"Using Supabase CLI (Recommended)"})]}),d.jsxs("div",{className:"ml-8 space-y-3",children:[d.jsxs("div",{children:[d.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Install Supabase CLI:"}),d.jsx("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:"npm install -g supabase"})]}),d.jsxs("div",{children:[d.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Clone the RealTimeX CRM repository to get migrations:"}),d.jsxs("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:["git clone https://github.com/therealtimex/realtimex-crm.git",`
165
165
  `,"cd realtimex-crm"]})]}),d.jsxs("div",{children:[d.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Link to your Supabase project:"}),d.jsxs("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:["supabase link --project-ref ",n||"YOUR_PROJECT_REF"]})]}),d.jsxs("div",{children:[d.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Push the migrations:"}),d.jsx("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:"supabase db push"})]}),d.jsx("div",{children:d.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Reload this page after migrations are complete."})})]})]}),d.jsxs("div",{className:"space-y-3",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.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"}),d.jsx("h3",{className:"font-semibold",children:"Using Supabase SQL Editor"})]}),d.jsxs("div",{className:"ml-8 space-y-3",children:[d.jsx("p",{className:"text-sm text-muted-foreground",children:"Manually run the SQL migrations in your Supabase SQL Editor:"}),d.jsxs("ol",{className:"list-decimal list-inside space-y-2 text-sm text-muted-foreground",children:[d.jsxs("li",{children:["Download migrations from"," ",d.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",d.jsx(df,{className:"h-3 w-3"})]})]}),d.jsxs("li",{children:["Open your"," ",d.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",d.jsx(df,{className:"h-3 w-3"})]})]}),d.jsx("li",{children:"Run each migration file in order (by date in filename)"}),d.jsx("li",{children:"Reload this page after all migrations are complete"})]}),n&&d.jsx(ze,{asChild:!0,variant:"outline",className:"w-full",children:d.jsxs("a",{href:`https://supabase.com/dashboard/project/${n}/sql/new`,target:"_blank",rel:"noopener noreferrer",children:[d.jsx(df,{className:"h-4 w-4 mr-2"}),"Open SQL Editor"]})})]})]}),d.jsxs("div",{className:"space-y-3 pt-4 border-t",children:[d.jsx("h3",{className:"font-semibold",children:"After Setup"}),d.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[d.jsxs("div",{className:"flex items-start gap-2",children:[d.jsx(Fo,{className:"h-4 w-4 mt-0.5 text-green-500"}),d.jsx("span",{children:"All tables will be created with proper schemas and relationships"})]}),d.jsxs("div",{className:"flex items-start gap-2",children:[d.jsx(Fo,{className:"h-4 w-4 mt-0.5 text-green-500"}),d.jsx("span",{children:"Row Level Security (RLS) policies will be configured"})]}),d.jsxs("div",{className:"flex items-start gap-2",children:[d.jsx(Fo,{className:"h-4 w-4 mt-0.5 text-green-500"}),d.jsx("span",{children:"Database triggers and functions will be set up"})]})]}),d.jsx(ze,{onClick:i(()=>window.location.reload(),"onClick"),className:"w-full mt-4",children:"Reload Page"})]})]})]}),d.jsxs(pn,{children:[d.jsx(Qo,{children:d.jsx(Xo,{className:"text-base",children:"Need Help?"})}),d.jsxs(Wn,{className:"space-y-2 text-sm",children:[d.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:[d.jsx(df,{className:"h-4 w-4"}),"View Full Setup Guide"]}),d.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:[d.jsx(df,{className:"h-4 w-4"}),"Report an Issue"]}),d.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:[d.jsx(df,{className:"h-4 w-4"}),"Supabase CLI Documentation"]})]})]})]})}i(OUe,"DatabaseSetupGuide");function kUe({children:e,dataProvider:t}){const[n,r]=y.useState(null),[a,o]=y.useState(!0);if(y.useEffect(()=>{let s=!1;async function l(){try{const f=await CUe(t);s||(r(f),o(!1))}catch(f){console.error("[DatabaseHealthCheck] Failed to check database health:",f),s||o(!1)}}return i(l,"checkHealth"),l(),()=>{s=!0}},[t]),a)return d.jsx("div",{className:"flex items-center justify-center min-h-screen",children:d.jsxs("div",{className:"text-center space-y-4",children:[d.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto"}),d.jsx("p",{className:"text-muted-foreground",children:"Checking database connection..."})]})});if(n&&!n.isHealthy){const s=xd();if(s)return d.jsx(OUe,{missingTables:n.missingTables,supabaseUrl:s.url})}return d.jsx(d.Fragment,{children:e})}i(kUe,"DatabaseHealthCheck");const RUe=i(({contactGender:e=XZ,companySectors:t=HZ,dealCategories:n=KZ,dealPipelineStatuses:r=GZ,dealStages:a=WZ,darkModeLogo:o=UZ,lightModeLogo:s=BZ,noteStatuses:l=YZ,taskTypes:f=QZ,title:c=VZ,dataProvider:p=Eze,authProvider:m=fze,disableTelemetry:g,...b})=>(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]),d.jsx(tke,{contactGender:e,companySectors:t,dealCategories:n,dealPipelineStatuses:r,dealStages:a,darkModeLogo:o,lightModeLogo:s,noteStatuses:l,taskTypes:f,title:c,children:d.jsx(kUe,{dataProvider:p,children:d.jsxs(oke,{dataProvider:p,authProvider:m,store:pG(void 0,"CRM"),layout:uze,loginPage:EUe,i18nProvider:jUe,dashboard:eze,requireAuth:!0,disableTelemetry:!0,...b,children:[d.jsxs(eP,{noLayout:!0,children:[d.jsx(Qn,{path:aD.path,element:d.jsx(aD,{})}),d.jsx(Qn,{path:XP.path,element:d.jsx(XP,{})}),d.jsx(Qn,{path:KP.path,element:d.jsx(KP,{})}),d.jsx(Qn,{path:ZP.path,element:d.jsx(ZP,{})}),d.jsx(Qn,{path:JP.path,element:d.jsx(JP,{})})]}),d.jsxs(eP,{children:[d.jsx(Qn,{path:oD.path,element:d.jsx(oD,{})}),d.jsx(Qn,{path:iD.path,element:d.jsx(iD,{})}),d.jsx(Qn,{path:sD.path,element:d.jsx(sD,{})})]}),d.jsx(Co,{name:"deals",...nze}),d.jsx(Co,{name:"contacts",...X5e}),d.jsx(Co,{name:"companies",...H4e}),d.jsx(Co,{name:"contactNotes"}),d.jsx(Co,{name:"dealNotes"}),d.jsx(Co,{name:"tasks"}),d.jsx(Co,{name:"sales",...Fze}),d.jsx(Co,{name:"tags"})]})})})),"CRM"),AUe=i(()=>{const[e,t]=y.useState(()=>!QRe());return e?d.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:d.jsx(iie,{open:!0,onComplete:i(()=>{t(!1)},"onComplete"),canClose:!1})}):d.jsx(RUe,{})},"App");Nse.createRoot(document.getElementById("root")).render(d.jsx(y.StrictMode,{children:d.jsx(AUe,{})}));export{Zn as $,nl as A,Pr as B,jK as C,mY as D,m4 as E,Wo as F,h4 as G,fn as H,Go as I,SJ as J,Se as K,AK as L,Jme as M,_r as N,dw as O,ie as P,hG as Q,dd as R,el as S,lr as T,rs as U,pn as V,Wn as W,Tp as X,Tr as Y,qp as Z,zp as _,oy as a,ze as a0,wa as a1,_a as a2,Gr as a3,hd as a4,pd as a5,ln as a6,nr as a7,Ry as a8,h3e as a9,Fye as aA,j4e as aB,mg as aC,V5e as aD,Rne as aE,Nw as aF,Yr as aG,ud as aH,Vte as aI,Hn as aJ,S4 as aK,B1 as aL,b4 as aM,sn as aN,_4 as aO,hPe as aP,P1 as aQ,kN as aa,Va as ab,Zs as ac,yne as ad,_n as ae,Gn as af,Pn as ag,ra as ah,q1 as ai,yd as aj,Vt as ak,aM as al,Lte as am,Wt as an,D4 as ao,Dr as ap,tp as aq,F1 as ar,Dne as as,Pc as at,R4e as au,Zi as av,is as aw,lY as ax,Pte as ay,cc as az,uM as b,cK as c,Hme as d,za as e,Ge as f,yM as g,Cc as h,xt as i,Ec as j,Jw as k,Et as l,d as m,Xs as n,ca as o,jy as p,gNe as q,y as r,bNe as s,wNe as t,ua as u,_Ne as v,il as w,Lw as x,Ht as y,fd as z};
166
- //# sourceMappingURL=index-mE-upBfc.js.map
166
+ //# sourceMappingURL=index-CGJPhLfC.js.map