realtimex-crm 0.14.0 → 0.14.2

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.
@@ -108,7 +108,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
108
108
  - less than the value passed to \`max\` (or ${s3} if no \`max\` prop is set)
109
109
  - \`null\` or \`undefined\` if the progress is indeterminate.
110
110
 
111
- Defaulting to \`null\`.`}i(F3e,"getInvalidValueError");var L3e=hne,$3e=mne;function d_({className:e,value:t,...n}){return u.jsx(L3e,{"data-slot":"progress",className:xe("bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",e),...n,children:u.jsx($3e,{"data-slot":"progress-indicator",className:"bg-primary h-full w-full flex-1 transition-all",style:{transform:`translateX(-${100-(t||0)}%)`}})})}i(d_,"Progress");const q3e=i(()=>{const e=Ft();if(!e)return null;const t=e.internal_heartbeat_score!==void 0||e.internal_heartbeat_status||e.days_since_last_activity!==void 0,n=e.external_heartbeat_status||e.external_heartbeat_checked_at;return!t&&!n?null:u.jsxs(fi,{title:"Company Health",children:[t&&u.jsxs("div",{className:"mb-4",children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(p1,{className:"w-4 h-4 text-muted-foreground"}),u.jsx("span",{className:"font-medium text-sm",children:"Internal Engagement"})]}),e.internal_heartbeat_score!==void 0&&u.jsxs("div",{className:"mb-2",children:[u.jsxs("div",{className:"flex items-center justify-between mb-1",children:[u.jsx("span",{className:"text-xs text-muted-foreground",children:"Engagement Score"}),u.jsxs("span",{className:"text-xs font-medium",children:[e.internal_heartbeat_score,"/100"]})]}),u.jsx(d_,{value:e.internal_heartbeat_score,className:"h-2"})]}),e.internal_heartbeat_status&&u.jsx("div",{className:"mb-2",children:u.jsx(U3e,{status:e.internal_heartbeat_status})}),e.days_since_last_activity!==void 0&&u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Last activity:"," ",e.days_since_last_activity===0?"Today":e.days_since_last_activity===1?"Yesterday":`${e.days_since_last_activity} days ago`]}),e.internal_heartbeat_updated_at&&u.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Updated"," ",nd(new Date(e.internal_heartbeat_updated_at),new Date,{addSuffix:!0})]})]}),n&&u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(ZM,{className:"w-4 h-4 text-muted-foreground"}),u.jsx("span",{className:"font-medium text-sm",children:"External Health"})]}),e.external_heartbeat_status&&u.jsx("div",{className:"mb-2",children:u.jsx(z3e,{status:e.external_heartbeat_status})}),e.external_heartbeat_checked_at&&u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Last checked"," ",nd(new Date(e.external_heartbeat_checked_at),new Date,{addSuffix:!0})]})]})]})},"CompanyHealthCard"),U3e=i(({status:e})=>{const n={engaged:{variant:"default",label:"Engaged"},quiet:{variant:"secondary",label:"Quiet"},at_risk:{variant:"outline",label:"At Risk"},unresponsive:{variant:"destructive",label:"Unresponsive"}}[e]||{variant:"outline",label:e};return u.jsx(Kn,{variant:n.variant,className:"text-xs",children:n.label})},"InternalStatusBadge$1"),z3e=i(({status:e})=>{const n={healthy:{variant:"default",label:"Healthy"},risky:{variant:"outline",label:"Risky"},dead:{variant:"destructive",label:"Dead"},unknown:{variant:"secondary",label:"Unknown"}}[e]||{variant:"outline",label:e};return u.jsx(Kn,{variant:n.variant,className:"text-xs",children:n.label})},"ExternalStatusBadge"),vne=i(({link:e="edit"})=>{const t=Ft();return t?u.jsxs("div",{className:"hidden sm:block w-[250px] min-w-[250px] space-y-4",children:[u.jsx("div",{className:"flex flex-row space-x-1",children:e==="edit"?u.jsx(lne,{label:"Edit Company"}):u.jsx(cne,{label:"Show Company"})}),u.jsx(q3e,{}),u.jsx(B3e,{record:t}),u.jsx(V3e,{record:t}),u.jsx(H3e,{record:t}),u.jsx(W3e,{record:t}),e!=="edit"&&u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"mt-6 pt-6 border-t hidden sm:flex flex-col gap-2 items-start",children:u.jsx(A3e,{})}),u.jsx("div",{className:"mt-6 pt-6 border-t hidden sm:flex flex-col gap-2 items-start",children:u.jsx(c_,{className:"h-6 cursor-pointer hover:bg-destructive/10! text-destructive! border-destructive! focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",size:"sm"})})]})]}):null},"CompanyAside"),B3e=i(({record:e})=>!e.website&&!e.linkedin_url&&!e.phone_number?null:u.jsxs(fi,{title:"Company Info",children:[e.website&&u.jsxs("div",{className:"flex flex-row items-center gap-1 min-h-[24px]",children:[u.jsx(m1e,{className:"w-4 h-4"}),u.jsx(k3e,{source:"website",target:"_blank",rel:"noopener",content:e.website.replace("http://","").replace("https://","")})]}),e.linkedin_url&&u.jsxs("div",{className:"flex flex-row items-center gap-1 min-h-[24px]",children:[u.jsx(JM,{className:"w-4 h-4"}),u.jsx("a",{className:"underline hover:no-underline",href:e.linkedin_url,target:"_blank",rel:"noopener noreferrer",title:e.linkedin_url,children:"LinkedIn"})]}),e.phone_number&&u.jsxs("div",{className:"flex flex-row items-center gap-1 min-h-[24px]",children:[u.jsx(n4,{className:"w-4 h-4"}),u.jsx(Ir,{source:"phone_number"})]})]}),"CompanyInfo"),H3e=i(({record:e})=>!e.revenue&&!e.id?null:u.jsxs(fi,{title:"Context",children:[e.sector&&u.jsxs("span",{children:["Sector: ",u.jsx(Ir,{source:"sector"})]}),e.size&&u.jsxs("span",{children:["Size: ",u.jsx(R3e,{source:"size",choices:W4})]}),e.revenue&&u.jsxs("span",{children:["Revenue: ",u.jsx(Ir,{source:"revenue"})]}),e.tax_identifier&&u.jsxs("span",{children:["Tax Identifier: ",u.jsx(Ir,{source:"tax_identifier"})]})]}),"ContextInfo"),V3e=i(({record:e})=>!e.address&&!e.city&&!e.zipcode&&!e.stateAbbr?null:u.jsxs(fi,{title:"Main Address",noGap:!0,children:[u.jsx(Ir,{source:"address"}),u.jsx(Ir,{source:"city"}),u.jsx(Ir,{source:"zipcode"}),u.jsx(Ir,{source:"stateAbbr"}),u.jsx(Ir,{source:"country"})]}),"AddressInfo"),W3e=i(({record:e})=>{if(!e.created_at&&!e.sales_id&&!e.description&&!e.context_links)return null;const t=i(n=>new URL(n.startsWith("http")?n:`https://${n}`).hostname,"getBaseURL");return u.jsxs(fi,{title:"Additional Info",children:[e.description&&u.jsx("p",{className:"text-sm mb-1",children:e.description}),e.context_links&&Array.isArray(e.context_links)&&u.jsx("div",{className:"flex flex-col",children:e.context_links.map((n,r)=>n?u.jsx("a",{className:"text-sm underline hover:no-underline mb-1",href:n.startsWith("http")?n:`https://${n}`,target:"_blank",rel:"noopener noreferrer",title:n,children:t(n)},r):null)}),e.sales_id!==null&&u.jsxs("div",{className:"inline-flex text-sm text-muted-foreground mb-1",children:["Followed by ",u.jsx(xn,{source:"sales_id",reference:"sales",record:e,children:u.jsx(Bc,{})})]}),e.created_at&&u.jsxs("p",{className:"text-sm text-muted-foreground mb-1",children:["Added on"," ",u.jsx(cd,{source:"created_at",record:e,options:{year:"numeric",month:"long",day:"numeric"}})]})]})},"AdditionalInfo"),G3e=i(()=>u.jsx(DM,{children:u.jsx(K3e,{})}),"CompanyShow"),K3e=i(()=>{const{record:e,isPending:t}=MM(),n=Ra(),a=MD("/companies/:id/show/:tab")?.params?.tab||"activity",s=i(o=>{if(o!==a){if(o==="activity"){n(`/companies/${e?.id}/show`);return}n(`/companies/${e?.id}/show/${o}`)}},"handleTabChange");return t||!e?null:u.jsxs("div",{className:"mt-2 flex pb-2 gap-8",children:[u.jsx("div",{className:"flex-1",children:u.jsx(un,{children:u.jsxs(Un,{children:[u.jsxs("div",{className:"flex mb-3",children:[u.jsx(kd,{}),u.jsx("h5",{className:"text-xl ml-2 flex-1",children:e.name})]}),u.jsxs(Gte,{defaultValue:a,onValueChange:s,children:[u.jsxs(Kte,{className:"grid w-full grid-cols-4",children:[u.jsx(cc,{value:"activity",children:"Activity"}),u.jsx(cc,{value:"contacts",children:e.nb_contacts?e.nb_contacts===1?"1 Contact":`${e.nb_contacts} Contacts`:"No Contacts"}),u.jsx(cc,{value:"notes",children:e.nb_notes?e.nb_notes===1?"1 Note":`${e.nb_notes} Notes`:"Notes"}),e.nb_deals?u.jsx(cc,{value:"deals",children:e.nb_deals===1?"1 deal":`${e.nb_deals} deals`}):null]}),u.jsx(uc,{value:"activity",className:"pt-2",children:u.jsx(nne,{companyId:e.id,context:"company"})}),u.jsx(uc,{value:"contacts",children:e.nb_contacts?u.jsx(Gu,{reference:"contacts_summary",target:"company_id",sort:{field:"last_name",order:"ASC"},children:u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex flex-row justify-end space-x-2 mt-1",children:[!!e.nb_contacts&&u.jsx(H4,{fields:["last_name","first_name","last_seen"]}),u.jsx(FH,{})]}),u.jsx(Y3e,{})]})}):u.jsx("div",{className:"flex flex-col gap-4",children:u.jsx("div",{className:"flex flex-row justify-end space-x-2 mt-1",children:u.jsx(FH,{})})})}),u.jsx(uc,{value:"notes",children:u.jsx(Gu,{reference:"companyNotes",target:"company_id",sort:{field:"date",order:"DESC"},empty:u.jsx(l_,{reference:"companies",className:"mt-4"}),children:u.jsx(a3,{reference:"companies"})})}),u.jsx(uc,{value:"deals",children:e.nb_deals?u.jsx(Gu,{reference:"deals",target:"company_id",sort:{field:"name",order:"ASC"},children:u.jsx(Q3e,{})}):null})]})]})})}),u.jsx(vne,{})]})},"CompanyShowContent"),Y3e=i(()=>{const e=Ur(),{data:t,error:n,isPending:r}=Xn();if(r||n)return null;const a=Date.now();return u.jsx("div",{className:"pt-0",children:t.map(s=>u.jsx(Ya,{value:s,children:u.jsx("div",{className:"p-0 text-sm",children:u.jsxs(nn,{to:`/contacts/${s.id}/show`,state:{from:e.pathname},className:"flex items-center justify-between hover:bg-muted py-2 transition-colors",children:[u.jsx("div",{className:"mr-4",children:u.jsx(ho,{})}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"font-medium",children:`${s.first_name} ${s.last_name}`}),u.jsxs("div",{className:"text-sm text-muted-foreground",children:[s.title,s.nb_tasks?` - ${s.nb_tasks} task${s.nb_tasks>1?"s":""}`:"","   ",u.jsx(rne,{})]})]}),s.last_seen&&u.jsx("div",{className:"text-right",children:u.jsxs("div",{className:"text-sm text-muted-foreground",children:["last activity ",nd(s.last_seen,a)," ago"," ",u.jsx(zy,{status:s.status})]})})]})})},s.id))})},"ContactsIterator"),FH=i(()=>{const e=Ft();return u.jsx(Le,{variant:"outline",asChild:!0,size:"sm",className:"h-9",children:u.jsxs(nn,{to:"/contacts/create",state:e?{record:{company_id:e.id}}:void 0,className:"flex items-center gap-2",children:[u.jsx(N_e,{className:"h-4 w-4"}),"Add contact"]})})},"CreateRelatedContactButton"),Q3e=i(()=>{const{data:e,error:t,isPending:n}=Xn(),{dealStages:r}=la();if(n||t)return null;const a=Date.now();return u.jsx("div",{children:u.jsx("div",{children:e.map(s=>u.jsx("div",{className:"p-0 text-sm",children:u.jsxs(nn,{to:`/deals/${s.id}/show`,className:"flex items-center justify-between hover:bg-muted py-2 px-4 transition-colors",children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"font-medium",children:s.name}),u.jsxs("div",{className:"text-sm text-muted-foreground",children:[d3e(r,s.stage),","," ",s.amount.toLocaleString("en-US",{notation:"compact",style:"currency",currency:"USD",currencyDisplay:"narrowSymbol",minimumSignificantDigits:3}),s.category?`, ${s.category}`:""]})]}),u.jsx("div",{className:"text-right",children:u.jsxs("div",{className:"text-sm text-muted-foreground",children:["last activity ",nd(s.updated_at,a)," ago"," "]})})]})},s.id))})})},"DealsIterator"),o3=i(()=>u.jsxs("div",{role:"toolbar",className:"sticky flex pt-4 pb-4 md:pb-0 bottom-0 bg-linear-to-b from-transparent to-card to-10% flex-row justify-end gap-2",children:[u.jsx(t_,{}),u.jsx(jd,{})]}),"FormToolbar"),X3e=i(()=>u.jsx(wM,{actions:!1,redirect:"show",transform:i(e=>(e.website&&!e.website.startsWith("http")&&(e.website=`https://${e.website}`),e),"transform"),children:u.jsxs("div",{className:"mt-2 flex gap-8",children:[u.jsx(zr,{className:"flex flex-1 flex-col gap-4 pb-2",children:u.jsx(un,{children:u.jsxs(Un,{children:[u.jsx(Ite,{}),u.jsx(o3,{})]})})}),u.jsx(vne,{link:"show"})]})}),"CompanyEdit"),Z3e={list:xPe,create:$4e,edit:X3e,show:G3e};var f_="Switch",[J3e,sHe]=oa(f_),[e5e,t5e]=J3e(f_),yne=y.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:a,defaultChecked:s,required:o,disabled:l,value:f="on",onCheckedChange:c,form:p,...m}=e,[v,b]=y.useState(null),w=Xt(t,k=>b(k)),S=y.useRef(!1),_=v?p||!!v.closest("form"):!0,[j,C]=Fi({prop:a,defaultProp:s??!1,onChange:c,caller:f_});return u.jsxs(e5e,{scope:n,checked:j,disabled:l,children:[u.jsx(mt.button,{type:"button",role:"switch","aria-checked":j,"aria-required":o,"data-state":_ne(j),"data-disabled":l?"":void 0,disabled:l,value:f,...m,ref:w,onClick:Je(e.onClick,k=>{C(E=>!E),_&&(S.current=k.isPropagationStopped(),S.current||k.stopPropagation())})}),_&&u.jsx(wne,{control:v,bubbles:!S.current,name:r,value:f,checked:j,required:o,disabled:l,form:p,style:{transform:"translateX(-100%)"}})]})});yne.displayName=f_;var bne="SwitchThumb",xne=y.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,a=t5e(bne,n);return u.jsx(mt.span,{"data-state":_ne(a.checked),"data-disabled":a.disabled?"":void 0,...r,ref:t})});xne.displayName=bne;var n5e="SwitchBubbleInput",wne=y.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...a},s)=>{const o=y.useRef(null),l=Xt(o,s),f=W1(n),c=O1(t);return y.useEffect(()=>{const p=o.current;if(!p)return;const m=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(m,"checked").set;if(f!==n&&b){const w=new Event("click",{bubbles:r});b.call(p,n),p.dispatchEvent(w)}},[f,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...a,tabIndex:-1,ref:l,style:{...a.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});wne.displayName=n5e;function _ne(e){return e?"checked":"unchecked"}i(_ne,"getState$2");var r5e=yne,a5e=xne;function l3({className:e,...t}){return u.jsx(r5e,{"data-slot":"switch",className:xe("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:u.jsx(a5e,{"data-slot":"switch-thumb",className:xe("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}i(l3,"Switch");const ew=i(e=>{const{className:t,defaultValue:n=!1,format:r,label:a,helperText:s,onBlur:o,onChange:l,onFocus:f,readOnly:c,disabled:p,parse:m,resource:v,source:b,validate:w,...S}=e,{id:_,field:j,isRequired:C}=Pc({defaultValue:n,format:r,parse:m,resource:v,source:b,onBlur:o,onChange:l,type:"checkbox",validate:w,disabled:p,readOnly:c,...S}),k=y.useCallback(E=>{j.onChange(E),j.onBlur()},[j]);return u.jsxs(eo,{className:t,id:_,name:j.name,children:[u.jsxs("div",{className:"flex items-center space-x-2",children:[u.jsx(l3,{id:_,checked:!!j.value,onFocus:f,onCheckedChange:k}),u.jsx(al,{htmlFor:_,children:u.jsx(ma,{label:a,source:b,resource:v,isRequired:C})})]}),u.jsx(to,{helperText:s}),u.jsx(ul,{})]})},"BooleanInput");var c3="Radio",[i5e,Sne]=oa(c3),[s5e,o5e]=i5e(c3),jne=y.forwardRef((e,t)=>{const{__scopeRadio:n,name:r,checked:a=!1,required:s,disabled:o,value:l="on",onCheck:f,form:c,...p}=e,[m,v]=y.useState(null),b=Xt(t,_=>v(_)),w=y.useRef(!1),S=m?c||!!m.closest("form"):!0;return u.jsxs(s5e,{scope:n,checked:a,disabled:o,children:[u.jsx(mt.button,{type:"button",role:"radio","aria-checked":a,"data-state":One(a),"data-disabled":o?"":void 0,disabled:o,value:l,...p,ref:b,onClick:Je(e.onClick,_=>{a||f?.(),S&&(w.current=_.isPropagationStopped(),w.current||_.stopPropagation())})}),S&&u.jsx(kne,{control:m,bubbles:!w.current,name:r,value:l,checked:a,required:s,disabled:o,form:c,style:{transform:"translateX(-100%)"}})]})});jne.displayName=c3;var Cne="RadioIndicator",Ene=y.forwardRef((e,t)=>{const{__scopeRadio:n,forceMount:r,...a}=e,s=o5e(Cne,n);return u.jsx(ba,{present:r||s.checked,children:u.jsx(mt.span,{"data-state":One(s.checked),"data-disabled":s.disabled?"":void 0,...a,ref:t})})});Ene.displayName=Cne;var l5e="RadioBubbleInput",kne=y.forwardRef(({__scopeRadio:e,control:t,checked:n,bubbles:r=!0,...a},s)=>{const o=y.useRef(null),l=Xt(o,s),f=W1(n),c=O1(t);return y.useEffect(()=>{const p=o.current;if(!p)return;const m=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(m,"checked").set;if(f!==n&&b){const w=new Event("click",{bubbles:r});b.call(p,n),p.dispatchEvent(w)}},[f,n,r]),u.jsx(mt.input,{type:"radio","aria-hidden":!0,defaultChecked:n,...a,tabIndex:-1,ref:l,style:{...a.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});kne.displayName=l5e;function One(e){return e?"checked":"unchecked"}i(One,"getState$1");var c5e=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],h_="RadioGroup",[u5e,oHe]=oa(h_,[Hp,Sne]),Rne=Hp(),Ane=Sne(),[d5e,f5e]=u5e(h_),Tne=y.forwardRef((e,t)=>{const{__scopeRadioGroup:n,name:r,defaultValue:a,value:s,required:o=!1,disabled:l=!1,orientation:f,dir:c,loop:p=!0,onValueChange:m,...v}=e,b=Rne(n),w=Ny(c),[S,_]=Fi({prop:s,defaultProp:a??null,onChange:m,caller:h_});return u.jsx(d5e,{scope:n,name:r,required:o,disabled:l,value:S,onValueChange:_,children:u.jsx(_4,{asChild:!0,...b,orientation:f,dir:w,loop:p,children:u.jsx(mt.div,{role:"radiogroup","aria-required":o,"aria-orientation":f,"data-disabled":l?"":void 0,dir:w,...v,ref:t})})})});Tne.displayName=h_;var Nne="RadioGroupItem",Pne=y.forwardRef((e,t)=>{const{__scopeRadioGroup:n,disabled:r,...a}=e,s=f5e(Nne,n),o=s.disabled||r,l=Rne(n),f=Ane(n),c=y.useRef(null),p=Xt(t,c),m=s.value===a.value,v=y.useRef(!1);return y.useEffect(()=>{const b=i(S=>{c5e.includes(S.key)&&(v.current=!0)},"handleKeyDown"),w=i(()=>v.current=!1,"handleKeyUp");return document.addEventListener("keydown",b),document.addEventListener("keyup",w),()=>{document.removeEventListener("keydown",b),document.removeEventListener("keyup",w)}},[]),u.jsx(S4,{asChild:!0,...l,focusable:!o,active:m,children:u.jsx(jne,{disabled:o,required:s.required,checked:m,...f,...a,name:s.name,ref:p,onCheck:i(()=>s.onValueChange(a.value),"onCheck"),onKeyDown:Je(b=>{b.key==="Enter"&&b.preventDefault()}),onFocus:Je(a.onFocus,()=>{v.current&&c.current?.click()})})})});Pne.displayName=Nne;var h5e="RadioGroupIndicator",Dne=y.forwardRef((e,t)=>{const{__scopeRadioGroup:n,...r}=e,a=Ane(n);return u.jsx(Ene,{...a,...r,ref:t})});Dne.displayName=h5e;var p5e=Tne,m5e=Pne,g5e=Dne;function v5e({className:e,...t}){return u.jsx(p5e,{"data-slot":"radio-group",className:xe("grid gap-3",e),...t})}i(v5e,"RadioGroup");function y5e({className:e,...t}){return u.jsx(m5e,{"data-slot":"radio-group-item",className:xe("border-input text-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 aspect-square size-4 shrink-0 rounded-full border shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:u.jsx(g5e,{"data-slot":"radio-group-indicator",className:"relative flex items-center justify-center",children:u.jsx(ON,{className:"fill-primary absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2"})})})}i(y5e,"RadioGroupItem");const b5e=i(e=>{const{choices:t,isFetching:n,isLoading:r,isPending:a,resource:s,source:o,format:l,onBlur:f,onChange:c,parse:p,validate:m,disabled:v,readOnly:b,optionText:w,optionValue:S="id",translateChoice:_,disableValue:j="disabled",className:C,helperText:k,label:E,row:T,...R}=e,{allChoices:A,isPending:N,error:D,resource:M,source:I}=$M({choices:t,isFetching:n,isLoading:r,isPending:a,resource:s,source:o});if(I===void 0)throw new Error("If you're not wrapping the RadioButtonGroupInput inside a ReferenceArrayInput, you must provide the source prop");if(!N&&!D&&A===void 0)throw new Error("If you're not wrapping the RadioButtonGroupInput inside a ReferenceArrayInput, you must provide the choices prop");const{id:F,field:L,isRequired:q}=Pc({format:l,onBlur:f,onChange:c,parse:p,resource:M,source:I,validate:m,disabled:v,readOnly:b,...R}),{getChoiceText:z,getChoiceValue:$,getDisableValue:H}=l1({optionText:w,optionValue:S,translateChoice:_,disableValue:j});return N?u.jsx(cn,{className:"w-full h-9"}):u.jsxs(eo,{id:F,className:C,name:L.name,children:[E&&u.jsx(al,{children:u.jsx(ma,{label:E,source:I,resource:M,isRequired:q})}),u.jsx(Iy,{children:u.jsx(v5e,{...R,value:L.value||"",onValueChange:L.onChange,className:xe("flex",T?"flex-row gap-4":"flex-col gap-2"),disabled:v||b,children:A?.map(U=>{const W=$(U),V=v||b||H(U);return u.jsxs("div",{className:"flex items-center space-x-2",children:[u.jsx(y5e,{value:W,id:`${F}-${W}`,disabled:V}),u.jsx(Gn,{htmlFor:`${F}-${W}`,className:xe("text-sm font-normal cursor-pointer",V&&"opacity-50 cursor-not-allowed"),children:z(U)})]},W)})})}),u.jsx(to,{helperText:k}),u.jsx(ul,{})]})},"RadioButtonGroupInput"),x5e=i(({validate:e})=>{const[t]=IM(),{identity:n}=Yn(),r=Ht(),a=i(async s=>{if(s)try{return await t("companies",{data:{name:s,sales_id:n?.id,created_at:new Date().toISOString()}},{returnPromise:!0})}catch{r("An error occurred while creating the company",{type:"error"})}},"handleCreateCompany");return u.jsx(Od,{optionText:"name",helperText:!1,onCreate:a,createItemLabel:"Create %{item}",createLabel:"Start typing to create a new company",validate:e})},"AutocompleteCompanyInput"),Mne=i(()=>{const e=xd();return u.jsxs("div",{className:"flex flex-col gap-2 p-1",children:[u.jsx(ho,{}),u.jsxs("div",{className:`flex gap-6 ${e?"flex-col":"flex-row"}`,children:[u.jsxs("div",{className:"flex flex-col gap-10 flex-1",children:[u.jsx(w5e,{}),u.jsx(_5e,{})]}),u.jsx(bc,{orientation:e?"horizontal":"vertical",className:"flex-shrink-0"}),u.jsxs("div",{className:"flex flex-col gap-10 flex-1",children:[u.jsx(S5e,{}),u.jsx(j5e,{})]})]})]})},"ContactInputs"),w5e=i(()=>{const{contactGender:e}=la();return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("h6",{className:"text-lg font-semibold",children:"Identity"}),u.jsx(b5e,{label:!1,row:!0,source:"gender",choices:e,helperText:!1,optionText:"label",optionValue:"value",defaultValue:e[0].value}),u.jsx(Ut,{source:"first_name",validate:Pn(),helperText:!1}),u.jsx(Ut,{source:"last_name",validate:Pn(),helperText:!1})]})},"ContactIdentityInputs"),_5e=i(()=>u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("h6",{className:"text-lg font-semibold",children:"Position"}),u.jsx(Ut,{source:"title",helperText:!1}),u.jsx(ro,{source:"company_id",reference:"companies",perPage:10,children:u.jsx(x5e,{})})]}),"ContactPositionInputs"),S5e=i(()=>{const{getValues:e,setValue:t}=ya(),n=i(s=>{const{first_name:o,last_name:l}=e();if(o||l||!s)return;const[f,c]=s.split("@")[0].split(".");t("first_name",f.charAt(0).toUpperCase()+f.slice(1)),t("last_name",c?c.charAt(0).toUpperCase()+c.slice(1):"")},"handleEmailChange"),r=i(s=>{const o=s.clipboardData?.getData("text/plain");n(o)},"handleEmailPaste"),a=i(s=>{const o=s.target.value;n(o)},"handleEmailBlur");return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("h6",{className:"text-lg font-semibold",children:"Personal info"}),u.jsx(kP,{source:"email_jsonb",label:"Email addresses",helperText:!1,children:u.jsxs(OP,{inline:!0,disableReordering:!0,disableClear:!0,className:"[&>ul>li]:border-b-0 [&>ul>li]:pb-0",children:[u.jsx(Ut,{source:"email",className:"w-full",helperText:!1,label:!1,placeholder:"Email",validate:EY(),onPaste:r,onBlur:a}),u.jsx(or,{source:"type",helperText:!1,label:!1,optionText:"id",choices:LH,defaultValue:"Work",className:"w-24 min-w-24"})]})}),u.jsx(kP,{source:"phone_jsonb",label:"Phone numbers",helperText:!1,children:u.jsxs(OP,{inline:!0,disableReordering:!0,disableClear:!0,className:"[&>ul>li]:border-b-0 [&>ul>li]:pb-0",children:[u.jsx(Ut,{source:"number",className:"w-full",helperText:!1,label:!1,placeholder:"Phone number"}),u.jsx(or,{source:"type",helperText:!1,label:!1,optionText:"id",choices:LH,defaultValue:"Work",className:"w-24 min-w-24"})]})}),u.jsx(Ut,{source:"linkedin_url",label:"Linkedin URL",helperText:!1,validate:Mte})]})},"ContactPersonalInformationInputs"),LH=[{id:"Work"},{id:"Home"},{id:"Other"}],j5e=i(()=>u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("h6",{className:"text-lg font-semibold",children:"Misc"}),u.jsx(Ut,{source:"background",label:"Background info (bio, how you met, etc)",multiline:!0,helperText:!1}),u.jsx(ew,{source:"has_newsletter",helperText:!1}),u.jsx(ro,{reference:"sales",source:"sales_id",sort:{field:"last_name",order:"ASC"},filter:{"disabled@neq":!0},children:u.jsx(or,{helperText:!1,label:"Account manager",optionText:C5e,validate:Pn()})})]}),"ContactMiscInputs"),C5e=i(e=>`${e.first_name} ${e.last_name}`,"saleOptionRenderer"),E5e=i(()=>{const{identity:e}=Yn();return u.jsx(hy,{redirect:"show",transform:i(t=>({...t,first_seen:new Date().toISOString(),last_seen:new Date().toISOString(),tags:[]}),"transform"),children:u.jsx("div",{className:"mt-2 flex lg:mr-72",children:u.jsx("div",{className:"flex-1",children:u.jsx(zr,{defaultValues:{sales_id:e?.id},children:u.jsx(un,{children:u.jsxs(Un,{children:[u.jsx(Mne,{}),u.jsx(n_,{})]})})})})})})},"ContactCreate"),$H=i(e=>{const{children:t,resource:n,perPage:r,sort:a,filter:s}=e,o=pi(e)||k5e,l=Qw({data:o,resource:n,perPage:r,sort:a,filter:s});return u.jsx(py,{value:l,children:t})},"ArrayField"),k5e=[],O5e=i(({icon:e=R5e,label:t,className:n,...r})=>{const{handleDelete:a,isPending:s}=Ope(r);return u.jsxs(Le,{variant:"destructive",type:"button",onClick:a,disabled:s,className:xe("h-9",n),children:[e,u.jsx(nr,{i18nKey:t??"ra.action.delete",children:t??"Delete"})]})},"BulkDeleteButton"),R5e=u.jsx(a4,{}),A5e=i(({icon:e=T5e,label:t="ra.action.export",onClick:n,...r})=>{const a=bme(r),s=i(o=>{a(),n?.(o)},"handleClick");return u.jsxs(Le,{onClick:s,role:"button",variant:"outline",size:"sm",className:"flex items-center gap-2 h-9",...N5e(r),children:[e,t&&u.jsx(nr,{i18nKey:t,children:t})]})},"BulkExportButton"),T5e=u.jsx(QM,{className:"h-4 w-4"}),N5e=i(({resource:e,exporter:t,onClick:n,label:r,icon:a,meta:s,...o})=>o,"sanitizeRestProps");function Ine(){return u.jsxs(u.Fragment,{children:[u.jsx(A5e,{}),u.jsx(O5e,{})]})}i(Ine,"BulkActionsToolbarChildren");const Fne=i(({children:e=u.jsx(Ine,{})})=>{const{selectedIds:t,onUnselectItems:n}=Xn();if(!t?.length)return null;const r=i(a=>{a.stopPropagation(),n()},"handleUnselectAll");return u.jsxs(un,{className:"flex flex-col gap-2 md:gap-6 md:flex-row items-stretch sm:items-center p-2 px-4 w-[90%] sm:w-fit mx-auto fixed bottom-2 left-0 right-0 z-10 bg-zinc-100 dark:bg-zinc-900",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(Le,{variant:"ghost",className:"has-[>svg]:px-0",onClick:r,children:u.jsx($p,{})}),u.jsx("span",{className:"text-sm text-muted-foreground",children:u.jsxs(nr,{i18nKey:"ra.action.bulk_actions",options:{smart_count:t.length},children:[t.length," rows selected"]})})]}),e]})},"BulkActionsToolbar");var FA={exports:{}},qH;function P5e(){return qH||(qH=1,(function(e){(function(t,n){e.exports?e.exports=n():this[t]=n()})("Diacritics",function(){for(var t={map:{}},n=[{base:" ",letters:" "},{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"Th",letters:"Þ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"ff",letters:"ff"},{base:"fi",letters:"fi"},{base:"fl",letters:"fl"},{base:"ffi",letters:"ffi"},{base:"ffl",letters:"ffl"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nñnⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥлԉ"},{base:"nj",letters:"nj"},{base:"o",letters:"߀oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oe",letters:"Œœ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"ss",letters:"ß"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"th",letters:"þ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],r=0,a=n.length;r<a;r++)for(var s=n[r].letters.split(""),o=0,l=s.length;o<l;o++)t.map[s[o]]=n[r].base;return t.clean=function(f){if(!f||!f.length||f.length<1)return"";for(var c="",p=f.split(""),m=0,v=p.length,b;m<v;m++)b=p[m],c+=b in t.map?t.map[b]:b;return c},t})})(FA)),FA.exports}i(P5e,"requireDiacritics");var UH=P5e();const D5e=i(e=>{const{selected:t,label:n,onToggle:r,onMove:a,source:s,index:o}=e,l=Wt(),f=y.useRef(null),c=y.useRef(null),p=y.useRef(null),m=y.useCallback(_=>{c.current=_.clientX,p.current=_.clientY},[]),v=i(()=>{document.addEventListener("dragover",m)},"handleDragStart"),b=i(_=>{const j=_.target;j.dataset.dragActive="true";const C=j.closest("ul");if(c.current==null||p.current==null)return;const k=document.elementFromPoint(c.current,p.current);let E=k===null?j:k.closest("li");if(!E)return;if(E.classList.contains("dragIcon")){const R=E.parentNode;R instanceof HTMLElement&&(E=R)}if(E===j)return;const T=E.parentNode;if(C&&T instanceof HTMLElement&&C===T.closest("ul")){const R=E.dataset.index;R&&(f.current=parseInt(R,10)),E===j.nextSibling&&(E=E.nextSibling),C.insertBefore(j,E)}},"handleDrag"),w=i(_=>{const j=_.target,C=j.closest("ul"),k=c.current!=null&&p.current!=null?document.elementFromPoint(c.current,p.current):null;let E=c.current==null||p.current==null||k===null?j:k.closest("li");if(p.current!==null&&C&&!E){const T=j.closest("ul");T&&p.current>T.getBoundingClientRect().bottom?E=C.lastChild:E=C.firstChild}E&&C&&E.closest("ul")===C?a&&a(j.dataset.index,f.current):(_.preventDefault(),_.stopPropagation()),j.dataset.dragActive="false",document.removeEventListener("dragover",m)},"handleDragEnd"),S=i(_=>{_.preventDefault(),_.dataTransfer.dropEffect="move"},"handleDragOver");return u.jsxs("li",{role:"option",draggable:a?"true":void 0,onDrag:a?b:void 0,onDragStart:a?v:void 0,onDragEnd:a?w:void 0,onDragOver:a?S:void 0,"data-index":o,className:xe("flex justify-between items-center py-1","data-[drag-active=true]:bg-transparent data-[drag-active=true]:text-transparent data-[drag-active=true]:outline data-[drag-active=true]:outline-1 data-[drag-active=true]:outline-border"),children:[u.jsxs("label",{htmlFor:`switch_${o}`,className:"flex items-center gap-2 cursor-pointer",children:[u.jsx(l3,{id:`switch_${o}`,checked:t,onCheckedChange:r,name:`${o}`}),u.jsx("span",{className:"text-sm",children:u.jsx(ma,{label:n,source:s,resource:l})})]}),a&&u.jsx(v1e,{className:"cursor-move dragIcon w-4 h-4 text-muted-foreground"})]},s)},"FieldToggle"),M5e=i(({children:e})=>{const t=xt(),{storeKey:n,defaultHiddenColumns:r}=o1(),[a,s]=ka(`${n}_columnRanks`),[o,l]=ka(n,r),f=`${n}-columnsSelector`,[c,p]=y.useState(()=>typeof document<"u"?document.getElementById(f):null);y.useEffect(()=>{if(c&&typeof document<"u"&&document.body.contains(c))return;const _=setInterval(()=>{const C=document.getElementById(f);C&&p(C)},100),j=setTimeout(()=>clearInterval(_),500);return()=>{clearInterval(_),clearTimeout(j)}},[f,c]);const[m,v]=y.useState("");if(!c)return null;const b=y.Children.toArray(e),w=HP(a??[],b.length),S=b.length>5;return ol.createPortal(u.jsxs("ul",{className:"max-h-[50vh] p-1 overflow-auto",children:[S?u.jsx("li",{className:"pb-2",tabIndex:-1,children:u.jsxs("div",{className:"relative",children:[u.jsx(Er,{value:m,onChange:i(_=>{v(_.target.value)},"onChange"),placeholder:t("ra.action.search_columns",{_:"Search columns"}),className:"pr-8"}),u.jsx(r4,{className:"absolute right-2 top-2 h-4 w-4 text-muted-foreground"}),m&&u.jsx("button",{onClick:i(()=>v(""),"onClick"),className:"absolute right-8 top-2 h-4 w-4 text-muted-foreground","aria-label":"Clear",children:"×"})]})}):null,w.map((_,j)=>u.jsx(nQ.Provider,{value:_,children:u.jsx(rQ.Provider,{value:m,children:b[_]},j)},j)),u.jsx("li",{className:"text-center mt-2 px-3",children:u.jsx(Le,{variant:"outline",size:"sm",onClick:i(()=>{s(void 0),l(r)},"onClick"),children:"Reset"})})]}),c)},"ColumnsSelector"),I5e=i(({source:e,label:t})=>{const n=Wt(),{storeKey:r,defaultHiddenColumns:a}=o1(),[s,o]=ka(r,a),l=jye(),[f,c]=ka(`${r}_columnRanks`),p=Cye(),m=a1();if(!e&&!t)return null;const v=m({label:typeof t=="string"?t:void 0,resource:n,source:e}),b=s.includes(e),w=F5e(v,p),S=i((_,j)=>{const C=f?Math.max(Number(_),Number(j||0))>f.length-1?HP(f,Math.max(Number(_),Number(j||0))+1):f:HP([],Math.max(Number(_),Number(j||0))+1),k=C.findIndex(R=>R==Number(_)),E=C.findIndex(R=>R==Number(j));if(k===-1||E===-1)return;let T;k>E?T=[...C.slice(0,E),C[k],...C.slice(E,k),...C.slice(k+1)]:T=[...C.slice(0,k),...C.slice(k+1,E+1),C[k],...C.slice(E+1)],c(T)},"handleMove");return w?u.jsx(D5e,{source:e,label:v,index:String(l),selected:!b,onToggle:i(()=>o(b?s.filter(_=>_!==e):[...s,e]),"onToggle"),onMove:S},l):null},"ColumnsSelectorItem"),HP=i((e,t)=>e.concat(Array.from({length:t-e.length},(n,r)=>e.length+r)),"padRanks"),F5e=i((e,t)=>t?UH.clean(e).toLowerCase().includes(UH.clean(t).toLowerCase()):!0,"fieldLabelMatchesFilter"),L5e=i(({actions:e,children:t,className:n,disableBreadcrumb:r,title:a,...s})=>u.jsx(hy,{...s,children:u.jsx($5e,{actions:e,className:n,disableBreadcrumb:r,title:a,children:t})}),"Create"),$5e=i(({actions:e,disableBreadcrumb:t,title:n,children:r,className:a})=>{const s=qpe(),o=Wt();if(!o)throw new Error("The CreateView component must be used within a ResourceContextProvider");const f=Tc()(o,2),p=co()({resource:o,type:"list"}),m=FM();return u.jsxs(u.Fragment,{children:[!t&&u.jsxs(V1,{children:[m&&u.jsx(_v,{children:u.jsx(nn,{to:"/",children:u.jsx(nr,{i18nKey:"ra.page.dashboard",children:"Home"})})}),u.jsx(_v,{children:u.jsx(nn,{to:p,children:f})}),u.jsx($4,{children:u.jsx(nr,{i18nKey:"ra.action.create",children:"Create"})})]}),u.jsxs("div",{className:xe("flex justify-between items-start flex-wrap gap-2 my-2",a),children:[u.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:n!==void 0?n:s.defaultTitle}),e]}),u.jsx("div",{className:"my-2",children:r})]})},"CreateView");function q5e({className:e,...t}){return u.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:u.jsx("table",{"data-slot":"table",className:xe("w-full caption-bottom text-sm",e),...t})})}i(q5e,"Table");function U5e({className:e,...t}){return u.jsx("thead",{"data-slot":"table-header",className:xe("[&_tr]:border-b",e),...t})}i(U5e,"TableHeader");function z5e({className:e,...t}){return u.jsx("tbody",{"data-slot":"table-body",className:xe("[&_tr:last-child]:border-0",e),...t})}i(z5e,"TableBody");function Lne({className:e,...t}){return u.jsx("tr",{"data-slot":"table-row",className:xe("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",e),...t})}i(Lne,"TableRow");function $ne({className:e,...t}){return u.jsx("th",{"data-slot":"table-head",className:xe("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...t})}i($ne,"TableHead");function qne({className:e,...t}){return u.jsx("td",{"data-slot":"table-cell",className:xe("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...t})}i(qne,"TableCell");var p_="Checkbox",[B5e,lHe]=oa(p_),[H5e,u3]=B5e(p_);function V5e(e){const{__scopeCheckbox:t,checked:n,children:r,defaultChecked:a,disabled:s,form:o,name:l,onCheckedChange:f,required:c,value:p="on",internal_do_not_use_render:m}=e,[v,b]=Fi({prop:n,defaultProp:a??!1,onChange:f,caller:p_}),[w,S]=y.useState(null),[_,j]=y.useState(null),C=y.useRef(!1),k=w?!!o||!!w.closest("form"):!0,E={checked:v,disabled:s,setChecked:b,control:w,setControl:S,name:l,form:o,value:p,hasConsumerStoppedPropagationRef:C,required:c,defaultChecked:vc(a)?!1:a,isFormControl:k,bubbleInput:_,setBubbleInput:j};return u.jsx(H5e,{scope:t,...E,children:W5e(m)?m(E):r})}i(V5e,"CheckboxProvider");var Une="CheckboxTrigger",zne=y.forwardRef(({__scopeCheckbox:e,onKeyDown:t,onClick:n,...r},a)=>{const{control:s,value:o,disabled:l,checked:f,required:c,setControl:p,setChecked:m,hasConsumerStoppedPropagationRef:v,isFormControl:b,bubbleInput:w}=u3(Une,e),S=Xt(a,p),_=y.useRef(f);return y.useEffect(()=>{const j=s?.form;if(j){const C=i(()=>m(_.current),"reset");return j.addEventListener("reset",C),()=>j.removeEventListener("reset",C)}},[s,m]),u.jsx(mt.button,{type:"button",role:"checkbox","aria-checked":vc(f)?"mixed":f,"aria-required":c,"data-state":Kne(f),"data-disabled":l?"":void 0,disabled:l,value:o,...r,ref:S,onKeyDown:Je(t,j=>{j.key==="Enter"&&j.preventDefault()}),onClick:Je(n,j=>{m(C=>vc(C)?!0:!C),w&&b&&(v.current=j.isPropagationStopped(),v.current||j.stopPropagation())})})});zne.displayName=Une;var Bne=y.forwardRef((e,t)=>{const{__scopeCheckbox:n,name:r,checked:a,defaultChecked:s,required:o,disabled:l,value:f,onCheckedChange:c,form:p,...m}=e;return u.jsx(V5e,{__scopeCheckbox:n,checked:a,defaultChecked:s,disabled:l,required:o,onCheckedChange:c,name:r,form:p,value:f,internal_do_not_use_render:i(({isFormControl:v})=>u.jsxs(u.Fragment,{children:[u.jsx(zne,{...m,ref:t,__scopeCheckbox:n}),v&&u.jsx(Gne,{__scopeCheckbox:n})]}),"internal_do_not_use_render")})});Bne.displayName=p_;var Hne="CheckboxIndicator",Vne=y.forwardRef((e,t)=>{const{__scopeCheckbox:n,forceMount:r,...a}=e,s=u3(Hne,n);return u.jsx(ba,{present:r||vc(s.checked)||s.checked===!0,children:u.jsx(mt.span,{"data-state":Kne(s.checked),"data-disabled":s.disabled?"":void 0,...a,ref:t,style:{pointerEvents:"none",...e.style}})})});Vne.displayName=Hne;var Wne="CheckboxBubbleInput",Gne=y.forwardRef(({__scopeCheckbox:e,...t},n)=>{const{control:r,hasConsumerStoppedPropagationRef:a,checked:s,defaultChecked:o,required:l,disabled:f,name:c,value:p,form:m,bubbleInput:v,setBubbleInput:b}=u3(Wne,e),w=Xt(n,b),S=W1(s),_=O1(r);y.useEffect(()=>{const C=v;if(!C)return;const k=window.HTMLInputElement.prototype,T=Object.getOwnPropertyDescriptor(k,"checked").set,R=!a.current;if(S!==s&&T){const A=new Event("click",{bubbles:R});C.indeterminate=vc(s),T.call(C,vc(s)?!1:s),C.dispatchEvent(A)}},[v,S,s,a]);const j=y.useRef(vc(s)?!1:s);return u.jsx(mt.input,{type:"checkbox","aria-hidden":!0,defaultChecked:o??j.current,required:l,disabled:f,name:c,value:p,form:m,...t,tabIndex:-1,ref:w,style:{...t.style,..._,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Gne.displayName=Wne;function W5e(e){return typeof e=="function"}i(W5e,"isFunction");function vc(e){return e==="indeterminate"}i(vc,"isIndeterminate");function Kne(e){return vc(e)?"indeterminate":e?"checked":"unchecked"}i(Kne,"getState");function Qp({className:e,...t}){return u.jsx(Bne,{"data-slot":"checkbox",className:xe("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:u.jsx(Vne,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:u.jsx(ss,{className:"size-3.5"})})})}i(Qp,"Checkbox");const G5e=i(({defaultValue:e,source:t,record:n,empty:r,transform:a=K5e,locales:s,options:o,...l})=>{let f=pi({defaultValue:e,source:t,record:n});const c=xt();return f==null?r?u.jsx("span",{...l,children:typeof r=="string"?c(r,{_:r}):r}):null:(a&&(f=a(f)),u.jsx("span",{...l,children:Y5e&&typeof f=="number"?f.toLocaleString(s,o):f}))},"NumberField"),K5e=i(e=>e&&typeof e=="string"&&!isNaN(e)?+e:e,"defaultTransform"),Y5e=!!(typeof Intl=="object"&&Intl&&typeof Intl.NumberFormat=="function"),zH=u.jsx(Ine,{});function sa(e){const{children:t,className:n,rowClassName:r,bulkActionButtons:a=zH,bulkActionsToolbar:s,...o}=e,l=!!s||a!==!1,f=Wt(e),c=e.storeKey||`${f}.datatable`,[p]=ka(`${c}_columnRanks`),m=p?t6e(t,p):t;return u.jsxs(_ye,{hasBulkActions:l,loading:null,empty:u.jsx(e6e,{}),...o,children:[u.jsx("div",{className:xe("rounded-md border",n),children:u.jsxs(q5e,{children:[u.jsx(bN.Provider,{value:"header",children:u.jsx(Q5e,{children:m})}),u.jsx(X5e,{rowClassName:r,children:m})]})}),s??(a!==!1&&u.jsx(Fne,{children:y.isValidElement(a)?a:zH})),u.jsx(bN.Provider,{value:"columnsSelector",children:u.jsx(M5e,{children:t})})]})}i(sa,"DataTable");sa.Col=Yne;sa.NumberCol=i6e;const Q5e=i(({children:e})=>{const t=XY(),{hasBulkActions:n=!1}=YY(),{onSelect:r}=LM(),a=JY(),s=i(l=>{!r||!t||!a||r(l?a.concat(t.filter(f=>!a.includes(f.id)).map(f=>f.id)):[])},"handleToggleSelectAll"),o=Array.isArray(t)?t.map(l=>l.id):[];return u.jsx(U5e,{children:u.jsxs(Lne,{children:[n?u.jsx($ne,{className:"w-8",children:u.jsx(Qp,{onCheckedChange:s,checked:a&&a.length>0&&o.length>0&&o.every(l=>a.includes(l)),className:"mb-2"})}):null,e]})})},"DataTableHead"),X5e=i(({children:e,rowClassName:t})=>{const n=XY();return u.jsx(z5e,{children:n?.map((r,a)=>u.jsx(Ya,{value:r,children:u.jsx(Z5e,{className:t?.(r),children:e})},r.id??`row${a}`))})},"DataTableBody"),Z5e=i(({children:e,className:t})=>{const{rowClick:n,handleToggleItem:r}=LM(),a=JY(),{hasBulkActions:s=!1}=YY(),o=Ft();if(!o)throw new Error("DataTableRow can only be used within a RecordContext");const l=Wt();if(!l)throw new Error("DataTableRow can only be used within a ResourceContext");const f=Ra(),c=OK(),p=y.useCallback(v=>{v.stopPropagation(),r&&r(o.id,v)},[r,o.id]),m=y.useCallback(async()=>{const v=typeof n=="function"?n(o.id,l,o):n,b=J5e(v)?await v:v,w=await c({record:o,resource:l,link:b});w===!1||w==null||f(w,{state:{_scrollToTop:!0}})},[o,l,n,f,c]);return u.jsxs(Lne,{onClick:m,className:xe(n!==!1&&"cursor-pointer",t),children:[s?u.jsx(qne,{className:"flex w-8",onClick:p,children:u.jsx(Qp,{checked:a?.includes(o.id),onClick:p})}):null,e]},o.id)},"DataTableRow"),J5e=i(e=>e&&typeof e.then=="function","isPromise"),e6e=i(()=>u.jsx(Ga,{children:u.jsx(di,{children:"No results found."})}),"DataTableEmpty");function Yne(e){switch(Eye()){case"columnsSelector":return u.jsx(I5e,{...e});case"header":return u.jsx(n6e,{...e});case"data":return u.jsx(a6e,{...e})}}i(Yne,"DataTableColumn");const t6e=i((e,t)=>y.Children.toArray(e).reduce((n,r,a)=>{const s=t.indexOf(a);return s===-1?n[a]=r:n[s]=r,n},[]),"reorderChildren");function n6e(e){const{disableSort:t,source:n,label:r,sortByOrder:a,className:s,headerClassName:o}=e,l=wye(),{handleSort:f}=LM(),c=Wt(),p=xt(),m=a1(),{storeKey:v,defaultHiddenColumns:b}=o1(),[w]=ka(v,b);if(w.includes(n))return null;const _=l&&l.field===n?r6e[l.order]:a??"ASC",j=m({label:typeof r=="string"?r:void 0,resource:c,source:n}),C=p("ra.sort.sort_by",{field:j,field_lower_first:typeof j=="string"?j.charAt(0).toLowerCase()+j.slice(1):void 0,order:p(`ra.sort.${_}`),_:p("ra.action.sort")});return u.jsx($ne,{className:xe(s,o),children:f&&l&&!t&&n?u.jsx(Li,{children:u.jsxs(ds,{children:[u.jsx(fs,{asChild:!0,children:u.jsxs(Le,{variant:"ghost",size:"sm",className:"-ml-3 -mr-3 h-8 data-[state=open]:bg-accent cursor-pointer","data-field":n,onClick:f,children:[o?.includes("text-right")?null:u.jsx(ma,{label:r,source:n,resource:c}),l.field===n?l.order==="ASC"?u.jsx(swe,{className:"ml-2 h-6 w-6"}):u.jsx(dwe,{className:"ml-2 h-6 w-6"}):null,o?.includes("text-right")?u.jsx(ma,{label:r,source:n,resource:c}):null]})}),u.jsx(hs,{children:u.jsx("p",{children:C})})]})}):u.jsx(ma,{label:r,source:n,resource:c})})}i(n6e,"DataTableHeadCell");const r6e={ASC:"DESC",DESC:"ASC"};function a6e(e){const{children:t,render:n,field:r,source:a,className:s,cellClassName:o,conditionalClassName:l}=e,{storeKey:f,defaultHiddenColumns:c}=o1(),[p]=ka(f,c),m=Ft();if(p.includes(a))return null;if(!n&&!r&&!t&&!a)throw new Error("DataTableColumn: Missing at least one of the following props: render, field, children, or source");return u.jsx(qne,{className:xe("py-1",s,o,m&&l?.(m)),children:t??(n?m&&n(m):r?y.createElement(r,{source:a}):Qt(m,a))})}i(a6e,"DataTableCell");function i6e(e){const{source:t,options:n,locales:r,className:a,headerClassName:s,cellClassName:o,...l}=e;return u.jsx(Yne,{source:t,...l,className:a,headerClassName:xe("text-right",s),cellClassName:xe("text-right",o),children:u.jsx(G5e,{source:t,options:n,locales:r})})}i(i6e,"DataTableNumberColumn");const d3=i(e=>{const{className:t,inputClassName:n,defaultValue:r,format:a=o6e,label:s,source:o,helperText:l,onChange:f,onFocus:c,validate:p,disabled:m,readOnly:v,...b}=e,w=Wt(e),{field:S,id:_,isRequired:j}=Pc({defaultValue:r,source:o,validate:p,disabled:m,readOnly:v,format:a,...b}),C=y.useRef(null),k=y.useRef(S.value),[E,T]=y.useState(1),R=y.useRef(!1);y.useEffect(()=>{if(R.current){R.current=!1;return}C.current?.value!==S.value&&!(C.current?.value===""&&S.value==null)&&(k.current=S.value,T($=>$+1),R.current=!1)},[T,S.value]);const{onBlur:A}=S,N=y.useRef(!1),D=Ct(z=>{if(f&&f(z),typeof z.target>"u"||typeof z.target.value>"u")return;const $=z.target,H=$.value,U=H===""||$.valueAsDate!=null&&!isNaN(new Date($.valueAsDate).getTime());H!==""&&H!=null&&U&&(S.onChange(H),R.current=!0)}),M=Ct(z=>{c&&c(z),N.current=!0}),I=Ct(()=>{if(N.current=!1,!C.current)return;const z=C.current.value;(z===""||C.current.valueAsDate!=null&&!isNaN(new Date(C.current.valueAsDate).getTime()))&&S.value!==z&&S.onChange(z??""),A&&A()}),{ref:F,name:L}=S,q=y.useCallback(z=>{typeof F=="function"?F(z):F&&z&&(F.current=z),C.current=z},[F]);return u.jsxs(eo,{id:_,className:t,name:L,children:[s!==!1&&u.jsx(al,{children:u.jsx(ma,{label:s,source:o,resource:w,isRequired:j})}),u.jsx(Iy,{children:u.jsx(Er,{ref:q,defaultValue:a(k.current)??"",type:"date",onChange:D,onFocus:M,onBlur:I,className:xe("ra-input",`ra-input-${o}`,"[color-scheme:light] dark:[color-scheme:dark] relative [&::-webkit-calendar-picker-indicator]:cursor-pointer [&::-webkit-calendar-picker-indicator]:absolute [&::-webkit-calendar-picker-indicator]:right-3 [&::-webkit-calendar-picker-indicator]:opacity-100",n),disabled:m||v,readOnly:v,...b},E)}),u.jsx(to,{helperText:l}),u.jsx(ul,{})]})},"DateInput"),BH=i(e=>{if(!(e instanceof Date)||isNaN(e.getDate()))return"";const t=new Date(e.getTime()),n="00",r=t.getFullYear().toString(),a=(t.getMonth()+1).toString(),s=t.getDate().toString();return`${r}-${(n+a).slice(-2)}-${(n+s).slice(-2)}`},"convertDateToString"),s6e=/^\d{4}-\d{2}-\d{2}$/,o6e=i(e=>e==null||e===""?null:e instanceof Date?BH(e):typeof e=="string"&&s6e.test(e)?e:BH(new Date(e)),"defaultFormat"),Qne=i(e=>{const{className:t,empty:n,defaultValue:r,source:a,record:s,...o}=e,l=pi({defaultValue:r,source:a,record:s}),f=xt();return l==null?n?u.jsx("span",{className:t,...o,children:typeof n=="string"?f(n,{_:n}):n}):null:u.jsx("a",{className:xe("underline hover:no-underline",t),href:`mailto:${l}`,onClick:c6e,...o,children:l})},"EmailFieldImpl");Qne.displayName="EmailFieldImpl";const l6e=u_(Qne),c6e=i(e=>e.stopPropagation(),"stopPropagation");sa.Col;const u6e=i(e=>{const{children:t,className:n,empty:r,field:a,label:s,render:o,resource:l,source:f,record:c,variant:p,...m}=e,v=Wt(e),b=Ft({recordProp:c}),w=xt();return!f&&!s&&!o?null:u.jsxs("div",{className:xe(n,"flex",p==="inline"?"flex-row":"flex-col"),...m,children:[s!==""&&s!==!1?u.jsx("div",{className:xe(p==="inline"?"block min-w-50":"text-xs","text-muted-foreground"),children:u.jsx(ma,{label:s,source:f,resource:v,isRequired:!1})}):null,t?u.jsx("span",{className:"flex-1",children:t}):o?b&&u.jsx("span",{className:"flex-1",children:o(b)||(typeof r=="string"?w(r,{_:r}):r)}):a?y.createElement(a,{source:f,empty:r,className:"flex-1"}):f?u.jsx(Ir,{source:f,empty:r,className:"flex-1"}):null]})},"RecordField"),d6e=i(()=>{const e=Ft();return e?u.jsxs("div",{className:"flex flex-row gap-4 items-center justify-start",children:[u.jsx(ho,{height:40,width:40,record:e}),u.jsxs("div",{className:"flex flex-col items-start gap-1",children:[u.jsxs("span",{children:[e.first_name," ",e.last_name]}),u.jsxs("span",{className:"text-xs text-muted-foreground",children:[e.title,e.title&&e.company_name&&" at ",e.company_name]})]})]}):null},"ContactOptionRender"),tw=u.jsx(d6e,{}),Xne=i(({selectContact:e,display:t="chip"})=>{const{identity:n}=Yn(),r=wn(),[a]=yd(),s=Ht(),{taskTypes:o}=la(),l=Ft(),[f,c]=y.useState(!1),p=i(()=>{c(!0)},"handleOpen"),m=i(async v=>{c(!1);const b=await r.getOne("contacts",{id:v.contact_id});b.data&&(await a("contacts",{id:b.data.id,data:{last_seen:new Date().toISOString()},previousData:b.data}),s("Task added"))},"handleSuccess");return n?u.jsxs(u.Fragment,{children:[t==="icon"?u.jsx(Li,{children:u.jsxs(ds,{children:[u.jsx(fs,{asChild:!0,children:u.jsx(Le,{size:"sm",variant:"ghost",className:"p-2 cursor-pointer",onClick:p,children:u.jsx(os,{className:"w-4 h-4"})})}),u.jsx(hs,{children:"Create task"})]})}):u.jsx("div",{className:"my-2",children:u.jsxs(Le,{variant:"outline",className:"h-6 cursor-pointer",onClick:p,size:"sm",children:[u.jsx(os,{className:"w-4 h-4"}),"Add task"]})}),u.jsx(hy,{resource:"tasks",record:{type:"None",contact_id:l?.id,due_date:new Date().toISOString().slice(0,10),sales_id:n.id},transform:i(v=>{const b=new Date(v.due_date);return b.setHours(0,0,0,0),v.due_date=b.toISOString(),{...v,due_date:new Date(v.due_date).toISOString()}},"transform"),mutationOptions:{onSuccess:m},children:u.jsx(ga,{open:f,onOpenChange:i(()=>c(!1),"onOpenChange"),children:u.jsx(va,{className:"lg:max-w-xl overflow-y-auto max-h-9/10 top-1/20 translate-y-0",children:u.jsxs(zr,{className:"flex flex-col gap-4",children:[u.jsx(Fr,{children:u.jsxs(Lr,{children:[e?"Create a new task":"Create a new task for ",!e&&u.jsx(eY,{record:l,resource:"contacts"})]})}),u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx(Ut,{autoFocus:!0,source:"text",label:"Description",validate:Pn(),multiline:!0,className:"m-0",helperText:!1}),e&&u.jsx(ro,{source:"contact_id",reference:"contacts_summary",children:u.jsx(Od,{label:"Contact",optionText:tw,helperText:!1,validate:Pn()})}),u.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[u.jsx(d3,{source:"due_date",helperText:!1,validate:Pn()}),u.jsx(or,{source:"type",validate:Pn(),choices:o.map(v=>({id:v,name:v})),helperText:!1})]})]}),u.jsx(ps,{className:"w-full justify-end",children:u.jsx(jd,{})})]})})})})]}):null},"AddTask"),Zne=i(({open:e,close:t,taskId:n})=>{const{taskTypes:r,taskPriorities:a,taskStatuses:s}=la(),o=Ht();return u.jsx(ga,{open:e,onOpenChange:t,children:n&&u.jsx(wM,{id:n,resource:"tasks",className:"mt-0",mutationOptions:{onSuccess:i(()=>{t(),o("Task updated",{type:"info",undoable:!0})},"onSuccess")},redirect:!1,children:u.jsx(va,{className:"lg:max-w-xl overflow-y-auto max-h-9/10 top-1/20 translate-y-0",children:u.jsxs(zr,{className:"flex flex-col gap-4",children:[u.jsx(Fr,{children:u.jsx(Lr,{children:"Edit task"})}),u.jsx(Ut,{autoFocus:!0,source:"text",label:"Description",validate:Pn(),multiline:!0,helperText:!1}),u.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[u.jsx(d3,{source:"due_date",helperText:!1,validate:Pn()}),u.jsx(or,{source:"type",choices:r.map(l=>({id:l,name:l})),helperText:!1,validate:Pn()}),u.jsx(or,{source:"priority",choices:a,helperText:!1}),u.jsx(or,{source:"status",choices:s,helperText:!1}),u.jsx(ro,{source:"assigned_to",reference:"sales",children:u.jsx(or,{optionText:i(l=>`${l.first_name} ${l.last_name}`,"optionText"),label:"Assigned To"})})]}),u.jsxs(ps,{className:"w-full sm:justify-between gap-4",children:[u.jsx(c_,{mutationOptions:{onSuccess:i(()=>{t(),o("Task deleted",{type:"info",undoable:!0})},"onSuccess")},redirect:!1}),u.jsx(jd,{label:"Save"})]})]})})})})},"TaskEdit"),f6e=i(({task:e,showContact:t})=>{const n=Ht(),r=Dn(),[a,s]=y.useState(!1),o=i(()=>{s(!1)},"handleCloseEdit"),[l,{isPending:f,isSuccess:c,variables:p}]=yd(),{handleDelete:m}=HK({record:e,redirect:!1,mutationOptions:{onSuccess(){n("Task deleted successfully",{undoable:!0})}}}),v=i(()=>{s(!0)},"handleEdit"),b=i(()=>()=>{l("tasks",{id:e.id,data:{done_date:e.done_date?null:new Date().toISOString()},previousData:e})},"handleCheck");y.useEffect(()=>{f||!c||p?.data?.done_date!=null||r.invalidateQueries({queryKey:["tasks","getList"]})},[r,f,c,p]);const w=`checkbox-list-label-${e.id}`;return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex items-start justify-between",children:[u.jsxs("div",{className:"flex items-start gap-2 flex-1",children:[u.jsx(Qp,{id:w,checked:!!e.done_date,onCheckedChange:b(),disabled:f,className:"mt-1"}),u.jsxs("div",{className:`flex-grow ${e.done_date?"line-through":""}`,children:[u.jsx(nn,{to:`/tasks/${e.id}/show`,className:"block hover:text-primary transition-colors",children:u.jsxs("div",{className:"text-sm",children:[e.type&&e.type!=="None"&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"font-semibold text-sm",children:e.type})," "]}),e.text]})}),u.jsxs("div",{className:"text-sm text-muted-foreground",children:["due ",u.jsx(cd,{source:"due_date",record:e}),t&&u.jsx(xn,{source:"contact_id",reference:"contacts",record:e,link:"show",className:"inline text-sm text-muted-foreground",render:i(({referenceRecord:S})=>S?u.jsxs(u.Fragment,{children:[" ","(Re: ",S?.first_name," ",S?.last_name,")"]}):null,"render")})]})]})]}),u.jsxs(Fc,{children:[u.jsx(rl,{asChild:!0,children:u.jsx(Le,{variant:"ghost",size:"icon",className:"h-5 pr-0! size-8 cursor-pointer","aria-label":"task actions",children:u.jsx(r1e,{className:"h-4 w-4"})})}),u.jsxs(Lc,{align:"end",children:[u.jsx(sr,{asChild:!0,children:u.jsx(nn,{to:`/tasks/${e.id}/show`,className:"cursor-pointer",children:"Show Details"})}),u.jsx(sr,{className:"cursor-pointer",onClick:i(()=>{l("tasks",{id:e.id,data:{due_date:new Date(Date.now()+1440*60*1e3).toISOString().slice(0,10)},previousData:e})},"onClick"),children:"Postpone to tomorrow"}),u.jsx(sr,{className:"cursor-pointer",onClick:i(()=>{l("tasks",{id:e.id,data:{due_date:new Date(Date.now()+10080*60*1e3).toISOString().slice(0,10)},previousData:e})},"onClick"),children:"Postpone to next week"}),u.jsx(sr,{className:"cursor-pointer",onClick:v,children:"Edit"}),u.jsx(sr,{className:"cursor-pointer",onClick:m,children:"Delete"})]})]})]}),a&&u.jsx(Zne,{taskId:e.id,open:a,close:o})]})},"Task"),Jne=i(({showContact:e,className:t})=>{const{data:n,error:r,isPending:a}=Xn();if(a||r||n.length===0)return null;const s=n.filter(o=>!o.done_date||wbe(new Date(o.done_date),new Date(Date.now()-300*1e3)));return u.jsx("div",{className:`space-y-2 ${t||""}`,children:s.map(o=>u.jsx(f6e,{task:o,showContact:e},o.id))})},"TasksIterator"),kb=["#eddcd2","#fff1e6","#fde2e4","#fad2e1","#c5dedd","#dbe7e4","#f0efeb","#d6e2e9","#bcd4e6","#99c1de"],h6e=i(({color:e,handleClick:t,selected:n})=>u.jsx("button",{type:"button",className:`w-8 h-8 rounded-full inline-block m-1 transition-all ${n?"ring-2 ring-gray-500 ring-offset-1":""}`,style:{backgroundColor:e},onClick:t}),"RoundButton");function ere({open:e,tag:t,title:n,onClose:r,onSubmit:a}){const[s,o]=y.useState(""),[l,f]=y.useState(kb[0]),[c,p]=y.useState(!1),m=i(w=>{o(w.target.value)},"handleNewTagNameChange"),v=i(()=>{p(!1),r()},"handleClose"),b=i(async w=>{w.preventDefault(),await a({name:s,color:l}),p(!0),o(""),f(kb[0]),v()},"handleSubmit");return y.useEffect(()=>{o(t?.name??""),f(t?.color??kb[0])},[t]),u.jsx(ga,{open:e,onOpenChange:v,children:u.jsx(va,{className:"sm:max-w-lg",children:u.jsxs("form",{onSubmit:b,children:[u.jsx(Fr,{children:u.jsx(Lr,{children:n})}),u.jsxs("div",{className:"space-y-4 py-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"tag-name",children:"Tag name"}),u.jsx(Er,{id:"tag-name",autoFocus:!0,value:s,onChange:m,placeholder:"Enter tag name"})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{children:"Color"}),u.jsx("div",{className:"flex flex-wrap",children:kb.map(w=>u.jsx(h6e,{color:w,selected:w===l,handleClick:i(()=>{f(w)},"handleClick")},w))})]})]}),u.jsx("div",{className:"flex justify-end pt-4",children:u.jsxs(Le,{variant:"outline",disabled:c,className:xe(Mc({variant:"outline"}),"text-primary",c?"opacity-50 cursor-not-allowed":"cursor-pointer"),children:[u.jsx(v1,{}),"Save"]})})]})})})}i(ere,"TagDialog");function p6e({tag:e,open:t,onClose:n,onSuccess:r}){const[a]=yd(),s=i(async o=>{await a("tags",{id:e.id,data:o,previousData:e},{onSuccess:i(async l=>{await r?.(l)},"onSuccess")})},"handleEditTag");return u.jsx(ere,{open:t,title:"Edit tag",onClose:n,onSubmit:s,tag:e})}i(p6e,"TagEditModal");function m6e({tag:e,onUnlink:t}){const[n,r]=y.useState(!1),a=i(()=>{r(!1)},"handleClose"),s=i(()=>{r(!0)},"handleClick");return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"text-black inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:e.color},onClick:s,children:[e.name,u.jsx("button",{onClick:i(o=>{o.stopPropagation(),t()},"onClick"),className:"transition-colors p-0 ml-1 cursor-pointer",children:u.jsx($p,{className:"w-3 h-3"})})]}),u.jsx(p6e,{tag:e,open:n,onClose:a})]})}i(m6e,"TagChip");function g6e({open:e,onClose:t,onSuccess:n}){const[r]=IM(),a=i(async s=>{await r("tags",{data:s},{onSuccess:i(async o=>{await n?.(o)},"onSuccess")})},"handleCreateTag");return u.jsx(ere,{open:e,title:"Create a new tag",onClose:t,onSubmit:a})}i(g6e,"TagCreateModal");const v6e=i(()=>{const e=Ft(),[t,n]=y.useState(!1),{data:r,isPending:a}=pa("tags",{pagination:{page:1,perPage:10},sort:{field:"name",order:"ASC"}}),{data:s,isPending:o}=Zhe("tags",{ids:e?.tags},{enabled:e&&e.tags&&e.tags.length>0}),[l]=yd(),f=r&&e&&r.filter(w=>!(e.tags??[]).includes(w.id)),c=i(w=>{if(!e)throw new Error("No contact record found");const S=[...e.tags??[],w];l("contacts",{id:e.id,data:{tags:S},previousData:e})},"handleTagAdd"),p=i(async w=>{if(!e)throw new Error("No contact record found");const S=(e.tags??[]).filter(_=>_!==w);await l("contacts",{id:e.id,data:{tags:S},previousData:e})},"handleTagDelete"),m=i(()=>{n(!0)},"openTagCreateDialog"),v=i(()=>{n(!1)},"handleTagCreateClose"),b=y.useCallback(async w=>{if(!e)throw new Error("No contact record found");await l("contacts",{id:e.id,data:{tags:[...e.tags??[],w.id]},previousData:e},{onSuccess:i(()=>{n(!1)},"onSuccess")})},[l,e]);return o||a?null:u.jsxs("div",{className:"flex flex-wrap gap-2",children:[s?.map(w=>u.jsx("div",{children:u.jsx(m6e,{tag:w,onUnlink:i(()=>p(w.id),"onUnlink")})},w.id)),u.jsx("div",{children:u.jsxs(Fc,{children:[u.jsx(rl,{asChild:!0,children:u.jsxs(Le,{variant:"outline",size:"sm",className:"h-6 cursor-pointer",children:[u.jsx(os,{className:"h-3 w-3 mr-1"}),"Add tag"]})}),u.jsxs(Lc,{children:[f?.map(w=>u.jsx(sr,{onClick:i(()=>c(w.id),"onClick"),children:u.jsx(Kn,{variant:"secondary",className:"text-xs font-normal text-black",style:{backgroundColor:w.color},children:w.name})},w.id)),u.jsx(sr,{onClick:m,children:u.jsxs(Le,{variant:"ghost",size:"sm",className:"w-full justify-start p-0 cursor-pointer",children:[u.jsx(QQ,{className:"h-3 w-3 mr-2"}),"Create new tag"]})})]})]})}),u.jsx(g6e,{open:t,onClose:v,onSuccess:b})]})},"TagsListEdit"),y6e=i(()=>{const[e,t]=y.useState(!1);return u.jsxs(u.Fragment,{children:[u.jsxs(Le,{variant:"outline",className:"h-6 cursor-pointer",size:"sm",onClick:i(()=>t(!0),"onClick"),children:[u.jsx(g1,{className:"w-4 h-4"}),"Merge with another contact"]}),u.jsx(b6e,{open:e,onClose:i(()=>t(!1),"onClose")})]})},"ContactMergeButton"),b6e=i(({open:e,onClose:t})=>{const n=Ft(),r=Ht(),a=zi(),s=wn(),[o,l]=y.useState(null),[f,c]=y.useState(null),[p,m]=y.useState(!1),{mutateAsync:v}=qr({mutationKey:["contacts","merge",{loserId:n?.id,winnerId:o}],mutationFn:i(async()=>s.mergeContacts(n?.id,o),"mutationFn")}),{data:b}=pa("contacts",{filter:{first_name:n?.first_name,last_name:n?.last_name,"id@neq":`${n?.id}`},pagination:{page:1,perPage:10}},{enabled:e&&!!n}),w=e&&!!n&&!!o,{total:S}=nv("tasks",{target:"contact_id",id:n?.id,pagination:{page:1,perPage:1}},{enabled:w}),{total:_}=nv("contactNotes",{target:"contact_id",id:n?.id,pagination:{page:1,perPage:1}},{enabled:w}),{total:j}=pa("deals",{filter:{"contact_ids@cs":`{${n?.id}}`},pagination:{page:1,perPage:1}},{enabled:w});y.useEffect(()=>{if(b&&b.length>0){const k=b[0].id;c(k),l(k)}},[b]);const C=i(async()=>{if(!o||!n){r("Please select a contact to merge with",{type:"warning"});return}try{m(!0),await v(),m(!1),r("Contacts merged successfully",{type:"success"}),a(`/contacts/${o}/show`),t()}catch(k){m(!1),r("Failed to merge contacts",{type:"error"}),console.error("Merge failed:",k)}},"handleMerge");return n?u.jsx(ga,{open:e,onOpenChange:t,children:u.jsxs(va,{className:"md:min-w-lg max-w-2xl",children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Merge Contact"}),u.jsx(ui,{children:"Merge this contact with another one."})]}),u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"p-4 bg-primary/5 rounded-lg border border-primary/20",children:[u.jsx("p",{className:"font-medium text-sm",children:"Current Contact (will be deleted)"}),u.jsx("div",{className:"font-medium text-sm mt-4",children:tw}),u.jsx("div",{className:"flex justify-center my-4",children:u.jsx(WQ,{className:"h-5 w-5 text-muted-foreground"})}),u.jsx("p",{className:"font-medium text-sm mb-2",children:"Target Contact (will be kept)"}),u.jsx(zr,{children:u.jsx(ro,{source:"winner_id",reference:"contacts",filter:{"id@neq":n.id},children:u.jsx(Od,{label:"",optionText:tw,validate:Pn(),onChange:l,defaultValue:f,helperText:!1})})})]}),o&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("p",{className:"font-medium text-sm",children:"What will be merged:"}),u.jsxs("ul",{className:"text-sm text-muted-foreground space-y-1 ml-4",children:[_!=null&&_>0&&u.jsxs("li",{children:["• ",_," note",_!==1?"s":""," will be reassigned"]}),S!=null&&S>0&&u.jsxs("li",{children:["• ",S," task",S!==1?"s":""," will be reassigned"]}),j!=null&&j>0&&u.jsxs("li",{children:["• ",j," deal",j!==1?"s":""," will be updated"]}),n.email_jsonb?.length>0&&u.jsxs("li",{children:["• ",n.email_jsonb.length," email address",n.email_jsonb.length!==1?"es":""," will be added"]}),n.phone_jsonb?.length>0&&u.jsxs("li",{children:["• ",n.phone_jsonb.length," phone number",n.phone_jsonb.length!==1?"s":""," will be added"]}),!_&&!S&&!j&&!n.email_jsonb?.length&&!n.phone_jsonb?.length&&u.jsx("li",{className:"text-muted-foreground/60",children:"No additional data to merge"})]})]}),u.jsxs(Ga,{variant:"destructive",children:[u.jsx(XQ,{className:"h-4 w-4"}),u.jsx(n3,{children:"Warning: Destructive Operation"}),u.jsx(di,{children:"All data will be transferred to the second contact. This action cannot be undone."})]})]})]}),u.jsxs(ps,{children:[u.jsxs(Le,{variant:"ghost",onClick:t,disabled:p,children:[u.jsx(uo,{}),"Cancel"]}),u.jsxs(Le,{onClick:C,disabled:!o||p,children:[u.jsx(g1,{}),p?"Merging...":"Merge Contacts"]})]})]})}):null},"ContactMergeDialog");function x6e(e){if(e.length<=75)return e;const n=[];let r=e.substring(0,75),a=e.substring(75);for(n.push(r);a.length>0;)r=" "+a.substring(0,74),a=a.substring(74),n.push(r);return n.join(`\r
111
+ Defaulting to \`null\`.`}i(F3e,"getInvalidValueError");var L3e=hne,$3e=mne;function d_({className:e,value:t,...n}){return u.jsx(L3e,{"data-slot":"progress",className:xe("bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",e),...n,children:u.jsx($3e,{"data-slot":"progress-indicator",className:"bg-primary h-full w-full flex-1 transition-all",style:{transform:`translateX(-${100-(t||0)}%)`}})})}i(d_,"Progress");const q3e=i(()=>{const e=Ft();if(!e)return null;const t=e.internal_heartbeat_score!==void 0||e.internal_heartbeat_status||e.days_since_last_activity!==void 0,n=e.external_heartbeat_status||e.external_heartbeat_checked_at;return!t&&!n?null:u.jsxs(fi,{title:"Company Health",children:[t&&u.jsxs("div",{className:"mb-4",children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(p1,{className:"w-4 h-4 text-muted-foreground"}),u.jsx("span",{className:"font-medium text-sm",children:"Internal Engagement"})]}),e.internal_heartbeat_score!==void 0&&u.jsxs("div",{className:"mb-2",children:[u.jsxs("div",{className:"flex items-center justify-between mb-1",children:[u.jsx("span",{className:"text-xs text-muted-foreground",children:"Engagement Score"}),u.jsxs("span",{className:"text-xs font-medium",children:[e.internal_heartbeat_score,"/100"]})]}),u.jsx(d_,{value:e.internal_heartbeat_score,className:"h-2"})]}),e.internal_heartbeat_status&&u.jsx("div",{className:"mb-2",children:u.jsx(U3e,{status:e.internal_heartbeat_status})}),e.days_since_last_activity!==void 0&&u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Last activity:"," ",e.days_since_last_activity===0?"Today":e.days_since_last_activity===1?"Yesterday":`${e.days_since_last_activity} days ago`]}),e.internal_heartbeat_updated_at&&u.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Updated"," ",nd(new Date(e.internal_heartbeat_updated_at),new Date,{addSuffix:!0})]})]}),n&&u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(ZM,{className:"w-4 h-4 text-muted-foreground"}),u.jsx("span",{className:"font-medium text-sm",children:"External Health"})]}),e.external_heartbeat_status&&u.jsx("div",{className:"mb-2",children:u.jsx(z3e,{status:e.external_heartbeat_status})}),e.external_heartbeat_checked_at&&u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Last checked"," ",nd(new Date(e.external_heartbeat_checked_at),new Date,{addSuffix:!0})]})]})]})},"CompanyHealthCard"),U3e=i(({status:e})=>{const n={engaged:{variant:"default",label:"Engaged"},quiet:{variant:"secondary",label:"Quiet"},at_risk:{variant:"outline",label:"At Risk"},unresponsive:{variant:"destructive",label:"Unresponsive"}}[e]||{variant:"outline",label:e};return u.jsx(Kn,{variant:n.variant,className:"text-xs",children:n.label})},"InternalStatusBadge$1"),z3e=i(({status:e})=>{const n={healthy:{variant:"default",label:"Healthy"},risky:{variant:"outline",label:"Risky"},dead:{variant:"destructive",label:"Dead"},unknown:{variant:"secondary",label:"Unknown"}}[e]||{variant:"outline",label:e};return u.jsx(Kn,{variant:n.variant,className:"text-xs",children:n.label})},"ExternalStatusBadge"),vne=i(({link:e="edit"})=>{const t=Ft();return t?u.jsxs("div",{className:"hidden sm:block w-[250px] min-w-[250px] space-y-4",children:[u.jsx("div",{className:"flex flex-row space-x-1",children:e==="edit"?u.jsx(lne,{label:"Edit Company"}):u.jsx(cne,{label:"Show Company"})}),u.jsx(q3e,{}),u.jsx(B3e,{record:t}),u.jsx(V3e,{record:t}),u.jsx(H3e,{record:t}),u.jsx(W3e,{record:t}),e!=="edit"&&u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"mt-6 pt-6 border-t hidden sm:flex flex-col gap-2 items-start",children:u.jsx(A3e,{})}),u.jsx("div",{className:"mt-6 pt-6 border-t hidden sm:flex flex-col gap-2 items-start",children:u.jsx(c_,{className:"h-6 cursor-pointer hover:bg-destructive/10! text-destructive! border-destructive! focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",size:"sm"})})]})]}):null},"CompanyAside"),B3e=i(({record:e})=>!e.website&&!e.linkedin_url&&!e.phone_number?null:u.jsxs(fi,{title:"Company Info",children:[e.website&&u.jsxs("div",{className:"flex flex-row items-center gap-1 min-h-[24px]",children:[u.jsx(m1e,{className:"w-4 h-4"}),u.jsx(k3e,{source:"website",target:"_blank",rel:"noopener",content:e.website.replace("http://","").replace("https://","")})]}),e.linkedin_url&&u.jsxs("div",{className:"flex flex-row items-center gap-1 min-h-[24px]",children:[u.jsx(JM,{className:"w-4 h-4"}),u.jsx("a",{className:"underline hover:no-underline",href:e.linkedin_url,target:"_blank",rel:"noopener noreferrer",title:e.linkedin_url,children:"LinkedIn"})]}),e.phone_number&&u.jsxs("div",{className:"flex flex-row items-center gap-1 min-h-[24px]",children:[u.jsx(n4,{className:"w-4 h-4"}),u.jsx(Ir,{source:"phone_number"})]})]}),"CompanyInfo"),H3e=i(({record:e})=>!e.revenue&&!e.id?null:u.jsxs(fi,{title:"Context",children:[e.sector&&u.jsxs("span",{children:["Sector: ",u.jsx(Ir,{source:"sector"})]}),e.size&&u.jsxs("span",{children:["Size: ",u.jsx(R3e,{source:"size",choices:W4})]}),e.revenue&&u.jsxs("span",{children:["Revenue: ",u.jsx(Ir,{source:"revenue"})]}),e.tax_identifier&&u.jsxs("span",{children:["Tax Identifier: ",u.jsx(Ir,{source:"tax_identifier"})]})]}),"ContextInfo"),V3e=i(({record:e})=>!e.address&&!e.city&&!e.zipcode&&!e.stateAbbr?null:u.jsxs(fi,{title:"Main Address",noGap:!0,children:[u.jsx(Ir,{source:"address"}),u.jsx(Ir,{source:"city"}),u.jsx(Ir,{source:"zipcode"}),u.jsx(Ir,{source:"stateAbbr"}),u.jsx(Ir,{source:"country"})]}),"AddressInfo"),W3e=i(({record:e})=>{if(!e.created_at&&!e.sales_id&&!e.description&&!e.context_links)return null;const t=i(n=>new URL(n.startsWith("http")?n:`https://${n}`).hostname,"getBaseURL");return u.jsxs(fi,{title:"Additional Info",children:[e.description&&u.jsx("p",{className:"text-sm mb-1",children:e.description}),e.context_links&&Array.isArray(e.context_links)&&u.jsx("div",{className:"flex flex-col",children:e.context_links.map((n,r)=>n?u.jsx("a",{className:"text-sm underline hover:no-underline mb-1",href:n.startsWith("http")?n:`https://${n}`,target:"_blank",rel:"noopener noreferrer",title:n,children:t(n)},r):null)}),e.sales_id!==null&&u.jsxs("div",{className:"inline-flex text-sm text-muted-foreground mb-1",children:["Followed by ",u.jsx(xn,{source:"sales_id",reference:"sales",record:e,children:u.jsx(Bc,{})})]}),e.created_at&&u.jsxs("p",{className:"text-sm text-muted-foreground mb-1",children:["Added on"," ",u.jsx(cd,{source:"created_at",record:e,options:{year:"numeric",month:"long",day:"numeric"}})]})]})},"AdditionalInfo"),G3e=i(()=>u.jsx(DM,{children:u.jsx(K3e,{})}),"CompanyShow"),K3e=i(()=>{const{record:e,isPending:t}=MM(),n=Ra(),a=MD("/companies/:id/show/:tab")?.params?.tab||"activity",s=i(o=>{if(o!==a){if(o==="activity"){n(`/companies/${e?.id}/show`);return}n(`/companies/${e?.id}/show/${o}`)}},"handleTabChange");return t||!e?null:u.jsxs("div",{className:"mt-2 flex pb-2 gap-8",children:[u.jsx("div",{className:"flex-1",children:u.jsx(un,{children:u.jsxs(Un,{children:[u.jsxs("div",{className:"flex mb-3",children:[u.jsx(kd,{}),u.jsx("h5",{className:"text-xl ml-2 flex-1",children:e.name})]}),u.jsxs(Gte,{defaultValue:a,onValueChange:s,children:[u.jsxs(Kte,{className:"grid w-full grid-cols-4",children:[u.jsx(cc,{value:"activity",children:"Activity"}),u.jsx(cc,{value:"contacts",children:e.nb_contacts?e.nb_contacts===1?"1 Contact":`${e.nb_contacts} Contacts`:"No Contacts"}),u.jsx(cc,{value:"notes",children:e.nb_notes?e.nb_notes===1?"1 Note":`${e.nb_notes} Notes`:"Notes"}),e.nb_deals?u.jsx(cc,{value:"deals",children:e.nb_deals===1?"1 deal":`${e.nb_deals} deals`}):null]}),u.jsx(uc,{value:"activity",className:"pt-2",children:u.jsx(nne,{companyId:e.id,context:"company"})}),u.jsx(uc,{value:"contacts",children:e.nb_contacts?u.jsx(Gu,{reference:"contacts_summary",target:"company_id",sort:{field:"last_name",order:"ASC"},children:u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex flex-row justify-end space-x-2 mt-1",children:[!!e.nb_contacts&&u.jsx(H4,{fields:["last_name","first_name","last_seen"]}),u.jsx(FH,{})]}),u.jsx(Y3e,{})]})}):u.jsx("div",{className:"flex flex-col gap-4",children:u.jsx("div",{className:"flex flex-row justify-end space-x-2 mt-1",children:u.jsx(FH,{})})})}),u.jsx(uc,{value:"notes",children:u.jsx(Gu,{reference:"companyNotes",target:"company_id",sort:{field:"date",order:"DESC"},empty:u.jsx(l_,{reference:"companies",className:"mt-4"}),children:u.jsx(a3,{reference:"companies"})})}),u.jsx(uc,{value:"deals",children:e.nb_deals?u.jsx(Gu,{reference:"deals",target:"company_id",sort:{field:"name",order:"ASC"},children:u.jsx(Q3e,{})}):null})]})]})})}),u.jsx(vne,{})]})},"CompanyShowContent"),Y3e=i(()=>{const e=Ur(),{data:t,error:n,isPending:r}=Xn();if(r||n)return null;const a=Date.now();return u.jsx("div",{className:"pt-0",children:t.map(s=>u.jsx(Ya,{value:s,children:u.jsx("div",{className:"p-0 text-sm",children:u.jsxs(nn,{to:`/contacts/${s.id}/show`,state:{from:e.pathname},className:"flex items-center justify-between hover:bg-muted py-2 transition-colors",children:[u.jsx("div",{className:"mr-4",children:u.jsx(ho,{})}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"font-medium",children:`${s.first_name} ${s.last_name}`}),u.jsxs("div",{className:"text-sm text-muted-foreground",children:[s.title,s.nb_tasks?` - ${s.nb_tasks} task${s.nb_tasks>1?"s":""}`:"","   ",u.jsx(rne,{})]})]}),s.last_seen&&u.jsx("div",{className:"text-right",children:u.jsxs("div",{className:"text-sm text-muted-foreground",children:["last activity ",nd(s.last_seen,a)," ago"," ",u.jsx(zy,{status:s.status})]})})]})})},s.id))})},"ContactsIterator"),FH=i(()=>{const e=Ft();return u.jsx(Le,{variant:"outline",asChild:!0,size:"sm",className:"h-9",children:u.jsxs(nn,{to:"/contacts/create",state:e?{record:{company_id:e.id}}:void 0,className:"flex items-center gap-2",children:[u.jsx(N_e,{className:"h-4 w-4"}),"Add contact"]})})},"CreateRelatedContactButton"),Q3e=i(()=>{const{data:e,error:t,isPending:n}=Xn(),{dealStages:r}=la();if(n||t)return null;const a=Date.now();return u.jsx("div",{children:u.jsx("div",{children:e.map(s=>u.jsx("div",{className:"p-0 text-sm",children:u.jsxs(nn,{to:`/deals/${s.id}/show`,className:"flex items-center justify-between hover:bg-muted py-2 px-4 transition-colors",children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"font-medium",children:s.name}),u.jsxs("div",{className:"text-sm text-muted-foreground",children:[d3e(r,s.stage),","," ",s.amount.toLocaleString("en-US",{notation:"compact",style:"currency",currency:"USD",currencyDisplay:"narrowSymbol",minimumSignificantDigits:3}),s.category?`, ${s.category}`:""]})]}),u.jsx("div",{className:"text-right",children:u.jsxs("div",{className:"text-sm text-muted-foreground",children:["last activity ",nd(s.updated_at,a)," ago"," "]})})]})},s.id))})})},"DealsIterator"),o3=i(()=>u.jsxs("div",{role:"toolbar",className:"sticky flex pt-4 pb-4 md:pb-0 bottom-0 bg-linear-to-b from-transparent to-card to-10% flex-row justify-end gap-2",children:[u.jsx(t_,{}),u.jsx(jd,{})]}),"FormToolbar"),X3e=i(()=>u.jsx(wM,{actions:!1,redirect:"show",transform:i(e=>(e.website&&!e.website.startsWith("http")&&(e.website=`https://${e.website}`),e),"transform"),children:u.jsxs("div",{className:"mt-2 flex gap-8",children:[u.jsx(zr,{className:"flex flex-1 flex-col gap-4 pb-2",children:u.jsx(un,{children:u.jsxs(Un,{children:[u.jsx(Ite,{}),u.jsx(o3,{})]})})}),u.jsx(vne,{link:"show"})]})}),"CompanyEdit"),Z3e={list:xPe,create:$4e,edit:X3e,show:G3e};var f_="Switch",[J3e,sHe]=oa(f_),[e5e,t5e]=J3e(f_),yne=y.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:a,defaultChecked:s,required:o,disabled:l,value:f="on",onCheckedChange:c,form:p,...m}=e,[v,b]=y.useState(null),w=Xt(t,k=>b(k)),S=y.useRef(!1),_=v?p||!!v.closest("form"):!0,[j,C]=Fi({prop:a,defaultProp:s??!1,onChange:c,caller:f_});return u.jsxs(e5e,{scope:n,checked:j,disabled:l,children:[u.jsx(mt.button,{type:"button",role:"switch","aria-checked":j,"aria-required":o,"data-state":_ne(j),"data-disabled":l?"":void 0,disabled:l,value:f,...m,ref:w,onClick:Je(e.onClick,k=>{C(E=>!E),_&&(S.current=k.isPropagationStopped(),S.current||k.stopPropagation())})}),_&&u.jsx(wne,{control:v,bubbles:!S.current,name:r,value:f,checked:j,required:o,disabled:l,form:p,style:{transform:"translateX(-100%)"}})]})});yne.displayName=f_;var bne="SwitchThumb",xne=y.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,a=t5e(bne,n);return u.jsx(mt.span,{"data-state":_ne(a.checked),"data-disabled":a.disabled?"":void 0,...r,ref:t})});xne.displayName=bne;var n5e="SwitchBubbleInput",wne=y.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...a},s)=>{const o=y.useRef(null),l=Xt(o,s),f=W1(n),c=O1(t);return y.useEffect(()=>{const p=o.current;if(!p)return;const m=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(m,"checked").set;if(f!==n&&b){const w=new Event("click",{bubbles:r});b.call(p,n),p.dispatchEvent(w)}},[f,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...a,tabIndex:-1,ref:l,style:{...a.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});wne.displayName=n5e;function _ne(e){return e?"checked":"unchecked"}i(_ne,"getState$2");var r5e=yne,a5e=xne;function l3({className:e,...t}){return u.jsx(r5e,{"data-slot":"switch",className:xe("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:u.jsx(a5e,{"data-slot":"switch-thumb",className:xe("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}i(l3,"Switch");const ew=i(e=>{const{className:t,defaultValue:n=!1,format:r,label:a,helperText:s,onBlur:o,onChange:l,onFocus:f,readOnly:c,disabled:p,parse:m,resource:v,source:b,validate:w,...S}=e,{id:_,field:j,isRequired:C}=Pc({defaultValue:n,format:r,parse:m,resource:v,source:b,onBlur:o,onChange:l,type:"checkbox",validate:w,disabled:p,readOnly:c,...S}),k=y.useCallback(E=>{j.onChange(E),j.onBlur()},[j]);return u.jsxs(eo,{className:t,id:_,name:j.name,children:[u.jsxs("div",{className:"flex items-center space-x-2",children:[u.jsx(l3,{id:_,checked:!!j.value,onFocus:f,onCheckedChange:k}),u.jsx(al,{htmlFor:_,children:u.jsx(ma,{label:a,source:b,resource:v,isRequired:C})})]}),u.jsx(to,{helperText:s}),u.jsx(ul,{})]})},"BooleanInput");var c3="Radio",[i5e,Sne]=oa(c3),[s5e,o5e]=i5e(c3),jne=y.forwardRef((e,t)=>{const{__scopeRadio:n,name:r,checked:a=!1,required:s,disabled:o,value:l="on",onCheck:f,form:c,...p}=e,[m,v]=y.useState(null),b=Xt(t,_=>v(_)),w=y.useRef(!1),S=m?c||!!m.closest("form"):!0;return u.jsxs(s5e,{scope:n,checked:a,disabled:o,children:[u.jsx(mt.button,{type:"button",role:"radio","aria-checked":a,"data-state":One(a),"data-disabled":o?"":void 0,disabled:o,value:l,...p,ref:b,onClick:Je(e.onClick,_=>{a||f?.(),S&&(w.current=_.isPropagationStopped(),w.current||_.stopPropagation())})}),S&&u.jsx(kne,{control:m,bubbles:!w.current,name:r,value:l,checked:a,required:s,disabled:o,form:c,style:{transform:"translateX(-100%)"}})]})});jne.displayName=c3;var Cne="RadioIndicator",Ene=y.forwardRef((e,t)=>{const{__scopeRadio:n,forceMount:r,...a}=e,s=o5e(Cne,n);return u.jsx(ba,{present:r||s.checked,children:u.jsx(mt.span,{"data-state":One(s.checked),"data-disabled":s.disabled?"":void 0,...a,ref:t})})});Ene.displayName=Cne;var l5e="RadioBubbleInput",kne=y.forwardRef(({__scopeRadio:e,control:t,checked:n,bubbles:r=!0,...a},s)=>{const o=y.useRef(null),l=Xt(o,s),f=W1(n),c=O1(t);return y.useEffect(()=>{const p=o.current;if(!p)return;const m=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(m,"checked").set;if(f!==n&&b){const w=new Event("click",{bubbles:r});b.call(p,n),p.dispatchEvent(w)}},[f,n,r]),u.jsx(mt.input,{type:"radio","aria-hidden":!0,defaultChecked:n,...a,tabIndex:-1,ref:l,style:{...a.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});kne.displayName=l5e;function One(e){return e?"checked":"unchecked"}i(One,"getState$1");var c5e=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],h_="RadioGroup",[u5e,oHe]=oa(h_,[Hp,Sne]),Rne=Hp(),Ane=Sne(),[d5e,f5e]=u5e(h_),Tne=y.forwardRef((e,t)=>{const{__scopeRadioGroup:n,name:r,defaultValue:a,value:s,required:o=!1,disabled:l=!1,orientation:f,dir:c,loop:p=!0,onValueChange:m,...v}=e,b=Rne(n),w=Ny(c),[S,_]=Fi({prop:s,defaultProp:a??null,onChange:m,caller:h_});return u.jsx(d5e,{scope:n,name:r,required:o,disabled:l,value:S,onValueChange:_,children:u.jsx(_4,{asChild:!0,...b,orientation:f,dir:w,loop:p,children:u.jsx(mt.div,{role:"radiogroup","aria-required":o,"aria-orientation":f,"data-disabled":l?"":void 0,dir:w,...v,ref:t})})})});Tne.displayName=h_;var Nne="RadioGroupItem",Pne=y.forwardRef((e,t)=>{const{__scopeRadioGroup:n,disabled:r,...a}=e,s=f5e(Nne,n),o=s.disabled||r,l=Rne(n),f=Ane(n),c=y.useRef(null),p=Xt(t,c),m=s.value===a.value,v=y.useRef(!1);return y.useEffect(()=>{const b=i(S=>{c5e.includes(S.key)&&(v.current=!0)},"handleKeyDown"),w=i(()=>v.current=!1,"handleKeyUp");return document.addEventListener("keydown",b),document.addEventListener("keyup",w),()=>{document.removeEventListener("keydown",b),document.removeEventListener("keyup",w)}},[]),u.jsx(S4,{asChild:!0,...l,focusable:!o,active:m,children:u.jsx(jne,{disabled:o,required:s.required,checked:m,...f,...a,name:s.name,ref:p,onCheck:i(()=>s.onValueChange(a.value),"onCheck"),onKeyDown:Je(b=>{b.key==="Enter"&&b.preventDefault()}),onFocus:Je(a.onFocus,()=>{v.current&&c.current?.click()})})})});Pne.displayName=Nne;var h5e="RadioGroupIndicator",Dne=y.forwardRef((e,t)=>{const{__scopeRadioGroup:n,...r}=e,a=Ane(n);return u.jsx(Ene,{...a,...r,ref:t})});Dne.displayName=h5e;var p5e=Tne,m5e=Pne,g5e=Dne;function v5e({className:e,...t}){return u.jsx(p5e,{"data-slot":"radio-group",className:xe("grid gap-3",e),...t})}i(v5e,"RadioGroup");function y5e({className:e,...t}){return u.jsx(m5e,{"data-slot":"radio-group-item",className:xe("border-input text-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 aspect-square size-4 shrink-0 rounded-full border shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:u.jsx(g5e,{"data-slot":"radio-group-indicator",className:"relative flex items-center justify-center",children:u.jsx(ON,{className:"fill-primary absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2"})})})}i(y5e,"RadioGroupItem");const b5e=i(e=>{const{choices:t,isFetching:n,isLoading:r,isPending:a,resource:s,source:o,format:l,onBlur:f,onChange:c,parse:p,validate:m,disabled:v,readOnly:b,optionText:w,optionValue:S="id",translateChoice:_,disableValue:j="disabled",className:C,helperText:k,label:E,row:T,...R}=e,{allChoices:A,isPending:N,error:D,resource:M,source:I}=$M({choices:t,isFetching:n,isLoading:r,isPending:a,resource:s,source:o});if(I===void 0)throw new Error("If you're not wrapping the RadioButtonGroupInput inside a ReferenceArrayInput, you must provide the source prop");if(!N&&!D&&A===void 0)throw new Error("If you're not wrapping the RadioButtonGroupInput inside a ReferenceArrayInput, you must provide the choices prop");const{id:F,field:L,isRequired:q}=Pc({format:l,onBlur:f,onChange:c,parse:p,resource:M,source:I,validate:m,disabled:v,readOnly:b,...R}),{getChoiceText:z,getChoiceValue:$,getDisableValue:H}=l1({optionText:w,optionValue:S,translateChoice:_,disableValue:j});return N?u.jsx(cn,{className:"w-full h-9"}):u.jsxs(eo,{id:F,className:C,name:L.name,children:[E&&u.jsx(al,{children:u.jsx(ma,{label:E,source:I,resource:M,isRequired:q})}),u.jsx(Iy,{children:u.jsx(v5e,{...R,value:L.value||"",onValueChange:L.onChange,className:xe("flex",T?"flex-row gap-4":"flex-col gap-2"),disabled:v||b,children:A?.map(U=>{const W=$(U),V=v||b||H(U);return u.jsxs("div",{className:"flex items-center space-x-2",children:[u.jsx(y5e,{value:W,id:`${F}-${W}`,disabled:V}),u.jsx(Gn,{htmlFor:`${F}-${W}`,className:xe("text-sm font-normal cursor-pointer",V&&"opacity-50 cursor-not-allowed"),children:z(U)})]},W)})})}),u.jsx(to,{helperText:k}),u.jsx(ul,{})]})},"RadioButtonGroupInput"),x5e=i(({validate:e})=>{const[t]=IM(),{identity:n}=Yn(),r=Ht(),a=i(async s=>{if(s)try{return await t("companies",{data:{name:s,sales_id:n?.id,created_at:new Date().toISOString()}},{returnPromise:!0})}catch{r("An error occurred while creating the company",{type:"error"})}},"handleCreateCompany");return u.jsx(Od,{optionText:"name",helperText:!1,onCreate:a,createItemLabel:"Create %{item}",createLabel:"Start typing to create a new company",validate:e})},"AutocompleteCompanyInput"),Mne=i(()=>{const e=xd();return u.jsxs("div",{className:"flex flex-col gap-2 p-1",children:[u.jsx(ho,{}),u.jsxs("div",{className:`flex gap-6 ${e?"flex-col":"flex-row"}`,children:[u.jsxs("div",{className:"flex flex-col gap-10 flex-1",children:[u.jsx(w5e,{}),u.jsx(_5e,{})]}),u.jsx(bc,{orientation:e?"horizontal":"vertical",className:"flex-shrink-0"}),u.jsxs("div",{className:"flex flex-col gap-10 flex-1",children:[u.jsx(S5e,{}),u.jsx(j5e,{})]})]})]})},"ContactInputs"),w5e=i(()=>{const{contactGender:e}=la();return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("h6",{className:"text-lg font-semibold",children:"Identity"}),u.jsx(b5e,{label:!1,row:!0,source:"gender",choices:e,helperText:!1,optionText:"label",optionValue:"value",defaultValue:e[0].value}),u.jsx(Ut,{source:"first_name",validate:Pn(),helperText:!1}),u.jsx(Ut,{source:"last_name",validate:Pn(),helperText:!1})]})},"ContactIdentityInputs"),_5e=i(()=>u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("h6",{className:"text-lg font-semibold",children:"Position"}),u.jsx(Ut,{source:"title",helperText:!1}),u.jsx(ro,{source:"company_id",reference:"companies",perPage:10,children:u.jsx(x5e,{})})]}),"ContactPositionInputs"),S5e=i(()=>{const{getValues:e,setValue:t}=ya(),n=i(s=>{const{first_name:o,last_name:l}=e();if(o||l||!s)return;const[f,c]=s.split("@")[0].split(".");t("first_name",f.charAt(0).toUpperCase()+f.slice(1)),t("last_name",c?c.charAt(0).toUpperCase()+c.slice(1):"")},"handleEmailChange"),r=i(s=>{const o=s.clipboardData?.getData("text/plain");n(o)},"handleEmailPaste"),a=i(s=>{const o=s.target.value;n(o)},"handleEmailBlur");return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("h6",{className:"text-lg font-semibold",children:"Personal info"}),u.jsx(kP,{source:"email_jsonb",label:"Email addresses",helperText:!1,children:u.jsxs(OP,{inline:!0,disableReordering:!0,disableClear:!0,className:"[&>ul>li]:border-b-0 [&>ul>li]:pb-0",children:[u.jsx(Ut,{source:"email",className:"w-full",helperText:!1,label:!1,placeholder:"Email",validate:EY(),onPaste:r,onBlur:a}),u.jsx(or,{source:"type",helperText:!1,label:!1,optionText:"id",choices:LH,defaultValue:"Work",className:"w-24 min-w-24"})]})}),u.jsx(kP,{source:"phone_jsonb",label:"Phone numbers",helperText:!1,children:u.jsxs(OP,{inline:!0,disableReordering:!0,disableClear:!0,className:"[&>ul>li]:border-b-0 [&>ul>li]:pb-0",children:[u.jsx(Ut,{source:"number",className:"w-full",helperText:!1,label:!1,placeholder:"Phone number"}),u.jsx(or,{source:"type",helperText:!1,label:!1,optionText:"id",choices:LH,defaultValue:"Work",className:"w-24 min-w-24"})]})}),u.jsx(Ut,{source:"linkedin_url",label:"Linkedin URL",helperText:!1,validate:Mte})]})},"ContactPersonalInformationInputs"),LH=[{id:"Work"},{id:"Home"},{id:"Other"}],j5e=i(()=>u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("h6",{className:"text-lg font-semibold",children:"Misc"}),u.jsx(Ut,{source:"background",label:"Background info (bio, how you met, etc)",multiline:!0,helperText:!1}),u.jsx(ew,{source:"has_newsletter",helperText:!1}),u.jsx(ro,{reference:"sales",source:"sales_id",sort:{field:"last_name",order:"ASC"},filter:{"disabled@neq":!0},children:u.jsx(or,{helperText:!1,label:"Account manager",optionText:C5e,validate:Pn()})})]}),"ContactMiscInputs"),C5e=i(e=>`${e.first_name} ${e.last_name}`,"saleOptionRenderer"),E5e=i(()=>{const{identity:e}=Yn();return u.jsx(hy,{redirect:"show",transform:i(t=>({...t,first_seen:new Date().toISOString(),last_seen:new Date().toISOString(),tags:[]}),"transform"),children:u.jsx("div",{className:"mt-2 flex lg:mr-72",children:u.jsx("div",{className:"flex-1",children:u.jsx(zr,{defaultValues:{sales_id:e?.id},children:u.jsx(un,{children:u.jsxs(Un,{children:[u.jsx(Mne,{}),u.jsx(n_,{})]})})})})})})},"ContactCreate"),$H=i(e=>{const{children:t,resource:n,perPage:r,sort:a,filter:s}=e,o=pi(e)||k5e,l=Qw({data:o,resource:n,perPage:r,sort:a,filter:s});return u.jsx(py,{value:l,children:t})},"ArrayField"),k5e=[],O5e=i(({icon:e=R5e,label:t,className:n,...r})=>{const{handleDelete:a,isPending:s}=Ope(r);return u.jsxs(Le,{variant:"destructive",type:"button",onClick:a,disabled:s,className:xe("h-9",n),children:[e,u.jsx(nr,{i18nKey:t??"ra.action.delete",children:t??"Delete"})]})},"BulkDeleteButton"),R5e=u.jsx(a4,{}),A5e=i(({icon:e=T5e,label:t="ra.action.export",onClick:n,...r})=>{const a=bme(r),s=i(o=>{a(),n?.(o)},"handleClick");return u.jsxs(Le,{onClick:s,role:"button",variant:"outline",size:"sm",className:"flex items-center gap-2 h-9",...N5e(r),children:[e,t&&u.jsx(nr,{i18nKey:t,children:t})]})},"BulkExportButton"),T5e=u.jsx(QM,{className:"h-4 w-4"}),N5e=i(({resource:e,exporter:t,onClick:n,label:r,icon:a,meta:s,...o})=>o,"sanitizeRestProps");function Ine(){return u.jsxs(u.Fragment,{children:[u.jsx(A5e,{}),u.jsx(O5e,{})]})}i(Ine,"BulkActionsToolbarChildren");const Fne=i(({children:e=u.jsx(Ine,{})})=>{const{selectedIds:t,onUnselectItems:n}=Xn();if(!t?.length)return null;const r=i(a=>{a.stopPropagation(),n()},"handleUnselectAll");return u.jsxs(un,{className:"flex flex-col gap-2 md:gap-6 md:flex-row items-stretch sm:items-center p-2 px-4 w-[90%] sm:w-fit mx-auto fixed bottom-2 left-0 right-0 z-10 bg-zinc-100 dark:bg-zinc-900",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(Le,{variant:"ghost",className:"has-[>svg]:px-0",onClick:r,children:u.jsx($p,{})}),u.jsx("span",{className:"text-sm text-muted-foreground",children:u.jsxs(nr,{i18nKey:"ra.action.bulk_actions",options:{smart_count:t.length},children:[t.length," rows selected"]})})]}),e]})},"BulkActionsToolbar");var FA={exports:{}},qH;function P5e(){return qH||(qH=1,(function(e){(function(t,n){e.exports?e.exports=n():this[t]=n()})("Diacritics",function(){for(var t={map:{}},n=[{base:" ",letters:" "},{base:"A",letters:"AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"BⒷBḂḄḆɃƂƁ"},{base:"C",letters:"CⒸCĆĈĊČÇḈƇȻꜾ"},{base:"D",letters:"DⒹDḊĎḌḐḒḎĐƋƊƉꝹ"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ"},{base:"F",letters:"FⒻFḞƑꝻ"},{base:"G",letters:"GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ"},{base:"H",letters:"HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"JⒿJĴɈ"},{base:"K",letters:"KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"MⓂMḾṀṂⱮƜ"},{base:"N",letters:"NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"P",letters:"PⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"QⓆQꝖꝘɊ"},{base:"R",letters:"RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"Th",letters:"Þ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"VⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"WⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"XⓍXẊẌ"},{base:"Y",letters:"YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"bⓑbḃḅḇƀƃɓ"},{base:"c",letters:"cⓒcćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"dⓓdḋďḍḑḓḏđƌɖɗꝺ"},{base:"dz",letters:"dzdž"},{base:"e",letters:"eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ"},{base:"f",letters:"fⓕfḟƒꝼ"},{base:"ff",letters:"ff"},{base:"fi",letters:"fi"},{base:"fl",letters:"fl"},{base:"ffi",letters:"ffi"},{base:"ffl",letters:"ffl"},{base:"g",letters:"gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ"},{base:"h",letters:"hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"jⓙjĵǰɉ"},{base:"k",letters:"kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ"},{base:"lj",letters:"lj"},{base:"m",letters:"mⓜmḿṁṃɱɯ"},{base:"n",letters:"nñnⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥлԉ"},{base:"nj",letters:"nj"},{base:"o",letters:"߀oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ"},{base:"oe",letters:"Œœ"},{base:"oi",letters:"ƣ"},{base:"ou",letters:"ȣ"},{base:"oo",letters:"ꝏ"},{base:"p",letters:"pⓟpṕṗƥᵽꝑꝓꝕ"},{base:"q",letters:"qⓠqɋꝗꝙ"},{base:"r",letters:"rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"sⓢsßśṥŝṡšṧṣṩșşȿꞩꞅẛ"},{base:"ss",letters:"ß"},{base:"t",letters:"tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"th",letters:"þ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"vⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"wⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"xⓧxẋẍ"},{base:"y",letters:"yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"zⓩzźẑżžẓẕƶȥɀⱬꝣ"}],r=0,a=n.length;r<a;r++)for(var s=n[r].letters.split(""),o=0,l=s.length;o<l;o++)t.map[s[o]]=n[r].base;return t.clean=function(f){if(!f||!f.length||f.length<1)return"";for(var c="",p=f.split(""),m=0,v=p.length,b;m<v;m++)b=p[m],c+=b in t.map?t.map[b]:b;return c},t})})(FA)),FA.exports}i(P5e,"requireDiacritics");var UH=P5e();const D5e=i(e=>{const{selected:t,label:n,onToggle:r,onMove:a,source:s,index:o}=e,l=Wt(),f=y.useRef(null),c=y.useRef(null),p=y.useRef(null),m=y.useCallback(_=>{c.current=_.clientX,p.current=_.clientY},[]),v=i(()=>{document.addEventListener("dragover",m)},"handleDragStart"),b=i(_=>{const j=_.target;j.dataset.dragActive="true";const C=j.closest("ul");if(c.current==null||p.current==null)return;const k=document.elementFromPoint(c.current,p.current);let E=k===null?j:k.closest("li");if(!E)return;if(E.classList.contains("dragIcon")){const R=E.parentNode;R instanceof HTMLElement&&(E=R)}if(E===j)return;const T=E.parentNode;if(C&&T instanceof HTMLElement&&C===T.closest("ul")){const R=E.dataset.index;R&&(f.current=parseInt(R,10)),E===j.nextSibling&&(E=E.nextSibling),C.insertBefore(j,E)}},"handleDrag"),w=i(_=>{const j=_.target,C=j.closest("ul"),k=c.current!=null&&p.current!=null?document.elementFromPoint(c.current,p.current):null;let E=c.current==null||p.current==null||k===null?j:k.closest("li");if(p.current!==null&&C&&!E){const T=j.closest("ul");T&&p.current>T.getBoundingClientRect().bottom?E=C.lastChild:E=C.firstChild}E&&C&&E.closest("ul")===C?a&&a(j.dataset.index,f.current):(_.preventDefault(),_.stopPropagation()),j.dataset.dragActive="false",document.removeEventListener("dragover",m)},"handleDragEnd"),S=i(_=>{_.preventDefault(),_.dataTransfer.dropEffect="move"},"handleDragOver");return u.jsxs("li",{role:"option",draggable:a?"true":void 0,onDrag:a?b:void 0,onDragStart:a?v:void 0,onDragEnd:a?w:void 0,onDragOver:a?S:void 0,"data-index":o,className:xe("flex justify-between items-center py-1","data-[drag-active=true]:bg-transparent data-[drag-active=true]:text-transparent data-[drag-active=true]:outline data-[drag-active=true]:outline-1 data-[drag-active=true]:outline-border"),children:[u.jsxs("label",{htmlFor:`switch_${o}`,className:"flex items-center gap-2 cursor-pointer",children:[u.jsx(l3,{id:`switch_${o}`,checked:t,onCheckedChange:r,name:`${o}`}),u.jsx("span",{className:"text-sm",children:u.jsx(ma,{label:n,source:s,resource:l})})]}),a&&u.jsx(v1e,{className:"cursor-move dragIcon w-4 h-4 text-muted-foreground"})]},s)},"FieldToggle"),M5e=i(({children:e})=>{const t=xt(),{storeKey:n,defaultHiddenColumns:r}=o1(),[a,s]=ka(`${n}_columnRanks`),[o,l]=ka(n,r),f=`${n}-columnsSelector`,[c,p]=y.useState(()=>typeof document<"u"?document.getElementById(f):null);y.useEffect(()=>{if(c&&typeof document<"u"&&document.body.contains(c))return;const _=setInterval(()=>{const C=document.getElementById(f);C&&p(C)},100),j=setTimeout(()=>clearInterval(_),500);return()=>{clearInterval(_),clearTimeout(j)}},[f,c]);const[m,v]=y.useState("");if(!c)return null;const b=y.Children.toArray(e),w=HP(a??[],b.length),S=b.length>5;return ol.createPortal(u.jsxs("ul",{className:"max-h-[50vh] p-1 overflow-auto",children:[S?u.jsx("li",{className:"pb-2",tabIndex:-1,children:u.jsxs("div",{className:"relative",children:[u.jsx(Er,{value:m,onChange:i(_=>{v(_.target.value)},"onChange"),placeholder:t("ra.action.search_columns",{_:"Search columns"}),className:"pr-8"}),u.jsx(r4,{className:"absolute right-2 top-2 h-4 w-4 text-muted-foreground"}),m&&u.jsx("button",{onClick:i(()=>v(""),"onClick"),className:"absolute right-8 top-2 h-4 w-4 text-muted-foreground","aria-label":"Clear",children:"×"})]})}):null,w.map((_,j)=>u.jsx(nQ.Provider,{value:_,children:u.jsx(rQ.Provider,{value:m,children:b[_]},j)},j)),u.jsx("li",{className:"text-center mt-2 px-3",children:u.jsx(Le,{variant:"outline",size:"sm",onClick:i(()=>{s(void 0),l(r)},"onClick"),children:"Reset"})})]}),c)},"ColumnsSelector"),I5e=i(({source:e,label:t})=>{const n=Wt(),{storeKey:r,defaultHiddenColumns:a}=o1(),[s,o]=ka(r,a),l=jye(),[f,c]=ka(`${r}_columnRanks`),p=Cye(),m=a1();if(!e&&!t)return null;const v=m({label:typeof t=="string"?t:void 0,resource:n,source:e}),b=s.includes(e),w=F5e(v,p),S=i((_,j)=>{const C=f?Math.max(Number(_),Number(j||0))>f.length-1?HP(f,Math.max(Number(_),Number(j||0))+1):f:HP([],Math.max(Number(_),Number(j||0))+1),k=C.findIndex(R=>R==Number(_)),E=C.findIndex(R=>R==Number(j));if(k===-1||E===-1)return;let T;k>E?T=[...C.slice(0,E),C[k],...C.slice(E,k),...C.slice(k+1)]:T=[...C.slice(0,k),...C.slice(k+1,E+1),C[k],...C.slice(E+1)],c(T)},"handleMove");return w?u.jsx(D5e,{source:e,label:v,index:String(l),selected:!b,onToggle:i(()=>o(b?s.filter(_=>_!==e):[...s,e]),"onToggle"),onMove:S},l):null},"ColumnsSelectorItem"),HP=i((e,t)=>e.concat(Array.from({length:t-e.length},(n,r)=>e.length+r)),"padRanks"),F5e=i((e,t)=>t?UH.clean(e).toLowerCase().includes(UH.clean(t).toLowerCase()):!0,"fieldLabelMatchesFilter"),L5e=i(({actions:e,children:t,className:n,disableBreadcrumb:r,title:a,...s})=>u.jsx(hy,{...s,children:u.jsx($5e,{actions:e,className:n,disableBreadcrumb:r,title:a,children:t})}),"Create"),$5e=i(({actions:e,disableBreadcrumb:t,title:n,children:r,className:a})=>{const s=qpe(),o=Wt();if(!o)throw new Error("The CreateView component must be used within a ResourceContextProvider");const f=Tc()(o,2),p=co()({resource:o,type:"list"}),m=FM();return u.jsxs(u.Fragment,{children:[!t&&u.jsxs(V1,{children:[m&&u.jsx(_v,{children:u.jsx(nn,{to:"/",children:u.jsx(nr,{i18nKey:"ra.page.dashboard",children:"Home"})})}),u.jsx(_v,{children:u.jsx(nn,{to:p,children:f})}),u.jsx($4,{children:u.jsx(nr,{i18nKey:"ra.action.create",children:"Create"})})]}),u.jsxs("div",{className:xe("flex justify-between items-start flex-wrap gap-2 my-2",a),children:[u.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:n!==void 0?n:s.defaultTitle}),e]}),u.jsx("div",{className:"my-2",children:r})]})},"CreateView");function q5e({className:e,...t}){return u.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:u.jsx("table",{"data-slot":"table",className:xe("w-full caption-bottom text-sm",e),...t})})}i(q5e,"Table");function U5e({className:e,...t}){return u.jsx("thead",{"data-slot":"table-header",className:xe("[&_tr]:border-b",e),...t})}i(U5e,"TableHeader");function z5e({className:e,...t}){return u.jsx("tbody",{"data-slot":"table-body",className:xe("[&_tr:last-child]:border-0",e),...t})}i(z5e,"TableBody");function Lne({className:e,...t}){return u.jsx("tr",{"data-slot":"table-row",className:xe("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",e),...t})}i(Lne,"TableRow");function $ne({className:e,...t}){return u.jsx("th",{"data-slot":"table-head",className:xe("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...t})}i($ne,"TableHead");function qne({className:e,...t}){return u.jsx("td",{"data-slot":"table-cell",className:xe("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...t})}i(qne,"TableCell");var p_="Checkbox",[B5e,lHe]=oa(p_),[H5e,u3]=B5e(p_);function V5e(e){const{__scopeCheckbox:t,checked:n,children:r,defaultChecked:a,disabled:s,form:o,name:l,onCheckedChange:f,required:c,value:p="on",internal_do_not_use_render:m}=e,[v,b]=Fi({prop:n,defaultProp:a??!1,onChange:f,caller:p_}),[w,S]=y.useState(null),[_,j]=y.useState(null),C=y.useRef(!1),k=w?!!o||!!w.closest("form"):!0,E={checked:v,disabled:s,setChecked:b,control:w,setControl:S,name:l,form:o,value:p,hasConsumerStoppedPropagationRef:C,required:c,defaultChecked:vc(a)?!1:a,isFormControl:k,bubbleInput:_,setBubbleInput:j};return u.jsx(H5e,{scope:t,...E,children:W5e(m)?m(E):r})}i(V5e,"CheckboxProvider");var Une="CheckboxTrigger",zne=y.forwardRef(({__scopeCheckbox:e,onKeyDown:t,onClick:n,...r},a)=>{const{control:s,value:o,disabled:l,checked:f,required:c,setControl:p,setChecked:m,hasConsumerStoppedPropagationRef:v,isFormControl:b,bubbleInput:w}=u3(Une,e),S=Xt(a,p),_=y.useRef(f);return y.useEffect(()=>{const j=s?.form;if(j){const C=i(()=>m(_.current),"reset");return j.addEventListener("reset",C),()=>j.removeEventListener("reset",C)}},[s,m]),u.jsx(mt.button,{type:"button",role:"checkbox","aria-checked":vc(f)?"mixed":f,"aria-required":c,"data-state":Kne(f),"data-disabled":l?"":void 0,disabled:l,value:o,...r,ref:S,onKeyDown:Je(t,j=>{j.key==="Enter"&&j.preventDefault()}),onClick:Je(n,j=>{m(C=>vc(C)?!0:!C),w&&b&&(v.current=j.isPropagationStopped(),v.current||j.stopPropagation())})})});zne.displayName=Une;var Bne=y.forwardRef((e,t)=>{const{__scopeCheckbox:n,name:r,checked:a,defaultChecked:s,required:o,disabled:l,value:f,onCheckedChange:c,form:p,...m}=e;return u.jsx(V5e,{__scopeCheckbox:n,checked:a,defaultChecked:s,disabled:l,required:o,onCheckedChange:c,name:r,form:p,value:f,internal_do_not_use_render:i(({isFormControl:v})=>u.jsxs(u.Fragment,{children:[u.jsx(zne,{...m,ref:t,__scopeCheckbox:n}),v&&u.jsx(Gne,{__scopeCheckbox:n})]}),"internal_do_not_use_render")})});Bne.displayName=p_;var Hne="CheckboxIndicator",Vne=y.forwardRef((e,t)=>{const{__scopeCheckbox:n,forceMount:r,...a}=e,s=u3(Hne,n);return u.jsx(ba,{present:r||vc(s.checked)||s.checked===!0,children:u.jsx(mt.span,{"data-state":Kne(s.checked),"data-disabled":s.disabled?"":void 0,...a,ref:t,style:{pointerEvents:"none",...e.style}})})});Vne.displayName=Hne;var Wne="CheckboxBubbleInput",Gne=y.forwardRef(({__scopeCheckbox:e,...t},n)=>{const{control:r,hasConsumerStoppedPropagationRef:a,checked:s,defaultChecked:o,required:l,disabled:f,name:c,value:p,form:m,bubbleInput:v,setBubbleInput:b}=u3(Wne,e),w=Xt(n,b),S=W1(s),_=O1(r);y.useEffect(()=>{const C=v;if(!C)return;const k=window.HTMLInputElement.prototype,T=Object.getOwnPropertyDescriptor(k,"checked").set,R=!a.current;if(S!==s&&T){const A=new Event("click",{bubbles:R});C.indeterminate=vc(s),T.call(C,vc(s)?!1:s),C.dispatchEvent(A)}},[v,S,s,a]);const j=y.useRef(vc(s)?!1:s);return u.jsx(mt.input,{type:"checkbox","aria-hidden":!0,defaultChecked:o??j.current,required:l,disabled:f,name:c,value:p,form:m,...t,tabIndex:-1,ref:w,style:{...t.style,..._,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Gne.displayName=Wne;function W5e(e){return typeof e=="function"}i(W5e,"isFunction");function vc(e){return e==="indeterminate"}i(vc,"isIndeterminate");function Kne(e){return vc(e)?"indeterminate":e?"checked":"unchecked"}i(Kne,"getState");function Qp({className:e,...t}){return u.jsx(Bne,{"data-slot":"checkbox",className:xe("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:u.jsx(Vne,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:u.jsx(ss,{className:"size-3.5"})})})}i(Qp,"Checkbox");const G5e=i(({defaultValue:e,source:t,record:n,empty:r,transform:a=K5e,locales:s,options:o,...l})=>{let f=pi({defaultValue:e,source:t,record:n});const c=xt();return f==null?r?u.jsx("span",{...l,children:typeof r=="string"?c(r,{_:r}):r}):null:(a&&(f=a(f)),u.jsx("span",{...l,children:Y5e&&typeof f=="number"?f.toLocaleString(s,o):f}))},"NumberField"),K5e=i(e=>e&&typeof e=="string"&&!isNaN(e)?+e:e,"defaultTransform"),Y5e=!!(typeof Intl=="object"&&Intl&&typeof Intl.NumberFormat=="function"),zH=u.jsx(Ine,{});function sa(e){const{children:t,className:n,rowClassName:r,bulkActionButtons:a=zH,bulkActionsToolbar:s,...o}=e,l=!!s||a!==!1,f=Wt(e),c=e.storeKey||`${f}.datatable`,[p]=ka(`${c}_columnRanks`),m=p?t6e(t,p):t;return u.jsxs(_ye,{hasBulkActions:l,loading:null,empty:u.jsx(e6e,{}),...o,children:[u.jsx("div",{className:xe("rounded-md border",n),children:u.jsxs(q5e,{children:[u.jsx(bN.Provider,{value:"header",children:u.jsx(Q5e,{children:m})}),u.jsx(X5e,{rowClassName:r,children:m})]})}),s??(a!==!1&&u.jsx(Fne,{children:y.isValidElement(a)?a:zH})),u.jsx(bN.Provider,{value:"columnsSelector",children:u.jsx(M5e,{children:t})})]})}i(sa,"DataTable");sa.Col=Yne;sa.NumberCol=i6e;const Q5e=i(({children:e})=>{const t=XY(),{hasBulkActions:n=!1}=YY(),{onSelect:r}=LM(),a=JY(),s=i(l=>{!r||!t||!a||r(l?a.concat(t.filter(f=>!a.includes(f.id)).map(f=>f.id)):[])},"handleToggleSelectAll"),o=Array.isArray(t)?t.map(l=>l.id):[];return u.jsx(U5e,{children:u.jsxs(Lne,{children:[n?u.jsx($ne,{className:"w-8",children:u.jsx(Qp,{onCheckedChange:s,checked:a&&a.length>0&&o.length>0&&o.every(l=>a.includes(l)),className:"mb-2"})}):null,e]})})},"DataTableHead"),X5e=i(({children:e,rowClassName:t})=>{const n=XY();return u.jsx(z5e,{children:n?.map((r,a)=>u.jsx(Ya,{value:r,children:u.jsx(Z5e,{className:t?.(r),children:e})},r.id??`row${a}`))})},"DataTableBody"),Z5e=i(({children:e,className:t})=>{const{rowClick:n,handleToggleItem:r}=LM(),a=JY(),{hasBulkActions:s=!1}=YY(),o=Ft();if(!o)throw new Error("DataTableRow can only be used within a RecordContext");const l=Wt();if(!l)throw new Error("DataTableRow can only be used within a ResourceContext");const f=Ra(),c=OK(),p=y.useCallback(v=>{v.stopPropagation(),r&&r(o.id,v)},[r,o.id]),m=y.useCallback(async()=>{const v=typeof n=="function"?n(o.id,l,o):n,b=J5e(v)?await v:v,w=await c({record:o,resource:l,link:b});w===!1||w==null||f(w,{state:{_scrollToTop:!0}})},[o,l,n,f,c]);return u.jsxs(Lne,{onClick:m,className:xe(n!==!1&&"cursor-pointer",t),children:[s?u.jsx(qne,{className:"flex w-8",onClick:p,children:u.jsx(Qp,{checked:a?.includes(o.id),onClick:p})}):null,e]},o.id)},"DataTableRow"),J5e=i(e=>e&&typeof e.then=="function","isPromise"),e6e=i(()=>u.jsx(Ga,{children:u.jsx(di,{children:"No results found."})}),"DataTableEmpty");function Yne(e){switch(Eye()){case"columnsSelector":return u.jsx(I5e,{...e});case"header":return u.jsx(n6e,{...e});case"data":return u.jsx(a6e,{...e})}}i(Yne,"DataTableColumn");const t6e=i((e,t)=>y.Children.toArray(e).reduce((n,r,a)=>{const s=t.indexOf(a);return s===-1?n[a]=r:n[s]=r,n},[]),"reorderChildren");function n6e(e){const{disableSort:t,source:n,label:r,sortByOrder:a,className:s,headerClassName:o}=e,l=wye(),{handleSort:f}=LM(),c=Wt(),p=xt(),m=a1(),{storeKey:v,defaultHiddenColumns:b}=o1(),[w]=ka(v,b);if(w.includes(n))return null;const _=l&&l.field===n?r6e[l.order]:a??"ASC",j=m({label:typeof r=="string"?r:void 0,resource:c,source:n}),C=p("ra.sort.sort_by",{field:j,field_lower_first:typeof j=="string"?j.charAt(0).toLowerCase()+j.slice(1):void 0,order:p(`ra.sort.${_}`),_:p("ra.action.sort")});return u.jsx($ne,{className:xe(s,o),children:f&&l&&!t&&n?u.jsx(Li,{children:u.jsxs(ds,{children:[u.jsx(fs,{asChild:!0,children:u.jsxs(Le,{variant:"ghost",size:"sm",className:"-ml-3 -mr-3 h-8 data-[state=open]:bg-accent cursor-pointer","data-field":n,onClick:f,children:[o?.includes("text-right")?null:u.jsx(ma,{label:r,source:n,resource:c}),l.field===n?l.order==="ASC"?u.jsx(swe,{className:"ml-2 h-6 w-6"}):u.jsx(dwe,{className:"ml-2 h-6 w-6"}):null,o?.includes("text-right")?u.jsx(ma,{label:r,source:n,resource:c}):null]})}),u.jsx(hs,{children:u.jsx("p",{children:C})})]})}):u.jsx(ma,{label:r,source:n,resource:c})})}i(n6e,"DataTableHeadCell");const r6e={ASC:"DESC",DESC:"ASC"};function a6e(e){const{children:t,render:n,field:r,source:a,className:s,cellClassName:o,conditionalClassName:l}=e,{storeKey:f,defaultHiddenColumns:c}=o1(),[p]=ka(f,c),m=Ft();if(p.includes(a))return null;if(!n&&!r&&!t&&!a)throw new Error("DataTableColumn: Missing at least one of the following props: render, field, children, or source");return u.jsx(qne,{className:xe("py-1",s,o,m&&l?.(m)),children:t??(n?m&&n(m):r?y.createElement(r,{source:a}):Qt(m,a))})}i(a6e,"DataTableCell");function i6e(e){const{source:t,options:n,locales:r,className:a,headerClassName:s,cellClassName:o,...l}=e;return u.jsx(Yne,{source:t,...l,className:a,headerClassName:xe("text-right",s),cellClassName:xe("text-right",o),children:u.jsx(G5e,{source:t,options:n,locales:r})})}i(i6e,"DataTableNumberColumn");const d3=i(e=>{const{className:t,inputClassName:n,defaultValue:r,format:a=o6e,label:s,source:o,helperText:l,onChange:f,onFocus:c,validate:p,disabled:m,readOnly:v,...b}=e,w=Wt(e),{field:S,id:_,isRequired:j}=Pc({defaultValue:r,source:o,validate:p,disabled:m,readOnly:v,format:a,...b}),C=y.useRef(null),k=y.useRef(S.value),[E,T]=y.useState(1),R=y.useRef(!1);y.useEffect(()=>{if(R.current){R.current=!1;return}C.current?.value!==S.value&&!(C.current?.value===""&&S.value==null)&&(k.current=S.value,T($=>$+1),R.current=!1)},[T,S.value]);const{onBlur:A}=S,N=y.useRef(!1),D=Ct(z=>{if(f&&f(z),typeof z.target>"u"||typeof z.target.value>"u")return;const $=z.target,H=$.value,U=H===""||$.valueAsDate!=null&&!isNaN(new Date($.valueAsDate).getTime());H!==""&&H!=null&&U&&(S.onChange(H),R.current=!0)}),M=Ct(z=>{c&&c(z),N.current=!0}),I=Ct(()=>{if(N.current=!1,!C.current)return;const z=C.current.value;(z===""||C.current.valueAsDate!=null&&!isNaN(new Date(C.current.valueAsDate).getTime()))&&S.value!==z&&S.onChange(z??""),A&&A()}),{ref:F,name:L}=S,q=y.useCallback(z=>{typeof F=="function"?F(z):F&&z&&(F.current=z),C.current=z},[F]);return u.jsxs(eo,{id:_,className:t,name:L,children:[s!==!1&&u.jsx(al,{children:u.jsx(ma,{label:s,source:o,resource:w,isRequired:j})}),u.jsx(Iy,{children:u.jsx(Er,{ref:q,defaultValue:a(k.current)??"",type:"date",onChange:D,onFocus:M,onBlur:I,className:xe("ra-input",`ra-input-${o}`,"[color-scheme:light] dark:[color-scheme:dark] relative [&::-webkit-calendar-picker-indicator]:cursor-pointer [&::-webkit-calendar-picker-indicator]:absolute [&::-webkit-calendar-picker-indicator]:right-3 [&::-webkit-calendar-picker-indicator]:opacity-100",n),disabled:m||v,readOnly:v,...b},E)}),u.jsx(to,{helperText:l}),u.jsx(ul,{})]})},"DateInput"),BH=i(e=>{if(!(e instanceof Date)||isNaN(e.getDate()))return"";const t=new Date(e.getTime()),n="00",r=t.getFullYear().toString(),a=(t.getMonth()+1).toString(),s=t.getDate().toString();return`${r}-${(n+a).slice(-2)}-${(n+s).slice(-2)}`},"convertDateToString"),s6e=/^\d{4}-\d{2}-\d{2}$/,o6e=i(e=>e==null||e===""?null:e instanceof Date?BH(e):typeof e=="string"&&s6e.test(e)?e:BH(new Date(e)),"defaultFormat"),Qne=i(e=>{const{className:t,empty:n,defaultValue:r,source:a,record:s,...o}=e,l=pi({defaultValue:r,source:a,record:s}),f=xt();return l==null?n?u.jsx("span",{className:t,...o,children:typeof n=="string"?f(n,{_:n}):n}):null:u.jsx("a",{className:xe("underline hover:no-underline",t),href:`mailto:${l}`,onClick:c6e,...o,children:l})},"EmailFieldImpl");Qne.displayName="EmailFieldImpl";const l6e=u_(Qne),c6e=i(e=>e.stopPropagation(),"stopPropagation");sa.Col;const u6e=i(e=>{const{children:t,className:n,empty:r,field:a,label:s,render:o,resource:l,source:f,record:c,variant:p,...m}=e,v=Wt(e),b=Ft({recordProp:c}),w=xt();return!f&&!s&&!o?null:u.jsxs("div",{className:xe(n,"flex",p==="inline"?"flex-row":"flex-col"),...m,children:[s!==""&&s!==!1?u.jsx("div",{className:xe(p==="inline"?"block min-w-50":"text-xs","text-muted-foreground"),children:u.jsx(ma,{label:s,source:f,resource:v,isRequired:!1})}):null,t?u.jsx("span",{className:"flex-1",children:t}):o?b&&u.jsx("span",{className:"flex-1",children:o(b)||(typeof r=="string"?w(r,{_:r}):r)}):a?y.createElement(a,{source:f,empty:r,className:"flex-1"}):f?u.jsx(Ir,{source:f,empty:r,className:"flex-1"}):null]})},"RecordField"),d6e=i(()=>{const e=Ft();return e?u.jsxs("div",{className:"flex flex-row gap-4 items-center justify-start",children:[u.jsx(ho,{height:40,width:40,record:e}),u.jsxs("div",{className:"flex flex-col items-start gap-1",children:[u.jsxs("span",{children:[e.first_name," ",e.last_name]}),u.jsxs("span",{className:"text-xs text-muted-foreground",children:[e.title,e.title&&e.company_name&&" at ",e.company_name]})]})]}):null},"ContactOptionRender"),tw=u.jsx(d6e,{}),Xne=i(({selectContact:e,display:t="chip"})=>{const{identity:n}=Yn(),r=wn(),[a]=yd(),s=Ht(),{taskTypes:o}=la(),l=Ft(),[f,c]=y.useState(!1),p=i(()=>{c(!0)},"handleOpen"),m=i(async v=>{c(!1);const b=await r.getOne("contacts",{id:v.contact_id});b.data&&(await a("contacts",{id:b.data.id,data:{last_seen:new Date().toISOString()},previousData:b.data}),s("Task added"))},"handleSuccess");return n?u.jsxs(u.Fragment,{children:[t==="icon"?u.jsx(Li,{children:u.jsxs(ds,{children:[u.jsx(fs,{asChild:!0,children:u.jsx(Le,{size:"sm",variant:"ghost",className:"p-2 cursor-pointer",onClick:p,children:u.jsx(os,{className:"w-4 h-4"})})}),u.jsx(hs,{children:"Create task"})]})}):u.jsx("div",{className:"my-2",children:u.jsxs(Le,{variant:"outline",className:"h-6 cursor-pointer",onClick:p,size:"sm",children:[u.jsx(os,{className:"w-4 h-4"}),"Add task"]})}),u.jsx(hy,{resource:"tasks",record:{type:"None",contact_id:l?.id,due_date:new Date().toISOString().slice(0,10),sales_id:n.id},transform:i(v=>{const b=new Date(v.due_date);return b.setHours(0,0,0,0),v.due_date=b.toISOString(),{...v,due_date:new Date(v.due_date).toISOString()}},"transform"),mutationOptions:{onSuccess:m},children:u.jsx(ga,{open:f,onOpenChange:i(()=>c(!1),"onOpenChange"),children:u.jsx(va,{className:"lg:max-w-xl overflow-y-auto max-h-9/10 top-1/20 translate-y-0",children:u.jsxs(zr,{className:"flex flex-col gap-4",children:[u.jsx(Fr,{children:u.jsxs(Lr,{children:[e?"Create a new task":"Create a new task for ",!e&&u.jsx(eY,{record:l,resource:"contacts"})]})}),u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx(Ut,{autoFocus:!0,source:"text",label:"Description",validate:Pn(),multiline:!0,className:"m-0",helperText:!1}),e&&u.jsx(ro,{source:"contact_id",reference:"contacts_summary",children:u.jsx(Od,{label:"Contact",optionText:tw,helperText:!1,validate:Pn()})}),u.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[u.jsx(d3,{source:"due_date",helperText:!1,validate:Pn()}),u.jsx(or,{source:"type",validate:Pn(),choices:o.map(v=>({id:v,name:v})),helperText:!1})]})]}),u.jsx(ps,{className:"w-full justify-end",children:u.jsx(jd,{})})]})})})})]}):null},"AddTask"),Zne=i(({open:e,close:t,taskId:n})=>{const{taskTypes:r,taskPriorities:a,taskStatuses:s}=la(),o=Ht();return u.jsx(ga,{open:e,onOpenChange:t,children:n&&u.jsx(wM,{id:n,resource:"tasks",className:"mt-0",mutationOptions:{onSuccess:i(()=>{t(),o("Task updated",{type:"info",undoable:!0})},"onSuccess")},redirect:!1,children:u.jsx(va,{className:"lg:max-w-xl overflow-y-auto max-h-9/10 top-1/20 translate-y-0",children:u.jsxs(zr,{className:"flex flex-col gap-4",children:[u.jsx(Fr,{children:u.jsx(Lr,{children:"Edit task"})}),u.jsx(Ut,{autoFocus:!0,source:"text",label:"Description",validate:Pn(),multiline:!0,helperText:!1}),u.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[u.jsx(d3,{source:"due_date",helperText:!1,validate:Pn()}),u.jsx(or,{source:"type",choices:r.map(l=>({id:l,name:l})),helperText:!1,validate:Pn()}),u.jsx(or,{source:"priority",choices:a,helperText:!1}),u.jsx(or,{source:"status",choices:s,helperText:!1}),u.jsx(ro,{source:"assigned_to",reference:"sales",children:u.jsx(or,{optionText:i(l=>`${l.first_name} ${l.last_name}`,"optionText"),label:"Assigned To"})})]}),u.jsxs(ps,{className:"w-full sm:justify-between gap-4",children:[u.jsx(c_,{mutationOptions:{onSuccess:i(()=>{t(),o("Task deleted",{type:"info",undoable:!0})},"onSuccess")},redirect:!1}),u.jsx(jd,{label:"Save"})]})]})})})})},"TaskEdit"),f6e=i(({task:e,showContact:t})=>{const n=Ht(),r=Dn(),[a,s]=y.useState(!1),o=i(()=>{s(!1)},"handleCloseEdit"),[l,{isPending:f,isSuccess:c,variables:p}]=yd(),{handleDelete:m}=HK({record:e,redirect:!1,mutationOptions:{onSuccess(){n("Task deleted successfully",{undoable:!0})}}}),v=i(()=>{s(!0)},"handleEdit"),b=i(()=>()=>{l("tasks",{id:e.id,data:{done_date:e.done_date?null:new Date().toISOString()},previousData:e})},"handleCheck");y.useEffect(()=>{f||!c||p?.data?.done_date!=null||r.invalidateQueries({queryKey:["tasks","getList"]})},[r,f,c,p]);const w=`checkbox-list-label-${e.id}`;return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex items-start justify-between",children:[u.jsxs("div",{className:"flex items-start gap-2 flex-1",children:[u.jsx(Qp,{id:w,checked:!!e.done_date,onCheckedChange:b(),disabled:f,className:"mt-1"}),u.jsxs("div",{className:`flex-grow ${e.done_date?"line-through":""}`,children:[u.jsx(nn,{to:`/tasks/${e.id}/show`,className:"block hover:text-primary transition-colors",title:e.text,children:u.jsxs("div",{className:"text-sm line-clamp-2",children:[e.type&&e.type!=="None"&&u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"font-semibold text-sm",children:e.type})," "]}),e.text]})}),u.jsxs("div",{className:"text-sm text-muted-foreground",children:["due ",u.jsx(cd,{source:"due_date",record:e}),t&&u.jsx(xn,{source:"contact_id",reference:"contacts",record:e,link:"show",className:"inline text-sm text-muted-foreground",render:i(({referenceRecord:S})=>S?u.jsxs(u.Fragment,{children:[" ","(Re: ",S?.first_name," ",S?.last_name,")"]}):null,"render")})]})]})]}),u.jsxs(Fc,{children:[u.jsx(rl,{asChild:!0,children:u.jsx(Le,{variant:"ghost",size:"icon",className:"h-5 pr-0! size-8 cursor-pointer","aria-label":"task actions",children:u.jsx(r1e,{className:"h-4 w-4"})})}),u.jsxs(Lc,{align:"end",children:[u.jsx(sr,{asChild:!0,children:u.jsx(nn,{to:`/tasks/${e.id}/show`,className:"cursor-pointer",children:"Show Details"})}),u.jsx(sr,{className:"cursor-pointer",onClick:i(()=>{l("tasks",{id:e.id,data:{due_date:new Date(Date.now()+1440*60*1e3).toISOString().slice(0,10)},previousData:e})},"onClick"),children:"Postpone to tomorrow"}),u.jsx(sr,{className:"cursor-pointer",onClick:i(()=>{l("tasks",{id:e.id,data:{due_date:new Date(Date.now()+10080*60*1e3).toISOString().slice(0,10)},previousData:e})},"onClick"),children:"Postpone to next week"}),u.jsx(sr,{className:"cursor-pointer",onClick:v,children:"Edit"}),u.jsx(sr,{className:"cursor-pointer",onClick:m,children:"Delete"})]})]})]}),a&&u.jsx(Zne,{taskId:e.id,open:a,close:o})]})},"Task"),Jne=i(({showContact:e,className:t})=>{const{data:n,error:r,isPending:a}=Xn();if(a||r||n.length===0)return null;const s=n.filter(o=>!o.done_date||wbe(new Date(o.done_date),new Date(Date.now()-300*1e3)));return u.jsx("div",{className:`space-y-2 ${t||""}`,children:s.map(o=>u.jsx(f6e,{task:o,showContact:e},o.id))})},"TasksIterator"),kb=["#eddcd2","#fff1e6","#fde2e4","#fad2e1","#c5dedd","#dbe7e4","#f0efeb","#d6e2e9","#bcd4e6","#99c1de"],h6e=i(({color:e,handleClick:t,selected:n})=>u.jsx("button",{type:"button",className:`w-8 h-8 rounded-full inline-block m-1 transition-all ${n?"ring-2 ring-gray-500 ring-offset-1":""}`,style:{backgroundColor:e},onClick:t}),"RoundButton");function ere({open:e,tag:t,title:n,onClose:r,onSubmit:a}){const[s,o]=y.useState(""),[l,f]=y.useState(kb[0]),[c,p]=y.useState(!1),m=i(w=>{o(w.target.value)},"handleNewTagNameChange"),v=i(()=>{p(!1),r()},"handleClose"),b=i(async w=>{w.preventDefault(),await a({name:s,color:l}),p(!0),o(""),f(kb[0]),v()},"handleSubmit");return y.useEffect(()=>{o(t?.name??""),f(t?.color??kb[0])},[t]),u.jsx(ga,{open:e,onOpenChange:v,children:u.jsx(va,{className:"sm:max-w-lg",children:u.jsxs("form",{onSubmit:b,children:[u.jsx(Fr,{children:u.jsx(Lr,{children:n})}),u.jsxs("div",{className:"space-y-4 py-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"tag-name",children:"Tag name"}),u.jsx(Er,{id:"tag-name",autoFocus:!0,value:s,onChange:m,placeholder:"Enter tag name"})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{children:"Color"}),u.jsx("div",{className:"flex flex-wrap",children:kb.map(w=>u.jsx(h6e,{color:w,selected:w===l,handleClick:i(()=>{f(w)},"handleClick")},w))})]})]}),u.jsx("div",{className:"flex justify-end pt-4",children:u.jsxs(Le,{variant:"outline",disabled:c,className:xe(Mc({variant:"outline"}),"text-primary",c?"opacity-50 cursor-not-allowed":"cursor-pointer"),children:[u.jsx(v1,{}),"Save"]})})]})})})}i(ere,"TagDialog");function p6e({tag:e,open:t,onClose:n,onSuccess:r}){const[a]=yd(),s=i(async o=>{await a("tags",{id:e.id,data:o,previousData:e},{onSuccess:i(async l=>{await r?.(l)},"onSuccess")})},"handleEditTag");return u.jsx(ere,{open:t,title:"Edit tag",onClose:n,onSubmit:s,tag:e})}i(p6e,"TagEditModal");function m6e({tag:e,onUnlink:t}){const[n,r]=y.useState(!1),a=i(()=>{r(!1)},"handleClose"),s=i(()=>{r(!0)},"handleClick");return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"text-black inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:e.color},onClick:s,children:[e.name,u.jsx("button",{onClick:i(o=>{o.stopPropagation(),t()},"onClick"),className:"transition-colors p-0 ml-1 cursor-pointer",children:u.jsx($p,{className:"w-3 h-3"})})]}),u.jsx(p6e,{tag:e,open:n,onClose:a})]})}i(m6e,"TagChip");function g6e({open:e,onClose:t,onSuccess:n}){const[r]=IM(),a=i(async s=>{await r("tags",{data:s},{onSuccess:i(async o=>{await n?.(o)},"onSuccess")})},"handleCreateTag");return u.jsx(ere,{open:e,title:"Create a new tag",onClose:t,onSubmit:a})}i(g6e,"TagCreateModal");const v6e=i(()=>{const e=Ft(),[t,n]=y.useState(!1),{data:r,isPending:a}=pa("tags",{pagination:{page:1,perPage:10},sort:{field:"name",order:"ASC"}}),{data:s,isPending:o}=Zhe("tags",{ids:e?.tags},{enabled:e&&e.tags&&e.tags.length>0}),[l]=yd(),f=r&&e&&r.filter(w=>!(e.tags??[]).includes(w.id)),c=i(w=>{if(!e)throw new Error("No contact record found");const S=[...e.tags??[],w];l("contacts",{id:e.id,data:{tags:S},previousData:e})},"handleTagAdd"),p=i(async w=>{if(!e)throw new Error("No contact record found");const S=(e.tags??[]).filter(_=>_!==w);await l("contacts",{id:e.id,data:{tags:S},previousData:e})},"handleTagDelete"),m=i(()=>{n(!0)},"openTagCreateDialog"),v=i(()=>{n(!1)},"handleTagCreateClose"),b=y.useCallback(async w=>{if(!e)throw new Error("No contact record found");await l("contacts",{id:e.id,data:{tags:[...e.tags??[],w.id]},previousData:e},{onSuccess:i(()=>{n(!1)},"onSuccess")})},[l,e]);return o||a?null:u.jsxs("div",{className:"flex flex-wrap gap-2",children:[s?.map(w=>u.jsx("div",{children:u.jsx(m6e,{tag:w,onUnlink:i(()=>p(w.id),"onUnlink")})},w.id)),u.jsx("div",{children:u.jsxs(Fc,{children:[u.jsx(rl,{asChild:!0,children:u.jsxs(Le,{variant:"outline",size:"sm",className:"h-6 cursor-pointer",children:[u.jsx(os,{className:"h-3 w-3 mr-1"}),"Add tag"]})}),u.jsxs(Lc,{children:[f?.map(w=>u.jsx(sr,{onClick:i(()=>c(w.id),"onClick"),children:u.jsx(Kn,{variant:"secondary",className:"text-xs font-normal text-black",style:{backgroundColor:w.color},children:w.name})},w.id)),u.jsx(sr,{onClick:m,children:u.jsxs(Le,{variant:"ghost",size:"sm",className:"w-full justify-start p-0 cursor-pointer",children:[u.jsx(QQ,{className:"h-3 w-3 mr-2"}),"Create new tag"]})})]})]})}),u.jsx(g6e,{open:t,onClose:v,onSuccess:b})]})},"TagsListEdit"),y6e=i(()=>{const[e,t]=y.useState(!1);return u.jsxs(u.Fragment,{children:[u.jsxs(Le,{variant:"outline",className:"h-6 cursor-pointer",size:"sm",onClick:i(()=>t(!0),"onClick"),children:[u.jsx(g1,{className:"w-4 h-4"}),"Merge with another contact"]}),u.jsx(b6e,{open:e,onClose:i(()=>t(!1),"onClose")})]})},"ContactMergeButton"),b6e=i(({open:e,onClose:t})=>{const n=Ft(),r=Ht(),a=zi(),s=wn(),[o,l]=y.useState(null),[f,c]=y.useState(null),[p,m]=y.useState(!1),{mutateAsync:v}=qr({mutationKey:["contacts","merge",{loserId:n?.id,winnerId:o}],mutationFn:i(async()=>s.mergeContacts(n?.id,o),"mutationFn")}),{data:b}=pa("contacts",{filter:{first_name:n?.first_name,last_name:n?.last_name,"id@neq":`${n?.id}`},pagination:{page:1,perPage:10}},{enabled:e&&!!n}),w=e&&!!n&&!!o,{total:S}=nv("tasks",{target:"contact_id",id:n?.id,pagination:{page:1,perPage:1}},{enabled:w}),{total:_}=nv("contactNotes",{target:"contact_id",id:n?.id,pagination:{page:1,perPage:1}},{enabled:w}),{total:j}=pa("deals",{filter:{"contact_ids@cs":`{${n?.id}}`},pagination:{page:1,perPage:1}},{enabled:w});y.useEffect(()=>{if(b&&b.length>0){const k=b[0].id;c(k),l(k)}},[b]);const C=i(async()=>{if(!o||!n){r("Please select a contact to merge with",{type:"warning"});return}try{m(!0),await v(),m(!1),r("Contacts merged successfully",{type:"success"}),a(`/contacts/${o}/show`),t()}catch(k){m(!1),r("Failed to merge contacts",{type:"error"}),console.error("Merge failed:",k)}},"handleMerge");return n?u.jsx(ga,{open:e,onOpenChange:t,children:u.jsxs(va,{className:"md:min-w-lg max-w-2xl",children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Merge Contact"}),u.jsx(ui,{children:"Merge this contact with another one."})]}),u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"p-4 bg-primary/5 rounded-lg border border-primary/20",children:[u.jsx("p",{className:"font-medium text-sm",children:"Current Contact (will be deleted)"}),u.jsx("div",{className:"font-medium text-sm mt-4",children:tw}),u.jsx("div",{className:"flex justify-center my-4",children:u.jsx(WQ,{className:"h-5 w-5 text-muted-foreground"})}),u.jsx("p",{className:"font-medium text-sm mb-2",children:"Target Contact (will be kept)"}),u.jsx(zr,{children:u.jsx(ro,{source:"winner_id",reference:"contacts",filter:{"id@neq":n.id},children:u.jsx(Od,{label:"",optionText:tw,validate:Pn(),onChange:l,defaultValue:f,helperText:!1})})})]}),o&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("p",{className:"font-medium text-sm",children:"What will be merged:"}),u.jsxs("ul",{className:"text-sm text-muted-foreground space-y-1 ml-4",children:[_!=null&&_>0&&u.jsxs("li",{children:["• ",_," note",_!==1?"s":""," will be reassigned"]}),S!=null&&S>0&&u.jsxs("li",{children:["• ",S," task",S!==1?"s":""," will be reassigned"]}),j!=null&&j>0&&u.jsxs("li",{children:["• ",j," deal",j!==1?"s":""," will be updated"]}),n.email_jsonb?.length>0&&u.jsxs("li",{children:["• ",n.email_jsonb.length," email address",n.email_jsonb.length!==1?"es":""," will be added"]}),n.phone_jsonb?.length>0&&u.jsxs("li",{children:["• ",n.phone_jsonb.length," phone number",n.phone_jsonb.length!==1?"s":""," will be added"]}),!_&&!S&&!j&&!n.email_jsonb?.length&&!n.phone_jsonb?.length&&u.jsx("li",{className:"text-muted-foreground/60",children:"No additional data to merge"})]})]}),u.jsxs(Ga,{variant:"destructive",children:[u.jsx(XQ,{className:"h-4 w-4"}),u.jsx(n3,{children:"Warning: Destructive Operation"}),u.jsx(di,{children:"All data will be transferred to the second contact. This action cannot be undone."})]})]})]}),u.jsxs(ps,{children:[u.jsxs(Le,{variant:"ghost",onClick:t,disabled:p,children:[u.jsx(uo,{}),"Cancel"]}),u.jsxs(Le,{onClick:C,disabled:!o||p,children:[u.jsx(g1,{}),p?"Merging...":"Merge Contacts"]})]})]})}):null},"ContactMergeDialog");function x6e(e){if(e.length<=75)return e;const n=[];let r=e.substring(0,75),a=e.substring(75);for(n.push(r);a.length>0;)r=" "+a.substring(0,74),a=a.substring(74),n.push(r);return n.join(`\r
112
112
  `)}i(x6e,"foldLine");function w6e(e,t,n){const r=[];if(r.push("BEGIN:VCARD"),r.push("VERSION:3.0"),r.push(`N:${e.last_name};${e.first_name};;;`),r.push(`FN:${e.first_name} ${e.last_name}`),e.title&&r.push(`TITLE:${e.title}`),t?.name&&r.push(`ORG:${t.name}`),e.email_jsonb&&e.email_jsonb.length>0&&e.email_jsonb.forEach(a=>{const s=a.type.toUpperCase();r.push(`EMAIL;TYPE=${s}:${a.email}`)}),e.phone_jsonb&&e.phone_jsonb.length>0&&e.phone_jsonb.forEach(a=>{const s=a.type.toUpperCase();r.push(`TEL;TYPE=${s}:${a.number}`)}),e.linkedin_url&&r.push(`URL:${e.linkedin_url}`),e.background){const a=e.background.replace(/\\/g,"\\\\").replace(/\n/g,"\\n").replace(/,/g,"\\,").replace(/;/g,"\\;");r.push(`NOTE:${a}`)}if(n){const s=`PHOTO;ENCODING=b;TYPE=${n.mimeType.split("/")[1]?.toUpperCase()||"PNG"}:${n.base64}`;r.push(x6e(s))}return r.push("END:VCARD"),r.join(`\r
113
113
  `)}i(w6e,"exportToVCard");const _6e=i(()=>{const e=Ft(),{data:t}=Hw("companies",{id:e?.company_id},{enabled:!!e?.company_id}),n=i(async()=>{if(!e)return;let r;if(e.avatar?.src)try{const c=await(await fetch(e.avatar.src)).blob(),p=c.type||"image/png";r={base64:await new Promise((v,b)=>{const w=new FileReader;w.onloadend=()=>{const _=w.result.split(",")[1];v(_)},w.onerror=b,w.readAsDataURL(c)}),mimeType:p}}catch(f){console.error("Failed to fetch avatar image:",f)}const a=w6e(e,t,r),s=new Blob([a],{type:"text/vcard;charset=utf-8"}),o=URL.createObjectURL(s),l=document.createElement("a");l.href=o,l.download=`${e.first_name}_${e.last_name}.vcf`,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(o)},"handleExport");return e?u.jsxs(Le,{variant:"outline",size:"sm",onClick:n,className:"h-6 cursor-pointer",children:[u.jsx(QM,{className:"w-4 h-4"}),"Export to vCard"]}):null},"ExportVCardButton"),S6e=i(({status:e})=>{let t="outline",n="";switch(e){case"strong":t="default";break;case"active":t="secondary",n="bg-green-100 text-green-800 hover:bg-green-100";break;case"cooling":t="secondary",n="bg-yellow-100 text-yellow-800 hover:bg-yellow-100";break;case"cold":t="secondary",n="bg-orange-100 text-orange-800 hover:bg-orange-100";break;case"dormant":t="secondary";break}return u.jsx(Kn,{variant:t,className:n,children:e.charAt(0).toUpperCase()+e.slice(1)})},"InternalStatusBadge"),j6e=i(({status:e})=>{let t="outline",n="";switch(e){case"valid":t="secondary",n="bg-green-100 text-green-800 hover:bg-green-100";break;case"risky":t="secondary",n="bg-yellow-100 text-yellow-800 hover:bg-yellow-100";break;case"invalid":t="destructive";break}return u.jsx(Kn,{variant:t,className:n,children:e.charAt(0).toUpperCase()+e.slice(1)})},"EmailStatusBadge"),C6e=i(({status:e})=>{let t="outline",n="";switch(e){case"active":t="default",n="bg-[#0077b5] hover:bg-[#0077b5]";break;case"inactive":t="secondary";break;case"not_found":t="destructive";break}return u.jsx(Kn,{variant:t,className:n,children:e.split("_").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")})},"LinkedInStatusBadge"),E6e=i(()=>{const e=Ft();if(!e)return null;const t=e.days_since_last_activity??(e.last_seen?Math.floor((new Date().getTime()-new Date(e.last_seen).getTime())/(1e3*60*60*24)):void 0),n=e.internal_heartbeat_score!=null||e.internal_heartbeat_status!=null||t!=null,r=e.external_heartbeat_status!=null||e.email_validation_status!=null||e.linkedin_profile_status!=null;return u.jsxs(fi,{title:"Contact Health",children:[!n&&!r&&u.jsx("div",{className:"text-xs text-muted-foreground italic",children:"No health data calculated yet."}),n&&u.jsxs("div",{className:"mb-4",children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(p1,{className:"w-4 h-4 text-muted-foreground"}),u.jsx("span",{className:"font-medium text-sm",children:"Relationship Strength"})]}),e.internal_heartbeat_score!=null&&u.jsxs("div",{className:"mb-2",children:[u.jsxs("div",{className:"flex items-center justify-between mb-1",children:[u.jsx("span",{className:"text-xs text-muted-foreground",children:"Engagement Score"}),u.jsxs("span",{className:"text-xs font-medium",children:[e.internal_heartbeat_score,"/100"]})]}),u.jsx(d_,{value:e.internal_heartbeat_score,className:"h-2"})]}),e.internal_heartbeat_status&&u.jsx("div",{className:"mb-2",children:u.jsx(S6e,{status:e.internal_heartbeat_status})}),t!=null&&u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Last activity:"," ",t===0?"Today":t===1?"Yesterday":`${t} days ago`]})]}),r&&u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(ZM,{className:"w-4 h-4 text-muted-foreground"}),u.jsx("span",{className:"font-medium text-sm",children:"Contact Validation"})]}),e.email_validation_status&&u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(e4,{className:"w-3 h-3 text-muted-foreground"}),u.jsx(j6e,{status:e.email_validation_status}),e.email_last_bounced_at&&u.jsx("span",{className:"text-xs text-destructive",children:"(bounced)"})]}),e.linkedin_profile_status&&u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(JM,{className:"w-3 h-3 text-muted-foreground"}),u.jsx(C6e,{status:e.linkedin_profile_status})]}),e.external_heartbeat_checked_at&&u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Validated"," ",nd(new Date(e.external_heartbeat_checked_at),new Date,{addSuffix:!0})]})]})]})},"ContactHealthCard"),tre=i(({link:e="edit"})=>{const{contactGender:t}=la(),n=Ft();return n?u.jsxs("div",{className:"hidden sm:block w-64 min-w-64 text-sm",children:[u.jsx("div",{className:"mb-4 -ml-1",children:e==="edit"?u.jsx(lne,{label:"Edit Contact"}):u.jsx(cne,{label:"Show Contact"})}),u.jsx(E6e,{}),u.jsxs(fi,{title:"Personal info",children:[u.jsx($H,{source:"email_jsonb",children:u.jsx(Xx,{className:"flex-col",children:u.jsx(Ob,{icon:u.jsx(e4,{className:"w-4 h-4 text-muted-foreground"}),primary:u.jsx(l6e,{source:"email"})})})}),n.has_newsletter&&u.jsx("p",{className:"pl-6 text-sm text-muted-foreground",children:"Subscribed to newsletter"}),n.linkedin_url&&u.jsx(Ob,{icon:u.jsx(JM,{className:"w-4 h-4 text-muted-foreground"}),primary:u.jsx("a",{className:"underline hover:no-underline text-sm text-muted-foreground",href:n.linkedin_url,target:"_blank",rel:"noopener noreferrer",title:n.linkedin_url,children:"LinkedIn"})}),u.jsx($H,{source:"phone_jsonb",children:u.jsx(Xx,{className:"flex-col",children:u.jsx(Ob,{icon:u.jsx(n4,{className:"w-4 h-4 text-muted-foreground"}),primary:u.jsx(Ir,{source:"number"}),showType:!0})})}),t.map(r=>n.gender===r.value?u.jsx(Ob,{icon:u.jsx(r.icon,{className:"w-4 h-4 text-muted-foreground"}),primary:u.jsx("span",{children:r.label})},r.value):null).filter(Boolean)]}),u.jsxs(fi,{title:"Background info",children:[u.jsx(bM,{render:i(r=>r?.background?u.jsx(Ir,{source:"background",record:r,className:"pb-2"}):null,"render")}),u.jsxs("div",{className:"text-muted-foreground",children:[u.jsx("span",{className:"text-sm",children:"Added on"})," ",u.jsx(cd,{source:"first_seen",options:{year:"numeric",month:"long",day:"numeric"}})]}),u.jsxs("div",{className:"text-muted-foreground",children:[u.jsx("span",{className:"text-sm",children:"Last activity on"})," ",u.jsx(cd,{source:"last_seen",options:{year:"numeric",month:"long",day:"numeric"}})]}),u.jsxs("div",{className:"inline-flex text-muted-foreground",children:["Followed by ",u.jsx(xn,{source:"sales_id",reference:"sales",children:u.jsx(Bc,{})})]})]}),u.jsx(fi,{title:"Tags",children:u.jsx(v6e,{})}),u.jsxs(fi,{title:"Tasks",children:[u.jsx(Gu,{target:"contact_id",reference:"tasks",sort:{field:"due_date",order:"ASC"},children:u.jsx(Jne,{})}),u.jsx(Xne,{})]}),e!=="edit"&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"mt-6 pt-6 border-t hidden sm:flex flex-col gap-2 items-start",children:[u.jsx(_6e,{}),u.jsx(y6e,{})]}),u.jsx("div",{className:"mt-6 pt-6 border-t hidden sm:flex flex-col gap-2 items-start",children:u.jsx(c_,{className:"h-6 cursor-pointer hover:bg-destructive/10! text-destructive! border-destructive! focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",size:"sm"})})]})]}):null},"ContactAside"),Ob=i(({icon:e,primary:t,showType:n})=>u.jsxs("div",{className:"flex flex-row items-center gap-2 min-h-6",children:[e,u.jsxs("div",{className:"flex flex-wrap gap-x-2 gap-y-0",children:[t,n?u.jsx(bM,{render:i(r=>r.type!=="Other"&&u.jsx(Ir,{source:"type",className:"text-muted-foreground"}),"render")}):null]})]}),"PersonalInfoRow"),k6e=i(()=>u.jsx(wM,{redirect:"show",children:u.jsx(O6e,{})}),"ContactEdit"),O6e=i(()=>{const{isPending:e,record:t}=Wpe();return e||!t?null:u.jsxs("div",{className:"mt-2 flex gap-8",children:[u.jsx(zr,{className:"flex flex-1 flex-col gap-4",children:u.jsx(un,{children:u.jsxs(Un,{children:[u.jsx(Mne,{}),u.jsx(o3,{})]})})}),u.jsx(tre,{link:"show"})]})},"ContactEditContent");var Vb={exports:{}};var R6e=Vb.exports,HH;function A6e(){return HH||(HH=1,(function(e,t){((n,r)=>{e.exports=r()})(R6e,i(function n(){var r=typeof self<"u"?self:typeof window<"u"?window:r!==void 0?r:{},a,s=!r.document&&!!r.postMessage,o=r.IS_PAPA_WORKER||!1,l={},f=0,c={};function p(N){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(D){var M=T(D);M.chunkSize=parseInt(M.chunkSize),D.step||D.chunk||(M.chunkSize=null),this._handle=new S(M),(this._handle.streamer=this)._config=M}).call(this,N),this.parseChunk=function(D,M){var I=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<I){let L=this._config.newline;L||(F=this._config.quoteChar||'"',L=this._handle.guessLineEndings(D,F)),D=[...D.split(L).slice(I)].join(L)}this.isFirstChunk&&A(this._config.beforeFirstChunk)&&(F=this._config.beforeFirstChunk(D))!==void 0&&(D=F),this.isFirstChunk=!1,this._halted=!1;var I=this._partialLine+D,F=(this._partialLine="",this._handle.parse(I,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(D=F.meta.cursor,I=(this._finished||(this._partialLine=I.substring(D-this._baseIndex),this._baseIndex=D),F&&F.data&&(this._rowCount+=F.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),o)r.postMessage({results:F,workerId:c.WORKER_ID,finished:I});else if(A(this._config.chunk)&&!M){if(this._config.chunk(F,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=F=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(F.data),this._completeResults.errors=this._completeResults.errors.concat(F.errors),this._completeResults.meta=F.meta),this._completed||!I||!A(this._config.complete)||F&&F.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),I||F&&F.meta.paused||this._nextChunk(),F}this._halted=!0},this._sendError=function(D){A(this._config.error)?this._config.error(D):o&&this._config.error&&r.postMessage({workerId:c.WORKER_ID,error:D,finished:!1})}}i(p,"u");function m(N){var D;(N=N||{}).chunkSize||(N.chunkSize=c.RemoteChunkSize),p.call(this,N),this._nextChunk=s?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(M){this._input=M,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(D=new XMLHttpRequest,this._config.withCredentials&&(D.withCredentials=this._config.withCredentials),s||(D.onload=R(this._chunkLoaded,this),D.onerror=R(this._chunkError,this)),D.open(this._config.downloadRequestBody?"POST":"GET",this._input,!s),this._config.downloadRequestHeaders){var M,I=this._config.downloadRequestHeaders;for(M in I)D.setRequestHeader(M,I[M])}var F;this._config.chunkSize&&(F=this._start+this._config.chunkSize-1,D.setRequestHeader("Range","bytes="+this._start+"-"+F));try{D.send(this._config.downloadRequestBody)}catch(L){this._chunkError(L.message)}s&&D.status===0&&this._chunkError()}},this._chunkLoaded=function(){D.readyState===4&&(D.status<200||400<=D.status?this._chunkError():(this._start+=this._config.chunkSize||D.responseText.length,this._finished=!this._config.chunkSize||this._start>=(M=>(M=M.getResponseHeader("Content-Range"))!==null?parseInt(M.substring(M.lastIndexOf("/")+1)):-1)(D),this.parseChunk(D.responseText)))},this._chunkError=function(M){M=D.statusText||M,this._sendError(new Error(M))}}i(m,"f");function v(N){(N=N||{}).chunkSize||(N.chunkSize=c.LocalChunkSize),p.call(this,N);var D,M,I=typeof FileReader<"u";this.stream=function(F){this._input=F,M=F.slice||F.webkitSlice||F.mozSlice,I?((D=new FileReader).onload=R(this._chunkLoaded,this),D.onerror=R(this._chunkError,this)):D=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var F=this._input,L=(this._config.chunkSize&&(L=Math.min(this._start+this._config.chunkSize,this._input.size),F=M.call(F,this._start,L)),D.readAsText(F,this._config.encoding));I||this._chunkLoaded({target:{result:L}})},this._chunkLoaded=function(F){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(F.target.result)},this._chunkError=function(){this._sendError(D.error)}}i(v,"l");function b(N){var D;p.call(this,N=N||{}),this.stream=function(M){return D=M,this._nextChunk()},this._nextChunk=function(){var M,I;if(!this._finished)return M=this._config.chunkSize,D=M?(I=D.substring(0,M),D.substring(M)):(I=D,""),this._finished=!D,this.parseChunk(I)}}i(b,"c");function w(N){p.call(this,N=N||{});var D=[],M=!0,I=!1;this.pause=function(){p.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){p.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(F){this._input=F,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){I&&D.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),D.length?this.parseChunk(D.shift()):M=!0},this._streamData=R(function(F){try{D.push(typeof F=="string"?F:F.toString(this._config.encoding)),M&&(M=!1,this._checkIsFinished(),this.parseChunk(D.shift()))}catch(L){this._streamError(L)}},this),this._streamError=R(function(F){this._streamCleanUp(),this._sendError(F)},this),this._streamEnd=R(function(){this._streamCleanUp(),I=!0,this._streamData("")},this),this._streamCleanUp=R(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}i(w,"p");function S(N){var D,M,I,F,L=Math.pow(2,53),q=-L,z=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,$=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,H=this,U=0,W=0,V=!1,Q=!1,Y=[],K={data:[],errors:[],meta:{}};function ee(fe){return N.skipEmptyLines==="greedy"?fe.join("").trim()==="":fe.length===1&&fe[0].length===0}i(ee,"y");function te(){if(K&&I&&(ne("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+c.DefaultDelimiter+"'"),I=!1),N.skipEmptyLines&&(K.data=K.data.filter(function(he){return!ee(he)})),se()){let he=function(J,Me){A(N.transformHeader)&&(J=N.transformHeader(J,Me)),Y.push(J)};if(i(he,"t"),K)if(Array.isArray(K.data[0])){for(var fe=0;se()&&fe<K.data.length;fe++)K.data[fe].forEach(he);K.data.splice(0,1)}else K.data.forEach(he)}function re(he,J){for(var Me=N.header?{}:[],_e=0;_e<he.length;_e++){var Ce=_e,Re=he[_e],Re=((Oe,Ne)=>(ze=>(N.dynamicTypingFunction&&N.dynamicTyping[ze]===void 0&&(N.dynamicTyping[ze]=N.dynamicTypingFunction(ze)),(N.dynamicTyping[ze]||N.dynamicTyping)===!0))(Oe)?Ne==="true"||Ne==="TRUE"||Ne!=="false"&&Ne!=="FALSE"&&((ze=>{if(z.test(ze)&&(ze=parseFloat(ze),q<ze&&ze<L))return 1})(Ne)?parseFloat(Ne):$.test(Ne)?new Date(Ne):Ne===""?null:Ne):Ne)(Ce=N.header?_e>=Y.length?"__parsed_extra":Y[_e]:Ce,Re=N.transform?N.transform(Re,Ce):Re);Ce==="__parsed_extra"?(Me[Ce]=Me[Ce]||[],Me[Ce].push(Re)):Me[Ce]=Re}return N.header&&(_e>Y.length?ne("FieldMismatch","TooManyFields","Too many fields: expected "+Y.length+" fields but parsed "+_e,W+J):_e<Y.length&&ne("FieldMismatch","TooFewFields","Too few fields: expected "+Y.length+" fields but parsed "+_e,W+J)),Me}i(re,"i");var ce;K&&(N.header||N.dynamicTyping||N.transform)&&(ce=1,!K.data.length||Array.isArray(K.data[0])?(K.data=K.data.map(re),ce=K.data.length):K.data=re(K.data,0),N.header&&K.meta&&(K.meta.fields=Y),W+=ce)}i(te,"g");function se(){return N.header&&Y.length===0}i(se,"_");function ne(fe,re,ce,he){fe={type:fe,code:re,message:ce},he!==void 0&&(fe.row=he),K.errors.push(fe)}i(ne,"k"),A(N.step)&&(F=N.step,N.step=function(fe){K=fe,se()?te():(te(),K.data.length!==0&&(U+=fe.data.length,N.preview&&U>N.preview?M.abort():(K.data=K.data[0],F(K,H))))}),this.parse=function(fe,re,ce){var he=N.quoteChar||'"',he=(N.newline||(N.newline=this.guessLineEndings(fe,he)),I=!1,N.delimiter?A(N.delimiter)&&(N.delimiter=N.delimiter(fe),K.meta.delimiter=N.delimiter):((he=((J,Me,_e,Ce,Re)=>{var Oe,Ne,ze,X;Re=Re||[","," ","|",";",c.RECORD_SEP,c.UNIT_SEP];for(var oe=0;oe<Re.length;oe++){for(var me,Te=Re[oe],de=0,ue=0,Ae=0,Pe=(ze=void 0,new j({comments:Ce,delimiter:Te,newline:Me,preview:10}).parse(J)),Fe=0;Fe<Pe.data.length;Fe++)_e&&ee(Pe.data[Fe])?Ae++:(me=Pe.data[Fe].length,ue+=me,ze===void 0?ze=me:0<me&&(de+=Math.abs(me-ze),ze=me));0<Pe.data.length&&(ue/=Pe.data.length-Ae),(Ne===void 0||de<=Ne)&&(X===void 0||X<ue)&&1.99<ue&&(Ne=de,Oe=Te,X=ue)}return{successful:!!(N.delimiter=Oe),bestDelimiter:Oe}})(fe,N.newline,N.skipEmptyLines,N.comments,N.delimitersToGuess)).successful?N.delimiter=he.bestDelimiter:(I=!0,N.delimiter=c.DefaultDelimiter),K.meta.delimiter=N.delimiter),T(N));return N.preview&&N.header&&he.preview++,D=fe,M=new j(he),K=M.parse(D,re,ce),te(),V?{meta:{paused:!0}}:K||{meta:{paused:!1}}},this.paused=function(){return V},this.pause=function(){V=!0,M.abort(),D=A(N.chunk)?"":D.substring(M.getCharIndex())},this.resume=function(){H.streamer._halted?(V=!1,H.streamer.parseChunk(D,!0)):setTimeout(H.resume,3)},this.aborted=function(){return Q},this.abort=function(){Q=!0,M.abort(),K.meta.aborted=!0,A(N.complete)&&N.complete(K),D=""},this.guessLineEndings=function(J,he){J=J.substring(0,1048576);var he=new RegExp(_(he)+"([^]*?)"+_(he),"gm"),ce=(J=J.replace(he,"")).split("\r"),he=J.split(`
114
114
  `),J=1<he.length&&he[0].length<ce[0].length;if(ce.length===1||J)return`
@@ -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:o,strokeWidth:f,stroke:c===void 0?"transparent":c,style:{pointerEvents:"none"}})})},"y");function hc(){return hc=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},hc.apply(null,arguments)}i(hc,"b");var Pi={translateX:0,translateY:0,padding:0,itemsSpacing:0,itemDirection:"left-to-right",justify:!1,symbolShape:"square",symbolSize:16,symbolSpacing:8},Wqe={top:0,right:0,bottom:0,left:0},a5=i(function(e){var t,n=e.direction,r=e.itemsSpacing,a=e.padding,s=e.itemCount,o=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}:hc({},Wqe,a),c=f.left+f.right,p=f.top+f.bottom,m=o+c,v=l+p,b=(s-1)*r;return n==="row"?m=o*s+b+c:n==="column"&&(v=l*s+b+p),{width:m,height:v,padding:f}},"A"),pie=i(function(e){var t=e.anchor,n=e.translateX,r=e.translateY,a=e.containerWidth,s=e.containerHeight,o=e.width,l=e.height,f=n,c=r;switch(t){case"top":f+=(a-o)/2;break;case"top-right":f+=a-o;break;case"right":f+=a-o,c+=(s-l)/2;break;case"bottom-right":f+=a-o,c+=s-l;break;case"bottom":f+=(a-o)/2,c+=s-l;break;case"bottom-left":c+=s-l;break;case"left":c+=(s-l)/2;break;case"center":f+=(a-o)/2,c+=(s-l)/2}return{x:f,y:c}},"C"),mie=i(function(e){var t,n,r,a,s,o,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,o="central",f?(r=m,s="end"):(r=c+p,s="start");break;case"right-to-left":t=m-c,n=(v-c)/2,a=v/2,o="central",f?(r=0,s="start"):(r=m-c-p,s="end");break;case"top-to-bottom":t=(m-c)/2,n=0,r=m/2,s="middle",f?(a=v,o="alphabetic"):(a=c+p,o="text-before-edge");break;case"bottom-to-top":t=(m-c)/2,n=v-c,r=m/2,s="middle",f?(a=0,o="text-before-edge"):(a=v-c-p,o="alphabetic")}return{symbolX:t,symbolY:n,labelX:r,labelY:a,labelAnchor:s,labelAlignment:o}},"z"),Gqe={circle:zqe,diamond:Bqe,square:Hqe,triangle:Vqe},Kqe=i(function(e){var t,n,r,a,s,o,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?Pi.itemDirection:j,k=e.justify,E=k===void 0?Pi.justify:k,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?Pi.symbolShape:M,F=e.symbolSize,L=F===void 0?Pi.symbolSize:F,q=e.symbolSpacing,z=q===void 0?Pi.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({}),se=te[0],ne=te[1],fe=Br(),re=y.useCallback((function(X){if(ee){var oe=ee.filter((function(me){return me.on==="hover"})).reduce((function(me,Te){return hc({},me,Te.style)}),{});ne(oe)}Q?.(_,X)}),[Q,_,ee]),ce=y.useCallback((function(X){if(ee){var oe=ee.filter((function(me){return me.on!=="hover"})).reduce((function(me,Te){return hc({},me,Te.style)}),{});ne(oe)}Y?.(_,X)}),[Y,_,ee]),he=mie({direction:C,justify:E,symbolSize:(t=se.symbolSize)!=null?t:L,symbolSpacing:z,width:w,height:S}),J=he.symbolX,Me=he.symbolY,_e=he.labelX,Ce=he.labelY,Re=he.labelAnchor,Oe=he.labelAlignment,Ne=[V,Q,Y,K].some((function(X){return X!==void 0})),ze=typeof I=="function"?I:Gqe[I];return u.jsxs("g",{transform:"translate("+v+","+b+")",style:{opacity:(n=se.itemOpacity)!=null?n:D},children:[u.jsx("rect",{width:w,height:S,fill:(r=se.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,hc({id:_.id,x:J,y:Me,size:(a=se.symbolSize)!=null?a:L,fill:(s=(o=_.fill)!=null?o:_.color)!=null?s:"black",borderWidth:(l=se.symbolBorderWidth)!=null?l:H,borderColor:(f=se.symbolBorderColor)!=null?f:W},_.hidden?fe.legends.hidden.symbol:void 0)),u.jsx(lS,{textAnchor:Re,style:hc({},fe.legends.text,{fill:(c=(p=(m=se.itemTextColor)!=null?m:T)!=null?p:fe.legends.text.fill)!=null?c:"black",dominantBaseline:Oe,pointerEvents:"none",userSelect:"none"},_.hidden?fe.legends.hidden.text:void 0),x:_e,y:Ce,children:_.label})]})},"B"),Yqe=i(function(e){var t=e.data,n=e.x,r=e.y,a=e.direction,s=e.padding,o=s===void 0?Pi.padding:s,l=e.justify,f=e.effects,c=e.itemWidth,p=e.itemHeight,m=e.itemDirection,v=m===void 0?Pi.itemDirection:m,b=e.itemsSpacing,w=b===void 0?Pi.itemsSpacing:b,S=e.itemTextColor,_=e.itemBackground,j=_===void 0?"transparent":_,C=e.itemOpacity,k=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=a5({itemCount:t.length,itemWidth:c,itemHeight:p,itemsSpacing:w,direction:a,padding:o}).padding,q=a==="row"?c+w:0,z=a==="column"?p+w:0;return u.jsx("g",{transform:"translate("+n+","+r+")",children:t.map((function($,H){return u.jsx(Kqe,{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:k,symbolShape:E,symbolSize:T,symbolSpacing:R,symbolBorderWidth:A,symbolBorderColor:N,onClick:D,onMouseEnter:M,onMouseLeave:I,toggleSerie:F},H)}))})},"H"),Qqe=i(function(e){var t=e.data,n=e.containerWidth,r=e.containerHeight,a=e.translateX,s=a===void 0?Pi.translateX:a,o=e.translateY,l=o===void 0?Pi.translateY:o,f=e.anchor,c=e.direction,p=e.padding,m=p===void 0?Pi.padding:p,v=e.justify,b=e.itemsSpacing,w=b===void 0?Pi.itemsSpacing:b,S=e.itemWidth,_=e.itemHeight,j=e.itemDirection,C=e.itemTextColor,k=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=a5({itemCount:t.length,itemsSpacing:w,itemWidth:S,itemHeight:_,direction:c,padding:m}),$=z.width,H=z.height,U=pie({anchor:f,translateX:s,translateY:l,containerWidth:n,containerHeight:r,width:$,height:H}),W=U.x,V=U.y;return u.jsx(Yqe,{data:t,x:W,y:V,direction:c,padding:m,justify:v,effects:q,itemsSpacing:w,itemWidth:S,itemHeight:_,itemDirection:j,itemTextColor:C,itemBackground:k,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"),Xqe={start:"left",middle:"center",end:"right"},Zqe=i(function(e,t){var n=t.data,r=t.containerWidth,a=t.containerHeight,s=t.translateX,o=s===void 0?0:s,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,k=t.itemDirection,E=k===void 0?"left-to-right":k,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=a5({itemCount:n.length,itemWidth:j,itemHeight:C,itemsSpacing:_,direction:p,padding:v}),F=I.width,L=I.height,q=I.padding,z=pie({anchor:c,translateX:o,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),Gv(e,M.legends.text),n.forEach((function(V,Q){var Y,K=Q*U+q.left,ee=Q*W+q.top,te=mie({direction:E,justify:w,symbolSize:A,symbolSpacing:D,width:j,height:C}),se=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+se,ee+ne,A,A),e.textAlign=Xqe[ce],he==="central"&&(e.textBaseline="middle"),Kv(e,hc({},M.legends.text,{fill:T??M.legends.text.fill}),String(V.label),K+fe,ee+re)})),e.restore()},"L"),Jqe=i(function(e,t,n,r,a,s){s>0?(e.moveTo(t+s,n),e.lineTo(t+r-s,n),e.quadraticCurveTo(t+r,n,t+r,n+s),e.lineTo(t+r,n+a-s),e.quadraticCurveTo(t+r,n+a,t+r-s,n+a),e.lineTo(t+s,n+a),e.quadraticCurveTo(t,n+a,t,n+a-s),e.lineTo(t,n+s),e.quadraticCurveTo(t,n,t+s,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 Hc(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(Hc,"U");var UW,eUe=i(function(e){var t=e.bars,n=e.annotations,r=uie({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 s=a.height,o=a.width;return{width:o,height:s,size:Math.max(o,s)}},"getDimensions")});return u.jsx(u.Fragment,{children:r.map((function(a,s){return u.jsx(Cqe,gn({},a),s)}))})},"$"),tUe=i(function(e){var t=e.width,n=e.height,r=e.legends,a=e.toggleSerie;return u.jsx(u.Fragment,{children:r.map((function(s,o){var l,f=s[0],c=s[1];return u.jsx(Qqe,gn({},f,{containerWidth:t,containerHeight:n,data:(l=f.data)!=null?l:c,toggleSerie:f.toggleSerie&&f.dataFrom==="keys"?a:void 0}),o)}))})},"ee"),nUe=["data"],rUe=i(function(e){var t,n=e.bar,r=n.data,a=Hc(n,nUe),s=e.style,o=s.borderColor,l=s.color,f=s.height,c=s.labelColor,p=s.labelOpacity,m=s.labelX,v=s.labelY,b=s.transform,w=s.width,S=s.textAnchor,_=e.borderRadius,j=e.borderWidth,C=e.label,k=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=Br(),$=Bre(),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]),se=y.useCallback((function(){W()}),[W]);return u.jsxs(vr.g,{transform:b,children:[u.jsx(vr.rect,{width:aD(w,(function(ne){return Math.max(ne,0)})),height:aD(f,(function(ne){return Math.max(ne,0)})),rx:_,ry:_,fill:(t=r.fill)!=null?t:l,strokeWidth:j,stroke:o,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?se:void 0,"data-testid":"bar.item."+r.id+"."+r.index}),k&&u.jsx(lS,{x:m,y:v,textAnchor:S,dominantBaseline:"central",fillOpacity:p,style:gn({},z.labels.text,{pointerEvents:"none",fill:c}),children:C})]})},"ae"),aUe=["color","label"],iUe=i(function(e){var t=e.color,n=e.label,r=Hc(e,aUe);return u.jsx(CIe,{id:n,value:r.formattedValue,enableChip:!0,color:t})},"ne"),$n={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:iUe,tooltipLabel:i(function(e){return e.id+" - "+e.indexValue},"tooltipLabel"),legends:[],initialHiddenIds:[],annotations:[],enableTotals:!1,totalsOffset:10},Ln=gn({},$n,{layers:["grid","axes","bars","totals","markers","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},barComponent:rUe,defs:[],fill:[],markers:[],animate:!0,animateOnMount:!1,motionConfig:"default",role:"img",isFocusable:!1}),xr=gn({},$n,{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,s=n.width,o=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(),Jqe(e,o,l,s,a,Math.min(c,a)),e.fill(),p>0&&e.stroke(),v&&(e.textBaseline="middle",e.textAlign=_==="middle"?"center":_,Kv(e,b,m,o+w,l+S))},"renderBar"),pixelRatio:typeof window<"u"&&(UW=window.devicePixelRatio)!=null?UW:1}),gie=i(function(e,t,n,r,a,s){return r5(r,{all:e.map(t),min:0,max:0},a,s).padding(n)},"de"),vie=i(function(e,t){return e.map((function(n){return gn({},t.reduce((function(r,a){return r[a]=null,r}),{}),n)}))},"ue"),cS=i(function(e){return Object.keys(e).reduce((function(t,n){return e[n]&&(t[n]=e[n]),t}),{})},"se"),uS=i(function(e){return[e,Number(e)]},"ce");function yie(e,t,n,r){return e===void 0&&(e=$n.layout),n===void 0&&(n=$n.labelPosition),r===void 0&&(r=$n.labelOffset),function(a,s){var o=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+o,labelY:s/2,textAnchor:n==="middle"?"middle":t?"end":"start"}}var f=s/2;return n==="start"?f=t?0:s:n==="end"&&(f=t?s:0),{labelX:a/2,labelY:f-o,textAnchor:"middle"}}}i(yie,"he");var sUe=["layout","width","height","padding","innerPadding","valueScale","indexScale","hiddenIds"],i5=i(function(e,t){return e>t},"be"),bie=i(function(e,t){return e<t},"ge"),xie=i(function(e,t){return Array.from(" ".repeat(t-e),(function(n,r){return e+r}))},"ve"),oUe=i(function(e){return i5(e,0)?0:e},"me"),lUe=i(function(e,t,n,r){var a=e.data,s=e.formatValue,o=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?bie:i5,_=a.map(cS),j=[];return m.forEach((function(C,k){return xie(0,v.domain().length).forEach((function(E){var T,R,A,N=uS(a[E][C]),D=N[0],M=N[1],I=l(a[E]),F=((T=v(I))!=null?T:0)+t*k+p*k,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:s(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:o(z),label:f(z)})}))})),j},"pe"),cUe=i(function(e,t,n,r){var a=e.data,s=e.formatValue,o=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?bie:i5,_=a.map(cS),j=[];return c.forEach((function(C,k){return xie(0,b.domain().length).forEach((function(E){var T,R,A,N=uS(a[E][C]),D=N[0],M=N[1],I=o(a[E]),F=S(R=M,0)?r:(A=v(R))!=null?A:0,L=((T=b(I))!=null?T:0)+t*k+m*k,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:s(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"),uUe=i(function(e){var t,n,r,a=e.layout,s=e.width,o=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=Hc(e,sUe),_=S.keys.filter((function(H){return!w.includes(H)})),j=vie(S.data,_),C=a==="vertical"?["y","x",s]:["x","y",o],k=C[0],E=C[1],T=C[2],R=gie(j,S.getIndex,f,v,T,E),A=m.min==="auto"?oUe: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=r5(m,{all:N,min:D,max:M},k==="x"?s:o,k),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"?lUe.apply(void 0,$):cUe.apply(void 0,$):[]}},"xe"),dUe=["data","layout","width","height","padding","valueScale","indexScale","hiddenIds"],wie=i(function(e){var t;return e.some(Array.isArray)?wie((t=[]).concat.apply(t,e)):e},"ke"),fUe=i(function(e,t,n){var r=e.formatValue,a=e.getColor,s=e.getIndex,o=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],k=(_=c(s(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=uS(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:cS(C.data)};v.push({key:b.key+"."+w,index:v.length,data:D,x:k,y:E,absX:m.left+k,absY:m.top+E,width:t,height:T,color:a(D),label:o(D)})}))})),v},"we"),hUe=i(function(e,t,n){var r=e.formatValue,a=e.getColor,s=e.getIndex,o=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],k=(_=p(s(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=uS(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:cS(C.data)};v.push({key:b.key+"."+w,index:v.length,data:D,x:E,y:k,absX:m.left+E,absY:m.top+k,width:T,height:t,color:a(D),label:o(D)})}))})),v},"Le"),pUe=i(function(e){var t,n,r=e.data,a=e.layout,s=e.width,o=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=Hc(e,dUe),w=b.keys.filter((function(z){return!v.includes(z)})),S=LFe().keys(w).offset($Fe)(vie(r,w)),_=a==="vertical"?["y","x",s]:["x","y",o],j=_[0],C=_[1],k=_[2],E=gie(r,b.getIndex,f,p,k,C),T=(n=wie(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=r5(c,{all:T,min:R,max:A},j==="x"?s:o,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"?fUe.apply(void 0,q):hUe.apply(void 0,q):[]}},"Ce"),mUe=i(function(e){var t=e.bars,n=e.direction,r=e.from,a=e.groupMode,s=e.layout,o=e.legendLabel,l=e.reverse,f=eie(o??(r==="indexes"?"indexValue":"id"));return r==="indexes"?(function(c,p,m){var v=pW(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,s,f):(function(c,p,m,v,b,w){var S=pW(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,s,n,a,l,f)},"We"),zW=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+n)},"Me"),gUe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+(n>0?n:0))},"Be"),vUe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,Math.max(r,Number(n)))},"Re"),yUe=i(function(e,t){var n=e.get(t)||0;e.set(t,n+1)},"Oe"),_ie=i(function(e){var t,n=e.indexBy,r=n===void 0?$n.indexBy:n,a=e.keys,s=a===void 0?$n.keys:a,o=e.label,l=o===void 0?$n.label:o,f=e.tooltipLabel,c=f===void 0?$n.tooltipLabel:f,p=e.valueFormat,m=e.colors,v=m===void 0?$n.colors:m,b=e.colorBy,w=b===void 0?$n.colorBy:b,S=e.borderColor,_=S===void 0?$n.borderColor:S,j=e.labelTextColor,C=j===void 0?$n.labelTextColor:j,k=e.groupMode,E=k===void 0?$n.groupMode:k,T=e.layout,R=T===void 0?$n.layout:T,A=e.data,N=e.margin,D=e.width,M=e.height,I=e.padding,F=I===void 0?$n.padding:I,L=e.innerPadding,q=L===void 0?$n.innerPadding:L,z=e.valueScale,$=z===void 0?$n.valueScale:z,H=e.indexScale,U=H===void 0?$n.indexScale:H,W=e.initialHiddenIds,V=W===void 0?$n.initialHiddenIds:W,Q=e.enableLabel,Y=Q===void 0?$n.enableLabel:Q,K=e.labelSkipWidth,ee=K===void 0?$n.labelSkipWidth:K,te=e.labelSkipHeight,se=te===void 0?$n.labelSkipHeight:te,ne=e.legends,fe=ne===void 0?$n.legends:ne,re=e.legendLabel,ce=e.totalsOffset,he=ce===void 0?$n.totalsOffset:ce,J=y.useState(V??[]),Me=J[0],_e=J[1],Ce=y.useCallback((function(Ke){_e((function(pt){return pt.indexOf(Ke)>-1?pt.filter((function(ve){return ve!==Ke})):[].concat(pt,[Ke])}))}),[]),Re=iT(r),Oe=iT(l),Ne=iT(c),ze=n5(p),X=Br(),oe=Uqe(v,w),me=qW(_,X),Te=qW(C,X),de=(E==="grouped"?uUe:pUe)({layout:R,data:A,getIndex:Re,keys:s,width:D,height:M,getColor:oe,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)&&!(se>0&&ve<se)}),[Y,ee,se]),Nt=y.useMemo((function(){return s.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,s,ue]),qt=(t=$.reverse)!=null&&t,Rt=y.useMemo((function(){return fe.map((function(Ke){return[Ke,mUe({bars:Ke.dataFrom==="keys"?Nt:ue,direction:Ke.direction,from:Ke.dataFrom,groupMode:E,layout:R,legendLabel:re,reverse:qt})]}))}),[fe,Nt,ue,E,R,re,qt]),zt=y.useMemo((function(){return(function(Ke,pt,ve,ye,ct,$e,Xe){ye===void 0&&(ye=$n.layout),ct===void 0&&(ct=$n.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;zW(tt,vt,Number(Et)),gUe(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 Lt=new Map,Pt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Et=_t.value;zW(tt,vt,Number(Et)),vUe(Lt,vt,Number(Et)),yUe(Pt,vt)})),Lt.forEach((function(At,_t){var vt,Et,Z,pe=tt.get(_t)||0,Se=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"?Se*jt/2:$e,Et+=ye==="vertical"?-$e:Se*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:Oe,getTooltipLabel:Ne,formatValue:ze,getColor:oe,getBorderColor:me,getLabelColor:Te,shouldRenderBarLabel:et,hiddenIds:Me,toggleSerie:Ce,legendsWithData:Rt,barTotals:zt}},"Ie"),bUe=i(function(e){var t=e.data,n=e.springConfig,r=e.animate,a=e.layout,s=a===void 0?Ln.layout:a,o=Br();return j_(t,{keys:i(function(l){return l.key},"keys"),from:i(function(l){return{x:s==="vertical"?l.x:l.animationOffset,y:s==="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:s==="vertical"?l.x:l.animationOffset,y:s==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"leave"),config:n,immediate:!r,initial:r?void 0:null})((function(l,f){return u.jsx(vr.text,{x:l.x,y:l.y,fillOpacity:l.labelOpacity,style:gn({},o.labels.text,{pointerEvents:"none"}),fontWeight:"bold",fontSize:o.labels.text.fontSize,fontFamily:o.labels.text.fontFamily,textAnchor:s==="vertical"?"middle":"start",alignmentBaseline:s==="vertical"?"alphabetic":"middle",children:f.formattedValue},f.key)}))},"Ve"),xUe=["isInteractive","animate","motionConfig","theme","renderWrapper"],wUe=i(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,s=e.margin,o=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?Ln.axisBottom:_,C=e.axisLeft,k=C===void 0?Ln.axisLeft:C,E=e.enableGridX,T=E===void 0?Ln.enableGridX:E,R=e.enableGridY,A=R===void 0?Ln.enableGridY:R,N=e.gridXValues,D=e.gridYValues,M=e.layers,I=M===void 0?Ln.layers:M,F=e.barComponent,L=F===void 0?Ln.barComponent:F,q=e.enableLabel,z=q===void 0?Ln.enableLabel:q,$=e.label,H=e.labelSkipWidth,U=H===void 0?Ln.labelSkipWidth:H,W=e.labelSkipHeight,V=W===void 0?Ln.labelSkipHeight:W,Q=e.labelTextColor,Y=e.labelPosition,K=Y===void 0?Ln.labelPosition:Y,ee=e.labelOffset,te=ee===void 0?Ln.labelOffset:ee,se=e.markers,ne=se===void 0?Ln.markers:se,fe=e.colorBy,re=e.colors,ce=e.defs,he=ce===void 0?Ln.defs:ce,J=e.fill,Me=J===void 0?Ln.fill:J,_e=e.borderRadius,Ce=_e===void 0?Ln.borderRadius:_e,Re=e.borderWidth,Oe=Re===void 0?Ln.borderWidth:Re,Ne=e.borderColor,ze=e.annotations,X=ze===void 0?Ln.annotations:ze,oe=e.legendLabel,me=e.tooltipLabel,Te=e.valueFormat,de=e.isInteractive,ue=de===void 0?Ln.isInteractive:de,Ae=e.tooltip,Pe=Ae===void 0?Ln.tooltip:Ae,Fe=e.onClick,et=e.onMouseEnter,Nt=e.onMouseLeave,qt=e.legends,Rt=e.role,zt=Rt===void 0?Ln.role:Rt,Ke=e.ariaLabel,pt=e.ariaLabelledBy,ve=e.ariaDescribedBy,ye=e.isFocusable,ct=ye===void 0?Ln.isFocusable:ye,$e=e.barAriaLabel,Xe=e.barAriaLabelledBy,We=e.barAriaDescribedBy,tt=e.barAriaHidden,jt=e.barAriaDisabled,Ye=e.initialHiddenIds,gt=e.enableTotals,Lt=gt===void 0?Ln.enableTotals:gt,Pt=e.totalsOffset,At=Pt===void 0?Ln.totalsOffset:Pt,_t=e.forwardedRef,vt=_s(),Et=vt.animate,Z=vt.config,pe=Jae(o,l,s),Se=pe.outerWidth,qe=pe.outerHeight,He=pe.margin,rt=pe.innerWidth,nt=pe.innerHeight,Qe=_ie({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:qt,legendLabel:oe,initialHiddenIds:Ye,totalsOffset:At}),st=Qe.bars,ut=Qe.barsWithValue,ot=Qe.xScale,lt=Qe.yScale,yt=Qe.getLabel,at=Qe.getTooltipLabel,Ot=Qe.getBorderColor,bt=Qe.getLabelColor,$t=Qe.shouldRenderBarLabel,Mt=Qe.toggleSerie,Vr=Qe.legendsWithData,Na=Qe.barTotals,gi=Qe.getColor,fr=yie(c,(t=p?.reverse)!=null&&t,K,te),Ss=j_(ut,{keys:i(function(Ve){return Ve.key},"keys"),from:i(function(Ve){return gn({borderColor:Ot(Ve),color:Ve.color,height:0,labelColor:bt(Ve),labelOpacity:0},fr(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:Ot(Ve),color:Ve.color,height:Ve.height,labelColor:bt(Ve),labelOpacity:1},fr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+Ve.y+")",width:Ve.width})},"enter"),update:i(function(Ve){return gn({borderColor:Ot(Ve),color:Ve.color,height:Ve.height,labelColor:bt(Ve),labelOpacity:1},fr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+Ve.y+")",width:Ve.width})},"update"),leave:i(function(Ve){return gn({borderColor:Ot(Ve),color:Ve.color,height:0,labelColor:bt(Ve),labelOpacity:0},fr(Ve.width,Ve.height),{labelY:0,transform:"translate("+Ve.x+", "+(Ve.y+Ve.height)+")",width:Ve.width},c==="vertical"?{}:gn({},fr(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}),Wr=y.useMemo((function(){return{borderRadius:Ce,borderWidth:Oe,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,Oe,z,at,ue,V,U,Fe,et,Nt,Pe,ct,$e,Xe,We,tt,jt]),Qa=y9e(he,st,Me,{dataKey:"data",targetKey:"data.fill"}),na={annotations:null,axes:null,bars:null,grid:null,legends:null,markers:null,totals:null};I.includes("annotations")&&(na.annotations=u.jsx(eUe,{bars:st,annotations:X},"annotations")),I.includes("axes")&&(na.axes=u.jsx(Z9e,{xScale:ot,yScale:lt,width:rt,height:nt,top:w,right:S,bottom:j,left:k},"axes")),I.includes("bars")&&(na.bars=u.jsx(y.Fragment,{children:Ss((function(Ve,Bn){return y.createElement(L,gn({},Wr,{bar:Bn,style:Ve,shouldRenderLabel:$t(Bn),label:yt(Bn.data)}))}))},"bars")),I.includes("grid")&&(na.grid=u.jsx(eqe,{width:rt,height:nt,xScale:T?ot:null,yScale:A?lt:null,xValues:N,yValues:D},"grid")),I.includes("legends")&&(na.legends=u.jsx(tUe,{width:rt,height:nt,legends:Vr,toggleSerie:Mt},"legends")),I.includes("markers")&&(na.markers=u.jsx(l9e,{markers:ne,width:rt,height:nt,xScale:ot,yScale:lt},"markers")),I.includes("totals")&&Lt&&(na.totals=u.jsx(bUe,{data:Na,springConfig:Z,animate:Et,layout:c},"totals"));var Xa=gn({},Wr,{margin:He,width:o,height:l,innerWidth:rt,innerHeight:nt,bars:st,legendData:Vr,enableLabel:z,xScale:ot,yScale:lt,tooltip:Pe,getTooltipLabel:at,onClick:Fe,onMouseEnter:et,onMouseLeave:Nt,getColor:gi});return u.jsx(i9e,{width:Se,height:qe,margin:He,defs:Qa,role:zt,ariaLabel:Ke,ariaLabelledBy:pt,ariaDescribedBy:ve,isFocusable:ct,ref:_t,children:I.map((function(Ve,Bn){var Bi;return typeof Ve=="function"?u.jsx(y.Fragment,{children:y.createElement(Ve,Xa)},Bn):(Bi=na?.[Ve])!=null?Bi:null}))})},"He"),_Ue=y.forwardRef((function(e,t){var n=e.isInteractive,r=n===void 0?Ln.isInteractive:n,a=e.animate,s=a===void 0?Ln.animate:a,o=e.motionConfig,l=o===void 0?Ln.motionConfig:o,f=e.theme,c=e.renderWrapper,p=Hc(e,xUe);return u.jsx(Kae,{animate:s,isInteractive:r,motionConfig:l,renderWrapper:c,theme:f,children:u.jsx(wUe,gn({},p,{isInteractive:r,forwardedRef:t}))})})),SUe=["isInteractive","renderWrapper","theme"],RT=i(function(e,t,n,r){return e.find((function(a){return p9e(a.x+t.left,a.y+t.top,a.width,a.height,n,r)}))},"Fe"),jUe=i(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,s=e.margin,o=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?xr.axisBottom:_,C=e.axisLeft,k=C===void 0?xr.axisLeft:C,E=e.enableGridX,T=E===void 0?xr.enableGridX:E,R=e.enableGridY,A=R===void 0?xr.enableGridY:R,N=e.gridXValues,D=e.gridYValues,M=e.labelPosition,I=M===void 0?xr.labelPosition:M,F=e.labelOffset,L=F===void 0?xr.labelOffset:F,q=e.layers,z=q===void 0?xr.layers:q,$=e.renderBar,H=$===void 0?xr.renderBar:$,U=e.enableLabel,W=U===void 0?xr.enableLabel:U,V=e.label,Q=e.labelSkipWidth,Y=Q===void 0?xr.labelSkipWidth:Q,K=e.labelSkipHeight,ee=K===void 0?xr.labelSkipHeight:K,te=e.labelTextColor,se=e.colorBy,ne=e.colors,fe=e.borderRadius,re=fe===void 0?xr.borderRadius:fe,ce=e.borderWidth,he=ce===void 0?xr.borderWidth:ce,J=e.borderColor,Me=e.annotations,_e=Me===void 0?xr.annotations:Me,Ce=e.legendLabel,Re=e.tooltipLabel,Oe=e.valueFormat,Ne=e.isInteractive,ze=Ne===void 0?xr.isInteractive:Ne,X=e.tooltip,oe=X===void 0?xr.tooltip:X,me=e.onClick,Te=e.onMouseEnter,de=e.onMouseLeave,ue=e.legends,Ae=e.pixelRatio,Pe=Ae===void 0?xr.pixelRatio:Ae,Fe=e.role,et=e.forwardedRef,Nt=e.enableTotals,qt=Nt===void 0?xr.enableTotals:Nt,Rt=e.totalsOffset,zt=Rt===void 0?xr.totalsOffset:Rt,Ke=y.useRef(null),pt=Br(),ve=Jae(o,l,s),ye=ve.margin,ct=ve.innerWidth,$e=ve.innerHeight,Xe=ve.outerWidth,We=ve.outerHeight,tt=_ie({indexBy:r,label:V,tooltipLabel:Re,valueFormat:Oe,colors:ne,colorBy:se,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:zt}),jt=tt.bars,Ye=tt.barsWithValue,gt=tt.xScale,Lt=tt.yScale,Pt=tt.getLabel,At=tt.getTooltipLabel,_t=tt.getBorderColor,vt=tt.getLabelColor,Et=tt.shouldRenderBarLabel,Z=tt.legendsWithData,pe=tt.barTotals,Se=tt.getColor,qe=Bre(),He=qe.showTooltipFromEvent,rt=qe.hideTooltip,nt=bqe({annotations:uie({data:jt,annotations:_e,getPosition:i(function(at){return{x:at.x,y:at.y}},"getPosition"),getDimensions:i(function(at){var Ot=at.width,bt=at.height;return{width:Ot,height:bt,size:Math.max(Ot,bt)}},"getDimensions")})}),Qe=y.useMemo((function(){return{borderRadius:re,borderWidth:he,isInteractive:ze,isFocusable:!1,labelSkipWidth:Y,labelSkipHeight:ee,margin:ye,width:o,height:l,innerWidth:ct,innerHeight:$e,bars:jt,legendData:Z,enableLabel:W,xScale:gt,yScale:Lt,tooltip:oe,getTooltipLabel:At,onClick:me,onMouseEnter:Te,onMouseLeave:de,getColor:Se}}),[re,he,ze,Y,ee,ye,o,l,ct,$e,jt,Z,W,gt,Lt,oe,At,me,Te,de,Se]),st=n5(Oe),ut=yie(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(Ot){Ot==="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&&kW(at,{width:ct,height:$e,scale:gt,axis:"x",values:N}),A&&kW(at,{width:ct,height:$e,scale:Lt,axis:"y",values:D})):Ot==="axes"?nqe(at,{xScale:gt,yScale:Lt,width:ct,height:$e,top:w,right:S,bottom:j,left:k,theme:pt}):Ot==="bars"?(Gv(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)))}))):Ot==="legends"?Z.forEach((function(bt){var $t=bt[0],Mt=bt[1];Zqe(at,gn({},$t,{data:Mt,containerWidth:ct,containerHeight:$e,theme:pt}))})):Ot==="annotations"?Eqe(at,{annotations:nt,theme:pt}):Ot==="totals"&&qt?(function(bt,$t,Mt,Vr){Vr===void 0&&(Vr=xr.layout),Gv(bt,Mt.labels.text),bt.textBaseline=Vr==="vertical"?"alphabetic":"middle",bt.textAlign=Vr==="vertical"?"center":"start",$t.forEach((function(Na){Kv(bt,Mt.labels.text,Na.formattedValue,Na.x,Na.y)}))})(at,pe,pt,c):typeof Ot=="function"&&Ot(at,Qe)})),at.save()}}),[j,k,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,Lt,Et,pt,o,pe,qt,st,ut]);var ot=y.useCallback((function(at){if(jt&&Ke.current){var Ot=sT(Ke.current,at),bt=Ot[0],$t=Ot[1],Mt=RT(jt,ye,bt,$t);Mt!==void 0?(He(y.createElement(oe,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,oe]),lt=y.useCallback((function(at){if(jt&&Ke.current){rt();var Ot=sT(Ke.current,at),bt=Ot[0],$t=Ot[1],Mt=RT(jt,ye,bt,$t);Mt&&de?.(Mt.data,at)}}),[rt,ye,de,jt]),yt=y.useCallback((function(at){if(jt&&Ke.current){var Ot=sT(Ke.current,at),bt=Ot[0],$t=Ot[1],Mt=RT(jt,ye,bt,$t);Mt!==void 0&&me?.(gn({},Mt.data,{color:Mt.color}),at)}}),[ye,me,jt]);return u.jsx("canvas",{ref:b9e(Ke,et),width:Xe*Pe,height:We*Pe,style:{width:Xe,height:We,cursor:ze?"auto":"normal"},onMouseEnter:ze?ot:void 0,onMouseMove:ze?ot:void 0,onMouseLeave:ze?lt:void 0,onClick:ze?yt:void 0,role:Fe})},"ze"),CUe=y.forwardRef((function(e,t){var n=e.isInteractive,r=e.renderWrapper,a=e.theme,s=Hc(e,SUe);return u.jsx(Kae,{isInteractive:n,renderWrapper:r,theme:a,animate:!1,children:u.jsx(jUe,gn({},s,{isInteractive:n,forwardedRef:t}))})})),EUe=["defaultWidth","defaultHeight","onResize","debounceResize"],kUe=y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,s=e.debounceResize,o=Hc(e,EUe);return u.jsx(Yae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:s,children:i(function(l){var f=l.width,c=l.height;return u.jsx(_Ue,gn({},o,{width:f,height:c,ref:t}))},"children")})})),OUe=["defaultWidth","defaultHeight","onResize","debounceResize"];y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,s=e.debounceResize,o=Hc(e,OUe);return u.jsx(Yae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:s,children:i(function(l){var f=l.width,c=l.height;return u.jsx(CUe,gn({},o,{width:f,height:c,ref:t}))},"children")})}));const RUe={opportunity:.2,"proposal-sent":.5,"in-negociation":.8,delayed:.3},AUe=new Date(new Date().setMonth(new Date().getMonth()-6)).toISOString(),BW="en-US",TUe="USD",NUe=y.memo(()=>{const e=navigator?navigator.languages||[navigator.language]:[BW],{data:t,isPending:n}=pa("deals",{pagination:{perPage:100,page:1},sort:{field:"created_at",order:"ASC"},filter:{"created_at@gte":AUe}}),r=y.useMemo(()=>{if(!t)return[];const o=t.reduce((f,c)=>{const p=CN(c.created_at??new Date).toISOString();return f[p]||(f[p]=[]),f[p].push(c),f},{});return Object.keys(o).map(f=>({date:gc(f,"MMM"),won:o[f].filter(c=>c.stage==="won").reduce((c,p)=>{const m=p.amount??0;return isNaN(m)||(c+=m),c},0),pending:o[f].filter(c=>!["won","lost"].includes(c.stage)).reduce((c,p)=>{const m=p.amount??0,v=RUe[p.stage]??0;return!isNaN(m)&&!isNaN(v)&&(c+=m*v),c},0),lost:o[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((o,l)=>(o.min=Math.min(o.min,l.lost),o.max=Math.max(o.max,l.won+l.pending),o),{min:0,max:0}),s={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 u.jsxs("div",{className:"flex flex-col",children:[u.jsxs("div",{className:"flex items-center mb-4",children:[u.jsx("div",{className:"mr-3 flex",children:u.jsx(KQ,{className:"text-muted-foreground w-6 h-6"})}),u.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Upcoming Deal Revenue"})]}),u.jsx("div",{className:"h-[400px]",children:u.jsx(kUe,{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:s.min,max:s.max},indexScale:{type:"band",round:!0},enableGridX:!0,enableGridY:!1,enableLabel:!1,tooltip:i(({value:o,indexValue:l})=>u.jsxs("div",{className:"p-2 bg-secondary rounded shadow inline-flex items-center gap-1 text-secondary-foreground",children:[u.jsxs("strong",{children:[l,": "]})," ",o>0?"+":"",o.toLocaleString(e.at(0)??BW,{style:"currency",currency:TUe})]}),"tooltip"),axisTop:{tickSize:0,tickPadding:12,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},axisBottom:{legendPosition:"middle",legendOffset:50,tickSize:0,tickPadding:12,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},axisLeft:null,axisRight:{format:i(o=>`${Math.abs(o/1e3)}k`,"format"),tickValues:8,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},markers:[{axis:"y",value:0,lineStyle:{strokeOpacity:0},textStyle:{fill:"#2ebca6"},legend:"Won",legendPosition:"top-left",legendOrientation:"vertical"},{axis:"y",value:0,lineStyle:{stroke:"#f47560",strokeWidth:1},textStyle:{fill:"#e25c3b"},legend:"Lost",legendPosition:"bottom-left",legendOrientation:"vertical"}]})})]})}),PUe=i(e=>{const t=xt(),n=Wt(e),{filterValues:r,setFilters:a}=Yw(e),s=Tc();if(!n)throw new Error("<ListNoResults> must be used inside a <List> component");return u.jsx("div",{className:"p-6",children:u.jsx("p",{className:"text-sm text-muted-foreground",children:r&&a&&Object.keys(r).length>0?u.jsxs(u.Fragment,{children:[t("ra.navigation.no_filtered_results",{resource:n,name:s(n,0),_:"No results found with the current filters."})," ",u.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:s(n,0),_:"No results found."})})})},"ListNoResults"),DUe=i(e=>{const{children:t,linkType:n,rowClick:r,style:a}=e,s=Wt(e),o=Ft(e),l=Ra(),f=typeof n=="function"||typeof r=="function",c=CK({link:f?!1:n??r,resource:s}),p=OK(),m=Ct(async()=>{if(!f||!o)return;const v=typeof n=="function"?n(o,o.id):typeof r=="function"?(w,S)=>r(w.id,S,w):!1,b=await p({record:o,resource:s,link:v});b===!1||b==null||l(b)});return o?f?u.jsx("li",{className:"w-full",children:u.jsx("button",{onClick:m,style:a,className:"w-full text-left hover:bg-muted focus: bg-muted focus:outline-none",children:t})}):c?u.jsx("li",{className:"w-full",children:u.jsx(nn,{to:c,style:a,className:"block w-full hover:bg-muted focus:bg-muted focus:outline-none",children:t})}):u.jsx("li",{className:"w-full",children:t}):null},"SimpleListItem"),AT=i(({className:e})=>u.jsx("span",{className:xe("bg-gray-300 flex",e),children:" "}),"ListPlaceholder"),MUe=i(e=>{const{className:t,hasLeftAvatarOrIcon:n,hasRightAvatarOrIcon:r,hasSecondaryText:a,hasTertiaryText:s,nbFakeLines:o=5,...l}=e;return rY(1e3)?u.jsx("ul",{className:t,...l,children:IUe(o,c=>u.jsxs("li",{className:"flex items-center space-x-3 p-3",children:[n&&u.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"mb-1",children:[u.jsx(AT,{className:"w-1/3 inline-block mb-1"}),s&&u.jsx("span",{className:"float-right opacity-55 min-w-[10vw]",children:u.jsx(AT,{})})]}),a&&u.jsx(AT,{className:"w-1/4"})]}),r&&u.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "})]},c))}):null},"SimpleListLoading"),IUe=i((e,t)=>Array.from({length:e},(n,r)=>t(r)),"times"),FUe=i(e=>{const{className:t,empty:n=$Ue,leftAvatar:r,leftIcon:a,linkType:s,rowClick:o,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,resource:v,...b}=e,{data:w,isPending:S,total:_}=Yw(e);return S===!0?u.jsx(MUe,{className:t,hasLeftAvatarOrIcon:!!a||!!r,hasRightAvatarOrIcon:!!c||!!f,hasSecondaryText:!!p,hasTertiaryText:!!m}):w==null||w.length===0||_===0?n||null:u.jsx("ul",{className:t,...Dme(b),children:u.jsx(Ume,{data:w,total:_,render:i((j,C)=>u.jsx(DUe,{rowIndex:C,linkType:s,rowClick:o,resource:v,children:u.jsx(LUe,{leftAvatar:r,leftIcon:a,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,rowIndex:C})},j.id),"render")})})},"SimpleList"),LUe=i(e=>{const{leftAvatar:t,leftIcon:n,primaryText:r,rightAvatar:a,rightIcon:s,secondaryText:o,tertiaryText:l}=e,f=Wt(e),c=Ft(e),p=Nc(f),m=xt(),v=i((b,w)=>{const S=w(b,b.id);return typeof S=="string"&&(S.startsWith("http")||S.startsWith("data:"))?u.jsx("img",{src:S,alt:"",className:"w-10 h-10 rounded-full object-cover"}):u.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-sm",children:S})},"renderAvatar");return c?u.jsxs("div",{className:"flex items-center space-x-3 p-3",children:[n&&u.jsx("div",{className:"flex-shrink-0",children:n(c,c.id)}),t&&u.jsx("div",{className:"flex-shrink-0",children:v(c,t)}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.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&&u.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)})]}),!!o&&u.jsx("div",{className:"text-sm text-muted-foreground truncate",children:typeof o=="string"?m(o,{...c,_:o}):y.isValidElement(o)?o:o(c,c.id)})]}),(a||s)&&u.jsxs("div",{className:"flex-shrink-0 flex items-center space-x-2",children:[a&&v(c,a),s&&s(c,c.id)]})]}):null},"SimpleListItemContent"),$Ue=u.jsx(PUe,{}),qUe=i(()=>{const{identity:e}=Yn(),{data:t,total:n,isPending:r}=pa("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 u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-center",children:[u.jsx("div",{className:"mr-3 flex",children:u.jsx(i4,{className:"text-muted-foreground w-6 h-6"})}),u.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Hot Contacts"}),u.jsx(Li,{children:u.jsxs(ds,{children:[u.jsx(fs,{asChild:!0,children:u.jsx(Le,{variant:"ghost",size:"sm",className:"ml-auto text-muted-foreground",asChild:!0,children:u.jsx(nn,{to:"/contacts/create",children:u.jsx(os,{className:"w-4 h-4 text-primary"})})})}),u.jsx(hs,{children:"Create contact"})]})})]}),u.jsx(un,{className:"py-0",children:u.jsx(FUe,{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=>u.jsxs(u.Fragment,{children:[a.title," at ",a.company_name]}),"secondaryText"),leftAvatar:i(a=>u.jsx(ho,{record:a}),"leftAvatar"),empty:u.jsxs("div",{className:"p-4",children:[u.jsx("p",{className:"text-sm mb-4",children:'Contacts with a "hot" status will appear here.'}),u.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"),UUe=i(()=>{const{identity:e}=Yn(),{total:t}=pa("tasks",{pagination:{page:1,perPage:1},filter:{sales_id:e?.id}},{enabled:!!e});return t?null:u.jsx("p",{className:"text-sm",children:"Tasks added to your contacts will appear here."})},"TasksListEmpty"),yg=i(({title:e,filter:t})=>{const{identity:n}=Yn(),{data:r,total:a,isPending:s}=pa("tasks",{pagination:{page:1,perPage:100},sort:{field:"due_date",order:"ASC"},filter:{...t,sales_id:n?.id}},{enabled:!!n}),o=Qw({data:r,isPending:s,resource:"tasks",perPage:5});return s||!r||!a?null:u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium mb-2",children:e}),u.jsx(bd,{value:"tasks",children:u.jsx(py,{value:o,children:u.jsx(Jne,{showContact:!0})})}),a>o.perPage&&u.jsx("div",{className:"flex justify-center",children:u.jsx("a",{href:"#",onClick:i(l=>{o.setPerPage(o.perPage+10),l.preventDefault()},"onClick"),className:"text-sm underline hover:no-underline",children:"Load more"})})]})},"TasksListFilter"),Sie=new Date,zUe=xbe(Sie),BUe=zUe<5,HW=_be().toISOString(),VW=b0e().toISOString(),WW=x0e().toISOString(),GW=y0e(Sie,{weekStartsOn:0}).toISOString(),bg={overdue:{"done_date@is":null,"due_date@lt":HW},today:{"done_date@is":null,"due_date@gte":HW,"due_date@lte":VW},tomorrow:{"done_date@is":null,"due_date@gt":VW,"due_date@lt":WW},thisWeek:{"done_date@is":null,"due_date@gte":WW,"due_date@lte":GW},later:{"done_date@is":null,"due_date@gt":GW}},HUe=i(()=>u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-center",children:[u.jsx("div",{className:"mr-3 flex",children:u.jsx(YQ,{className:"text-muted-foreground w-6 h-6"})}),u.jsx("h2",{className:"text-xl font-semibold text-muted-foreground flex-1",children:"Upcoming Tasks"}),u.jsx(Xne,{display:"icon",selectContact:!0})]}),u.jsx(un,{className:"p-4 mb-2",children:u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx(UUe,{}),u.jsx(yg,{title:"Overdue",filter:bg.overdue}),u.jsx(yg,{title:"Today",filter:bg.today}),u.jsx(yg,{title:"Tomorrow",filter:bg.tomorrow}),BUe&&u.jsx(yg,{title:"This week",filter:bg.thisWeek}),u.jsx(yg,{title:"Later",filter:bg.later})]})})]}),"TasksList"),VUe=i(()=>{const{data:e,total:t,isPending:n}=pa("contacts",{pagination:{page:1,perPage:1}}),{total:r,isPending:a}=pa("contactNotes",{pagination:{page:1,perPage:1}}),{total:s,isPending:o}=pa("deals",{pagination:{page:1,perPage:1}});return n||a||o?null:t?r?u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-6 mt-1",children:[u.jsx("div",{className:"md:col-span-3",children:u.jsxs("div",{className:"flex flex-col gap-4",children:[null,u.jsx(qUe,{})]})}),u.jsx("div",{className:"md:col-span-6",children:u.jsxs("div",{className:"flex flex-col gap-6",children:[s?u.jsx(NUe,{}):null,u.jsx(X6e,{})]})}),u.jsx("div",{className:"md:col-span-3",children:u.jsx(HUe,{})})]}):u.jsx(GH,{step:2,contactId:e?.[0]?.id}):u.jsx(GH,{step:1})},"Dashboard"),WUe=y.lazy(()=>Vp(()=>import("./DealList-BrMu9tSP.js"),[],import.meta.url)),GUe={list:WUe},KUe=y.createContext(void 0),dS=i(()=>y.useContext(KUe),"useUserMenu"),YUe=i(()=>{const{darkModeLogo:e,lightModeLogo:t,title:n}=la(),r=Ur(),s=[{path:"/",pattern:"/"},{path:"/contacts",pattern:"/contacts/*"},{path:"/companies",pattern:"/companies/*"},{path:"/deals",pattern:"/deals/*"},{path:"/tasks",pattern:"/tasks/*"}].find(o=>cp(o.pattern,r.pathname))?.path||!1;return u.jsx("header",{className:"bg-secondary fixed top-0 left-0 right-0 z-50 border-b border-border",children:u.jsx("div",{className:"px-4",children:u.jsxs("div",{className:"flex justify-between items-center flex-1",children:[u.jsx(QUe,{darkLogo:e,lightLogo:t,title:n}),u.jsxs("nav",{className:"flex","aria-label":"Main navigation",children:[u.jsx(xg,{label:"Dashboard",to:"/",isActive:s==="/"}),u.jsx(xg,{label:"Contacts",to:"/contacts",isActive:s==="/contacts"}),u.jsx(xg,{label:"Companies",to:"/companies",isActive:s==="/companies"}),u.jsx(xg,{label:"Deals",to:"/deals",isActive:s==="/deals"}),u.jsx(xg,{label:"Tasks",to:"/tasks",isActive:s==="/tasks"})]}),u.jsxs("div",{className:"flex items-center",children:[u.jsx(rJ,{}),u.jsx(aJ,{}),u.jsxs(eJ,{children:[u.jsx(ZUe,{}),u.jsx(JUe,{}),u.jsx(eze,{}),u.jsx(aye,{resource:"sales",action:"list",children:u.jsx(XUe,{})}),u.jsx(hv,{}),u.jsx(T4,{className:"font-normal",children:u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Version ","0.14.0"]})})]})]})]})})})},"Header"),QUe=i(({darkLogo:e,lightLogo:t,title:n})=>u.jsxs(nn,{to:"/",className:"flex items-center gap-2 text-secondary-foreground no-underline hover:opacity-80 transition-opacity",children:[u.jsx("img",{className:"[.light_&]:hidden h-6",src:e,alt:`${n} logo`}),u.jsx("img",{className:"[.dark_&]:hidden h-6",src:t,alt:`${n} logo`}),u.jsx("h1",{className:"text-xl font-semibold",children:n})]}),"Logo"),xg=i(({label:e,to:t,isActive:n})=>u.jsx(nn,{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"),XUe=i(()=>{const{onClose:e}=dS()??{};return u.jsx(sr,{asChild:!0,onClick:e,children:u.jsxs(nn,{to:"/sales",className:"flex items-center gap-2",children:[u.jsx(JQ,{className:"h-4 w-4"}),"Users"]})})},"UsersMenu"),ZUe=i(()=>{const{onClose:e}=dS()??{};return u.jsx(sr,{asChild:!0,onClick:e,children:u.jsxs(nn,{to:"/settings",className:"flex items-center gap-2",children:[u.jsx(RN,{className:"h-4 w-4"}),"My info"]})})},"ConfigurationMenu"),JUe=i(()=>{const{onClose:e}=dS()??{};return u.jsx(sr,{asChild:!0,onClick:e,children:u.jsxs(nn,{to:"/database",className:"flex items-center gap-2",children:[u.jsx(ov,{className:"h-4 w-4"}),"Database"]})})},"DatabaseMenu"),eze=i(()=>{const{onClose:e}=dS()??{};return u.jsx(sr,{asChild:!0,onClick:e,children:u.jsxs(nn,{to:"/integrations",className:"flex items-center gap-2",children:[u.jsx(L_e,{className:"h-4 w-4"}),"Integrations"]})})},"IntegrationsMenu"),tze=i(({children:e})=>u.jsxs(u.Fragment,{children:[u.jsx(YUe,{}),u.jsx("main",{className:"max-w-screen-xl mx-auto pt-20 px-4",id:"main-content",children:u.jsx(_x,{FallbackComponent:cJ,children:u.jsx(y.Suspense,{fallback:u.jsx(cn,{className:"h-12 w-12 rounded-full"}),children:e})})}),u.jsx(U1,{})]}),"Layout"),jie=i(()=>u.jsx("div",{className:"max-w-screen-xl mx-auto h-screen pt-8",children:u.jsx("div",{className:"h-full",children:u.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-8",children:[u.jsx(cn,{className:"w-full h-[100px]"}),u.jsx(cn,{className:"w-4/5 h-[50px]"}),u.jsx(cn,{className:"w-full h-9"}),u.jsx(cn,{className:"w-full h-9"}),u.jsx(cn,{className:"w-full h-9"}),u.jsx(cn,{className:"w-2/5 h-9"})]})})}),"LoginSkeleton"),xD=i(()=>{const e=Dn(),t=wn(),{darkModeLogo:n,title:r}=la(),{data:a,isPending:s}=ea({queryKey:["init"],queryFn:i(async()=>t.isInitialized(),"queryFn")}),{isPending:o,mutate:l}=qr({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=HY(),c=Ht(),{register:p,handleSubmit:m,formState:{isValid:v}}=vy({mode:"onChange"});if(s)return u.jsx(jie,{});if(a)return u.jsx(kw,{to:"/login"});const b=i(async w=>{l(w)},"onSubmit");return u.jsxs("div",{className:"h-screen p-8",children:[u.jsxs("div",{className:"flex items-center gap-4",children:[u.jsx("img",{src:n,alt:r,width:24,className:"filter brightness-0 invert"}),u.jsx("h1",{className:"text-xl font-semibold",children:r})]}),u.jsx("div",{className:"h-full",children:u.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-4",children:[u.jsx("h1",{className:"text-2xl font-bold mb-4",children:"Welcome to CRM"}),u.jsx("p",{className:"text-base mb-4",children:"Create the first user account to complete the setup."}),u.jsxs("form",{onSubmit:m(b),className:"space-y-4",children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx(Gn,{htmlFor:"first_name",children:"First name"}),u.jsx(Er,{...p("first_name",{required:!0}),id:"first_name",type:"text",required:!0})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx(Gn,{htmlFor:"last_name",children:"Last name"}),u.jsx(Er,{...p("last_name",{required:!0}),id:"last_name",type:"text",required:!0})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx(Gn,{htmlFor:"email",children:"Email"}),u.jsx(Er,{...p("email",{required:!0}),id:"email",type:"email",required:!0})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx(Gn,{htmlFor:"password",children:"Password"}),u.jsx(Er,{...p("password",{required:!0}),id:"password",type:"password",required:!0})]}),u.jsx("div",{className:"flex justify-between items-center mt-8",children:u.jsx(Le,{type:"submit",disabled:!v||o,className:"w-full",children:o?u.jsxs(u.Fragment,{children:[u.jsx(Dc,{className:"w-4 h-4 animate-spin mr-2"}),"Creating..."]}):"Create account"})})]})]})})]})},"SignupPage");xD.path="/sign-up";const nze=i((e,t)=>e==="admin"?!0:t.resource!=="sales","canAccess"),TT=PAe(qn,{getIdentity:i(async()=>{const e=await Cie();if(e==null)throw new Error;return{id:e.id,fullName:`${e.first_name} ${e.last_name}`,avatar:e.avatar?.src}},"getIdentity")});async function Jo(){if(Jo._is_initialized_cache==null){const{data:e}=await qn.from("init_state").select("is_initialized");Jo._is_initialized_cache=e?.at(0)?.is_initialized>0}return Jo._is_initialized_cache}i(Jo,"getIsInitialized");(e=>{e._is_initialized_cache=null})(Jo||(Jo={}));const rze={...TT,login:i(async e=>{const t=await TT.login(e);return Yb=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 Jo())throw await qn.auth.signOut(),{redirectTo:"/sign-up",message:!1};return TT.checkAuth(e)},"checkAuth"),canAccess:i(async e=>{if(!await Jo())return!1;const n=await Cie();if(n==null)return!1;const r=n.administrator?"admin":"user";return nze(r,e)},"canAccess")};let Yb;const Cie=i(async()=>{if(Yb!=null)return Yb;const{data:e,error:t}=await qn.auth.getSession();if(e?.session?.user==null||t)return;const{data:n,error:r}=await qn.from("sales").select("id, first_name, last_name, avatar, administrator").match({user_id:e?.session?.user.id}).single();if(!(n==null||r))return Yb=n,n},"getSaleFromCache");async function aze(e,t,n){const r={};t&&(r.id=t);const a={};t&&(a.company_id=t);const[s,o,l,f]=await Promise.all([ize(e,r),sze(e,a),oze(e,a),lze(e,a)]);return[...s,...o,...l,...f].sort((c,p)=>c.date&&p.date?c.date.localeCompare(p.date)*-1:0).slice(0,250)}i(aze,"getActivityLog");const ize=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 sze(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"}}),s=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})),o=a.map(l=>({id:`contactNote.${l.id}.created`,type:Jte,sales_id:l.sales_id,contactNote:l,date:l.date}));return[...s,...o]}i(sze,"getNewContactsAndNotes");async function oze(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"}}),s=n.map(l=>({id:`deal.${l.id}.created`,type:ene,company_id:l.company_id,sales_id:l.sales_id,deal:l,date:l.created_at})),o=a.map(l=>({id:`dealNote.${l.id}.created`,type:tne,sales_id:l.sales_id,dealNote:l,date:l.date}));return[...s,...o]}i(oze,"getNewDealsAndNotes");async function lze(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(s=>({id:`companyNote.${s.id}.created`,type:Xte,sales_id:s.sales_id,companyNote:s,date:s.date}))}i(lze,"getNewCompanyNotes");async function cze(e){return e.website?{src:`https://favicon.show/${e.website.replace(/^https?:\/\//,"").replace(/\/$/,"")}`,title:"Company favicon"}:null}i(cze,"getCompanyAvatar");async function uze(e,t={}){const{timeout:n=2e3}=t,r=new AbortController,a=setTimeout(()=>r.abort(),n),s=await fetch(e,{...t,signal:r.signal});return clearTimeout(a),s}i(uze,"fetchWithTimeout");const dze=["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 fze(e){const t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(s=>s.toString(16).padStart(2,"0")).join("")}i(fze,"hash");async function hze(e){return`https://www.gravatar.com/avatar/${await fze(e)}?d=404`}i(hze,"getGravatarUrl");async function pze(e){if(dze.includes(e))return null;try{const t=`https://${e}/favicon.ico`;if((await uze(t)).ok)return t}catch{return null}return null}i(pze,"getFaviconUrl");async function mze(e){if(!e.email_jsonb||!e.email_jsonb.length)return null;for(const{email:t}of e.email_jsonb){const n=await hze(t);try{if((await fetch(n)).ok)return n}catch{}const r=t.split("@")[1],a=await pze(r);if(a)return a}return null}i(mze,"getContactAvatar");const KW=Ed()||{url:"https://placeholder.supabase.co",anonKey:"placeholder-key"},Fa=XAe({instanceUrl:KW.url,apiKey:KW.anonKey,supabaseClient:qn,sortOrder:"asc,desc.nullslast"}),YW=i(async e=>{let t=e.data.logo;return typeof t!="object"||t===null||!t.src?t=await cze(e.data):t.rawFile instanceof File&&await Qb(t),{...e,data:{...e.data,logo:t}}},"processCompanyLogo");async function QW(e){const{data:t}=e;if(t.avatar?.src||!t.email_jsonb||!t.email_jsonb.length)return e;const n=await mze(t),r={...t,avatar:{src:n||void 0}};return{...e,data:r}}i(QW,"processContactAvatar");const gze={...Fa,async getList(e,t){return e==="companies"?Fa.getList("companies_summary",t):e==="contacts"?Fa.getList("contacts_summary",t):e==="tasks"?Fa.getList("tasks_summary",t):Fa.getList(e,t)},async getOne(e,t){return e==="companies"?Fa.getOne("companies_summary",t):e==="contacts"?Fa.getOne("contacts_summary",t):e==="tasks"?Fa.getOne("tasks_summary",t):Fa.getOne(e,t)},async update(e,t){if(e==="tasks"){const{contact_first_name:n,contact_last_name:r,contact_email:a,company_id:s,company_name:o,assigned_first_name:l,assigned_last_name:f,creator_first_name:c,creator_last_name:p,nb_notes:m,last_note_date:v,...b}=t.data;return Fa.update(e,{...t,data:b})}return Fa.update(e,t)},async signUp({email:e,password:t,first_name:n,last_name:r}){const{data:a,error:s}=await qn.functions.invoke("setup",{method:"POST",body:{email:e,password:t,first_name:n,last_name:r}});if(!a||s)throw console.error("signUp.error",s),new Error("Failed to create account");return Jo._is_initialized_cache=!0,{id:a.data.id,email:e,password:t}},async salesCreate(e){const{data:t,error:n}=await qn.functions.invoke("users",{method:"POST",body:e});if(!t||n)throw console.error("salesCreate.error",n),new Error("Failed to create account manager");return t},async salesUpdate(e,t){const{email:n,first_name:r,last_name:a,administrator:s,avatar:o,disabled:l}=t,{data:f,error:c}=await qn.functions.invoke("users",{method:"PATCH",body:{sales_id:e,email:n,first_name:r,last_name:a,administrator:s,disabled:l,avatar:o}});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 qn.functions.invoke("users",{method:"PUT",body:{sales_id:e,action:"invite"}});if(!t||n)throw console.error("resendInvite.error",n),new Error("Failed to resend invitation");return t},async resetPassword(e){const{data:t,error:n}=await qn.functions.invoke("users",{method:"PUT",body:{sales_id:e,action:"reset"}});if(!t||n)throw console.error("resetPassword.error",n),new Error("Failed to send password reset");return t},async updatePassword(e){const{data:t,error:n}=await qn.functions.invoke("updatePassword",{method:"PATCH",body:{sales_id:e}});if(!t||n)throw console.error("passwordUpdate.error",n),new Error("Failed to update password");return t},async unarchiveDeal(e){const{data:t}=await Fa.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=>Fa.update("deals",{id:r.id,data:r,previousData:t.find(a=>a.id===r.id)})))},async getActivityLog(e){return aze(Fa,e)},async isInitialized(){return Jo()},async mergeContacts(e,t){const{data:n,error:r}=await qn.functions.invoke("mergeContacts",{method:"POST",body:{loserId:e,winnerId:t}});if(r)throw console.error("mergeContacts.error",r),new Error("Failed to merge contacts");return n},async mergeCompanies(e,t){const{data:n,error:r}=await qn.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}},vze=Bhe(gze,[{resource:"contactNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await Qb(r);return e},"beforeSave")},{resource:"dealNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await Qb(r);return e},"beforeSave")},{resource:"sales",beforeSave:i(async(e,t,n)=>(e.avatar&&await Qb(e.avatar),e),"beforeSave")},{resource:"contacts",beforeCreate:i(async e=>QW(e),"beforeCreate"),beforeUpdate:i(async e=>QW(e),"beforeUpdate"),beforeGetList:i(async e=>wg(["first_name","last_name","company_name","title","email","phone","background"])(e),"beforeGetList")},{resource:"companies",beforeGetList:i(async e=>wg(["name","phone_number","website","zipcode","city","stateAbbr"])(e),"beforeGetList"),beforeCreate:i(async e=>{const t=await YW(e);return{...t,data:{...t.data,created_at:new Date().toISOString()}}},"beforeCreate"),beforeUpdate:i(async e=>await YW(e),"beforeUpdate")},{resource:"contacts_summary",beforeGetList:i(async e=>wg(["first_name","last_name"])(e),"beforeGetList")},{resource:"tasks",beforeGetList:i(async e=>wg(["text","contact_first_name"])(e),"beforeGetList")},{resource:"deals",beforeGetList:i(async e=>wg(["name","type","description"])(e),"beforeGetList")}]),wg=i(e=>t=>{if(!t.filter?.q)return t;const{q:n,...r}=t.filter;return{...t,filter:{...r,"@or":e.reduce((a,s)=>s==="email"?{...a,"email_fts@ilike":n}:s==="phone"?{...a,"phone_fts@ilike":n}:{...a,[`${s}@ilike`]:n},{})}}},"applyFullTextSearch"),Qb=i(async e=>{if(!e.src.startsWith("blob:")&&!e.src.startsWith("data:")&&e.path){const{error:c}=await qn.storage.from("attachments").createSignedUrl(e.path,60);if(!c)return}const t=e.src?await fetch(e.src).then(c=>c.blob()):e.rawFile,n=e.rawFile,r=n.name.split(".").pop(),s=`${`${Math.random()}.${r}`}`,{error:o}=await qn.storage.from("attachments").upload(s,t);if(o)throw console.error("uploadError",o),new Error("Failed to upload attachment");const{data:l}=qn.storage.from("attachments").getPublicUrl(s);e.path=s,e.src=l.publicUrl;const f=n.type;return e.type=f,e},"uploadToBucket");function Eie(){const{identity:e}=Yn(),t=Ft();return u.jsxs("div",{className:"space-y-4 w-full",children:[u.jsx(Ut,{source:"first_name",validate:Pn(),helperText:!1}),u.jsx(Ut,{source:"last_name",validate:Pn(),helperText:!1}),u.jsx(Ut,{source:"email",validate:[Pn(),EY()],helperText:!1}),u.jsx(ew,{source:"administrator",readOnly:t?.id===e?.id,helperText:!1}),u.jsx(ew,{source:"disabled",readOnly:t?.id===e?.id,helperText:!1})]})}i(Eie,"SalesInputs");function yze(){const e=wn(),t=Ht(),n=zi(),{mutate:r}=qr({mutationKey:["signup"],mutationFn:i(async s=>e.salesCreate(s),"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 s=>{r(s)},"onSubmit");return u.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:u.jsxs(un,{children:[u.jsx(ms,{children:u.jsx(gs,{children:"Create a new user"})}),u.jsx(Un,{children:u.jsx(zee,{onSubmit:a,children:u.jsx(Eie,{})})})]})})}i(yze,"SalesCreate");function bze(){return u.jsxs("div",{className:"flex justify-end gap-4",children:[u.jsx(t_,{}),u.jsx(jd,{})]})}i(bze,"EditToolbar");function xze(){const{record:e}=JK(),t=wn(),n=Ht(),r=zi(),{mutate:a}=qr({mutationKey:["signup"],mutationFn:i(async o=>{if(!e)throw new Error("Record not found");return t.salesUpdate(e.id,o)},"mutationFn"),onSuccess:i(()=>{r("/sales"),n("User updated successfully")},"onSuccess"),onError:i(()=>{n("An error occurred. Please try again.")},"onError")}),s=i(async o=>{a(o)},"onSubmit");return u.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:u.jsx(un,{children:u.jsx(Un,{children:u.jsxs(zee,{toolbar:u.jsx(bze,{}),onSubmit:s,record:e,children:[u.jsx(wze,{}),u.jsx(Eie,{})]})})})})}i(xze,"SalesEdit");const wze=i(()=>{const e=Ft();return e?u.jsxs("h2",{className:"text-lg font-semibold mb-4",children:["Edit ",e?.first_name," ",e?.last_name]}):null},"SaleEditTitle"),_ze=i(()=>u.jsxs(X1,{children:[u.jsx(Ly,{}),u.jsx(dl,{label:"New user"})]}),"SalesListActions"),Sze=[u.jsx(e_,{source:"q",alwaysOn:!0})],jze=i(e=>{const t=Ft();return t?u.jsxs("div",{className:"flex flex-row gap-1",children:[t.administrator&&u.jsx(Kn,{variant:"outline",className:"border-blue-300 dark:border-blue-700",children:"Admin"}),t.disabled&&u.jsx(Kn,{variant:"outline",className:"border-orange-300 dark:border-orange-700",children:"Disabled"})]}):null},"OptionsField"),Cze=i(()=>{const e=Ft(),t=wn(),n=Ht(),r=Bw(),[a,s]=y.useState(!1),[o,l]=y.useState(!1),{mutate:f,isPending:c}=qr({mutationFn:i(async()=>t.resendInvite(e.id),"mutationFn"),onSuccess:i(()=>{n("Invitation email resent successfully"),s(!1),r()},"onSuccess"),onError:i(()=>{n("Failed to resend invitation email",{type:"error"}),s(!1)},"onError")}),{mutate:p,isPending:m}=qr({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:o}),u.jsxs(u.Fragment,{children:[u.jsxs(Fc,{children:[u.jsx(rl,{asChild:!0,children:u.jsxs(Le,{variant:"ghost",className:"h-8 w-8 p-0",children:[u.jsx("span",{className:"sr-only",children:"Open menu"}),u.jsx(XM,{className:"h-4 w-4"})]})}),u.jsxs(Lc,{align:"end",children:[u.jsx(T4,{children:"Email Actions"}),u.jsx(hv,{}),!v&&u.jsxs(sr,{onClick:i(w=>{w.preventDefault(),w.stopPropagation(),console.log("[Menu] Clicked Resend Invite"),s(!0)},"onClick"),children:[u.jsx(r_e,{className:"mr-2 h-4 w-4"}),"Resend Invite"]}),v&&!b&&u.jsxs(sr,{onClick:i(()=>l(!0),"onClick"),children:[u.jsx(j1e,{className:"mr-2 h-4 w-4"}),"Send Password Reset"]})]})]}),u.jsx(ga,{open:a,onOpenChange:s,children:u.jsxs(va,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Resend Invitation"}),u.jsxs(ui,{children:["Send a new invitation email to ",u.jsx("strong",{children:e.email}),"?",u.jsx("br",{}),u.jsx("br",{}),"This will send them a fresh invitation link to set up their account."]})]}),u.jsxs(ps,{children:[u.jsx(Le,{variant:"outline",onClick:i(w=>{w.stopPropagation(),s(!1)},"onClick"),disabled:c,children:"Cancel"}),u.jsx(Le,{onClick:i(w=>{w.stopPropagation(),f()},"onClick"),disabled:c,children:c?"Sending...":"Send Invitation"})]})]})}),u.jsx(ga,{open:o,onOpenChange:l,children:u.jsxs(va,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Send Password Reset"}),u.jsxs(ui,{children:["Send a password reset email to ",u.jsx("strong",{children:e.email}),"?",u.jsx("br",{}),u.jsx("br",{}),"This will send them a link to reset their password."]})]}),u.jsxs(ps,{children:[u.jsx(Le,{variant:"outline",onClick:i(w=>{w.stopPropagation(),l(!1)},"onClick"),disabled:m,children:"Cancel"}),u.jsx(Le,{onClick:i(w=>{w.stopPropagation(),p()},"onClick"),disabled:m,children:m?"Sending...":"Send Reset Link"})]})]})})]})},"RowActions");function Eze(){return u.jsx(Q1,{filters:Sze,actions:u.jsx(_ze,{}),sort:{field:"first_name",order:"ASC"},children:u.jsx(kze,{})})}i(Eze,"SalesList");const kze=i(()=>{const{data:e,isPending:t,filterValues:n}=Xn(),{identity:r}=Yn(),a=n&&Object.keys(n).length>0;return!r||t?u.jsx(un,{className:"p-4",children:u.jsxs("div",{className:"space-y-3",children:[u.jsx(cn,{className:"h-12 w-full"}),u.jsx(cn,{className:"h-12 w-full"}),u.jsx(cn,{className:"h-12 w-full"}),u.jsx(cn,{className:"h-12 w-full"}),u.jsx(cn,{className:"h-12 w-full"})]})}):!e?.length&&!a?u.jsx(Oze,{}):u.jsxs(sa,{children:[u.jsx(sa.Col,{source:"first_name"}),u.jsx(sa.Col,{source:"last_name"}),u.jsx(sa.Col,{source:"email"}),u.jsx(sa.Col,{label:!1,children:u.jsx(jze,{})}),u.jsx(sa.Col,{label:!1,children:u.jsx(Cze,{})})]})},"SalesListLayout"),Oze=i(()=>{const e=Z1();return u.jsxs("div",{className:"flex flex-col justify-center items-center gap-3",style:{height:`calc(100dvh - ${e}px)`},children:[u.jsx("img",{src:"./img/empty.svg",alt:"No users found"}),u.jsxs("div",{className:"flex flex-col gap-0 items-center",children:[u.jsx("h6",{className:"text-lg font-bold",children:"No users found"}),u.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"It seems your user list is empty."})]}),u.jsx("div",{className:"flex flex-row gap-2",children:u.jsx(dl,{label:"New user"})})]})},"SalesEmpty"),Rze={list:Eze,create:yze,edit:xze,recordRepresentation:i(e=>`${e.first_name} ${e.last_name}`,"recordRepresentation")};function XW(e){const t=e.trim();return t?t.startsWith("http://")||t.startsWith("https://")?t:`https://${t}.supabase.co`:""}i(XW,"normalizeSupabaseUrl");function Aze(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(Aze,"validateUrlFormat");function Tze(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(Tze,"validateKeyFormat");function kie({open:e,onComplete:t,canClose:n=!1}){const[r,a]=y.useState("welcome"),[s,o]=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=XW(s),R=l.trim(),A=await RAe(T,R);A.valid?(EAe({url:T,anonKey:R}),a("success"),setTimeout(()=>{window.location.href=window.location.origin},1500)):(p(A.error||"Connection failed"),a("credentials"))},"handleValidateAndSave"),_=s?Aze(s):{valid:!1},j=l?Tze(l):{valid:!1},C=s?XW(s):"",k=s&&!s.startsWith("http")&&_.valid,E=i(()=>{n&&t()},"handleClose");return u.jsx(ga,{open:e,onOpenChange:n?E:void 0,children:u.jsxs(va,{className:"sm:max-w-md",onPointerDownOutside:i(T=>!n&&T.preventDefault(),"onPointerDownOutside"),onEscapeKeyDown:i(T=>!n&&T.preventDefault(),"onEscapeKeyDown"),children:[r==="welcome"&&u.jsxs(u.Fragment,{children:[u.jsxs(Fr,{children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(ov,{className:"h-6 w-6 text-primary"}),u.jsx(Lr,{children:"Welcome to CRM"})]}),u.jsx(ui,{children:"To get started, you'll need to connect to a Supabase database."})]}),u.jsxs("div",{className:"space-y-4 py-4",children:[u.jsx(Ga,{children:u.jsxs(di,{children:[u.jsx("strong",{children:"Don't have a Supabase project?"}),u.jsx("br",{}),"Create one for free at"," ",u.jsxs("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline text-primary inline-flex items-center gap-1",children:["supabase.com",u.jsx(Wl,{className:"h-3 w-3"})]})]})}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("h4",{className:"font-medium text-sm",children:"What you'll need:"}),u.jsxs("ul",{className:"list-disc list-inside text-sm text-muted-foreground space-y-1",children:[u.jsx("li",{children:"Your Supabase project URL or project ID"}),u.jsx("li",{children:"Your API key (anon or publishable key)"})]})]}),u.jsx("div",{className:"space-y-2",children:u.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?",u.jsx(Wl,{className:"h-3 w-3"})]})}),u.jsx(Le,{onClick:i(()=>a("credentials"),"onClick"),className:"w-full",children:"Continue"})]})]}),r==="credentials"&&u.jsxs(u.Fragment,{children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Connect to Supabase"}),u.jsx(ui,{children:"Enter your Supabase project credentials"})]}),u.jsxs("div",{className:"space-y-4 py-4",children:[c&&u.jsxs(Ga,{variant:"destructive",children:[u.jsx(Lp,{className:"h-4 w-4"}),u.jsx(di,{children:c})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"supabase-url",children:"Project URL or ID"}),u.jsxs("div",{className:"relative",children:[u.jsx(Er,{id:"supabase-url",placeholder:"xxxxx or https://xxxxx.supabase.co",value:s,onChange:i(T=>{o(T.target.value),v(!0)},"onChange"),onBlur:i(()=>v(!0),"onBlur"),className:m&&s?_.valid?"pr-8 border-green-500":"pr-8 border-destructive":""}),m&&s&&_.valid&&u.jsx(ss,{className:"absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 text-green-500"})]}),k&&u.jsxs("div",{className:"flex items-start gap-1.5 text-xs text-green-600 dark:text-green-400",children:[u.jsx(ss,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),u.jsxs("span",{children:["Will expand to: ",C]})]}),m&&s&&_.message&&!_.valid&&u.jsx("p",{className:"text-xs text-destructive",children:_.message}),(!m||!s)&&u.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter full URL or just the project ID (from Project Settings → API)"})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"anon-key",children:"API Key"}),u.jsxs("div",{className:"relative",children:[u.jsx(Er,{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&&u.jsx(ss,{className:"absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 text-green-500"})]}),b&&l&&j.message&&u.jsx("p",{className:`text-xs ${j.valid?"text-green-600 dark:text-green-400":"text-destructive"}`,children:j.message}),(!b||!l)&&u.jsx("p",{className:"text-xs text-muted-foreground",children:"Anon or publishable key (from Project Settings → API)"})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Le,{variant:"outline",onClick:i(()=>a("welcome"),"onClick"),className:"flex-1",children:"Back"}),u.jsx(Le,{onClick:S,disabled:!_.valid||!j.valid,className:"flex-1",children:"Connect"})]})]})]}),r==="validating"&&u.jsxs(u.Fragment,{children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Validating Connection"}),u.jsx(ui,{children:"Testing your Supabase credentials..."})]}),u.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[u.jsx(Dc,{className:"h-12 w-12 animate-spin text-primary mb-4"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait..."})]})]}),r==="success"&&u.jsxs(u.Fragment,{children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Connection Successful!"}),u.jsx(ui,{children:"Your Supabase database is now connected"})]}),u.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[u.jsx(Vs,{className:"h-12 w-12 text-green-500 mb-4"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Reloading application..."})]})]})]})})}i(kie,"SupabaseSetupWizard");function Nze(){const[e,t]=y.useState(!1),n=Ed(),r=AAe(),a=i(()=>{confirm("Are you sure you want to clear the database configuration? The app will need to be reconfigured on next launch.")&&(kAe(),window.location.reload())},"handleClearConfig");return u.jsxs(u.Fragment,{children:[u.jsxs(un,{children:[u.jsxs(ms,{children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ov,{className:"h-5 w-5"}),u.jsx(gs,{children:"Database Connection"})]}),u.jsx(V4,{children:"Manage your Supabase database connection settings"})]}),u.jsx(Un,{className:"space-y-4",children:n?u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex items-start gap-3 p-4 border rounded-lg",children:[u.jsx(Vs,{className:"h-5 w-5 text-green-500 mt-0.5"}),u.jsxs("div",{className:"flex-1 space-y-1",children:[u.jsx("p",{className:"font-medium",children:"Connected"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:n.url}),n.configuredAt&&u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Configured on"," ",new Date(n.configuredAt).toLocaleDateString()]})]})]}),r==="env"&&u.jsxs(Ga,{children:[u.jsx(RN,{className:"h-4 w-4"}),u.jsx(di,{children:"Using configuration from environment variables. You can override this by setting up a new connection via the UI."})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsxs(Le,{variant:"outline",onClick:i(()=>t(!0),"onClick"),className:"flex-1",children:[u.jsx(RN,{className:"h-4 w-4 mr-2"}),"Change Connection"]}),r==="ui"&&u.jsxs(Le,{variant:"destructive",onClick:a,className:"flex-1",children:[u.jsx(wy,{className:"h-4 w-4 mr-2"}),"Clear Configuration"]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Pze,{className:"text-sm font-medium",children:"Anonymous Key"}),u.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)]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex items-start gap-3 p-4 border border-dashed rounded-lg",children:[u.jsx(uo,{className:"h-5 w-5 text-destructive mt-0.5"}),u.jsxs("div",{className:"flex-1 space-y-1",children:[u.jsx("p",{className:"font-medium",children:"Not Connected"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"No Supabase database is configured"})]})]}),u.jsx(Ga,{children:u.jsxs(di,{children:["Connect to a Supabase database to start using Atomic CRM. You can create a free project at"," ",u.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"supabase.com"})]})}),u.jsxs(Le,{onClick:i(()=>t(!0),"onClick"),className:"w-full",children:[u.jsx(ov,{className:"h-4 w-4 mr-2"}),"Connect to Supabase"]})]})})]}),u.jsx(kie,{open:e,onComplete:i(()=>t(!1),"onComplete"),canClose:!0})]})}i(Nze,"DatabaseSettings");function Pze({children:e,className:t}){return u.jsx("label",{className:t,children:e})}i(Pze,"Label");const wD=i(()=>u.jsx("div",{className:"max-w-lg mx-auto mt-8",children:u.jsx(Nze,{})}),"DatabasePage");wD.path="/database";const _D=i(()=>{const[e,t]=y.useState(!1),{identity:n,refetch:r}=Yn(),{data:a,refetch:s}=Hw("sales",{id:n?.id}),o=Ht(),l=wn(),{mutate:f}=qr({mutationKey:["signup"],mutationFn:i(async p=>{if(!n)throw new Error("Record not found");return l.salesUpdate(n.id,p)},"mutationFn"),onSuccess:i(()=>{r(),s(),t(!1),o("Your profile has been updated")},"onSuccess"),onError:i(p=>{o("An error occurred. Please try again",{type:"error"})},"onError")});if(!n)return null;const c=i(async p=>{f(p)},"handleOnSubmit");return u.jsx("div",{className:"max-w-lg mx-auto mt-8",children:u.jsx(zr,{onSubmit:c,record:a,children:u.jsx(Dze,{isEditMode:e,setEditMode:t})})})},"SettingsPage"),Dze=i(({isEditMode:e,setEditMode:t})=>{const n=Ht(),r=Ra(),a=Ft(),{identity:s,refetch:o}=Yn(),{isDirty:l}=gy(),f=wn(),{mutate:c}=qr({mutationKey:["signup"],mutationFn:i(async v=>{if(!a)throw new Error("Record not found");return f.salesUpdate(a.id,v)},"mutationFn"),onSuccess:i(()=>{o(),n("Your profile has been updated")},"onSuccess"),onError:i(()=>{n("An error occurred. Please try again.")},"onError")});if(!s)return null;const p=i(()=>{r("/change-password")},"handleClickOpenPasswordChange"),m=i(async v=>{c(v)},"handleAvatarUpdate");return u.jsxs("div",{className:"space-y-4",children:[u.jsx(un,{children:u.jsxs(Un,{children:[u.jsx("div",{className:"mb-4 flex flex-row justify-between",children:u.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"My info"})}),u.jsxs("div",{className:"space-y-4 mb-4",children:[u.jsx(Dte,{source:"avatar",type:"avatar",onSave:m,linkPosition:"right"}),u.jsx(NT,{source:"first_name",isEditMode:e}),u.jsx(NT,{source:"last_name",isEditMode:e}),u.jsx(NT,{source:"email",isEditMode:e})]}),u.jsxs("div",{className:"flex flex-row justify-end gap-2",children:[!e&&u.jsx(u.Fragment,{children:u.jsx(Le,{variant:"outline",type:"button",onClick:p,children:"Change password"})}),u.jsxs(Le,{type:"button",variant:e?"ghost":"outline",onClick:i(()=>t(!e),"onClick"),className:"flex items-center",children:[e?u.jsx(uo,{}):u.jsx(t4,{}),e?"Cancel":"Edit"]}),e&&u.jsxs(Le,{type:"submit",disabled:!l,variant:"outline",children:[u.jsx(v1,{}),"Save"]})]})]})}),void 0]})},"SettingsForm"),NT=i(({source:e,isEditMode:t})=>t?u.jsx(Ut,{source:e,helperText:!1}):u.jsx("div",{className:"m-2",children:u.jsx(u6e,{source:e})}),"TextRender");_D.path="/settings";function Oie(){const e=new Uint8Array(16);return crypto.getRandomValues(e),`ak_live_${Array.from(e).map(n=>n.toString(16).padStart(2,"0")).join("")}`}i(Oie,"generateApiKey");async function Mze(e){const n=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(r)).map(s=>s.toString(16).padStart(2,"0")).join("")}i(Mze,"hashApiKey");const Ize=[{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"}],Fze=i(({open:e,onClose:t})=>{const[n,r]=y.useState(null),[a,s]=y.useState(!1),o=wn(),l=Ht(),f=Dn(),{identity:c}=Yn(),{register:p,handleSubmit:m,watch:v,setValue:b,reset:w}=vy({defaultValues:{name:"",scopes:[],expires_at:""}}),S=qr({mutationFn:i(async k=>{const E=Oie(),T=await Mze(E),R=E.substring(0,12),{data:A}=await o.create("api_keys",{data:{name:k.name,key_hash:T,key_prefix:R,scopes:k.scopes,is_active:!0,expires_at:k.expires_at||null,sales_id:c?.id,created_by_sales_id:c?.id}});return{data:A,apiKey:E}},"mutationFn"),onSuccess:i(({apiKey:k})=>{r(k),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),s(!1),w(),t()},"handleClose"),j=i(()=>{n&&(navigator.clipboard.writeText(n),s(!0),setTimeout(()=>s(!1),2e3))},"copyApiKey"),C=i(k=>{const E=v("scopes");E.includes(k)?b("scopes",E.filter(T=>T!==k)):b("scopes",[...E,k])},"toggleScope");return u.jsx(ga,{open:e,onOpenChange:_,children:u.jsxs(va,{className:"sm:max-w-[500px]",children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:n?"API Key Created":"Create API Key"}),u.jsx(ui,{children:n?"Copy this key now - it won't be shown again!":"Create a new API key to access the CRM API"})]}),n?u.jsxs("div",{className:"space-y-4",children:[u.jsx(Ga,{children:u.jsx(di,{children:"Make sure to copy your API key now. You won't be able to see it again!"})}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{children:"Your API Key"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Er,{value:n,readOnly:!0,className:"font-mono text-sm"}),u.jsx(Le,{type:"button",variant:"outline",size:"icon",onClick:j,children:a?u.jsx(Vs,{className:"h-4 w-4 text-green-500"}):u.jsx(YM,{className:"h-4 w-4"})})]})]}),u.jsx("div",{className:"flex justify-end",children:u.jsx(Le,{onClick:_,children:"Done"})})]}):u.jsx("form",{onSubmit:m(k=>S.mutate(k)),children:u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"name",children:"Name"}),u.jsx(Er,{id:"name",placeholder:"e.g., Production API Key",...p("name",{required:!0})})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{children:"Scopes"}),u.jsx("div",{className:"space-y-2",children:Ize.map(k=>u.jsxs("div",{className:"flex items-center space-x-2",children:[u.jsx(Qp,{id:k.value,checked:v("scopes").includes(k.value),onCheckedChange:i(()=>C(k.value),"onCheckedChange")}),u.jsx("label",{htmlFor:k.value,className:"text-sm cursor-pointer",children:k.label})]},k.value))})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"expires_at",children:"Expiration (optional)"}),u.jsx(Er,{id:"expires_at",type:"date",...p("expires_at")})]}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx(Le,{type:"button",variant:"outline",onClick:_,children:"Cancel"}),u.jsx(Le,{type:"submit",disabled:S.isPending,children:"Create"})]})]})})]})})},"CreateApiKeyDialog");var Lze=Symbol("radix.slottable");function $ze(e){const t=i(({children:n})=>u.jsx(u.Fragment,{children:n}),"Slottable2");return t.displayName=`${e}.Slottable`,t.__radixId=Lze,t}i($ze,"createSlottable");var Rie="AlertDialog",[qze,cHe]=oa(Rie,[pX]),hl=pX(),Aie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=hl(t);return u.jsx(jy,{...r,...n,modal:!0})},"AlertDialog$1");Aie.displayName=Rie;var Uze="AlertDialogTrigger",zze=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(AX,{...a,...r,ref:t})});zze.displayName=Uze;var Bze="AlertDialogPortal",Tie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=hl(t);return u.jsx(Cy,{...r,...n})},"AlertDialogPortal$1");Tie.displayName=Bze;var Hze="AlertDialogOverlay",Nie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(Ey,{...a,...r,ref:t})});Nie.displayName=Hze;var yh="AlertDialogContent",[Vze,Wze]=qze(yh),Gze=$ze("AlertDialogContent"),Pie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,children:r,...a}=e,s=hl(n),o=y.useRef(null),l=Xt(t,o),f=y.useRef(null);return u.jsx(_je,{contentName:yh,titleName:Die,docsSlug:"alert-dialog",children:u.jsx(Vze,{scope:n,cancelRef:f,children:u.jsxs(ky,{role:"alertdialog",...s,...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:[u.jsx(Gze,{children:r}),u.jsx(Yze,{contentRef:o})]})})})});Pie.displayName=yh;var Die="AlertDialogTitle",Mie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(_1,{...a,...r,ref:t})});Mie.displayName=Die;var Iie="AlertDialogDescription",Fie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(S1,{...a,...r,ref:t})});Fie.displayName=Iie;var Kze="AlertDialogAction",Lie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(Oy,{...a,...r,ref:t})});Lie.displayName=Kze;var $ie="AlertDialogCancel",qie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,{cancelRef:a}=Wze($ie,n),s=hl(n),o=Xt(t,a);return u.jsx(Oy,{...s,...r,ref:o})});qie.displayName=$ie;var Yze=i(({contentRef:e})=>{const t=`\`${yh}\` requires a description for the component to be accessible for screen reader users.
154
+ `,fill:a,opacity:o,strokeWidth:f,stroke:c===void 0?"transparent":c,style:{pointerEvents:"none"}})})},"y");function hc(){return hc=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},hc.apply(null,arguments)}i(hc,"b");var Pi={translateX:0,translateY:0,padding:0,itemsSpacing:0,itemDirection:"left-to-right",justify:!1,symbolShape:"square",symbolSize:16,symbolSpacing:8},Wqe={top:0,right:0,bottom:0,left:0},a5=i(function(e){var t,n=e.direction,r=e.itemsSpacing,a=e.padding,s=e.itemCount,o=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}:hc({},Wqe,a),c=f.left+f.right,p=f.top+f.bottom,m=o+c,v=l+p,b=(s-1)*r;return n==="row"?m=o*s+b+c:n==="column"&&(v=l*s+b+p),{width:m,height:v,padding:f}},"A"),pie=i(function(e){var t=e.anchor,n=e.translateX,r=e.translateY,a=e.containerWidth,s=e.containerHeight,o=e.width,l=e.height,f=n,c=r;switch(t){case"top":f+=(a-o)/2;break;case"top-right":f+=a-o;break;case"right":f+=a-o,c+=(s-l)/2;break;case"bottom-right":f+=a-o,c+=s-l;break;case"bottom":f+=(a-o)/2,c+=s-l;break;case"bottom-left":c+=s-l;break;case"left":c+=(s-l)/2;break;case"center":f+=(a-o)/2,c+=(s-l)/2}return{x:f,y:c}},"C"),mie=i(function(e){var t,n,r,a,s,o,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,o="central",f?(r=m,s="end"):(r=c+p,s="start");break;case"right-to-left":t=m-c,n=(v-c)/2,a=v/2,o="central",f?(r=0,s="start"):(r=m-c-p,s="end");break;case"top-to-bottom":t=(m-c)/2,n=0,r=m/2,s="middle",f?(a=v,o="alphabetic"):(a=c+p,o="text-before-edge");break;case"bottom-to-top":t=(m-c)/2,n=v-c,r=m/2,s="middle",f?(a=0,o="text-before-edge"):(a=v-c-p,o="alphabetic")}return{symbolX:t,symbolY:n,labelX:r,labelY:a,labelAnchor:s,labelAlignment:o}},"z"),Gqe={circle:zqe,diamond:Bqe,square:Hqe,triangle:Vqe},Kqe=i(function(e){var t,n,r,a,s,o,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?Pi.itemDirection:j,k=e.justify,E=k===void 0?Pi.justify:k,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?Pi.symbolShape:M,F=e.symbolSize,L=F===void 0?Pi.symbolSize:F,q=e.symbolSpacing,z=q===void 0?Pi.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({}),se=te[0],ne=te[1],fe=Br(),re=y.useCallback((function(X){if(ee){var oe=ee.filter((function(me){return me.on==="hover"})).reduce((function(me,Te){return hc({},me,Te.style)}),{});ne(oe)}Q?.(_,X)}),[Q,_,ee]),ce=y.useCallback((function(X){if(ee){var oe=ee.filter((function(me){return me.on!=="hover"})).reduce((function(me,Te){return hc({},me,Te.style)}),{});ne(oe)}Y?.(_,X)}),[Y,_,ee]),he=mie({direction:C,justify:E,symbolSize:(t=se.symbolSize)!=null?t:L,symbolSpacing:z,width:w,height:S}),J=he.symbolX,Me=he.symbolY,_e=he.labelX,Ce=he.labelY,Re=he.labelAnchor,Oe=he.labelAlignment,Ne=[V,Q,Y,K].some((function(X){return X!==void 0})),ze=typeof I=="function"?I:Gqe[I];return u.jsxs("g",{transform:"translate("+v+","+b+")",style:{opacity:(n=se.itemOpacity)!=null?n:D},children:[u.jsx("rect",{width:w,height:S,fill:(r=se.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,hc({id:_.id,x:J,y:Me,size:(a=se.symbolSize)!=null?a:L,fill:(s=(o=_.fill)!=null?o:_.color)!=null?s:"black",borderWidth:(l=se.symbolBorderWidth)!=null?l:H,borderColor:(f=se.symbolBorderColor)!=null?f:W},_.hidden?fe.legends.hidden.symbol:void 0)),u.jsx(lS,{textAnchor:Re,style:hc({},fe.legends.text,{fill:(c=(p=(m=se.itemTextColor)!=null?m:T)!=null?p:fe.legends.text.fill)!=null?c:"black",dominantBaseline:Oe,pointerEvents:"none",userSelect:"none"},_.hidden?fe.legends.hidden.text:void 0),x:_e,y:Ce,children:_.label})]})},"B"),Yqe=i(function(e){var t=e.data,n=e.x,r=e.y,a=e.direction,s=e.padding,o=s===void 0?Pi.padding:s,l=e.justify,f=e.effects,c=e.itemWidth,p=e.itemHeight,m=e.itemDirection,v=m===void 0?Pi.itemDirection:m,b=e.itemsSpacing,w=b===void 0?Pi.itemsSpacing:b,S=e.itemTextColor,_=e.itemBackground,j=_===void 0?"transparent":_,C=e.itemOpacity,k=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=a5({itemCount:t.length,itemWidth:c,itemHeight:p,itemsSpacing:w,direction:a,padding:o}).padding,q=a==="row"?c+w:0,z=a==="column"?p+w:0;return u.jsx("g",{transform:"translate("+n+","+r+")",children:t.map((function($,H){return u.jsx(Kqe,{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:k,symbolShape:E,symbolSize:T,symbolSpacing:R,symbolBorderWidth:A,symbolBorderColor:N,onClick:D,onMouseEnter:M,onMouseLeave:I,toggleSerie:F},H)}))})},"H"),Qqe=i(function(e){var t=e.data,n=e.containerWidth,r=e.containerHeight,a=e.translateX,s=a===void 0?Pi.translateX:a,o=e.translateY,l=o===void 0?Pi.translateY:o,f=e.anchor,c=e.direction,p=e.padding,m=p===void 0?Pi.padding:p,v=e.justify,b=e.itemsSpacing,w=b===void 0?Pi.itemsSpacing:b,S=e.itemWidth,_=e.itemHeight,j=e.itemDirection,C=e.itemTextColor,k=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=a5({itemCount:t.length,itemsSpacing:w,itemWidth:S,itemHeight:_,direction:c,padding:m}),$=z.width,H=z.height,U=pie({anchor:f,translateX:s,translateY:l,containerWidth:n,containerHeight:r,width:$,height:H}),W=U.x,V=U.y;return u.jsx(Yqe,{data:t,x:W,y:V,direction:c,padding:m,justify:v,effects:q,itemsSpacing:w,itemWidth:S,itemHeight:_,itemDirection:j,itemTextColor:C,itemBackground:k,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"),Xqe={start:"left",middle:"center",end:"right"},Zqe=i(function(e,t){var n=t.data,r=t.containerWidth,a=t.containerHeight,s=t.translateX,o=s===void 0?0:s,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,k=t.itemDirection,E=k===void 0?"left-to-right":k,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=a5({itemCount:n.length,itemWidth:j,itemHeight:C,itemsSpacing:_,direction:p,padding:v}),F=I.width,L=I.height,q=I.padding,z=pie({anchor:c,translateX:o,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),Gv(e,M.legends.text),n.forEach((function(V,Q){var Y,K=Q*U+q.left,ee=Q*W+q.top,te=mie({direction:E,justify:w,symbolSize:A,symbolSpacing:D,width:j,height:C}),se=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+se,ee+ne,A,A),e.textAlign=Xqe[ce],he==="central"&&(e.textBaseline="middle"),Kv(e,hc({},M.legends.text,{fill:T??M.legends.text.fill}),String(V.label),K+fe,ee+re)})),e.restore()},"L"),Jqe=i(function(e,t,n,r,a,s){s>0?(e.moveTo(t+s,n),e.lineTo(t+r-s,n),e.quadraticCurveTo(t+r,n,t+r,n+s),e.lineTo(t+r,n+a-s),e.quadraticCurveTo(t+r,n+a,t+r-s,n+a),e.lineTo(t+s,n+a),e.quadraticCurveTo(t,n+a,t,n+a-s),e.lineTo(t,n+s),e.quadraticCurveTo(t,n,t+s,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 Hc(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(Hc,"U");var UW,eUe=i(function(e){var t=e.bars,n=e.annotations,r=uie({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 s=a.height,o=a.width;return{width:o,height:s,size:Math.max(o,s)}},"getDimensions")});return u.jsx(u.Fragment,{children:r.map((function(a,s){return u.jsx(Cqe,gn({},a),s)}))})},"$"),tUe=i(function(e){var t=e.width,n=e.height,r=e.legends,a=e.toggleSerie;return u.jsx(u.Fragment,{children:r.map((function(s,o){var l,f=s[0],c=s[1];return u.jsx(Qqe,gn({},f,{containerWidth:t,containerHeight:n,data:(l=f.data)!=null?l:c,toggleSerie:f.toggleSerie&&f.dataFrom==="keys"?a:void 0}),o)}))})},"ee"),nUe=["data"],rUe=i(function(e){var t,n=e.bar,r=n.data,a=Hc(n,nUe),s=e.style,o=s.borderColor,l=s.color,f=s.height,c=s.labelColor,p=s.labelOpacity,m=s.labelX,v=s.labelY,b=s.transform,w=s.width,S=s.textAnchor,_=e.borderRadius,j=e.borderWidth,C=e.label,k=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=Br(),$=Bre(),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]),se=y.useCallback((function(){W()}),[W]);return u.jsxs(vr.g,{transform:b,children:[u.jsx(vr.rect,{width:aD(w,(function(ne){return Math.max(ne,0)})),height:aD(f,(function(ne){return Math.max(ne,0)})),rx:_,ry:_,fill:(t=r.fill)!=null?t:l,strokeWidth:j,stroke:o,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?se:void 0,"data-testid":"bar.item."+r.id+"."+r.index}),k&&u.jsx(lS,{x:m,y:v,textAnchor:S,dominantBaseline:"central",fillOpacity:p,style:gn({},z.labels.text,{pointerEvents:"none",fill:c}),children:C})]})},"ae"),aUe=["color","label"],iUe=i(function(e){var t=e.color,n=e.label,r=Hc(e,aUe);return u.jsx(CIe,{id:n,value:r.formattedValue,enableChip:!0,color:t})},"ne"),$n={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:iUe,tooltipLabel:i(function(e){return e.id+" - "+e.indexValue},"tooltipLabel"),legends:[],initialHiddenIds:[],annotations:[],enableTotals:!1,totalsOffset:10},Ln=gn({},$n,{layers:["grid","axes","bars","totals","markers","legends","annotations"],axisTop:null,axisRight:null,axisBottom:{},axisLeft:{},barComponent:rUe,defs:[],fill:[],markers:[],animate:!0,animateOnMount:!1,motionConfig:"default",role:"img",isFocusable:!1}),xr=gn({},$n,{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,s=n.width,o=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(),Jqe(e,o,l,s,a,Math.min(c,a)),e.fill(),p>0&&e.stroke(),v&&(e.textBaseline="middle",e.textAlign=_==="middle"?"center":_,Kv(e,b,m,o+w,l+S))},"renderBar"),pixelRatio:typeof window<"u"&&(UW=window.devicePixelRatio)!=null?UW:1}),gie=i(function(e,t,n,r,a,s){return r5(r,{all:e.map(t),min:0,max:0},a,s).padding(n)},"de"),vie=i(function(e,t){return e.map((function(n){return gn({},t.reduce((function(r,a){return r[a]=null,r}),{}),n)}))},"ue"),cS=i(function(e){return Object.keys(e).reduce((function(t,n){return e[n]&&(t[n]=e[n]),t}),{})},"se"),uS=i(function(e){return[e,Number(e)]},"ce");function yie(e,t,n,r){return e===void 0&&(e=$n.layout),n===void 0&&(n=$n.labelPosition),r===void 0&&(r=$n.labelOffset),function(a,s){var o=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+o,labelY:s/2,textAnchor:n==="middle"?"middle":t?"end":"start"}}var f=s/2;return n==="start"?f=t?0:s:n==="end"&&(f=t?s:0),{labelX:a/2,labelY:f-o,textAnchor:"middle"}}}i(yie,"he");var sUe=["layout","width","height","padding","innerPadding","valueScale","indexScale","hiddenIds"],i5=i(function(e,t){return e>t},"be"),bie=i(function(e,t){return e<t},"ge"),xie=i(function(e,t){return Array.from(" ".repeat(t-e),(function(n,r){return e+r}))},"ve"),oUe=i(function(e){return i5(e,0)?0:e},"me"),lUe=i(function(e,t,n,r){var a=e.data,s=e.formatValue,o=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?bie:i5,_=a.map(cS),j=[];return m.forEach((function(C,k){return xie(0,v.domain().length).forEach((function(E){var T,R,A,N=uS(a[E][C]),D=N[0],M=N[1],I=l(a[E]),F=((T=v(I))!=null?T:0)+t*k+p*k,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:s(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:o(z),label:f(z)})}))})),j},"pe"),cUe=i(function(e,t,n,r){var a=e.data,s=e.formatValue,o=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?bie:i5,_=a.map(cS),j=[];return c.forEach((function(C,k){return xie(0,b.domain().length).forEach((function(E){var T,R,A,N=uS(a[E][C]),D=N[0],M=N[1],I=o(a[E]),F=S(R=M,0)?r:(A=v(R))!=null?A:0,L=((T=b(I))!=null?T:0)+t*k+m*k,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:s(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"),uUe=i(function(e){var t,n,r,a=e.layout,s=e.width,o=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=Hc(e,sUe),_=S.keys.filter((function(H){return!w.includes(H)})),j=vie(S.data,_),C=a==="vertical"?["y","x",s]:["x","y",o],k=C[0],E=C[1],T=C[2],R=gie(j,S.getIndex,f,v,T,E),A=m.min==="auto"?oUe: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=r5(m,{all:N,min:D,max:M},k==="x"?s:o,k),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"?lUe.apply(void 0,$):cUe.apply(void 0,$):[]}},"xe"),dUe=["data","layout","width","height","padding","valueScale","indexScale","hiddenIds"],wie=i(function(e){var t;return e.some(Array.isArray)?wie((t=[]).concat.apply(t,e)):e},"ke"),fUe=i(function(e,t,n){var r=e.formatValue,a=e.getColor,s=e.getIndex,o=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],k=(_=c(s(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=uS(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:cS(C.data)};v.push({key:b.key+"."+w,index:v.length,data:D,x:k,y:E,absX:m.left+k,absY:m.top+E,width:t,height:T,color:a(D),label:o(D)})}))})),v},"we"),hUe=i(function(e,t,n){var r=e.formatValue,a=e.getColor,s=e.getIndex,o=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],k=(_=p(s(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=uS(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:cS(C.data)};v.push({key:b.key+"."+w,index:v.length,data:D,x:E,y:k,absX:m.left+E,absY:m.top+k,width:T,height:t,color:a(D),label:o(D)})}))})),v},"Le"),pUe=i(function(e){var t,n,r=e.data,a=e.layout,s=e.width,o=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=Hc(e,dUe),w=b.keys.filter((function(z){return!v.includes(z)})),S=LFe().keys(w).offset($Fe)(vie(r,w)),_=a==="vertical"?["y","x",s]:["x","y",o],j=_[0],C=_[1],k=_[2],E=gie(r,b.getIndex,f,p,k,C),T=(n=wie(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=r5(c,{all:T,min:R,max:A},j==="x"?s:o,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"?fUe.apply(void 0,q):hUe.apply(void 0,q):[]}},"Ce"),mUe=i(function(e){var t=e.bars,n=e.direction,r=e.from,a=e.groupMode,s=e.layout,o=e.legendLabel,l=e.reverse,f=eie(o??(r==="indexes"?"indexValue":"id"));return r==="indexes"?(function(c,p,m){var v=pW(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,s,f):(function(c,p,m,v,b,w){var S=pW(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,s,n,a,l,f)},"We"),zW=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+n)},"Me"),gUe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,r+(n>0?n:0))},"Be"),vUe=i(function(e,t,n){var r=e.get(t)||0;e.set(t,Math.max(r,Number(n)))},"Re"),yUe=i(function(e,t){var n=e.get(t)||0;e.set(t,n+1)},"Oe"),_ie=i(function(e){var t,n=e.indexBy,r=n===void 0?$n.indexBy:n,a=e.keys,s=a===void 0?$n.keys:a,o=e.label,l=o===void 0?$n.label:o,f=e.tooltipLabel,c=f===void 0?$n.tooltipLabel:f,p=e.valueFormat,m=e.colors,v=m===void 0?$n.colors:m,b=e.colorBy,w=b===void 0?$n.colorBy:b,S=e.borderColor,_=S===void 0?$n.borderColor:S,j=e.labelTextColor,C=j===void 0?$n.labelTextColor:j,k=e.groupMode,E=k===void 0?$n.groupMode:k,T=e.layout,R=T===void 0?$n.layout:T,A=e.data,N=e.margin,D=e.width,M=e.height,I=e.padding,F=I===void 0?$n.padding:I,L=e.innerPadding,q=L===void 0?$n.innerPadding:L,z=e.valueScale,$=z===void 0?$n.valueScale:z,H=e.indexScale,U=H===void 0?$n.indexScale:H,W=e.initialHiddenIds,V=W===void 0?$n.initialHiddenIds:W,Q=e.enableLabel,Y=Q===void 0?$n.enableLabel:Q,K=e.labelSkipWidth,ee=K===void 0?$n.labelSkipWidth:K,te=e.labelSkipHeight,se=te===void 0?$n.labelSkipHeight:te,ne=e.legends,fe=ne===void 0?$n.legends:ne,re=e.legendLabel,ce=e.totalsOffset,he=ce===void 0?$n.totalsOffset:ce,J=y.useState(V??[]),Me=J[0],_e=J[1],Ce=y.useCallback((function(Ke){_e((function(pt){return pt.indexOf(Ke)>-1?pt.filter((function(ve){return ve!==Ke})):[].concat(pt,[Ke])}))}),[]),Re=iT(r),Oe=iT(l),Ne=iT(c),ze=n5(p),X=Br(),oe=Uqe(v,w),me=qW(_,X),Te=qW(C,X),de=(E==="grouped"?uUe:pUe)({layout:R,data:A,getIndex:Re,keys:s,width:D,height:M,getColor:oe,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)&&!(se>0&&ve<se)}),[Y,ee,se]),Nt=y.useMemo((function(){return s.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,s,ue]),qt=(t=$.reverse)!=null&&t,Rt=y.useMemo((function(){return fe.map((function(Ke){return[Ke,mUe({bars:Ke.dataFrom==="keys"?Nt:ue,direction:Ke.direction,from:Ke.dataFrom,groupMode:E,layout:R,legendLabel:re,reverse:qt})]}))}),[fe,Nt,ue,E,R,re,qt]),zt=y.useMemo((function(){return(function(Ke,pt,ve,ye,ct,$e,Xe){ye===void 0&&(ye=$n.layout),ct===void 0&&(ct=$n.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;zW(tt,vt,Number(Et)),gUe(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 Lt=new Map,Pt=new Map;Ke.forEach((function(At){var _t=At.data,vt=_t.indexValue,Et=_t.value;zW(tt,vt,Number(Et)),vUe(Lt,vt,Number(Et)),yUe(Pt,vt)})),Lt.forEach((function(At,_t){var vt,Et,Z,pe=tt.get(_t)||0,Se=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"?Se*jt/2:$e,Et+=ye==="vertical"?-$e:Se*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:Oe,getTooltipLabel:Ne,formatValue:ze,getColor:oe,getBorderColor:me,getLabelColor:Te,shouldRenderBarLabel:et,hiddenIds:Me,toggleSerie:Ce,legendsWithData:Rt,barTotals:zt}},"Ie"),bUe=i(function(e){var t=e.data,n=e.springConfig,r=e.animate,a=e.layout,s=a===void 0?Ln.layout:a,o=Br();return j_(t,{keys:i(function(l){return l.key},"keys"),from:i(function(l){return{x:s==="vertical"?l.x:l.animationOffset,y:s==="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:s==="vertical"?l.x:l.animationOffset,y:s==="vertical"?l.animationOffset:l.y,labelOpacity:0}},"leave"),config:n,immediate:!r,initial:r?void 0:null})((function(l,f){return u.jsx(vr.text,{x:l.x,y:l.y,fillOpacity:l.labelOpacity,style:gn({},o.labels.text,{pointerEvents:"none"}),fontWeight:"bold",fontSize:o.labels.text.fontSize,fontFamily:o.labels.text.fontFamily,textAnchor:s==="vertical"?"middle":"start",alignmentBaseline:s==="vertical"?"alphabetic":"middle",children:f.formattedValue},f.key)}))},"Ve"),xUe=["isInteractive","animate","motionConfig","theme","renderWrapper"],wUe=i(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,s=e.margin,o=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?Ln.axisBottom:_,C=e.axisLeft,k=C===void 0?Ln.axisLeft:C,E=e.enableGridX,T=E===void 0?Ln.enableGridX:E,R=e.enableGridY,A=R===void 0?Ln.enableGridY:R,N=e.gridXValues,D=e.gridYValues,M=e.layers,I=M===void 0?Ln.layers:M,F=e.barComponent,L=F===void 0?Ln.barComponent:F,q=e.enableLabel,z=q===void 0?Ln.enableLabel:q,$=e.label,H=e.labelSkipWidth,U=H===void 0?Ln.labelSkipWidth:H,W=e.labelSkipHeight,V=W===void 0?Ln.labelSkipHeight:W,Q=e.labelTextColor,Y=e.labelPosition,K=Y===void 0?Ln.labelPosition:Y,ee=e.labelOffset,te=ee===void 0?Ln.labelOffset:ee,se=e.markers,ne=se===void 0?Ln.markers:se,fe=e.colorBy,re=e.colors,ce=e.defs,he=ce===void 0?Ln.defs:ce,J=e.fill,Me=J===void 0?Ln.fill:J,_e=e.borderRadius,Ce=_e===void 0?Ln.borderRadius:_e,Re=e.borderWidth,Oe=Re===void 0?Ln.borderWidth:Re,Ne=e.borderColor,ze=e.annotations,X=ze===void 0?Ln.annotations:ze,oe=e.legendLabel,me=e.tooltipLabel,Te=e.valueFormat,de=e.isInteractive,ue=de===void 0?Ln.isInteractive:de,Ae=e.tooltip,Pe=Ae===void 0?Ln.tooltip:Ae,Fe=e.onClick,et=e.onMouseEnter,Nt=e.onMouseLeave,qt=e.legends,Rt=e.role,zt=Rt===void 0?Ln.role:Rt,Ke=e.ariaLabel,pt=e.ariaLabelledBy,ve=e.ariaDescribedBy,ye=e.isFocusable,ct=ye===void 0?Ln.isFocusable:ye,$e=e.barAriaLabel,Xe=e.barAriaLabelledBy,We=e.barAriaDescribedBy,tt=e.barAriaHidden,jt=e.barAriaDisabled,Ye=e.initialHiddenIds,gt=e.enableTotals,Lt=gt===void 0?Ln.enableTotals:gt,Pt=e.totalsOffset,At=Pt===void 0?Ln.totalsOffset:Pt,_t=e.forwardedRef,vt=_s(),Et=vt.animate,Z=vt.config,pe=Jae(o,l,s),Se=pe.outerWidth,qe=pe.outerHeight,He=pe.margin,rt=pe.innerWidth,nt=pe.innerHeight,Qe=_ie({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:qt,legendLabel:oe,initialHiddenIds:Ye,totalsOffset:At}),st=Qe.bars,ut=Qe.barsWithValue,ot=Qe.xScale,lt=Qe.yScale,yt=Qe.getLabel,at=Qe.getTooltipLabel,Ot=Qe.getBorderColor,bt=Qe.getLabelColor,$t=Qe.shouldRenderBarLabel,Mt=Qe.toggleSerie,Vr=Qe.legendsWithData,Na=Qe.barTotals,gi=Qe.getColor,fr=yie(c,(t=p?.reverse)!=null&&t,K,te),Ss=j_(ut,{keys:i(function(Ve){return Ve.key},"keys"),from:i(function(Ve){return gn({borderColor:Ot(Ve),color:Ve.color,height:0,labelColor:bt(Ve),labelOpacity:0},fr(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:Ot(Ve),color:Ve.color,height:Ve.height,labelColor:bt(Ve),labelOpacity:1},fr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+Ve.y+")",width:Ve.width})},"enter"),update:i(function(Ve){return gn({borderColor:Ot(Ve),color:Ve.color,height:Ve.height,labelColor:bt(Ve),labelOpacity:1},fr(Ve.width,Ve.height),{transform:"translate("+Ve.x+", "+Ve.y+")",width:Ve.width})},"update"),leave:i(function(Ve){return gn({borderColor:Ot(Ve),color:Ve.color,height:0,labelColor:bt(Ve),labelOpacity:0},fr(Ve.width,Ve.height),{labelY:0,transform:"translate("+Ve.x+", "+(Ve.y+Ve.height)+")",width:Ve.width},c==="vertical"?{}:gn({},fr(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}),Wr=y.useMemo((function(){return{borderRadius:Ce,borderWidth:Oe,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,Oe,z,at,ue,V,U,Fe,et,Nt,Pe,ct,$e,Xe,We,tt,jt]),Qa=y9e(he,st,Me,{dataKey:"data",targetKey:"data.fill"}),na={annotations:null,axes:null,bars:null,grid:null,legends:null,markers:null,totals:null};I.includes("annotations")&&(na.annotations=u.jsx(eUe,{bars:st,annotations:X},"annotations")),I.includes("axes")&&(na.axes=u.jsx(Z9e,{xScale:ot,yScale:lt,width:rt,height:nt,top:w,right:S,bottom:j,left:k},"axes")),I.includes("bars")&&(na.bars=u.jsx(y.Fragment,{children:Ss((function(Ve,Bn){return y.createElement(L,gn({},Wr,{bar:Bn,style:Ve,shouldRenderLabel:$t(Bn),label:yt(Bn.data)}))}))},"bars")),I.includes("grid")&&(na.grid=u.jsx(eqe,{width:rt,height:nt,xScale:T?ot:null,yScale:A?lt:null,xValues:N,yValues:D},"grid")),I.includes("legends")&&(na.legends=u.jsx(tUe,{width:rt,height:nt,legends:Vr,toggleSerie:Mt},"legends")),I.includes("markers")&&(na.markers=u.jsx(l9e,{markers:ne,width:rt,height:nt,xScale:ot,yScale:lt},"markers")),I.includes("totals")&&Lt&&(na.totals=u.jsx(bUe,{data:Na,springConfig:Z,animate:Et,layout:c},"totals"));var Xa=gn({},Wr,{margin:He,width:o,height:l,innerWidth:rt,innerHeight:nt,bars:st,legendData:Vr,enableLabel:z,xScale:ot,yScale:lt,tooltip:Pe,getTooltipLabel:at,onClick:Fe,onMouseEnter:et,onMouseLeave:Nt,getColor:gi});return u.jsx(i9e,{width:Se,height:qe,margin:He,defs:Qa,role:zt,ariaLabel:Ke,ariaLabelledBy:pt,ariaDescribedBy:ve,isFocusable:ct,ref:_t,children:I.map((function(Ve,Bn){var Bi;return typeof Ve=="function"?u.jsx(y.Fragment,{children:y.createElement(Ve,Xa)},Bn):(Bi=na?.[Ve])!=null?Bi:null}))})},"He"),_Ue=y.forwardRef((function(e,t){var n=e.isInteractive,r=n===void 0?Ln.isInteractive:n,a=e.animate,s=a===void 0?Ln.animate:a,o=e.motionConfig,l=o===void 0?Ln.motionConfig:o,f=e.theme,c=e.renderWrapper,p=Hc(e,xUe);return u.jsx(Kae,{animate:s,isInteractive:r,motionConfig:l,renderWrapper:c,theme:f,children:u.jsx(wUe,gn({},p,{isInteractive:r,forwardedRef:t}))})})),SUe=["isInteractive","renderWrapper","theme"],RT=i(function(e,t,n,r){return e.find((function(a){return p9e(a.x+t.left,a.y+t.top,a.width,a.height,n,r)}))},"Fe"),jUe=i(function(e){var t,n=e.data,r=e.indexBy,a=e.keys,s=e.margin,o=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?xr.axisBottom:_,C=e.axisLeft,k=C===void 0?xr.axisLeft:C,E=e.enableGridX,T=E===void 0?xr.enableGridX:E,R=e.enableGridY,A=R===void 0?xr.enableGridY:R,N=e.gridXValues,D=e.gridYValues,M=e.labelPosition,I=M===void 0?xr.labelPosition:M,F=e.labelOffset,L=F===void 0?xr.labelOffset:F,q=e.layers,z=q===void 0?xr.layers:q,$=e.renderBar,H=$===void 0?xr.renderBar:$,U=e.enableLabel,W=U===void 0?xr.enableLabel:U,V=e.label,Q=e.labelSkipWidth,Y=Q===void 0?xr.labelSkipWidth:Q,K=e.labelSkipHeight,ee=K===void 0?xr.labelSkipHeight:K,te=e.labelTextColor,se=e.colorBy,ne=e.colors,fe=e.borderRadius,re=fe===void 0?xr.borderRadius:fe,ce=e.borderWidth,he=ce===void 0?xr.borderWidth:ce,J=e.borderColor,Me=e.annotations,_e=Me===void 0?xr.annotations:Me,Ce=e.legendLabel,Re=e.tooltipLabel,Oe=e.valueFormat,Ne=e.isInteractive,ze=Ne===void 0?xr.isInteractive:Ne,X=e.tooltip,oe=X===void 0?xr.tooltip:X,me=e.onClick,Te=e.onMouseEnter,de=e.onMouseLeave,ue=e.legends,Ae=e.pixelRatio,Pe=Ae===void 0?xr.pixelRatio:Ae,Fe=e.role,et=e.forwardedRef,Nt=e.enableTotals,qt=Nt===void 0?xr.enableTotals:Nt,Rt=e.totalsOffset,zt=Rt===void 0?xr.totalsOffset:Rt,Ke=y.useRef(null),pt=Br(),ve=Jae(o,l,s),ye=ve.margin,ct=ve.innerWidth,$e=ve.innerHeight,Xe=ve.outerWidth,We=ve.outerHeight,tt=_ie({indexBy:r,label:V,tooltipLabel:Re,valueFormat:Oe,colors:ne,colorBy:se,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:zt}),jt=tt.bars,Ye=tt.barsWithValue,gt=tt.xScale,Lt=tt.yScale,Pt=tt.getLabel,At=tt.getTooltipLabel,_t=tt.getBorderColor,vt=tt.getLabelColor,Et=tt.shouldRenderBarLabel,Z=tt.legendsWithData,pe=tt.barTotals,Se=tt.getColor,qe=Bre(),He=qe.showTooltipFromEvent,rt=qe.hideTooltip,nt=bqe({annotations:uie({data:jt,annotations:_e,getPosition:i(function(at){return{x:at.x,y:at.y}},"getPosition"),getDimensions:i(function(at){var Ot=at.width,bt=at.height;return{width:Ot,height:bt,size:Math.max(Ot,bt)}},"getDimensions")})}),Qe=y.useMemo((function(){return{borderRadius:re,borderWidth:he,isInteractive:ze,isFocusable:!1,labelSkipWidth:Y,labelSkipHeight:ee,margin:ye,width:o,height:l,innerWidth:ct,innerHeight:$e,bars:jt,legendData:Z,enableLabel:W,xScale:gt,yScale:Lt,tooltip:oe,getTooltipLabel:At,onClick:me,onMouseEnter:Te,onMouseLeave:de,getColor:Se}}),[re,he,ze,Y,ee,ye,o,l,ct,$e,jt,Z,W,gt,Lt,oe,At,me,Te,de,Se]),st=n5(Oe),ut=yie(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(Ot){Ot==="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&&kW(at,{width:ct,height:$e,scale:gt,axis:"x",values:N}),A&&kW(at,{width:ct,height:$e,scale:Lt,axis:"y",values:D})):Ot==="axes"?nqe(at,{xScale:gt,yScale:Lt,width:ct,height:$e,top:w,right:S,bottom:j,left:k,theme:pt}):Ot==="bars"?(Gv(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)))}))):Ot==="legends"?Z.forEach((function(bt){var $t=bt[0],Mt=bt[1];Zqe(at,gn({},$t,{data:Mt,containerWidth:ct,containerHeight:$e,theme:pt}))})):Ot==="annotations"?Eqe(at,{annotations:nt,theme:pt}):Ot==="totals"&&qt?(function(bt,$t,Mt,Vr){Vr===void 0&&(Vr=xr.layout),Gv(bt,Mt.labels.text),bt.textBaseline=Vr==="vertical"?"alphabetic":"middle",bt.textAlign=Vr==="vertical"?"center":"start",$t.forEach((function(Na){Kv(bt,Mt.labels.text,Na.formattedValue,Na.x,Na.y)}))})(at,pe,pt,c):typeof Ot=="function"&&Ot(at,Qe)})),at.save()}}),[j,k,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,Lt,Et,pt,o,pe,qt,st,ut]);var ot=y.useCallback((function(at){if(jt&&Ke.current){var Ot=sT(Ke.current,at),bt=Ot[0],$t=Ot[1],Mt=RT(jt,ye,bt,$t);Mt!==void 0?(He(y.createElement(oe,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,oe]),lt=y.useCallback((function(at){if(jt&&Ke.current){rt();var Ot=sT(Ke.current,at),bt=Ot[0],$t=Ot[1],Mt=RT(jt,ye,bt,$t);Mt&&de?.(Mt.data,at)}}),[rt,ye,de,jt]),yt=y.useCallback((function(at){if(jt&&Ke.current){var Ot=sT(Ke.current,at),bt=Ot[0],$t=Ot[1],Mt=RT(jt,ye,bt,$t);Mt!==void 0&&me?.(gn({},Mt.data,{color:Mt.color}),at)}}),[ye,me,jt]);return u.jsx("canvas",{ref:b9e(Ke,et),width:Xe*Pe,height:We*Pe,style:{width:Xe,height:We,cursor:ze?"auto":"normal"},onMouseEnter:ze?ot:void 0,onMouseMove:ze?ot:void 0,onMouseLeave:ze?lt:void 0,onClick:ze?yt:void 0,role:Fe})},"ze"),CUe=y.forwardRef((function(e,t){var n=e.isInteractive,r=e.renderWrapper,a=e.theme,s=Hc(e,SUe);return u.jsx(Kae,{isInteractive:n,renderWrapper:r,theme:a,animate:!1,children:u.jsx(jUe,gn({},s,{isInteractive:n,forwardedRef:t}))})})),EUe=["defaultWidth","defaultHeight","onResize","debounceResize"],kUe=y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,s=e.debounceResize,o=Hc(e,EUe);return u.jsx(Yae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:s,children:i(function(l){var f=l.width,c=l.height;return u.jsx(_Ue,gn({},o,{width:f,height:c,ref:t}))},"children")})})),OUe=["defaultWidth","defaultHeight","onResize","debounceResize"];y.forwardRef((function(e,t){var n=e.defaultWidth,r=e.defaultHeight,a=e.onResize,s=e.debounceResize,o=Hc(e,OUe);return u.jsx(Yae,{defaultWidth:n,defaultHeight:r,onResize:a,debounceResize:s,children:i(function(l){var f=l.width,c=l.height;return u.jsx(CUe,gn({},o,{width:f,height:c,ref:t}))},"children")})}));const RUe={opportunity:.2,"proposal-sent":.5,"in-negociation":.8,delayed:.3},AUe=new Date(new Date().setMonth(new Date().getMonth()-6)).toISOString(),BW="en-US",TUe="USD",NUe=y.memo(()=>{const e=navigator?navigator.languages||[navigator.language]:[BW],{data:t,isPending:n}=pa("deals",{pagination:{perPage:100,page:1},sort:{field:"created_at",order:"ASC"},filter:{"created_at@gte":AUe}}),r=y.useMemo(()=>{if(!t)return[];const o=t.reduce((f,c)=>{const p=CN(c.created_at??new Date).toISOString();return f[p]||(f[p]=[]),f[p].push(c),f},{});return Object.keys(o).map(f=>({date:gc(f,"MMM"),won:o[f].filter(c=>c.stage==="won").reduce((c,p)=>{const m=p.amount??0;return isNaN(m)||(c+=m),c},0),pending:o[f].filter(c=>!["won","lost"].includes(c.stage)).reduce((c,p)=>{const m=p.amount??0,v=RUe[p.stage]??0;return!isNaN(m)&&!isNaN(v)&&(c+=m*v),c},0),lost:o[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((o,l)=>(o.min=Math.min(o.min,l.lost),o.max=Math.max(o.max,l.won+l.pending),o),{min:0,max:0}),s={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 u.jsxs("div",{className:"flex flex-col",children:[u.jsxs("div",{className:"flex items-center mb-4",children:[u.jsx("div",{className:"mr-3 flex",children:u.jsx(KQ,{className:"text-muted-foreground w-6 h-6"})}),u.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Upcoming Deal Revenue"})]}),u.jsx("div",{className:"h-[400px]",children:u.jsx(kUe,{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:s.min,max:s.max},indexScale:{type:"band",round:!0},enableGridX:!0,enableGridY:!1,enableLabel:!1,tooltip:i(({value:o,indexValue:l})=>u.jsxs("div",{className:"p-2 bg-secondary rounded shadow inline-flex items-center gap-1 text-secondary-foreground",children:[u.jsxs("strong",{children:[l,": "]})," ",o>0?"+":"",o.toLocaleString(e.at(0)??BW,{style:"currency",currency:TUe})]}),"tooltip"),axisTop:{tickSize:0,tickPadding:12,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},axisBottom:{legendPosition:"middle",legendOffset:50,tickSize:0,tickPadding:12,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},axisLeft:null,axisRight:{format:i(o=>`${Math.abs(o/1e3)}k`,"format"),tickValues:8,style:{ticks:{text:{fill:"var(--color-muted-foreground)"}},legend:{text:{fill:"var(--color-muted-foreground)"}}}},markers:[{axis:"y",value:0,lineStyle:{strokeOpacity:0},textStyle:{fill:"#2ebca6"},legend:"Won",legendPosition:"top-left",legendOrientation:"vertical"},{axis:"y",value:0,lineStyle:{stroke:"#f47560",strokeWidth:1},textStyle:{fill:"#e25c3b"},legend:"Lost",legendPosition:"bottom-left",legendOrientation:"vertical"}]})})]})}),PUe=i(e=>{const t=xt(),n=Wt(e),{filterValues:r,setFilters:a}=Yw(e),s=Tc();if(!n)throw new Error("<ListNoResults> must be used inside a <List> component");return u.jsx("div",{className:"p-6",children:u.jsx("p",{className:"text-sm text-muted-foreground",children:r&&a&&Object.keys(r).length>0?u.jsxs(u.Fragment,{children:[t("ra.navigation.no_filtered_results",{resource:n,name:s(n,0),_:"No results found with the current filters."})," ",u.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:s(n,0),_:"No results found."})})})},"ListNoResults"),DUe=i(e=>{const{children:t,linkType:n,rowClick:r,style:a}=e,s=Wt(e),o=Ft(e),l=Ra(),f=typeof n=="function"||typeof r=="function",c=CK({link:f?!1:n??r,resource:s}),p=OK(),m=Ct(async()=>{if(!f||!o)return;const v=typeof n=="function"?n(o,o.id):typeof r=="function"?(w,S)=>r(w.id,S,w):!1,b=await p({record:o,resource:s,link:v});b===!1||b==null||l(b)});return o?f?u.jsx("li",{className:"w-full",children:u.jsx("button",{onClick:m,style:a,className:"w-full text-left hover:bg-muted focus: bg-muted focus:outline-none",children:t})}):c?u.jsx("li",{className:"w-full",children:u.jsx(nn,{to:c,style:a,className:"block w-full hover:bg-muted focus:bg-muted focus:outline-none",children:t})}):u.jsx("li",{className:"w-full",children:t}):null},"SimpleListItem"),AT=i(({className:e})=>u.jsx("span",{className:xe("bg-gray-300 flex",e),children:" "}),"ListPlaceholder"),MUe=i(e=>{const{className:t,hasLeftAvatarOrIcon:n,hasRightAvatarOrIcon:r,hasSecondaryText:a,hasTertiaryText:s,nbFakeLines:o=5,...l}=e;return rY(1e3)?u.jsx("ul",{className:t,...l,children:IUe(o,c=>u.jsxs("li",{className:"flex items-center space-x-3 p-3",children:[n&&u.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"mb-1",children:[u.jsx(AT,{className:"w-1/3 inline-block mb-1"}),s&&u.jsx("span",{className:"float-right opacity-55 min-w-[10vw]",children:u.jsx(AT,{})})]}),a&&u.jsx(AT,{className:"w-1/4"})]}),r&&u.jsx("div",{className:"w-10 h-10 bg-gray-300 rounded-full flex-shrink-0",children:" "})]},c))}):null},"SimpleListLoading"),IUe=i((e,t)=>Array.from({length:e},(n,r)=>t(r)),"times"),FUe=i(e=>{const{className:t,empty:n=$Ue,leftAvatar:r,leftIcon:a,linkType:s,rowClick:o,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,resource:v,...b}=e,{data:w,isPending:S,total:_}=Yw(e);return S===!0?u.jsx(MUe,{className:t,hasLeftAvatarOrIcon:!!a||!!r,hasRightAvatarOrIcon:!!c||!!f,hasSecondaryText:!!p,hasTertiaryText:!!m}):w==null||w.length===0||_===0?n||null:u.jsx("ul",{className:t,...Dme(b),children:u.jsx(Ume,{data:w,total:_,render:i((j,C)=>u.jsx(DUe,{rowIndex:C,linkType:s,rowClick:o,resource:v,children:u.jsx(LUe,{leftAvatar:r,leftIcon:a,primaryText:l,rightAvatar:f,rightIcon:c,secondaryText:p,tertiaryText:m,rowIndex:C})},j.id),"render")})})},"SimpleList"),LUe=i(e=>{const{leftAvatar:t,leftIcon:n,primaryText:r,rightAvatar:a,rightIcon:s,secondaryText:o,tertiaryText:l}=e,f=Wt(e),c=Ft(e),p=Nc(f),m=xt(),v=i((b,w)=>{const S=w(b,b.id);return typeof S=="string"&&(S.startsWith("http")||S.startsWith("data:"))?u.jsx("img",{src:S,alt:"",className:"w-10 h-10 rounded-full object-cover"}):u.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-sm",children:S})},"renderAvatar");return c?u.jsxs("div",{className:"flex items-center space-x-3 p-3",children:[n&&u.jsx("div",{className:"flex-shrink-0",children:n(c,c.id)}),t&&u.jsx("div",{className:"flex-shrink-0",children:v(c,t)}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.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&&u.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)})]}),!!o&&u.jsx("div",{className:"text-sm text-muted-foreground truncate",children:typeof o=="string"?m(o,{...c,_:o}):y.isValidElement(o)?o:o(c,c.id)})]}),(a||s)&&u.jsxs("div",{className:"flex-shrink-0 flex items-center space-x-2",children:[a&&v(c,a),s&&s(c,c.id)]})]}):null},"SimpleListItemContent"),$Ue=u.jsx(PUe,{}),qUe=i(()=>{const{identity:e}=Yn(),{data:t,total:n,isPending:r}=pa("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 u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-center",children:[u.jsx("div",{className:"mr-3 flex",children:u.jsx(i4,{className:"text-muted-foreground w-6 h-6"})}),u.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"Hot Contacts"}),u.jsx(Li,{children:u.jsxs(ds,{children:[u.jsx(fs,{asChild:!0,children:u.jsx(Le,{variant:"ghost",size:"sm",className:"ml-auto text-muted-foreground",asChild:!0,children:u.jsx(nn,{to:"/contacts/create",children:u.jsx(os,{className:"w-4 h-4 text-primary"})})})}),u.jsx(hs,{children:"Create contact"})]})})]}),u.jsx(un,{className:"py-0",children:u.jsx(FUe,{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=>u.jsxs(u.Fragment,{children:[a.title," at ",a.company_name]}),"secondaryText"),leftAvatar:i(a=>u.jsx(ho,{record:a}),"leftAvatar"),empty:u.jsxs("div",{className:"p-4",children:[u.jsx("p",{className:"text-sm mb-4",children:'Contacts with a "hot" status will appear here.'}),u.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"),UUe=i(()=>{const{identity:e}=Yn(),{total:t}=pa("tasks",{pagination:{page:1,perPage:1},filter:{sales_id:e?.id}},{enabled:!!e});return t?null:u.jsx("p",{className:"text-sm",children:"Tasks added to your contacts will appear here."})},"TasksListEmpty"),yg=i(({title:e,filter:t})=>{const{identity:n}=Yn(),{data:r,total:a,isPending:s}=pa("tasks",{pagination:{page:1,perPage:100},sort:{field:"due_date",order:"ASC"},filter:{...t,sales_id:n?.id}},{enabled:!!n}),o=Qw({data:r,isPending:s,resource:"tasks",perPage:5});return s||!r||!a?null:u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx("p",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium mb-2",children:e}),u.jsx(bd,{value:"tasks",children:u.jsx(py,{value:o,children:u.jsx(Jne,{showContact:!0})})}),a>o.perPage&&u.jsx("div",{className:"flex justify-center",children:u.jsx("a",{href:"#",onClick:i(l=>{o.setPerPage(o.perPage+10),l.preventDefault()},"onClick"),className:"text-sm underline hover:no-underline",children:"Load more"})})]})},"TasksListFilter"),Sie=new Date,zUe=xbe(Sie),BUe=zUe<5,HW=_be().toISOString(),VW=b0e().toISOString(),WW=x0e().toISOString(),GW=y0e(Sie,{weekStartsOn:0}).toISOString(),bg={overdue:{"done_date@is":null,"due_date@lt":HW},today:{"done_date@is":null,"due_date@gte":HW,"due_date@lte":VW},tomorrow:{"done_date@is":null,"due_date@gt":VW,"due_date@lt":WW},thisWeek:{"done_date@is":null,"due_date@gte":WW,"due_date@lte":GW},later:{"done_date@is":null,"due_date@gt":GW}},HUe=i(()=>u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-center",children:[u.jsx("div",{className:"mr-3 flex",children:u.jsx(YQ,{className:"text-muted-foreground w-6 h-6"})}),u.jsx("h2",{className:"text-xl font-semibold text-muted-foreground flex-1",children:"Upcoming Tasks"}),u.jsx(Xne,{display:"icon",selectContact:!0})]}),u.jsx(un,{className:"p-4 mb-2",children:u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx(UUe,{}),u.jsx(yg,{title:"Overdue",filter:bg.overdue}),u.jsx(yg,{title:"Today",filter:bg.today}),u.jsx(yg,{title:"Tomorrow",filter:bg.tomorrow}),BUe&&u.jsx(yg,{title:"This week",filter:bg.thisWeek}),u.jsx(yg,{title:"Later",filter:bg.later})]})})]}),"TasksList"),VUe=i(()=>{const{data:e,total:t,isPending:n}=pa("contacts",{pagination:{page:1,perPage:1}}),{total:r,isPending:a}=pa("contactNotes",{pagination:{page:1,perPage:1}}),{total:s,isPending:o}=pa("deals",{pagination:{page:1,perPage:1}});return n||a||o?null:t?r?u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-6 mt-1",children:[u.jsx("div",{className:"md:col-span-3",children:u.jsxs("div",{className:"flex flex-col gap-4",children:[null,u.jsx(qUe,{})]})}),u.jsx("div",{className:"md:col-span-6",children:u.jsxs("div",{className:"flex flex-col gap-6",children:[s?u.jsx(NUe,{}):null,u.jsx(X6e,{})]})}),u.jsx("div",{className:"md:col-span-3",children:u.jsx(HUe,{})})]}):u.jsx(GH,{step:2,contactId:e?.[0]?.id}):u.jsx(GH,{step:1})},"Dashboard"),WUe=y.lazy(()=>Vp(()=>import("./DealList-ypDCCiwg.js"),[],import.meta.url)),GUe={list:WUe},KUe=y.createContext(void 0),dS=i(()=>y.useContext(KUe),"useUserMenu"),YUe=i(()=>{const{darkModeLogo:e,lightModeLogo:t,title:n}=la(),r=Ur(),s=[{path:"/",pattern:"/"},{path:"/contacts",pattern:"/contacts/*"},{path:"/companies",pattern:"/companies/*"},{path:"/deals",pattern:"/deals/*"},{path:"/tasks",pattern:"/tasks/*"}].find(o=>cp(o.pattern,r.pathname))?.path||!1;return u.jsx("header",{className:"bg-secondary fixed top-0 left-0 right-0 z-50 border-b border-border",children:u.jsx("div",{className:"px-4",children:u.jsxs("div",{className:"flex justify-between items-center flex-1",children:[u.jsx(QUe,{darkLogo:e,lightLogo:t,title:n}),u.jsxs("nav",{className:"flex","aria-label":"Main navigation",children:[u.jsx(xg,{label:"Dashboard",to:"/",isActive:s==="/"}),u.jsx(xg,{label:"Contacts",to:"/contacts",isActive:s==="/contacts"}),u.jsx(xg,{label:"Companies",to:"/companies",isActive:s==="/companies"}),u.jsx(xg,{label:"Deals",to:"/deals",isActive:s==="/deals"}),u.jsx(xg,{label:"Tasks",to:"/tasks",isActive:s==="/tasks"})]}),u.jsxs("div",{className:"flex items-center",children:[u.jsx(rJ,{}),u.jsx(aJ,{}),u.jsxs(eJ,{children:[u.jsx(ZUe,{}),u.jsx(JUe,{}),u.jsx(eze,{}),u.jsx(aye,{resource:"sales",action:"list",children:u.jsx(XUe,{})}),u.jsx(hv,{}),u.jsx(T4,{className:"font-normal",children:u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Version ","0.14.2"]})})]})]})]})})})},"Header"),QUe=i(({darkLogo:e,lightLogo:t,title:n})=>u.jsxs(nn,{to:"/",className:"flex items-center gap-2 text-secondary-foreground no-underline hover:opacity-80 transition-opacity",children:[u.jsx("img",{className:"[.light_&]:hidden h-6",src:e,alt:`${n} logo`}),u.jsx("img",{className:"[.dark_&]:hidden h-6",src:t,alt:`${n} logo`}),u.jsx("h1",{className:"text-xl font-semibold",children:n})]}),"Logo"),xg=i(({label:e,to:t,isActive:n})=>u.jsx(nn,{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"),XUe=i(()=>{const{onClose:e}=dS()??{};return u.jsx(sr,{asChild:!0,onClick:e,children:u.jsxs(nn,{to:"/sales",className:"flex items-center gap-2",children:[u.jsx(JQ,{className:"h-4 w-4"}),"Users"]})})},"UsersMenu"),ZUe=i(()=>{const{onClose:e}=dS()??{};return u.jsx(sr,{asChild:!0,onClick:e,children:u.jsxs(nn,{to:"/settings",className:"flex items-center gap-2",children:[u.jsx(RN,{className:"h-4 w-4"}),"My info"]})})},"ConfigurationMenu"),JUe=i(()=>{const{onClose:e}=dS()??{};return u.jsx(sr,{asChild:!0,onClick:e,children:u.jsxs(nn,{to:"/database",className:"flex items-center gap-2",children:[u.jsx(ov,{className:"h-4 w-4"}),"Database"]})})},"DatabaseMenu"),eze=i(()=>{const{onClose:e}=dS()??{};return u.jsx(sr,{asChild:!0,onClick:e,children:u.jsxs(nn,{to:"/integrations",className:"flex items-center gap-2",children:[u.jsx(L_e,{className:"h-4 w-4"}),"Integrations"]})})},"IntegrationsMenu"),tze=i(({children:e})=>u.jsxs(u.Fragment,{children:[u.jsx(YUe,{}),u.jsx("main",{className:"max-w-screen-xl mx-auto pt-20 px-4",id:"main-content",children:u.jsx(_x,{FallbackComponent:cJ,children:u.jsx(y.Suspense,{fallback:u.jsx(cn,{className:"h-12 w-12 rounded-full"}),children:e})})}),u.jsx(U1,{})]}),"Layout"),jie=i(()=>u.jsx("div",{className:"max-w-screen-xl mx-auto h-screen pt-8",children:u.jsx("div",{className:"h-full",children:u.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-8",children:[u.jsx(cn,{className:"w-full h-[100px]"}),u.jsx(cn,{className:"w-4/5 h-[50px]"}),u.jsx(cn,{className:"w-full h-9"}),u.jsx(cn,{className:"w-full h-9"}),u.jsx(cn,{className:"w-full h-9"}),u.jsx(cn,{className:"w-2/5 h-9"})]})})}),"LoginSkeleton"),xD=i(()=>{const e=Dn(),t=wn(),{darkModeLogo:n,title:r}=la(),{data:a,isPending:s}=ea({queryKey:["init"],queryFn:i(async()=>t.isInitialized(),"queryFn")}),{isPending:o,mutate:l}=qr({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=HY(),c=Ht(),{register:p,handleSubmit:m,formState:{isValid:v}}=vy({mode:"onChange"});if(s)return u.jsx(jie,{});if(a)return u.jsx(kw,{to:"/login"});const b=i(async w=>{l(w)},"onSubmit");return u.jsxs("div",{className:"h-screen p-8",children:[u.jsxs("div",{className:"flex items-center gap-4",children:[u.jsx("img",{src:n,alt:r,width:24,className:"filter brightness-0 invert"}),u.jsx("h1",{className:"text-xl font-semibold",children:r})]}),u.jsx("div",{className:"h-full",children:u.jsxs("div",{className:"max-w-sm mx-auto h-full flex flex-col justify-center gap-4",children:[u.jsx("h1",{className:"text-2xl font-bold mb-4",children:"Welcome to CRM"}),u.jsx("p",{className:"text-base mb-4",children:"Create the first user account to complete the setup."}),u.jsxs("form",{onSubmit:m(b),className:"space-y-4",children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx(Gn,{htmlFor:"first_name",children:"First name"}),u.jsx(Er,{...p("first_name",{required:!0}),id:"first_name",type:"text",required:!0})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx(Gn,{htmlFor:"last_name",children:"Last name"}),u.jsx(Er,{...p("last_name",{required:!0}),id:"last_name",type:"text",required:!0})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx(Gn,{htmlFor:"email",children:"Email"}),u.jsx(Er,{...p("email",{required:!0}),id:"email",type:"email",required:!0})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx(Gn,{htmlFor:"password",children:"Password"}),u.jsx(Er,{...p("password",{required:!0}),id:"password",type:"password",required:!0})]}),u.jsx("div",{className:"flex justify-between items-center mt-8",children:u.jsx(Le,{type:"submit",disabled:!v||o,className:"w-full",children:o?u.jsxs(u.Fragment,{children:[u.jsx(Dc,{className:"w-4 h-4 animate-spin mr-2"}),"Creating..."]}):"Create account"})})]})]})})]})},"SignupPage");xD.path="/sign-up";const nze=i((e,t)=>e==="admin"?!0:t.resource!=="sales","canAccess"),TT=PAe(qn,{getIdentity:i(async()=>{const e=await Cie();if(e==null)throw new Error;return{id:e.id,fullName:`${e.first_name} ${e.last_name}`,avatar:e.avatar?.src}},"getIdentity")});async function Jo(){if(Jo._is_initialized_cache==null){const{data:e}=await qn.from("init_state").select("is_initialized");Jo._is_initialized_cache=e?.at(0)?.is_initialized>0}return Jo._is_initialized_cache}i(Jo,"getIsInitialized");(e=>{e._is_initialized_cache=null})(Jo||(Jo={}));const rze={...TT,login:i(async e=>{const t=await TT.login(e);return Yb=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 Jo())throw await qn.auth.signOut(),{redirectTo:"/sign-up",message:!1};return TT.checkAuth(e)},"checkAuth"),canAccess:i(async e=>{if(!await Jo())return!1;const n=await Cie();if(n==null)return!1;const r=n.administrator?"admin":"user";return nze(r,e)},"canAccess")};let Yb;const Cie=i(async()=>{if(Yb!=null)return Yb;const{data:e,error:t}=await qn.auth.getSession();if(e?.session?.user==null||t)return;const{data:n,error:r}=await qn.from("sales").select("id, first_name, last_name, avatar, administrator").match({user_id:e?.session?.user.id}).single();if(!(n==null||r))return Yb=n,n},"getSaleFromCache");async function aze(e,t,n){const r={};t&&(r.id=t);const a={};t&&(a.company_id=t);const[s,o,l,f]=await Promise.all([ize(e,r),sze(e,a),oze(e,a),lze(e,a)]);return[...s,...o,...l,...f].sort((c,p)=>c.date&&p.date?c.date.localeCompare(p.date)*-1:0).slice(0,250)}i(aze,"getActivityLog");const ize=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 sze(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"}}),s=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})),o=a.map(l=>({id:`contactNote.${l.id}.created`,type:Jte,sales_id:l.sales_id,contactNote:l,date:l.date}));return[...s,...o]}i(sze,"getNewContactsAndNotes");async function oze(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"}}),s=n.map(l=>({id:`deal.${l.id}.created`,type:ene,company_id:l.company_id,sales_id:l.sales_id,deal:l,date:l.created_at})),o=a.map(l=>({id:`dealNote.${l.id}.created`,type:tne,sales_id:l.sales_id,dealNote:l,date:l.date}));return[...s,...o]}i(oze,"getNewDealsAndNotes");async function lze(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(s=>({id:`companyNote.${s.id}.created`,type:Xte,sales_id:s.sales_id,companyNote:s,date:s.date}))}i(lze,"getNewCompanyNotes");async function cze(e){return e.website?{src:`https://favicon.show/${e.website.replace(/^https?:\/\//,"").replace(/\/$/,"")}`,title:"Company favicon"}:null}i(cze,"getCompanyAvatar");async function uze(e,t={}){const{timeout:n=2e3}=t,r=new AbortController,a=setTimeout(()=>r.abort(),n),s=await fetch(e,{...t,signal:r.signal});return clearTimeout(a),s}i(uze,"fetchWithTimeout");const dze=["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 fze(e){const t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(s=>s.toString(16).padStart(2,"0")).join("")}i(fze,"hash");async function hze(e){return`https://www.gravatar.com/avatar/${await fze(e)}?d=404`}i(hze,"getGravatarUrl");async function pze(e){if(dze.includes(e))return null;try{const t=`https://${e}/favicon.ico`;if((await uze(t)).ok)return t}catch{return null}return null}i(pze,"getFaviconUrl");async function mze(e){if(!e.email_jsonb||!e.email_jsonb.length)return null;for(const{email:t}of e.email_jsonb){const n=await hze(t);try{if((await fetch(n)).ok)return n}catch{}const r=t.split("@")[1],a=await pze(r);if(a)return a}return null}i(mze,"getContactAvatar");const KW=Ed()||{url:"https://placeholder.supabase.co",anonKey:"placeholder-key"},Fa=XAe({instanceUrl:KW.url,apiKey:KW.anonKey,supabaseClient:qn,sortOrder:"asc,desc.nullslast"}),YW=i(async e=>{let t=e.data.logo;return typeof t!="object"||t===null||!t.src?t=await cze(e.data):t.rawFile instanceof File&&await Qb(t),{...e,data:{...e.data,logo:t}}},"processCompanyLogo");async function QW(e){const{data:t}=e;if(t.avatar?.src||!t.email_jsonb||!t.email_jsonb.length)return e;const n=await mze(t),r={...t,avatar:{src:n||void 0}};return{...e,data:r}}i(QW,"processContactAvatar");const gze={...Fa,async getList(e,t){return e==="companies"?Fa.getList("companies_summary",t):e==="contacts"?Fa.getList("contacts_summary",t):e==="tasks"?Fa.getList("tasks_summary",t):Fa.getList(e,t)},async getOne(e,t){return e==="companies"?Fa.getOne("companies_summary",t):e==="contacts"?Fa.getOne("contacts_summary",t):e==="tasks"?Fa.getOne("tasks_summary",t):Fa.getOne(e,t)},async update(e,t){if(e==="tasks"){const{contact_first_name:n,contact_last_name:r,contact_email:a,company_id:s,company_name:o,assigned_first_name:l,assigned_last_name:f,creator_first_name:c,creator_last_name:p,nb_notes:m,last_note_date:v,...b}=t.data;return Fa.update(e,{...t,data:b})}return Fa.update(e,t)},async signUp({email:e,password:t,first_name:n,last_name:r}){const{data:a,error:s}=await qn.functions.invoke("setup",{method:"POST",body:{email:e,password:t,first_name:n,last_name:r}});if(!a||s)throw console.error("signUp.error",s),new Error("Failed to create account");return Jo._is_initialized_cache=!0,{id:a.data.id,email:e,password:t}},async salesCreate(e){const{data:t,error:n}=await qn.functions.invoke("users",{method:"POST",body:e});if(!t||n)throw console.error("salesCreate.error",n),new Error("Failed to create account manager");return t},async salesUpdate(e,t){const{email:n,first_name:r,last_name:a,administrator:s,avatar:o,disabled:l}=t,{data:f,error:c}=await qn.functions.invoke("users",{method:"PATCH",body:{sales_id:e,email:n,first_name:r,last_name:a,administrator:s,disabled:l,avatar:o}});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 qn.functions.invoke("users",{method:"PUT",body:{sales_id:e,action:"invite"}});if(!t||n)throw console.error("resendInvite.error",n),new Error("Failed to resend invitation");return t},async resetPassword(e){const{data:t,error:n}=await qn.functions.invoke("users",{method:"PUT",body:{sales_id:e,action:"reset"}});if(!t||n)throw console.error("resetPassword.error",n),new Error("Failed to send password reset");return t},async updatePassword(e){const{data:t,error:n}=await qn.functions.invoke("updatePassword",{method:"PATCH",body:{sales_id:e}});if(!t||n)throw console.error("passwordUpdate.error",n),new Error("Failed to update password");return t},async unarchiveDeal(e){const{data:t}=await Fa.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=>Fa.update("deals",{id:r.id,data:r,previousData:t.find(a=>a.id===r.id)})))},async getActivityLog(e){return aze(Fa,e)},async isInitialized(){return Jo()},async mergeContacts(e,t){const{data:n,error:r}=await qn.functions.invoke("mergeContacts",{method:"POST",body:{loserId:e,winnerId:t}});if(r)throw console.error("mergeContacts.error",r),new Error("Failed to merge contacts");return n},async mergeCompanies(e,t){const{data:n,error:r}=await qn.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}},vze=Bhe(gze,[{resource:"contactNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await Qb(r);return e},"beforeSave")},{resource:"dealNotes",beforeSave:i(async(e,t,n)=>{if(e.attachments)for(const r of e.attachments)await Qb(r);return e},"beforeSave")},{resource:"sales",beforeSave:i(async(e,t,n)=>(e.avatar&&await Qb(e.avatar),e),"beforeSave")},{resource:"contacts",beforeCreate:i(async e=>QW(e),"beforeCreate"),beforeUpdate:i(async e=>QW(e),"beforeUpdate"),beforeGetList:i(async e=>wg(["first_name","last_name","company_name","title","email","phone","background"])(e),"beforeGetList")},{resource:"companies",beforeGetList:i(async e=>wg(["name","phone_number","website","zipcode","city","stateAbbr"])(e),"beforeGetList"),beforeCreate:i(async e=>{const t=await YW(e);return{...t,data:{...t.data,created_at:new Date().toISOString()}}},"beforeCreate"),beforeUpdate:i(async e=>await YW(e),"beforeUpdate")},{resource:"contacts_summary",beforeGetList:i(async e=>wg(["first_name","last_name"])(e),"beforeGetList")},{resource:"tasks",beforeGetList:i(async e=>wg(["text","contact_first_name"])(e),"beforeGetList")},{resource:"deals",beforeGetList:i(async e=>wg(["name","type","description"])(e),"beforeGetList")}]),wg=i(e=>t=>{if(!t.filter?.q)return t;const{q:n,...r}=t.filter;return{...t,filter:{...r,"@or":e.reduce((a,s)=>s==="email"?{...a,"email_fts@ilike":n}:s==="phone"?{...a,"phone_fts@ilike":n}:{...a,[`${s}@ilike`]:n},{})}}},"applyFullTextSearch"),Qb=i(async e=>{if(!e.src.startsWith("blob:")&&!e.src.startsWith("data:")&&e.path){const{error:c}=await qn.storage.from("attachments").createSignedUrl(e.path,60);if(!c)return}const t=e.src?await fetch(e.src).then(c=>c.blob()):e.rawFile,n=e.rawFile,r=n.name.split(".").pop(),s=`${`${Math.random()}.${r}`}`,{error:o}=await qn.storage.from("attachments").upload(s,t);if(o)throw console.error("uploadError",o),new Error("Failed to upload attachment");const{data:l}=qn.storage.from("attachments").getPublicUrl(s);e.path=s,e.src=l.publicUrl;const f=n.type;return e.type=f,e},"uploadToBucket");function Eie(){const{identity:e}=Yn(),t=Ft();return u.jsxs("div",{className:"space-y-4 w-full",children:[u.jsx(Ut,{source:"first_name",validate:Pn(),helperText:!1}),u.jsx(Ut,{source:"last_name",validate:Pn(),helperText:!1}),u.jsx(Ut,{source:"email",validate:[Pn(),EY()],helperText:!1}),u.jsx(ew,{source:"administrator",readOnly:t?.id===e?.id,helperText:!1}),u.jsx(ew,{source:"disabled",readOnly:t?.id===e?.id,helperText:!1})]})}i(Eie,"SalesInputs");function yze(){const e=wn(),t=Ht(),n=zi(),{mutate:r}=qr({mutationKey:["signup"],mutationFn:i(async s=>e.salesCreate(s),"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 s=>{r(s)},"onSubmit");return u.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:u.jsxs(un,{children:[u.jsx(ms,{children:u.jsx(gs,{children:"Create a new user"})}),u.jsx(Un,{children:u.jsx(zee,{onSubmit:a,children:u.jsx(Eie,{})})})]})})}i(yze,"SalesCreate");function bze(){return u.jsxs("div",{className:"flex justify-end gap-4",children:[u.jsx(t_,{}),u.jsx(jd,{})]})}i(bze,"EditToolbar");function xze(){const{record:e}=JK(),t=wn(),n=Ht(),r=zi(),{mutate:a}=qr({mutationKey:["signup"],mutationFn:i(async o=>{if(!e)throw new Error("Record not found");return t.salesUpdate(e.id,o)},"mutationFn"),onSuccess:i(()=>{r("/sales"),n("User updated successfully")},"onSuccess"),onError:i(()=>{n("An error occurred. Please try again.")},"onError")}),s=i(async o=>{a(o)},"onSubmit");return u.jsx("div",{className:"max-w-lg w-full mx-auto mt-8",children:u.jsx(un,{children:u.jsx(Un,{children:u.jsxs(zee,{toolbar:u.jsx(bze,{}),onSubmit:s,record:e,children:[u.jsx(wze,{}),u.jsx(Eie,{})]})})})})}i(xze,"SalesEdit");const wze=i(()=>{const e=Ft();return e?u.jsxs("h2",{className:"text-lg font-semibold mb-4",children:["Edit ",e?.first_name," ",e?.last_name]}):null},"SaleEditTitle"),_ze=i(()=>u.jsxs(X1,{children:[u.jsx(Ly,{}),u.jsx(dl,{label:"New user"})]}),"SalesListActions"),Sze=[u.jsx(e_,{source:"q",alwaysOn:!0})],jze=i(e=>{const t=Ft();return t?u.jsxs("div",{className:"flex flex-row gap-1",children:[t.administrator&&u.jsx(Kn,{variant:"outline",className:"border-blue-300 dark:border-blue-700",children:"Admin"}),t.disabled&&u.jsx(Kn,{variant:"outline",className:"border-orange-300 dark:border-orange-700",children:"Disabled"})]}):null},"OptionsField"),Cze=i(()=>{const e=Ft(),t=wn(),n=Ht(),r=Bw(),[a,s]=y.useState(!1),[o,l]=y.useState(!1),{mutate:f,isPending:c}=qr({mutationFn:i(async()=>t.resendInvite(e.id),"mutationFn"),onSuccess:i(()=>{n("Invitation email resent successfully"),s(!1),r()},"onSuccess"),onError:i(()=>{n("Failed to resend invitation email",{type:"error"}),s(!1)},"onError")}),{mutate:p,isPending:m}=qr({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:o}),u.jsxs(u.Fragment,{children:[u.jsxs(Fc,{children:[u.jsx(rl,{asChild:!0,children:u.jsxs(Le,{variant:"ghost",className:"h-8 w-8 p-0",children:[u.jsx("span",{className:"sr-only",children:"Open menu"}),u.jsx(XM,{className:"h-4 w-4"})]})}),u.jsxs(Lc,{align:"end",children:[u.jsx(T4,{children:"Email Actions"}),u.jsx(hv,{}),!v&&u.jsxs(sr,{onClick:i(w=>{w.preventDefault(),w.stopPropagation(),console.log("[Menu] Clicked Resend Invite"),s(!0)},"onClick"),children:[u.jsx(r_e,{className:"mr-2 h-4 w-4"}),"Resend Invite"]}),v&&!b&&u.jsxs(sr,{onClick:i(()=>l(!0),"onClick"),children:[u.jsx(j1e,{className:"mr-2 h-4 w-4"}),"Send Password Reset"]})]})]}),u.jsx(ga,{open:a,onOpenChange:s,children:u.jsxs(va,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Resend Invitation"}),u.jsxs(ui,{children:["Send a new invitation email to ",u.jsx("strong",{children:e.email}),"?",u.jsx("br",{}),u.jsx("br",{}),"This will send them a fresh invitation link to set up their account."]})]}),u.jsxs(ps,{children:[u.jsx(Le,{variant:"outline",onClick:i(w=>{w.stopPropagation(),s(!1)},"onClick"),disabled:c,children:"Cancel"}),u.jsx(Le,{onClick:i(w=>{w.stopPropagation(),f()},"onClick"),disabled:c,children:c?"Sending...":"Send Invitation"})]})]})}),u.jsx(ga,{open:o,onOpenChange:l,children:u.jsxs(va,{onClick:i(w=>w.stopPropagation(),"onClick"),onPointerDown:i(w=>w.stopPropagation(),"onPointerDown"),children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Send Password Reset"}),u.jsxs(ui,{children:["Send a password reset email to ",u.jsx("strong",{children:e.email}),"?",u.jsx("br",{}),u.jsx("br",{}),"This will send them a link to reset their password."]})]}),u.jsxs(ps,{children:[u.jsx(Le,{variant:"outline",onClick:i(w=>{w.stopPropagation(),l(!1)},"onClick"),disabled:m,children:"Cancel"}),u.jsx(Le,{onClick:i(w=>{w.stopPropagation(),p()},"onClick"),disabled:m,children:m?"Sending...":"Send Reset Link"})]})]})})]})},"RowActions");function Eze(){return u.jsx(Q1,{filters:Sze,actions:u.jsx(_ze,{}),sort:{field:"first_name",order:"ASC"},children:u.jsx(kze,{})})}i(Eze,"SalesList");const kze=i(()=>{const{data:e,isPending:t,filterValues:n}=Xn(),{identity:r}=Yn(),a=n&&Object.keys(n).length>0;return!r||t?u.jsx(un,{className:"p-4",children:u.jsxs("div",{className:"space-y-3",children:[u.jsx(cn,{className:"h-12 w-full"}),u.jsx(cn,{className:"h-12 w-full"}),u.jsx(cn,{className:"h-12 w-full"}),u.jsx(cn,{className:"h-12 w-full"}),u.jsx(cn,{className:"h-12 w-full"})]})}):!e?.length&&!a?u.jsx(Oze,{}):u.jsxs(sa,{children:[u.jsx(sa.Col,{source:"first_name"}),u.jsx(sa.Col,{source:"last_name"}),u.jsx(sa.Col,{source:"email"}),u.jsx(sa.Col,{label:!1,children:u.jsx(jze,{})}),u.jsx(sa.Col,{label:!1,children:u.jsx(Cze,{})})]})},"SalesListLayout"),Oze=i(()=>{const e=Z1();return u.jsxs("div",{className:"flex flex-col justify-center items-center gap-3",style:{height:`calc(100dvh - ${e}px)`},children:[u.jsx("img",{src:"./img/empty.svg",alt:"No users found"}),u.jsxs("div",{className:"flex flex-col gap-0 items-center",children:[u.jsx("h6",{className:"text-lg font-bold",children:"No users found"}),u.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"It seems your user list is empty."})]}),u.jsx("div",{className:"flex flex-row gap-2",children:u.jsx(dl,{label:"New user"})})]})},"SalesEmpty"),Rze={list:Eze,create:yze,edit:xze,recordRepresentation:i(e=>`${e.first_name} ${e.last_name}`,"recordRepresentation")};function XW(e){const t=e.trim();return t?t.startsWith("http://")||t.startsWith("https://")?t:`https://${t}.supabase.co`:""}i(XW,"normalizeSupabaseUrl");function Aze(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(Aze,"validateUrlFormat");function Tze(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(Tze,"validateKeyFormat");function kie({open:e,onComplete:t,canClose:n=!1}){const[r,a]=y.useState("welcome"),[s,o]=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=XW(s),R=l.trim(),A=await RAe(T,R);A.valid?(EAe({url:T,anonKey:R}),a("success"),setTimeout(()=>{window.location.href=window.location.origin},1500)):(p(A.error||"Connection failed"),a("credentials"))},"handleValidateAndSave"),_=s?Aze(s):{valid:!1},j=l?Tze(l):{valid:!1},C=s?XW(s):"",k=s&&!s.startsWith("http")&&_.valid,E=i(()=>{n&&t()},"handleClose");return u.jsx(ga,{open:e,onOpenChange:n?E:void 0,children:u.jsxs(va,{className:"sm:max-w-md",onPointerDownOutside:i(T=>!n&&T.preventDefault(),"onPointerDownOutside"),onEscapeKeyDown:i(T=>!n&&T.preventDefault(),"onEscapeKeyDown"),children:[r==="welcome"&&u.jsxs(u.Fragment,{children:[u.jsxs(Fr,{children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[u.jsx(ov,{className:"h-6 w-6 text-primary"}),u.jsx(Lr,{children:"Welcome to CRM"})]}),u.jsx(ui,{children:"To get started, you'll need to connect to a Supabase database."})]}),u.jsxs("div",{className:"space-y-4 py-4",children:[u.jsx(Ga,{children:u.jsxs(di,{children:[u.jsx("strong",{children:"Don't have a Supabase project?"}),u.jsx("br",{}),"Create one for free at"," ",u.jsxs("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline text-primary inline-flex items-center gap-1",children:["supabase.com",u.jsx(Wl,{className:"h-3 w-3"})]})]})}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("h4",{className:"font-medium text-sm",children:"What you'll need:"}),u.jsxs("ul",{className:"list-disc list-inside text-sm text-muted-foreground space-y-1",children:[u.jsx("li",{children:"Your Supabase project URL or project ID"}),u.jsx("li",{children:"Your API key (anon or publishable key)"})]})]}),u.jsx("div",{className:"space-y-2",children:u.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?",u.jsx(Wl,{className:"h-3 w-3"})]})}),u.jsx(Le,{onClick:i(()=>a("credentials"),"onClick"),className:"w-full",children:"Continue"})]})]}),r==="credentials"&&u.jsxs(u.Fragment,{children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Connect to Supabase"}),u.jsx(ui,{children:"Enter your Supabase project credentials"})]}),u.jsxs("div",{className:"space-y-4 py-4",children:[c&&u.jsxs(Ga,{variant:"destructive",children:[u.jsx(Lp,{className:"h-4 w-4"}),u.jsx(di,{children:c})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"supabase-url",children:"Project URL or ID"}),u.jsxs("div",{className:"relative",children:[u.jsx(Er,{id:"supabase-url",placeholder:"xxxxx or https://xxxxx.supabase.co",value:s,onChange:i(T=>{o(T.target.value),v(!0)},"onChange"),onBlur:i(()=>v(!0),"onBlur"),className:m&&s?_.valid?"pr-8 border-green-500":"pr-8 border-destructive":""}),m&&s&&_.valid&&u.jsx(ss,{className:"absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 text-green-500"})]}),k&&u.jsxs("div",{className:"flex items-start gap-1.5 text-xs text-green-600 dark:text-green-400",children:[u.jsx(ss,{className:"h-3 w-3 mt-0.5 flex-shrink-0"}),u.jsxs("span",{children:["Will expand to: ",C]})]}),m&&s&&_.message&&!_.valid&&u.jsx("p",{className:"text-xs text-destructive",children:_.message}),(!m||!s)&&u.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter full URL or just the project ID (from Project Settings → API)"})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"anon-key",children:"API Key"}),u.jsxs("div",{className:"relative",children:[u.jsx(Er,{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&&u.jsx(ss,{className:"absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 text-green-500"})]}),b&&l&&j.message&&u.jsx("p",{className:`text-xs ${j.valid?"text-green-600 dark:text-green-400":"text-destructive"}`,children:j.message}),(!b||!l)&&u.jsx("p",{className:"text-xs text-muted-foreground",children:"Anon or publishable key (from Project Settings → API)"})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Le,{variant:"outline",onClick:i(()=>a("welcome"),"onClick"),className:"flex-1",children:"Back"}),u.jsx(Le,{onClick:S,disabled:!_.valid||!j.valid,className:"flex-1",children:"Connect"})]})]})]}),r==="validating"&&u.jsxs(u.Fragment,{children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Validating Connection"}),u.jsx(ui,{children:"Testing your Supabase credentials..."})]}),u.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[u.jsx(Dc,{className:"h-12 w-12 animate-spin text-primary mb-4"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait..."})]})]}),r==="success"&&u.jsxs(u.Fragment,{children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:"Connection Successful!"}),u.jsx(ui,{children:"Your Supabase database is now connected"})]}),u.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[u.jsx(Vs,{className:"h-12 w-12 text-green-500 mb-4"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Reloading application..."})]})]})]})})}i(kie,"SupabaseSetupWizard");function Nze(){const[e,t]=y.useState(!1),n=Ed(),r=AAe(),a=i(()=>{confirm("Are you sure you want to clear the database configuration? The app will need to be reconfigured on next launch.")&&(kAe(),window.location.reload())},"handleClearConfig");return u.jsxs(u.Fragment,{children:[u.jsxs(un,{children:[u.jsxs(ms,{children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ov,{className:"h-5 w-5"}),u.jsx(gs,{children:"Database Connection"})]}),u.jsx(V4,{children:"Manage your Supabase database connection settings"})]}),u.jsx(Un,{className:"space-y-4",children:n?u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex items-start gap-3 p-4 border rounded-lg",children:[u.jsx(Vs,{className:"h-5 w-5 text-green-500 mt-0.5"}),u.jsxs("div",{className:"flex-1 space-y-1",children:[u.jsx("p",{className:"font-medium",children:"Connected"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:n.url}),n.configuredAt&&u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Configured on"," ",new Date(n.configuredAt).toLocaleDateString()]})]})]}),r==="env"&&u.jsxs(Ga,{children:[u.jsx(RN,{className:"h-4 w-4"}),u.jsx(di,{children:"Using configuration from environment variables. You can override this by setting up a new connection via the UI."})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsxs(Le,{variant:"outline",onClick:i(()=>t(!0),"onClick"),className:"flex-1",children:[u.jsx(RN,{className:"h-4 w-4 mr-2"}),"Change Connection"]}),r==="ui"&&u.jsxs(Le,{variant:"destructive",onClick:a,className:"flex-1",children:[u.jsx(wy,{className:"h-4 w-4 mr-2"}),"Clear Configuration"]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Pze,{className:"text-sm font-medium",children:"Anonymous Key"}),u.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)]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex items-start gap-3 p-4 border border-dashed rounded-lg",children:[u.jsx(uo,{className:"h-5 w-5 text-destructive mt-0.5"}),u.jsxs("div",{className:"flex-1 space-y-1",children:[u.jsx("p",{className:"font-medium",children:"Not Connected"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"No Supabase database is configured"})]})]}),u.jsx(Ga,{children:u.jsxs(di,{children:["Connect to a Supabase database to start using Atomic CRM. You can create a free project at"," ",u.jsx("a",{href:"https://supabase.com",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"supabase.com"})]})}),u.jsxs(Le,{onClick:i(()=>t(!0),"onClick"),className:"w-full",children:[u.jsx(ov,{className:"h-4 w-4 mr-2"}),"Connect to Supabase"]})]})})]}),u.jsx(kie,{open:e,onComplete:i(()=>t(!1),"onComplete"),canClose:!0})]})}i(Nze,"DatabaseSettings");function Pze({children:e,className:t}){return u.jsx("label",{className:t,children:e})}i(Pze,"Label");const wD=i(()=>u.jsx("div",{className:"max-w-lg mx-auto mt-8",children:u.jsx(Nze,{})}),"DatabasePage");wD.path="/database";const _D=i(()=>{const[e,t]=y.useState(!1),{identity:n,refetch:r}=Yn(),{data:a,refetch:s}=Hw("sales",{id:n?.id}),o=Ht(),l=wn(),{mutate:f}=qr({mutationKey:["signup"],mutationFn:i(async p=>{if(!n)throw new Error("Record not found");return l.salesUpdate(n.id,p)},"mutationFn"),onSuccess:i(()=>{r(),s(),t(!1),o("Your profile has been updated")},"onSuccess"),onError:i(p=>{o("An error occurred. Please try again",{type:"error"})},"onError")});if(!n)return null;const c=i(async p=>{f(p)},"handleOnSubmit");return u.jsx("div",{className:"max-w-lg mx-auto mt-8",children:u.jsx(zr,{onSubmit:c,record:a,children:u.jsx(Dze,{isEditMode:e,setEditMode:t})})})},"SettingsPage"),Dze=i(({isEditMode:e,setEditMode:t})=>{const n=Ht(),r=Ra(),a=Ft(),{identity:s,refetch:o}=Yn(),{isDirty:l}=gy(),f=wn(),{mutate:c}=qr({mutationKey:["signup"],mutationFn:i(async v=>{if(!a)throw new Error("Record not found");return f.salesUpdate(a.id,v)},"mutationFn"),onSuccess:i(()=>{o(),n("Your profile has been updated")},"onSuccess"),onError:i(()=>{n("An error occurred. Please try again.")},"onError")});if(!s)return null;const p=i(()=>{r("/change-password")},"handleClickOpenPasswordChange"),m=i(async v=>{c(v)},"handleAvatarUpdate");return u.jsxs("div",{className:"space-y-4",children:[u.jsx(un,{children:u.jsxs(Un,{children:[u.jsx("div",{className:"mb-4 flex flex-row justify-between",children:u.jsx("h2",{className:"text-xl font-semibold text-muted-foreground",children:"My info"})}),u.jsxs("div",{className:"space-y-4 mb-4",children:[u.jsx(Dte,{source:"avatar",type:"avatar",onSave:m,linkPosition:"right"}),u.jsx(NT,{source:"first_name",isEditMode:e}),u.jsx(NT,{source:"last_name",isEditMode:e}),u.jsx(NT,{source:"email",isEditMode:e})]}),u.jsxs("div",{className:"flex flex-row justify-end gap-2",children:[!e&&u.jsx(u.Fragment,{children:u.jsx(Le,{variant:"outline",type:"button",onClick:p,children:"Change password"})}),u.jsxs(Le,{type:"button",variant:e?"ghost":"outline",onClick:i(()=>t(!e),"onClick"),className:"flex items-center",children:[e?u.jsx(uo,{}):u.jsx(t4,{}),e?"Cancel":"Edit"]}),e&&u.jsxs(Le,{type:"submit",disabled:!l,variant:"outline",children:[u.jsx(v1,{}),"Save"]})]})]})}),void 0]})},"SettingsForm"),NT=i(({source:e,isEditMode:t})=>t?u.jsx(Ut,{source:e,helperText:!1}):u.jsx("div",{className:"m-2",children:u.jsx(u6e,{source:e})}),"TextRender");_D.path="/settings";function Oie(){const e=new Uint8Array(16);return crypto.getRandomValues(e),`ak_live_${Array.from(e).map(n=>n.toString(16).padStart(2,"0")).join("")}`}i(Oie,"generateApiKey");async function Mze(e){const n=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(r)).map(s=>s.toString(16).padStart(2,"0")).join("")}i(Mze,"hashApiKey");const Ize=[{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"}],Fze=i(({open:e,onClose:t})=>{const[n,r]=y.useState(null),[a,s]=y.useState(!1),o=wn(),l=Ht(),f=Dn(),{identity:c}=Yn(),{register:p,handleSubmit:m,watch:v,setValue:b,reset:w}=vy({defaultValues:{name:"",scopes:[],expires_at:""}}),S=qr({mutationFn:i(async k=>{const E=Oie(),T=await Mze(E),R=E.substring(0,12),{data:A}=await o.create("api_keys",{data:{name:k.name,key_hash:T,key_prefix:R,scopes:k.scopes,is_active:!0,expires_at:k.expires_at||null,sales_id:c?.id,created_by_sales_id:c?.id}});return{data:A,apiKey:E}},"mutationFn"),onSuccess:i(({apiKey:k})=>{r(k),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),s(!1),w(),t()},"handleClose"),j=i(()=>{n&&(navigator.clipboard.writeText(n),s(!0),setTimeout(()=>s(!1),2e3))},"copyApiKey"),C=i(k=>{const E=v("scopes");E.includes(k)?b("scopes",E.filter(T=>T!==k)):b("scopes",[...E,k])},"toggleScope");return u.jsx(ga,{open:e,onOpenChange:_,children:u.jsxs(va,{className:"sm:max-w-[500px]",children:[u.jsxs(Fr,{children:[u.jsx(Lr,{children:n?"API Key Created":"Create API Key"}),u.jsx(ui,{children:n?"Copy this key now - it won't be shown again!":"Create a new API key to access the CRM API"})]}),n?u.jsxs("div",{className:"space-y-4",children:[u.jsx(Ga,{children:u.jsx(di,{children:"Make sure to copy your API key now. You won't be able to see it again!"})}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{children:"Your API Key"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Er,{value:n,readOnly:!0,className:"font-mono text-sm"}),u.jsx(Le,{type:"button",variant:"outline",size:"icon",onClick:j,children:a?u.jsx(Vs,{className:"h-4 w-4 text-green-500"}):u.jsx(YM,{className:"h-4 w-4"})})]})]}),u.jsx("div",{className:"flex justify-end",children:u.jsx(Le,{onClick:_,children:"Done"})})]}):u.jsx("form",{onSubmit:m(k=>S.mutate(k)),children:u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"name",children:"Name"}),u.jsx(Er,{id:"name",placeholder:"e.g., Production API Key",...p("name",{required:!0})})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{children:"Scopes"}),u.jsx("div",{className:"space-y-2",children:Ize.map(k=>u.jsxs("div",{className:"flex items-center space-x-2",children:[u.jsx(Qp,{id:k.value,checked:v("scopes").includes(k.value),onCheckedChange:i(()=>C(k.value),"onCheckedChange")}),u.jsx("label",{htmlFor:k.value,className:"text-sm cursor-pointer",children:k.label})]},k.value))})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Gn,{htmlFor:"expires_at",children:"Expiration (optional)"}),u.jsx(Er,{id:"expires_at",type:"date",...p("expires_at")})]}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx(Le,{type:"button",variant:"outline",onClick:_,children:"Cancel"}),u.jsx(Le,{type:"submit",disabled:S.isPending,children:"Create"})]})]})})]})})},"CreateApiKeyDialog");var Lze=Symbol("radix.slottable");function $ze(e){const t=i(({children:n})=>u.jsx(u.Fragment,{children:n}),"Slottable2");return t.displayName=`${e}.Slottable`,t.__radixId=Lze,t}i($ze,"createSlottable");var Rie="AlertDialog",[qze,cHe]=oa(Rie,[pX]),hl=pX(),Aie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=hl(t);return u.jsx(jy,{...r,...n,modal:!0})},"AlertDialog$1");Aie.displayName=Rie;var Uze="AlertDialogTrigger",zze=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(AX,{...a,...r,ref:t})});zze.displayName=Uze;var Bze="AlertDialogPortal",Tie=i(e=>{const{__scopeAlertDialog:t,...n}=e,r=hl(t);return u.jsx(Cy,{...r,...n})},"AlertDialogPortal$1");Tie.displayName=Bze;var Hze="AlertDialogOverlay",Nie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(Ey,{...a,...r,ref:t})});Nie.displayName=Hze;var yh="AlertDialogContent",[Vze,Wze]=qze(yh),Gze=$ze("AlertDialogContent"),Pie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,children:r,...a}=e,s=hl(n),o=y.useRef(null),l=Xt(t,o),f=y.useRef(null);return u.jsx(_je,{contentName:yh,titleName:Die,docsSlug:"alert-dialog",children:u.jsx(Vze,{scope:n,cancelRef:f,children:u.jsxs(ky,{role:"alertdialog",...s,...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:[u.jsx(Gze,{children:r}),u.jsx(Yze,{contentRef:o})]})})})});Pie.displayName=yh;var Die="AlertDialogTitle",Mie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(_1,{...a,...r,ref:t})});Mie.displayName=Die;var Iie="AlertDialogDescription",Fie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(S1,{...a,...r,ref:t})});Fie.displayName=Iie;var Kze="AlertDialogAction",Lie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,a=hl(n);return u.jsx(Oy,{...a,...r,ref:t})});Lie.displayName=Kze;var $ie="AlertDialogCancel",qie=y.forwardRef((e,t)=>{const{__scopeAlertDialog:n,...r}=e,{cancelRef:a}=Wze($ie,n),s=hl(n),o=Xt(t,a);return u.jsx(Oy,{...s,...r,ref:o})});qie.displayName=$ie;var Yze=i(({contentRef:e})=>{const t=`\`${yh}\` requires a description for the component to be accessible for screen reader users.
155
155
 
156
156
  You can add a description to the \`${yh}\` by passing a \`${Iie}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
157
157
 
@@ -161,6 +161,6 @@ For more information, see https://radix-ui.com/primitives/docs/components/alert-
161
161
  border-2 border-dashed rounded-lg p-12 text-center cursor-pointer
162
162
  transition-all duration-200
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
- `,children:[u.jsx("input",{...m()}),u.jsx(ZQ,{className:"w-12 h-12 mx-auto mb-4 text-gray-400"}),v?u.jsx("p",{className:"text-lg font-medium",children:"Drop files here..."}):u.jsxs(u.Fragment,{children:[u.jsx("p",{className:"text-lg font-medium mb-2",children:"Drag & drop files here, or click to select"}),u.jsx("p",{className:"text-sm text-gray-500",children:"Supports all file types (executables blocked for security)"})]})]}),e.length>0&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("h3",{className:"font-medium",children:["Files (",e.length,")"]}),u.jsxs("div",{className:"space-x-2",children:[u.jsx(Le,{size:"sm",onClick:w,disabled:!e.some(j=>j.status==="pending"),children:"Upload All"}),u.jsx(Le,{size:"sm",variant:"outline",onClick:S,disabled:!e.some(j=>j.status==="success"),children:"Clear Completed"})]})]}),u.jsx("div",{className:"space-y-2",children:e.map((j,C)=>u.jsxs("div",{className:"border rounded-lg p-4 space-y-2",children:[u.jsxs("div",{className:"flex items-start justify-between gap-4",children:[u.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[u.jsx(c1e,{className:"w-5 h-5 mt-0.5 flex-shrink-0 text-gray-400"}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("p",{className:"font-medium truncate",children:j.file.name}),u.jsxs("p",{className:"text-sm text-gray-500",children:[_(j.file.size),j.activityId&&u.jsxs("span",{className:"ml-2 text-xs",children:["ID: ",j.activityId.substring(0,8),"..."]})]})]})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[j.status==="pending"&&u.jsx(Le,{size:"sm",onClick:i(()=>b(C),"onClick"),children:"Upload"}),j.status==="uploading"&&u.jsx(Dc,{className:"w-5 h-5 animate-spin text-primary"}),j.status==="success"&&u.jsx(Vs,{className:"w-5 h-5 text-green-500"}),j.status==="error"&&u.jsx(uo,{className:"w-5 h-5 text-red-500"})]})]}),j.status==="uploading"&&u.jsx(d_,{value:j.progress,className:"h-1"}),j.status==="error"&&j.error&&u.jsxs("p",{className:"text-sm text-red-500",children:["Error: ",j.error]})]},C))})]})]})]}),u.jsxs(un,{children:[u.jsx(ms,{children:u.jsx(gs,{className:"text-base",children:"How it works"})}),u.jsxs(Un,{className:"text-sm text-gray-600 space-y-2",children:[u.jsx("p",{children:"• Files are uploaded directly to secure storage (no database bloat)"}),u.jsx("p",{children:"• Each file creates an activity record for tracking and search"}),u.jsx("p",{children:"• Large files are handled automatically (no size limits)"}),u.jsx("p",{children:"• Files are linked to your selected ingestion channel"}),u.jsx("p",{children:"• Activities appear in the Activity Feed immediately"})]})]})]})},"FileUpload"),SD=i(()=>u.jsxs("div",{className:"max-w-6xl mx-auto mt-8 px-4",children:[u.jsxs("div",{className:"mb-6",children:[u.jsx("h1",{className:"text-3xl font-bold",children:"Integrations"}),u.jsx("p",{className:"text-muted-foreground mt-2",children:"Manage API keys, webhooks, and ingestion channels to integrate Atomic CRM with external systems."})]}),u.jsxs(Gte,{defaultValue:"ingestion",children:[u.jsxs(Kte,{className:"mb-4",children:[u.jsx(cc,{value:"ingestion",children:"Ingestion Channels"}),u.jsx(cc,{value:"file-upload",children:"File Upload"}),u.jsx(cc,{value:"api-keys",children:"API Keys"}),u.jsx(cc,{value:"webhooks",children:"Webhooks (Outbound)"})]}),u.jsx(uc,{value:"ingestion",children:u.jsx(hBe,{})}),u.jsx(uc,{value:"file-upload",children:u.jsx(mBe,{})}),u.jsx(uc,{value:"api-keys",children:u.jsx(sBe,{})}),u.jsx(uc,{value:"webhooks",children:u.jsx(cBe,{})})]})]}),"IntegrationsPage");SD.path="/integrations";const gBe=i(()=>{const{identity:e}=Yn(),{taskTypes:t,taskPriorities:n,taskStatuses:r}=la(),a=Ht(),s=zi(),o=i(()=>{a("Task created"),s("list","tasks")},"handleSuccess");return u.jsx("div",{className:"mt-4 max-w-2xl mx-auto",children:u.jsxs(un,{children:[u.jsx(ms,{children:u.jsx(gs,{children:"Create Task"})}),u.jsx(Un,{children:u.jsx(L5e,{resource:"tasks",redirect:"list",mutationOptions:{onSuccess:o},transform:i(l=>({...l,sales_id:e?.id,created_at:new Date().toISOString(),updated_at:new Date().toISOString()}),"transform"),children:u.jsxs(zr,{defaultValues:{due_date:new Date().toISOString().slice(0,10),priority:"medium",status:"todo",assigned_to:e?.id},children:[u.jsx(Ut,{autoFocus:!0,source:"text",label:"Description",validate:Pn(),multiline:!0,className:"w-full"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 mt-4",children:[u.jsx(ro,{source:"contact_id",reference:"contacts_summary",children:u.jsx(Od,{label:"Contact",optionText:tw,validate:Pn()})}),u.jsx(d3,{source:"due_date",validate:Pn()}),u.jsx(or,{source:"type",validate:Pn(),choices:t.map(l=>({id:l,name:l}))}),u.jsx(or,{source:"priority",choices:n}),u.jsx(or,{source:"status",choices:r}),u.jsx(ro,{source:"assigned_to",reference:"sales",children:u.jsx(or,{optionText:i(l=>`${l.first_name} ${l.last_name}`,"optionText"),label:"Assigned To"})})]}),u.jsx(o3,{})]})})})]})})},"TaskCreate"),vBe=i(({source:e="assigned_to",label:t="My Tasks"})=>{const{filterValues:n,displayedFilters:r,setFilters:a}=Hme(),{identity:s}=Yn(),o=i(()=>{const l={...n};typeof n[e]<"u"?delete l[e]:l[e]=s&&s?.id,a(l,r)},"handleChange");return u.jsx("div",{className:"mt-auto pb-2.25",children:u.jsxs("div",{className:"flex items-center space-x-2",children:[u.jsx(l3,{id:"my-tasks",checked:typeof n[e]<"u",onCheckedChange:o}),u.jsx(Gn,{htmlFor:"my-tasks",children:t})]})})},"MyTasksInput"),yBe={low:"bg-slate-500 hover:bg-slate-600",medium:"bg-blue-500 hover:bg-blue-600",high:"bg-orange-500 hover:bg-orange-600",urgent:"bg-red-500 hover:bg-red-600"},Uie=i(({priority:e})=>{if(!e)return null;const t=yBe[e]||"bg-slate-500";return u.jsx(Kn,{className:xe("capitalize",t),children:e})},"TaskPriorityBadge"),bBe={todo:"bg-slate-500 hover:bg-slate-600",in_progress:"bg-blue-500 hover:bg-blue-600",blocked:"bg-red-500 hover:bg-red-600",done:"bg-green-500 hover:bg-green-600",cancelled:"bg-gray-400 hover:bg-gray-500"},zie=i(({status:e})=>{if(!e)return null;const t=bBe[e]||"bg-slate-500";return u.jsx(Kn,{className:xe("capitalize",t),children:e.replace("_"," ")})},"TaskStatusBadge"),xBe=i(()=>u.jsxs(sa,{rowClick:"show",children:[u.jsx(sa.Col,{source:"text",label:"Task",className:"w-[35%]",cellClassName:"max-w-md",render:i(e=>u.jsxs("div",{className:"truncate",title:e.text,children:[e.type&&e.type!=="None"&&u.jsxs("span",{className:"font-semibold",children:[e.type,": "]}),e.text]}),"render")}),u.jsx(sa.Col,{label:"Contact",className:"w-[15%]",children:u.jsx(xn,{source:"contact_id",reference:"contacts",link:"show"})}),u.jsx(sa.Col,{label:"Company",className:"w-[15%]",children:u.jsx(xn,{source:"company_id",reference:"companies",link:"show",sortable:!1,children:u.jsx(Ir,{source:"name"})})}),u.jsx(sa.Col,{label:"Due Date",className:"w-[12%]",children:u.jsx(cd,{source:"due_date"})}),u.jsx(sa.Col,{label:"Priority",className:"w-[10%]",render:i(e=>u.jsx(Uie,{priority:e.priority}),"render")}),u.jsx(sa.Col,{label:"Status",className:"w-[10%]",render:i(e=>u.jsx(zie,{status:e.status}),"render")}),u.jsx(sa.Col,{label:"Assigned To",className:"w-[13%]",children:u.jsx(xn,{source:"assigned_to",reference:"sales",link:!1})})]}),"TaskListTable"),wBe=i(()=>{const{taskStatuses:e,taskPriorities:t}=la(),n=[u.jsx(e_,{source:"q",alwaysOn:!0}),u.jsx(or,{source:"status",choices:e,alwaysOn:!0}),u.jsx(ro,{source:"contact_id",reference:"contacts",children:u.jsx(Od,{label:!1,placeholder:"Contact"})}),u.jsx(or,{source:"priority",choices:t}),u.jsx(vBe,{source:"assigned_to",label:"My Tasks",alwaysOn:!0}),u.jsx(ew,{source:"archived",label:"Archived"})];return u.jsx(Q1,{perPage:25,sort:{field:"due_date",order:"ASC"},filters:n,filterDefaultValues:{archived:!1},actions:u.jsx(_Be,{}),title:"Tasks",children:u.jsx(xBe,{})})},"TaskList"),_Be=i(()=>u.jsxs(X1,{children:[u.jsx(Iee,{}),u.jsx(Ly,{}),u.jsx(dl,{label:"New Task"})]}),"TaskActions"),SBe=i(()=>{const e=Ft(),[t,n]=y.useState(!1);return e?u.jsxs("div",{className:"hidden sm:block w-64 min-w-64 text-sm",children:[u.jsx("div",{className:"mb-4 -ml-1",children:u.jsxs(Le,{variant:"outline",size:"sm",onClick:i(()=>n(!0),"onClick"),className:"flex items-center gap-2",children:[u.jsx(t4,{className:"h-4 w-4"}),"Edit Task"]})}),u.jsx(Zne,{open:t,close:i(()=>n(!1),"close"),taskId:e.id}),u.jsxs(fi,{title:"Task Info",children:[u.jsx($f,{icon:u.jsx(kN,{className:"w-4 h-4 text-muted-foreground"}),label:"Due Date",value:u.jsx(cd,{source:"due_date"})}),e.done_date&&u.jsx($f,{icon:u.jsx(kN,{className:"w-4 h-4 text-muted-foreground"}),label:"Completed",value:u.jsx(cd,{source:"done_date"})})]}),u.jsxs(fi,{title:"Related",children:[u.jsx($f,{icon:u.jsx(pz,{className:"w-4 h-4 text-muted-foreground"}),label:"Contact",value:u.jsx(xn,{source:"contact_id",reference:"contacts",link:"show"})}),u.jsx($f,{icon:u.jsx(wwe,{className:"w-4 h-4 text-muted-foreground"}),label:"Company",value:u.jsx(xn,{source:"contact_id",reference:"contacts",link:!1,children:u.jsx(xn,{source:"company_id",reference:"companies",link:"show",children:u.jsx(Ir,{source:"name"})})})})]}),u.jsxs(fi,{title:"Assignment",children:[u.jsx($f,{icon:u.jsx(A_e,{className:"w-4 h-4 text-muted-foreground"}),label:"Assigned To",value:u.jsx(xn,{source:"assigned_to",reference:"sales",link:!1})}),u.jsx($f,{icon:u.jsx(pz,{className:"w-4 h-4 text-muted-foreground"}),label:"Created By",value:u.jsx(xn,{source:"sales_id",reference:"sales",link:!1})})]}),u.jsx("div",{className:"mt-6 pt-6 border-t hidden sm:flex flex-col gap-2 items-start",children:u.jsx(c_,{className:"h-6 cursor-pointer hover:bg-destructive/10! text-destructive! border-destructive! focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",size:"sm"})})]}):null},"TaskAside"),$f=i(({icon:e,label:t,value:n})=>u.jsxs("div",{className:"flex flex-col gap-1 mb-3",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[e,u.jsx("span",{className:"text-xs text-muted-foreground",children:t})]}),u.jsx("div",{className:"pl-6 text-sm",children:n})]}),"InfoRow"),jBe=i(({taskId:e})=>{const{data:t,isPending:n}=pa("task_activity",{filter:{task_id:e},pagination:{page:1,perPage:100},sort:{field:"created_at",order:"DESC"}});return n?u.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Loading activity..."}):!t||t.length===0?u.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"No activity recorded."}):u.jsx("div",{className:"space-y-6 relative pl-4 border-l border-border ml-2 my-4",children:t.map(r=>u.jsxs("div",{className:"relative",children:[u.jsx("div",{className:"absolute -left-[21px] top-1 h-3 w-3 rounded-full bg-primary ring-4 ring-background"}),u.jsxs("div",{className:"text-sm",children:[u.jsx(xn,{source:"sales_id",record:r,reference:"sales",link:!1,children:u.jsx(CBe,{})})," ",EBe(r)]}),u.jsx("div",{className:"text-xs text-muted-foreground",children:nd(new Date(r.created_at),new Date,{addSuffix:!0})})]},r.id))})},"TaskActivityTimeline"),CBe=i(()=>{const e=Ft();return e?u.jsxs("span",{className:"font-semibold",children:[e.first_name," ",e.last_name]}):null},"SaleName"),EBe=i(e=>{switch(e.action){case"created":return"created this task";case"updated":return e.field_name?`changed ${e.field_name}`:"updated this task";case"assigned":return"assigned this task";case"completed":return"completed this task";case"reopened":return"reopened this task";case"duplicated":return"duplicated this task";case"archived":return"archived this task";default:return e.action}},"formatActivityMessage"),kBe=i(()=>u.jsx(DM,{children:u.jsx(OBe,{})}),"TaskShow"),OBe=i(()=>{const{record:e,isPending:t}=MM();return t||!e?null:u.jsxs("div",{className:"mt-2 mb-2 flex gap-8",children:[u.jsx("div",{className:"flex-1",children:u.jsx(un,{children:u.jsxs(Un,{children:[u.jsxs("div",{className:"mb-6",children:[u.jsx("h5",{className:"text-xl font-semibold mb-3",children:e.type}),u.jsxs("div",{className:"flex gap-3 mb-4",children:[u.jsx(zie,{status:e.status}),u.jsx(Uie,{priority:e.priority})]}),e.text&&u.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-line",children:e.text})]}),u.jsxs("div",{className:"mt-8",children:[u.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Activity Timeline"}),u.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Track all status changes and updates for this task"}),u.jsx(jBe,{taskId:e.id})]}),u.jsxs("div",{className:"mt-8",children:[u.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Notes"}),u.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Add notes and updates to this task"}),u.jsx(Gu,{reference:"taskNotes",target:"task_id",sort:{field:"date",order:"DESC"},empty:u.jsx(l_,{reference:"tasks",showStatus:!0,className:"mt-4"}),children:u.jsx(a3,{reference:"tasks",showStatus:!0})})]})]})})}),u.jsx(SBe,{})]})},"TaskShowContent"),RBe={list:wBe,show:kBe,create:gBe};var ABe={"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 TBe={"ra-supabase":{auth:{password_reset:"Check your emails for a Reset Password message."}}},NBe=AQ(()=>Ofe(vQ,ABe,TBe),"en",[{locale:"en",name:"English"}],{allowMissing:!0}),PBe=i(()=>{const e=wn(),{data:t,error:n,isPending:r}=ea({queryKey:["init"],queryFn:i(async()=>e.isInitialized(),"queryFn")});return r?u.jsx(jie,{}):n?u.jsx(Tx,{}):t?u.jsx(Tx,{}):u.jsx(kw,{to:"/sign-up"})},"StartPage");async function DBe(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(DBe,"checkDatabaseHealth");function MBe({missingTables:e,supabaseUrl:t}){const n=t.match(/https:\/\/([^.]+)\.supabase\.co/)?.[1];return u.jsxs("div",{className:"max-w-2xl mx-auto mt-8 space-y-4",children:[u.jsxs(Ga,{variant:"destructive",children:[u.jsx(Lp,{className:"h-4 w-4"}),u.jsx(n3,{children:"Database Schema Not Configured"}),u.jsx(di,{children:"Your Supabase database is connected, but the CRM schema hasn't been set up yet."})]}),u.jsxs(un,{children:[u.jsxs(ms,{children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ov,{className:"h-5 w-5"}),u.jsx(gs,{children:"Setup Instructions"})]}),u.jsx(V4,{children:"Follow these steps to set up your database schema"})]}),u.jsxs(Un,{className:"space-y-6",children:[u.jsxs("div",{children:[u.jsx("h3",{className:"font-semibold mb-2",children:"Missing Tables:"}),u.jsx("div",{className:"flex flex-wrap gap-2",children:e.map(r=>u.jsx("span",{className:"px-2 py-1 bg-destructive/10 text-destructive text-sm rounded",children:r},r))})]}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.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"}),u.jsx("h3",{className:"font-semibold",children:"Using Supabase CLI (Recommended)"})]}),u.jsxs("div",{className:"ml-8 space-y-3",children:[u.jsxs("div",{children:[u.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Install Supabase CLI:"}),u.jsx("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:"npm install -g supabase"})]}),u.jsxs("div",{children:[u.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Clone the RealTimeX CRM repository to get migrations:"}),u.jsxs("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:["git clone https://github.com/therealtimex/realtimex-crm.git",`
164
+ `,children:[u.jsx("input",{...m()}),u.jsx(ZQ,{className:"w-12 h-12 mx-auto mb-4 text-gray-400"}),v?u.jsx("p",{className:"text-lg font-medium",children:"Drop files here..."}):u.jsxs(u.Fragment,{children:[u.jsx("p",{className:"text-lg font-medium mb-2",children:"Drag & drop files here, or click to select"}),u.jsx("p",{className:"text-sm text-gray-500",children:"Supports all file types (executables blocked for security)"})]})]}),e.length>0&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("h3",{className:"font-medium",children:["Files (",e.length,")"]}),u.jsxs("div",{className:"space-x-2",children:[u.jsx(Le,{size:"sm",onClick:w,disabled:!e.some(j=>j.status==="pending"),children:"Upload All"}),u.jsx(Le,{size:"sm",variant:"outline",onClick:S,disabled:!e.some(j=>j.status==="success"),children:"Clear Completed"})]})]}),u.jsx("div",{className:"space-y-2",children:e.map((j,C)=>u.jsxs("div",{className:"border rounded-lg p-4 space-y-2",children:[u.jsxs("div",{className:"flex items-start justify-between gap-4",children:[u.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[u.jsx(c1e,{className:"w-5 h-5 mt-0.5 flex-shrink-0 text-gray-400"}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("p",{className:"font-medium truncate",children:j.file.name}),u.jsxs("p",{className:"text-sm text-gray-500",children:[_(j.file.size),j.activityId&&u.jsxs("span",{className:"ml-2 text-xs",children:["ID: ",j.activityId.substring(0,8),"..."]})]})]})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[j.status==="pending"&&u.jsx(Le,{size:"sm",onClick:i(()=>b(C),"onClick"),children:"Upload"}),j.status==="uploading"&&u.jsx(Dc,{className:"w-5 h-5 animate-spin text-primary"}),j.status==="success"&&u.jsx(Vs,{className:"w-5 h-5 text-green-500"}),j.status==="error"&&u.jsx(uo,{className:"w-5 h-5 text-red-500"})]})]}),j.status==="uploading"&&u.jsx(d_,{value:j.progress,className:"h-1"}),j.status==="error"&&j.error&&u.jsxs("p",{className:"text-sm text-red-500",children:["Error: ",j.error]})]},C))})]})]})]}),u.jsxs(un,{children:[u.jsx(ms,{children:u.jsx(gs,{className:"text-base",children:"How it works"})}),u.jsxs(Un,{className:"text-sm text-gray-600 space-y-2",children:[u.jsx("p",{children:"• Files are uploaded directly to secure storage (no database bloat)"}),u.jsx("p",{children:"• Each file creates an activity record for tracking and search"}),u.jsx("p",{children:"• Large files are handled automatically (no size limits)"}),u.jsx("p",{children:"• Files are linked to your selected ingestion channel"}),u.jsx("p",{children:"• Activities appear in the Activity Feed immediately"})]})]})]})},"FileUpload"),SD=i(()=>u.jsxs("div",{className:"max-w-6xl mx-auto mt-8 px-4",children:[u.jsxs("div",{className:"mb-6",children:[u.jsx("h1",{className:"text-3xl font-bold",children:"Integrations"}),u.jsx("p",{className:"text-muted-foreground mt-2",children:"Manage API keys, webhooks, and ingestion channels to integrate Atomic CRM with external systems."})]}),u.jsxs(Gte,{defaultValue:"ingestion",children:[u.jsxs(Kte,{className:"mb-4",children:[u.jsx(cc,{value:"ingestion",children:"Ingestion Channels"}),u.jsx(cc,{value:"file-upload",children:"File Upload"}),u.jsx(cc,{value:"api-keys",children:"API Keys"}),u.jsx(cc,{value:"webhooks",children:"Webhooks (Outbound)"})]}),u.jsx(uc,{value:"ingestion",children:u.jsx(hBe,{})}),u.jsx(uc,{value:"file-upload",children:u.jsx(mBe,{})}),u.jsx(uc,{value:"api-keys",children:u.jsx(sBe,{})}),u.jsx(uc,{value:"webhooks",children:u.jsx(cBe,{})})]})]}),"IntegrationsPage");SD.path="/integrations";const gBe=i(()=>{const{identity:e}=Yn(),{taskTypes:t,taskPriorities:n,taskStatuses:r}=la(),a=Ht(),s=zi(),o=i(()=>{a("Task created"),s("list","tasks")},"handleSuccess");return u.jsx("div",{className:"mt-4 max-w-2xl mx-auto",children:u.jsxs(un,{children:[u.jsx(ms,{children:u.jsx(gs,{children:"Create Task"})}),u.jsx(Un,{children:u.jsx(L5e,{resource:"tasks",redirect:"list",mutationOptions:{onSuccess:o},transform:i(l=>({...l,sales_id:e?.id,created_at:new Date().toISOString(),updated_at:new Date().toISOString()}),"transform"),children:u.jsxs(zr,{defaultValues:{due_date:new Date().toISOString().slice(0,10),priority:"medium",status:"todo",assigned_to:e?.id},children:[u.jsx(Ut,{autoFocus:!0,source:"text",label:"Description",validate:Pn(),multiline:!0,className:"w-full"}),u.jsxs("div",{className:"grid grid-cols-2 gap-4 mt-4",children:[u.jsx(ro,{source:"contact_id",reference:"contacts_summary",children:u.jsx(Od,{label:"Contact",optionText:tw,validate:Pn()})}),u.jsx(d3,{source:"due_date",validate:Pn()}),u.jsx(or,{source:"type",validate:Pn(),choices:t.map(l=>({id:l,name:l}))}),u.jsx(or,{source:"priority",choices:n}),u.jsx(or,{source:"status",choices:r}),u.jsx(ro,{source:"assigned_to",reference:"sales",children:u.jsx(or,{optionText:i(l=>`${l.first_name} ${l.last_name}`,"optionText"),label:"Assigned To"})})]}),u.jsx(o3,{})]})})})]})})},"TaskCreate"),vBe=i(({source:e="assigned_to",label:t="My Tasks"})=>{const{filterValues:n,displayedFilters:r,setFilters:a}=Hme(),{identity:s}=Yn(),o=i(()=>{const l={...n};typeof n[e]<"u"?delete l[e]:l[e]=s&&s?.id,a(l,r)},"handleChange");return u.jsx("div",{className:"mt-auto pb-2.25",children:u.jsxs("div",{className:"flex items-center space-x-2",children:[u.jsx(l3,{id:"my-tasks",checked:typeof n[e]<"u",onCheckedChange:o}),u.jsx(Gn,{htmlFor:"my-tasks",children:t})]})})},"MyTasksInput"),yBe={low:"bg-slate-500 hover:bg-slate-600",medium:"bg-blue-500 hover:bg-blue-600",high:"bg-orange-500 hover:bg-orange-600",urgent:"bg-red-500 hover:bg-red-600"},Uie=i(({priority:e})=>{if(!e)return null;const t=yBe[e]||"bg-slate-500";return u.jsx(Kn,{className:xe("capitalize",t),children:e})},"TaskPriorityBadge"),bBe={todo:"bg-slate-500 hover:bg-slate-600",in_progress:"bg-blue-500 hover:bg-blue-600",blocked:"bg-red-500 hover:bg-red-600",done:"bg-green-500 hover:bg-green-600",cancelled:"bg-gray-400 hover:bg-gray-500"},zie=i(({status:e})=>{if(!e)return null;const t=bBe[e]||"bg-slate-500";return u.jsx(Kn,{className:xe("capitalize",t),children:e.replace("_"," ")})},"TaskStatusBadge"),xBe=i(()=>u.jsxs(sa,{rowClick:"show",children:[u.jsx(sa.Col,{source:"text",label:"Task",className:"w-[35%]",cellClassName:"max-w-md",render:i(e=>u.jsxs("div",{className:"line-clamp-2",title:e.text,children:[e.type&&e.type!=="None"&&u.jsxs("span",{className:"font-semibold",children:[e.type,": "]}),e.text]}),"render")}),u.jsx(sa.Col,{label:"Contact",className:"w-[15%]",children:u.jsx(xn,{source:"contact_id",reference:"contacts",link:"show"})}),u.jsx(sa.Col,{label:"Company",className:"w-[15%]",children:u.jsx(xn,{source:"company_id",reference:"companies",link:"show",sortable:!1,children:u.jsx(Ir,{source:"name"})})}),u.jsx(sa.Col,{label:"Due Date",className:"w-[12%]",children:u.jsx(cd,{source:"due_date"})}),u.jsx(sa.Col,{label:"Priority",className:"w-[10%]",render:i(e=>u.jsx(Uie,{priority:e.priority}),"render")}),u.jsx(sa.Col,{label:"Status",className:"w-[10%]",render:i(e=>u.jsx(zie,{status:e.status}),"render")}),u.jsx(sa.Col,{label:"Assigned To",className:"w-[13%]",children:u.jsx(xn,{source:"assigned_to",reference:"sales",link:!1})})]}),"TaskListTable"),wBe=i(()=>{const{taskStatuses:e,taskPriorities:t}=la(),n=[u.jsx(e_,{source:"q",alwaysOn:!0}),u.jsx(or,{source:"status",choices:e,alwaysOn:!0}),u.jsx(ro,{source:"contact_id",reference:"contacts",children:u.jsx(Od,{label:!1,placeholder:"Contact"})}),u.jsx(or,{source:"priority",choices:t}),u.jsx(vBe,{source:"assigned_to",label:"My Tasks",alwaysOn:!0}),u.jsx(ew,{source:"archived",label:"Archived"})];return u.jsx(Q1,{perPage:25,sort:{field:"due_date",order:"ASC"},filters:n,filterDefaultValues:{archived:!1},actions:u.jsx(_Be,{}),title:"Tasks",children:u.jsx(xBe,{})})},"TaskList"),_Be=i(()=>u.jsxs(X1,{children:[u.jsx(Iee,{}),u.jsx(Ly,{}),u.jsx(dl,{label:"New Task"})]}),"TaskActions"),SBe=i(()=>{const e=Ft(),[t,n]=y.useState(!1);return e?u.jsxs("div",{className:"hidden sm:block w-64 min-w-64 text-sm",children:[u.jsx("div",{className:"mb-4 -ml-1",children:u.jsxs(Le,{variant:"outline",size:"sm",onClick:i(()=>n(!0),"onClick"),className:"flex items-center gap-2",children:[u.jsx(t4,{className:"h-4 w-4"}),"Edit Task"]})}),u.jsx(Zne,{open:t,close:i(()=>n(!1),"close"),taskId:e.id}),u.jsxs(fi,{title:"Task Info",children:[u.jsx($f,{icon:u.jsx(kN,{className:"w-4 h-4 text-muted-foreground"}),label:"Due Date",value:u.jsx(cd,{source:"due_date"})}),e.done_date&&u.jsx($f,{icon:u.jsx(kN,{className:"w-4 h-4 text-muted-foreground"}),label:"Completed",value:u.jsx(cd,{source:"done_date"})})]}),u.jsxs(fi,{title:"Related",children:[u.jsx($f,{icon:u.jsx(pz,{className:"w-4 h-4 text-muted-foreground"}),label:"Contact",value:u.jsx(xn,{source:"contact_id",reference:"contacts",link:"show"})}),u.jsx($f,{icon:u.jsx(wwe,{className:"w-4 h-4 text-muted-foreground"}),label:"Company",value:u.jsx(xn,{source:"contact_id",reference:"contacts",link:!1,children:u.jsx(xn,{source:"company_id",reference:"companies",link:"show",children:u.jsx(Ir,{source:"name"})})})})]}),u.jsxs(fi,{title:"Assignment",children:[u.jsx($f,{icon:u.jsx(A_e,{className:"w-4 h-4 text-muted-foreground"}),label:"Assigned To",value:u.jsx(xn,{source:"assigned_to",reference:"sales",link:!1})}),u.jsx($f,{icon:u.jsx(pz,{className:"w-4 h-4 text-muted-foreground"}),label:"Created By",value:u.jsx(xn,{source:"sales_id",reference:"sales",link:!1})})]}),u.jsx("div",{className:"mt-6 pt-6 border-t hidden sm:flex flex-col gap-2 items-start",children:u.jsx(c_,{className:"h-6 cursor-pointer hover:bg-destructive/10! text-destructive! border-destructive! focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",size:"sm"})})]}):null},"TaskAside"),$f=i(({icon:e,label:t,value:n})=>u.jsxs("div",{className:"flex flex-col gap-1 mb-3",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[e,u.jsx("span",{className:"text-xs text-muted-foreground",children:t})]}),u.jsx("div",{className:"pl-6 text-sm",children:n})]}),"InfoRow"),jBe=i(({taskId:e})=>{const{data:t,isPending:n}=pa("task_activity",{filter:{task_id:e},pagination:{page:1,perPage:100},sort:{field:"created_at",order:"DESC"}});return n?u.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Loading activity..."}):!t||t.length===0?u.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"No activity recorded."}):u.jsx("div",{className:"space-y-6 relative pl-4 border-l border-border ml-2 my-4",children:t.map(r=>u.jsxs("div",{className:"relative",children:[u.jsx("div",{className:"absolute -left-[21px] top-1 h-3 w-3 rounded-full bg-primary ring-4 ring-background"}),u.jsxs("div",{className:"text-sm",children:[u.jsx(xn,{source:"sales_id",record:r,reference:"sales",link:!1,children:u.jsx(CBe,{})})," ",EBe(r)]}),u.jsx("div",{className:"text-xs text-muted-foreground",children:nd(new Date(r.created_at),new Date,{addSuffix:!0})})]},r.id))})},"TaskActivityTimeline"),CBe=i(()=>{const e=Ft();return e?u.jsxs("span",{className:"font-semibold",children:[e.first_name," ",e.last_name]}):null},"SaleName"),EBe=i(e=>{switch(e.action){case"created":return"created this task";case"updated":return e.field_name?`changed ${e.field_name}`:"updated this task";case"assigned":return"assigned this task";case"completed":return"completed this task";case"reopened":return"reopened this task";case"duplicated":return"duplicated this task";case"archived":return"archived this task";default:return e.action}},"formatActivityMessage"),kBe=i(()=>u.jsx(DM,{children:u.jsx(OBe,{})}),"TaskShow"),OBe=i(()=>{const{record:e,isPending:t}=MM();return t||!e?null:u.jsxs("div",{className:"mt-2 mb-2 flex gap-8",children:[u.jsx("div",{className:"flex-1",children:u.jsx(un,{children:u.jsxs(Un,{children:[u.jsxs("div",{className:"mb-6",children:[u.jsx("h5",{className:"text-xl font-semibold mb-3",children:e.type}),u.jsxs("div",{className:"flex gap-3 mb-4",children:[u.jsx(zie,{status:e.status}),u.jsx(Uie,{priority:e.priority})]}),e.text&&u.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-line",children:e.text})]}),u.jsxs("div",{className:"mt-8",children:[u.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Activity Timeline"}),u.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Track all status changes and updates for this task"}),u.jsx(jBe,{taskId:e.id})]}),u.jsxs("div",{className:"mt-8",children:[u.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Notes"}),u.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Add notes and updates to this task"}),u.jsx(Gu,{reference:"taskNotes",target:"task_id",sort:{field:"date",order:"DESC"},empty:u.jsx(l_,{reference:"tasks",showStatus:!0,className:"mt-4"}),children:u.jsx(a3,{reference:"tasks",showStatus:!0})})]})]})})}),u.jsx(SBe,{})]})},"TaskShowContent"),RBe={list:wBe,show:kBe,create:gBe};var ABe={"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 TBe={"ra-supabase":{auth:{password_reset:"Check your emails for a Reset Password message."}}},NBe=AQ(()=>Ofe(vQ,ABe,TBe),"en",[{locale:"en",name:"English"}],{allowMissing:!0}),PBe=i(()=>{const e=wn(),{data:t,error:n,isPending:r}=ea({queryKey:["init"],queryFn:i(async()=>e.isInitialized(),"queryFn")});return r?u.jsx(jie,{}):n?u.jsx(Tx,{}):t?u.jsx(Tx,{}):u.jsx(kw,{to:"/sign-up"})},"StartPage");async function DBe(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(DBe,"checkDatabaseHealth");function MBe({missingTables:e,supabaseUrl:t}){const n=t.match(/https:\/\/([^.]+)\.supabase\.co/)?.[1];return u.jsxs("div",{className:"max-w-2xl mx-auto mt-8 space-y-4",children:[u.jsxs(Ga,{variant:"destructive",children:[u.jsx(Lp,{className:"h-4 w-4"}),u.jsx(n3,{children:"Database Schema Not Configured"}),u.jsx(di,{children:"Your Supabase database is connected, but the CRM schema hasn't been set up yet."})]}),u.jsxs(un,{children:[u.jsxs(ms,{children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(ov,{className:"h-5 w-5"}),u.jsx(gs,{children:"Setup Instructions"})]}),u.jsx(V4,{children:"Follow these steps to set up your database schema"})]}),u.jsxs(Un,{className:"space-y-6",children:[u.jsxs("div",{children:[u.jsx("h3",{className:"font-semibold mb-2",children:"Missing Tables:"}),u.jsx("div",{className:"flex flex-wrap gap-2",children:e.map(r=>u.jsx("span",{className:"px-2 py-1 bg-destructive/10 text-destructive text-sm rounded",children:r},r))})]}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.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"}),u.jsx("h3",{className:"font-semibold",children:"Using Supabase CLI (Recommended)"})]}),u.jsxs("div",{className:"ml-8 space-y-3",children:[u.jsxs("div",{children:[u.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Install Supabase CLI:"}),u.jsx("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:"npm install -g supabase"})]}),u.jsxs("div",{children:[u.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Clone the RealTimeX CRM repository to get migrations:"}),u.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"]})]}),u.jsxs("div",{children:[u.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Link to your Supabase project:"}),u.jsxs("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:["supabase link --project-ref ",n||"YOUR_PROJECT_REF"]})]}),u.jsxs("div",{children:[u.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Push the migrations:"}),u.jsx("pre",{className:"bg-muted p-3 rounded text-sm overflow-x-auto",children:"supabase db push"})]}),u.jsx("div",{children:u.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Reload this page after migrations are complete."})})]})]}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.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"}),u.jsx("h3",{className:"font-semibold",children:"Using Supabase SQL Editor"})]}),u.jsxs("div",{className:"ml-8 space-y-3",children:[u.jsx("p",{className:"text-sm text-muted-foreground",children:"Manually run the SQL migrations in your Supabase SQL Editor:"}),u.jsxs("ol",{className:"list-decimal list-inside space-y-2 text-sm text-muted-foreground",children:[u.jsxs("li",{children:["Download migrations from"," ",u.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",u.jsx(Wl,{className:"h-3 w-3"})]})]}),u.jsxs("li",{children:["Open your"," ",u.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",u.jsx(Wl,{className:"h-3 w-3"})]})]}),u.jsx("li",{children:"Run each migration file in order (by date in filename)"}),u.jsx("li",{children:"Reload this page after all migrations are complete"})]}),n&&u.jsx(Le,{asChild:!0,variant:"outline",className:"w-full",children:u.jsxs("a",{href:`https://supabase.com/dashboard/project/${n}/sql/new`,target:"_blank",rel:"noopener noreferrer",children:[u.jsx(Wl,{className:"h-4 w-4 mr-2"}),"Open SQL Editor"]})})]})]}),u.jsxs("div",{className:"space-y-3 pt-4 border-t",children:[u.jsx("h3",{className:"font-semibold",children:"After Setup"}),u.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[u.jsxs("div",{className:"flex items-start gap-2",children:[u.jsx(Vs,{className:"h-4 w-4 mt-0.5 text-green-500"}),u.jsx("span",{children:"All tables will be created with proper schemas and relationships"})]}),u.jsxs("div",{className:"flex items-start gap-2",children:[u.jsx(Vs,{className:"h-4 w-4 mt-0.5 text-green-500"}),u.jsx("span",{children:"Row Level Security (RLS) policies will be configured"})]}),u.jsxs("div",{className:"flex items-start gap-2",children:[u.jsx(Vs,{className:"h-4 w-4 mt-0.5 text-green-500"}),u.jsx("span",{children:"Database triggers and functions will be set up"})]})]}),u.jsx(Le,{onClick:i(()=>window.location.reload(),"onClick"),className:"w-full mt-4",children:"Reload Page"})]})]})]}),u.jsxs(un,{children:[u.jsx(ms,{children:u.jsx(gs,{className:"text-base",children:"Need Help?"})}),u.jsxs(Un,{className:"space-y-2 text-sm",children:[u.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:[u.jsx(Wl,{className:"h-4 w-4"}),"View Full Setup Guide"]}),u.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:[u.jsx(Wl,{className:"h-4 w-4"}),"Report an Issue"]}),u.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:[u.jsx(Wl,{className:"h-4 w-4"}),"Supabase CLI Documentation"]})]})]})]})}i(MBe,"DatabaseSetupGuide");function IBe({children:e,dataProvider:t}){const[n,r]=y.useState(null),[a,s]=y.useState(!0);if(y.useEffect(()=>{let o=!1;async function l(){try{const f=await DBe(t);o||(r(f),s(!1))}catch(f){console.error("[DatabaseHealthCheck] Failed to check database health:",f),o||s(!1)}}return i(l,"checkHealth"),l(),()=>{o=!0}},[t]),a)return u.jsx("div",{className:"flex items-center justify-center min-h-screen",children:u.jsxs("div",{className:"text-center space-y-4",children:[u.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto"}),u.jsx("p",{className:"text-muted-foreground",children:"Checking database connection..."})]})});if(n&&!n.isHealthy){const o=Ed();if(o)return u.jsx(MBe,{missingTables:n.missingTables,supabaseUrl:o.url})}return u.jsx(u.Fragment,{children:e})}i(IBe,"DatabaseHealthCheck");const FBe=i(({contactGender:e=CJ,companySectors:t=vJ,dealCategories:n=xJ,dealPipelineStatuses:r=bJ,dealStages:a=yJ,darkModeLogo:s=pJ,lightModeLogo:o=mJ,noteStatuses:l=wJ,taskTypes:f=_J,taskPriorities:c=SJ,taskStatuses:p=jJ,title:m=gJ,dataProvider:v=vze,authProvider:b=rze,disableTelemetry:w,...S})=>(y.useEffect(()=>{if(w||typeof window>"u"||typeof window.location>"u"||typeof Image>"u")return;const _=new Image;_.src=`https://atomic-crm-telemetry.marmelab.com/atomic-crm-telemetry?domain=${window.location.hostname}`},[w]),u.jsx(POe,{contactGender:e,companySectors:t,dealCategories:n,dealPipelineStatuses:r,dealStages:a,darkModeLogo:s,lightModeLogo:o,noteStatuses:l,taskTypes:f,taskPriorities:c,taskStatuses:p,title:m,children:u.jsx(IBe,{dataProvider:v,children:u.jsxs(LOe,{dataProvider:v,authProvider:b,store:BG(void 0,"CRM"),layout:tze,loginPage:PBe,i18nProvider:NBe,dashboard:VUe,requireAuth:!0,disableTelemetry:!0,...S,children:[u.jsxs(vN,{noLayout:!0,children:[u.jsx(er,{path:xD.path,element:u.jsx(xD,{})}),u.jsx(er,{path:mP.path,element:u.jsx(mP,{})}),u.jsx(er,{path:fP.path,element:u.jsx(fP,{})}),u.jsx(er,{path:gP.path,element:u.jsx(gP,{})}),u.jsx(er,{path:vP.path,element:u.jsx(vP,{})})]}),u.jsxs(vN,{children:[u.jsx(er,{path:_D.path,element:u.jsx(_D,{})}),u.jsx(er,{path:wD.path,element:u.jsx(wD,{})}),u.jsx(er,{path:SD.path,element:u.jsx(SD,{})})]}),u.jsx(ii,{name:"deals",...GUe}),u.jsx(ii,{name:"contacts",...Q6e}),u.jsx(ii,{name:"companies",...Z3e}),u.jsx(ii,{name:"companyNotes"}),u.jsx(ii,{name:"contactNotes"}),u.jsx(ii,{name:"dealNotes"}),u.jsx(ii,{name:"taskNotes"}),u.jsx(ii,{name:"task_activity"}),u.jsx(ii,{name:"tasks",...RBe}),u.jsx(ii,{name:"sales",...Rze}),u.jsx(ii,{name:"tags"})]})})})),"CRM"),LBe=[{id:"prospect",name:"Prospect"},{id:"customer",name:"Customer"},{id:"churned",name:"Churned"},{id:"lost",name:"Lost"},{id:"archived",name:"Archived"}],$Be=[{id:"customer",name:"Customer"},{id:"prospect",name:"Prospect"},{id:"partner",name:"Partner"},{id:"vendor",name:"Vendor"},{id:"competitor",name:"Competitor"},{id:"internal",name:"Internal"}],qBe=[{id:"qualified",name:"Qualified"},{id:"unqualified",name:"Unqualified"},{id:"duplicate",name:"Duplicate"},{id:"spam",name:"Spam"},{id:"test",name:"Test"}],UBe=[{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"}],zBe=[{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"}],BBe=[{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"}],HBe=i(()=>{const[e,t]=y.useState(()=>!OAe());return e?u.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:u.jsx(kie,{open:!0,onComplete:i(()=>{t(!1)},"onComplete"),canClose:!1})}):u.jsx(FBe,{companyLifecycleStages:LBe,companyTypes:$Be,companyQualificationStatuses:qBe,companyRevenueRanges:UBe,externalHeartbeatStatuses:zBe,internalHeartbeatStatuses:BBe})},"App");rle.createRoot(document.getElementById("root")).render(u.jsx(y.StrictMode,{children:u.jsx(HBe,{})}));export{tw as $,ie as A,Kn as B,KPe as C,zG as D,ol as E,eo as F,zi as G,un as H,to as I,Un as J,xn as K,kd as L,Yn as M,Le as N,ga as O,va as P,Lr as Q,bd as R,e2e as S,xd as T,bc as U,Ut as V,Pn as W,$p as X,ro as Y,x5e as Z,Kp as _,yy as a,la as a0,or as a1,d3 as a2,wn as a3,Xn as a4,Dn as a5,L5e as a6,zr as a7,n_ as a8,jd as a9,l3 as aA,Gn as aB,e_ as aC,Od as aD,Q1 as aE,cn as aF,X1 as aG,Iee as aH,Ly as aI,Ht as aa,wM as ab,o3 as ac,Ft as ad,c_ as ae,nn as af,Ur as ag,cp as ah,Z1 as ai,d_ as aj,dl as ak,d3e as al,is as am,ho as an,DM as ao,lne as ap,gc as aq,c0e as ar,s3e as as,Gu as at,a3 as au,l_ as av,Bw as aw,qr as ax,yd as ay,Hme as az,OM as b,LK as c,vge as d,pa as e,Ge as f,$M as g,Pc as h,xt as i,Nc as j,l1 as k,Ct as l,u as m,al as n,ma as o,Iy as p,QPe as q,y as r,ZPe as s,JPe as t,ya as u,ul as v,Cge as w,Wt as x,Er as y,ww as z};
166
- //# sourceMappingURL=index-Ce7mf_H5.js.map
166
+ //# sourceMappingURL=index-BzvO-53A.js.map