realtimex-crm 0.13.7 → 0.13.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 dc(){return dc=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},dc.apply(null,arguments)}i(dc,"b");var Ri={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},V3=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}:dc({},Tqe,a),c=f.left+f.right,p=f.top+f.bottom,m=s+c,v=l+p,b=(o-1)*r;return n==="row"?m=s*o+b+c:n==="column"&&(v=l*o+b+p),{width:m,height:v,padding:f}},"A"),sie=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"),lie=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,v=e.height;switch(l){case"left-to-right":t=0,n=(v-c)/2,a=v/2,s="central",f?(r=m,o="end"):(r=c+p,o="start");break;case"right-to-left":t=m-c,n=(v-c)/2,a=v/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=v,s="alphabetic"):(a=c+p,s="text-before-edge");break;case"bottom-to-top":t=(m-c)/2,n=v-c,r=m/2,o="middle",f?(a=0,s="text-before-edge"):(a=v-c-p,s="alphabetic")}return{symbolX:t,symbolY:n,labelX:r,labelY:a,labelAnchor:o,labelAlignment:s}},"z"),Nqe={circle:Oqe,diamond:kqe,square:Rqe,triangle:Aqe},Pqe=i(function(e){var t,n,r,a,o,s,l,f,c,p,m,v=e.x,b=e.y,w=e.width,S=e.height,_=e.data,j=e.direction,C=j===void 0?Ri.itemDirection:j,O=e.justify,E=O===void 0?Ri.justify:O,T=e.textColor,R=e.background,A=R===void 0?"transparent":R,N=e.opacity,D=N===void 0?1:N,M=e.symbolShape,I=M===void 0?Ri.symbolShape:M,F=e.symbolSize,L=F===void 0?Ri.symbolSize:F,q=e.symbolSpacing,z=q===void 0?Ri.symbolSpacing:q,$=e.symbolBorderWidth,H=$===void 0?0:$,U=e.symbolBorderColor,W=U===void 0?"transparent":U,V=e.onClick,Q=e.onMouseEnter,Y=e.onMouseLeave,K=e.toggleSerie,ee=e.effects,te=y.useState({}),oe=te[0],ne=te[1],fe=qr(),re=y.useCallback((function(X){if(ee){var se=ee.filter((function(me){return me.on==="hover"})).reduce((function(me,Te){return dc({},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 dc({},me,Te.style)}),{});ne(se)}Y?.(_,X)}),[Y,_,ee]),he=lie({direction:C,justify:E,symbolSize:(t=oe.symbolSize)!=null?t:L,symbolSpacing:z,width:w,height:S}),J=he.symbolX,Me=he.symbolY,we=he.labelX,Ce=he.labelY,Re=he.labelAnchor,ke=he.labelAlignment,Ne=[V,Q,Y,K].some((function(X){return X!==void 0})),ze=typeof I=="function"?I:Nqe[I];return d.jsxs("g",{transform:"translate("+v+","+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:Ne?"pointer":"auto"},onClick:i(function(X){V?.(_,X),K?.(_.id)},"onClick"),onMouseEnter:re,onMouseLeave:ce}),y.createElement(ze,dc({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:H,borderColor:(f=oe.symbolBorderColor)!=null?f:W},_.hidden?fe.legends.hidden.symbol:void 0)),d.jsx(Z_,{textAnchor:Re,style:dc({},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:Ce,children:_.label})]})},"B"),Dqe=i(function(e){var t=e.data,n=e.x,r=e.y,a=e.direction,o=e.padding,s=o===void 0?Ri.padding:o,l=e.justify,f=e.effects,c=e.itemWidth,p=e.itemHeight,m=e.itemDirection,v=m===void 0?Ri.itemDirection:m,b=e.itemsSpacing,w=b===void 0?Ri.itemsSpacing:b,S=e.itemTextColor,_=e.itemBackground,j=_===void 0?"transparent":_,C=e.itemOpacity,O=C===void 0?1:C,E=e.symbolShape,T=e.symbolSize,R=e.symbolSpacing,A=e.symbolBorderWidth,N=e.symbolBorderColor,D=e.onClick,M=e.onMouseEnter,I=e.onMouseLeave,F=e.toggleSerie,L=V3({itemCount:t.length,itemWidth:c,itemHeight:p,itemsSpacing:w,direction:a,padding:s}).padding,q=a==="row"?c+w:0,z=a==="column"?p+w:0;return d.jsx("g",{transform:"translate("+n+","+r+")",children:t.map((function($,H){return d.jsx(Pqe,{data:$,x:H*q+L.left,y:H*z+L.top,width:c,height:p,direction:v,justify:l,effects:f,textColor:S,background:j,opacity:O,symbolShape:E,symbolSize:T,symbolSpacing:R,symbolBorderWidth:A,symbolBorderColor:N,onClick:D,onMouseEnter:M,onMouseLeave:I,toggleSerie:F},H)}))})},"H"),Mqe=i(function(e){var t=e.data,n=e.containerWidth,r=e.containerHeight,a=e.translateX,o=a===void 0?Ri.translateX:a,s=e.translateY,l=s===void 0?Ri.translateY:s,f=e.anchor,c=e.direction,p=e.padding,m=p===void 0?Ri.padding:p,v=e.justify,b=e.itemsSpacing,w=b===void 0?Ri.itemsSpacing:b,S=e.itemWidth,_=e.itemHeight,j=e.itemDirection,C=e.itemTextColor,O=e.itemBackground,E=e.itemOpacity,T=e.symbolShape,R=e.symbolSize,A=e.symbolSpacing,N=e.symbolBorderWidth,D=e.symbolBorderColor,M=e.onClick,I=e.onMouseEnter,F=e.onMouseLeave,L=e.toggleSerie,q=e.effects,z=V3({itemCount:t.length,itemsSpacing:w,itemWidth:S,itemHeight:_,direction:c,padding:m}),$=z.width,H=z.height,U=sie({anchor:f,translateX:o,translateY:l,containerWidth:n,containerHeight:r,width:$,height:H}),W=U.x,V=U.y;return d.jsx(Dqe,{data:t,x:W,y:V,direction:c,padding:m,justify:v,effects:q,itemsSpacing:w,itemWidth:S,itemHeight:_,itemDirection:j,itemTextColor:C,itemBackground:O,itemOpacity:E,symbolShape:T,symbolSize:R,symbolSpacing:A,symbolBorderWidth:N,symbolBorderColor:D,onClick:M,onMouseEnter:I,onMouseLeave:F,toggleSerie:typeof L=="boolean"?void 0:L})},"E"),Iqe={start:"left",middle:"center",end:"right"},Fqe=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,v=m===void 0?0:m,b=t.justify,w=b!==void 0&&b,S=t.itemsSpacing,_=S===void 0?0:S,j=t.itemWidth,C=t.itemHeight,O=t.itemDirection,E=O===void 0?"left-to-right":O,T=t.itemTextColor,R=t.symbolSize,A=R===void 0?16:R,N=t.symbolSpacing,D=N===void 0?8:N,M=t.theme,I=V3({itemCount:n.length,itemWidth:j,itemHeight:C,itemsSpacing:_,direction:p,padding:v}),F=I.width,L=I.height,q=I.padding,z=sie({anchor:c,translateX:s,translateY:f,containerWidth:r,containerHeight:a,width:F,height:L}),$=z.x,H=z.y,U=p==="row"?j+_:0,W=p==="column"?C+_:0;e.save(),e.translate($,H),Uv(e,M.legends.text),n.forEach((function(V,Q){var Y,K=Q*U+q.left,ee=Q*W+q.top,te=lie({direction:E,justify:w,symbolSize:A,symbolSpacing:D,width:j,height:C}),oe=te.symbolX,ne=te.symbolY,fe=te.labelX,re=te.labelY,ce=te.labelAnchor,he=te.labelAlignment;e.fillStyle=(Y=V.color)!=null?Y:"black",e.fillRect(K+oe,ee+ne,A,A),e.textAlign=Iqe[ce],he==="central"&&(e.textBaseline="middle"),zv(e,dc({},M.legends.text,{fill:T??M.legends.text.fill}),String(V.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 gn(){return gn=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},gn.apply(null,arguments)}i(gn,"Q");function zc(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(zc,"U");var OW,$qe=i(function(e){var t=e.bars,n=e.annotations,r=rie({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(uqe,gn({},a),o)}))})},"$"),qqe=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(Mqe,gn({},f,{containerWidth:t,containerHeight:n,data:(l=f.data)!=null?l:c,toggleSerie:f.toggleSerie&&f.dataFrom==="keys"?a:void 0}),s)}))})},"ee"),Uqe=["data"],zqe=i(function(e){var t,n=e.bar,r=n.data,a=zc(n,Uqe),o=e.style,s=o.borderColor,l=o.color,f=o.height,c=o.labelColor,p=o.labelOpacity,m=o.labelX,v=o.labelY,b=o.transform,w=o.width,S=o.textAnchor,_=e.borderRadius,j=e.borderWidth,C=e.label,O=e.shouldRenderLabel,E=e.isInteractive,T=e.onClick,R=e.onMouseEnter,A=e.onMouseLeave,N=e.tooltip,D=e.isFocusable,M=e.ariaLabel,I=e.ariaLabelledBy,F=e.ariaDescribedBy,L=e.ariaDisabled,q=e.ariaHidden,z=qr(),$=Ire(),H=$.showTooltipFromEvent,U=$.showTooltipAt,W=$.hideTooltip,V=y.useMemo((function(){return function(){return y.createElement(N,gn({},a,r))}}),[N,a,r]),Q=y.useCallback((function(ne){T?.(gn({color:a.color},r),ne)}),[a,r,T]),Y=y.useCallback((function(ne){return H(V(),ne)}),[H,V]),K=y.useCallback((function(ne){R?.(r,ne),H(V(),ne)}),[r,R,H,V]),ee=y.useCallback((function(ne){A?.(r,ne),W()}),[r,W,A]),te=y.useCallback((function(){U(V(),[a.absX+a.width/2,a.absY])}),[U,V,a]),oe=y.useCallback((function(){W()}),[W]);return d.jsxs(gr.g,{transform:b,children:[d.jsx(gr.rect,{width:YP(w,(function(ne){return Math.max(ne,0)})),height:YP(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:E?K:void 0,onMouseMove:E?Y:void 0,onMouseLeave:E?ee:void 0,onClick:E?Q:void 0,onFocus:E&&D?te:void 0,onBlur:E&&D?oe:void 0,"data-testid":"bar.item."+r.id+"."+r.index}),O&&d.jsx(Z_,{x:m,y:v,textAnchor:S,dominantBaseline:"central",fillOpacity:p,style:gn({},z.labels.text,{pointerEvents:"none",fill:c}),children:C})]})},"ae"),Bqe=["color","label"],Hqe=i(function(e){var t=e.color,n=e.label,r=zc(e,Bqe);return d.jsx(uIe,{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:Hqe,tooltipLabel:i(function(e){return e.id+" - "+e.indexValue},"tooltipLabel"),legends:[],initialHiddenIds:[],annotations:[],enableTotals:!1,totalsOffset:10},In=gn({},Fn,{layers:["grid","axes","bars","totals","markers","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},barComponent:zqe,defs:[],fill:[],markers:[],animate:!0,animateOnMount:!1,motionConfig:"default",role:"img",isFocusable:!1}),br=gn({},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,v=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(),v&&(e.textBaseline="middle",e.textAlign=_==="middle"?"center":_,zv(e,b,m,s+w,l+S))},"renderBar"),pixelRatio:typeof window<"u"&&(OW=window.devicePixelRatio)!=null?OW:1}),cie=i(function(e,t,n,r,a,o){return H3(r,{all:e.map(t),min:0,max:0},a,o).padding(n)},"de"),uie=i(function(e,t){return e.map((function(n){return gn({},t.reduce((function(r,a){return r[a]=null,r}),{}),n)}))},"ue"),J_=i(function(e){return Object.keys(e).reduce((function(t,n){return e[n]&&(t[n]=e[n]),t}),{})},"se"),eS=i(function(e){return[e,Number(e)]},"ce");function die(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(die,"he");var Vqe=["layout","width","height","padding","innerPadding","valueScale","indexScale","hiddenIds"],W3=i(function(e,t){return e>t},"be"),fie=i(function(e,t){return e<t},"ge"),hie=i(function(e,t){return Array.from(" ".repeat(t-e),(function(n,r){return e+r}))},"ve"),Wqe=i(function(e){return W3(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,v=e.xScale,b=e.yScale,w=e.margin,S=n?fie:W3,_=a.map(J_),j=[];return m.forEach((function(C,O){return hie(0,v.domain().length).forEach((function(E){var T,R,A,N=eS(a[E][C]),D=N[0],M=N[1],I=l(a[E]),F=((T=v(I))!=null?T:0)+t*O+p*O,L=S(R=M,0)?(A=b(R))!=null?A:0:r,q=(function($,H){var U;return S($,0)?r-H:((U=b($))!=null?U:0)-r})(M,L),z={id:C,value:D===null?D:M,formattedValue:o(M),hidden:!1,index:E,indexValue:I,data:_[E]};j.push({key:C+"."+z.indexValue,index:j.length,data:z,x:F,y:L,absX:w.left+F,absY:w.top+L,width:t,height:q,color:s(z),label:f(z)})}))})),j},"pe"),Kqe=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,v=e.xScale,b=e.yScale,w=e.margin,S=n?fie:W3,_=a.map(J_),j=[];return c.forEach((function(C,O){return hie(0,b.domain().length).forEach((function(E){var T,R,A,N=eS(a[E][C]),D=N[0],M=N[1],I=s(a[E]),F=S(R=M,0)?r:(A=v(R))!=null?A:0,L=((T=b(I))!=null?T:0)+t*O+m*O,q=(function($,H){var U;return S($,0)?((U=v($))!=null?U:0)-r:r-H})(M,F),z={id:C,value:D===null?D:M,formattedValue:o(M),hidden:!1,index:E,indexValue:I,data:_[E]};j.push({key:C+"."+z.indexValue,index:j.length,data:z,x:F,y:L,absX:w.left+F,absY:w.top+L,width:q,height:t,color:l(z),label:f(z)})}))})),j},"ye"),Yqe=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,v=e.indexScale,b=e.hiddenIds,w=b===void 0?[]:b,S=zc(e,Vqe),_=S.keys.filter((function(H){return!w.includes(H)})),j=uie(S.data,_),C=a==="vertical"?["y","x",o]:["x","y",s],O=C[0],E=C[1],T=C[2],R=cie(j,S.getIndex,f,v,T,E),A=m.min==="auto"?Wqe:function(H){return H},N=j.reduce((function(H,U){return[].concat(H,_.map((function(W){return U[W]})))}),[]).filter(Boolean),D=A(Math.min.apply(Math,N)),M=(r=Math.max.apply(Math,N),isFinite(r)?r:0),I=H3(m,{all:N,min:D,max:M},O==="x"?o:s,O),F=a==="vertical"?[R,I]:[I,R],L=F[0],q=F[1],z=(R.bandwidth()-p*(_.length-1))/_.length,$=[gn({},S,{data:j,keys:_,innerPadding:p,xScale:L,yScale:q}),z,(t=m.reverse)!=null&&t,(n=I(0))!=null?n:0];return{xScale:L,yScale:q,bars:z>0?a==="vertical"?Gqe.apply(void 0,$):Kqe.apply(void 0,$):[]}},"xe"),Qqe=["data","layout","width","height","padding","valueScale","indexScale","hiddenIds"],pie=i(function(e){var t;return e.some(Array.isArray)?pie((t=[]).concat.apply(t,e)):e},"ke"),Xqe=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,v=[];return f.forEach((function(b){return c.domain().forEach((function(w,S){var _,j,C=b[S],O=(_=c(o(C.data)))!=null?_:0,E=((j=(function(M){return p(M[n?0:1])})(C))!=null?j:0)+.5*l,T=(function(M,I){var F;return((F=p(M[n?1:0]))!=null?F:0)-I})(C,E)-l,R=eS(C.data[b.key]),A=R[0],N=R[1],D={id:b.key,value:A===null?A:N,formattedValue:r(N),hidden:!1,index:S,indexValue:w,data:J_(C.data)};v.push({key:b.key+"."+w,index:v.length,data:D,x:O,y:E,absX:m.left+O,absY:m.top+E,width:t,height:T,color:a(D),label:s(D)})}))})),v},"we"),Zqe=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,v=[];return f.forEach((function(b){return p.domain().forEach((function(w,S){var _,j,C=b[S],O=(_=p(o(C.data)))!=null?_:0,E=((j=(function(M){return c(M[n?1:0])})(C))!=null?j:0)+.5*l,T=(function(M,I){var F;return((F=c(M[n?0:1]))!=null?F:0)-I})(C,E)-l,R=eS(C.data[b.key]),A=R[0],N=R[1],D={id:b.key,value:A===null?A:N,formattedValue:r(N),hidden:!1,index:S,indexValue:w,data:J_(C.data)};v.push({key:b.key+"."+w,index:v.length,data:D,x:E,y:O,absX:m.left+E,absY:m.top+O,width:T,height:t,color:a(D),label:s(D)})}))})),v},"Le"),Jqe=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,v=m===void 0?[]:m,b=zc(e,Qqe),w=b.keys.filter((function(z){return!v.includes(z)})),S=SFe().keys(w).offset(jFe)(uie(r,w)),_=a==="vertical"?["y","x",o]:["x","y",s],j=_[0],C=_[1],O=_[2],E=cie(r,b.getIndex,f,p,O,C),T=(n=pie(S),c.type==="log"?n.filter((function(z){return z!==0})):n),R=Math.min.apply(Math,T),A=Math.max.apply(Math,T),N=H3(c,{all:T,min:R,max:A},j==="x"?o:s,j),D=a==="vertical"?[E,N]:[N,E],M=D[0],I=D[1],F=b.innerPadding>0?b.innerPadding:0,L=E.bandwidth(),q=[gn({},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"?Xqe.apply(void 0,q):Zqe.apply(void 0,q):[]}},"Ce"),eUe=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=Gae(s??(r==="indexes"?"indexValue":"id"));return r==="indexes"?(function(c,p,m){var v=eW(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"&&v.reverse(),v})(t,o,f):(function(c,p,m,v,b,w){var S=eW(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"&&v==="stacked"&&m==="column"&&b!==!0||p==="horizontal"&&v==="stacked"&&b===!0)&&S.reverse(),S})(t,o,n,a,l,f)},"We"),kW=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+n)},"Me"),tUe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+(n>0?n:0))},"Be"),nUe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,Math.max(r,Number(n)))},"Re"),rUe=i(function(e,t){var n=e.get(t)||0;e.set(t,n+1)},"Oe"),mie=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,v=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,C=j===void 0?Fn.labelTextColor:j,O=e.groupMode,E=O===void 0?Fn.groupMode:O,T=e.layout,R=T===void 0?Fn.layout:T,A=e.data,N=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,z=e.valueScale,$=z===void 0?Fn.valueScale:z,H=e.indexScale,U=H===void 0?Fn.indexScale:H,W=e.initialHiddenIds,V=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(V??[]),Me=J[0],we=J[1],Ce=y.useCallback((function(Ke){we((function(pt){return pt.indexOf(Ke)>-1?pt.filter((function(ve){return ve!==Ke})):[].concat(pt,[Ke])}))}),[]),Re=YA(r),ke=YA(l),Ne=YA(c),ze=B3(p),X=qr(),se=Eqe(v,w),me=EW(_,X),Te=EW(C,X),de=(E==="grouped"?Yqe:Jqe)({layout:R,data:A,getIndex:Re,keys:o,width:D,height:M,getColor:se,padding:F,innerPadding:q,valueScale:$,indexScale:U,hiddenIds:Me,formatValue:ze,getTooltipLabel:Ne,margin:N}),ue=de.bars,Ae=de.xScale,Pe=de.yScale,Fe=y.useMemo((function(){return ue.filter((function(Ke){return Ke.data.value!==null})).map((function(Ke,pt){return gn({},Ke,{index:pt})}))}),[ue]),et=y.useCallback((function(Ke){var pt=Ke.width,ve=Ke.height;return!!Y&&!(ee>0&&pt<ee)&&!(oe>0&&ve<oe)}),[Y,ee,oe]),Nt=y.useMemo((function(){return o.map((function(Ke){var pt=ue.find((function(ve){return ve.data.id===Ke}));return gn({},pt,{data:gn({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,eUe({bars:Ke.dataFrom==="keys"?Nt:ue,direction:Ke.direction,from:Ke.dataFrom,groupMode:E,layout:R,legendLabel:re,reverse:$t})]}))}),[fe,Nt,ue,E,R,re,$t]),Ut=y.useMemo((function(){return(function(Ke,pt,ve,ye,ct,$e,Xe){ye===void 0&&(ye=Fn.layout),ct===void 0&&(ct=Fn.groupMode);var We=[];if(Ke.length===0)return We;var tt=new Map,jt=Ke[0].width,Ye=Ke[0].height;if(ct==="stacked"){var gt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Et=_t.value;kW(tt,vt,Number(Et)),tUe(gt,vt,Number(Et))})),gt.forEach((function(At,_t){var vt,Et,Z,pe=tt.get(_t)||0;ye==="vertical"?(vt=pt(_t),Et=ve(At),Z=ve(At/2)):(vt=pt(At),Et=ve(_t),Z=pt(At/2)),vt+=ye==="vertical"?jt/2:$e,Et+=ye==="vertical"?-$e:Ye/2,We.push({key:"total_"+_t,x:vt,y:Et,value:pe,formattedValue:Xe(pe),animationOffset:Z})}))}else if(ct==="grouped"){var Ft=new Map,Pt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Et=_t.value;kW(tt,vt,Number(Et)),nUe(Ft,vt,Number(Et)),rUe(Pt,vt)})),Ft.forEach((function(At,_t){var vt,Et,Z,pe=tt.get(_t)||0,_e=Pt.get(_t);ye==="vertical"?(vt=pt(_t),Et=ve(At),Z=ve(At/2)):(vt=pt(At),Et=ve(_t),Z=pt(At/2)),vt+=ye==="vertical"?_e*jt/2:$e,Et+=ye==="vertical"?-$e:_e*Ye/2,We.push({key:"total_"+_t,x:vt,y:Et,value:pe,formattedValue:Xe(pe),animationOffset:Z})}))}return We})(ue,Ae,Pe,R,E,he,ze)}),[ue,Ae,Pe,R,E,he,ze]);return{bars:ue,barsWithValue:Fe,xScale:Ae,yScale:Pe,getIndex:Re,getLabel:ke,getTooltipLabel:Ne,formatValue:ze,getColor:se,getBorderColor:me,getLabelColor:Te,shouldRenderBarLabel:et,hiddenIds:Me,toggleSerie:Ce,legendsWithData:Rt,barTotals:Ut}},"Ie"),aUe=i(function(e){var t=e.data,n=e.springConfig,r=e.animate,a=e.layout,o=a===void 0?In.layout:a,s=qr();return p_(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(gr.text,{x:l.x,y:l.y,fillOpacity:l.labelOpacity,style:gn({},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"),iUe=["isInteractive","animate","motionConfig","theme","renderWrapper"],oUe=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,v=e.padding,b=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,j=_===void 0?In.axisBottom:_,C=e.axisLeft,O=C===void 0?In.axisLeft:C,E=e.enableGridX,T=E===void 0?In.enableGridX:E,R=e.enableGridY,A=R===void 0?In.enableGridY:R,N=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,z=q===void 0?In.enableLabel:q,$=e.label,H=e.labelSkipWidth,U=H===void 0?In.labelSkipWidth:H,W=e.labelSkipHeight,V=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,Ce=we===void 0?In.borderRadius:we,Re=e.borderWidth,ke=Re===void 0?In.borderWidth:Re,Ne=e.borderColor,ze=e.annotations,X=ze===void 0?In.annotations:ze,se=e.legendLabel,me=e.tooltipLabel,Te=e.valueFormat,de=e.isInteractive,ue=de===void 0?In.isInteractive:de,Ae=e.tooltip,Pe=Ae===void 0?In.tooltip:Ae,Fe=e.onClick,et=e.onMouseEnter,Nt=e.onMouseLeave,$t=e.legends,Rt=e.role,Ut=Rt===void 0?In.role:Rt,Ke=e.ariaLabel,pt=e.ariaLabelledBy,ve=e.ariaDescribedBy,ye=e.isFocusable,ct=ye===void 0?In.isFocusable:ye,$e=e.barAriaLabel,Xe=e.barAriaLabelledBy,We=e.barAriaDescribedBy,tt=e.barAriaHidden,jt=e.barAriaDisabled,Ye=e.initialHiddenIds,gt=e.enableTotals,Ft=gt===void 0?In.enableTotals:gt,Pt=e.totalsOffset,At=Pt===void 0?In.totalsOffset:Pt,_t=e.forwardedRef,vt=yo(),Et=vt.animate,Z=vt.config,pe=Wae(s,l,o),_e=pe.outerWidth,qe=pe.outerHeight,He=pe.margin,rt=pe.innerWidth,nt=pe.innerHeight,Qe=mie({indexBy:r,label:$,tooltipLabel:me,valueFormat:Te,colors:re,colorBy:fe,borderColor:Ne,labelTextColor:Q,groupMode:f,layout:c,data:n,keys:a,margin:He,width:rt,height:nt,padding:v,innerPadding:b,valueScale:p,indexScale:m,enableLabel:z,labelSkipWidth:U,labelSkipHeight:V,legends:$t,legendLabel:se,initialHiddenIds:Ye,totalsOffset:At}),ot=Qe.bars,ut=Qe.barsWithValue,st=Qe.xScale,lt=Qe.yScale,yt=Qe.getLabel,at=Qe.getTooltipLabel,kt=Qe.getBorderColor,bt=Qe.getLabelColor,Lt=Qe.shouldRenderBarLabel,Mt=Qe.toggleSerie,zr=Qe.legendsWithData,Aa=Qe.barTotals,fi=Qe.getColor,dr=die(c,(t=p?.reverse)!=null&&t,K,te),bo=p_(ut,{keys:i(function(Ve){return Ve.key},"keys"),from:i(function(Ve){return gn({borderColor:kt(Ve),color:Ve.color,height:0,labelColor:bt(Ve),labelOpacity:0},dr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+(Ve.y+Ve.height)+")",width:Ve.width},c==="vertical"?{}:{height:Ve.height,transform:"translate("+Ve.x+", "+Ve.y+")",width:0})},"from"),enter:i(function(Ve){return gn({borderColor:kt(Ve),color:Ve.color,height:Ve.height,labelColor:bt(Ve),labelOpacity:1},dr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+Ve.y+")",width:Ve.width})},"enter"),update:i(function(Ve){return gn({borderColor:kt(Ve),color:Ve.color,height:Ve.height,labelColor:bt(Ve),labelOpacity:1},dr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+Ve.y+")",width:Ve.width})},"update"),leave:i(function(Ve){return gn({borderColor:kt(Ve),color:Ve.color,height:0,labelColor:bt(Ve),labelOpacity:0},dr(Ve.width,Ve.height),{labelY:0,transform:"translate("+Ve.x+", "+(Ve.y+Ve.height)+")",width:Ve.width},c==="vertical"?{}:gn({},dr(Ve.width,Ve.height),{labelX:0,height:Ve.height,transform:"translate("+Ve.x+", "+Ve.y+")",width:0}))},"leave"),config:Z,immediate:!Et,initial:Et?void 0:null}),Br=y.useMemo((function(){return{borderRadius:Ce,borderWidth:ke,enableLabel:z,isInteractive:ue,labelSkipWidth:U,labelSkipHeight:V,onClick:Fe,onMouseEnter:et,onMouseLeave:Nt,getTooltipLabel:at,tooltip:Pe,isFocusable:ct,ariaLabel:$e,ariaLabelledBy:Xe,ariaDescribedBy:We,ariaHidden:tt,ariaDisabled:jt}}),[Ce,ke,z,at,ue,V,U,Fe,et,Nt,Pe,ct,$e,Xe,We,tt,jt]),Ka=r9e(he,ot,Me,{dataKey:"data",targetKey:"data.fill"}),ea={annotations:null,axes:null,bars:null,grid:null,legends:null,markers:null,totals:null};I.includes("annotations")&&(ea.annotations=d.jsx($qe,{bars:ot,annotations:X},"annotations")),I.includes("axes")&&(ea.axes=d.jsx(F9e,{xScale:st,yScale:lt,width:rt,height:nt,top:w,right:S,bottom:j,left:O},"axes")),I.includes("bars")&&(ea.bars=d.jsx(y.Fragment,{children:bo((function(Ve,qn){return y.createElement(L,gn({},Br,{bar:qn,style:Ve,shouldRenderLabel:Lt(qn),label:yt(qn.data)}))}))},"bars")),I.includes("grid")&&(ea.grid=d.jsx($9e,{width:rt,height:nt,xScale:T?st:null,yScale:A?lt:null,xValues:N,yValues:D},"grid")),I.includes("legends")&&(ea.legends=d.jsx(qqe,{width:rt,height:nt,legends:zr,toggleSerie:Mt},"legends")),I.includes("markers")&&(ea.markers=d.jsx(G7e,{markers:ne,width:rt,height:nt,xScale:st,yScale:lt},"markers")),I.includes("totals")&&Ft&&(ea.totals=d.jsx(aUe,{data:Aa,springConfig:Z,animate:Et,layout:c},"totals"));var Ya=gn({},Br,{margin:He,width:s,height:l,innerWidth:rt,innerHeight:nt,bars:ot,legendData:zr,enableLabel:z,xScale:st,yScale:lt,tooltip:Pe,getTooltipLabel:at,onClick:Fe,onMouseEnter:et,onMouseLeave:Nt,getColor:fi});return d.jsx(H7e,{width:_e,height:qe,margin:He,defs:Ka,role:Ut,ariaLabel:Ke,ariaLabelledBy:pt,ariaDescribedBy:ve,isFocusable:ct,ref:_t,children:I.map((function(Ve,qn){var Li;return typeof Ve=="function"?d.jsx(y.Fragment,{children:y.createElement(Ve,Ya)},qn):(Li=ea?.[Ve])!=null?Li:null}))})},"He"),sUe=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=zc(e,iUe);return d.jsx(Uae,{animate:o,isInteractive:r,motionConfig:l,renderWrapper:c,theme:f,children:d.jsx(oUe,gn({},p,{isInteractive:r,forwardedRef:t}))})})),lUe=["isInteractive","renderWrapper","theme"],bT=i(function(e,t,n,r){return e.find((function(a){return J7e(a.x+t.left,a.y+t.top,a.width,a.height,n,r)}))},"Fe"),cUe=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,v=e.padding,b=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,j=_===void 0?br.axisBottom:_,C=e.axisLeft,O=C===void 0?br.axisLeft:C,E=e.enableGridX,T=E===void 0?br.enableGridX:E,R=e.enableGridY,A=R===void 0?br.enableGridY:R,N=e.gridXValues,D=e.gridYValues,M=e.labelPosition,I=M===void 0?br.labelPosition:M,F=e.labelOffset,L=F===void 0?br.labelOffset:F,q=e.layers,z=q===void 0?br.layers:q,$=e.renderBar,H=$===void 0?br.renderBar:$,U=e.enableLabel,W=U===void 0?br.enableLabel:U,V=e.label,Q=e.labelSkipWidth,Y=Q===void 0?br.labelSkipWidth:Q,K=e.labelSkipHeight,ee=K===void 0?br.labelSkipHeight:K,te=e.labelTextColor,oe=e.colorBy,ne=e.colors,fe=e.borderRadius,re=fe===void 0?br.borderRadius:fe,ce=e.borderWidth,he=ce===void 0?br.borderWidth:ce,J=e.borderColor,Me=e.annotations,we=Me===void 0?br.annotations:Me,Ce=e.legendLabel,Re=e.tooltipLabel,ke=e.valueFormat,Ne=e.isInteractive,ze=Ne===void 0?br.isInteractive:Ne,X=e.tooltip,se=X===void 0?br.tooltip:X,me=e.onClick,Te=e.onMouseEnter,de=e.onMouseLeave,ue=e.legends,Ae=e.pixelRatio,Pe=Ae===void 0?br.pixelRatio:Ae,Fe=e.role,et=e.forwardedRef,Nt=e.enableTotals,$t=Nt===void 0?br.enableTotals:Nt,Rt=e.totalsOffset,Ut=Rt===void 0?br.totalsOffset:Rt,Ke=y.useRef(null),pt=qr(),ve=Wae(s,l,o),ye=ve.margin,ct=ve.innerWidth,$e=ve.innerHeight,Xe=ve.outerWidth,We=ve.outerHeight,tt=mie({indexBy:r,label:V,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:$e,padding:v,innerPadding:b,valueScale:p,indexScale:m,enableLabel:W,labelSkipWidth:Y,labelSkipHeight:ee,legends:ue,legendLabel:Ce,totalsOffset:Ut}),jt=tt.bars,Ye=tt.barsWithValue,gt=tt.xScale,Ft=tt.yScale,Pt=tt.getLabel,At=tt.getTooltipLabel,_t=tt.getBorderColor,vt=tt.getLabelColor,Et=tt.shouldRenderBarLabel,Z=tt.legendsWithData,pe=tt.barTotals,_e=tt.getColor,qe=Ire(),He=qe.showTooltipFromEvent,rt=qe.hideTooltip,nt=aqe({annotations:rie({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:ze,isFocusable:!1,labelSkipWidth:Y,labelSkipHeight:ee,margin:ye,width:s,height:l,innerWidth:ct,innerHeight:$e,bars:jt,legendData:Z,enableLabel:W,xScale:gt,yScale:Ft,tooltip:se,getTooltipLabel:At,onClick:me,onMouseEnter:Te,onMouseLeave:de,getColor:_e}}),[re,he,ze,Y,ee,ye,s,l,ct,$e,jt,Z,W,gt,Ft,se,At,me,Te,de,_e]),ot=B3(ke),ut=die(c,(t=p?.reverse)!=null&&t,I,L);y.useEffect((function(){if(Ke.current){Ke.current.width=Xe*Pe,Ke.current.height=We*Pe;var at=Ke.current.getContext("2d");at.scale(Pe,Pe),at.fillStyle=pt.background,at.fillRect(0,0,Xe,We),at.translate(ye.left,ye.top),z.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&&hW(at,{width:ct,height:$e,scale:gt,axis:"x",values:N}),A&&hW(at,{width:ct,height:$e,scale:Ft,axis:"y",values:D})):kt==="axes"?U9e(at,{xScale:gt,yScale:Ft,width:ct,height:$e,top:w,right:S,bottom:j,left:O,theme:pt}):kt==="bars"?(Uv(at,pt.text),Ye.forEach((function(bt){H(at,gn({bar:bt,borderColor:_t(bt),borderRadius:re,borderWidth:he,label:Pt(bt.data),shouldRenderLabel:Et(bt),labelStyle:gn({},pt.labels.text,{fill:vt(bt)})},ut(bt.width,bt.height)))}))):kt==="legends"?Z.forEach((function(bt){var Lt=bt[0],Mt=bt[1];Fqe(at,gn({},Lt,{data:Mt,containerWidth:ct,containerHeight:$e,theme:pt}))})):kt==="annotations"?dqe(at,{annotations:nt,theme:pt}):kt==="totals"&&$t?(function(bt,Lt,Mt,zr){zr===void 0&&(zr=br.layout),Uv(bt,Mt.labels.text),bt.textBaseline=zr==="vertical"?"alphabetic":"middle",bt.textAlign=zr==="vertical"?"center":"start",Lt.forEach((function(Aa){zv(bt,Mt.labels.text,Aa.formattedValue,Aa.x,Aa.y)}))})(at,pe,pt,c):typeof kt=="function"&&kt(at,Qe)})),at.save()}}),[j,O,S,w,Ye,re,he,nt,T,A,_t,Pt,vt,N,D,f,l,$e,ct,Qe,z,c,Z,ye.left,ye.top,We,Xe,Pe,H,gt,Ft,Et,pt,s,pe,$t,ot,ut]);var st=y.useCallback((function(at){if(jt&&Ke.current){var kt=QA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=bT(jt,ye,bt,Lt);Mt!==void 0?(He(y.createElement(se,gn({},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,He,se]),lt=y.useCallback((function(at){if(jt&&Ke.current){rt();var kt=QA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=bT(jt,ye,bt,Lt);Mt&&de?.(Mt.data,at)}}),[rt,ye,de,jt]),yt=y.useCallback((function(at){if(jt&&Ke.current){var kt=QA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=bT(jt,ye,bt,Lt);Mt!==void 0&&me?.(gn({},Mt.data,{color:Mt.color}),at)}}),[ye,me,jt]);return d.jsx("canvas",{ref:a9e(Ke,et),width:Xe*Pe,height:We*Pe,style:{width:Xe,height:We,cursor:ze?"auto":"normal"},onMouseEnter:ze?st:void 0,onMouseMove:ze?st:void 0,onMouseLeave:ze?lt:void 0,onClick:ze?yt:void 0,role:Fe})},"ze"),uUe=y.forwardRef((function(e,t){var n=e.isInteractive,r=e.renderWrapper,a=e.theme,o=zc(e,lUe);return d.jsx(Uae,{isInteractive:n,renderWrapper:r,theme:a,animate:!1,children:d.jsx(cUe,gn({},o,{isInteractive:n,forwardedRef:t}))})})),dUe=["defaultWidth","defaultHeight","onResize","debounceResize"],fUe=y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,o=e.debounceResize,s=zc(e,dUe);return d.jsx(zae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:o,children:i(function(l){var f=l.width,c=l.height;return d.jsx(sUe,gn({},s,{width:f,height:c,ref:t}))},"children")})})),hUe=["defaultWidth","defaultHeight","onResize","debounceResize"];y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,o=e.debounceResize,s=zc(e,hUe);return d.jsx(zae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:o,children:i(function(l){var f=l.width,c=l.height;return d.jsx(uUe,gn({},s,{width:f,height:c,ref:t}))},"children")})}));const pUe={opportunity:.2,"proposal-sent":.5,"in-negociation":.8,delayed:.3},mUe=new Date(new Date().setMonth(new Date().getMonth()-6)).toISOString(),RW="en-US",gUe="USD",vUe=y.memo(()=>{const e=navigator?navigator.languages||[navigator.language]:[RW],{data:t,isPending:n}=Sa("deals",{pagination:{perPage:100,page:1},sort:{field:"created_at",order:"ASC"},filter:{"created_at@gte":mUe}}),r=y.useMemo(()=>{if(!t)return[];const s=t.reduce((f,c)=>{const p=mN(c.created_at??new Date).toISOString();return f[p]||(f[p]=[]),f[p].push(c),f},{});return Object.keys(s).map(f=>({date:pc(f,"MMM"),won:s[f].filter(c=>c.stage==="won").reduce((c,p)=>{const m=p.amount??0;return isNaN(m)||(c+=m),c},0),pending:s[f].filter(c=>!["won","lost"].includes(c.stage)).reduce((c,p)=>{const m=p.amount??0,v=pUe[p.stage]??0;return!isNaN(m)&&!isNaN(v)&&(c+=m*v),c},0),lost:s[f].filter(c=>c.stage==="lost").reduce((c,p)=>{const m=p.amount??0;return isNaN(m)||(c-=m),c},0)})).filter(f=>!isNaN(f.won)&&!isNaN(f.pending)&&!isNaN(f.lost))},[t]);if(n||r.length===0)return null;const a=r.reduce((s,l)=>(s.min=Math.min(s.min,l.lost),s.max=Math.max(s.max,l.won+l.pending),s),{min:0,max:0}),o={min:a.min===0&&a.max===0?-100:a.min*1.2,max:a.min===0&&a.max===0?100:a.max*1.2};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($Q,{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(fUe,{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:o.min,max:o.max},indexScale:{type:"band",round:!0},enableGridX:!0,enableGridY:!1,enableLabel:!1,tooltip:i(({value:s,indexValue:l})=>d.jsxs("div",{className:"p-2 bg-secondary rounded shadow inline-flex items-center gap-1 text-secondary-foreground",children:[d.jsxs("strong",{children:[l,": "]})," ",s>0?"+":"",s.toLocaleString(e.at(0)??RW,{style:"currency",currency:gUe})]}),"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(s=>`${Math.abs(s/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"}]})})]})}),yUe=i(e=>{const t=xt(),n=Gt(e),{filterValues:r,setFilters:a}=Hw(e),o=md();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(Le,{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"),bUe=i(e=>{const{children:t,linkType:n,rowClick:r,style:a}=e,o=Gt(e),s=qt(e),l=Ea(),f=typeof n=="function"||typeof r=="function",c=dK({link:f?!1:n??r,resource:o}),p=pK(),m=Ct(async()=>{if(!f||!s)return;const v=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:v});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"),xT=i(({className:e})=>d.jsx("span",{className:Se("bg-gray-300 flex",e),children:" "}),"ListPlaceholder"),xUe=i(e=>{const{className:t,hasLeftAvatarOrIcon:n,hasRightAvatarOrIcon:r,hasSecondaryText:a,hasTertiaryText:o,nbFakeLines:s=5,...l}=e;return HK(1e3)?d.jsx("ul",{className:t,...l,children:wUe(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(xT,{className:"w-1/3 inline-block mb-1"}),o&&d.jsx("span",{className:"float-right opacity-55 min-w-[10vw]",children:d.jsx(xT,{})})]}),a&&d.jsx(xT,{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"),wUe=i((e,t)=>Array.from({length:e},(n,r)=>t(r)),"times"),_Ue=i(e=>{const{className:t,empty:n=jUe,leftAvatar:r,leftIcon:a,linkType:o,rowClick:s,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,resource:v,...b}=e,{data:w,isPending:S,total:_}=Hw(e);return S===!0?d.jsx(xUe,{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,...jme(b),children:d.jsx(Tme,{data:w,total:_,render:i((j,C)=>d.jsx(bUe,{rowIndex:C,linkType:o,rowClick:s,resource:v,children:d.jsx(SUe,{leftAvatar:r,leftIcon:a,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,rowIndex:C})},j.id),"render")})})},"SimpleList"),SUe=i(e=>{const{leftAvatar:t,leftIcon:n,primaryText:r,rightAvatar:a,rightIcon:o,secondaryText:s,tertiaryText:l}=e,f=Gt(e),c=qt(e),p=Rc(f),m=xt(),v=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:v(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&&v(c,a),o&&o(c,c.id)]})]}):null},"SimpleListItemContent"),jUe=d.jsx(yUe,{}),CUe=i(()=>{const{identity:e}=er(),{data:t,total:n,isPending:r}=Sa("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(HM,{className:"text-muted-foreground w-6 h-6"})}),d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Hot Contacts"}),d.jsx(Di,{children:d.jsxs(so,{children:[d.jsx(lo,{asChild:!0,children:d.jsx(Le,{variant:"ghost",size:"sm",className:"ml-auto text-muted-foreground",asChild:!0,children:d.jsx(fn,{to:"/contacts/create",children:d.jsx(ro,{className:"w-4 h-4 text-primary"})})})}),d.jsx(co,{children:"Create contact"})]})})]}),d.jsx(pn,{className:"py-0",children:d.jsx(_Ue,{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(us,{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"),EUe=i(()=>{const{identity:e}=er(),{total:t}=Sa("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"),mg=i(({title:e,filter:t})=>{const{identity:n}=er(),{data:r,total:a,isPending:o}=Sa("tasks",{pagination:{page:1,perPage:100},sort:{field:"due_date",order:"ASC"},filter:{...t,sales_id:n?.id}},{enabled:!!n}),s=Vw({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(pd,{value:"tasks",children:d.jsx(sy,{value:s,children:d.jsx(Wne,{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"),gie=new Date,OUe=cbe(gie),kUe=OUe<5,AW=dbe().toISOString(),TW=l0e().toISOString(),NW=c0e().toISOString(),PW=s0e(gie,{weekStartsOn:0}).toISOString(),gg={overdue:{"done_date@is":null,"due_date@lt":AW},today:{"done_date@is":null,"due_date@gte":AW,"due_date@lte":TW},tomorrow:{"done_date@is":null,"due_date@gt":TW,"due_date@lt":NW},thisWeek:{"done_date@is":null,"due_date@gte":NW,"due_date@lte":PW},later:{"done_date@is":null,"due_date@gt":PW}},RUe=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(UQ,{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(Vne,{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(EUe,{}),d.jsx(mg,{title:"Overdue",filter:gg.overdue}),d.jsx(mg,{title:"Today",filter:gg.today}),d.jsx(mg,{title:"Tomorrow",filter:gg.tomorrow}),kUe&&d.jsx(mg,{title:"This week",filter:gg.thisWeek}),d.jsx(mg,{title:"Later",filter:gg.later})]})})]}),"TasksList"),AUe=i(()=>{const{data:e,total:t,isPending:n}=Sa("contacts",{pagination:{page:1,perPage:1}}),{total:r,isPending:a}=Sa("contactNotes",{pagination:{page:1,perPage:1}}),{total:o,isPending:s}=Sa("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(CUe,{})]})}),d.jsx("div",{className:"md:col-span-6",children:d.jsxs("div",{className:"flex flex-col gap-6",children:[o?d.jsx(vUe,{}):null,d.jsx(I6e,{})]})}),d.jsx("div",{className:"md:col-span-3",children:d.jsx(RUe,{})})]}):d.jsx(PH,{step:2,contactId:e?.[0]?.id}):d.jsx(PH,{step:1})},"Dashboard"),TUe=y.lazy(()=>Up(()=>import("./DealList-D4GG0g38.js"),[],import.meta.url)),NUe={list:TUe},PUe=y.createContext(void 0),tS=i(()=>y.useContext(PUe),"useUserMenu"),DUe=i(()=>{const{darkModeLogo:e,lightModeLogo:t,title:n}=Ra(),r=$r(),o=[{path:"/",pattern:"/"},{path:"/contacts",pattern:"/contacts/*"},{path:"/companies",pattern:"/companies/*"},{path:"/deals",pattern:"/deals/*"}].find(s=>ap(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(MUe,{darkLogo:e,lightLogo:t,title:n}),d.jsxs("nav",{className:"flex","aria-label":"Main navigation",children:[d.jsx(Rb,{label:"Dashboard",to:"/",isActive:o==="/"}),d.jsx(Rb,{label:"Contacts",to:"/contacts",isActive:o==="/contacts"}),d.jsx(Rb,{label:"Companies",to:"/companies",isActive:o==="/companies"}),d.jsx(Rb,{label:"Deals",to:"/deals",isActive:o==="/deals"})]}),d.jsxs("div",{className:"flex items-center",children:[d.jsx(YZ,{}),d.jsx(QZ,{}),d.jsxs(WZ,{children:[d.jsx(FUe,{}),d.jsx(LUe,{}),d.jsx($Ue,{}),d.jsx(Gve,{resource:"sales",action:"list",children:d.jsx(IUe,{})}),d.jsx(lv,{}),d.jsx(g4,{className:"font-normal",children:d.jsxs("div",{className:"text-xs text-muted-foreground",children:["Version ","0.13.7"]})})]})]})]})})})},"Header"),MUe=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"),Rb=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"),IUe=i(()=>{const{onClose:e}=tS()??{};return d.jsx(cr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/sales",className:"flex items-center gap-2",children:[d.jsx(VQ,{className:"h-4 w-4"}),"Users"]})})},"UsersMenu"),FUe=i(()=>{const{onClose:e}=tS()??{};return d.jsx(cr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/settings",className:"flex items-center gap-2",children:[d.jsx(yN,{className:"h-4 w-4"}),"My info"]})})},"ConfigurationMenu"),LUe=i(()=>{const{onClose:e}=tS()??{};return d.jsx(cr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/database",className:"flex items-center gap-2",children:[d.jsx(nv,{className:"h-4 w-4"}),"Database"]})})},"DatabaseMenu"),$Ue=i(()=>{const{onClose:e}=tS()??{};return d.jsx(cr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/integrations",className:"flex items-center gap-2",children:[d.jsx(S_e,{className:"h-4 w-4"}),"Integrations"]})})},"IntegrationsMenu"),qUe=i(({children:e})=>d.jsxs(d.Fragment,{children:[d.jsx(DUe,{}),d.jsx("main",{className:"max-w-screen-xl mx-auto pt-20 px-4",id:"main-content",children:d.jsx(vx,{FallbackComponent:tJ,children:d.jsx(y.Suspense,{fallback:d.jsx(ln,{className:"h-12 w-12 rounded-full"}),children:e})})}),d.jsx(I1,{})]}),"Layout"),vie=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(ln,{className:"w-full h-[100px]"}),d.jsx(ln,{className:"w-4/5 h-[50px]"}),d.jsx(ln,{className:"w-full h-9"}),d.jsx(ln,{className:"w-full h-9"}),d.jsx(ln,{className:"w-full h-9"}),d.jsx(ln,{className:"w-2/5 h-9"})]})})}),"LoginSkeleton"),dD=i(()=>{const e=Nn(),t=xn(),{darkModeLogo:n,title:r}=Ra(),{data:a,isPending:o}=Xr({queryKey:["init"],queryFn:i(async()=>t.isInitialized(),"queryFn")}),{isPending:s,mutate:l}=Lr({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=MY(),c=Vt(),{register:p,handleSubmit:m,formState:{isValid:v}}=uy({mode:"onChange"});if(o)return d.jsx(vie,{});if(a)return d.jsx(ww,{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(Vn,{htmlFor:"first_name",children:"First name"}),d.jsx(Cr,{...p("first_name",{required:!0}),id:"first_name",type:"text",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Vn,{htmlFor:"last_name",children:"Last name"}),d.jsx(Cr,{...p("last_name",{required:!0}),id:"last_name",type:"text",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Vn,{htmlFor:"email",children:"Email"}),d.jsx(Cr,{...p("email",{required:!0}),id:"email",type:"email",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Vn,{htmlFor:"password",children:"Password"}),d.jsx(Cr,{...p("password",{required:!0}),id:"password",type:"password",required:!0})]}),d.jsx("div",{className:"flex justify-between items-center mt-8",children:d.jsx(Le,{type:"submit",disabled:!v||s,className:"w-full",children:s?d.jsxs(d.Fragment,{children:[d.jsx(Tc,{className:"w-4 h-4 animate-spin mr-2"}),"Creating..."]}):"Create account"})})]})]})})]})},"SignupPage");dD.path="/sign-up";const UUe=i((e,t)=>e==="admin"?!0:t.resource!=="sales","canAccess"),wT=yAe(Ln,{getIdentity:i(async()=>{const e=await yie();if(e==null)throw new Error;return{id:e.id,fullName:`${e.first_name} ${e.last_name}`,avatar:e.avatar?.src}},"getIdentity")});async function Xs(){if(Xs._is_initialized_cache==null){const{data:e}=await Ln.from("init_state").select("is_initialized");Xs._is_initialized_cache=e?.at(0)?.is_initialized>0}return Xs._is_initialized_cache}i(Xs,"getIsInitialized");(e=>{e._is_initialized_cache=null})(Xs||(Xs={}));const zUe={...wT,login:i(async e=>{const t=await wT.login(e);return Hb=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 Xs())throw await Ln.auth.signOut(),{redirectTo:"/sign-up",message:!1};return wT.checkAuth(e)},"checkAuth"),canAccess:i(async e=>{if(!await Xs())return!1;const n=await yie();if(n==null)return!1;const r=n.administrator?"admin":"user";return UUe(r,e)},"canAccess")};let Hb;const yie=i(async()=>{if(Hb!=null)return Hb;const{data:e,error:t}=await Ln.auth.getSession();if(e?.session?.user==null||t)return;const{data:n,error:r}=await Ln.from("sales").select("id, first_name, last_name, avatar, administrator").match({user_id:e?.session?.user.id}).single();if(!(n==null||r))return Hb=n,n},"getSaleFromCache");async function BUe(e,t,n){const r={};t&&(r.id=t);const a={};t&&(a.company_id=t);const[o,s,l,f]=await Promise.all([HUe(e,r),VUe(e,a),WUe(e,a),GUe(e,a)]);return[...o,...s,...l,...f].sort((c,p)=>c.date&&p.date?c.date.localeCompare(p.date)*-1:0).slice(0,250)}i(BUe,"getActivityLog");const HUe=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:qte,company_id:r.id,company:r,sales_id:r.sales_id,date:r.created_at}))},"getNewCompanies");async function VUe(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:zte,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:Bte,sales_id:l.sales_id,contactNote:l,date:l.date}));return[...o,...s]}i(VUe,"getNewContactsAndNotes");async function WUe(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:Hte,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:Vte,sales_id:l.sales_id,dealNote:l,date:l.date}));return[...o,...s]}i(WUe,"getNewDealsAndNotes");async function GUe(e,t){const n={};t.sales_id&&(n.sales_id=t.sales_id),t.company_id&&(n.company_id=t.company_id);const{data:r}=await e.getList("companyNotes",{filter:n,pagination:{page:1,perPage:250},sort:{field:"date",order:"DESC"}});return r.map(o=>({id:`companyNote.${o.id}.created`,type:Ute,sales_id:o.sales_id,companyNote:o,date:o.date}))}i(GUe,"getNewCompanyNotes");async function KUe(e){return e.website?{src:`https://favicon.show/${e.website.replace(/^https?:\/\//,"").replace(/\/$/,"")}`,title:"Company favicon"}:null}i(KUe,"getCompanyAvatar");async function YUe(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(YUe,"fetchWithTimeout");const QUe=["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 XUe(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(XUe,"hash");async function ZUe(e){return`https://www.gravatar.com/avatar/${await XUe(e)}?d=404`}i(ZUe,"getGravatarUrl");async function JUe(e){if(QUe.includes(e))return null;try{const t=`https://${e}/favicon.ico`;if((await YUe(t)).ok)return t}catch{return null}return null}i(JUe,"getFaviconUrl");async function eze(e){if(!e.email_jsonb||!e.email_jsonb.length)return null;for(const{email:t}of e.email_jsonb){const n=await ZUe(t);try{if((await fetch(n)).ok)return n}catch{}const r=t.split("@")[1],a=await JUe(r);if(a)return a}return null}i(eze,"getContactAvatar");const DW=_d()||{url:"https://placeholder.supabase.co",anonKey:"placeholder-key"},ko=IAe({instanceUrl:DW.url,apiKey:DW.anonKey,supabaseClient:Ln,sortOrder:"asc,desc.nullslast"}),MW=i(async e=>{let t=e.data.logo;return typeof t!="object"||t===null||!t.src?t=await KUe(e.data):t.rawFile instanceof File&&await Vb(t),{...e,data:{...e.data,logo:t}}},"processCompanyLogo");async function IW(e){const{data:t}=e;if(t.avatar?.src||!t.email_jsonb||!t.email_jsonb.length)return e;const n=await eze(t),r={...t,avatar:{src:n||void 0}};return{...e,data:r}}i(IW,"processContactAvatar");const tze={...ko,async getList(e,t){return e==="companies"?ko.getList("companies_summary",t):e==="contacts"?ko.getList("contacts_summary",t):ko.getList(e,t)},async getOne(e,t){return e==="companies"?ko.getOne("companies_summary",t):e==="contacts"?ko.getOne("contacts_summary",t):ko.getOne(e,t)},async signUp({email:e,password:t,first_name:n,last_name:r}){const{data:a,error:o}=await Ln.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 Xs._is_initialized_cache=!0,{id:a.data.id,email:e,password:t}},async salesCreate(e){const{data:t,error:n}=await Ln.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 Ln.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 Ln.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 Ln.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 Ln.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 ko.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=>ko.update("deals",{id:r.id,data:r,previousData:t.find(a=>a.id===r.id)})))},async getActivityLog(e){return BUe(ko,e)},async isInitialized(){return Xs()},async mergeContacts(e,t){const{data:n,error:r}=await Ln.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},async mergeCompanies(e,t){const{data:n,error:r}=await Ln.functions.invoke("mergeCompanies",{method:"POST",body:{loserId:e,winnerId:t}});if(r)throw console.error("mergeCompanies.error",r),new Error("Failed to merge companies");return n}},nze=Dhe(tze,[{resource:"contactNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await Vb(r);return e},"beforeSave")},{resource:"dealNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await Vb(r);return e},"beforeSave")},{resource:"sales",beforeSave:i(async(e,t,n)=>(e.avatar&&await Vb(e.avatar),e),"beforeSave")},{resource:"contacts",beforeCreate:i(async e=>IW(e),"beforeCreate"),beforeUpdate:i(async e=>IW(e),"beforeUpdate"),beforeGetList:i(async e=>Ab(["first_name","last_name","company_name","title","email","phone","background"])(e),"beforeGetList")},{resource:"companies",beforeGetList:i(async e=>Ab(["name","phone_number","website","zipcode","city","stateAbbr"])(e),"beforeGetList"),beforeCreate:i(async e=>{const t=await MW(e);return{...t,data:{...t.data,created_at:new Date().toISOString()}}},"beforeCreate"),beforeUpdate:i(async e=>await MW(e),"beforeUpdate")},{resource:"contacts_summary",beforeGetList:i(async e=>Ab(["first_name","last_name"])(e),"beforeGetList")},{resource:"deals",beforeGetList:i(async e=>Ab(["name","type","description"])(e),"beforeGetList")}]),Ab=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"),Vb=i(async e=>{if(!e.src.startsWith("blob:")&&!e.src.startsWith("data:")&&e.path){const{error:c}=await Ln.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 Ln.storage.from("attachments").upload(o,t);if(s)throw console.error("uploadError",s),new Error("Failed to upload attachment");const{data:l}=Ln.storage.from("attachments").getPublicUrl(o);e.path=o,e.src=l.publicUrl;const f=n.type;return e.type=f,e},"uploadToBucket");function bie(){const{identity:e}=er(),t=qt();return d.jsxs("div",{className:"space-y-4 w-full",children:[d.jsx(Bt,{source:"first_name",validate:Zn(),helperText:!1}),d.jsx(Bt,{source:"last_name",validate:Zn(),helperText:!1}),d.jsx(Bt,{source:"email",validate:[Zn(),pY()],helperText:!1}),d.jsx(PP,{source:"administrator",readOnly:t?.id===e?.id,helperText:!1}),d.jsx(PP,{source:"disabled",readOnly:t?.id===e?.id,helperText:!1})]})}i(bie,"SalesInputs");function rze(){const e=xn(),t=Vt(),n=go(),{mutate:r}=Lr({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(ts,{children:d.jsx(ns,{children:"Create a new user"})}),d.jsx(Wn,{children:d.jsx(Nee,{onSubmit:a,children:d.jsx(bie,{})})})]})})}i(rze,"SalesCreate");function aze(){return d.jsxs("div",{className:"flex justify-end gap-4",children:[d.jsx(G1,{}),d.jsx(xd,{})]})}i(aze,"EditToolbar");function ize(){const{record:e}=qK(),t=xn(),n=Vt(),r=go(),{mutate:a}=Lr({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(Nee,{toolbar:d.jsx(aze,{}),onSubmit:o,record:e,children:[d.jsx(oze,{}),d.jsx(bie,{})]})})})})}i(ize,"SalesEdit");const oze=i(()=>{const e=qt();return e?d.jsxs("h2",{className:"text-lg font-semibold mb-4",children:["Edit ",e?.first_name," ",e?.last_name]}):null},"SaleEditTitle"),sze=i(()=>d.jsxs(P4,{children:[d.jsx(q1,{}),d.jsx(Ic,{label:"New user"})]}),"SalesListActions"),lze=[d.jsx(D4,{source:"q",alwaysOn:!0})],cze=i(e=>{const t=qt();return t?d.jsxs("div",{className:"flex flex-row gap-1",children:[t.administrator&&d.jsx(Jn,{variant:"outline",className:"border-blue-300 dark:border-blue-700",children:"Admin"}),t.disabled&&d.jsx(Jn,{variant:"outline",className:"border-orange-300 dark:border-orange-700",children:"Disabled"})]}):null},"OptionsField"),uze=i(()=>{const e=qt(),t=xn(),n=Vt(),r=Fw(),[a,o]=y.useState(!1),[s,l]=y.useState(!1),{mutate:f,isPending:c}=Lr({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}=Lr({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 v=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:v,isDisabled:b,inviteDialogOpen:a,resetDialogOpen:s}),d.jsxs(d.Fragment,{children:[d.jsxs(Dc,{children:[d.jsx(tl,{asChild:!0,children:d.jsxs(Le,{variant:"ghost",className:"h-8 w-8 p-0",children:[d.jsx("span",{className:"sr-only",children:"Open menu"}),d.jsx(FM,{className:"h-4 w-4"})]})}),d.jsxs(Mc,{align:"end",children:[d.jsx(g4,{children:"Email Actions"}),d.jsx(lv,{}),!v&&d.jsxs(cr,{onClick:i(w=>{w.preventDefault(),w.stopPropagation(),console.log("[Menu] Clicked Resend Invite"),o(!0)},"onClick"),children:[d.jsx(H1e,{className:"mr-2 h-4 w-4"}),"Resend Invite"]}),v&&!b&&d.jsxs(cr,{onClick:i(()=>l(!0),"onClick"),children:[d.jsx(d1e,{className:"mr-2 h-4 w-4"}),"Send Password Reset"]})]})]}),d.jsx(fa,{open:a,onOpenChange:o,children:d.jsxs(ha,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:"Resend Invitation"}),d.jsxs(si,{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(uo,{children:[d.jsx(Le,{variant:"outline",onClick:i(w=>{w.stopPropagation(),o(!1)},"onClick"),disabled:c,children:"Cancel"}),d.jsx(Le,{onClick:i(w=>{w.stopPropagation(),f()},"onClick"),disabled:c,children:c?"Sending...":"Send Invitation"})]})]})}),d.jsx(fa,{open:s,onOpenChange:l,children:d.jsxs(ha,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:"Send Password Reset"}),d.jsxs(si,{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(uo,{children:[d.jsx(Le,{variant:"outline",onClick:i(w=>{w.stopPropagation(),l(!1)},"onClick"),disabled:m,children:"Cancel"}),d.jsx(Le,{onClick:i(w=>{w.stopPropagation(),p()},"onClick"),disabled:m,children:m?"Sending...":"Send Reset Link"})]})]})})]})},"RowActions");function dze(){return d.jsx(A4,{filters:lze,actions:d.jsx(sze,{}),sort:{field:"first_name",order:"ASC"},children:d.jsx(fze,{})})}i(dze,"SalesList");const fze=i(()=>{const{data:e,isPending:t,filterValues:n}=Gn(),{identity:r}=er(),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(ln,{className:"h-12 w-full"}),d.jsx(ln,{className:"h-12 w-full"}),d.jsx(ln,{className:"h-12 w-full"}),d.jsx(ln,{className:"h-12 w-full"}),d.jsx(ln,{className:"h-12 w-full"})]})}):!e?.length&&!a?d.jsx(hze,{}):d.jsxs(zs,{children:[d.jsx(zs.Col,{source:"first_name"}),d.jsx(zs.Col,{source:"last_name"}),d.jsx(zs.Col,{source:"email"}),d.jsx(zs.Col,{label:!1,children:d.jsx(cze,{})}),d.jsx(zs.Col,{label:!1,children:d.jsx(uze,{})})]})},"SalesListLayout"),hze=i(()=>{const e=V1();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(Ic,{label:"New user"})})]})},"SalesEmpty"),pze={list:dze,create:rze,edit:ize,recordRepresentation:i(e=>`${e.first_name} ${e.last_name}`,"recordRepresentation")};function FW(e){const t=e.trim();return t?t.startsWith("http://")||t.startsWith("https://")?t:`https://${t}.supabase.co`:""}i(FW,"normalizeSupabaseUrl");function mze(e){const t=e.trim();if(!t)return{valid:!1};if(t.startsWith("http://")||t.startsWith("https://"))try{return new URL(t).hostname.endsWith(".supabase.co")?{valid:!0,message:"Valid Supabase URL"}:{valid:!1,message:"URL must be a Supabase domain"}}catch{return{valid:!1,message:"Invalid URL format"}}return/^[a-z0-9]+$/.test(t)?{valid:!0,message:"Valid project ID (will expand to full URL)"}:{valid:!1,message:"Enter full URL or project ID"}}i(mze,"validateUrlFormat");function gze(e){const t=e.trim();return t?t.startsWith("sb_publishable_")?t.length>35?{valid:!0,message:"Valid publishable key format"}:{valid:!1,message:"Publishable key seems incomplete"}:t.startsWith("eyJ")?t.length>100?{valid:!0,message:"Valid anon key format"}:{valid:!1,message:"Anon key seems incomplete"}:{valid:!1,message:"Must be a valid Supabase API key (anon or publishable)"}:{valid:!1}}i(gze,"validateKeyFormat");function xie({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,v]=y.useState(!1),[b,w]=y.useState(!1),S=i(async()=>{p(null),a("validating");const T=FW(o),R=l.trim(),A=await pAe(T,R);A.valid?(dAe({url:T,anonKey:R}),a("success"),setTimeout(()=>{window.location.href=window.location.origin},1500)):(p(A.error||"Connection failed"),a("credentials"))},"handleValidateAndSave"),_=o?mze(o):{valid:!1},j=l?gze(l):{valid:!1},C=o?FW(o):"",O=o&&!o.startsWith("http")&&_.valid,E=i(()=>{n&&t()},"handleClose");return d.jsx(fa,{open:e,onOpenChange:n?E:void 0,children:d.jsxs(ha,{className:"sm:max-w-md",onPointerDownOutside:i(T=>!n&&T.preventDefault(),"onPointerDownOutside"),onEscapeKeyDown:i(T=>!n&&T.preventDefault(),"onEscapeKeyDown"),children:[r==="welcome"&&d.jsxs(d.Fragment,{children:[d.jsxs(Mr,{children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d.jsx(nv,{className:"h-6 w-6 text-primary"}),d.jsx(Ir,{children:"Welcome to CRM"})]}),d.jsx(si,{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(Va,{children:d.jsxs(li,{children:[d.jsx("strong",{children:"Don't have a Supabase project?"}),d.jsx("br",{}),"Create one for free at"," ",d.jsxs("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline text-primary inline-flex items-center gap-1",children:["supabase.com",d.jsx(Hl,{className:"h-3 w-3"})]})]})}),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 or project ID"}),d.jsx("li",{children:"Your API key (anon or publishable key)"})]})]}),d.jsx("div",{className:"space-y-2",children:d.jsxs("a",{href:"https://supabase.com/docs/guides/api#api-url-and-keys",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline inline-flex items-center gap-1",children:["Where do I find these?",d.jsx(Hl,{className:"h-3 w-3"})]})}),d.jsx(Le,{onClick:i(()=>a("credentials"),"onClick"),className:"w-full",children:"Continue"})]})]}),r==="credentials"&&d.jsxs(d.Fragment,{children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:"Connect to Supabase"}),d.jsx(si,{children:"Enter your Supabase project credentials"})]}),d.jsxs("div",{className:"space-y-4 py-4",children:[c&&d.jsxs(Va,{variant:"destructive",children:[d.jsx(Dp,{className:"h-4 w-4"}),d.jsx(li,{children:c})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Vn,{htmlFor:"supabase-url",children:"Project URL or ID"}),d.jsxs("div",{className:"relative",children:[d.jsx(Cr,{id:"supabase-url",placeholder:"xxxxx or https://xxxxx.supabase.co",value:o,onChange:i(T=>{s(T.target.value),v(!0)},"onChange"),onBlur:i(()=>v(!0),"onBlur"),className:m&&o?_.valid?"pr-8 border-green-500":"pr-8 border-destructive":""}),m&&o&&_.valid&&d.jsx(no,{className:"absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 text-green-500"})]}),O&&d.jsxs("div",{className:"flex items-start gap-1.5 text-xs text-green-600 dark:text-green-400",children:[d.jsx(no,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),d.jsxs("span",{children:["Will expand to: ",C]})]}),m&&o&&_.message&&!_.valid&&d.jsx("p",{className:"text-xs text-destructive",children:_.message}),(!m||!o)&&d.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter full URL or just the project ID (from Project Settings → API)"})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Vn,{htmlFor:"anon-key",children:"API Key"}),d.jsxs("div",{className:"relative",children:[d.jsx(Cr,{id:"anon-key",type:"password",placeholder:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",value:l,onChange:i(T=>{f(T.target.value),w(!0)},"onChange"),onBlur:i(()=>w(!0),"onBlur"),className:b&&l?j.valid?"pr-8 border-green-500":"pr-8 border-destructive":""}),b&&l&&j.valid&&d.jsx(no,{className:"absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 text-green-500"})]}),b&&l&&j.message&&d.jsx("p",{className:`text-xs ${j.valid?"text-green-600 dark:text-green-400":"text-destructive"}`,children:j.message}),(!b||!l)&&d.jsx("p",{className:"text-xs text-muted-foreground",children:"Anon or publishable key (from Project Settings → API)"})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Le,{variant:"outline",onClick:i(()=>a("welcome"),"onClick"),className:"flex-1",children:"Back"}),d.jsx(Le,{onClick:S,disabled:!_.valid||!j.valid,className:"flex-1",children:"Connect"})]})]})]}),r==="validating"&&d.jsxs(d.Fragment,{children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:"Validating Connection"}),d.jsx(si,{children:"Testing your Supabase credentials..."})]}),d.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[d.jsx(Tc,{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(Mr,{children:[d.jsx(Ir,{children:"Connection Successful!"}),d.jsx(si,{children:"Your Supabase database is now connected"})]}),d.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[d.jsx(Bo,{className:"h-12 w-12 text-green-500 mb-4"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Reloading application..."})]})]})]})})}i(xie,"SupabaseSetupWizard");function vze(){const[e,t]=y.useState(!1),n=_d(),r=mAe(),a=i(()=>{confirm("Are you sure you want to clear the database configuration? The app will need to be reconfigured on next launch.")&&(fAe(),window.location.reload())},"handleClearConfig");return d.jsxs(d.Fragment,{children:[d.jsxs(pn,{children:[d.jsxs(ts,{children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(nv,{className:"h-5 w-5"}),d.jsx(ns,{children:"Database Connection"})]}),d.jsx(N4,{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(Bo,{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(Va,{children:[d.jsx(yN,{className:"h-4 w-4"}),d.jsx(li,{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(Le,{variant:"outline",onClick:i(()=>t(!0),"onClick"),className:"flex-1",children:[d.jsx(yN,{className:"h-4 w-4 mr-2"}),"Change Connection"]}),r==="ui"&&d.jsxs(Le,{variant:"destructive",onClick:a,className:"flex-1",children:[d.jsx(py,{className:"h-4 w-4 mr-2"}),"Clear Configuration"]})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(yze,{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(ls,{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(Va,{children:d.jsxs(li,{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(Le,{onClick:i(()=>t(!0),"onClick"),className:"w-full",children:[d.jsx(nv,{className:"h-4 w-4 mr-2"}),"Connect to Supabase"]})]})})]}),d.jsx(xie,{open:e,onComplete:i(()=>t(!1),"onComplete"),canClose:!0})]})}i(vze,"DatabaseSettings");function yze({children:e,className:t}){return d.jsx("label",{className:t,children:e})}i(yze,"Label");const fD=i(()=>d.jsx("div",{className:"max-w-lg mx-auto mt-8",children:d.jsx(vze,{})}),"DatabasePage");fD.path="/database";const hD=i(()=>{const[e,t]=y.useState(!1),{identity:n,refetch:r}=er(),{data:a,refetch:o}=Lw("sales",{id:n?.id}),s=Vt(),l=xn(),{mutate:f}=Lr({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(Zr,{onSubmit:c,record:a,children:d.jsx(bze,{isEditMode:e,setEditMode:t})})})},"SettingsPage"),bze=i(({isEditMode:e,setEditMode:t})=>{const n=Vt(),r=Ea(),a=qt(),{identity:o,refetch:s}=er(),{isDirty:l}=cy(),f=xn(),{mutate:c}=Lr({mutationKey:["signup"],mutationFn:i(async v=>{if(!a)throw new Error("Record not found");return f.salesUpdate(a.id,v)},"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 v=>{c(v)},"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(jte,{source:"avatar",type:"avatar",onSave:m,linkPosition:"right"}),d.jsx(_T,{source:"first_name",isEditMode:e}),d.jsx(_T,{source:"last_name",isEditMode:e}),d.jsx(_T,{source:"email",isEditMode:e})]}),d.jsxs("div",{className:"flex flex-row justify-end gap-2",children:[!e&&d.jsx(d.Fragment,{children:d.jsx(Le,{variant:"outline",type:"button",onClick:p,children:"Change password"})}),d.jsxs(Le,{type:"button",variant:e?"ghost":"outline",onClick:i(()=>t(!e),"onClick"),className:"flex items-center",children:[e?d.jsx(ls,{}):d.jsx(qQ,{}),e?"Cancel":"Edit"]}),e&&d.jsxs(Le,{type:"submit",disabled:!l,variant:"outline",children:[d.jsx(f1,{}),"Save"]})]})]})}),void 0]})},"SettingsForm"),_T=i(({source:e,isEditMode:t})=>t?d.jsx(Bt,{source:e,helperText:!1}):d.jsx("div",{className:"m-2",children:d.jsx(K5e,{source:e})}),"TextRender");hD.path="/settings";function wie(){const e=new Uint8Array(16);return crypto.getRandomValues(e),`ak_live_${Array.from(e).map(n=>n.toString(16).padStart(2,"0")).join("")}`}i(wie,"generateApiKey");async function xze(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(xze,"hashApiKey");const wze=[{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"}],_ze=i(({open:e,onClose:t})=>{const[n,r]=y.useState(null),[a,o]=y.useState(!1),s=xn(),l=Vt(),f=Nn(),{identity:c}=er(),{register:p,handleSubmit:m,watch:v,setValue:b,reset:w}=uy({defaultValues:{name:"",scopes:[],expires_at:""}}),S=Lr({mutationFn:i(async O=>{const E=wie(),T=await xze(E),R=E.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:E}},"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"),C=i(O=>{const E=v("scopes");E.includes(O)?b("scopes",E.filter(T=>T!==O)):b("scopes",[...E,O])},"toggleScope");return d.jsx(fa,{open:e,onOpenChange:_,children:d.jsxs(ha,{className:"sm:max-w-[500px]",children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:n?"API Key Created":"Create API Key"}),d.jsx(si,{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(Va,{children:d.jsx(li,{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(Vn,{children:"Your API Key"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Cr,{value:n,readOnly:!0,className:"font-mono text-sm"}),d.jsx(Le,{type:"button",variant:"outline",size:"icon",onClick:j,children:a?d.jsx(Bo,{className:"h-4 w-4 text-green-500"}):d.jsx(MM,{className:"h-4 w-4"})})]})]}),d.jsx("div",{className:"flex justify-end",children:d.jsx(Le,{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(Vn,{htmlFor:"name",children:"Name"}),d.jsx(Cr,{id:"name",placeholder:"e.g., Production API Key",...p("name",{required:!0})})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Vn,{children:"Scopes"}),d.jsx("div",{className:"space-y-2",children:wze.map(O=>d.jsxs("div",{className:"flex items-center space-x-2",children:[d.jsx(Gp,{id:O.value,checked:v("scopes").includes(O.value),onCheckedChange:i(()=>C(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(Vn,{htmlFor:"expires_at",children:"Expiration (optional)"}),d.jsx(Cr,{id:"expires_at",type:"date",...p("expires_at")})]}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(Le,{type:"button",variant:"outline",onClick:_,children:"Cancel"}),d.jsx(Le,{type:"submit",disabled:S.isPending,children:"Create"})]})]})})]})})},"CreateApiKeyDialog");var Sze=Symbol("radix.slottable");function jze(e){const t=i(({children:n})=>d.jsx(d.Fragment,{children:n}),"Slottable2");return t.displayName=`${e}.Slottable`,t.__radixId=Sze,t}i(jze,"createSlottable");var _ie="AlertDialog",[Cze,DBe]=ia(_ie,[oX]),dl=oX(),Sie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=dl(t);return d.jsx(vy,{...r,...n,modal:!0})},"AlertDialog$1");Sie.displayName=_ie;var Eze="AlertDialogTrigger",Oze=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(_X,{...a,...r,ref:t})});Oze.displayName=Eze;var kze="AlertDialogPortal",jie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=dl(t);return d.jsx(yy,{...r,...n})},"AlertDialogPortal$1");jie.displayName=kze;var Rze="AlertDialogOverlay",Cie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(by,{...a,...r,ref:t})});Cie.displayName=Rze;var hh="AlertDialogContent",[Aze,Tze]=Cze(hh),Nze=jze("AlertDialogContent"),Eie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,children:r,...a}=e,o=dl(n),s=y.useRef(null),l=Xt(t,s),f=y.useRef(null);return d.jsx(sje,{contentName:hh,titleName:Oie,docsSlug:"alert-dialog",children:d.jsx(Aze,{scope:n,cancelRef:f,children:d.jsxs(xy,{role:"alertdialog",...o,...a,ref:l,onOpenAutoFocus:Je(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(Nze,{children:r}),d.jsx(Dze,{contentRef:s})]})})})});Eie.displayName=hh;var Oie="AlertDialogTitle",kie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(v1,{...a,...r,ref:t})});kie.displayName=Oie;var Rie="AlertDialogDescription",Aie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(y1,{...a,...r,ref:t})});Aie.displayName=Rie;var Pze="AlertDialogAction",Tie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(wy,{...a,...r,ref:t})});Tie.displayName=Pze;var Nie="AlertDialogCancel",Pie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,{cancelRef:a}=Tze(Nie,n),o=dl(n),s=Xt(t,a);return d.jsx(wy,{...o,...r,ref:s})});Pie.displayName=Nie;var Dze=i(({contentRef:e})=>{const t=`\`${hh}\` 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 dc(){return dc=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},dc.apply(null,arguments)}i(dc,"b");var Ri={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},V3=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}:dc({},Tqe,a),c=f.left+f.right,p=f.top+f.bottom,m=s+c,v=l+p,b=(o-1)*r;return n==="row"?m=s*o+b+c:n==="column"&&(v=l*o+b+p),{width:m,height:v,padding:f}},"A"),sie=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"),lie=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,v=e.height;switch(l){case"left-to-right":t=0,n=(v-c)/2,a=v/2,s="central",f?(r=m,o="end"):(r=c+p,o="start");break;case"right-to-left":t=m-c,n=(v-c)/2,a=v/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=v,s="alphabetic"):(a=c+p,s="text-before-edge");break;case"bottom-to-top":t=(m-c)/2,n=v-c,r=m/2,o="middle",f?(a=0,s="text-before-edge"):(a=v-c-p,s="alphabetic")}return{symbolX:t,symbolY:n,labelX:r,labelY:a,labelAnchor:o,labelAlignment:s}},"z"),Nqe={circle:Oqe,diamond:kqe,square:Rqe,triangle:Aqe},Pqe=i(function(e){var t,n,r,a,o,s,l,f,c,p,m,v=e.x,b=e.y,w=e.width,S=e.height,_=e.data,j=e.direction,C=j===void 0?Ri.itemDirection:j,O=e.justify,E=O===void 0?Ri.justify:O,T=e.textColor,R=e.background,A=R===void 0?"transparent":R,N=e.opacity,D=N===void 0?1:N,M=e.symbolShape,I=M===void 0?Ri.symbolShape:M,F=e.symbolSize,L=F===void 0?Ri.symbolSize:F,q=e.symbolSpacing,z=q===void 0?Ri.symbolSpacing:q,$=e.symbolBorderWidth,H=$===void 0?0:$,U=e.symbolBorderColor,W=U===void 0?"transparent":U,V=e.onClick,Q=e.onMouseEnter,Y=e.onMouseLeave,K=e.toggleSerie,ee=e.effects,te=y.useState({}),oe=te[0],ne=te[1],fe=qr(),re=y.useCallback((function(X){if(ee){var se=ee.filter((function(me){return me.on==="hover"})).reduce((function(me,Te){return dc({},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 dc({},me,Te.style)}),{});ne(se)}Y?.(_,X)}),[Y,_,ee]),he=lie({direction:C,justify:E,symbolSize:(t=oe.symbolSize)!=null?t:L,symbolSpacing:z,width:w,height:S}),J=he.symbolX,Me=he.symbolY,we=he.labelX,Ce=he.labelY,Re=he.labelAnchor,ke=he.labelAlignment,Ne=[V,Q,Y,K].some((function(X){return X!==void 0})),ze=typeof I=="function"?I:Nqe[I];return d.jsxs("g",{transform:"translate("+v+","+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:Ne?"pointer":"auto"},onClick:i(function(X){V?.(_,X),K?.(_.id)},"onClick"),onMouseEnter:re,onMouseLeave:ce}),y.createElement(ze,dc({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:H,borderColor:(f=oe.symbolBorderColor)!=null?f:W},_.hidden?fe.legends.hidden.symbol:void 0)),d.jsx(Z_,{textAnchor:Re,style:dc({},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:Ce,children:_.label})]})},"B"),Dqe=i(function(e){var t=e.data,n=e.x,r=e.y,a=e.direction,o=e.padding,s=o===void 0?Ri.padding:o,l=e.justify,f=e.effects,c=e.itemWidth,p=e.itemHeight,m=e.itemDirection,v=m===void 0?Ri.itemDirection:m,b=e.itemsSpacing,w=b===void 0?Ri.itemsSpacing:b,S=e.itemTextColor,_=e.itemBackground,j=_===void 0?"transparent":_,C=e.itemOpacity,O=C===void 0?1:C,E=e.symbolShape,T=e.symbolSize,R=e.symbolSpacing,A=e.symbolBorderWidth,N=e.symbolBorderColor,D=e.onClick,M=e.onMouseEnter,I=e.onMouseLeave,F=e.toggleSerie,L=V3({itemCount:t.length,itemWidth:c,itemHeight:p,itemsSpacing:w,direction:a,padding:s}).padding,q=a==="row"?c+w:0,z=a==="column"?p+w:0;return d.jsx("g",{transform:"translate("+n+","+r+")",children:t.map((function($,H){return d.jsx(Pqe,{data:$,x:H*q+L.left,y:H*z+L.top,width:c,height:p,direction:v,justify:l,effects:f,textColor:S,background:j,opacity:O,symbolShape:E,symbolSize:T,symbolSpacing:R,symbolBorderWidth:A,symbolBorderColor:N,onClick:D,onMouseEnter:M,onMouseLeave:I,toggleSerie:F},H)}))})},"H"),Mqe=i(function(e){var t=e.data,n=e.containerWidth,r=e.containerHeight,a=e.translateX,o=a===void 0?Ri.translateX:a,s=e.translateY,l=s===void 0?Ri.translateY:s,f=e.anchor,c=e.direction,p=e.padding,m=p===void 0?Ri.padding:p,v=e.justify,b=e.itemsSpacing,w=b===void 0?Ri.itemsSpacing:b,S=e.itemWidth,_=e.itemHeight,j=e.itemDirection,C=e.itemTextColor,O=e.itemBackground,E=e.itemOpacity,T=e.symbolShape,R=e.symbolSize,A=e.symbolSpacing,N=e.symbolBorderWidth,D=e.symbolBorderColor,M=e.onClick,I=e.onMouseEnter,F=e.onMouseLeave,L=e.toggleSerie,q=e.effects,z=V3({itemCount:t.length,itemsSpacing:w,itemWidth:S,itemHeight:_,direction:c,padding:m}),$=z.width,H=z.height,U=sie({anchor:f,translateX:o,translateY:l,containerWidth:n,containerHeight:r,width:$,height:H}),W=U.x,V=U.y;return d.jsx(Dqe,{data:t,x:W,y:V,direction:c,padding:m,justify:v,effects:q,itemsSpacing:w,itemWidth:S,itemHeight:_,itemDirection:j,itemTextColor:C,itemBackground:O,itemOpacity:E,symbolShape:T,symbolSize:R,symbolSpacing:A,symbolBorderWidth:N,symbolBorderColor:D,onClick:M,onMouseEnter:I,onMouseLeave:F,toggleSerie:typeof L=="boolean"?void 0:L})},"E"),Iqe={start:"left",middle:"center",end:"right"},Fqe=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,v=m===void 0?0:m,b=t.justify,w=b!==void 0&&b,S=t.itemsSpacing,_=S===void 0?0:S,j=t.itemWidth,C=t.itemHeight,O=t.itemDirection,E=O===void 0?"left-to-right":O,T=t.itemTextColor,R=t.symbolSize,A=R===void 0?16:R,N=t.symbolSpacing,D=N===void 0?8:N,M=t.theme,I=V3({itemCount:n.length,itemWidth:j,itemHeight:C,itemsSpacing:_,direction:p,padding:v}),F=I.width,L=I.height,q=I.padding,z=sie({anchor:c,translateX:s,translateY:f,containerWidth:r,containerHeight:a,width:F,height:L}),$=z.x,H=z.y,U=p==="row"?j+_:0,W=p==="column"?C+_:0;e.save(),e.translate($,H),Uv(e,M.legends.text),n.forEach((function(V,Q){var Y,K=Q*U+q.left,ee=Q*W+q.top,te=lie({direction:E,justify:w,symbolSize:A,symbolSpacing:D,width:j,height:C}),oe=te.symbolX,ne=te.symbolY,fe=te.labelX,re=te.labelY,ce=te.labelAnchor,he=te.labelAlignment;e.fillStyle=(Y=V.color)!=null?Y:"black",e.fillRect(K+oe,ee+ne,A,A),e.textAlign=Iqe[ce],he==="central"&&(e.textBaseline="middle"),zv(e,dc({},M.legends.text,{fill:T??M.legends.text.fill}),String(V.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 gn(){return gn=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},gn.apply(null,arguments)}i(gn,"Q");function zc(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(zc,"U");var OW,$qe=i(function(e){var t=e.bars,n=e.annotations,r=rie({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(uqe,gn({},a),o)}))})},"$"),qqe=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(Mqe,gn({},f,{containerWidth:t,containerHeight:n,data:(l=f.data)!=null?l:c,toggleSerie:f.toggleSerie&&f.dataFrom==="keys"?a:void 0}),s)}))})},"ee"),Uqe=["data"],zqe=i(function(e){var t,n=e.bar,r=n.data,a=zc(n,Uqe),o=e.style,s=o.borderColor,l=o.color,f=o.height,c=o.labelColor,p=o.labelOpacity,m=o.labelX,v=o.labelY,b=o.transform,w=o.width,S=o.textAnchor,_=e.borderRadius,j=e.borderWidth,C=e.label,O=e.shouldRenderLabel,E=e.isInteractive,T=e.onClick,R=e.onMouseEnter,A=e.onMouseLeave,N=e.tooltip,D=e.isFocusable,M=e.ariaLabel,I=e.ariaLabelledBy,F=e.ariaDescribedBy,L=e.ariaDisabled,q=e.ariaHidden,z=qr(),$=Ire(),H=$.showTooltipFromEvent,U=$.showTooltipAt,W=$.hideTooltip,V=y.useMemo((function(){return function(){return y.createElement(N,gn({},a,r))}}),[N,a,r]),Q=y.useCallback((function(ne){T?.(gn({color:a.color},r),ne)}),[a,r,T]),Y=y.useCallback((function(ne){return H(V(),ne)}),[H,V]),K=y.useCallback((function(ne){R?.(r,ne),H(V(),ne)}),[r,R,H,V]),ee=y.useCallback((function(ne){A?.(r,ne),W()}),[r,W,A]),te=y.useCallback((function(){U(V(),[a.absX+a.width/2,a.absY])}),[U,V,a]),oe=y.useCallback((function(){W()}),[W]);return d.jsxs(gr.g,{transform:b,children:[d.jsx(gr.rect,{width:YP(w,(function(ne){return Math.max(ne,0)})),height:YP(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:E?K:void 0,onMouseMove:E?Y:void 0,onMouseLeave:E?ee:void 0,onClick:E?Q:void 0,onFocus:E&&D?te:void 0,onBlur:E&&D?oe:void 0,"data-testid":"bar.item."+r.id+"."+r.index}),O&&d.jsx(Z_,{x:m,y:v,textAnchor:S,dominantBaseline:"central",fillOpacity:p,style:gn({},z.labels.text,{pointerEvents:"none",fill:c}),children:C})]})},"ae"),Bqe=["color","label"],Hqe=i(function(e){var t=e.color,n=e.label,r=zc(e,Bqe);return d.jsx(uIe,{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:Hqe,tooltipLabel:i(function(e){return e.id+" - "+e.indexValue},"tooltipLabel"),legends:[],initialHiddenIds:[],annotations:[],enableTotals:!1,totalsOffset:10},In=gn({},Fn,{layers:["grid","axes","bars","totals","markers","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},barComponent:zqe,defs:[],fill:[],markers:[],animate:!0,animateOnMount:!1,motionConfig:"default",role:"img",isFocusable:!1}),br=gn({},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,v=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(),v&&(e.textBaseline="middle",e.textAlign=_==="middle"?"center":_,zv(e,b,m,s+w,l+S))},"renderBar"),pixelRatio:typeof window<"u"&&(OW=window.devicePixelRatio)!=null?OW:1}),cie=i(function(e,t,n,r,a,o){return H3(r,{all:e.map(t),min:0,max:0},a,o).padding(n)},"de"),uie=i(function(e,t){return e.map((function(n){return gn({},t.reduce((function(r,a){return r[a]=null,r}),{}),n)}))},"ue"),J_=i(function(e){return Object.keys(e).reduce((function(t,n){return e[n]&&(t[n]=e[n]),t}),{})},"se"),eS=i(function(e){return[e,Number(e)]},"ce");function die(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(die,"he");var Vqe=["layout","width","height","padding","innerPadding","valueScale","indexScale","hiddenIds"],W3=i(function(e,t){return e>t},"be"),fie=i(function(e,t){return e<t},"ge"),hie=i(function(e,t){return Array.from(" ".repeat(t-e),(function(n,r){return e+r}))},"ve"),Wqe=i(function(e){return W3(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,v=e.xScale,b=e.yScale,w=e.margin,S=n?fie:W3,_=a.map(J_),j=[];return m.forEach((function(C,O){return hie(0,v.domain().length).forEach((function(E){var T,R,A,N=eS(a[E][C]),D=N[0],M=N[1],I=l(a[E]),F=((T=v(I))!=null?T:0)+t*O+p*O,L=S(R=M,0)?(A=b(R))!=null?A:0:r,q=(function($,H){var U;return S($,0)?r-H:((U=b($))!=null?U:0)-r})(M,L),z={id:C,value:D===null?D:M,formattedValue:o(M),hidden:!1,index:E,indexValue:I,data:_[E]};j.push({key:C+"."+z.indexValue,index:j.length,data:z,x:F,y:L,absX:w.left+F,absY:w.top+L,width:t,height:q,color:s(z),label:f(z)})}))})),j},"pe"),Kqe=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,v=e.xScale,b=e.yScale,w=e.margin,S=n?fie:W3,_=a.map(J_),j=[];return c.forEach((function(C,O){return hie(0,b.domain().length).forEach((function(E){var T,R,A,N=eS(a[E][C]),D=N[0],M=N[1],I=s(a[E]),F=S(R=M,0)?r:(A=v(R))!=null?A:0,L=((T=b(I))!=null?T:0)+t*O+m*O,q=(function($,H){var U;return S($,0)?((U=v($))!=null?U:0)-r:r-H})(M,F),z={id:C,value:D===null?D:M,formattedValue:o(M),hidden:!1,index:E,indexValue:I,data:_[E]};j.push({key:C+"."+z.indexValue,index:j.length,data:z,x:F,y:L,absX:w.left+F,absY:w.top+L,width:q,height:t,color:l(z),label:f(z)})}))})),j},"ye"),Yqe=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,v=e.indexScale,b=e.hiddenIds,w=b===void 0?[]:b,S=zc(e,Vqe),_=S.keys.filter((function(H){return!w.includes(H)})),j=uie(S.data,_),C=a==="vertical"?["y","x",o]:["x","y",s],O=C[0],E=C[1],T=C[2],R=cie(j,S.getIndex,f,v,T,E),A=m.min==="auto"?Wqe:function(H){return H},N=j.reduce((function(H,U){return[].concat(H,_.map((function(W){return U[W]})))}),[]).filter(Boolean),D=A(Math.min.apply(Math,N)),M=(r=Math.max.apply(Math,N),isFinite(r)?r:0),I=H3(m,{all:N,min:D,max:M},O==="x"?o:s,O),F=a==="vertical"?[R,I]:[I,R],L=F[0],q=F[1],z=(R.bandwidth()-p*(_.length-1))/_.length,$=[gn({},S,{data:j,keys:_,innerPadding:p,xScale:L,yScale:q}),z,(t=m.reverse)!=null&&t,(n=I(0))!=null?n:0];return{xScale:L,yScale:q,bars:z>0?a==="vertical"?Gqe.apply(void 0,$):Kqe.apply(void 0,$):[]}},"xe"),Qqe=["data","layout","width","height","padding","valueScale","indexScale","hiddenIds"],pie=i(function(e){var t;return e.some(Array.isArray)?pie((t=[]).concat.apply(t,e)):e},"ke"),Xqe=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,v=[];return f.forEach((function(b){return c.domain().forEach((function(w,S){var _,j,C=b[S],O=(_=c(o(C.data)))!=null?_:0,E=((j=(function(M){return p(M[n?0:1])})(C))!=null?j:0)+.5*l,T=(function(M,I){var F;return((F=p(M[n?1:0]))!=null?F:0)-I})(C,E)-l,R=eS(C.data[b.key]),A=R[0],N=R[1],D={id:b.key,value:A===null?A:N,formattedValue:r(N),hidden:!1,index:S,indexValue:w,data:J_(C.data)};v.push({key:b.key+"."+w,index:v.length,data:D,x:O,y:E,absX:m.left+O,absY:m.top+E,width:t,height:T,color:a(D),label:s(D)})}))})),v},"we"),Zqe=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,v=[];return f.forEach((function(b){return p.domain().forEach((function(w,S){var _,j,C=b[S],O=(_=p(o(C.data)))!=null?_:0,E=((j=(function(M){return c(M[n?1:0])})(C))!=null?j:0)+.5*l,T=(function(M,I){var F;return((F=c(M[n?0:1]))!=null?F:0)-I})(C,E)-l,R=eS(C.data[b.key]),A=R[0],N=R[1],D={id:b.key,value:A===null?A:N,formattedValue:r(N),hidden:!1,index:S,indexValue:w,data:J_(C.data)};v.push({key:b.key+"."+w,index:v.length,data:D,x:E,y:O,absX:m.left+E,absY:m.top+O,width:T,height:t,color:a(D),label:s(D)})}))})),v},"Le"),Jqe=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,v=m===void 0?[]:m,b=zc(e,Qqe),w=b.keys.filter((function(z){return!v.includes(z)})),S=SFe().keys(w).offset(jFe)(uie(r,w)),_=a==="vertical"?["y","x",o]:["x","y",s],j=_[0],C=_[1],O=_[2],E=cie(r,b.getIndex,f,p,O,C),T=(n=pie(S),c.type==="log"?n.filter((function(z){return z!==0})):n),R=Math.min.apply(Math,T),A=Math.max.apply(Math,T),N=H3(c,{all:T,min:R,max:A},j==="x"?o:s,j),D=a==="vertical"?[E,N]:[N,E],M=D[0],I=D[1],F=b.innerPadding>0?b.innerPadding:0,L=E.bandwidth(),q=[gn({},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"?Xqe.apply(void 0,q):Zqe.apply(void 0,q):[]}},"Ce"),eUe=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=Gae(s??(r==="indexes"?"indexValue":"id"));return r==="indexes"?(function(c,p,m){var v=eW(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"&&v.reverse(),v})(t,o,f):(function(c,p,m,v,b,w){var S=eW(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"&&v==="stacked"&&m==="column"&&b!==!0||p==="horizontal"&&v==="stacked"&&b===!0)&&S.reverse(),S})(t,o,n,a,l,f)},"We"),kW=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+n)},"Me"),tUe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+(n>0?n:0))},"Be"),nUe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,Math.max(r,Number(n)))},"Re"),rUe=i(function(e,t){var n=e.get(t)||0;e.set(t,n+1)},"Oe"),mie=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,v=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,C=j===void 0?Fn.labelTextColor:j,O=e.groupMode,E=O===void 0?Fn.groupMode:O,T=e.layout,R=T===void 0?Fn.layout:T,A=e.data,N=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,z=e.valueScale,$=z===void 0?Fn.valueScale:z,H=e.indexScale,U=H===void 0?Fn.indexScale:H,W=e.initialHiddenIds,V=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(V??[]),Me=J[0],we=J[1],Ce=y.useCallback((function(Ke){we((function(pt){return pt.indexOf(Ke)>-1?pt.filter((function(ve){return ve!==Ke})):[].concat(pt,[Ke])}))}),[]),Re=YA(r),ke=YA(l),Ne=YA(c),ze=B3(p),X=qr(),se=Eqe(v,w),me=EW(_,X),Te=EW(C,X),de=(E==="grouped"?Yqe:Jqe)({layout:R,data:A,getIndex:Re,keys:o,width:D,height:M,getColor:se,padding:F,innerPadding:q,valueScale:$,indexScale:U,hiddenIds:Me,formatValue:ze,getTooltipLabel:Ne,margin:N}),ue=de.bars,Ae=de.xScale,Pe=de.yScale,Fe=y.useMemo((function(){return ue.filter((function(Ke){return Ke.data.value!==null})).map((function(Ke,pt){return gn({},Ke,{index:pt})}))}),[ue]),et=y.useCallback((function(Ke){var pt=Ke.width,ve=Ke.height;return!!Y&&!(ee>0&&pt<ee)&&!(oe>0&&ve<oe)}),[Y,ee,oe]),Nt=y.useMemo((function(){return o.map((function(Ke){var pt=ue.find((function(ve){return ve.data.id===Ke}));return gn({},pt,{data:gn({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,eUe({bars:Ke.dataFrom==="keys"?Nt:ue,direction:Ke.direction,from:Ke.dataFrom,groupMode:E,layout:R,legendLabel:re,reverse:$t})]}))}),[fe,Nt,ue,E,R,re,$t]),Ut=y.useMemo((function(){return(function(Ke,pt,ve,ye,ct,$e,Xe){ye===void 0&&(ye=Fn.layout),ct===void 0&&(ct=Fn.groupMode);var We=[];if(Ke.length===0)return We;var tt=new Map,jt=Ke[0].width,Ye=Ke[0].height;if(ct==="stacked"){var gt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Et=_t.value;kW(tt,vt,Number(Et)),tUe(gt,vt,Number(Et))})),gt.forEach((function(At,_t){var vt,Et,Z,pe=tt.get(_t)||0;ye==="vertical"?(vt=pt(_t),Et=ve(At),Z=ve(At/2)):(vt=pt(At),Et=ve(_t),Z=pt(At/2)),vt+=ye==="vertical"?jt/2:$e,Et+=ye==="vertical"?-$e:Ye/2,We.push({key:"total_"+_t,x:vt,y:Et,value:pe,formattedValue:Xe(pe),animationOffset:Z})}))}else if(ct==="grouped"){var Ft=new Map,Pt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Et=_t.value;kW(tt,vt,Number(Et)),nUe(Ft,vt,Number(Et)),rUe(Pt,vt)})),Ft.forEach((function(At,_t){var vt,Et,Z,pe=tt.get(_t)||0,_e=Pt.get(_t);ye==="vertical"?(vt=pt(_t),Et=ve(At),Z=ve(At/2)):(vt=pt(At),Et=ve(_t),Z=pt(At/2)),vt+=ye==="vertical"?_e*jt/2:$e,Et+=ye==="vertical"?-$e:_e*Ye/2,We.push({key:"total_"+_t,x:vt,y:Et,value:pe,formattedValue:Xe(pe),animationOffset:Z})}))}return We})(ue,Ae,Pe,R,E,he,ze)}),[ue,Ae,Pe,R,E,he,ze]);return{bars:ue,barsWithValue:Fe,xScale:Ae,yScale:Pe,getIndex:Re,getLabel:ke,getTooltipLabel:Ne,formatValue:ze,getColor:se,getBorderColor:me,getLabelColor:Te,shouldRenderBarLabel:et,hiddenIds:Me,toggleSerie:Ce,legendsWithData:Rt,barTotals:Ut}},"Ie"),aUe=i(function(e){var t=e.data,n=e.springConfig,r=e.animate,a=e.layout,o=a===void 0?In.layout:a,s=qr();return p_(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(gr.text,{x:l.x,y:l.y,fillOpacity:l.labelOpacity,style:gn({},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"),iUe=["isInteractive","animate","motionConfig","theme","renderWrapper"],oUe=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,v=e.padding,b=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,j=_===void 0?In.axisBottom:_,C=e.axisLeft,O=C===void 0?In.axisLeft:C,E=e.enableGridX,T=E===void 0?In.enableGridX:E,R=e.enableGridY,A=R===void 0?In.enableGridY:R,N=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,z=q===void 0?In.enableLabel:q,$=e.label,H=e.labelSkipWidth,U=H===void 0?In.labelSkipWidth:H,W=e.labelSkipHeight,V=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,Ce=we===void 0?In.borderRadius:we,Re=e.borderWidth,ke=Re===void 0?In.borderWidth:Re,Ne=e.borderColor,ze=e.annotations,X=ze===void 0?In.annotations:ze,se=e.legendLabel,me=e.tooltipLabel,Te=e.valueFormat,de=e.isInteractive,ue=de===void 0?In.isInteractive:de,Ae=e.tooltip,Pe=Ae===void 0?In.tooltip:Ae,Fe=e.onClick,et=e.onMouseEnter,Nt=e.onMouseLeave,$t=e.legends,Rt=e.role,Ut=Rt===void 0?In.role:Rt,Ke=e.ariaLabel,pt=e.ariaLabelledBy,ve=e.ariaDescribedBy,ye=e.isFocusable,ct=ye===void 0?In.isFocusable:ye,$e=e.barAriaLabel,Xe=e.barAriaLabelledBy,We=e.barAriaDescribedBy,tt=e.barAriaHidden,jt=e.barAriaDisabled,Ye=e.initialHiddenIds,gt=e.enableTotals,Ft=gt===void 0?In.enableTotals:gt,Pt=e.totalsOffset,At=Pt===void 0?In.totalsOffset:Pt,_t=e.forwardedRef,vt=yo(),Et=vt.animate,Z=vt.config,pe=Wae(s,l,o),_e=pe.outerWidth,qe=pe.outerHeight,He=pe.margin,rt=pe.innerWidth,nt=pe.innerHeight,Qe=mie({indexBy:r,label:$,tooltipLabel:me,valueFormat:Te,colors:re,colorBy:fe,borderColor:Ne,labelTextColor:Q,groupMode:f,layout:c,data:n,keys:a,margin:He,width:rt,height:nt,padding:v,innerPadding:b,valueScale:p,indexScale:m,enableLabel:z,labelSkipWidth:U,labelSkipHeight:V,legends:$t,legendLabel:se,initialHiddenIds:Ye,totalsOffset:At}),ot=Qe.bars,ut=Qe.barsWithValue,st=Qe.xScale,lt=Qe.yScale,yt=Qe.getLabel,at=Qe.getTooltipLabel,kt=Qe.getBorderColor,bt=Qe.getLabelColor,Lt=Qe.shouldRenderBarLabel,Mt=Qe.toggleSerie,zr=Qe.legendsWithData,Aa=Qe.barTotals,fi=Qe.getColor,dr=die(c,(t=p?.reverse)!=null&&t,K,te),bo=p_(ut,{keys:i(function(Ve){return Ve.key},"keys"),from:i(function(Ve){return gn({borderColor:kt(Ve),color:Ve.color,height:0,labelColor:bt(Ve),labelOpacity:0},dr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+(Ve.y+Ve.height)+")",width:Ve.width},c==="vertical"?{}:{height:Ve.height,transform:"translate("+Ve.x+", "+Ve.y+")",width:0})},"from"),enter:i(function(Ve){return gn({borderColor:kt(Ve),color:Ve.color,height:Ve.height,labelColor:bt(Ve),labelOpacity:1},dr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+Ve.y+")",width:Ve.width})},"enter"),update:i(function(Ve){return gn({borderColor:kt(Ve),color:Ve.color,height:Ve.height,labelColor:bt(Ve),labelOpacity:1},dr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+Ve.y+")",width:Ve.width})},"update"),leave:i(function(Ve){return gn({borderColor:kt(Ve),color:Ve.color,height:0,labelColor:bt(Ve),labelOpacity:0},dr(Ve.width,Ve.height),{labelY:0,transform:"translate("+Ve.x+", "+(Ve.y+Ve.height)+")",width:Ve.width},c==="vertical"?{}:gn({},dr(Ve.width,Ve.height),{labelX:0,height:Ve.height,transform:"translate("+Ve.x+", "+Ve.y+")",width:0}))},"leave"),config:Z,immediate:!Et,initial:Et?void 0:null}),Br=y.useMemo((function(){return{borderRadius:Ce,borderWidth:ke,enableLabel:z,isInteractive:ue,labelSkipWidth:U,labelSkipHeight:V,onClick:Fe,onMouseEnter:et,onMouseLeave:Nt,getTooltipLabel:at,tooltip:Pe,isFocusable:ct,ariaLabel:$e,ariaLabelledBy:Xe,ariaDescribedBy:We,ariaHidden:tt,ariaDisabled:jt}}),[Ce,ke,z,at,ue,V,U,Fe,et,Nt,Pe,ct,$e,Xe,We,tt,jt]),Ka=r9e(he,ot,Me,{dataKey:"data",targetKey:"data.fill"}),ea={annotations:null,axes:null,bars:null,grid:null,legends:null,markers:null,totals:null};I.includes("annotations")&&(ea.annotations=d.jsx($qe,{bars:ot,annotations:X},"annotations")),I.includes("axes")&&(ea.axes=d.jsx(F9e,{xScale:st,yScale:lt,width:rt,height:nt,top:w,right:S,bottom:j,left:O},"axes")),I.includes("bars")&&(ea.bars=d.jsx(y.Fragment,{children:bo((function(Ve,qn){return y.createElement(L,gn({},Br,{bar:qn,style:Ve,shouldRenderLabel:Lt(qn),label:yt(qn.data)}))}))},"bars")),I.includes("grid")&&(ea.grid=d.jsx($9e,{width:rt,height:nt,xScale:T?st:null,yScale:A?lt:null,xValues:N,yValues:D},"grid")),I.includes("legends")&&(ea.legends=d.jsx(qqe,{width:rt,height:nt,legends:zr,toggleSerie:Mt},"legends")),I.includes("markers")&&(ea.markers=d.jsx(G7e,{markers:ne,width:rt,height:nt,xScale:st,yScale:lt},"markers")),I.includes("totals")&&Ft&&(ea.totals=d.jsx(aUe,{data:Aa,springConfig:Z,animate:Et,layout:c},"totals"));var Ya=gn({},Br,{margin:He,width:s,height:l,innerWidth:rt,innerHeight:nt,bars:ot,legendData:zr,enableLabel:z,xScale:st,yScale:lt,tooltip:Pe,getTooltipLabel:at,onClick:Fe,onMouseEnter:et,onMouseLeave:Nt,getColor:fi});return d.jsx(H7e,{width:_e,height:qe,margin:He,defs:Ka,role:Ut,ariaLabel:Ke,ariaLabelledBy:pt,ariaDescribedBy:ve,isFocusable:ct,ref:_t,children:I.map((function(Ve,qn){var Li;return typeof Ve=="function"?d.jsx(y.Fragment,{children:y.createElement(Ve,Ya)},qn):(Li=ea?.[Ve])!=null?Li:null}))})},"He"),sUe=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=zc(e,iUe);return d.jsx(Uae,{animate:o,isInteractive:r,motionConfig:l,renderWrapper:c,theme:f,children:d.jsx(oUe,gn({},p,{isInteractive:r,forwardedRef:t}))})})),lUe=["isInteractive","renderWrapper","theme"],bT=i(function(e,t,n,r){return e.find((function(a){return J7e(a.x+t.left,a.y+t.top,a.width,a.height,n,r)}))},"Fe"),cUe=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,v=e.padding,b=e.innerPadding,w=e.axisTop,S=e.axisRight,_=e.axisBottom,j=_===void 0?br.axisBottom:_,C=e.axisLeft,O=C===void 0?br.axisLeft:C,E=e.enableGridX,T=E===void 0?br.enableGridX:E,R=e.enableGridY,A=R===void 0?br.enableGridY:R,N=e.gridXValues,D=e.gridYValues,M=e.labelPosition,I=M===void 0?br.labelPosition:M,F=e.labelOffset,L=F===void 0?br.labelOffset:F,q=e.layers,z=q===void 0?br.layers:q,$=e.renderBar,H=$===void 0?br.renderBar:$,U=e.enableLabel,W=U===void 0?br.enableLabel:U,V=e.label,Q=e.labelSkipWidth,Y=Q===void 0?br.labelSkipWidth:Q,K=e.labelSkipHeight,ee=K===void 0?br.labelSkipHeight:K,te=e.labelTextColor,oe=e.colorBy,ne=e.colors,fe=e.borderRadius,re=fe===void 0?br.borderRadius:fe,ce=e.borderWidth,he=ce===void 0?br.borderWidth:ce,J=e.borderColor,Me=e.annotations,we=Me===void 0?br.annotations:Me,Ce=e.legendLabel,Re=e.tooltipLabel,ke=e.valueFormat,Ne=e.isInteractive,ze=Ne===void 0?br.isInteractive:Ne,X=e.tooltip,se=X===void 0?br.tooltip:X,me=e.onClick,Te=e.onMouseEnter,de=e.onMouseLeave,ue=e.legends,Ae=e.pixelRatio,Pe=Ae===void 0?br.pixelRatio:Ae,Fe=e.role,et=e.forwardedRef,Nt=e.enableTotals,$t=Nt===void 0?br.enableTotals:Nt,Rt=e.totalsOffset,Ut=Rt===void 0?br.totalsOffset:Rt,Ke=y.useRef(null),pt=qr(),ve=Wae(s,l,o),ye=ve.margin,ct=ve.innerWidth,$e=ve.innerHeight,Xe=ve.outerWidth,We=ve.outerHeight,tt=mie({indexBy:r,label:V,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:$e,padding:v,innerPadding:b,valueScale:p,indexScale:m,enableLabel:W,labelSkipWidth:Y,labelSkipHeight:ee,legends:ue,legendLabel:Ce,totalsOffset:Ut}),jt=tt.bars,Ye=tt.barsWithValue,gt=tt.xScale,Ft=tt.yScale,Pt=tt.getLabel,At=tt.getTooltipLabel,_t=tt.getBorderColor,vt=tt.getLabelColor,Et=tt.shouldRenderBarLabel,Z=tt.legendsWithData,pe=tt.barTotals,_e=tt.getColor,qe=Ire(),He=qe.showTooltipFromEvent,rt=qe.hideTooltip,nt=aqe({annotations:rie({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:ze,isFocusable:!1,labelSkipWidth:Y,labelSkipHeight:ee,margin:ye,width:s,height:l,innerWidth:ct,innerHeight:$e,bars:jt,legendData:Z,enableLabel:W,xScale:gt,yScale:Ft,tooltip:se,getTooltipLabel:At,onClick:me,onMouseEnter:Te,onMouseLeave:de,getColor:_e}}),[re,he,ze,Y,ee,ye,s,l,ct,$e,jt,Z,W,gt,Ft,se,At,me,Te,de,_e]),ot=B3(ke),ut=die(c,(t=p?.reverse)!=null&&t,I,L);y.useEffect((function(){if(Ke.current){Ke.current.width=Xe*Pe,Ke.current.height=We*Pe;var at=Ke.current.getContext("2d");at.scale(Pe,Pe),at.fillStyle=pt.background,at.fillRect(0,0,Xe,We),at.translate(ye.left,ye.top),z.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&&hW(at,{width:ct,height:$e,scale:gt,axis:"x",values:N}),A&&hW(at,{width:ct,height:$e,scale:Ft,axis:"y",values:D})):kt==="axes"?U9e(at,{xScale:gt,yScale:Ft,width:ct,height:$e,top:w,right:S,bottom:j,left:O,theme:pt}):kt==="bars"?(Uv(at,pt.text),Ye.forEach((function(bt){H(at,gn({bar:bt,borderColor:_t(bt),borderRadius:re,borderWidth:he,label:Pt(bt.data),shouldRenderLabel:Et(bt),labelStyle:gn({},pt.labels.text,{fill:vt(bt)})},ut(bt.width,bt.height)))}))):kt==="legends"?Z.forEach((function(bt){var Lt=bt[0],Mt=bt[1];Fqe(at,gn({},Lt,{data:Mt,containerWidth:ct,containerHeight:$e,theme:pt}))})):kt==="annotations"?dqe(at,{annotations:nt,theme:pt}):kt==="totals"&&$t?(function(bt,Lt,Mt,zr){zr===void 0&&(zr=br.layout),Uv(bt,Mt.labels.text),bt.textBaseline=zr==="vertical"?"alphabetic":"middle",bt.textAlign=zr==="vertical"?"center":"start",Lt.forEach((function(Aa){zv(bt,Mt.labels.text,Aa.formattedValue,Aa.x,Aa.y)}))})(at,pe,pt,c):typeof kt=="function"&&kt(at,Qe)})),at.save()}}),[j,O,S,w,Ye,re,he,nt,T,A,_t,Pt,vt,N,D,f,l,$e,ct,Qe,z,c,Z,ye.left,ye.top,We,Xe,Pe,H,gt,Ft,Et,pt,s,pe,$t,ot,ut]);var st=y.useCallback((function(at){if(jt&&Ke.current){var kt=QA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=bT(jt,ye,bt,Lt);Mt!==void 0?(He(y.createElement(se,gn({},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,He,se]),lt=y.useCallback((function(at){if(jt&&Ke.current){rt();var kt=QA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=bT(jt,ye,bt,Lt);Mt&&de?.(Mt.data,at)}}),[rt,ye,de,jt]),yt=y.useCallback((function(at){if(jt&&Ke.current){var kt=QA(Ke.current,at),bt=kt[0],Lt=kt[1],Mt=bT(jt,ye,bt,Lt);Mt!==void 0&&me?.(gn({},Mt.data,{color:Mt.color}),at)}}),[ye,me,jt]);return d.jsx("canvas",{ref:a9e(Ke,et),width:Xe*Pe,height:We*Pe,style:{width:Xe,height:We,cursor:ze?"auto":"normal"},onMouseEnter:ze?st:void 0,onMouseMove:ze?st:void 0,onMouseLeave:ze?lt:void 0,onClick:ze?yt:void 0,role:Fe})},"ze"),uUe=y.forwardRef((function(e,t){var n=e.isInteractive,r=e.renderWrapper,a=e.theme,o=zc(e,lUe);return d.jsx(Uae,{isInteractive:n,renderWrapper:r,theme:a,animate:!1,children:d.jsx(cUe,gn({},o,{isInteractive:n,forwardedRef:t}))})})),dUe=["defaultWidth","defaultHeight","onResize","debounceResize"],fUe=y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,o=e.debounceResize,s=zc(e,dUe);return d.jsx(zae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:o,children:i(function(l){var f=l.width,c=l.height;return d.jsx(sUe,gn({},s,{width:f,height:c,ref:t}))},"children")})})),hUe=["defaultWidth","defaultHeight","onResize","debounceResize"];y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,o=e.debounceResize,s=zc(e,hUe);return d.jsx(zae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:o,children:i(function(l){var f=l.width,c=l.height;return d.jsx(uUe,gn({},s,{width:f,height:c,ref:t}))},"children")})}));const pUe={opportunity:.2,"proposal-sent":.5,"in-negociation":.8,delayed:.3},mUe=new Date(new Date().setMonth(new Date().getMonth()-6)).toISOString(),RW="en-US",gUe="USD",vUe=y.memo(()=>{const e=navigator?navigator.languages||[navigator.language]:[RW],{data:t,isPending:n}=Sa("deals",{pagination:{perPage:100,page:1},sort:{field:"created_at",order:"ASC"},filter:{"created_at@gte":mUe}}),r=y.useMemo(()=>{if(!t)return[];const s=t.reduce((f,c)=>{const p=mN(c.created_at??new Date).toISOString();return f[p]||(f[p]=[]),f[p].push(c),f},{});return Object.keys(s).map(f=>({date:pc(f,"MMM"),won:s[f].filter(c=>c.stage==="won").reduce((c,p)=>{const m=p.amount??0;return isNaN(m)||(c+=m),c},0),pending:s[f].filter(c=>!["won","lost"].includes(c.stage)).reduce((c,p)=>{const m=p.amount??0,v=pUe[p.stage]??0;return!isNaN(m)&&!isNaN(v)&&(c+=m*v),c},0),lost:s[f].filter(c=>c.stage==="lost").reduce((c,p)=>{const m=p.amount??0;return isNaN(m)||(c-=m),c},0)})).filter(f=>!isNaN(f.won)&&!isNaN(f.pending)&&!isNaN(f.lost))},[t]);if(n||r.length===0)return null;const a=r.reduce((s,l)=>(s.min=Math.min(s.min,l.lost),s.max=Math.max(s.max,l.won+l.pending),s),{min:0,max:0}),o={min:a.min===0&&a.max===0?-100:a.min*1.2,max:a.min===0&&a.max===0?100:a.max*1.2};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($Q,{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(fUe,{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:o.min,max:o.max},indexScale:{type:"band",round:!0},enableGridX:!0,enableGridY:!1,enableLabel:!1,tooltip:i(({value:s,indexValue:l})=>d.jsxs("div",{className:"p-2 bg-secondary rounded shadow inline-flex items-center gap-1 text-secondary-foreground",children:[d.jsxs("strong",{children:[l,": "]})," ",s>0?"+":"",s.toLocaleString(e.at(0)??RW,{style:"currency",currency:gUe})]}),"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(s=>`${Math.abs(s/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"}]})})]})}),yUe=i(e=>{const t=xt(),n=Gt(e),{filterValues:r,setFilters:a}=Hw(e),o=md();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(Le,{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"),bUe=i(e=>{const{children:t,linkType:n,rowClick:r,style:a}=e,o=Gt(e),s=qt(e),l=Ea(),f=typeof n=="function"||typeof r=="function",c=dK({link:f?!1:n??r,resource:o}),p=pK(),m=Ct(async()=>{if(!f||!s)return;const v=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:v});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"),xT=i(({className:e})=>d.jsx("span",{className:Se("bg-gray-300 flex",e),children:" "}),"ListPlaceholder"),xUe=i(e=>{const{className:t,hasLeftAvatarOrIcon:n,hasRightAvatarOrIcon:r,hasSecondaryText:a,hasTertiaryText:o,nbFakeLines:s=5,...l}=e;return HK(1e3)?d.jsx("ul",{className:t,...l,children:wUe(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(xT,{className:"w-1/3 inline-block mb-1"}),o&&d.jsx("span",{className:"float-right opacity-55 min-w-[10vw]",children:d.jsx(xT,{})})]}),a&&d.jsx(xT,{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"),wUe=i((e,t)=>Array.from({length:e},(n,r)=>t(r)),"times"),_Ue=i(e=>{const{className:t,empty:n=jUe,leftAvatar:r,leftIcon:a,linkType:o,rowClick:s,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,resource:v,...b}=e,{data:w,isPending:S,total:_}=Hw(e);return S===!0?d.jsx(xUe,{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,...jme(b),children:d.jsx(Tme,{data:w,total:_,render:i((j,C)=>d.jsx(bUe,{rowIndex:C,linkType:o,rowClick:s,resource:v,children:d.jsx(SUe,{leftAvatar:r,leftIcon:a,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,rowIndex:C})},j.id),"render")})})},"SimpleList"),SUe=i(e=>{const{leftAvatar:t,leftIcon:n,primaryText:r,rightAvatar:a,rightIcon:o,secondaryText:s,tertiaryText:l}=e,f=Gt(e),c=qt(e),p=Rc(f),m=xt(),v=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:v(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&&v(c,a),o&&o(c,c.id)]})]}):null},"SimpleListItemContent"),jUe=d.jsx(yUe,{}),CUe=i(()=>{const{identity:e}=er(),{data:t,total:n,isPending:r}=Sa("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(HM,{className:"text-muted-foreground w-6 h-6"})}),d.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Hot Contacts"}),d.jsx(Di,{children:d.jsxs(so,{children:[d.jsx(lo,{asChild:!0,children:d.jsx(Le,{variant:"ghost",size:"sm",className:"ml-auto text-muted-foreground",asChild:!0,children:d.jsx(fn,{to:"/contacts/create",children:d.jsx(ro,{className:"w-4 h-4 text-primary"})})})}),d.jsx(co,{children:"Create contact"})]})})]}),d.jsx(pn,{className:"py-0",children:d.jsx(_Ue,{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(us,{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"),EUe=i(()=>{const{identity:e}=er(),{total:t}=Sa("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"),mg=i(({title:e,filter:t})=>{const{identity:n}=er(),{data:r,total:a,isPending:o}=Sa("tasks",{pagination:{page:1,perPage:100},sort:{field:"due_date",order:"ASC"},filter:{...t,sales_id:n?.id}},{enabled:!!n}),s=Vw({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(pd,{value:"tasks",children:d.jsx(sy,{value:s,children:d.jsx(Wne,{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"),gie=new Date,OUe=cbe(gie),kUe=OUe<5,AW=dbe().toISOString(),TW=l0e().toISOString(),NW=c0e().toISOString(),PW=s0e(gie,{weekStartsOn:0}).toISOString(),gg={overdue:{"done_date@is":null,"due_date@lt":AW},today:{"done_date@is":null,"due_date@gte":AW,"due_date@lte":TW},tomorrow:{"done_date@is":null,"due_date@gt":TW,"due_date@lt":NW},thisWeek:{"done_date@is":null,"due_date@gte":NW,"due_date@lte":PW},later:{"done_date@is":null,"due_date@gt":PW}},RUe=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(UQ,{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(Vne,{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(EUe,{}),d.jsx(mg,{title:"Overdue",filter:gg.overdue}),d.jsx(mg,{title:"Today",filter:gg.today}),d.jsx(mg,{title:"Tomorrow",filter:gg.tomorrow}),kUe&&d.jsx(mg,{title:"This week",filter:gg.thisWeek}),d.jsx(mg,{title:"Later",filter:gg.later})]})})]}),"TasksList"),AUe=i(()=>{const{data:e,total:t,isPending:n}=Sa("contacts",{pagination:{page:1,perPage:1}}),{total:r,isPending:a}=Sa("contactNotes",{pagination:{page:1,perPage:1}}),{total:o,isPending:s}=Sa("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(CUe,{})]})}),d.jsx("div",{className:"md:col-span-6",children:d.jsxs("div",{className:"flex flex-col gap-6",children:[o?d.jsx(vUe,{}):null,d.jsx(I6e,{})]})}),d.jsx("div",{className:"md:col-span-3",children:d.jsx(RUe,{})})]}):d.jsx(PH,{step:2,contactId:e?.[0]?.id}):d.jsx(PH,{step:1})},"Dashboard"),TUe=y.lazy(()=>Up(()=>import("./DealList-CyjZCmZS.js"),[],import.meta.url)),NUe={list:TUe},PUe=y.createContext(void 0),tS=i(()=>y.useContext(PUe),"useUserMenu"),DUe=i(()=>{const{darkModeLogo:e,lightModeLogo:t,title:n}=Ra(),r=$r(),o=[{path:"/",pattern:"/"},{path:"/contacts",pattern:"/contacts/*"},{path:"/companies",pattern:"/companies/*"},{path:"/deals",pattern:"/deals/*"}].find(s=>ap(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(MUe,{darkLogo:e,lightLogo:t,title:n}),d.jsxs("nav",{className:"flex","aria-label":"Main navigation",children:[d.jsx(Rb,{label:"Dashboard",to:"/",isActive:o==="/"}),d.jsx(Rb,{label:"Contacts",to:"/contacts",isActive:o==="/contacts"}),d.jsx(Rb,{label:"Companies",to:"/companies",isActive:o==="/companies"}),d.jsx(Rb,{label:"Deals",to:"/deals",isActive:o==="/deals"})]}),d.jsxs("div",{className:"flex items-center",children:[d.jsx(YZ,{}),d.jsx(QZ,{}),d.jsxs(WZ,{children:[d.jsx(FUe,{}),d.jsx(LUe,{}),d.jsx($Ue,{}),d.jsx(Gve,{resource:"sales",action:"list",children:d.jsx(IUe,{})}),d.jsx(lv,{}),d.jsx(g4,{className:"font-normal",children:d.jsxs("div",{className:"text-xs text-muted-foreground",children:["Version ","0.13.8"]})})]})]})]})})})},"Header"),MUe=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"),Rb=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"),IUe=i(()=>{const{onClose:e}=tS()??{};return d.jsx(cr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/sales",className:"flex items-center gap-2",children:[d.jsx(VQ,{className:"h-4 w-4"}),"Users"]})})},"UsersMenu"),FUe=i(()=>{const{onClose:e}=tS()??{};return d.jsx(cr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/settings",className:"flex items-center gap-2",children:[d.jsx(yN,{className:"h-4 w-4"}),"My info"]})})},"ConfigurationMenu"),LUe=i(()=>{const{onClose:e}=tS()??{};return d.jsx(cr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/database",className:"flex items-center gap-2",children:[d.jsx(nv,{className:"h-4 w-4"}),"Database"]})})},"DatabaseMenu"),$Ue=i(()=>{const{onClose:e}=tS()??{};return d.jsx(cr,{asChild:!0,onClick:e,children:d.jsxs(fn,{to:"/integrations",className:"flex items-center gap-2",children:[d.jsx(S_e,{className:"h-4 w-4"}),"Integrations"]})})},"IntegrationsMenu"),qUe=i(({children:e})=>d.jsxs(d.Fragment,{children:[d.jsx(DUe,{}),d.jsx("main",{className:"max-w-screen-xl mx-auto pt-20 px-4",id:"main-content",children:d.jsx(vx,{FallbackComponent:tJ,children:d.jsx(y.Suspense,{fallback:d.jsx(ln,{className:"h-12 w-12 rounded-full"}),children:e})})}),d.jsx(I1,{})]}),"Layout"),vie=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(ln,{className:"w-full h-[100px]"}),d.jsx(ln,{className:"w-4/5 h-[50px]"}),d.jsx(ln,{className:"w-full h-9"}),d.jsx(ln,{className:"w-full h-9"}),d.jsx(ln,{className:"w-full h-9"}),d.jsx(ln,{className:"w-2/5 h-9"})]})})}),"LoginSkeleton"),dD=i(()=>{const e=Nn(),t=xn(),{darkModeLogo:n,title:r}=Ra(),{data:a,isPending:o}=Xr({queryKey:["init"],queryFn:i(async()=>t.isInitialized(),"queryFn")}),{isPending:s,mutate:l}=Lr({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=MY(),c=Vt(),{register:p,handleSubmit:m,formState:{isValid:v}}=uy({mode:"onChange"});if(o)return d.jsx(vie,{});if(a)return d.jsx(ww,{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(Vn,{htmlFor:"first_name",children:"First name"}),d.jsx(Cr,{...p("first_name",{required:!0}),id:"first_name",type:"text",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Vn,{htmlFor:"last_name",children:"Last name"}),d.jsx(Cr,{...p("last_name",{required:!0}),id:"last_name",type:"text",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Vn,{htmlFor:"email",children:"Email"}),d.jsx(Cr,{...p("email",{required:!0}),id:"email",type:"email",required:!0})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx(Vn,{htmlFor:"password",children:"Password"}),d.jsx(Cr,{...p("password",{required:!0}),id:"password",type:"password",required:!0})]}),d.jsx("div",{className:"flex justify-between items-center mt-8",children:d.jsx(Le,{type:"submit",disabled:!v||s,className:"w-full",children:s?d.jsxs(d.Fragment,{children:[d.jsx(Tc,{className:"w-4 h-4 animate-spin mr-2"}),"Creating..."]}):"Create account"})})]})]})})]})},"SignupPage");dD.path="/sign-up";const UUe=i((e,t)=>e==="admin"?!0:t.resource!=="sales","canAccess"),wT=yAe(Ln,{getIdentity:i(async()=>{const e=await yie();if(e==null)throw new Error;return{id:e.id,fullName:`${e.first_name} ${e.last_name}`,avatar:e.avatar?.src}},"getIdentity")});async function Xs(){if(Xs._is_initialized_cache==null){const{data:e}=await Ln.from("init_state").select("is_initialized");Xs._is_initialized_cache=e?.at(0)?.is_initialized>0}return Xs._is_initialized_cache}i(Xs,"getIsInitialized");(e=>{e._is_initialized_cache=null})(Xs||(Xs={}));const zUe={...wT,login:i(async e=>{const t=await wT.login(e);return Hb=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 Xs())throw await Ln.auth.signOut(),{redirectTo:"/sign-up",message:!1};return wT.checkAuth(e)},"checkAuth"),canAccess:i(async e=>{if(!await Xs())return!1;const n=await yie();if(n==null)return!1;const r=n.administrator?"admin":"user";return UUe(r,e)},"canAccess")};let Hb;const yie=i(async()=>{if(Hb!=null)return Hb;const{data:e,error:t}=await Ln.auth.getSession();if(e?.session?.user==null||t)return;const{data:n,error:r}=await Ln.from("sales").select("id, first_name, last_name, avatar, administrator").match({user_id:e?.session?.user.id}).single();if(!(n==null||r))return Hb=n,n},"getSaleFromCache");async function BUe(e,t,n){const r={};t&&(r.id=t);const a={};t&&(a.company_id=t);const[o,s,l,f]=await Promise.all([HUe(e,r),VUe(e,a),WUe(e,a),GUe(e,a)]);return[...o,...s,...l,...f].sort((c,p)=>c.date&&p.date?c.date.localeCompare(p.date)*-1:0).slice(0,250)}i(BUe,"getActivityLog");const HUe=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:qte,company_id:r.id,company:r,sales_id:r.sales_id,date:r.created_at}))},"getNewCompanies");async function VUe(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:zte,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:Bte,sales_id:l.sales_id,contactNote:l,date:l.date}));return[...o,...s]}i(VUe,"getNewContactsAndNotes");async function WUe(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:Hte,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:Vte,sales_id:l.sales_id,dealNote:l,date:l.date}));return[...o,...s]}i(WUe,"getNewDealsAndNotes");async function GUe(e,t){const n={};t.sales_id&&(n.sales_id=t.sales_id),t.company_id&&(n.company_id=t.company_id);const{data:r}=await e.getList("companyNotes",{filter:n,pagination:{page:1,perPage:250},sort:{field:"date",order:"DESC"}});return r.map(o=>({id:`companyNote.${o.id}.created`,type:Ute,sales_id:o.sales_id,companyNote:o,date:o.date}))}i(GUe,"getNewCompanyNotes");async function KUe(e){return e.website?{src:`https://favicon.show/${e.website.replace(/^https?:\/\//,"").replace(/\/$/,"")}`,title:"Company favicon"}:null}i(KUe,"getCompanyAvatar");async function YUe(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(YUe,"fetchWithTimeout");const QUe=["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 XUe(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(XUe,"hash");async function ZUe(e){return`https://www.gravatar.com/avatar/${await XUe(e)}?d=404`}i(ZUe,"getGravatarUrl");async function JUe(e){if(QUe.includes(e))return null;try{const t=`https://${e}/favicon.ico`;if((await YUe(t)).ok)return t}catch{return null}return null}i(JUe,"getFaviconUrl");async function eze(e){if(!e.email_jsonb||!e.email_jsonb.length)return null;for(const{email:t}of e.email_jsonb){const n=await ZUe(t);try{if((await fetch(n)).ok)return n}catch{}const r=t.split("@")[1],a=await JUe(r);if(a)return a}return null}i(eze,"getContactAvatar");const DW=_d()||{url:"https://placeholder.supabase.co",anonKey:"placeholder-key"},ko=IAe({instanceUrl:DW.url,apiKey:DW.anonKey,supabaseClient:Ln,sortOrder:"asc,desc.nullslast"}),MW=i(async e=>{let t=e.data.logo;return typeof t!="object"||t===null||!t.src?t=await KUe(e.data):t.rawFile instanceof File&&await Vb(t),{...e,data:{...e.data,logo:t}}},"processCompanyLogo");async function IW(e){const{data:t}=e;if(t.avatar?.src||!t.email_jsonb||!t.email_jsonb.length)return e;const n=await eze(t),r={...t,avatar:{src:n||void 0}};return{...e,data:r}}i(IW,"processContactAvatar");const tze={...ko,async getList(e,t){return e==="companies"?ko.getList("companies_summary",t):e==="contacts"?ko.getList("contacts_summary",t):ko.getList(e,t)},async getOne(e,t){return e==="companies"?ko.getOne("companies_summary",t):e==="contacts"?ko.getOne("contacts_summary",t):ko.getOne(e,t)},async signUp({email:e,password:t,first_name:n,last_name:r}){const{data:a,error:o}=await Ln.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 Xs._is_initialized_cache=!0,{id:a.data.id,email:e,password:t}},async salesCreate(e){const{data:t,error:n}=await Ln.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 Ln.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 Ln.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 Ln.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 Ln.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 ko.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=>ko.update("deals",{id:r.id,data:r,previousData:t.find(a=>a.id===r.id)})))},async getActivityLog(e){return BUe(ko,e)},async isInitialized(){return Xs()},async mergeContacts(e,t){const{data:n,error:r}=await Ln.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},async mergeCompanies(e,t){const{data:n,error:r}=await Ln.functions.invoke("mergeCompanies",{method:"POST",body:{loserId:e,winnerId:t}});if(r)throw console.error("mergeCompanies.error",r),new Error("Failed to merge companies");return n}},nze=Dhe(tze,[{resource:"contactNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await Vb(r);return e},"beforeSave")},{resource:"dealNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await Vb(r);return e},"beforeSave")},{resource:"sales",beforeSave:i(async(e,t,n)=>(e.avatar&&await Vb(e.avatar),e),"beforeSave")},{resource:"contacts",beforeCreate:i(async e=>IW(e),"beforeCreate"),beforeUpdate:i(async e=>IW(e),"beforeUpdate"),beforeGetList:i(async e=>Ab(["first_name","last_name","company_name","title","email","phone","background"])(e),"beforeGetList")},{resource:"companies",beforeGetList:i(async e=>Ab(["name","phone_number","website","zipcode","city","stateAbbr"])(e),"beforeGetList"),beforeCreate:i(async e=>{const t=await MW(e);return{...t,data:{...t.data,created_at:new Date().toISOString()}}},"beforeCreate"),beforeUpdate:i(async e=>await MW(e),"beforeUpdate")},{resource:"contacts_summary",beforeGetList:i(async e=>Ab(["first_name","last_name"])(e),"beforeGetList")},{resource:"deals",beforeGetList:i(async e=>Ab(["name","type","description"])(e),"beforeGetList")}]),Ab=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"),Vb=i(async e=>{if(!e.src.startsWith("blob:")&&!e.src.startsWith("data:")&&e.path){const{error:c}=await Ln.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 Ln.storage.from("attachments").upload(o,t);if(s)throw console.error("uploadError",s),new Error("Failed to upload attachment");const{data:l}=Ln.storage.from("attachments").getPublicUrl(o);e.path=o,e.src=l.publicUrl;const f=n.type;return e.type=f,e},"uploadToBucket");function bie(){const{identity:e}=er(),t=qt();return d.jsxs("div",{className:"space-y-4 w-full",children:[d.jsx(Bt,{source:"first_name",validate:Zn(),helperText:!1}),d.jsx(Bt,{source:"last_name",validate:Zn(),helperText:!1}),d.jsx(Bt,{source:"email",validate:[Zn(),pY()],helperText:!1}),d.jsx(PP,{source:"administrator",readOnly:t?.id===e?.id,helperText:!1}),d.jsx(PP,{source:"disabled",readOnly:t?.id===e?.id,helperText:!1})]})}i(bie,"SalesInputs");function rze(){const e=xn(),t=Vt(),n=go(),{mutate:r}=Lr({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(ts,{children:d.jsx(ns,{children:"Create a new user"})}),d.jsx(Wn,{children:d.jsx(Nee,{onSubmit:a,children:d.jsx(bie,{})})})]})})}i(rze,"SalesCreate");function aze(){return d.jsxs("div",{className:"flex justify-end gap-4",children:[d.jsx(G1,{}),d.jsx(xd,{})]})}i(aze,"EditToolbar");function ize(){const{record:e}=qK(),t=xn(),n=Vt(),r=go(),{mutate:a}=Lr({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(Nee,{toolbar:d.jsx(aze,{}),onSubmit:o,record:e,children:[d.jsx(oze,{}),d.jsx(bie,{})]})})})})}i(ize,"SalesEdit");const oze=i(()=>{const e=qt();return e?d.jsxs("h2",{className:"text-lg font-semibold mb-4",children:["Edit ",e?.first_name," ",e?.last_name]}):null},"SaleEditTitle"),sze=i(()=>d.jsxs(P4,{children:[d.jsx(q1,{}),d.jsx(Ic,{label:"New user"})]}),"SalesListActions"),lze=[d.jsx(D4,{source:"q",alwaysOn:!0})],cze=i(e=>{const t=qt();return t?d.jsxs("div",{className:"flex flex-row gap-1",children:[t.administrator&&d.jsx(Jn,{variant:"outline",className:"border-blue-300 dark:border-blue-700",children:"Admin"}),t.disabled&&d.jsx(Jn,{variant:"outline",className:"border-orange-300 dark:border-orange-700",children:"Disabled"})]}):null},"OptionsField"),uze=i(()=>{const e=qt(),t=xn(),n=Vt(),r=Fw(),[a,o]=y.useState(!1),[s,l]=y.useState(!1),{mutate:f,isPending:c}=Lr({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}=Lr({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 v=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:v,isDisabled:b,inviteDialogOpen:a,resetDialogOpen:s}),d.jsxs(d.Fragment,{children:[d.jsxs(Dc,{children:[d.jsx(tl,{asChild:!0,children:d.jsxs(Le,{variant:"ghost",className:"h-8 w-8 p-0",children:[d.jsx("span",{className:"sr-only",children:"Open menu"}),d.jsx(FM,{className:"h-4 w-4"})]})}),d.jsxs(Mc,{align:"end",children:[d.jsx(g4,{children:"Email Actions"}),d.jsx(lv,{}),!v&&d.jsxs(cr,{onClick:i(w=>{w.preventDefault(),w.stopPropagation(),console.log("[Menu] Clicked Resend Invite"),o(!0)},"onClick"),children:[d.jsx(H1e,{className:"mr-2 h-4 w-4"}),"Resend Invite"]}),v&&!b&&d.jsxs(cr,{onClick:i(()=>l(!0),"onClick"),children:[d.jsx(d1e,{className:"mr-2 h-4 w-4"}),"Send Password Reset"]})]})]}),d.jsx(fa,{open:a,onOpenChange:o,children:d.jsxs(ha,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:"Resend Invitation"}),d.jsxs(si,{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(uo,{children:[d.jsx(Le,{variant:"outline",onClick:i(w=>{w.stopPropagation(),o(!1)},"onClick"),disabled:c,children:"Cancel"}),d.jsx(Le,{onClick:i(w=>{w.stopPropagation(),f()},"onClick"),disabled:c,children:c?"Sending...":"Send Invitation"})]})]})}),d.jsx(fa,{open:s,onOpenChange:l,children:d.jsxs(ha,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:"Send Password Reset"}),d.jsxs(si,{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(uo,{children:[d.jsx(Le,{variant:"outline",onClick:i(w=>{w.stopPropagation(),l(!1)},"onClick"),disabled:m,children:"Cancel"}),d.jsx(Le,{onClick:i(w=>{w.stopPropagation(),p()},"onClick"),disabled:m,children:m?"Sending...":"Send Reset Link"})]})]})})]})},"RowActions");function dze(){return d.jsx(A4,{filters:lze,actions:d.jsx(sze,{}),sort:{field:"first_name",order:"ASC"},children:d.jsx(fze,{})})}i(dze,"SalesList");const fze=i(()=>{const{data:e,isPending:t,filterValues:n}=Gn(),{identity:r}=er(),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(ln,{className:"h-12 w-full"}),d.jsx(ln,{className:"h-12 w-full"}),d.jsx(ln,{className:"h-12 w-full"}),d.jsx(ln,{className:"h-12 w-full"}),d.jsx(ln,{className:"h-12 w-full"})]})}):!e?.length&&!a?d.jsx(hze,{}):d.jsxs(zs,{children:[d.jsx(zs.Col,{source:"first_name"}),d.jsx(zs.Col,{source:"last_name"}),d.jsx(zs.Col,{source:"email"}),d.jsx(zs.Col,{label:!1,children:d.jsx(cze,{})}),d.jsx(zs.Col,{label:!1,children:d.jsx(uze,{})})]})},"SalesListLayout"),hze=i(()=>{const e=V1();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(Ic,{label:"New user"})})]})},"SalesEmpty"),pze={list:dze,create:rze,edit:ize,recordRepresentation:i(e=>`${e.first_name} ${e.last_name}`,"recordRepresentation")};function FW(e){const t=e.trim();return t?t.startsWith("http://")||t.startsWith("https://")?t:`https://${t}.supabase.co`:""}i(FW,"normalizeSupabaseUrl");function mze(e){const t=e.trim();if(!t)return{valid:!1};if(t.startsWith("http://")||t.startsWith("https://"))try{return new URL(t).hostname.endsWith(".supabase.co")?{valid:!0,message:"Valid Supabase URL"}:{valid:!1,message:"URL must be a Supabase domain"}}catch{return{valid:!1,message:"Invalid URL format"}}return/^[a-z0-9]+$/.test(t)?{valid:!0,message:"Valid project ID (will expand to full URL)"}:{valid:!1,message:"Enter full URL or project ID"}}i(mze,"validateUrlFormat");function gze(e){const t=e.trim();return t?t.startsWith("sb_publishable_")?t.length>35?{valid:!0,message:"Valid publishable key format"}:{valid:!1,message:"Publishable key seems incomplete"}:t.startsWith("eyJ")?t.length>100?{valid:!0,message:"Valid anon key format"}:{valid:!1,message:"Anon key seems incomplete"}:{valid:!1,message:"Must be a valid Supabase API key (anon or publishable)"}:{valid:!1}}i(gze,"validateKeyFormat");function xie({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,v]=y.useState(!1),[b,w]=y.useState(!1),S=i(async()=>{p(null),a("validating");const T=FW(o),R=l.trim(),A=await pAe(T,R);A.valid?(dAe({url:T,anonKey:R}),a("success"),setTimeout(()=>{window.location.href=window.location.origin},1500)):(p(A.error||"Connection failed"),a("credentials"))},"handleValidateAndSave"),_=o?mze(o):{valid:!1},j=l?gze(l):{valid:!1},C=o?FW(o):"",O=o&&!o.startsWith("http")&&_.valid,E=i(()=>{n&&t()},"handleClose");return d.jsx(fa,{open:e,onOpenChange:n?E:void 0,children:d.jsxs(ha,{className:"sm:max-w-md",onPointerDownOutside:i(T=>!n&&T.preventDefault(),"onPointerDownOutside"),onEscapeKeyDown:i(T=>!n&&T.preventDefault(),"onEscapeKeyDown"),children:[r==="welcome"&&d.jsxs(d.Fragment,{children:[d.jsxs(Mr,{children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d.jsx(nv,{className:"h-6 w-6 text-primary"}),d.jsx(Ir,{children:"Welcome to CRM"})]}),d.jsx(si,{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(Va,{children:d.jsxs(li,{children:[d.jsx("strong",{children:"Don't have a Supabase project?"}),d.jsx("br",{}),"Create one for free at"," ",d.jsxs("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline text-primary inline-flex items-center gap-1",children:["supabase.com",d.jsx(Hl,{className:"h-3 w-3"})]})]})}),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 or project ID"}),d.jsx("li",{children:"Your API key (anon or publishable key)"})]})]}),d.jsx("div",{className:"space-y-2",children:d.jsxs("a",{href:"https://supabase.com/docs/guides/api#api-url-and-keys",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline inline-flex items-center gap-1",children:["Where do I find these?",d.jsx(Hl,{className:"h-3 w-3"})]})}),d.jsx(Le,{onClick:i(()=>a("credentials"),"onClick"),className:"w-full",children:"Continue"})]})]}),r==="credentials"&&d.jsxs(d.Fragment,{children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:"Connect to Supabase"}),d.jsx(si,{children:"Enter your Supabase project credentials"})]}),d.jsxs("div",{className:"space-y-4 py-4",children:[c&&d.jsxs(Va,{variant:"destructive",children:[d.jsx(Dp,{className:"h-4 w-4"}),d.jsx(li,{children:c})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Vn,{htmlFor:"supabase-url",children:"Project URL or ID"}),d.jsxs("div",{className:"relative",children:[d.jsx(Cr,{id:"supabase-url",placeholder:"xxxxx or https://xxxxx.supabase.co",value:o,onChange:i(T=>{s(T.target.value),v(!0)},"onChange"),onBlur:i(()=>v(!0),"onBlur"),className:m&&o?_.valid?"pr-8 border-green-500":"pr-8 border-destructive":""}),m&&o&&_.valid&&d.jsx(no,{className:"absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 text-green-500"})]}),O&&d.jsxs("div",{className:"flex items-start gap-1.5 text-xs text-green-600 dark:text-green-400",children:[d.jsx(no,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),d.jsxs("span",{children:["Will expand to: ",C]})]}),m&&o&&_.message&&!_.valid&&d.jsx("p",{className:"text-xs text-destructive",children:_.message}),(!m||!o)&&d.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter full URL or just the project ID (from Project Settings → API)"})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Vn,{htmlFor:"anon-key",children:"API Key"}),d.jsxs("div",{className:"relative",children:[d.jsx(Cr,{id:"anon-key",type:"password",placeholder:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",value:l,onChange:i(T=>{f(T.target.value),w(!0)},"onChange"),onBlur:i(()=>w(!0),"onBlur"),className:b&&l?j.valid?"pr-8 border-green-500":"pr-8 border-destructive":""}),b&&l&&j.valid&&d.jsx(no,{className:"absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 text-green-500"})]}),b&&l&&j.message&&d.jsx("p",{className:`text-xs ${j.valid?"text-green-600 dark:text-green-400":"text-destructive"}`,children:j.message}),(!b||!l)&&d.jsx("p",{className:"text-xs text-muted-foreground",children:"Anon or publishable key (from Project Settings → API)"})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Le,{variant:"outline",onClick:i(()=>a("welcome"),"onClick"),className:"flex-1",children:"Back"}),d.jsx(Le,{onClick:S,disabled:!_.valid||!j.valid,className:"flex-1",children:"Connect"})]})]})]}),r==="validating"&&d.jsxs(d.Fragment,{children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:"Validating Connection"}),d.jsx(si,{children:"Testing your Supabase credentials..."})]}),d.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[d.jsx(Tc,{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(Mr,{children:[d.jsx(Ir,{children:"Connection Successful!"}),d.jsx(si,{children:"Your Supabase database is now connected"})]}),d.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[d.jsx(Bo,{className:"h-12 w-12 text-green-500 mb-4"}),d.jsx("p",{className:"text-sm text-muted-foreground",children:"Reloading application..."})]})]})]})})}i(xie,"SupabaseSetupWizard");function vze(){const[e,t]=y.useState(!1),n=_d(),r=mAe(),a=i(()=>{confirm("Are you sure you want to clear the database configuration? The app will need to be reconfigured on next launch.")&&(fAe(),window.location.reload())},"handleClearConfig");return d.jsxs(d.Fragment,{children:[d.jsxs(pn,{children:[d.jsxs(ts,{children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(nv,{className:"h-5 w-5"}),d.jsx(ns,{children:"Database Connection"})]}),d.jsx(N4,{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(Bo,{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(Va,{children:[d.jsx(yN,{className:"h-4 w-4"}),d.jsx(li,{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(Le,{variant:"outline",onClick:i(()=>t(!0),"onClick"),className:"flex-1",children:[d.jsx(yN,{className:"h-4 w-4 mr-2"}),"Change Connection"]}),r==="ui"&&d.jsxs(Le,{variant:"destructive",onClick:a,className:"flex-1",children:[d.jsx(py,{className:"h-4 w-4 mr-2"}),"Clear Configuration"]})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(yze,{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(ls,{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(Va,{children:d.jsxs(li,{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(Le,{onClick:i(()=>t(!0),"onClick"),className:"w-full",children:[d.jsx(nv,{className:"h-4 w-4 mr-2"}),"Connect to Supabase"]})]})})]}),d.jsx(xie,{open:e,onComplete:i(()=>t(!1),"onComplete"),canClose:!0})]})}i(vze,"DatabaseSettings");function yze({children:e,className:t}){return d.jsx("label",{className:t,children:e})}i(yze,"Label");const fD=i(()=>d.jsx("div",{className:"max-w-lg mx-auto mt-8",children:d.jsx(vze,{})}),"DatabasePage");fD.path="/database";const hD=i(()=>{const[e,t]=y.useState(!1),{identity:n,refetch:r}=er(),{data:a,refetch:o}=Lw("sales",{id:n?.id}),s=Vt(),l=xn(),{mutate:f}=Lr({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(Zr,{onSubmit:c,record:a,children:d.jsx(bze,{isEditMode:e,setEditMode:t})})})},"SettingsPage"),bze=i(({isEditMode:e,setEditMode:t})=>{const n=Vt(),r=Ea(),a=qt(),{identity:o,refetch:s}=er(),{isDirty:l}=cy(),f=xn(),{mutate:c}=Lr({mutationKey:["signup"],mutationFn:i(async v=>{if(!a)throw new Error("Record not found");return f.salesUpdate(a.id,v)},"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 v=>{c(v)},"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(jte,{source:"avatar",type:"avatar",onSave:m,linkPosition:"right"}),d.jsx(_T,{source:"first_name",isEditMode:e}),d.jsx(_T,{source:"last_name",isEditMode:e}),d.jsx(_T,{source:"email",isEditMode:e})]}),d.jsxs("div",{className:"flex flex-row justify-end gap-2",children:[!e&&d.jsx(d.Fragment,{children:d.jsx(Le,{variant:"outline",type:"button",onClick:p,children:"Change password"})}),d.jsxs(Le,{type:"button",variant:e?"ghost":"outline",onClick:i(()=>t(!e),"onClick"),className:"flex items-center",children:[e?d.jsx(ls,{}):d.jsx(qQ,{}),e?"Cancel":"Edit"]}),e&&d.jsxs(Le,{type:"submit",disabled:!l,variant:"outline",children:[d.jsx(f1,{}),"Save"]})]})]})}),void 0]})},"SettingsForm"),_T=i(({source:e,isEditMode:t})=>t?d.jsx(Bt,{source:e,helperText:!1}):d.jsx("div",{className:"m-2",children:d.jsx(K5e,{source:e})}),"TextRender");hD.path="/settings";function wie(){const e=new Uint8Array(16);return crypto.getRandomValues(e),`ak_live_${Array.from(e).map(n=>n.toString(16).padStart(2,"0")).join("")}`}i(wie,"generateApiKey");async function xze(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(xze,"hashApiKey");const wze=[{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"}],_ze=i(({open:e,onClose:t})=>{const[n,r]=y.useState(null),[a,o]=y.useState(!1),s=xn(),l=Vt(),f=Nn(),{identity:c}=er(),{register:p,handleSubmit:m,watch:v,setValue:b,reset:w}=uy({defaultValues:{name:"",scopes:[],expires_at:""}}),S=Lr({mutationFn:i(async O=>{const E=wie(),T=await xze(E),R=E.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:E}},"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"),C=i(O=>{const E=v("scopes");E.includes(O)?b("scopes",E.filter(T=>T!==O)):b("scopes",[...E,O])},"toggleScope");return d.jsx(fa,{open:e,onOpenChange:_,children:d.jsxs(ha,{className:"sm:max-w-[500px]",children:[d.jsxs(Mr,{children:[d.jsx(Ir,{children:n?"API Key Created":"Create API Key"}),d.jsx(si,{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(Va,{children:d.jsx(li,{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(Vn,{children:"Your API Key"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx(Cr,{value:n,readOnly:!0,className:"font-mono text-sm"}),d.jsx(Le,{type:"button",variant:"outline",size:"icon",onClick:j,children:a?d.jsx(Bo,{className:"h-4 w-4 text-green-500"}):d.jsx(MM,{className:"h-4 w-4"})})]})]}),d.jsx("div",{className:"flex justify-end",children:d.jsx(Le,{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(Vn,{htmlFor:"name",children:"Name"}),d.jsx(Cr,{id:"name",placeholder:"e.g., Production API Key",...p("name",{required:!0})})]}),d.jsxs("div",{className:"space-y-2",children:[d.jsx(Vn,{children:"Scopes"}),d.jsx("div",{className:"space-y-2",children:wze.map(O=>d.jsxs("div",{className:"flex items-center space-x-2",children:[d.jsx(Gp,{id:O.value,checked:v("scopes").includes(O.value),onCheckedChange:i(()=>C(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(Vn,{htmlFor:"expires_at",children:"Expiration (optional)"}),d.jsx(Cr,{id:"expires_at",type:"date",...p("expires_at")})]}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(Le,{type:"button",variant:"outline",onClick:_,children:"Cancel"}),d.jsx(Le,{type:"submit",disabled:S.isPending,children:"Create"})]})]})})]})})},"CreateApiKeyDialog");var Sze=Symbol("radix.slottable");function jze(e){const t=i(({children:n})=>d.jsx(d.Fragment,{children:n}),"Slottable2");return t.displayName=`${e}.Slottable`,t.__radixId=Sze,t}i(jze,"createSlottable");var _ie="AlertDialog",[Cze,DBe]=ia(_ie,[oX]),dl=oX(),Sie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=dl(t);return d.jsx(vy,{...r,...n,modal:!0})},"AlertDialog$1");Sie.displayName=_ie;var Eze="AlertDialogTrigger",Oze=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(_X,{...a,...r,ref:t})});Oze.displayName=Eze;var kze="AlertDialogPortal",jie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=dl(t);return d.jsx(yy,{...r,...n})},"AlertDialogPortal$1");jie.displayName=kze;var Rze="AlertDialogOverlay",Cie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(by,{...a,...r,ref:t})});Cie.displayName=Rze;var hh="AlertDialogContent",[Aze,Tze]=Cze(hh),Nze=jze("AlertDialogContent"),Eie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,children:r,...a}=e,o=dl(n),s=y.useRef(null),l=Xt(t,s),f=y.useRef(null);return d.jsx(sje,{contentName:hh,titleName:Oie,docsSlug:"alert-dialog",children:d.jsx(Aze,{scope:n,cancelRef:f,children:d.jsxs(xy,{role:"alertdialog",...o,...a,ref:l,onOpenAutoFocus:Je(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(Nze,{children:r}),d.jsx(Dze,{contentRef:s})]})})})});Eie.displayName=hh;var Oie="AlertDialogTitle",kie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(v1,{...a,...r,ref:t})});kie.displayName=Oie;var Rie="AlertDialogDescription",Aie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(y1,{...a,...r,ref:t})});Aie.displayName=Rie;var Pze="AlertDialogAction",Tie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=dl(n);return d.jsx(wy,{...a,...r,ref:t})});Tie.displayName=Pze;var Nie="AlertDialogCancel",Pie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,{cancelRef:a}=Tze(Nie,n),o=dl(n),s=Xt(t,a);return d.jsx(wy,{...o,...r,ref:s})});Pie.displayName=Nie;var Dze=i(({contentRef:e})=>{const t=`\`${hh}\` requires a description for the component to be accessible for screen reader users.
155
155
 
156
156
  You can add a description to the \`${hh}\` by passing a \`${Rie}\` 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
  ${v?"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(HQ,{className:"w-12 h-12 mx-auto mb-4 text-gray-400"}),v?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(Le,{size:"sm",onClick:w,disabled:!e.some(j=>j.status==="pending"),children:"Upload All"}),d.jsx(Le,{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,C)=>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(Qwe,{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(Le,{size:"sm",onClick:i(()=>b(C),"onClick"),children:"Upload"}),j.status==="uploading"&&d.jsx(Tc,{className:"w-5 h-5 animate-spin text-primary"}),j.status==="success"&&d.jsx(Bo,{className:"w-5 h-5 text-green-500"}),j.status==="error"&&d.jsx(ls,{className:"w-5 h-5 text-red-500"})]})]}),j.status==="uploading"&&d.jsx(t_,{value:j.progress,className:"h-1"}),j.status==="error"&&j.error&&d.jsxs("p",{className:"text-sm text-red-500",children:["Error: ",j.error]})]},C))})]})]})]}),d.jsxs(pn,{children:[d.jsx(ts,{children:d.jsx(ns,{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"),pD=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(Fte,{defaultValue:"ingestion",children:[d.jsxs(Lte,{className:"mb-4",children:[d.jsx(sc,{value:"ingestion",children:"Ingestion Channels"}),d.jsx(sc,{value:"file-upload",children:"File Upload"}),d.jsx(sc,{value:"api-keys",children:"API Keys"}),d.jsx(sc,{value:"webhooks",children:"Webhooks (Outbound)"})]}),d.jsx(lc,{value:"ingestion",children:d.jsx(Zze,{})}),d.jsx(lc,{value:"file-upload",children:d.jsx(eBe,{})}),d.jsx(lc,{value:"api-keys",children:d.jsx(Vze,{})}),d.jsx(lc,{value:"webhooks",children:d.jsx(Kze,{})})]})]}),"IntegrationsPage");pD.path="/integrations";var tBe={"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 nBe={"ra-supabase":{auth:{password_reset:"Check your emails for a Reset Password message."}}},rBe=wQ(()=>bfe(lQ,tBe,nBe),"en",[{locale:"en",name:"English"}],{allowMissing:!0}),aBe=i(()=>{const e=xn(),{data:t,error:n,isPending:r}=Xr({queryKey:["init"],queryFn:i(async()=>e.isInitialized(),"queryFn")});return r?d.jsx(vie,{}):n?d.jsx(Ex,{}):t?d.jsx(Ex,{}):d.jsx(ww,{to:"/sign-up"})},"StartPage");async function iBe(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(iBe,"checkDatabaseHealth");function oBe({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(Va,{variant:"destructive",children:[d.jsx(Dp,{className:"h-4 w-4"}),d.jsx(V4,{children:"Database Schema Not Configured"}),d.jsx(li,{children:"Your Supabase database is connected, but the CRM schema hasn't been set up yet."})]}),d.jsxs(pn,{children:[d.jsxs(ts,{children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(nv,{className:"h-5 w-5"}),d.jsx(ns,{children:"Setup Instructions"})]}),d.jsx(N4,{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(Hl,{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(Hl,{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(Le,{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(Hl,{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(Bo,{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(Bo,{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(Bo,{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(Le,{onClick:i(()=>window.location.reload(),"onClick"),className:"w-full mt-4",children:"Reload Page"})]})]})]}),d.jsxs(pn,{children:[d.jsx(ts,{children:d.jsx(ns,{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(Hl,{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(Hl,{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(Hl,{className:"h-4 w-4"}),"Supabase CLI Documentation"]})]})]})]})}i(oBe,"DatabaseSetupGuide");function sBe({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 iBe(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=_d();if(s)return d.jsx(oBe,{missingTables:n.missingTables,supabaseUrl:s.url})}return d.jsx(d.Fragment,{children:e})}i(sBe,"DatabaseHealthCheck");const lBe=i(({contactGender:e=mJ,companySectors:t=cJ,dealCategories:n=fJ,dealPipelineStatuses:r=dJ,dealStages:a=uJ,darkModeLogo:o=oJ,lightModeLogo:s=sJ,noteStatuses:l=hJ,taskTypes:f=pJ,title:c=lJ,dataProvider:p=nze,authProvider:m=zUe,disableTelemetry:v,...b})=>(y.useEffect(()=>{if(v||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}`},[v]),d.jsx(yke,{contactGender:e,companySectors:t,dealCategories:n,dealPipelineStatuses:r,dealStages:a,darkModeLogo:o,lightModeLogo:s,noteStatuses:l,taskTypes:f,title:c,children:d.jsx(sBe,{dataProvider:p,children:d.jsxs(Ske,{dataProvider:p,authProvider:m,store:RG(void 0,"CRM"),layout:qUe,loginPage:aBe,i18nProvider:rBe,dashboard:AUe,requireAuth:!0,disableTelemetry:!0,...b,children:[d.jsxs(sN,{noLayout:!0,children:[d.jsx(Qn,{path:dD.path,element:d.jsx(dD,{})}),d.jsx(Qn,{path:aP.path,element:d.jsx(aP,{})}),d.jsx(Qn,{path:tP.path,element:d.jsx(tP,{})}),d.jsx(Qn,{path:iP.path,element:d.jsx(iP,{})}),d.jsx(Qn,{path:oP.path,element:d.jsx(oP,{})})]}),d.jsxs(sN,{children:[d.jsx(Qn,{path:hD.path,element:d.jsx(hD,{})}),d.jsx(Qn,{path:fD.path,element:d.jsx(fD,{})}),d.jsx(Qn,{path:pD.path,element:d.jsx(pD,{})})]}),d.jsx(Hi,{name:"deals",...NUe}),d.jsx(Hi,{name:"contacts",...M6e}),d.jsx(Hi,{name:"companies",...L3e}),d.jsx(Hi,{name:"companyNotes"}),d.jsx(Hi,{name:"contactNotes"}),d.jsx(Hi,{name:"dealNotes"}),d.jsx(Hi,{name:"tasks"}),d.jsx(Hi,{name:"sales",...pze}),d.jsx(Hi,{name:"tags"})]})})})),"CRM"),cBe=[{id:"prospect",name:"Prospect"},{id:"customer",name:"Customer"},{id:"churned",name:"Churned"},{id:"lost",name:"Lost"},{id:"archived",name:"Archived"}],uBe=[{id:"customer",name:"Customer"},{id:"prospect",name:"Prospect"},{id:"partner",name:"Partner"},{id:"vendor",name:"Vendor"},{id:"competitor",name:"Competitor"},{id:"internal",name:"Internal"}],dBe=[{id:"qualified",name:"Qualified"},{id:"unqualified",name:"Unqualified"},{id:"duplicate",name:"Duplicate"},{id:"spam",name:"Spam"},{id:"test",name:"Test"}],fBe=[{id:"0-1M",name:"Under $1M"},{id:"1M-10M",name:"$1M - $10M"},{id:"10M-50M",name:"$10M - $50M"},{id:"50M-100M",name:"$50M - $100M"},{id:"100M+",name:"Over $100M"},{id:"unknown",name:"Unknown"}],hBe=[{id:"healthy",name:"Healthy",color:"#10b981"},{id:"risky",name:"Risky",color:"#f59e0b"},{id:"dead",name:"Dead",color:"#ef4444"},{id:"unknown",name:"Not Checked",color:"#6b7280"}],pBe=[{id:"engaged",name:"Engaged",color:"#10b981"},{id:"quiet",name:"Quiet",color:"#3b82f6"},{id:"at_risk",name:"At Risk",color:"#f59e0b"},{id:"unresponsive",name:"Unresponsive",color:"#ef4444"},{id:"unknown",name:"Unknown",color:"#6b7280"}],mBe=i(()=>{const[e,t]=y.useState(()=>!hAe());return e?d.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:d.jsx(xie,{open:!0,onComplete:i(()=>{t(!1)},"onComplete"),canClose:!1})}):d.jsx(lBe,{companyLifecycleStages:cBe,companyTypes:uBe,companyQualificationStatuses:dBe,companyRevenueRanges:fBe,externalHeartbeatStatuses:hBe,internalHeartbeatStatuses:pBe})},"App");Kse.createRoot(document.getElementById("root")).render(d.jsx(y.StrictMode,{children:d.jsx(mBe,{})}));export{er as $,sl as A,Jn as B,$K as C,AY as D,E4 as E,Zo as F,j4 as G,fn as H,Jo as I,UJ as J,Se as K,VK as L,pge as M,Cr as N,mw as O,ie as P,kG as Q,pd as R,il as S,ur as T,go as U,pn as V,Wn as W,Mp as X,lr as Y,Sd as Z,Hp as _,dy as a,Le as a0,fa as a1,ha as a2,Ir as a3,gd as a4,vc as a5,Bt as a6,Zn as a7,Vp as a8,o5e as a9,Zye as aA,W4e as aB,oh as aC,Zte as aD,G4 as aE,Fw as aF,Lr as aG,hd as aH,mne as aI,Vn as aJ,D4 as aK,Dy as aL,A4 as aM,ln as aN,P4 as aO,ANe as aP,q1 as aQ,MP as aa,Ra as ab,Ba as ac,Bne as ad,xn as ae,Gn as af,Nn as ag,Zr as ah,K1 as ai,xd as aj,Vt as ak,dM as al,cne as am,qt as an,K4 as ao,$r as ap,ap as aq,V1 as ar,t_ as as,Ic as at,X4e as au,to as av,us as aw,SY as ax,Jte as ay,pc as az,vM as b,jK as c,oge as d,Sa as e,Ge as f,CM as g,Ac as h,xt as i,Rc as j,r1 as k,Ct as l,d as m,nl as n,da as o,Ry as p,DPe as q,y as r,IPe as s,LPe as t,pa as u,$Pe as v,cl as w,zw as x,Gt as y,md as z};
166
- //# sourceMappingURL=index-B1VkO6yf.js.map
166
+ //# sourceMappingURL=index-BrW7DPxi.js.map