randmarcomps 1.655.0 → 1.656.0

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.
@@ -5,7 +5,7 @@
5
5
  - Do not include <html>, <head>, <body>, or markdown fences. Output only the content itself.`:"Provide a helpful, concise response in plain text. Do not use any HTML tags or markdown formatting."}
6
6
  ${r?"Think carefully and be thorough, but stay concise.":"Be concise."}
7
7
  ---
8
- Prompt: "${a}"`;try{return(await s({applicationId:t,body:[{Role:"user",Parts:[{Text:u}]}]}).unwrap()).Content?.Parts?.find(c=>c.Text)?.Text??"Sorry, I couldn't generate a response for this."}catch(m){if(console.error("Error fetching AI response:",m),i>0)return await new Promise(c=>setTimeout(c,(4-i)*500)),Vn(s,t,a,r,n,i-1);const h=new Error("An error occurred while generating the response.");throw h.cause=m,h}},Do=s=>{const{applicationId:t,useProModel:a=!1,outputFormat:r="html"}=s,[n,i]=o.useState(null),[l,d]=o.useState(!1),[u,m]=o.useState(null),[h]=_.usePostV4PartnerByApplicationIdGenerationRandmarAssistantMutation(),c=o.useRef(null),y=o.useCallback(async p=>{if(!t?.trim()){m("applicationId is required.");return}c.current=p;const x=`${t}::${p}::${r}`;if(da.has(x)){const N=da.get(x);return c.current===p&&(i(N),d(!1),m(null)),N}if(Mt.has(x)){d(!0);try{return await Mt.get(x)}catch(N){c.current===p&&m(N instanceof Error?N.message:"An unknown error occurred.");return}finally{c.current===p&&d(!1)}}d(!0),m(null);const w=Vn(h,t,p,a,r).then(N=>{const j=Io(N,r);return da.set(x,j),j}).finally(()=>{Mt.delete(x)});Mt.set(x,w);try{const N=await w;return c.current===p&&i(N),N}catch(N){c.current===p&&m(N instanceof Error?N.message:"An unknown error occurred.");return}finally{c.current===p&&d(!1)}},[t,h,a,r]);return{response:n,isLoading:l,error:u,sendPrompt:y}};function Mo(s,t){if(!s||!t)return"";const a=s?.PublicName??"Our Company",r=t?.PublicName??"Partner";return`
8
+ Prompt: "${a}"`;try{return(await s({applicationId:t,body:[{Role:"user",Parts:[{Text:u}]}]}).unwrap()).Content?.Parts?.find(c=>c.Text)?.Text??"Sorry, I couldn't generate a response for this."}catch(m){if(console.error("Error fetching AI response:",m),i>0)return await new Promise(c=>setTimeout(c,(4-i)*500)),Vn(s,t,a,r,n,i-1);const h=new Error("An error occurred while generating the response.");throw h.cause=m,h}},Do=s=>{const{applicationId:t,useProModel:a=!1,outputFormat:r="html"}=s,[n,i]=o.useState(null),[l,d]=o.useState(!1),[u,m]=o.useState(null),[h]=_.usePostV4PartnerByApplicationIdGenerationV2JsonMutation(),c=o.useRef(null),y=o.useCallback(async p=>{if(!t?.trim()){m("applicationId is required.");return}c.current=p;const x=`${t}::${p}::${r}`;if(da.has(x)){const N=da.get(x);return c.current===p&&(i(N),d(!1),m(null)),N}if(Mt.has(x)){d(!0);try{return await Mt.get(x)}catch(N){c.current===p&&m(N instanceof Error?N.message:"An unknown error occurred.");return}finally{c.current===p&&d(!1)}}d(!0),m(null);const w=Vn(h,t,p,a,r).then(N=>{const j=Io(N,r);return da.set(x,j),j}).finally(()=>{Mt.delete(x)});Mt.set(x,w);try{const N=await w;return c.current===p&&i(N),N}catch(N){c.current===p&&m(N instanceof Error?N.message:"An unknown error occurred.");return}finally{c.current===p&&d(!1)}},[t,h,a,r]);return{response:n,isLoading:l,error:u,sendPrompt:y}};function Mo(s,t){if(!s||!t)return"";const a=s?.PublicName??"Our Company",r=t?.PublicName??"Partner";return`
9
9
  Act as a business analyst. Your task is to provide a short, high-level summary
10
10
  of the relationship between the two companies described in the JSON data below.
11
11
  Suggest how these two entities can best work together.
@@ -45,8 +45,8 @@ Prompt: "${a}"`;try{return(await s({applicationId:t,body:[{Role:"user",Parts:[{T
45
45
  - Output only the plain text of the message itself.
46
46
  `,ts=await j(ke);if(ts){const Ee=(await S({routeApplicationId:s,partnerId:"2"})).data?.ConversationId;if(Ee)await l(),Ve(Ee,ts);else throw new Error("Failed to retrieve conversation ID after creation.")}}catch(H){console.error("Error during 'Chat with Randmar' initiation:",H),te({title:"Error",description:"Could not initiate chat. Please try again later.",variant:"destructive"})}finally{w.current&&(w.current.disabled=!1),k(!1)}},Is=()=>{I&&p({routeApplicationId:s,partnerId:I[0]==s?I[1]:I[0]})},Ns=oe();return e.jsxs("div",{className:v("flex grow-1 overflow-hidden",a),children:[e.jsx(Fo,{appID:s,activeChat:I,chats:q,chatWithRandmarButton:w,isStartingChat:b,isRefreshingChats:m,isMarkingAllRead:c,handleChatWithRandmar:ea,onFullRefreshChats:Ne,onMarkAllRead:Fe,setActiveChat:B}),e.jsx(Uo,{activeChat:I,activeChatObj:Ns,appID:s,messagesEndRef:qe,inputRef:ue,content:F,setContent:U,handleSendMessage:Se,isPostBizDevConvoLoading:x,acceptChat:Is}),e.jsx(qo,{activeChatObj:Ns,appID:s,sendChatToAssistant:Ye,isAnalyzingPartnership:E,analyzePartnership:Je})]})}const Za=_s.Root,qt=R.forwardRef(({className:s,...t},a)=>e.jsx(_s.List,{ref:a,className:v("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...t}));qt.displayName=_s.List.displayName;const We=R.forwardRef(({className:s,...t},a)=>e.jsx(_s.Trigger,{ref:a,className:v("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",s),...t}));We.displayName=_s.Trigger.displayName;const Ze=R.forwardRef(({className:s,...t},a)=>e.jsx(_s.Content,{ref:a,className:v("mt-2 ring-offset-background focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...t}));Ze.displayName=_s.Content.displayName;function Ko({isOpen:s,onClose:t,onConfirm:a,title:r,description:n,confirmText:i="Confirm",cancelText:l="Cancel"}){return e.jsx(De,{open:s,onOpenChange:t,children:e.jsxs(Me,{className:"sm:max-w-[425px]",children:[e.jsxs(Le,{children:[e.jsx($e,{children:r}),e.jsx(_e,{children:n})]}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:t,children:l}),e.jsx(D,{onClick:a,children:i})]})]})})}function Hn(s){const[t,a]=o.useState(!1),r=ve.useBlocker(o.useCallback(({currentLocation:d,nextLocation:u})=>{const m=d.pathname!==u.pathname||d.search!==u.search||d.hash!==u.hash;return s()&&m},[s]));o.useEffect(()=>{r.state==="blocked"&&a(!0)},[r]),o.useEffect(()=>{const d=u=>{if(s())return u.preventDefault(),"You have unsaved changes. Are you sure you want to leave?"};return window.addEventListener("beforeunload",d),()=>{window.removeEventListener("beforeunload",d)}},[s]);const n=o.useCallback(()=>{a(!1),r.state==="blocked"&&r.proceed()},[r]),i=o.useCallback(()=>{a(!1),r.state==="blocked"&&r.reset()},[r]),l=o.useCallback(()=>e.jsx(Ko,{isOpen:t,onClose:i,onConfirm:n,title:"Unsaved Changes",description:"You have unsaved changes. Are you sure you want to leave? Your changes will be lost.",confirmText:"Discard Changes",cancelText:"Stay on Page"}),[t,i,n]);return{showDialog:t,handleConfirm:n,handleCancel:i,NavigationGuardDialog:l}}function Yo({manufacturer:s,readonly:t=!1,isLoading:a,onUnsavedChanges:r}){const{toast:n}=Ce(),[i]=_.usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[l,d]=o.useState({}),u=o.useMemo(()=>({accountsPayableRep:s?.ContactName??"",representativeEmail:s?.RepresentativeEmail??"",phone:s?.Phone??"",creditLimit:s?.CreditLimit??0,terms:s?.Terms??""}),[s]),{register:m,handleSubmit:h,reset:c,watch:y,formState:{errors:p,isSubmitting:x}}=bt.useForm({defaultValues:u}),w=y(),N=o.useCallback(()=>t||!l?!1:JSON.stringify(w)!==JSON.stringify(l),[t,w,l]);o.useEffect(()=>{r&&r(N())},[N,r]),o.useEffect(()=>{s&&(c(u),d(u))},[s,c,u]);const j=async b=>{if(t)return;let k=!0,S=!1;const M=[{key:"accountsPayableRep",apiKey:"ContactName",value:b.accountsPayableRep},{key:"representativeEmail",apiKey:"RepresentativeEmail",value:b.representativeEmail},{key:"phone",apiKey:"Phone",value:b.phone},{key:"terms",apiKey:"Terms",value:b.terms}];for(const A of M){const P=A.value,E=s?.[A.apiKey];if(P!==E&&P!==void 0){S=!0;try{await i({applicationId:s?.ManufacturerId??"",fieldName:A.apiKey,newValue:String(P)}).unwrap()||(k=!1,console.error(`Failed to update ${A.apiKey}`))}catch(T){console.error(`Error updating ${A.apiKey}:`,T),k=!1}}}k&&S?(n({title:"Billing info",description:"Information updated successfully",variant:"success"}),d({...b}),r&&r(!1)):k?S||n({title:"No changes",description:"No changes were made to the information.",variant:"info"}):n({title:"Update error",description:"Failed to update. Please try again.",variant:"destructive"})};return e.jsxs(z,{children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Billing, Credit, & Rebates"})}),e.jsx(G,{children:a?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-48"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-36"}),e.jsx(f,{className:"h-10 w-full"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-16"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-24"}),e.jsx(f,{className:"h-10 w-full"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-16"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsx(f,{className:"h-10 w-20"})]}):e.jsxs("form",{onSubmit:h(j),className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"accountsPayableRep",children:"Accounts Payable Representative"}),e.jsx(le,{id:"accountsPayableRep",placeholder:"John Doe",...m("accountsPayableRep"),readOnly:t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"representativeEmail",children:"Representative Email"}),e.jsx(le,{id:"representativeEmail",placeholder:"john.doe@company.com",...m("representativeEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),readOnly:t}),p.representativeEmail&&e.jsx("p",{className:"text-destructive text-sm",children:p.representativeEmail.message})]})]}),e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"phone",children:"Phone"}),e.jsx(le,{id:"phone",placeholder:"(555) 123-4567",...m("phone"),readOnly:t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"creditLimit",children:"Credit Limit"}),e.jsx("div",{className:"p-2 border rounded-md bg-muted/30",children:e.jsx(os.FormattedNumber,{value:s?.CreditLimit||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"terms",children:"Terms"}),e.jsx(le,{id:"terms",placeholder:"NET 30 DAYS",...m("terms"),readOnly:!0})]}),!t&&e.jsx("div",{className:"flex justify-end",children:e.jsx(D,{type:"submit",disabled:x,className:"w-full sm:w-auto",children:x?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})})]})}function Jo({manufacturer:s,readonly:t=!1,isLoading:a}){const{toast:r}=Ce(),[n]=_.usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),i=o.useMemo(()=>({openToWork:s?.OpenToWork??!1}),[s]),{reset:l,watch:d}=bt.useForm({defaultValues:i});o.useEffect(()=>{s&&l(i)},[s,l,i]);const u=async m=>{if(!t)try{await n({applicationId:s?.ManufacturerId??"",fieldName:"OpenToWork",newValue:m?"true":"false"}).unwrap()&&r({title:"Open to work info",description:"Information updated successfully",variant:"success"})}catch(h){console.error("Error updating",h)}};return e.jsxs(z,{children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Open to Work with Resellers"})}),e.jsx(G,{children:a?e.jsx("div",{className:"space-y-4",children:e.jsx(f,{className:"h-10 w-20"})}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Resellers will be introducing their business, and communicating opportunities for your Brand through Randmar."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"You'll engage directly with resellers, allow them to learn about your product lines, and grow your business faster."}),e.jsx("br",{}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(at,{id:"openToWork",checked:d("openToWork"),onCheckedChange:m=>u(m),disabled:t}),e.jsx(J,{htmlFor:"openToWork",children:"Open to work with Resellers"})]})]})})]})}const Zo=["Arts and Crafts","Cleaning Solutions","Clothing","Electronics","Generic Compatible Toner","Ink","Luggage and Bags","Miscellaneous","Networking Devices","Paper Products","Printers","Printing Supplies","Toner"];function Xo({manufacturer:s,readonly:t=!1,isLoading:a,onUnsavedChanges:r}){const{toast:n}=Ce(),[i]=_.usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[l,d]=o.useState([]),[u,m]=o.useState({}),h=o.useMemo(()=>({publicName:s?.PublicName??"",website:s?.Website??"",customerServiceEmail:s?.PublicEmail??"",publicResources:s?.PublicResourcesLink??""}),[s]),{register:c,handleSubmit:y,reset:p,watch:x,formState:{errors:w,isSubmitting:N}}=bt.useForm({defaultValues:h}),j=x(),b=o.useCallback(()=>t||!u?!1:JSON.stringify(j)!==JSON.stringify(u),[t,j,u]);o.useEffect(()=>{r&&r(b())},[b,r]),o.useEffect(()=>{s&&(p(h),d(s.Tags?s.Tags.split(",").map(A=>A.trim()):[]),m(h))},[s,p,h]);const k=async A=>{if(t)return;let P=!0,E=!1;const T=[{key:"publicName",apiKey:"PublicName",value:A.publicName},{key:"website",apiKey:"Website",value:A.website},{key:"manufacturerCategories",apiKey:"Tags",value:l.join(", ")},{key:"customerServiceEmail",apiKey:"PublicEmail",value:A.customerServiceEmail},{key:"publicResources",apiKey:"PublicResourcesLink",value:A.publicResources}];for(const I of T){const B=I.value,F=s?.[I.apiKey],U=typeof F=="boolean"?String(F):F;if(B!==U&&B!==void 0){E=!0;try{await i({applicationId:s?.ManufacturerId??"",fieldName:I.apiKey,newValue:String(B)}).unwrap()||(P=!1)}catch(V){console.error(`Error updating ${I.apiKey}:`,V),P=!1}}}P&&E?(n({title:"Public info",description:"Information updated successfully",variant:"success"}),m({...A}),r&&r(!1)):P||n({title:"Update error",description:"Failed to update",variant:"destructive"})},S=A=>!A||A.trim()==="",M=A=>{d(A)};return e.jsxs(z,{children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Public Information"})}),e.jsx(G,{children:a?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-40"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-24"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{className:"h-5 w-10"}),e.jsx(f,{className:"h-4 w-48"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-40"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-40"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-32"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsx(f,{className:"h-10 w-20"})]}):e.jsxs(e.Fragment,{children:[(S(x("publicName"))||S(x("website"))||S(x("customerServiceEmail")))&&e.jsxs(js,{variant:"destructive",className:"mb-6",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(bs,{children:"Missing information"}),e.jsx(ys,{children:"All fields are required to get started at working with Resellers."})]}),e.jsxs("form",{onSubmit:y(k),className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"publicName",children:"Public Manufacturer Name *"}),e.jsx(le,{id:"publicName",placeholder:"Company Name",...c("publicName",{}),className:S(x("publicName"))?"input-error-indicator":"",readOnly:t}),w.publicName&&e.jsx("p",{className:"text-destructive text-sm",children:w.publicName.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"website",children:"Website *"}),e.jsx(le,{id:"website",placeholder:"https://company.com",...c("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:S(x("website"))?"input-error-indicator":"",readOnly:t}),w.website&&e.jsx("p",{className:"text-destructive text-sm",children:w.website.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"manufacturerCategories",children:"Manufacturer Categories"}),e.jsx(hi,{options:Zo,selected:l,onChange:M,placeholder:"Select or type categories...",disabled:t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"customerServiceEmail",children:"Customer Service Email *"}),e.jsx(le,{id:"customerServiceEmail",placeholder:"support@company.com",...c("customerServiceEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:S(x("customerServiceEmail"))?"input-error-indicator":"",readOnly:t}),w.customerServiceEmail&&e.jsx("p",{className:"text-destructive text-sm",children:w.customerServiceEmail.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"publicResources",children:"Public Resources"}),e.jsx(le,{id:"publicResources",placeholder:"https://resources.company.com",...c("publicResources"),readOnly:t})]}),!t&&e.jsx("div",{className:"flex justify-end",children:e.jsx(D,{type:"submit",disabled:N,className:"w-full sm:w-auto",children:N?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})]})})]})}function ec({manufacturer:s,readonly:t=!1,isLoading:a,onUnsavedChanges:r}){const{toast:n}=Ce(),[i]=_.usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[l,d]=o.useState({}),u=o.useMemo(()=>({partnerPortal:s?.PartnerPortal??"",partnerRegistrationLink:s?.PartnerRegistrationLink??""}),[s]),{register:m,handleSubmit:h,reset:c,watch:y,formState:{errors:p,isSubmitting:x}}=bt.useForm({defaultValues:u}),w=y(),N=o.useCallback(()=>t||!l?!1:JSON.stringify(w)!==JSON.stringify(l),[t,w,l]);o.useEffect(()=>{r&&r(N())},[N,r]),o.useEffect(()=>{s&&(c(u),d(u))},[s,c,u]);const j=async k=>{if(t)return!1;let S=!0,M=!1;const A=[{key:"partnerPortal",apiKey:"PartnerPortal",value:k.partnerPortal},{key:"partnerRegistrationLink",apiKey:"PartnerRegistrationLink",value:k.partnerRegistrationLink}];for(const P of A){const E=P.value,T=s?.[P.apiKey];if(E!==T&&E!==void 0){M=!0;try{await i({applicationId:s?.ManufacturerId??"",fieldName:P.apiKey,newValue:String(E)}).unwrap()||(S=!1,console.error(`Failed to update ${P.apiKey}`))}catch(I){console.error(`Error updating ${P.apiKey}:`,I),S=!1}}}S&&M?(n({title:"Qualifications info",description:"Information updated successfully",variant:"success"}),d({...k}),r&&r(!1)):S?M||n({title:"No changes",description:"No changes were made to the information.",variant:"info"}):n({title:"Update error",description:"Failed to update. Please try again.",variant:"destructive"})},b=/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?(\?[^\s#]*)??(#[^\s]*)?$/i;return e.jsxs(z,{children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Qualifications"})}),e.jsx(G,{children:a?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-32"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-48"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsx(f,{className:"h-10 w-20"})]}):e.jsxs("form",{onSubmit:h(j),className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"partnerPortal",children:"Partner Portal"}),e.jsx(le,{id:"partnerPortal",placeholder:"https://partner.example.com",...m("partnerPortal",{pattern:{value:b,message:"Invalid URL format"}}),readOnly:t}),p.partnerPortal&&e.jsx("p",{className:"text-destructive text-sm",children:p.partnerPortal.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-sm font-medium leading-none",htmlFor:"partnerRegistrationLink",children:"Partner Registration Link"}),e.jsx(le,{id:"partnerRegistrationLink",placeholder:"https://register.example.com",...m("partnerRegistrationLink",{pattern:{value:b,message:"Invalid URL format"}}),readOnly:t}),p.partnerRegistrationLink&&e.jsx("p",{className:"text-destructive text-sm",children:p.partnerRegistrationLink.message})]}),!t&&e.jsx("div",{className:"flex justify-end",children:e.jsx(D,{type:"submit",disabled:x,className:"w-full sm:w-auto",children:x?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})})]})}function sc({manufacturerId:s,userEmail:t,isLoading:a}){const{toast:r}=Ce(),[n,i]=o.useState(null),[l,d]=o.useState(t),[u,m]=o.useState(!1),[h,c]=o.useState(),[y,p]=o.useState(),x=[{name:"Orders & Sales",reports:[{id:"OpenOrders",title:"Open Orders Report",description:"The Open Orders Report provides a snapshot of active orders, aiding your business in efficiently tracking and fulfilling customer demands.",icon:g.FileText},{id:"Sales",title:"Sales Report",description:"Summary of your company's sales activity over a certain period, detailing total sales and helping identifying trends, successes, and areas needing improvement.",icon:g.BarChart}]},{name:"Purchase Orders",reports:[{id:"PurchasedOrders",title:"Open Purchase Orders Report",description:"The Open Purchase Orders Report provides a snapshot of Randmar's active orders, aiding your business in efficiently tracking and fulfilling Randmar's inventory demands.",icon:g.ShoppingCart},{id:"Reorder",title:"Reordering Report",description:"The Reordering Report provides a snapshot of all part numbers auto-reordering statuses. Aiding your understanding of what will be automatically reordered by our system or not once the inventory reaches low numbers.",icon:g.ClipboardList}]},{name:"Inventory",reports:[{id:"Inventory",title:"Inventory Report",description:"Detailed document outlining the quantity, type, and value of products Randmar has on hand. It aids in managing stock levels, identifying shortages or surpluses, and informing purchasing decisions.",icon:g.Package},{id:"Products",title:"Products Report",description:"Detailed document outlining all your products properties. It provides a comprehensive overview of essential information and insights that help you make informed decisions.",icon:g.ClipboardList}]}],[w,{isLoading:N}]=_.usePostV4ManufacturerByRouteManufacturerIdReportOpenOrdersEmailMutation(),[j,{isLoading:b}]=_.usePostV4ManufacturerByRouteManufacturerIdReportSalesEmailMutation(),[k,{isLoading:S}]=_.usePostV4ManufacturerByRouteManufacturerIdReportPurchasedOrdersEmailMutation(),[M,{isLoading:A}]=_.usePostV4ManufacturerByRouteManufacturerIdReportReorderEmailMutation(),[P,{isLoading:E}]=_.usePostV4ManufacturerByRouteManufacturerIdReportInventoryEmailMutation(),[T,{isLoading:I}]=_.usePostV4ManufacturerByRouteManufacturerIdReportProductsEmailMutation(),B=N||b||S||A||E||I,F=q=>{i(q),m(!0)},U=q=>{m(q),q||(c(void 0),p(void 0))},V=async()=>{if(!(!n||!s))try{switch(n.id){case"OpenOrders":await w({routeManufacturerId:s,emailAddress:l}).unwrap();break;case"Sales":await j({routeManufacturerId:s,emailAddress:l,startDate:h?.toISOString(),endDate:y?.toISOString()}).unwrap();break;case"PurchasedOrders":await k({routeManufacturerId:s,emailAddress:l}).unwrap();break;case"Reorder":await M({routeManufacturerId:s,emailAddress:l}).unwrap();break;case"Inventory":await P({routeManufacturerId:s,emailAddress:l,inventoryDate:h?.toISOString()}).unwrap();break;case"Products":await T({routeManufacturerId:s,emailAddress:l}).unwrap();break;default:throw new Error("Invalid report ID")}r({title:"Report requested",description:`The ${n.title} will be sent to ${l} shortly.`,variant:"success"}),U(!1)}catch(q){console.error("Error requesting report:",q),r({title:"Error",description:"Failed to request the report. Please try again.",variant:"destructive"})}},O=()=>{switch(n?.id){case"Sales":return"Enter an email and date range for the report.";case"Inventory":return"Enter an email and select a date for the inventory snapshot.";default:return"Enter the email address where you would like to receive the report."}};return e.jsxs(z,{children:[e.jsxs(Y,{children:[e.jsx(me,{className:"text-1xl font-bold",children:"Reports"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Download essential business reports, from your Open Orders & Sales Report, to your Inventory Reports."})]}),e.jsx(G,{className:"space-y-6",children:a?Array.from({length:3}).map((q,W)=>e.jsxs("div",{className:"space-y-4",children:[e.jsx(f,{className:"h-6 w-48"}),Array.from({length:2}).map((ne,Pe)=>e.jsxs("div",{className:"flex items-start gap-4 rounded-lg border p-4",children:[e.jsx(f,{className:"h-9 w-9 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(f,{className:"mb-2 h-5 w-40"}),e.jsx(f,{className:"h-4 w-full"})]}),e.jsx(f,{className:"h-9 w-24"})]},Pe))]},W)):x.map(q=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:q.name}),q.reports.map(W=>e.jsxs("div",{className:"flex items-start gap-4 rounded-lg border p-4 transition-colors hover:bg-muted",children:[e.jsx("div",{className:"rounded-full bg-primary/10 p-2",children:e.jsx(W.icon,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"text-sm font-semibold",children:W.title}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:W.description})]}),e.jsxs(D,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>F(W),children:[e.jsx(g.Download,{className:"h-4 w-4"}),"Request"]})]},W.id))]},q.name))}),e.jsx(De,{open:u,onOpenChange:U,children:e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsxs($e,{children:["Request ",n?.title]}),e.jsx(_e,{children:O()})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(J,{htmlFor:"email",children:"Email"}),e.jsx(le,{id:"email",value:l,onChange:q=>d(q.target.value),placeholder:"your@email.com",className:"mt-2"})]}),n?.id==="Sales"&&e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsx(Ot,{label:"Start Date",id:"start-date",date:h,onDateChange:c}),e.jsx(Ot,{label:"End Date",id:"end-date",date:y,onDateChange:p})]}),n?.id==="Inventory"&&e.jsx(Ot,{label:"Inventory Date",id:"inventory-date",date:h,onDateChange:c})]}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>U(!1),children:"Cancel"}),e.jsx(D,{onClick:V,disabled:!l||B||n?.id==="Sales"&&(!h||!y)||n?.id==="Inventory"&&!h,children:B?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function tc(s){const{data:t,isLoading:a,isError:r}=_.useGetV4ManufacturerByRouteManufacturerIdDocumentsActiveOrderDetailsQuery({routeManufacturerId:s.manufacturerId},{skip:!!s.activeOrders||s.isLoading}),n=s.activeOrders??t,l=(()=>{if(!n)return{all:{orders:0,amount:0},processing:{orders:0,amount:0},shipped:{orders:0,amount:0},delayed:{orders:0,amount:0}};const u=n.filter(S=>S.DocumentType==="Order"),m=n.filter(S=>S.DocumentType==="Shipment"),h=u.filter(S=>S.WarehouseCode!=="3PLE"),c=h.reduce((S,M)=>S+(M.Quantity||0),0),y=h.reduce((S,M)=>S+(M.ExtendedPrice||0),0),p=u.filter(S=>S.WarehouseCode==="3PLE"),x=p.reduce((S,M)=>S+(M.Quantity||0),0),w=p.reduce((S,M)=>S+(M.ExtendedPrice||0),0),N=m.length,j=m.reduce((S,M)=>S+(M.ExtendedPrice||0),0),b=c+x+N,k=y+w+j;return{all:{orders:b,amount:k},processing:{orders:c,amount:y},shipped:{orders:N,amount:j},delayed:{orders:x,amount:w}}})(),d=[{name:"All",icon:g.Package,stripeClass:"bg-info/60",iconBgClass:"bg-info/90",iconTextClass:"text-info-foreground",orders:l.all.orders,amount:l.all.amount},{name:"Processing",icon:g.RefreshCcw,stripeClass:"bg-warning/60",iconBgClass:"bg-warning/90",iconTextClass:"text-warning-foreground",orders:l.processing.orders,amount:l.processing.amount},{name:"Shipped",icon:g.Truck,stripeClass:"bg-success/60",iconBgClass:"bg-success/90",iconTextClass:"text-success-foreground",orders:l.shipped.orders,amount:l.shipped.amount},{name:"Delayed",icon:g.AlertCircle,stripeClass:"bg-destructive/60",iconBgClass:"bg-destructive/90",iconTextClass:"text-destructive-foreground",orders:l.delayed.orders,amount:l.delayed.amount}];return a||s.isLoading?e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-base font-medium text-foreground",children:"Reseller Orders"})}),e.jsxs(G,{children:[e.jsx(f,{className:"h-4 w-40 mb-4"}),e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:[1,2,3,4].map(u=>e.jsx(f,{className:"h-32 w-full"},u))})]})]}):r?e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-base font-medium text-foreground",children:"Reseller Orders"})}),e.jsx(G,{children:e.jsxs(js,{variant:"destructive",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(bs,{children:"Error"}),e.jsx(ys,{children:"Failed to load reseller orders. Please try again later."})]})})]}):e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-base font-medium text-foreground",children:"Reseller Orders"})}),e.jsxs(G,{children:[e.jsxs("div",{className:"flex items-center mb-4",children:[e.jsx("span",{className:"text-sm font-medium",children:"Active Orders:"}),e.jsx("span",{className:"ml-2 font-bold",children:l.all.orders})]}),e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:d.map(u=>e.jsx(z,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:e.jsxs(G,{className:"p-0",children:[e.jsx("div",{className:`${u.stripeClass} h-[3px]`}),e.jsxs("div",{className:"p-6 border border-t-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:"font-semibold text-base",children:u.name}),e.jsx("div",{className:`${u.iconBgClass} p-2 rounded-full`,children:e.jsx(u.icon,{className:`size-4 shrink-0 ${u.iconTextClass}`})})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Orders"}),e.jsx("p",{className:"text-xl font-bold",children:u.orders})]}),e.jsxs("div",{className:"text-end",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),e.jsx("p",{className:"text-base font-semibold",children:e.jsx(os.FormattedNumber,{value:u.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},u.name))})]})]})}function ac(s){if(!s)return;const t=["","January","February","March","April","May","June","July","August","September","October","November","December"];return s===void 0&&(s=new Date().getMonth()+1),s<1&&(s=12+s),t[s]}function Gn({fiscalYearMonthStart:s,salesData:t,isLoading:a}){const r=t?.SalesLast30Days??0,n=t?.SalesLast3Months??0,i=t?.SalesYearToDay??0,l=ac(s);return a?e.jsxs("div",{className:"grid gap-4 @xl:grid-cols-2 @2xl:grid-cols-3 mb-4",children:[e.jsxs(z,{children:[e.jsxs(Y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(f,{className:"h-5 w-24"}),e.jsx(f,{className:"h-8 w-8 rounded-full"})]}),e.jsxs(G,{children:[e.jsx(f,{className:"h-8 w-32 mb-1"}),e.jsx(f,{className:"h-4 w-24"})]})]}),e.jsxs(z,{children:[e.jsxs(Y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(f,{className:"h-5 w-28"}),e.jsx(f,{className:"h-8 w-8 rounded-full"})]}),e.jsxs(G,{children:[e.jsx(f,{className:"h-8 w-32 mb-1"}),e.jsx(f,{className:"h-4 w-24"})]})]}),e.jsxs(z,{className:"@xl:col-span-2 @2xl:col-span-1",children:[e.jsxs(Y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(f,{className:"h-5 w-36"}),e.jsx(f,{className:"h-8 w-8 rounded-full"})]}),e.jsxs(G,{children:[e.jsx(f,{className:"h-8 w-32 mb-1"}),e.jsx(f,{className:"h-4 w-24"})]})]})]}):e.jsxs("div",{className:"grid gap-4 @xl:grid-cols-2 @2xl:grid-cols-3 mb-4",children:[e.jsxs(z,{children:[e.jsxs(Y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(me,{className:"text-sm font-medium",children:"Last 30 Days"}),e.jsx("div",{className:"p-2 rounded-full bg-muted",children:e.jsx(g.TrendingUp,{className:"size-4 shrink-0 text-muted-foreground"})})]}),e.jsxs(G,{children:[e.jsx("div",{className:"text-2xl font-bold",children:e.jsx(os.FormattedNumber,{value:r,style:"currency",currency:"CAD",currencyDisplay:"symbol"})}),e.jsx("p",{className:"text-xs text-muted-foreground"})]})]}),e.jsxs(z,{children:[e.jsxs(Y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(me,{className:"text-sm font-medium",children:"Last 3 Months"}),e.jsx("div",{className:"p-2 rounded-full bg-muted",children:e.jsx(g.Calendar,{className:"size-4 shrink-0 text-muted-foreground"})})]}),e.jsxs(G,{children:[e.jsx("div",{className:"text-2xl font-bold",children:e.jsx(os.FormattedNumber,{value:n,style:"currency",currency:"CAD",currencyDisplay:"symbol"})}),e.jsx("p",{className:"text-xs text-muted-foreground"})]})]}),l&&e.jsxs(z,{className:"@xl:col-span-2 @2xl:col-span-1",children:[e.jsxs(Y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs(me,{className:"text-sm font-medium",children:["Year to Date (",l,")"]}),e.jsx("div",{className:"p-2 rounded-full bg-muted",children:e.jsx(g.CalendarDays,{className:"size-4 shrink-0 text-muted-foreground"})})]}),e.jsxs(G,{children:[e.jsx("div",{className:"text-2xl font-bold",children:e.jsx(os.FormattedNumber,{value:i,style:"currency",currency:"CAD",currencyDisplay:"symbol"})}),e.jsx("p",{className:"text-xs text-muted-foreground"})]})]})]})}const z=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("rounded-md border bg-card text-card-foreground shadow-sm",s),...t}));z.displayName="Card";const Y=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("flex flex-col space-y-1.5 p-6",s),...t}));Y.displayName="CardHeader";const me=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("font-semibold leading-none tracking-tight",s),...t}));me.displayName="CardTitle";const rt=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("text-sm text-muted-foreground",s),...t}));rt.displayName="CardDescription";const G=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("p-6 pt-0",s),...t}));G.displayName="CardContent";const ms=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("flex items-center p-6 pt-0",s),...t}));ms.displayName="CardFooter";const nt=R.forwardRef(({className:s,value:t,...a},r)=>e.jsx(va.Root,{ref:r,className:v("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...a,children:e.jsx(va.Indicator,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(t||0)}%)`}})}));nt.displayName=va.Root.displayName;function rc({manufacturer:s,isLoading:t}){const{data:a=[],isLoading:r,isFetching:n}=_.useGetV4ManufacturerByRouteManufacturerIdInventoryValueQuery({routeManufacturerId:s?.ManufacturerId??""},{skip:!s?.ManufacturerId}),i=s?.DefaultMaxInventoryValue??0,l=a.reduce((m,h)=>m+(h.InventoryValue||0),0),d=i-l,u=i>0?Math.round(l/i*100):0;return t||r||n?e.jsxs(z,{children:[e.jsxs(Y,{children:[e.jsx(f,{className:"h-7 w-3/4"}),e.jsx(f,{className:"h-5 w-1/2 mt-2"})]}),e.jsxs(G,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-5 w-1/3"}),e.jsx(f,{className:"h-5 w-1/4"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-5 w-1/3"}),e.jsx(f,{className:"h-5 w-1/4"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-5 w-1/3"}),e.jsx(f,{className:"h-5 w-1/4"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-5 w-1/3"}),e.jsx(f,{className:"h-5 w-16"})]}),e.jsx(f,{className:"h-2 w-full"})]})]})]}):e.jsxs(z,{children:[e.jsxs(Y,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(g.DollarSign,{className:"h-5 w-5 text-muted-foreground"}),"Inventory Finance"]}),e.jsx(rt,{children:"Current inventory financial status"})]}),e.jsxs(G,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[i!==0&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Max Allowance"}),e.jsx("span",{className:"font-bold",children:de(i)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Current value"}),e.jsx("span",{className:"font-bold",children:de(l)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Available"}),e.jsx("span",{className:`font-bold ${d>=0?"text-success":"text-destructive"}`,children:de(d)})]})]}),i!==0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Budget Usage"}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("span",{className:"text-sm font-medium",children:[u,"%"]}),u>80&&e.jsx(g.AlertCircle,{className:"h-4 w-4 text-warning"})]})}),e.jsx(pe,{children:e.jsx("p",{children:u>80?"High usage alert":"Budget usage"})})]})})]}),e.jsx(nt,{value:u,className:"h-2"})]})]})]})}function nc({manufacturer:s,isLoading:t}){const a=s?.CreditLimit??0,r=s?.OutstandingBalance??0,n=a-r,i=Math.round(r/a*100);return t?e.jsxs(z,{children:[e.jsxs(Y,{children:[e.jsx(f,{className:"h-7 w-3/4"}),e.jsx(f,{className:"h-5 w-1/2 mt-2"})]}),e.jsxs(G,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-5 w-1/3"}),e.jsx(f,{className:"h-5 w-1/4"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-5 w-1/3"}),e.jsx(f,{className:"h-5 w-1/4"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-5 w-1/3"}),e.jsx(f,{className:"h-5 w-1/4"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-5 w-1/3"}),e.jsx(f,{className:"h-5 w-16"})]}),e.jsx(f,{className:"h-2 w-full"})]})]})]}):e.jsxs(z,{children:[e.jsxs(Y,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(g.CreditCard,{className:"h-5 w-5 text-muted-foreground"}),"Credit Finance"]}),e.jsx(rt,{children:"Current credit financial status"})]}),e.jsxs(G,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Credit Limit"}),e.jsx("span",{className:"font-bold",children:de(a)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Outstanding Balance"}),e.jsx("span",{className:"font-bold",children:de(r)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Available Credit"}),e.jsx("span",{className:`font-bold ${n>=0?"text-success":"text-destructive"}`,children:de(n)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Credit Usage"}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("span",{className:"text-sm font-medium",children:[i,"%"]}),i>80&&e.jsx(g.AlertCircle,{className:"h-4 w-4 text-warning"})]})}),e.jsx(pe,{children:e.jsx("p",{children:i>80?"High credit usage alert":"Credit usage"})})]})})]}),e.jsx(nt,{value:i,className:"h-2"})]})]})]})}function Xa({statistics:s,loading:t=!1,mode:a="month",chartHeight:r=300,className:n,size:i="default"}){return t?e.jsxs(z,{className:v("w-full",n),children:[e.jsx(Y,{children:e.jsx(f,{className:"h-7 w-48 rounded-md"})}),e.jsxs(G,{children:[e.jsx("div",{style:{height:r},children:e.jsx(f,{className:"h-full w-full rounded-md"})}),i==="default"&&a==="month"&&e.jsxs("div",{className:"mt-4 flex items-center space-x-2",children:[e.jsx(f,{className:"h-5 w-10 rounded-full"}),e.jsx(f,{className:"h-4 w-40 rounded-md"})]})]})]}):e.jsxs(z,{className:v("w-full",n),children:[e.jsx(Y,{children:e.jsx(me,{children:a==="week"?"Weekly Sales Performance":"Monthly Sales Performance"})}),e.jsx(G,{children:e.jsx(Vs,{statistics:s,mode:a,chartHeight:r,size:i})})]})}function Wn({applicationId:s,readonly:t,withReports:a,manufacturer:r,userEmail:n}){const{data:i,isLoading:l,isError:d}=_.useGetV4PartnerByApplicationIdAccountManufacturerQuery({applicationId:s,withSpecification:!0},{skip:!!r}),[u,m]=o.useState({publicInfo:{hasUnsavedChanges:!1},qualifications:{hasUnsavedChanges:!1},billingInfo:{hasUnsavedChanges:!1}}),h=o.useCallback(()=>t?!1:u.publicInfo.hasUnsavedChanges||u.qualifications.hasUnsavedChanges||u.billingInfo.hasUnsavedChanges,[t,u]),c=o.useCallback((x,w)=>{m(N=>N[x]?.hasUnsavedChanges!==w.hasUnsavedChanges?(console.log(`Updating form state for ${x}:`,w.hasUnsavedChanges),{...N,[x]:w}):N)},[]),{NavigationGuardDialog:y}=Hn(h),p=r??i;return e.jsxs("div",{className:"@container",children:[d?e.jsx(z,{className:"p-6",children:e.jsxs(js,{variant:"destructive",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(bs,{children:"Error"}),e.jsx(ys,{children:"There was an error loading your manufacturer information. Please try again later."})]})}):e.jsxs("div",{className:"space-y-6 mb-6",children:[e.jsx(Gn,{fiscalYearMonthStart:p?.FiscalYearMonthStart,salesData:p?.SalesData,isLoading:l}),e.jsxs("div",{className:"grid @2xl:grid-cols-2 gap-6",children:[e.jsx(Xa,{statistics:p?.SalesStatistics??[],loading:l}),e.jsx(tc,{manufacturerId:p?.ManufacturerId??"",activeOrders:p?.ActiveOrderDetails??void 0,isLoading:l}),a&&e.jsx(rc,{manufacturer:p,isLoading:l}),a&&e.jsx(nc,{manufacturer:p,isLoading:l}),a&&e.jsx(xi,{manufacturer:p??{},onSave:()=>{},loading:l,readonly:t}),a&&e.jsx(Xo,{manufacturer:p,readonly:t,isLoading:l,onUnsavedChanges:x=>c("publicInfo",{hasUnsavedChanges:x})}),a&&e.jsx(Jo,{manufacturer:p,readonly:t,isLoading:l}),a&&e.jsx(Yo,{manufacturer:p,readonly:t,isLoading:l,onUnsavedChanges:x=>c("billingInfo",{hasUnsavedChanges:x})}),a&&e.jsx(ec,{manufacturer:p,readonly:t,isLoading:l,onUnsavedChanges:x=>c("qualifications",{hasUnsavedChanges:x})})]}),a&&e.jsx(sc,{manufacturerId:p?.ManufacturerId??"",userEmail:n,isLoading:l})]}),e.jsx(y,{})]})}function Or({categories:s,activeCategory:t,onSelectCategory:a}){return e.jsx("div",{className:"grid",children:e.jsx("div",{className:"flex overflow-x-auto small-scrollbar pb-4",children:e.jsxs("div",{className:"flex gap-2 items-baseline",children:[e.jsx("p",{children:"Category filter:"}),s.map(r=>e.jsxs(D,{onClick:()=>a(r.CategoryCode??""),variant:t===r.CategoryCode?"default":"outline",size:"sm",className:"px-3 py-1.5 text-xs whitespace-nowrap rounded-full",children:[r.CategoryName??"Undefined",r.QualificationRequired&&e.jsx(g.ShieldCheck,{className:`ml-1 w-5 h-5 ${t!==r.CategoryCode?"text-destructive":""}`})]},r.CategoryCode))]})})})}function ic(s){const{data:t,isLoading:a,isFetching:r}=_.useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:s.appID,manufacturerId:s.manufID,categoryCode:s.categoryCode});return e.jsx(z,{className:"w-full",children:e.jsx(G,{className:"p-4 space-y-1",children:e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:s.categoryName}),e.jsx(Vs,{statistics:t?.SalesStatistics??[],loading:a||r,chartHeight:300})]})})})}function lc(s){return(s.categories??[]).filter(a=>a.CategoryName).map(a=>e.jsx(ic,{appID:s.appID,manufID:s.manufID,categoryCode:a.CategoryCode,categoryName:a.CategoryName},`${s.manufID}-${a.CategoryCode}`))}const Kn=et.cva("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/80",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground border border-border hover:bg-accent hover:text-accent-foreground",success:"bg-success text-success-foreground hover:bg-success/90",warning:"bg-warning text-warning-foreground hover:bg-warning/90",info:"bg-info text-info-foreground hover:bg-info/90",ghost:"bg-background hover:bg-accent hover:text-accent-foreground",randmarRed:"bg-primary text-primary-foreground hover:bg-primary/80",randmarBlue:"bg-primary text-primary-foreground hover:bg-primary/80",randmarPurple:"bg-primary text-primary-foreground hover:bg-primary/80",randmarGreen:"bg-primary text-primary-foreground hover:bg-primary/80",randmarBlack:"bg-foreground text-background hover:bg-foreground/90",randmarYellow:"bg-primary text-primary-foreground hover:bg-primary/80"},size:{default:"h-6",sm:"h-5 text-[10px]",lg:"h-7 px-3"}},defaultVariants:{variant:"default",size:"default"}}),fe=R.forwardRef(({className:s,variant:t,size:a,icon:r,children:n,...i},l)=>e.jsxs("div",{ref:l,className:v(Kn({variant:t,size:a}),s),...i,children:[r&&e.jsx("span",{className:"mr-1",children:r}),n]}));fe.displayName="Badge";function oc({name:s="N/A",niche:t="N/A",productsNumber:a=0,autoreorder:r=!1,starred:n=!1,isLoading:i=!1,children:l}){return i?e.jsxs(z,{children:[e.jsx(Y,{className:"pb-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("div",{className:"space-y-1 flex-1",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"h-3 w-28 bg-muted rounded-md animate-pulse"}),e.jsx("div",{className:"h-5 w-48 bg-muted rounded-md animate-pulse"})]})}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:"h-3 w-12 bg-muted rounded-md animate-pulse"}),e.jsx("div",{className:"h-5 w-5 bg-muted rounded-md animate-pulse"})]})]})}),e.jsxs(G,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"h-3 w-8 bg-muted rounded-md animate-pulse"}),e.jsx("div",{className:"h-4 w-32 bg-muted rounded-md animate-pulse"})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsx("div",{className:"h-3 w-16 bg-muted rounded-md animate-pulse"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 bg-muted rounded-md animate-pulse"}),e.jsx("div",{className:"h-4 w-6 bg-muted rounded-md animate-pulse"})]})]}),e.jsxs("div",{className:"space-y-1 flex-1 flex flex-col items-end",children:[e.jsx("div",{className:"h-3 w-20 bg-muted rounded-md animate-pulse"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 bg-muted rounded-md animate-pulse"}),e.jsx("div",{className:"h-6 w-16 bg-muted rounded-md animate-pulse"})]})]})]})]})]}):e.jsx(z,{children:e.jsxs(G,{className:"grid grid-cols-[1fr_auto] items-start gap-4 pt-6",children:[e.jsxs("div",{className:"flex flex-col items-start gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Category Name"}),e.jsx("h3",{className:"text-lg font-semibold leading-none tracking-tight",children:s})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Niche"}),e.jsx("p",{className:"text-sm font-medium",children:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Products"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g.Package,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:a})]})]})]}),e.jsxs("div",{className:"flex flex-col items-end justify-between gap-4 h-full",children:[l,e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Starred"}),n?e.jsx(g.Star,{className:"h-5 w-5 fill-warning text-warning"}):e.jsx(g.Star,{className:"h-5 w-5 text-muted-foreground"})]}),e.jsxs("div",{className:"space-y-1 flex flex-col items-end",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Auto-reorder"}),e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(g.RefreshCw,{className:"size-4 text-success"}):e.jsx(g.RefreshCwOff,{className:"size-4 text-warning"}),e.jsx(fe,{variant:r?"success":"warning",className:"text-xs",children:r?"Enabled":"Disabled"})]})]})]})]})})}const ks=Oe.Root,cc=Oe.Group,Rs=Oe.Value,ps=R.forwardRef(({className:s,children:t,...a},r)=>e.jsxs(Oe.Trigger,{ref:r,className:v("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background data-[placeholder]:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",s),...a,children:[t,e.jsx(Oe.Icon,{asChild:!0,children:e.jsx(g.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));ps.displayName=Oe.Trigger.displayName;const er=R.forwardRef(({className:s,...t},a)=>e.jsx(Oe.ScrollUpButton,{ref:a,className:v("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(g.ChevronUp,{className:"h-4 w-4"})}));er.displayName=Oe.ScrollUpButton.displayName;const sr=R.forwardRef(({className:s,...t},a)=>e.jsx(Oe.ScrollDownButton,{ref:a,className:v("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(g.ChevronDown,{className:"h-4 w-4"})}));sr.displayName=Oe.ScrollDownButton.displayName;const gs=R.forwardRef(({className:s,children:t,position:a="popper",...r},n)=>e.jsx(Oe.Portal,{children:e.jsxs(Oe.Content,{ref:n,className:v("relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",a==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:a,...r,children:[e.jsx(er,{}),e.jsx(Oe.Viewport,{className:v("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),e.jsx(sr,{})]})}));gs.displayName=Oe.Content.displayName;const Yn=R.forwardRef(({className:s,...t},a)=>e.jsx(Oe.Label,{ref:a,className:v("px-2 py-1.5 text-sm font-semibold",s),...t}));Yn.displayName=Oe.Label.displayName;const Xe=R.forwardRef(({className:s,children:t,...a},r)=>e.jsxs(Oe.Item,{ref:r,className:v("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...a,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Oe.ItemIndicator,{children:e.jsx(g.Check,{className:"h-4 w-4"})})}),e.jsx(Oe.ItemText,{children:t})]}));Xe.displayName=Oe.Item.displayName;const dc=R.forwardRef(({className:s,...t},a)=>e.jsx(Oe.Separator,{ref:a,className:v("-mx-1 my-1 h-px bg-muted",s),...t}));dc.displayName=Oe.Separator.displayName;function uc({applicationId:s,manufacturer:t,shopifyHostName:a}){const[r]=_.usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeShopifyMutation(),[n,i]=o.useState(()=>{const A=t.Categories?.[0]?.CategoryCode??"";if(typeof window>"u")return A;const P=new URLSearchParams(window.location.search).get("category")?.trim();return P&&t.Categories?.some(T=>T.CategoryCode===P)?P:A}),[l,d]=o.useState(!1),[u,m]=o.useState(!1),[h,c]=o.useState("percentile"),[y,p]=o.useState(!1),{toast:x}=Ce(),{data:w,isLoading:N,isFetching:j}=_.useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:s,manufacturerId:t.ManufacturerId,categoryCode:n??""},{skip:!t.ManufacturerId||!n}),b=async()=>{try{d(!0),m(!1),await r({routeResellerId:s,manufacturerId:t.ManufacturerId??"",categoryCode:n,shopifyHostName:a}).unwrap()&&x({title:"Success",description:"Category synced to Shopify successfully",variant:"success"})}catch(A){console.error("Error syncing to Shopify:",A),x({title:"Error",description:"Error syncing category to Shopify.",variant:"destructive"})}finally{d(!1)}},k=()=>t.Categories?.find(A=>A.CategoryCode===n)?.CategoryName||n,S=o.useMemo(()=>w?.Products?[...w.Products].sort((A,P)=>h==="price-asc"?(A.MAP??0)-(P.MAP??0):h==="price-desc"?(P.MAP??0)-(A.MAP??0):h==="name"?(A.Title??"").localeCompare(P.Title??""):h==="percentile"?(P.OverallPercentileRank??0)-(A.OverallPercentileRank??0):0):[],[w?.Products,h]),M=o.useMemo(()=>y?S.filter(A=>{const P=A.Distribution?.Inventory;return!Array.isArray(P)||P.length===0?!1:P.reduce((T,I)=>T+(I?.AvailableQuantity??0),0)>0}):S,[y,S]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx(Or,{categories:t.Categories||[],activeCategory:n,onSelectCategory:i}),e.jsx("div",{className:"mb-4 w-full",children:e.jsx(oc,{name:k(),niche:w?.Niche||"",productsNumber:w?.Products?.length||0,autoreorder:w?.AutoReorder||!1,starred:w?.Starred||!1,isLoading:N||j,children:a&&t.Categories?.findIndex(A=>A.AvailableToBuy)!==-1&&e.jsx(D,{className:"bg-success text-success-foreground hover:bg-success/90",disabled:l,onClick:()=>m(!0),children:l?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(g.ShoppingCart,{className:"mr-2 h-4 w-4"}),"Sync Category to Shopify"]})})})}),e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsx(lc,{categories:[t.Categories?.find(A=>A.CategoryCode===n)].filter(Boolean),manufID:t.ManufacturerId,appID:s}),e.jsx(ri,{orders:w?.ActiveOrderDetails??void 0,loading:N||j})]})]}),e.jsx(Or,{categories:t.Categories||[],activeCategory:n,onSelectCategory:i}),e.jsxs("div",{className:"flex justify-between items-center mt-7 mb-4",children:[e.jsx("h4",{className:"text-xl md:text-2xl text-foreground font-bold",children:"Products"}),e.jsxs("div",{className:"flex items-center gap-4 ms-auto",children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground whitespace-nowrap",children:"Sort by:"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(ks,{value:h,onValueChange:c,children:[e.jsx(ps,{className:"w-[220px]",children:e.jsx(Rs,{})}),e.jsxs(gs,{children:[e.jsx(Xe,{value:"price-asc",children:"MAP: Low to High"}),e.jsx(Xe,{value:"price-desc",children:"MAP: High to Low"}),e.jsx(Xe,{value:"name",children:"Name"}),e.jsx(Xe,{value:"percentile",children:"Best Selling"})]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ps,{id:"in-stock-filter",checked:y,onCheckedChange:A=>p(A===!0)}),e.jsx(J,{htmlFor:"in-stock-filter",className:"text-muted-foreground whitespace-nowrap",children:"In Stock"})]})]})]}),e.jsx("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4 mb-4",children:N||j?Array.from({length:4}).map((A,P)=>e.jsx(Vt,{},P)):M.length>0?M.map(A=>e.jsx(Vt,{applicationId:s,product:A,viewProductLink:`/${s}/Product/${A.RandmarSKU}`,shopifyHostname:a},A.RandmarSKU)):e.jsxs(js,{variant:"warning",className:"col-span-1 @md:col-span-2",children:[e.jsx(g.AlertCircleIcon,{className:"h-4 w-4"}),e.jsx(bs,{children:"Warning"}),e.jsx(ys,{children:y&&S.length>0?"No in-stock products found in this category. Try turning off the In Stock filter.":"No products found for this manufacturer category."})]})}),e.jsx(De,{open:u,onOpenChange:m,children:e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Confirm Sync to Shopify"}),e.jsxs(_e,{children:['Are you sure you want to sync the category "',k(),'" to Shopify? This will add all products in this category to your Shopify store.']})]}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),e.jsx(D,{className:"bg-success text-success-foreground hover:bg-success/90",onClick:b,disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})})]})}function mc({applicationId:s,partnerId:t,userEmail:a,shopifyHostName:r,isSuperAdmin:n}){const{data:i,isLoading:l,isFetching:d}=_.useGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery({routeApplicationId:s,partnerId:t,withSpecification:!0}),{toast:u}=Ce(),[m]=_.usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(),[h,c]=o.useState(!1),[y,p]=o.useState(!1),x=async()=>{try{c(!0),p(!1),await m({routeResellerId:s??"",manufacturerId:t??"",shopifyHostName:r}).unwrap()&&u({title:"Success",description:"Manufacturer synced to Shopify successfully",variant:"success"})}catch(b){console.error("Error syncing to Shopify:",b),u({title:"Error",description:"Error syncing manufacturer to Shopify.",variant:"destructive"})}finally{c(!1)}},w=()=>i?.Manufacturer?"products":i?.Reseller?"reseller-overview":"",N=()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("tab"),j=()=>{const b=N();return b==="reseller-overview"&&i?.Reseller?"reseller-overview":b==="manufacturer-overview"&&i?.Manufacturer?"manufacturer-overview":b==="products"&&i?.Manufacturer?"products":w()};return e.jsxs("div",{className:"@container",children:[e.jsxs("div",{className:"grid gap-4 @2xl:grid-cols-2",children:[e.jsx(Xn,{account:i,loading:l||d,withAbout:!0,action:" "}),e.jsxs("div",{className:"grid gap-4",children:[(i?.Manufacturer||l||d)&&e.jsx(Zs,{manufacturer:i?.Manufacturer,loading:l||d,mainAction:e.jsxs(e.Fragment,{children:[i?.Manufacturer&&e.jsx(or,{applicationId:s,manufacturer:i?.Manufacturer}),r&&i?.Manufacturer?.Categories?.findIndex(b=>b.AvailableToBuy)!==-1&&e.jsxs(De,{open:y,onOpenChange:p,children:[e.jsx(Ys,{asChild:!0,children:e.jsx(D,{className:"ml-2 bg-success text-success-foreground hover:bg-success/90",disabled:h,children:h?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(g.ShoppingCart,{className:"mr-2 h-4 w-4"}),"Sync Manufacturer to Shopify"]})})}),e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Confirm Sync to Shopify"}),e.jsxs(_e,{children:['Are you sure you want to sync the manufacturer "',i?.Manufacturer?.PublicName,'" to Shopify? This will add all products from this manufacturer to your Shopify store.']})]}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>p(!1),children:"Cancel"}),e.jsx(D,{className:"bg-success text-success-foreground hover:bg-success/90",onClick:x,disabled:h,children:h?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):"Confirm Sync"})]})]})]})]})}),i?.Reseller&&e.jsx(ei,{reseller:i?.Reseller,loading:l||d})]})]}),(i?.Reseller||i?.Manufacturer)&&!l&&!d&&e.jsx("div",{className:"w-full p-4 sm:p-6",children:e.jsxs(Za,{defaultValue:j(),className:"w-full",children:[e.jsxs(qt,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[i?.Reseller&&e.jsx(We,{value:"reseller-overview",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Reseller Overview"}),i?.Manufacturer&&e.jsx(We,{value:"manufacturer-overview",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Manufacturer Overview"}),i?.Manufacturer&&e.jsx(We,{value:"products",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:"Products"}),e.jsxs(We,{value:"assistant",className:"relative h-12 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 text-sm font-medium text-muted-foreground shadow-none transition-none hover:text-foreground data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none cursor-pointer",children:[e.jsx(g.LucideBot,{className:"mr-2 w-4 h-4"}),"Assistant"]})]}),i?.Reseller&&e.jsx(Ze,{value:"reseller-overview",children:e.jsx("div",{className:"mt-4",children:e.jsx(Zn,{readonly:!0,appID:i.ApplicationId||"",reseller:i?.Reseller,userEmail:a,isSuperAdmin:n,withoutReports:!0})})}),i?.Manufacturer&&e.jsx(Ze,{value:"manufacturer-overview",children:e.jsx("div",{className:"mt-4",children:e.jsx(Wn,{readonly:!0,manufacturer:i?.Manufacturer,applicationId:s,userEmail:a})})}),i?.Manufacturer&&e.jsx(Ze,{value:"products",children:e.jsx("div",{className:"mt-4",children:e.jsx(uc,{applicationId:s,manufacturer:i.Manufacturer,shopifyHostName:r})})})]})}),(l||d)&&e.jsx("div",{className:"mt-4 flex h-32 w-full items-center justify-center p-4 sm:p-6",children:e.jsx(g.Loader2,{className:"h-8 w-8 animate-spin text-primary"})})]})}const xc=({reseller:s,appID:t,isLoading:a,readonly:r,onUnsavedChanges:n})=>{const{toast:i}=Ce(),[l]=_.usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),[d,u]=o.useState({}),m=o.useMemo(()=>({publicEmail:s.PublicEmail??"",contactName:s.ContactName??"",phone:s.Phone??"",website:s.Website??""}),[s]),{register:h,handleSubmit:c,reset:y,watch:p,formState:{errors:x,isSubmitting:w}}=bt.useForm({defaultValues:m}),N=p(),j=o.useCallback(()=>d?JSON.stringify(N)!==JSON.stringify(d):!1,[N,d]);o.useEffect(()=>{n&&n(j())},[j,n]),o.useEffect(()=>{s&&Object.keys(s).length>0&&(y(m),u(m))},[s,y,m]);const b=async S=>{let M=!0,A=!1;const P=Object.keys(S).map(E=>({key:E,keyApi:E.charAt(0).toUpperCase()+E.slice(1)}));for(const E of P){const T=S[E.key],I=s[E.keyApi];if(T!==I&&T!==void 0){A=!0;try{await l({applicationId:t,fieldName:E.keyApi,newValue:String(T)}).unwrap()||(M=!1)}catch(B){console.error(`Error updating ${E.keyApi}:`,B),M=!1}}}M&&A?(i({title:"Public info",description:"Information updated successfully",variant:"success"}),u({...S}),n&&n(!1)):M||i({title:"Updation error",description:"Failed to update",variant:"destructive"})},k=S=>!S||S.trim()==="";return a?e.jsxs(z,{children:[e.jsx(Y,{children:e.jsx(me,{children:"Public Information"})}),e.jsx(G,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-32"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-24"}),e.jsx(f,{className:"h-10 w-full"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-20"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-4 w-28"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(f,{className:"h-10 w-20"})})]})})]}):e.jsxs(z,{children:[e.jsx(Y,{children:e.jsxs(me,{className:"text-1xl font-bold",children:["Public Information ",r?"(read only)":""]})}),e.jsxs(G,{children:[(k(p("contactName"))||k(p("publicEmail"))||k(p("website"))||k(p("phone")))&&e.jsxs(js,{variant:"destructive",className:"mb-6",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(bs,{children:"Missing information"}),e.jsx(ys,{children:"All fields are required to get started at working with Manufacturers."})]}),e.jsxs("form",{onSubmit:c(b),className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"contactName",children:"Main Representative *"}),e.jsx(le,{id:"contactName",placeholder:"John Doe",readOnly:r,...h("contactName",{}),className:x.contactName||k(p("contactName"))?"input-error-indicator":""}),x.contactName&&e.jsx("p",{className:"text-destructive text-sm",children:x.contactName.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"publicEmail",children:"Public Email *"}),e.jsx(le,{id:"publicEmail",placeholder:"contact@company.com",readOnly:r,...h("publicEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:x.publicEmail||k(p("publicEmail"))?"input-error-indicator":""}),x.publicEmail&&e.jsx("p",{className:"text-destructive text-sm",children:x.publicEmail.message})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"website",children:"Website *"}),e.jsx(le,{id:"website",placeholder:"https://company.com",readOnly:r,...h("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:x.website||k(p("website"))?"input-error-indicator":""}),x.website&&e.jsx("p",{className:"text-destructive text-sm",children:x.website.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium leading-none",htmlFor:"phone",children:"Phone Number *"}),e.jsx(le,{id:"phone",placeholder:"+1 (555) 123-4567",readOnly:r,...h("phone",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:x.phone||k(p("phone"))?"input-error-indicator":""}),x.phone&&e.jsx("p",{className:"text-destructive text-sm",children:x.phone.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(D,{type:"submit",disabled:w||r,className:r?"hidden":"",children:w?"Saving...":"Save"})})]})]})]})};function hc({appID:s,reseller:t,isLoading:a,withoutReports:r,userEmail:n,isSuperAdmin:i}){const{toast:l}=Ce(),{Statement:d,CreditLimit:u}=t,[m,h]=o.useState(!1),[c,y]=o.useState(!1),[p,x]=o.useState(!1),[w,N]=o.useState(!1),[j,b]=o.useState(n||""),[k,S]=o.useState(!1),[M,A]=o.useState(u?.toString()||""),[P,{isLoading:E}]=_.usePostV4PartnerByApplicationIdAccountResellerCreditLimitMutation(),T=[{label:"0 - 30 Days",value:e.jsx(os.FormattedNumber,{value:d?.Over0||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:g.Calendar},{label:"31 - 45 Days",value:e.jsx(os.FormattedNumber,{value:d?.Over30||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:g.CalendarDays},{label:"45+ Days",value:e.jsx(os.FormattedNumber,{value:d?.Over45||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:g.CalendarRange},{label:"Total",value:e.jsx(os.FormattedNumber,{value:d?.Total||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:g.DollarSign},{label:"Credit Limit",value:e.jsxs(e.Fragment,{children:[e.jsx(os.FormattedNumber,{value:u||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),i&&e.jsx(D,{size:"icon",variant:"outline",className:"ml-2",onClick:()=>{S(!0),A(u?.toString()||"")},children:e.jsx(g.EditIcon,{})})]}),icon:g.CreditCard}],[I]=_.useLazyGetV4ResellerByRouteResellerIdDocumentAndDocumentNumberPdfQuery(),B=async O=>{O?h(!0):y(!0);try{const W=(await I({routeResellerId:s,documentNumber:`ST${s}`})).data;if(!W)throw new Error("No data received for download.");if(O)window.open(W);else{const ne=document.createElement("a");ne.href=W,ne.download=`ST${s}.pdf`,document.body.appendChild(ne),ne.click(),ne.remove()}l({title:"Success",description:"Statement downloaded successfully.",variant:"success"})}catch(q){console.error("Download Error:",q),l({title:"Error",description:"An error occurred while downloading the statement. Please try again.",variant:"destructive"})}finally{O?h(!1):y(!1)}},[F]=_.usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),U=async()=>{if(!j||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(j)){l({title:"Invalid Email",description:"Please enter a valid email address.",variant:"destructive"});return}x(!0);try{await F({routeResellerId:s,emailAddress:j}).unwrap(),l({title:"Success",description:`Statement sent to ${j} successfully.`,variant:"success"}),N(!1)}catch(q){console.error("Send Email Error:",q),l({title:"Error",description:"An error occurred while sending the statement. Please try again.",variant:"destructive"})}finally{x(!1)}};if(a)return e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{className:"border-b p-6 md:p-5",children:e.jsx(f,{className:"h-6 w-36"})}),e.jsxs(G,{className:"p-6 md:p-5",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 sm:divide-x divide-border",children:[e.jsx("div",{className:"space-y-6 sm:pe-4",children:[1,2,3].map(O=>e.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-24"})]}),e.jsx(f,{className:"h-5 w-20 ms-auto"})]},O))}),e.jsx("div",{className:"space-y-6 sm:ps-4 pt-6 sm:pt-0 mt-6 sm:mt-0 border-t sm:border-t-0 border-border",children:[1,2].map(O=>e.jsx("div",{className:O===2?"pt-6 mt-6 border-t border-border":"",children:e.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-24"})]}),e.jsx(f,{className:"h-5 w-20 ms-auto"})]})},O))})]}),e.jsxs("div",{className:"flex justify-end mt-6 gap-2",children:[e.jsx(f,{className:"h-10 w-32"}),e.jsx(f,{className:"h-10 w-28"})]})]})]});const V=!r;return e.jsxs(e.Fragment,{children:[e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{className:"border-b p-6 md:p-5",children:e.jsx(me,{className:"text-1xl font-bold",children:"Billing Overview"})}),e.jsxs(G,{className:"p-6 md:p-5",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 sm:divide-x divide-border",children:[e.jsx("div",{className:"space-y-6 sm:pe-4",children:T.slice(0,3).map((O,q)=>e.jsx(Lr,{icon:O.icon,label:O.label,value:O.value},q))}),e.jsx("div",{className:"space-y-6 sm:ps-4 pt-6 sm:pt-0 mt-6 sm:mt-0 border-t sm:border-t-0 border-border",children:T.slice(3).map((O,q)=>e.jsx("div",{className:q===1?"pt-6 mt-6 border-t border-border":"",children:e.jsx(Lr,{icon:O.icon,label:O.label,value:O.value})},q))})]}),V&&e.jsxs("div",{className:"flex justify-end mt-6 gap-2",children:[e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"icon",onClick:()=>B(!0),disabled:m,children:m?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.Printer,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Print Statement"})})]})}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"icon",onClick:()=>B(!1),disabled:c,children:c?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.Download,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Download Statement"})})]})}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"outline",size:"icon",onClick:()=>N(!0),disabled:p,children:p?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.Mail,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Email Statement"})})]})}),e.jsx(ve.Link,{to:`${window.location.hostname==="dashboard.randmar.io"?"":"https://dashboard.randmar.io"}/${s}/PayInvoice`,target:window.location.hostname==="dashboard.randmar.io"?"_self":"_blank",children:e.jsxs(D,{children:[e.jsx(g.CreditCard,{className:"mr-2 h-4 w-4"}),"Pay Invoices"]})})]})]})]}),e.jsx(De,{open:w,onOpenChange:N,children:e.jsxs(Me,{className:"sm:max-w-[425px]",children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Send Statement by Email"}),e.jsx(_e,{children:"Enter the recipient's email address below. The statement will be sent as a PDF attachment."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx(J,{htmlFor:"email",className:"text-right",children:"Email"}),e.jsx(le,{id:"email",type:"email",value:j,onChange:O=>b(O.target.value),className:"col-span-3",placeholder:"recipient@example.com"})]})}),e.jsx(ze,{children:e.jsx(D,{type:"submit",onClick:U,disabled:p||!j,children:p?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):e.jsxs(e.Fragment,{children:[e.jsx(g.Send,{className:"mr-2 h-4 w-4"}),"Send"]})})})]})}),e.jsx(De,{open:k,onOpenChange:S,children:e.jsxs(Me,{className:"sm:max-w-[425px]",children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Edit Credit Limit"}),e.jsx(_e,{children:"Enter the new credit limit for this reseller."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[e.jsx(J,{htmlFor:"creditLimit",className:"text-right",children:"Amount"}),e.jsx(le,{id:"creditLimit",type:"number",value:M,onChange:O=>A(O.target.value),className:"col-span-3",placeholder:"0.00"})]})}),e.jsx(ze,{children:e.jsx(D,{type:"submit",onClick:async()=>{const O=Number(M);if(isNaN(O)){l({title:"Invalid Amount",description:"Please enter a valid number for credit limit.",variant:"destructive"});return}try{await P({applicationId:s,newValue:O}).unwrap(),S(!1),l({title:"Success",description:"Credit limit updated successfully.",variant:"success"})}catch(q){console.error("Update Credit Limit Error:",q),l({title:"Error",description:"Failed to update credit limit. Please try again.",variant:"destructive"})}},disabled:E,children:E?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})})]})}function Lr({icon:s,label:t,value:a}){return e.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s,{className:"size-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:t})]}),e.jsx("span",{className:"text-base font-semibold ms-auto",children:a})]})}function fc({open:s,setOpen:t,tier:a,onTierChange:r,isLoading:n}){const i=()=>{t(!1)};return e.jsx(De,{open:s,onOpenChange:t,children:e.jsxs(Me,{className:"sm:max-w-[425px]",children:[e.jsx(Le,{children:e.jsx($e,{children:"Change Pricing Tier"})}),e.jsxs("div",{className:"grid gap-1.5 py-2",children:[e.jsxs("p",{className:"text-lg text-muted-foreground",children:["Requested Pricing Tier: ",e.jsx("span",{className:"font-bold",children:a})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"If your account qualifies, your pricing will update immediately."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"If not, we'll review your request and notify you of the decision."})]}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:i,disabled:n,children:"Cancel"}),e.jsx(D,{onClick:r,disabled:n,children:n?"Loading...":`Apply for ${a}`})]})]})})}const pc=s=>s===1?"The Best":s===2?"Fixed 12.5% GP on all items":s===3?"Advantageous":s===4?"Buying Group":s===5?"Cost":s,gc=s=>s==="A"?"Free or Custom":s==="B"?"Fixed $10 anywhere":s==="C"?`Free shipping on $150+ orders to your location,
47
47
  $15 for drop shipped orders under $1,500,
48
- $10 with opportunities under $1,000`:s==="D"?"$15 under $1,500":s==="E"?"Full shipping charges":s,jc=s=>s==="STRIPE"?"Credit card payment":s==="NET30"?"Net 30 days":s,bc=({isSuperAdmin:s,readonly:t,reseller:a,appID:r,isLoading:n})=>{const{toast:i}=Ce(),[l,d]=o.useState(!1),[u,m]=o.useState(""),[h,{isLoading:c}]=_.usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),y=O=>O&&{Starter:"starter","E-Commerce":"ecommerce",Commercial:"commercial",Basics:"cws",Novexco:"novexco",COOPSCO:"coopsco","Jean Coutu":"jeancoutu",Exclusive:"exclusive"}[O]||"",p=O=>O&&{A:"free",B:"fixed",C:"dropshipped",D:"under1500",E:"fullcharges"}[O]||"",x=O=>O&&{1:"exclusive",2:"ecommerce",3:"commercial",4:"buyinggroup",5:"cost"}[O]||"",[w,N]=o.useState(y(a?.Priority??"")),[j,b]=o.useState(p(a?.ShippingProfile??"")),[k,S]=o.useState(x(a?.PriceProfile)),M=O=>({starter:"Starter",ecommerce:"E-Commerce",commercial:"Commercial",cws:"Basics",novexco:"Novexco",coopsco:"COOPSCO",jeancoutu:"Jean Coutu",exclusive:"Exclusive"})[O]||O,A=O=>({free:"A",fixed:"B",dropshipped:"C",under1500:"D",fullcharges:"E"})[O]||O,P=O=>({exclusive:"1",ecommerce:"2",commercial:"3",buyinggroup:"4",cost:"5"})[O]||O;o.useEffect(()=>{N(y(a?.Priority??"")),b(p(a?.ShippingProfile??"")),S(x(a?.PriceProfile))},[a]);const E=async(O,q,W,ne)=>{try{(await h({applicationId:r,fieldName:O,newValue:q})).error?i({title:"Error",description:ne,variant:"destructive"}):i({title:"Success",description:W,variant:"success"})}catch{i({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}},T=async O=>{N(O);const q=M(O);E("Priority",q,`Priority updated to ${q}`,"Failed to update priority")},I=async O=>{b(O);const q=A(O);E("ShippingProfile",q,`Shipping profile updated to ${q}`,"Failed to update shipping profile")},B=async O=>{S(O);const q=P(O);E("PriceProfile",q,`Pricing profile updated to ${q}`,"Failed to update pricing profile")},F=async()=>{try{const O=await h({applicationId:r,fieldName:"Tier",newValue:u});O.error?i({title:"Error",description:"Failed to update reseller",variant:"destructive"}):O.data?i({title:"Success",description:`Pricing Tier changed to ${u}`,variant:"success"}):i({title:"Considered",description:"Request being considered",variant:"success"})}catch{i({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}finally{d(!1),m("")}},U=[{name:"Terms",enabled:a.Priority==="Starter"},{name:"E-Commerce",enabled:a.Priority==="Commercial"},{name:"Commercial",enabled:a.Priority==="E-Commerce"},{name:"Exclusive",enabled:s}],V=O=>{m(O),d(!0)};return n?e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-6 w-28"}),e.jsx(f,{className:"h-6 w-16 rounded-full"})]})}),e.jsxs(G,{children:[e.jsxs("div",{className:"mb-3",children:[e.jsx(f,{className:"h-8 w-40 mb-1"}),e.jsx(f,{className:"h-4 w-56"})]}),e.jsx("div",{className:"grid gap-3",children:[1,2,3].map(O=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"h-8 w-8 rounded-full shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(f,{className:"h-5 w-20 mb-1"}),e.jsx(f,{className:"h-4 w-full"})]})]},O))}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(f,{className:"h-10 w-full"}),e.jsx(f,{className:"h-10 w-full"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(z,{className:"w-full",children:[e.jsxs(Y,{className:"pb-2 pt-4 px-4 flex flex-row items-center justify-between",children:[e.jsx(me,{className:"text-base font-medium text-foreground",children:"Account Tier"}),e.jsx(fe,{variant:"success",className:"text-xs",children:"Active"})]}),e.jsxs(G,{className:"pt-2 px-4 pb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 bg-primary/5 p-4 rounded-lg",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-bold text-primary",children:[a?.Priority||""," Tier"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optimized for online retail"})]}),e.jsx(g.CheckCircle2,{className:"h-6 w-6 text-success"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[e.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:e.jsx(g.Package2,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"Pricing"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:pc(a.PriceProfile||0)})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[e.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:e.jsx(g.Truck,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"Shipping"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:gc(a.ShippingProfile||"").split(".")[0]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[e.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:e.jsx(g.Calendar,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"Payment terms"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:jc(a?.Terms||"")})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[!t&&e.jsx(D,{variant:"outline",className:"flex-1",asChild:!0,children:e.jsxs(ve.Link,{to:"https://randmar.io/pricing",target:"_blank",children:[e.jsx(g.ExternalLink,{className:"h-4 w-4 mr-1"}),"Pricing Tiers"]})}),e.jsxs(wt,{children:[e.jsx(St,{asChild:!0,children:e.jsxs(D,{disabled:t,className:t?"hidden":"flex-1",children:["Upgrade Tier ",e.jsx(g.ChevronRight,{className:"h-3 w-3 ml-1"})]})}),e.jsx(it,{className:"w-56 p-2",children:e.jsxs("div",{className:"grid gap-1",children:[e.jsx("h4",{className:"font-medium text-xs mb-1",children:"Select a tier"}),U.map(O=>e.jsx(D,{variant:"ghost",size:"sm",className:"w-full justify-start h-8",disabled:!O.enabled,onClick:()=>V(O.name),children:O.name},O.name))]})})]})]})]})]}),e.jsx(fc,{isLoading:c,open:l,setOpen:d,tier:u,onTierChange:F}),s&&!t&&e.jsxs(z,{className:"mt-4",children:[e.jsx(Y,{className:"pb-2 pt-3 px-4",children:e.jsx(me,{className:"text-1xl font-bold",children:"Admin Configuration"})}),e.jsx(G,{className:"pt-2 px-4 pb-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[e.jsx(J,{className:"block mb-1 text-xs font-medium",children:"Priority"}),e.jsx(Hs,{value:w,onValueChange:T,className:"grid grid-cols-2 @sm:grid-cols-3 @md:grid-cols-4 gap-1",children:[{value:"starter",label:"Starter"},{value:"ecommerce",label:"E-Commerce"},{value:"commercial",label:"Commercial"},{value:"cws",label:"CWS (Basics)"},{value:"novexco",label:"Novexco"},{value:"coopsco",label:"COOPSCO"},{value:"jeancoutu",label:"Jean Coutu"},{value:"exclusive",label:"Exclusive"}].map(O=>e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(xs,{value:O.value,id:`priority-${O.value}`,className:"h-6 w-6 scale-50"}),e.jsx(J,{htmlFor:`priority-${O.value}`,className:"cursor-pointer text-xs",children:O.label})]},O.value))})]}),e.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[e.jsx(J,{className:"block mb-1 text-xs font-medium",children:"Shipping Profile"}),e.jsx(Hs,{value:j,onValueChange:I,className:"grid grid-cols-1 @md:grid-cols-2 gap-1",children:[{value:"free",label:"Free (A)"},{value:"fixed",label:"Fixed $10 Shipping (B)"},{value:"dropshipped",label:"$15 for drop shipped (C)"},{value:"under1500",label:"15$ under 1,500 (D)"},{value:"fullcharges",label:"Full shipping charges (E)"}].map(O=>e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(xs,{value:O.value,id:`shipping-${O.value}`,className:"h-6 w-6 scale-50"}),e.jsx(J,{htmlFor:`shipping-${O.value}`,className:"cursor-pointer text-xs",children:O.label})]},O.value))})]}),e.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[e.jsx(J,{className:"block mb-1 text-xs font-medium",children:"Pricing Profile"}),e.jsx(Hs,{value:k,onValueChange:B,className:"grid grid-cols-2 @sm:grid-cols-3 gap-1",children:[{value:"exclusive",label:"Exclusive (1)"},{value:"ecommerce",label:"E-Commerce (2)"},{value:"commercial",label:"Commercial (3)"},{value:"buyinggroup",label:"Buying Group (4)"},{value:"cost",label:"Cost (5)"}].map(O=>e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(xs,{value:O.value,id:`pricing-${O.value}`,className:"h-6 w-6 scale-50 antialiased"}),e.jsx(J,{htmlFor:`pricing-${O.value}`,className:"cursor-pointer text-xs",children:O.label})]},O.value))})]})]})})]})]})};function yc({openOrders:s=[],isLoading:t=!1}){const a=s?.filter(w=>w.DocumentType==="Order")||[],r=s?.filter(w=>w.DocumentType==="Shipment")||[],n=a.filter(w=>w.WarehouseCode!=="3PLE"),i=n.reduce((w,N)=>w+(N.Quantity??0),0),l=n.reduce((w,N)=>w+(N.ExtendedPrice??0),0),d=a.filter(w=>w.WarehouseCode==="3PLE"),u=d.reduce((w,N)=>w+(N.Quantity??0),0),m=d.reduce((w,N)=>w+(N.ExtendedPrice??0),0),h=r.reduce((w,N)=>w+(N.Quantity??0),0),c=r.reduce((w,N)=>w+(N.ExtendedPrice??0),0),y=i+u+h,p=l+m+c,x=[{name:"All",icon:g.Package,stripeClass:"bg-info/60",iconBgClass:"bg-info/90",iconTextClass:"text-info-foreground",orders:y,amount:p},{name:"Processing",icon:g.RefreshCcw,stripeClass:"bg-warning/60",iconBgClass:"bg-warning/90",iconTextClass:"text-warning-foreground",orders:i,amount:l},{name:"Shipped",icon:g.Truck,stripeClass:"bg-success/60",iconBgClass:"bg-success/90",iconTextClass:"text-success-foreground",orders:h,amount:c},{name:"Delayed",icon:g.AlertCircle,stripeClass:"bg-destructive/60",iconBgClass:"bg-destructive/90",iconTextClass:"text-destructive-foreground",orders:u,amount:m}];return t?e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(f,{className:"h-7 w-40"})}),e.jsx(G,{children:e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:[1,2,3,4].map(w=>e.jsx(z,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:e.jsxs(G,{className:"p-0",children:[e.jsx("div",{className:"bg-border h-[3px]"}),e.jsxs("div",{className:"p-6 border border-t-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx(f,{className:"h-5 w-24"}),e.jsx(f,{className:"h-8 w-8 rounded-full"})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx(f,{className:"h-3 w-20 mb-1"}),e.jsx(f,{className:"h-6 w-12"})]}),e.jsxs("div",{className:"text-end",children:[e.jsx(f,{className:"h-3 w-20 mb-1"}),e.jsx(f,{className:"h-5 w-20"})]})]})]})]})},w))})})]}):e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-base font-medium text-foreground",children:"Order Categories"})}),e.jsx(G,{children:e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:x.map(w=>e.jsx(z,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:e.jsxs(G,{className:"p-0",children:[e.jsx("div",{className:`${w.stripeClass} h-[3px]`}),e.jsxs("div",{className:"p-6 border border-t-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:"font-semibold text-base",children:w.name}),e.jsx("div",{className:`${w.iconBgClass} p-2 rounded-full`,children:e.jsx(w.icon,{className:`size-4 shrink-0 ${w.iconTextClass}`})})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Orders"}),e.jsx("p",{className:"text-xl font-bold",children:w.orders})]}),e.jsxs("div",{className:"text-end",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),e.jsx("p",{className:"text-base font-semibold",children:e.jsx(os.FormattedNumber,{value:w.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},w.name))})})]})}function Nc({isLoading:s,userEmail:t,appID:a}){const{toast:r}=Ce(),[n,{isLoading:i}]=_.usePostV4ResellerByRouteResellerIdReportWalmartTrackingFileEmailMutation(),[l,{isLoading:d}]=_.usePostV4ResellerByRouteResellerIdReportAmazonTrackingFileEmailMutation(),[u,{isLoading:m}]=_.usePostV4ResellerByRouteResellerIdReportOpenOrdersEmailMutation(),[h,{isLoading:c}]=_.usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[y,{isLoading:p}]=_.usePostV4ResellerByRouteResellerIdReportInvoicesEmailMutation(),[x,{isLoading:w}]=_.usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),[N,j]=o.useState(null),[b,k]=o.useState(t),[S,M]=o.useState(!1),[A,P]=o.useState("all"),{data:E,isLoading:T}=_.useGetV4PartnerByRouteApplicationIdManufacturersQuery({routeApplicationId:a,withSpecification:!1}),I=[{name:"Products",reports:[{id:"Products",title:"Universal Product List",description:"A comprehensive overview of your product list with detailed specifications and pricing information.",icon:g.Package}]},{name:"Operation Details",reports:[{id:"OpenOrders",title:"Order Details",description:"A detailed report of all your orders and shipments, including status, tracking information, and delivery estimates.",icon:g.ShoppingCart},{id:"Invoices",title:"Invoices and Credits Report",description:"Detailed overview of your invoices and credits within a specific date range. It also contains reports about additional charges, serial numbers, and other relevant information.",icon:g.ScrollText},{id:"Statement",title:"Statement and RMAs Report",description:"A detailed report of all unpaid invoices and active RMAs.",icon:g.Banknote}]},{name:"Tracking Files",reports:[{id:"AmazonTrackingFile",title:"Amazon Tracking File",description:"Track products sold on Amazon marketplace with detailed sales and inventory information.",icon:g.BarChart},{id:"WalmartTrackingFile",title:"Walmart Tracking File",description:"Track products sold on Walmart marketplace with detailed sales and inventory information.",icon:g.BarChart}]}],B=async V=>{j(V),V.id==="Products"&&P("all"),M(!0)},F=async()=>{if(!(!N||!a))try{switch(N.id){case"Products":{const V={routeResellerId:a,emailAddress:b};A&&A!=="all"&&(V.manufacturerId=A),await h(V).unwrap();break}case"AmazonTrackingFile":await l({routeResellerId:a,emailAddress:b}).unwrap();break;case"WalmartTrackingFile":await n({routeResellerId:a,emailAddress:b}).unwrap();break;case"OpenOrders":await u({routeResellerId:a,emailAddress:b}).unwrap();break;case"Invoices":await y({routeResellerId:a,emailAddress:b}).unwrap();break;case"Statement":await x({routeResellerId:a,emailAddress:b}).unwrap();break;default:throw new Error("invalid report id")}r({title:"Report requested",description:`The ${N.title} will be sent to ${b} shortly.`,variant:"success"}),M(!1)}catch(V){console.error("Error requesting report:",V),r({title:"Error",description:"Failed to request report. Please try again.",variant:"destructive"})}},U=m||c||d||i||w||p;return e.jsxs(z,{children:[e.jsxs(Y,{children:[e.jsx(me,{className:"text-1xl font-bold",children:"Reports"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Download essential business reports, from your Product List to your Order Details."})]}),e.jsx(G,{className:"space-y-6",children:s?e.jsx(e.Fragment,{children:[1,2,3].map(V=>e.jsxs("div",{className:"space-y-4",children:[e.jsx(f,{className:"h-6 w-48"}),[1,2].map(O=>e.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg",children:[e.jsx(f,{className:"h-9 w-9 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(f,{className:"h-5 w-40 mb-2"}),e.jsx(f,{className:"h-4 w-full"})]}),e.jsx(f,{className:"h-9 w-24"})]},O))]},V))}):e.jsx(e.Fragment,{children:I.map(V=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:V.name}),V.reports.map(O=>e.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg hover:bg-muted transition-colors",children:[e.jsx("div",{className:"bg-primary/10 p-2 rounded-full",children:e.jsx(O.icon,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-sm",children:O.title}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:O.description})]}),e.jsxs(D,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>B(O),children:[e.jsx(g.Download,{className:"h-4 w-4"}),"Request"]})]},O.id))]},V.name))})}),e.jsx(De,{open:S,onOpenChange:M,children:e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsxs($e,{children:["Request ",N?.title]}),e.jsx(_e,{children:"Enter the email address where you would like to receive the report."})]}),e.jsxs("div",{className:"py-4",children:[e.jsx(J,{htmlFor:"email",children:"Email"}),e.jsx(le,{id:"email",value:b,onChange:V=>k(V.target.value),placeholder:"your@email.com",className:"mt-2"})]}),N?.id==="Products"&&e.jsxs("div",{className:"py-2",children:[e.jsx(J,{htmlFor:"manufacturer",children:"Manufacturer"}),e.jsxs("select",{id:"manufacturer",className:"mt-2 block w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:A,onChange:V=>P(V.target.value),disabled:T,children:[e.jsx("option",{value:"all",children:"All manufacturers"}),!T&&Array.isArray(E)&&E.slice().sort((V,O)=>(V.PublicName||V.Name||"").localeCompare(O.PublicName||O.Name||"")).map(V=>V?.ManufacturerId?e.jsx("option",{value:V.ManufacturerId,children:(V.PublicName||V.Name||V.ManufacturerId)+(V.OpenToWork?" (Open to Work)":"")},V.ManufacturerId):null)]})]}),e.jsx(_e,{children:"The report will take around 5 minutes to generate."}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>M(!1),children:"Cancel"}),e.jsx(D,{onClick:F,disabled:!b||U,children:U?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function Jn({qualification:s}){return!s.QualificationId||s.QualificationId==="Suspended"?null:s.QualificationId==="Do Not Sell"?e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsxs(fe,{variant:"destructive",children:[e.jsx(g.X,{className:"h-3 w-3 mr-1"}),"Do Not Sell"]})}),e.jsx(pe,{children:e.jsx("p",{children:"Qualification"})})]})}):e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsxs(fe,{variant:"info",className:s.DefaultOpportunityNumber?"pr-1":"",children:[e.jsx(g.BadgeCheck,{className:"h-3 w-3 mr-1"}),s.QualificationId,s.DefaultOpportunityNumber&&e.jsx(fe,{variant:"secondary",size:"sm",className:"ml-1",children:s.DefaultOpportunityNumber})]})}),e.jsx(pe,{children:e.jsx("p",{children:"Qualification"})})]})})}function Vs({statistics:s,mode:t="month",chartHeight:a,loading:r=!1,size:n="default"}){const[i,l]=o.useState([]),[d,u]=o.useState(!1),m=[{name:"dollarVolume",label:"Dollar Volume",color:"var(--primary)",dotClassName:"bg-primary",yAxisId:"left",format:"money"},{name:"unitsSold",label:"Units Sold",color:"var(--chart-2)",dotClassName:"bg-chart-2",units:" units",yAxisId:"right",format:"integer"}];return o.useEffect(()=>{if(r||!s){l([]);return}let h;if(t==="week"){const c=new Map;s.forEach(y=>{const p=y.Day?.toString()||"";if(p.length===8){const x=parseInt(p.substring(0,4),10),w=parseInt(p.substring(4,6),10)-1,N=parseInt(p.substring(6,8),10),j=new Date(x,w,N),b=new Date(j);b.setDate(j.getDate()-j.getDay());const k=`${b.getFullYear()}-${String(b.getMonth()+1).padStart(2,"0")}-${String(b.getDate()).padStart(2,"0")}`,S=c.get(k)||{price:0,quantity:0};S.price+=y.ExtendedPrice||0,S.quantity+=y.Quantity||0,c.set(k,S)}}),h=Array.from(c).sort(([y],[p])=>y.localeCompare(p)).map(([y,p])=>({date:`${y.substring(5,7)}/${y.substring(8,10)}`,dollarVolume:p.price,unitsSold:p.quantity}))}else{const c=new Date,y=c.getFullYear(),p=c.getMonth(),x=c.getDate(),w=`${y}-${(p+1).toString().padStart(2,"0")}`,N=Array.from({length:12},(b,k)=>{const S=new Date(y,p-(11-k),1);return`${S.getFullYear()}-${(S.getMonth()+1).toString().padStart(2,"0")}`}),j=Object.fromEntries(N.map(b=>[b,{price:0,quantity:0}]));if(s.forEach(b=>{const k=String(b.Day??0);if(k.length!==8)return;const S=`${k.substring(0,4)}-${k.substring(4,6)}`;j[S]&&(j[S].price+=b.ExtendedPrice??0,j[S].quantity+=b.Quantity??0)}),h=N.map(b=>{const k=j[b],[S,M]=b.split("-").map(Number);return{date:new Date(S,M-1).toLocaleString("default",{month:"short",year:"numeric"}),dollarVolume:k.price,unitsSold:k.quantity}}),d){const b=j[w];if(b&&b.price>0&&x>0){const k=new Date(y,p+1,0).getDate();if(x<k){const S=b.price/x,M=b.quantity/x,A=S*k,P=M*k,E=h[h.length-1];E&&(E.dollarVolume=A,E.unitsSold=P)}}}}l(h)},[s,t,d,r]),r?e.jsx("div",{style:{height:a},children:e.jsx(f,{className:"h-full w-full rounded-md"})}):i.length===0?e.jsx("div",{style:{height:a},className:"flex items-center justify-center text-muted-foreground",children:"No sales data available."}):e.jsxs(e.Fragment,{children:[e.jsx(Bn,{data:i,series:m,height:a,size:n}),n==="default"&&t==="month"&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(at,{checked:d,onCheckedChange:u,id:"extrapolate-switch"}),e.jsx(J,{htmlFor:"extrapolate-switch",children:"Extrapolate Current Month"})]}),d&&e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["* Values for ",new Date().toLocaleString("default",{month:"long"})," are projected estimates."]})]})]})}function tr({type:s,applicationId:t,publicName:a,name:r,location:n,link:i,linkNewTab:l=!0,children:d}){const[u,m]=o.useState(!1),h=y=>{y.preventDefault(),y.stopPropagation(),navigator.clipboard.writeText(t),m(!0),setTimeout(()=>m(!1),2e3)},c=e.jsxs(Y,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-12 w-12 overflow-hidden rounded-md",children:e.jsx(us,{id:t,width:48,height:48},`partner_logo_${t}`)}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-primary",children:s}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"|"}),e.jsx(ye,{children:e.jsxs(ge,{delayDuration:300,children:[e.jsx(je,{asChild:!0,children:e.jsxs("div",{className:"flex cursor-pointer items-center gap-1",onClick:h,children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t}),u?e.jsx(g.Check,{className:"h-3 w-3 text-success"}):e.jsx(g.Copy,{className:"h-3 w-3 text-muted-foreground"})]})}),e.jsx(pe,{children:e.jsx("p",{children:u?"Copied!":"Copy ID"})})]})})]}),e.jsx("h3",{className:"font-semibold",children:a||"N/A"}),r&&e.jsx("p",{className:"text-sm text-muted-foreground",children:r}),n&&e.jsx("p",{className:"text-sm text-muted-foreground",children:n})]})]}),d&&e.jsx("div",{className:"flex flex-col items-end gap-2",children:d})]});return i?e.jsx(ve.Link,{to:i,target:l?"_blank":"_self",children:c}):c}function Zs({manufacturer:s,link:t,linkNewTab:a=!0,actions:r,mainAction:n,loading:i=!1,appID:l}){const{toast:d}=Ce(),[u,{isLoading:m}]=_.usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[h,c]=o.useState(!1),[y,p]=o.useState(""),{data:x}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:l||""},{skip:!l}),w=x?.IsReseller;if(i||!s)return e.jsxs(z,{className:"flex flex-col h-full",children:[e.jsxs(Y,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"h-12 w-12 rounded-md"}),e.jsxs("div",{children:[e.jsx(f,{className:"h-3 w-24 mb-2"}),e.jsx(f,{className:"h-5 w-40 mb-1"}),e.jsx(f,{className:"h-4 w-32 mb-1"}),e.jsx(f,{className:"h-4 w-48"})]})]}),e.jsx(f,{className:"h-16 w-24"})]}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex flex-col space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(f,{className:"h-5 w-16 rounded-full"}),e.jsx(f,{className:"h-5 w-20 rounded-full"}),e.jsx(f,{className:"h-5 w-14 rounded-full"})]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-32"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-40"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-36"})]})]})]})}),e.jsxs(ms,{className:"flex justify-between pt-2 gap-2 mt-auto",children:[e.jsx(f,{className:"h-9 w-24"}),e.jsx(f,{className:"h-9 w-40"})]})]});const N=[s.City,s.Province,s.Country].filter(Boolean),j=N.length>0?N.join(", "):"",b=s.Tags?.split(",").map(S=>S.trim()).filter(Boolean)||[],k=async()=>{if(!(!s?.ManufacturerId||!l||!y))try{await u({routeResellerId:l,emailAddress:y,manufacturerId:s.ManufacturerId}).unwrap(),d({title:"Report requested",description:`The Universal Product List for this manufacturer will be sent to ${y} shortly.`,variant:"success"}),c(!1)}catch(S){console.error("Error requesting product list:",S),d({title:"Error",description:"Failed to request product list. Please try again.",variant:"destructive"})}};return e.jsxs(z,{className:"flex flex-col h-full",children:[e.jsx(tr,{type:"Manufacturer",applicationId:s.ManufacturerId,publicName:s.PublicName,name:s.Name,location:j,link:t,linkNewTab:a,children:e.jsx("div",{className:"flex flex-col items-end gap-2",children:s.SalesStatistics&&s.SalesStatistics.length>0&&e.jsx("div",{className:"h-16 w-24",children:e.jsx(Vs,{statistics:s.SalesStatistics,size:"mini"})})})}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex",children:[e.jsxs("div",{className:"flex flex-col flex-1 space-y-2",children:[(!!s.Qualification?.QualificationId&&s.Qualification?.QualificationId!=="Suspended"||!!s.OpenToWork||!!s.OnHold&&s.OnHold!==0||b.length>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(Jn,{qualification:s.Qualification??{}}),!!s.OpenToWork&&e.jsxs(fe,{variant:"success",children:[e.jsx(g.HardHat,{className:"h-3 w-3 mr-1"}),"Open To Work"]}),!!s.OnHold&&s.OnHold!==0&&e.jsx(fe,{variant:"warning",children:"On Hold"}),b.map((S,M)=>e.jsx(fe,{variant:"outline",children:S},M))]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[s.Phone&&e.jsxs(ve.Link,{to:`tel:${s.Phone}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Phone,{className:"h-4 w-4"}),e.jsx("span",{children:s.Phone})]}),s.PublicEmail&&e.jsxs(ve.Link,{to:`mailto:${s.PublicEmail}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Mail,{className:"h-4 w-4"}),e.jsx("span",{children:s.PublicEmail})]}),s.Website&&e.jsxs(ve.Link,{to:s.Website,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Globe,{className:"h-4 w-4"}),e.jsx("span",{children:s.Website})]}),s.CurrencyCode&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.DollarSign,{className:"h-4 w-4"}),e.jsx("span",{children:s.CurrencyCode})]})]})]}),s.SalesData&&e.jsxs("div",{className:"border-l pl-2 ml-2 flex flex-col text-sm",children:[e.jsx("strong",{className:"",children:"YTD"}),e.jsx("p",{children:s.SalesData.SalesYearToDay?de(s.SalesData.SalesYearToDay):"—"}),e.jsx("strong",{className:"mt-2",children:"3 mo."}),e.jsx("p",{children:s.SalesData.SalesLast3Months?de(s.SalesData.SalesLast3Months):"—"}),e.jsx("strong",{className:"mt-2",children:"30 days"}),e.jsx("p",{children:s.SalesData.SalesLast30Days?de(s.SalesData.SalesLast30Days):"—"})]})]})}),(r||n||s.PublicResourcesLink||w&&l&&s.ManufacturerId||t)&&e.jsxs(ms,{className:"flex pt-2 gap-2 justify-between mt-auto",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r&&r,w&&l&&s.ManufacturerId&&e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{size:"icon",onClick:()=>c(!0),disabled:m,children:m?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.Download,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Email Product List"})})]})}),s.PublicResourcesLink&&e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:s.PublicResourcesLink,target:"_blank",children:e.jsx(D,{size:"icon",children:e.jsx(g.BookOpen,{className:"h-4 w-4"})})})}),e.jsx(pe,{children:e.jsx("p",{children:"Public Resources Link"})})]})})]}),n&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{children:n})})]}),e.jsx(De,{open:h,onOpenChange:c,children:e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Request Universal Product List"}),e.jsx(_e,{children:"Enter the email address where you would like to receive the report."})]}),e.jsxs("div",{className:"py-4",children:[e.jsx(J,{htmlFor:"email",children:"Email"}),e.jsx(le,{id:"email",value:y,onChange:S=>p(S.target.value),placeholder:"your@email.com",className:"mt-2"})]}),e.jsx(_e,{children:"The report will take around 5 minutes to generate."}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>c(!1),children:"Cancel"}),e.jsx(D,{onClick:k,disabled:!y||m,children:m?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function Zn({appID:s,reseller:t,readonly:a,userEmail:r,isSuperAdmin:n,withoutReports:i=!1,loadFullAfterSummary:l=!1}){const d=`${s}|${l?1:0}`,u=o.useRef(d),[m,h]=o.useState(()=>l?!!t:!1);o.useEffect(()=>{u.current!==d&&(u.current=d,h(!1))},[d]),o.useEffect(()=>{l&&t&&h(!0)},[l,t]);const c=l?m:!t,{data:y,isLoading:p,isError:x}=_.useGetV4PartnerByApplicationIdAccountResellerQuery({applicationId:s??"",withSpecification:!0},{skip:!s||!c}),[w,N]=o.useState({publicInfo:{hasUnsavedChanges:!1}}),j=o.useCallback(()=>a?!1:w.publicInfo.hasUnsavedChanges,[a,w]),b=o.useCallback((B,F)=>{N(U=>U[B]?.hasUnsavedChanges!==F.hasUnsavedChanges?{...U,[B]:F}:U)},[]),{NavigationGuardDialog:k}=Hn(j),S=y??t,M=p&&!S,A=x&&!S,P=!a||!!S?.Statement&&(S.Statement.Total??0)!==0,E=S?.QualifiedManufacturers??[],T=S?.Qualifications??[],I=[...S?.Opportunities??[]].sort((B,F)=>new Date(F.LastUpdate??0).getTime()-new Date(B.LastUpdate??0).getTime());return e.jsxs("div",{className:"@container",children:[A?e.jsx(z,{className:"p-6",children:e.jsxs(js,{variant:"destructive",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(bs,{children:"Error"}),e.jsx(ys,{children:"There was an error loading your reseller information. Please try again later."})]})}):e.jsxs("div",{className:"space-y-6 mb-6",children:[e.jsx(Gn,{fiscalYearMonthStart:S?.FiscalYearMonthStart||1,salesData:S?.SalesData,isLoading:M}),e.jsxs("div",{className:"grid @lg:grid-cols-2 gap-6",children:[e.jsx(Xa,{statistics:S?.SalesStatistics??[],loading:M}),e.jsx(yc,{openOrders:S?.ActiveOrderDetails??[],isLoading:M}),P&&e.jsx(hc,{appID:s,reseller:S||{},withoutReports:i,isLoading:M,userEmail:r,isSuperAdmin:n}),e.jsx(xc,{reseller:S||{},appID:s??"",isLoading:M,readonly:a,onUnsavedChanges:B=>b("publicInfo",{hasUnsavedChanges:B})}),e.jsx(bc,{isSuperAdmin:n,readonly:a,reseller:S||{},appID:s??"",isLoading:M}),M||E.length>0?e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{children:"Manufacturers you are qualified for"})}),e.jsx(G,{children:e.jsx("div",{className:"grid @lg:grid-cols-2 gap-4",children:M?Array.from({length:2}).map((B,F)=>e.jsx(Zs,{loading:!0},F)):E.map(B=>e.jsx(Zs,{manufacturer:B,link:`https://dashboard.randmar.io/${s}/Partner/${B.ManufacturerId}`},B.ManufacturerId))})})]}):T.length>0&&e.jsx(ji,{qualifications:T})]}),I.length>0&&e.jsx(mr,{applicationId:s,opportunities:I,loading:M}),!i&&e.jsx(Nc,{appID:s,userEmail:r,isLoading:!1})]}),e.jsx(k,{})]})}const vc=et.cva("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 bg-destructive/10 text-foreground [&>svg]:text-destructive",success:"border-success/50 bg-success/10 text-foreground [&>svg]:text-success",warning:"border-warning/50 bg-warning/10 text-foreground [&>svg]:text-warning",info:"border-info/50 bg-info/10 text-foreground [&>svg]:text-info"}},defaultVariants:{variant:"default"}}),js=R.forwardRef(({className:s,variant:t,...a},r)=>e.jsx("div",{ref:r,role:"alert",className:v(vc({variant:t}),s),...a}));js.displayName="Alert";const bs=R.forwardRef(({className:s,...t},a)=>e.jsx("h5",{ref:a,className:v("mb-1 font-medium leading-none tracking-tight",s),...t}));bs.displayName="AlertTitle";const ys=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("text-sm [&_p]:leading-relaxed",s),...t}));ys.displayName="AlertDescription";function As({columns:s,data:t,uniqueValues:a,tableClass:r,loading:n,initialSort:i}){const[l,d]=o.useState(i??[]),[u,m]=o.useState([]),[h,c]=o.useState({pageIndex:0,pageSize:10}),[y,p]=o.useState(null),x=Cs.useReactTable({data:n?[]:t,columns:s,getCoreRowModel:Cs.getCoreRowModel(),onSortingChange:d,getSortedRowModel:Cs.getSortedRowModel(),onColumnFiltersChange:m,getFilteredRowModel:Cs.getFilteredRowModel(),getPaginationRowModel:Cs.getPaginationRowModel(),onPaginationChange:c,state:{sorting:l,columnFilters:u,pagination:h},manualPagination:n,manualSorting:n,manualFiltering:n}),w=(N,j)=>{N.toggleSorting(j),p(null)};return n?e.jsxs("div",{className:"@container space-y-4",children:[e.jsx("div",{className:`rounded-md border ${r??""}`,children:e.jsxs(Lt,{children:[e.jsx(Ft,{children:e.jsx(Es,{children:s.map((N,j)=>e.jsx($t,{children:e.jsx(f,{className:"h-6 w-full"})},`skeleton-header-${j}`))})}),e.jsx(Bt,{children:Array.from({length:h.pageSize}).map((N,j)=>e.jsx(Es,{children:s.map((b,k)=>e.jsx(gt,{children:e.jsx(f,{className:"h-6 w-full"})},`skeleton-cell-${j}-${k}`))},`skeleton-row-${j}`))})]})}),e.jsxs("div",{className:"flex flex-col items-center gap-4 @[35rem]:flex-row @[35rem]:justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{className:"h-8 w-[110px]"}),e.jsx(f,{className:"h-8 w-[70px]"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{className:"hidden h-8 w-8 lg:flex"}),e.jsx(f,{className:"h-8 w-8"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(f,{className:"h-6 w-12"}),e.jsx(f,{className:"h-6 w-8"}),e.jsx(f,{className:"h-6 w-8"})]}),e.jsx(f,{className:"h-8 w-8"}),e.jsx(f,{className:"hidden h-8 w-8 lg:flex"})]})]})]}):e.jsxs("div",{className:"@container space-y-4",children:[e.jsxs(hs,{className:`rounded-md border ${r??""}`,children:[e.jsxs(Lt,{children:[e.jsx(Ft,{children:x.getHeaderGroups().map(N=>e.jsx(Es,{children:N.headers.map(j=>e.jsx($t,{children:j.isPlaceholder?null:j.column.getCanSort()||j.column.getCanFilter()?e.jsxs(wt,{open:y===j.id,onOpenChange:b=>p(b?j.id:null),children:[e.jsx(St,{asChild:!0,children:e.jsxs(D,{variant:"ghost",className:"pl-0",children:[Cs.flexRender(j.column.columnDef.header,j.getContext()),j.column.getIsFiltered()?e.jsx(g.Filter,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="asc"?e.jsx(g.ArrowUp,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="desc"?e.jsx(g.ArrowDown,{className:"ml-2 h-4 w-4"}):e.jsx(g.ArrowUpDown,{className:"ml-2 h-4 w-4"})]})}),e.jsx(it,{className:"w-56",children:e.jsxs("div",{className:"space-y-2",children:[j.column.getCanSort()&&e.jsxs(e.Fragment,{children:[e.jsxs(D,{variant:"ghost",className:"w-full justify-start",onClick:()=>w(j.column,!1),children:[e.jsx(g.ArrowUp,{className:"mr-2 h-4 w-4"}),"Sort Ascending"]}),e.jsxs(D,{variant:"ghost",className:"w-full justify-start",onClick:()=>w(j.column,!0),children:[e.jsx(g.ArrowDown,{className:"mr-2 h-4 w-4"}),"Sort Descending"]})]}),j.column.getCanFilter()&&e.jsx("div",{className:"px-2 py-1",children:a[j.column.id]?e.jsxs(ks,{onValueChange:b=>j.column.setFilterValue(b==="all"?void 0:[b]),children:[e.jsx(ps,{children:e.jsx(Rs,{placeholder:`Filter ${j.column.columnDef.header}...`})}),e.jsxs(gs,{children:[e.jsx(Xe,{value:"all",children:"All"}),a[j.column.id]?.map(b=>e.jsx(Xe,{value:b||"empty",children:b||"(Empty)"},b))]})]}):e.jsx(le,{placeholder:`Filter ${j.column.columnDef.header}...`,value:j.column.getFilterValue()??"",onChange:b=>j.column.setFilterValue(b.target.value),className:"w-full"})})]})})]}):e.jsx("div",{className:"py-2 px-4",children:Cs.flexRender(j.column.columnDef.header,j.getContext())})},j.id))},N.id))}),e.jsx(Bt,{children:x.getRowModel().rows?.length?x.getRowModel().rows.map(N=>e.jsx(Es,{"data-state":N.getIsSelected()&&"selected",children:N.getVisibleCells().map(j=>e.jsx(gt,{children:Cs.flexRender(j.column.columnDef.cell,j.getContext())},j.id))},N.id)):e.jsx(Es,{children:e.jsx(gt,{colSpan:s.length,className:"h-24 text-center",children:"No results."})})})]}),e.jsx(Ut,{orientation:"horizontal"})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 @[35rem]:flex-row @[35rem]:justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Rows per page"}),e.jsxs(ks,{value:`${x.getState().pagination.pageSize}`,onValueChange:N=>{x.setPageSize(Number(N))},children:[e.jsx(ps,{className:"h-8 w-[70px]",children:e.jsx(Rs,{asChild:!0,children:e.jsx("span",{children:x.getState().pagination.pageSize})})}),e.jsx(gs,{side:"top",children:[10,20,30,40,50].map(N=>e.jsx(Xe,{value:`${N}`,children:e.jsx("span",{children:N})},N))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(D,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>x.setPageIndex(0),disabled:!x.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to first page"}),e.jsx(g.ChevronsLeft,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>x.previousPage(),disabled:!x.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to previous page"}),e.jsx(g.ChevronLeft,{className:"h-4 w-4"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"Page"}),e.jsx("span",{className:"text-sm font-medium",children:x.getState().pagination.pageIndex+1}),e.jsx("p",{className:"text-sm font-medium",children:"of"}),e.jsx("span",{className:"text-sm font-medium",children:x.getPageCount()})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>x.nextPage(),disabled:!x.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to next page"}),e.jsx(g.ChevronRight,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>x.setPageIndex(x.getPageCount()-1),disabled:!x.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to last page"}),e.jsx(g.ChevronsRight,{className:"h-4 w-4"})]})]})]})]})}function Xn({account:s,action:t,loading:a=!1,className:r,withAbout:n=!1}){return a||!s?e.jsxs(z,{className:`flex flex-col h-full ${r}`,children:[e.jsx(Y,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"h-12 w-12 rounded-md"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-3 w-16"}),e.jsx(f,{className:"h-3 w-16"})]}),e.jsx(f,{className:"h-5 w-48 mt-1"})]})]})}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(f,{className:"h-5 w-24 rounded-full"}),e.jsx(f,{className:"h-5 w-20 rounded-full"}),e.jsx(f,{className:"h-5 w-16 rounded-full"})]}),n&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(f,{className:"h-5 w-full"}),e.jsx(f,{className:"h-5 w-full"}),e.jsx(f,{className:"h-5 w-full"})]})]})}),e.jsxs(ms,{className:"px-6 py-4 flex justify-between gap-2 mt-auto",children:[e.jsx(f,{className:"h-9 w-32"}),e.jsx(f,{className:"h-9 w-48"})]})]}):e.jsxs(z,{className:`flex flex-col h-full ${r}`,children:[e.jsx(tr,{type:"Partner",applicationId:s.ApplicationId,publicName:s.PublicName}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[(s.IsManufacturer||s.IsReseller||s.IsSalesAgency||s.HasShopifyStore||s.IsVendor)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.IsManufacturer&&e.jsx(fe,{variant:"info",children:"Manufacturer"}),s.IsReseller&&e.jsx(fe,{variant:"success",children:"Reseller"}),s.IsSalesAgency&&e.jsx(fe,{variant:"outline",children:"Agency"}),s.HasShopifyStore&&e.jsx(fe,{variant:"secondary",children:"Shopify"}),s.IsVendor&&e.jsx(fe,{variant:"outline",children:"Vendor"})]}),n&&s.About&&e.jsx("div",{className:"prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:s.About??""}})]})}),e.jsx(ms,{className:"px-6 py-4 flex justify-end gap-2 mt-auto",children:t||e.jsxs(D,{className:"flex items-center gap-2",children:[e.jsx(g.ExternalLink,{className:"h-4 w-4"}),"Go to Partner Dashboard"]})})]})}function ei({reseller:s,link:t,linkNewTab:a=!0,actions:r,mainAction:n,loading:i=!1}){if(i||!s)return e.jsxs(z,{className:"flex flex-col h-full",children:[e.jsx(Y,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"h-12 w-12 rounded-md"}),e.jsxs("div",{children:[e.jsx(f,{className:"h-3 w-24 mb-2"}),e.jsx(f,{className:"h-5 w-40 mb-1"}),e.jsx(f,{className:"h-4 w-32 mb-1"}),e.jsx(f,{className:"h-4 w-48"})]})]})}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsx("div",{className:"flex",children:e.jsxs("div",{className:"flex flex-col flex-1 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(f,{className:"h-5 w-16 rounded-full"}),e.jsx(f,{className:"h-5 w-20 rounded-full"}),e.jsx(f,{className:"h-5 w-14 rounded-full"})]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-32"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-40"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-36"})]})]})]})})}),e.jsxs(ms,{className:"flex justify-between pt-2 gap-2 mt-auto",children:[e.jsx(f,{className:"h-9 w-24"}),e.jsx(f,{className:"h-9 w-40"})]})]});const l=[s.City,s.Province,s.Country].filter(Boolean),d=l.length>0?l.join(", "):"Location not provided",u=s.Priority?.trim(),m=!!s.Qualification?.QualificationId&&s.Qualification?.QualificationId!=="Suspended",h=!!s.OnHold&&s.OnHold!==0,c=!!u,y=p=>{const x=p.toLowerCase();return x.includes("starter")||x.includes("basic")?"secondary":x.includes("exclusive")||x.includes("jean coutu")||x.includes("novexco")||x.includes("coopsco")?"success":"info"};return e.jsxs(z,{className:"flex flex-col h-full",children:[e.jsx(tr,{type:"Reseller",applicationId:s.ResellerId,publicName:s.PublicName,name:s.Name,location:d,link:t,linkNewTab:a,children:e.jsx("div",{className:"flex flex-col items-end gap-2",children:s.SalesStatistics&&s.SalesStatistics.length>0&&e.jsx("div",{className:"h-16 w-24",children:e.jsx(Vs,{statistics:s.SalesStatistics,size:"mini"})})})}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex",children:[e.jsxs("div",{className:"flex flex-col flex-1 space-y-2",children:[(m||h||c)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[m&&e.jsx(Jn,{qualification:s.Qualification??{}}),h&&e.jsx(fe,{variant:"warning",children:"On Hold"}),c&&e.jsx(fe,{variant:y(u),children:u})]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[s.Phone&&e.jsxs(ve.Link,{to:`tel:${s.Phone}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Phone,{className:"h-4 w-4"}),e.jsx("span",{children:s.Phone})]}),s.PublicEmail&&e.jsxs(ve.Link,{to:`mailto:${s.PublicEmail}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Mail,{className:"h-4 w-4"}),e.jsx("span",{children:s.PublicEmail})]}),s.Website&&e.jsxs(ve.Link,{to:s.Website,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Globe,{className:"h-4 w-4"}),e.jsx("span",{children:s.Website})]}),s.CurrencyCode&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.DollarSign,{className:"h-4 w-4"}),e.jsx("span",{children:s.CurrencyCode})]})]})]}),s?.SalesData&&e.jsxs("div",{className:"border-l pl-2 ml-2 flex flex-col text-sm",children:[e.jsx("strong",{className:"",children:"YTD"}),e.jsx("p",{children:s?.SalesData.SalesYearToDay?de(s?.SalesData.SalesYearToDay):"—"}),e.jsx("strong",{className:"mt-2",children:"3 mo."}),e.jsx("p",{children:s?.SalesData.SalesLast3Months?de(s?.SalesData.SalesLast3Months):"—"}),e.jsx("strong",{className:"mt-2",children:"30 days"}),e.jsx("p",{children:s?.SalesData.SalesLast30Days?de(s?.SalesData.SalesLast30Days):"—"})]})]})}),(r||n)&&e.jsxs(ms,{className:"flex pt-2 gap-2 justify-between mt-auto",children:[e.jsx("div",{className:"flex items-center gap-2",children:r&&r}),n&&e.jsx("div",{children:n})]})]})}const Lt=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:a,className:v("w-full caption-bottom text-sm",s),...t})}));Lt.displayName="Table";const Ft=R.forwardRef(({className:s,...t},a)=>e.jsx("thead",{ref:a,className:v("[&_tr]:border-b",s),...t}));Ft.displayName="TableHeader";const Bt=R.forwardRef(({className:s,...t},a)=>e.jsx("tbody",{ref:a,className:v("[&_tr:last-child]:border-0",s),...t}));Bt.displayName="TableBody";const si=R.forwardRef(({className:s,...t},a)=>e.jsx("tfoot",{ref:a,className:v("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...t}));si.displayName="TableFooter";const Es=R.forwardRef(({className:s,...t},a)=>e.jsx("tr",{ref:a,className:v("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...t}));Es.displayName="TableRow";const $t=R.forwardRef(({className:s,...t},a)=>e.jsx("th",{ref:a,className:v("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t,children:R.isValidElement(t.children)&&t.children.type==="span"?t.children:e.jsx("span",{children:t.children})}));$t.displayName="TableHead";const gt=R.forwardRef(({className:s,...t},a)=>e.jsx("td",{ref:a,className:v("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t,children:R.isValidElement(t.children)&&t.children.type==="span"?t.children:e.jsx("span",{children:t.children})}));gt.displayName="TableCell";const ti=R.forwardRef(({className:s,...t},a)=>e.jsx("caption",{ref:a,className:v("mt-4 text-sm text-muted-foreground",s),...t}));ti.displayName="TableCaption";const ai="[--rm-shell-header-height:3.5rem]",wc="h-[var(--rm-shell-header-height)]",Sc="pt-[var(--rm-shell-header-height)]",ar=o.forwardRef(({onSignOut:s,handleValidSearch:t,rightMenu:a,searchPlaceholder:r},n)=>{const[i,l]=o.useState(""),d=ve.useLocation(),{toast:u}=Ce();o.useEffect(()=>{const y=new URLSearchParams(d.search).get("q");y&&l(y)},[d.search]);const m=()=>{const c=i.trim();if(!c||c.length<2){u({title:"Enter more characters to search",description:"At least 2 characters are needed to search products.",variant:"destructive",duration:5e3});return}t(c)},h=c=>{c.key==="Enter"&&m()};return e.jsxs("header",{className:`fixed top-0 right-0 left-0 z-50 flex ${ai} ${wc} items-center gap-3 border-b border-primary/20 bg-primary px-4 text-primary-foreground transition-[left] duration-200 ease-linear lg:px-6 peer-data-[state=expanded]:lg:left-(--sidebar-width) peer-data-[collapsible=offcanvas]:lg:left-0 peer-data-[collapsible=icon]:lg:left-(--sidebar-width-icon)`,children:[e.jsx(Ba,{className:"h-10 w-10 text-primary-foreground hover:bg-primary-foreground/15 hover:text-primary-foreground focus-visible:ring-primary-foreground focus-visible:ring-offset-primary lg:hidden",children:e.jsx(g.Menu,{className:"h-5 w-5"})}),e.jsx("div",{className:"flex flex-1 items-center gap-4",children:e.jsx("div",{className:"relative w-full max-w-sm",children:e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"absolute left-1 top-1/2 inline-flex h-8 w-8 -translate-y-1/2 items-center justify-center rounded-md text-primary-foreground/90 transition-colors hover:bg-primary-foreground/15 hover:text-primary-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-foreground focus-visible:ring-offset-2 focus-visible:ring-offset-primary",onClick:m,"aria-label":"Search",children:e.jsx(g.Search,{className:"h-4 w-4"})}),e.jsx(le,{placeholder:r??"Search...","aria-label":r??"Search",className:"h-10 w-full border-primary-foreground/35 bg-primary-foreground/12 pl-10 text-primary-foreground placeholder:text-primary-foreground/70 focus-visible:ring-primary-foreground focus-visible:ring-offset-primary",value:i,onChange:c=>l(c.target.value),onKeyDown:h,ref:n},"topbar-search")]})})}),e.jsxs("div",{className:"flex items-center gap-3 text-primary-foreground [&_svg]:text-primary-foreground",children:[a,s&&e.jsx("div",{className:"flex items-center",children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-10 w-10 text-primary-foreground hover:bg-primary-foreground/15 hover:text-primary-foreground focus-visible:ring-primary-foreground focus-visible:ring-offset-primary",onClick:s,children:[e.jsx(g.LogOut,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Sign out"})]})})]})]})});ar.displayName="Topbar";function ri({orders:s,loading:t=!1}){const a=o.useMemo(()=>{if(!s||s.length===0)return{all:{orders:0,amount:0},processing:{orders:0,amount:0},shipped:{orders:0,amount:0},delayed:{orders:0,amount:0}};const n=s.filter(N=>N.DocumentType==="Order"),i=s.filter(N=>N.DocumentType==="Shipment"),l=n.filter(N=>N.WarehouseCode!=="3PLE"),d=l.reduce((N,j)=>N+(j.Quantity||0),0),u=l.reduce((N,j)=>N+(j.ExtendedPrice||0),0),m=n.filter(N=>N.WarehouseCode==="3PLE"),h=m.reduce((N,j)=>N+(j.Quantity||0),0),c=m.reduce((N,j)=>N+(j.ExtendedPrice||0),0),y=i.length,p=i.reduce((N,j)=>N+(j.ExtendedPrice||0),0),x=d+h+y,w=u+c+p;return{all:{orders:x,amount:w},processing:{orders:d,amount:u},shipped:{orders:y,amount:p},delayed:{orders:h,amount:c}}},[s]),r=[{name:"All",icon:g.Package,stripeClass:"bg-info/60",iconBgClass:"bg-info/90",iconTextClass:"text-info-foreground",orders:a.all.orders,amount:a.all.amount},{name:"Processing",icon:g.RefreshCcw,stripeClass:"bg-warning/60",iconBgClass:"bg-warning/90",iconTextClass:"text-warning-foreground",orders:a.processing.orders,amount:a.processing.amount},{name:"Shipped",icon:g.Truck,stripeClass:"bg-success/60",iconBgClass:"bg-success/90",iconTextClass:"text-success-foreground",orders:a.shipped.orders,amount:a.shipped.amount},{name:"Delayed",icon:g.AlertCircle,stripeClass:"bg-destructive/60",iconBgClass:"bg-destructive/90",iconTextClass:"text-destructive-foreground",orders:a.delayed.orders,amount:a.delayed.amount}];return t?e.jsxs(z,{className:"@container",children:[e.jsx(Y,{className:"pb-0",children:e.jsx(me,{className:"text-base font-medium text-foreground",children:"Active Orders"})}),e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-4 p-4",children:[1,2,3,4].map(n=>e.jsxs("div",{className:"overflow-hidden rounded-md border",children:[e.jsx("div",{className:"bg-border h-[3px]"}),e.jsxs("div",{className:"p-6 border border-t-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx(f,{className:"h-5 w-24"}),e.jsx(f,{className:"h-8 w-8 rounded-full"})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx(f,{className:"h-3 w-16 mb-2"}),e.jsx(f,{className:"h-7 w-12"})]}),e.jsxs("div",{className:"text-end",children:[e.jsx(f,{className:"h-3 w-16 mb-2"}),e.jsx(f,{className:"h-5 w-20"})]})]})]})]},n))})]}):e.jsxs(z,{className:"@container",children:[e.jsx(Y,{className:"pb-0",children:e.jsx(me,{className:"text-base font-medium text-foreground",children:"Active Orders"})}),e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-4 p-4",children:r.map(n=>e.jsxs("div",{className:"overflow-hidden rounded-md border",children:[e.jsx("div",{className:`${n.stripeClass} h-[3px]`}),e.jsxs("div",{className:"p-6 border border-t-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:"font-semibold text-base",children:n.name}),e.jsx("div",{className:`${n.iconBgClass} p-2 rounded-full`,children:e.jsx(n.icon,{className:`size-4 shrink-0 ${n.iconTextClass}`})})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Orders"}),e.jsx("p",{className:"text-xl font-bold",children:n.orders})]}),e.jsxs("div",{className:"text-end",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),e.jsx("p",{className:"text-base font-semibold",children:de(n.amount)})]})]})]})]},n.name))})]})}const Ps=R.forwardRef(({className:s,...t},a)=>e.jsx(wa.Root,{ref:a,className:v("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...t,children:e.jsx(wa.Indicator,{className:v("flex items-center justify-center text-current"),children:e.jsx(g.Check,{className:"h-4 w-4"})})}));Ps.displayName=wa.Root.displayName;function ni({items:s,selectedIds:t,onSelectedIdsChange:a,disabled:r=!1,loading:n=!1,selectionMode:i="multiple",layout:l="stack",gridColumns:d=2,emptyState:u,loadingState:m,getItemAriaLabel:h,renderItem:c,className:y,...p}){const x=R.useId(),w=R.useMemo(()=>new Set(t),[t]),N=l==="grid"?v("grid gap-3",d===2&&"grid-cols-1 sm:grid-cols-2"):"space-y-3",j=R.useCallback(b=>{if(r||n||b.disabled)return;const k=w.has(b.id);if(i==="single"){a(k?[]:[b.id]);return}if(k){a(t.filter(S=>S!==b.id));return}a([...t,b.id])},[r,n,a,w,t,i]);return n?e.jsx("div",{className:v(N,y),role:"status","aria-live":"polite",...p,children:m??e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:"Loading options"}),Array.from({length:l==="grid"?4:3}).map((b,k)=>e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 shadow-sm","aria-hidden":"true",children:[e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-muted"}),e.jsx("div",{className:"mt-2 h-3 w-1/2 animate-pulse rounded bg-muted"})]},`loading-${k}`))]})}):s.length===0?e.jsx("div",{className:v(N,y),...p,children:u??e.jsx("div",{className:"rounded-xl border border-dashed border-border bg-muted/30 p-4 text-sm text-muted-foreground",children:"No options are available."})}):e.jsx("div",{className:v(N,y),role:"group","aria-disabled":r||void 0,...p,children:s.map((b,k)=>{const S=w.has(b.id),M=r||b.disabled===!0,A=`${x}-${k}-label`,P=`${x}-${k}-description`;return e.jsxs("button",{type:"button",role:"checkbox","aria-checked":S,"aria-disabled":M,"aria-label":h?.(b)??b.label,"aria-labelledby":c?void 0:A,"aria-describedby":!c&&b.description?P:void 0,disabled:M,onClick:()=>j(b),className:v("flex w-full items-start gap-3 rounded-xl border bg-card p-4 text-left shadow-sm transition-colors transition-shadow","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","hover:bg-muted/30 hover:shadow",S?"border-primary bg-primary/5 ring-2 ring-primary/20":"border-border",M&&"cursor-not-allowed opacity-60 hover:bg-card hover:shadow-sm"),children:[e.jsx("span",{"aria-hidden":"true",className:v("mt-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm border border-primary shadow-sm",S?"bg-primary text-primary-foreground":"bg-background text-transparent"),children:e.jsx(g.Check,{className:"h-3.5 w-3.5"})}),e.jsx("div",{className:"min-w-0 flex-1",children:c?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:b.label}),c(b,{checked:S,disabled:M,index:k})]}):e.jsxs(e.Fragment,{children:[(b.prefix||b.emphasis)&&e.jsxs("div",{className:"flex flex-wrap items-baseline gap-1 text-xs",children:[b.prefix&&e.jsx("span",{className:"font-semibold uppercase tracking-wide text-muted-foreground",children:b.prefix}),b.emphasis&&e.jsx("span",{className:"font-semibold text-foreground",children:b.emphasis})]}),e.jsx("span",{id:A,className:v("block text-sm font-medium text-foreground",(b.prefix||b.emphasis)&&"mt-1"),children:b.label}),b.description&&e.jsx("span",{id:P,className:"mt-1 block text-sm text-muted-foreground",children:b.description})]})})]},b.id)})})}const Qt=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command,{ref:a,className:v("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...t}));Qt.displayName=es.Command.displayName;const Cc=({children:s,...t})=>e.jsx(De,{...t,children:e.jsx(Me,{className:"overflow-hidden p-0",children:e.jsx(Qt,{className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:s})})}),rr=R.forwardRef(({className:s,...t},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(g.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(es.Command.Input,{ref:a,className:v("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",s),...t})]}));rr.displayName=es.Command.Input.displayName;const nr=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command.List,{ref:a,className:v("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...t}));nr.displayName=es.Command.List.displayName;const ir=R.forwardRef((s,t)=>e.jsx(es.Command.Empty,{ref:t,className:"py-6 text-center text-sm",...s}));ir.displayName=es.Command.Empty.displayName;const lr=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command.Group,{ref:a,className:v("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",s),...t}));lr.displayName=es.Command.Group.displayName;const ii=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command.Separator,{ref:a,className:v("-mx-1 h-px bg-border",s),...t}));ii.displayName=es.Command.Separator.displayName;const _t=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command.Item,{ref:a,className:v("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",s),...t}));_t.displayName=es.Command.Item.displayName;const li=({className:s,...t})=>e.jsx("span",{className:v("ml-auto text-xs tracking-widest text-muted-foreground",s),...t});li.displayName="CommandShortcut";const oi=({countryCode:s,className:t=""})=>{const[a,r]=o.useState(!1),n=s.trim().toUpperCase();o.useEffect(()=>{r(!1)},[n]);const i=o.useMemo(()=>n?`https://purecatamphetamine.github.io/country-flag-icons/3x2/${encodeURIComponent(n)}.svg`:"",[n]);return!n||a?e.jsx("span",{className:t,children:s}):e.jsx("img",{src:i,alt:`${n} flag`,className:`inline-block h-auto w-6 ${t}`,loading:"lazy",onError:()=>r(!0)})};function kc({document:s,loading:t=!1}){return t?e.jsx("div",{children:"loading..."}):e.jsxs("div",{children:["GENERAL DOCUMENT CARD - ",s?.OrderNumber," for P.O. ",s?.PONumber]})}function ci({path:s,origin:t,...a}){const r=vt(),n=R.useMemo(()=>$s(s,t??r),[r,t,s]);return e.jsx("img",{...a,src:n})}const Rc="https://randmar-mcp-c5gebmhzenfpbdau.canadacentral-01.azurewebsites.net/mcp",Pc="2025-06-18",Ac=new Set(["search_api_endpoints","get_endpoint_details","execute_api_endpoint"]);function Ic(s,t){if(!t.includes("text/event-stream"))return JSON.parse(s);const a=s.split(/\r?\n/).filter(r=>r.startsWith("data:")).map(r=>r.slice(5).trim()).filter(Boolean);if(a.length===0)throw new Error("The MCP gateway returned an empty event stream.");return JSON.parse(a.join(`
49
- `))}function di(s){const t=JSON.parse(s.ArgumentsJson??"{}");if(typeof t!="object"||t===null||Array.isArray(t))throw new Error("Tool arguments must be a JSON object.");return t}function Dc(s){let t={};try{t=di(s)}catch{}return s.Name==="search_api_endpoints"?"Searching API endpoints":typeof t.operationId=="string"&&t.operationId.trim()?t.operationId:s.Name==="get_endpoint_details"?"Inspecting API endpoint":"Executing API endpoint"}async function Mc(s,t,a){const r=s.Name??"",n=s.ToolCallId??"",i=Dc(s);if(!r||!n)throw new Error("The assistant returned an incomplete MCP tool call.");if(!Ac.has(r)){const c=`Unknown MCP tool: ${r}.`;return{title:i,output:c,functionResponse:{ToolCallId:n,Name:r,Content:c}}}let l;try{l=di(s)}catch(c){const y=`Invalid JSON arguments for ${r}: ${c instanceof Error?c.message:"Unable to parse arguments."}`;return{title:i,output:y,functionResponse:{ToolCallId:n,Name:r,Content:y}}}const d=await fetch(Rc,{method:"POST",signal:a,headers:{Accept:"application/json, text/event-stream","Content-Type":"application/json","MCP-Protocol-Version":Pc,...t?{Authorization:`Bearer ${t}`}:{}},body:JSON.stringify({jsonrpc:"2.0",id:n,method:"tools/call",params:{name:r,arguments:l}})}),u=await d.text();if(!d.ok)throw new Error(`MCP HTTP ${String(d.status)}: ${u.trim()||"Request failed."}`);const m=Ic(u,d.headers.get("content-type")?.toLowerCase()??"");if(m.error){const c=m.error.data===void 0?"":` ${JSON.stringify(m.error.data)}`;throw new Error(`MCP ${String(m.error.code??"error")}: ${m.error.message??"Tool call failed."}${c}`)}const h=(m.result?.content??[]).filter(c=>c.type==="text"&&typeof c.text=="string").map(c=>c.text??"").join(`
48
+ $10 with opportunities under $1,000`:s==="D"?"$15 under $1,500":s==="E"?"Full shipping charges":s,jc=s=>s==="STRIPE"?"Credit card payment":s==="NET30"?"Net 30 days":s,bc=({isSuperAdmin:s,readonly:t,reseller:a,appID:r,isLoading:n})=>{const{toast:i}=Ce(),[l,d]=o.useState(!1),[u,m]=o.useState(""),[h,{isLoading:c}]=_.usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),y=O=>O&&{Starter:"starter","E-Commerce":"ecommerce",Commercial:"commercial",Basics:"cws",Novexco:"novexco",COOPSCO:"coopsco","Jean Coutu":"jeancoutu",Exclusive:"exclusive"}[O]||"",p=O=>O&&{A:"free",B:"fixed",C:"dropshipped",D:"under1500",E:"fullcharges"}[O]||"",x=O=>O&&{1:"exclusive",2:"ecommerce",3:"commercial",4:"buyinggroup",5:"cost"}[O]||"",[w,N]=o.useState(y(a?.Priority??"")),[j,b]=o.useState(p(a?.ShippingProfile??"")),[k,S]=o.useState(x(a?.PriceProfile)),M=O=>({starter:"Starter",ecommerce:"E-Commerce",commercial:"Commercial",cws:"Basics",novexco:"Novexco",coopsco:"COOPSCO",jeancoutu:"Jean Coutu",exclusive:"Exclusive"})[O]||O,A=O=>({free:"A",fixed:"B",dropshipped:"C",under1500:"D",fullcharges:"E"})[O]||O,P=O=>({exclusive:"1",ecommerce:"2",commercial:"3",buyinggroup:"4",cost:"5"})[O]||O;o.useEffect(()=>{N(y(a?.Priority??"")),b(p(a?.ShippingProfile??"")),S(x(a?.PriceProfile))},[a]);const E=async(O,q,W,ne)=>{try{(await h({applicationId:r,fieldName:O,newValue:q})).error?i({title:"Error",description:ne,variant:"destructive"}):i({title:"Success",description:W,variant:"success"})}catch{i({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}},T=async O=>{N(O);const q=M(O);E("Priority",q,`Priority updated to ${q}`,"Failed to update priority")},I=async O=>{b(O);const q=A(O);E("ShippingProfile",q,`Shipping profile updated to ${q}`,"Failed to update shipping profile")},B=async O=>{S(O);const q=P(O);E("PriceProfile",q,`Pricing profile updated to ${q}`,"Failed to update pricing profile")},F=async()=>{try{const O=await h({applicationId:r,fieldName:"Tier",newValue:u});O.error?i({title:"Error",description:"Failed to update reseller",variant:"destructive"}):O.data?i({title:"Success",description:`Pricing Tier changed to ${u}`,variant:"success"}):i({title:"Considered",description:"Request being considered",variant:"success"})}catch{i({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}finally{d(!1),m("")}},U=[{name:"Terms",enabled:a.Priority==="Starter"},{name:"E-Commerce",enabled:a.Priority==="Commercial"},{name:"Commercial",enabled:a.Priority==="E-Commerce"},{name:"Exclusive",enabled:s}],V=O=>{m(O),d(!0)};return n?e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{className:"h-6 w-28"}),e.jsx(f,{className:"h-6 w-16 rounded-full"})]})}),e.jsxs(G,{children:[e.jsxs("div",{className:"mb-3",children:[e.jsx(f,{className:"h-8 w-40 mb-1"}),e.jsx(f,{className:"h-4 w-56"})]}),e.jsx("div",{className:"grid gap-3",children:[1,2,3].map(O=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"h-8 w-8 rounded-full shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(f,{className:"h-5 w-20 mb-1"}),e.jsx(f,{className:"h-4 w-full"})]})]},O))}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(f,{className:"h-10 w-full"}),e.jsx(f,{className:"h-10 w-full"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(z,{className:"w-full",children:[e.jsxs(Y,{className:"pb-2 pt-4 px-4 flex flex-row items-center justify-between",children:[e.jsx(me,{className:"text-base font-medium text-foreground",children:"Account Tier"}),e.jsx(fe,{variant:"success",className:"text-xs",children:"Active"})]}),e.jsxs(G,{className:"pt-2 px-4 pb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 bg-primary/5 p-4 rounded-lg",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-bold text-primary",children:[a?.Priority||""," Tier"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optimized for online retail"})]}),e.jsx(g.CheckCircle2,{className:"h-6 w-6 text-success"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[e.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:e.jsx(g.Package2,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"Pricing"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:pc(a.PriceProfile||0)})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[e.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:e.jsx(g.Truck,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"Shipping"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:gc(a.ShippingProfile||"").split(".")[0]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg border bg-card hover:bg-accent/5 transition-colors",children:[e.jsx("div",{className:"bg-primary/10 p-1.5 rounded-full shrink-0",children:e.jsx(g.Calendar,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"Payment terms"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:jc(a?.Terms||"")})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[!t&&e.jsx(D,{variant:"outline",className:"flex-1",asChild:!0,children:e.jsxs(ve.Link,{to:"https://randmar.io/pricing",target:"_blank",children:[e.jsx(g.ExternalLink,{className:"h-4 w-4 mr-1"}),"Pricing Tiers"]})}),e.jsxs(wt,{children:[e.jsx(St,{asChild:!0,children:e.jsxs(D,{disabled:t,className:t?"hidden":"flex-1",children:["Upgrade Tier ",e.jsx(g.ChevronRight,{className:"h-3 w-3 ml-1"})]})}),e.jsx(it,{className:"w-56 p-2",children:e.jsxs("div",{className:"grid gap-1",children:[e.jsx("h4",{className:"font-medium text-xs mb-1",children:"Select a tier"}),U.map(O=>e.jsx(D,{variant:"ghost",size:"sm",className:"w-full justify-start h-8",disabled:!O.enabled,onClick:()=>V(O.name),children:O.name},O.name))]})})]})]})]})]}),e.jsx(fc,{isLoading:c,open:l,setOpen:d,tier:u,onTierChange:F}),s&&!t&&e.jsxs(z,{className:"mt-4",children:[e.jsx(Y,{className:"pb-2 pt-3 px-4",children:e.jsx(me,{className:"text-1xl font-bold",children:"Admin Configuration"})}),e.jsx(G,{className:"pt-2 px-4 pb-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[e.jsx(J,{className:"block mb-1 text-xs font-medium",children:"Priority"}),e.jsx(Hs,{value:w,onValueChange:T,className:"grid grid-cols-2 @sm:grid-cols-3 @md:grid-cols-4 gap-1",children:[{value:"starter",label:"Starter"},{value:"ecommerce",label:"E-Commerce"},{value:"commercial",label:"Commercial"},{value:"cws",label:"CWS (Basics)"},{value:"novexco",label:"Novexco"},{value:"coopsco",label:"COOPSCO"},{value:"jeancoutu",label:"Jean Coutu"},{value:"exclusive",label:"Exclusive"}].map(O=>e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(xs,{value:O.value,id:`priority-${O.value}`,className:"h-6 w-6 scale-50"}),e.jsx(J,{htmlFor:`priority-${O.value}`,className:"cursor-pointer text-xs",children:O.label})]},O.value))})]}),e.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[e.jsx(J,{className:"block mb-1 text-xs font-medium",children:"Shipping Profile"}),e.jsx(Hs,{value:j,onValueChange:I,className:"grid grid-cols-1 @md:grid-cols-2 gap-1",children:[{value:"free",label:"Free (A)"},{value:"fixed",label:"Fixed $10 Shipping (B)"},{value:"dropshipped",label:"$15 for drop shipped (C)"},{value:"under1500",label:"15$ under 1,500 (D)"},{value:"fullcharges",label:"Full shipping charges (E)"}].map(O=>e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(xs,{value:O.value,id:`shipping-${O.value}`,className:"h-6 w-6 scale-50"}),e.jsx(J,{htmlFor:`shipping-${O.value}`,className:"cursor-pointer text-xs",children:O.label})]},O.value))})]}),e.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[e.jsx(J,{className:"block mb-1 text-xs font-medium",children:"Pricing Profile"}),e.jsx(Hs,{value:k,onValueChange:B,className:"grid grid-cols-2 @sm:grid-cols-3 gap-1",children:[{value:"exclusive",label:"Exclusive (1)"},{value:"ecommerce",label:"E-Commerce (2)"},{value:"commercial",label:"Commercial (3)"},{value:"buyinggroup",label:"Buying Group (4)"},{value:"cost",label:"Cost (5)"}].map(O=>e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(xs,{value:O.value,id:`pricing-${O.value}`,className:"h-6 w-6 scale-50 antialiased"}),e.jsx(J,{htmlFor:`pricing-${O.value}`,className:"cursor-pointer text-xs",children:O.label})]},O.value))})]})]})})]})]})};function yc({openOrders:s=[],isLoading:t=!1}){const a=s?.filter(w=>w.DocumentType==="Order")||[],r=s?.filter(w=>w.DocumentType==="Shipment")||[],n=a.filter(w=>w.WarehouseCode!=="3PLE"),i=n.reduce((w,N)=>w+(N.Quantity??0),0),l=n.reduce((w,N)=>w+(N.ExtendedPrice??0),0),d=a.filter(w=>w.WarehouseCode==="3PLE"),u=d.reduce((w,N)=>w+(N.Quantity??0),0),m=d.reduce((w,N)=>w+(N.ExtendedPrice??0),0),h=r.reduce((w,N)=>w+(N.Quantity??0),0),c=r.reduce((w,N)=>w+(N.ExtendedPrice??0),0),y=i+u+h,p=l+m+c,x=[{name:"All",icon:g.Package,stripeClass:"bg-info/60",iconBgClass:"bg-info/90",iconTextClass:"text-info-foreground",orders:y,amount:p},{name:"Processing",icon:g.RefreshCcw,stripeClass:"bg-warning/60",iconBgClass:"bg-warning/90",iconTextClass:"text-warning-foreground",orders:i,amount:l},{name:"Shipped",icon:g.Truck,stripeClass:"bg-success/60",iconBgClass:"bg-success/90",iconTextClass:"text-success-foreground",orders:h,amount:c},{name:"Delayed",icon:g.AlertCircle,stripeClass:"bg-destructive/60",iconBgClass:"bg-destructive/90",iconTextClass:"text-destructive-foreground",orders:u,amount:m}];return t?e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(f,{className:"h-7 w-40"})}),e.jsx(G,{children:e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:[1,2,3,4].map(w=>e.jsx(z,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:e.jsxs(G,{className:"p-0",children:[e.jsx("div",{className:"bg-border h-[3px]"}),e.jsxs("div",{className:"p-6 border border-t-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx(f,{className:"h-5 w-24"}),e.jsx(f,{className:"h-8 w-8 rounded-full"})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx(f,{className:"h-3 w-20 mb-1"}),e.jsx(f,{className:"h-6 w-12"})]}),e.jsxs("div",{className:"text-end",children:[e.jsx(f,{className:"h-3 w-20 mb-1"}),e.jsx(f,{className:"h-5 w-20"})]})]})]})]})},w))})})]}):e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-base font-medium text-foreground",children:"Order Categories"})}),e.jsx(G,{children:e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:x.map(w=>e.jsx(z,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:e.jsxs(G,{className:"p-0",children:[e.jsx("div",{className:`${w.stripeClass} h-[3px]`}),e.jsxs("div",{className:"p-6 border border-t-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:"font-semibold text-base",children:w.name}),e.jsx("div",{className:`${w.iconBgClass} p-2 rounded-full`,children:e.jsx(w.icon,{className:`size-4 shrink-0 ${w.iconTextClass}`})})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Orders"}),e.jsx("p",{className:"text-xl font-bold",children:w.orders})]}),e.jsxs("div",{className:"text-end",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),e.jsx("p",{className:"text-base font-semibold",children:e.jsx(os.FormattedNumber,{value:w.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},w.name))})})]})}function Nc({isLoading:s,userEmail:t,appID:a}){const{toast:r}=Ce(),[n,{isLoading:i}]=_.usePostV4ResellerByRouteResellerIdReportWalmartTrackingFileEmailMutation(),[l,{isLoading:d}]=_.usePostV4ResellerByRouteResellerIdReportAmazonTrackingFileEmailMutation(),[u,{isLoading:m}]=_.usePostV4ResellerByRouteResellerIdReportOpenOrdersEmailMutation(),[h,{isLoading:c}]=_.usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[y,{isLoading:p}]=_.usePostV4ResellerByRouteResellerIdReportInvoicesEmailMutation(),[x,{isLoading:w}]=_.usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),[N,j]=o.useState(null),[b,k]=o.useState(t),[S,M]=o.useState(!1),[A,P]=o.useState("all"),{data:E,isLoading:T}=_.useGetV4PartnerByRouteApplicationIdManufacturersQuery({routeApplicationId:a,withSpecification:!1}),I=[{name:"Products",reports:[{id:"Products",title:"Universal Product List",description:"A comprehensive overview of your product list with detailed specifications and pricing information.",icon:g.Package}]},{name:"Operation Details",reports:[{id:"OpenOrders",title:"Order Details",description:"A detailed report of all your orders and shipments, including status, tracking information, and delivery estimates.",icon:g.ShoppingCart},{id:"Invoices",title:"Invoices and Credits Report",description:"Detailed overview of your invoices and credits within a specific date range. It also contains reports about additional charges, serial numbers, and other relevant information.",icon:g.ScrollText},{id:"Statement",title:"Statement and RMAs Report",description:"A detailed report of all unpaid invoices and active RMAs.",icon:g.Banknote}]},{name:"Tracking Files",reports:[{id:"AmazonTrackingFile",title:"Amazon Tracking File",description:"Track products sold on Amazon marketplace with detailed sales and inventory information.",icon:g.BarChart},{id:"WalmartTrackingFile",title:"Walmart Tracking File",description:"Track products sold on Walmart marketplace with detailed sales and inventory information.",icon:g.BarChart}]}],B=async V=>{j(V),V.id==="Products"&&P("all"),M(!0)},F=async()=>{if(!(!N||!a))try{switch(N.id){case"Products":{const V={routeResellerId:a,emailAddress:b};A&&A!=="all"&&(V.manufacturerId=A),await h(V).unwrap();break}case"AmazonTrackingFile":await l({routeResellerId:a,emailAddress:b}).unwrap();break;case"WalmartTrackingFile":await n({routeResellerId:a,emailAddress:b}).unwrap();break;case"OpenOrders":await u({routeResellerId:a,emailAddress:b}).unwrap();break;case"Invoices":await y({routeResellerId:a,emailAddress:b}).unwrap();break;case"Statement":await x({routeResellerId:a,emailAddress:b}).unwrap();break;default:throw new Error("invalid report id")}r({title:"Report requested",description:`The ${N.title} will be sent to ${b} shortly.`,variant:"success"}),M(!1)}catch(V){console.error("Error requesting report:",V),r({title:"Error",description:"Failed to request report. Please try again.",variant:"destructive"})}},U=m||c||d||i||w||p;return e.jsxs(z,{children:[e.jsxs(Y,{children:[e.jsx(me,{className:"text-1xl font-bold",children:"Reports"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Download essential business reports, from your Product List to your Order Details."})]}),e.jsx(G,{className:"space-y-6",children:s?e.jsx(e.Fragment,{children:[1,2,3].map(V=>e.jsxs("div",{className:"space-y-4",children:[e.jsx(f,{className:"h-6 w-48"}),[1,2].map(O=>e.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg",children:[e.jsx(f,{className:"h-9 w-9 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(f,{className:"h-5 w-40 mb-2"}),e.jsx(f,{className:"h-4 w-full"})]}),e.jsx(f,{className:"h-9 w-24"})]},O))]},V))}):e.jsx(e.Fragment,{children:I.map(V=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:V.name}),V.reports.map(O=>e.jsxs("div",{className:"flex items-start gap-4 p-4 border rounded-lg hover:bg-muted transition-colors",children:[e.jsx("div",{className:"bg-primary/10 p-2 rounded-full",children:e.jsx(O.icon,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-sm",children:O.title}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:O.description})]}),e.jsxs(D,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>B(O),children:[e.jsx(g.Download,{className:"h-4 w-4"}),"Request"]})]},O.id))]},V.name))})}),e.jsx(De,{open:S,onOpenChange:M,children:e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsxs($e,{children:["Request ",N?.title]}),e.jsx(_e,{children:"Enter the email address where you would like to receive the report."})]}),e.jsxs("div",{className:"py-4",children:[e.jsx(J,{htmlFor:"email",children:"Email"}),e.jsx(le,{id:"email",value:b,onChange:V=>k(V.target.value),placeholder:"your@email.com",className:"mt-2"})]}),N?.id==="Products"&&e.jsxs("div",{className:"py-2",children:[e.jsx(J,{htmlFor:"manufacturer",children:"Manufacturer"}),e.jsxs("select",{id:"manufacturer",className:"mt-2 block w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:A,onChange:V=>P(V.target.value),disabled:T,children:[e.jsx("option",{value:"all",children:"All manufacturers"}),!T&&Array.isArray(E)&&E.slice().sort((V,O)=>(V.PublicName||V.Name||"").localeCompare(O.PublicName||O.Name||"")).map(V=>V?.ManufacturerId?e.jsx("option",{value:V.ManufacturerId,children:(V.PublicName||V.Name||V.ManufacturerId)+(V.OpenToWork?" (Open to Work)":"")},V.ManufacturerId):null)]})]}),e.jsx(_e,{children:"The report will take around 5 minutes to generate."}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>M(!1),children:"Cancel"}),e.jsx(D,{onClick:F,disabled:!b||U,children:U?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function Jn({qualification:s}){return!s.QualificationId||s.QualificationId==="Suspended"?null:s.QualificationId==="Do Not Sell"?e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsxs(fe,{variant:"destructive",children:[e.jsx(g.X,{className:"h-3 w-3 mr-1"}),"Do Not Sell"]})}),e.jsx(pe,{children:e.jsx("p",{children:"Qualification"})})]})}):e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsxs(fe,{variant:"info",className:s.DefaultOpportunityNumber?"pr-1":"",children:[e.jsx(g.BadgeCheck,{className:"h-3 w-3 mr-1"}),s.QualificationId,s.DefaultOpportunityNumber&&e.jsx(fe,{variant:"secondary",size:"sm",className:"ml-1",children:s.DefaultOpportunityNumber})]})}),e.jsx(pe,{children:e.jsx("p",{children:"Qualification"})})]})})}function Vs({statistics:s,mode:t="month",chartHeight:a,loading:r=!1,size:n="default"}){const[i,l]=o.useState([]),[d,u]=o.useState(!1),m=[{name:"dollarVolume",label:"Dollar Volume",color:"var(--primary)",dotClassName:"bg-primary",yAxisId:"left",format:"money"},{name:"unitsSold",label:"Units Sold",color:"var(--chart-2)",dotClassName:"bg-chart-2",units:" units",yAxisId:"right",format:"integer"}];return o.useEffect(()=>{if(r||!s){l([]);return}let h;if(t==="week"){const c=new Map;s.forEach(y=>{const p=y.Day?.toString()||"";if(p.length===8){const x=parseInt(p.substring(0,4),10),w=parseInt(p.substring(4,6),10)-1,N=parseInt(p.substring(6,8),10),j=new Date(x,w,N),b=new Date(j);b.setDate(j.getDate()-j.getDay());const k=`${b.getFullYear()}-${String(b.getMonth()+1).padStart(2,"0")}-${String(b.getDate()).padStart(2,"0")}`,S=c.get(k)||{price:0,quantity:0};S.price+=y.ExtendedPrice||0,S.quantity+=y.Quantity||0,c.set(k,S)}}),h=Array.from(c).sort(([y],[p])=>y.localeCompare(p)).map(([y,p])=>({date:`${y.substring(5,7)}/${y.substring(8,10)}`,dollarVolume:p.price,unitsSold:p.quantity}))}else{const c=new Date,y=c.getFullYear(),p=c.getMonth(),x=c.getDate(),w=`${y}-${(p+1).toString().padStart(2,"0")}`,N=Array.from({length:12},(b,k)=>{const S=new Date(y,p-(11-k),1);return`${S.getFullYear()}-${(S.getMonth()+1).toString().padStart(2,"0")}`}),j=Object.fromEntries(N.map(b=>[b,{price:0,quantity:0}]));if(s.forEach(b=>{const k=String(b.Day??0);if(k.length!==8)return;const S=`${k.substring(0,4)}-${k.substring(4,6)}`;j[S]&&(j[S].price+=b.ExtendedPrice??0,j[S].quantity+=b.Quantity??0)}),h=N.map(b=>{const k=j[b],[S,M]=b.split("-").map(Number);return{date:new Date(S,M-1).toLocaleString("default",{month:"short",year:"numeric"}),dollarVolume:k.price,unitsSold:k.quantity}}),d){const b=j[w];if(b&&b.price>0&&x>0){const k=new Date(y,p+1,0).getDate();if(x<k){const S=b.price/x,M=b.quantity/x,A=S*k,P=M*k,E=h[h.length-1];E&&(E.dollarVolume=A,E.unitsSold=P)}}}}l(h)},[s,t,d,r]),r?e.jsx("div",{style:{height:a},children:e.jsx(f,{className:"h-full w-full rounded-md"})}):i.length===0?e.jsx("div",{style:{height:a},className:"flex items-center justify-center text-muted-foreground",children:"No sales data available."}):e.jsxs(e.Fragment,{children:[e.jsx(Bn,{data:i,series:m,height:a,size:n}),n==="default"&&t==="month"&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(at,{checked:d,onCheckedChange:u,id:"extrapolate-switch"}),e.jsx(J,{htmlFor:"extrapolate-switch",children:"Extrapolate Current Month"})]}),d&&e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["* Values for ",new Date().toLocaleString("default",{month:"long"})," are projected estimates."]})]})]})}function tr({type:s,applicationId:t,publicName:a,name:r,location:n,link:i,linkNewTab:l=!0,children:d}){const[u,m]=o.useState(!1),h=y=>{y.preventDefault(),y.stopPropagation(),navigator.clipboard.writeText(t),m(!0),setTimeout(()=>m(!1),2e3)},c=e.jsxs(Y,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-12 w-12 overflow-hidden rounded-md",children:e.jsx(us,{id:t,width:48,height:48},`partner_logo_${t}`)}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-primary",children:s}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"|"}),e.jsx(ye,{children:e.jsxs(ge,{delayDuration:300,children:[e.jsx(je,{asChild:!0,children:e.jsxs("div",{className:"flex cursor-pointer items-center gap-1",onClick:h,children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t}),u?e.jsx(g.Check,{className:"h-3 w-3 text-success"}):e.jsx(g.Copy,{className:"h-3 w-3 text-muted-foreground"})]})}),e.jsx(pe,{children:e.jsx("p",{children:u?"Copied!":"Copy ID"})})]})})]}),e.jsx("h3",{className:"font-semibold",children:a||"N/A"}),r&&e.jsx("p",{className:"text-sm text-muted-foreground",children:r}),n&&e.jsx("p",{className:"text-sm text-muted-foreground",children:n})]})]}),d&&e.jsx("div",{className:"flex flex-col items-end gap-2",children:d})]});return i?e.jsx(ve.Link,{to:i,target:l?"_blank":"_self",children:c}):c}function Zs({manufacturer:s,link:t,linkNewTab:a=!0,actions:r,mainAction:n,loading:i=!1,appID:l}){const{toast:d}=Ce(),[u,{isLoading:m}]=_.usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[h,c]=o.useState(!1),[y,p]=o.useState(""),{data:x}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:l||""},{skip:!l}),w=x?.IsReseller;if(i||!s)return e.jsxs(z,{className:"flex flex-col h-full",children:[e.jsxs(Y,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"h-12 w-12 rounded-md"}),e.jsxs("div",{children:[e.jsx(f,{className:"h-3 w-24 mb-2"}),e.jsx(f,{className:"h-5 w-40 mb-1"}),e.jsx(f,{className:"h-4 w-32 mb-1"}),e.jsx(f,{className:"h-4 w-48"})]})]}),e.jsx(f,{className:"h-16 w-24"})]}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex flex-col space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(f,{className:"h-5 w-16 rounded-full"}),e.jsx(f,{className:"h-5 w-20 rounded-full"}),e.jsx(f,{className:"h-5 w-14 rounded-full"})]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-32"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-40"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-36"})]})]})]})}),e.jsxs(ms,{className:"flex justify-between pt-2 gap-2 mt-auto",children:[e.jsx(f,{className:"h-9 w-24"}),e.jsx(f,{className:"h-9 w-40"})]})]});const N=[s.City,s.Province,s.Country].filter(Boolean),j=N.length>0?N.join(", "):"",b=s.Tags?.split(",").map(S=>S.trim()).filter(Boolean)||[],k=async()=>{if(!(!s?.ManufacturerId||!l||!y))try{await u({routeResellerId:l,emailAddress:y,manufacturerId:s.ManufacturerId}).unwrap(),d({title:"Report requested",description:`The Universal Product List for this manufacturer will be sent to ${y} shortly.`,variant:"success"}),c(!1)}catch(S){console.error("Error requesting product list:",S),d({title:"Error",description:"Failed to request product list. Please try again.",variant:"destructive"})}};return e.jsxs(z,{className:"flex flex-col h-full",children:[e.jsx(tr,{type:"Manufacturer",applicationId:s.ManufacturerId,publicName:s.PublicName,name:s.Name,location:j,link:t,linkNewTab:a,children:e.jsx("div",{className:"flex flex-col items-end gap-2",children:s.SalesStatistics&&s.SalesStatistics.length>0&&e.jsx("div",{className:"h-16 w-24",children:e.jsx(Vs,{statistics:s.SalesStatistics,size:"mini"})})})}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex",children:[e.jsxs("div",{className:"flex flex-col flex-1 space-y-2",children:[(!!s.Qualification?.QualificationId&&s.Qualification?.QualificationId!=="Suspended"||!!s.OpenToWork||!!s.OnHold&&s.OnHold!==0||b.length>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(Jn,{qualification:s.Qualification??{}}),!!s.OpenToWork&&e.jsxs(fe,{variant:"success",children:[e.jsx(g.HardHat,{className:"h-3 w-3 mr-1"}),"Open To Work"]}),!!s.OnHold&&s.OnHold!==0&&e.jsx(fe,{variant:"warning",children:"On Hold"}),b.map((S,M)=>e.jsx(fe,{variant:"outline",children:S},M))]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[s.Phone&&e.jsxs(ve.Link,{to:`tel:${s.Phone}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Phone,{className:"h-4 w-4"}),e.jsx("span",{children:s.Phone})]}),s.PublicEmail&&e.jsxs(ve.Link,{to:`mailto:${s.PublicEmail}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Mail,{className:"h-4 w-4"}),e.jsx("span",{children:s.PublicEmail})]}),s.Website&&e.jsxs(ve.Link,{to:s.Website,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Globe,{className:"h-4 w-4"}),e.jsx("span",{children:s.Website})]}),s.CurrencyCode&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.DollarSign,{className:"h-4 w-4"}),e.jsx("span",{children:s.CurrencyCode})]})]})]}),s.SalesData&&e.jsxs("div",{className:"border-l pl-2 ml-2 flex flex-col text-sm",children:[e.jsx("strong",{className:"",children:"YTD"}),e.jsx("p",{children:s.SalesData.SalesYearToDay?de(s.SalesData.SalesYearToDay):"—"}),e.jsx("strong",{className:"mt-2",children:"3 mo."}),e.jsx("p",{children:s.SalesData.SalesLast3Months?de(s.SalesData.SalesLast3Months):"—"}),e.jsx("strong",{className:"mt-2",children:"30 days"}),e.jsx("p",{children:s.SalesData.SalesLast30Days?de(s.SalesData.SalesLast30Days):"—"})]})]})}),(r||n||s.PublicResourcesLink||w&&l&&s.ManufacturerId||t)&&e.jsxs(ms,{className:"flex pt-2 gap-2 justify-between mt-auto",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r&&r,w&&l&&s.ManufacturerId&&e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{size:"icon",onClick:()=>c(!0),disabled:m,children:m?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.Download,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Email Product List"})})]})}),s.PublicResourcesLink&&e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:s.PublicResourcesLink,target:"_blank",children:e.jsx(D,{size:"icon",children:e.jsx(g.BookOpen,{className:"h-4 w-4"})})})}),e.jsx(pe,{children:e.jsx("p",{children:"Public Resources Link"})})]})})]}),n&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{children:n})})]}),e.jsx(De,{open:h,onOpenChange:c,children:e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Request Universal Product List"}),e.jsx(_e,{children:"Enter the email address where you would like to receive the report."})]}),e.jsxs("div",{className:"py-4",children:[e.jsx(J,{htmlFor:"email",children:"Email"}),e.jsx(le,{id:"email",value:y,onChange:S=>p(S.target.value),placeholder:"your@email.com",className:"mt-2"})]}),e.jsx(_e,{children:"The report will take around 5 minutes to generate."}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>c(!1),children:"Cancel"}),e.jsx(D,{onClick:k,disabled:!y||m,children:m?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function Zn({appID:s,reseller:t,readonly:a,userEmail:r,isSuperAdmin:n,withoutReports:i=!1,loadFullAfterSummary:l=!1}){const d=`${s}|${l?1:0}`,u=o.useRef(d),[m,h]=o.useState(()=>l?!!t:!1);o.useEffect(()=>{u.current!==d&&(u.current=d,h(!1))},[d]),o.useEffect(()=>{l&&t&&h(!0)},[l,t]);const c=l?m:!t,{data:y,isLoading:p,isError:x}=_.useGetV4PartnerByApplicationIdAccountResellerQuery({applicationId:s??"",withSpecification:!0},{skip:!s||!c}),[w,N]=o.useState({publicInfo:{hasUnsavedChanges:!1}}),j=o.useCallback(()=>a?!1:w.publicInfo.hasUnsavedChanges,[a,w]),b=o.useCallback((B,F)=>{N(U=>U[B]?.hasUnsavedChanges!==F.hasUnsavedChanges?{...U,[B]:F}:U)},[]),{NavigationGuardDialog:k}=Hn(j),S=y??t,M=p&&!S,A=x&&!S,P=!a||!!S?.Statement&&(S.Statement.Total??0)!==0,E=S?.QualifiedManufacturers??[],T=S?.Qualifications??[],I=[...S?.Opportunities??[]].sort((B,F)=>new Date(F.LastUpdate??0).getTime()-new Date(B.LastUpdate??0).getTime());return e.jsxs("div",{className:"@container",children:[A?e.jsx(z,{className:"p-6",children:e.jsxs(js,{variant:"destructive",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(bs,{children:"Error"}),e.jsx(ys,{children:"There was an error loading your reseller information. Please try again later."})]})}):e.jsxs("div",{className:"space-y-6 mb-6",children:[e.jsx(Gn,{fiscalYearMonthStart:S?.FiscalYearMonthStart||1,salesData:S?.SalesData,isLoading:M}),e.jsxs("div",{className:"grid @lg:grid-cols-2 gap-6",children:[e.jsx(Xa,{statistics:S?.SalesStatistics??[],loading:M}),e.jsx(yc,{openOrders:S?.ActiveOrderDetails??[],isLoading:M}),P&&e.jsx(hc,{appID:s,reseller:S||{},withoutReports:i,isLoading:M,userEmail:r,isSuperAdmin:n}),e.jsx(xc,{reseller:S||{},appID:s??"",isLoading:M,readonly:a,onUnsavedChanges:B=>b("publicInfo",{hasUnsavedChanges:B})}),e.jsx(bc,{isSuperAdmin:n,readonly:a,reseller:S||{},appID:s??"",isLoading:M}),M||E.length>0?e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{children:"Manufacturers you are qualified for"})}),e.jsx(G,{children:e.jsx("div",{className:"grid @lg:grid-cols-2 gap-4",children:M?Array.from({length:2}).map((B,F)=>e.jsx(Zs,{loading:!0},F)):E.map(B=>e.jsx(Zs,{manufacturer:B,link:`https://dashboard.randmar.io/${s}/Partner/${B.ManufacturerId}`},B.ManufacturerId))})})]}):T.length>0&&e.jsx(ji,{qualifications:T})]}),I.length>0&&e.jsx(mr,{applicationId:s,opportunities:I,loading:M}),!i&&e.jsx(Nc,{appID:s,userEmail:r,isLoading:!1})]}),e.jsx(k,{})]})}const vc=et.cva("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 bg-destructive/10 text-foreground [&>svg]:text-destructive",success:"border-success/50 bg-success/10 text-foreground [&>svg]:text-success",warning:"border-warning/50 bg-warning/10 text-foreground [&>svg]:text-warning",info:"border-info/50 bg-info/10 text-foreground [&>svg]:text-info"}},defaultVariants:{variant:"default"}}),js=R.forwardRef(({className:s,variant:t,...a},r)=>e.jsx("div",{ref:r,role:"alert",className:v(vc({variant:t}),s),...a}));js.displayName="Alert";const bs=R.forwardRef(({className:s,...t},a)=>e.jsx("h5",{ref:a,className:v("mb-1 font-medium leading-none tracking-tight",s),...t}));bs.displayName="AlertTitle";const ys=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("text-sm [&_p]:leading-relaxed",s),...t}));ys.displayName="AlertDescription";function As({columns:s,data:t,uniqueValues:a,tableClass:r,loading:n,initialSort:i}){const[l,d]=o.useState(i??[]),[u,m]=o.useState([]),[h,c]=o.useState({pageIndex:0,pageSize:10}),[y,p]=o.useState(null),x=Cs.useReactTable({data:n?[]:t,columns:s,getCoreRowModel:Cs.getCoreRowModel(),onSortingChange:d,getSortedRowModel:Cs.getSortedRowModel(),onColumnFiltersChange:m,getFilteredRowModel:Cs.getFilteredRowModel(),getPaginationRowModel:Cs.getPaginationRowModel(),onPaginationChange:c,state:{sorting:l,columnFilters:u,pagination:h},manualPagination:n,manualSorting:n,manualFiltering:n}),w=(N,j)=>{N.toggleSorting(j),p(null)};return n?e.jsxs("div",{className:"@container space-y-4",children:[e.jsx("div",{className:`rounded-md border ${r??""}`,children:e.jsxs(Lt,{children:[e.jsx(Ft,{children:e.jsx(Es,{children:s.map((N,j)=>e.jsx($t,{children:e.jsx(f,{className:"h-6 w-full"})},`skeleton-header-${j}`))})}),e.jsx(Bt,{children:Array.from({length:h.pageSize}).map((N,j)=>e.jsx(Es,{children:s.map((b,k)=>e.jsx(gt,{children:e.jsx(f,{className:"h-6 w-full"})},`skeleton-cell-${j}-${k}`))},`skeleton-row-${j}`))})]})}),e.jsxs("div",{className:"flex flex-col items-center gap-4 @[35rem]:flex-row @[35rem]:justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{className:"h-8 w-[110px]"}),e.jsx(f,{className:"h-8 w-[70px]"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{className:"hidden h-8 w-8 lg:flex"}),e.jsx(f,{className:"h-8 w-8"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(f,{className:"h-6 w-12"}),e.jsx(f,{className:"h-6 w-8"}),e.jsx(f,{className:"h-6 w-8"})]}),e.jsx(f,{className:"h-8 w-8"}),e.jsx(f,{className:"hidden h-8 w-8 lg:flex"})]})]})]}):e.jsxs("div",{className:"@container space-y-4",children:[e.jsxs(hs,{className:`rounded-md border ${r??""}`,children:[e.jsxs(Lt,{children:[e.jsx(Ft,{children:x.getHeaderGroups().map(N=>e.jsx(Es,{children:N.headers.map(j=>e.jsx($t,{children:j.isPlaceholder?null:j.column.getCanSort()||j.column.getCanFilter()?e.jsxs(wt,{open:y===j.id,onOpenChange:b=>p(b?j.id:null),children:[e.jsx(St,{asChild:!0,children:e.jsxs(D,{variant:"ghost",className:"pl-0",children:[Cs.flexRender(j.column.columnDef.header,j.getContext()),j.column.getIsFiltered()?e.jsx(g.Filter,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="asc"?e.jsx(g.ArrowUp,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="desc"?e.jsx(g.ArrowDown,{className:"ml-2 h-4 w-4"}):e.jsx(g.ArrowUpDown,{className:"ml-2 h-4 w-4"})]})}),e.jsx(it,{className:"w-56",children:e.jsxs("div",{className:"space-y-2",children:[j.column.getCanSort()&&e.jsxs(e.Fragment,{children:[e.jsxs(D,{variant:"ghost",className:"w-full justify-start",onClick:()=>w(j.column,!1),children:[e.jsx(g.ArrowUp,{className:"mr-2 h-4 w-4"}),"Sort Ascending"]}),e.jsxs(D,{variant:"ghost",className:"w-full justify-start",onClick:()=>w(j.column,!0),children:[e.jsx(g.ArrowDown,{className:"mr-2 h-4 w-4"}),"Sort Descending"]})]}),j.column.getCanFilter()&&e.jsx("div",{className:"px-2 py-1",children:a[j.column.id]?e.jsxs(ks,{onValueChange:b=>j.column.setFilterValue(b==="all"?void 0:[b]),children:[e.jsx(ps,{children:e.jsx(Rs,{placeholder:`Filter ${j.column.columnDef.header}...`})}),e.jsxs(gs,{children:[e.jsx(Xe,{value:"all",children:"All"}),a[j.column.id]?.map(b=>e.jsx(Xe,{value:b||"empty",children:b||"(Empty)"},b))]})]}):e.jsx(le,{placeholder:`Filter ${j.column.columnDef.header}...`,value:j.column.getFilterValue()??"",onChange:b=>j.column.setFilterValue(b.target.value),className:"w-full"})})]})})]}):e.jsx("div",{className:"py-2 px-4",children:Cs.flexRender(j.column.columnDef.header,j.getContext())})},j.id))},N.id))}),e.jsx(Bt,{children:x.getRowModel().rows?.length?x.getRowModel().rows.map(N=>e.jsx(Es,{"data-state":N.getIsSelected()&&"selected",children:N.getVisibleCells().map(j=>e.jsx(gt,{children:Cs.flexRender(j.column.columnDef.cell,j.getContext())},j.id))},N.id)):e.jsx(Es,{children:e.jsx(gt,{colSpan:s.length,className:"h-24 text-center",children:"No results."})})})]}),e.jsx(Ut,{orientation:"horizontal"})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 @[35rem]:flex-row @[35rem]:justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Rows per page"}),e.jsxs(ks,{value:`${x.getState().pagination.pageSize}`,onValueChange:N=>{x.setPageSize(Number(N))},children:[e.jsx(ps,{className:"h-8 w-[70px]",children:e.jsx(Rs,{asChild:!0,children:e.jsx("span",{children:x.getState().pagination.pageSize})})}),e.jsx(gs,{side:"top",children:[10,20,30,40,50].map(N=>e.jsx(Xe,{value:`${N}`,children:e.jsx("span",{children:N})},N))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(D,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>x.setPageIndex(0),disabled:!x.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to first page"}),e.jsx(g.ChevronsLeft,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>x.previousPage(),disabled:!x.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to previous page"}),e.jsx(g.ChevronLeft,{className:"h-4 w-4"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"Page"}),e.jsx("span",{className:"text-sm font-medium",children:x.getState().pagination.pageIndex+1}),e.jsx("p",{className:"text-sm font-medium",children:"of"}),e.jsx("span",{className:"text-sm font-medium",children:x.getPageCount()})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>x.nextPage(),disabled:!x.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to next page"}),e.jsx(g.ChevronRight,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>x.setPageIndex(x.getPageCount()-1),disabled:!x.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to last page"}),e.jsx(g.ChevronsRight,{className:"h-4 w-4"})]})]})]})]})}function Xn({account:s,action:t,loading:a=!1,className:r,withAbout:n=!1}){return a||!s?e.jsxs(z,{className:`flex flex-col h-full ${r}`,children:[e.jsx(Y,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"h-12 w-12 rounded-md"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-3 w-16"}),e.jsx(f,{className:"h-3 w-16"})]}),e.jsx(f,{className:"h-5 w-48 mt-1"})]})]})}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(f,{className:"h-5 w-24 rounded-full"}),e.jsx(f,{className:"h-5 w-20 rounded-full"}),e.jsx(f,{className:"h-5 w-16 rounded-full"})]}),n&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(f,{className:"h-5 w-full"}),e.jsx(f,{className:"h-5 w-full"}),e.jsx(f,{className:"h-5 w-full"})]})]})}),e.jsxs(ms,{className:"px-6 py-4 flex justify-between gap-2 mt-auto",children:[e.jsx(f,{className:"h-9 w-32"}),e.jsx(f,{className:"h-9 w-48"})]})]}):e.jsxs(z,{className:`flex flex-col h-full ${r}`,children:[e.jsx(tr,{type:"Partner",applicationId:s.ApplicationId,publicName:s.PublicName}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[(s.IsManufacturer||s.IsReseller||s.IsSalesAgency||s.HasShopifyStore||s.IsVendor)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.IsManufacturer&&e.jsx(fe,{variant:"info",children:"Manufacturer"}),s.IsReseller&&e.jsx(fe,{variant:"success",children:"Reseller"}),s.IsSalesAgency&&e.jsx(fe,{variant:"outline",children:"Agency"}),s.HasShopifyStore&&e.jsx(fe,{variant:"secondary",children:"Shopify"}),s.IsVendor&&e.jsx(fe,{variant:"outline",children:"Vendor"})]}),n&&s.About&&e.jsx("div",{className:"prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:s.About??""}})]})}),e.jsx(ms,{className:"px-6 py-4 flex justify-end gap-2 mt-auto",children:t||e.jsxs(D,{className:"flex items-center gap-2",children:[e.jsx(g.ExternalLink,{className:"h-4 w-4"}),"Go to Partner Dashboard"]})})]})}function ei({reseller:s,link:t,linkNewTab:a=!0,actions:r,mainAction:n,loading:i=!1}){if(i||!s)return e.jsxs(z,{className:"flex flex-col h-full",children:[e.jsx(Y,{className:"flex flex-row items-start justify-between space-y-0 pb-2 pt-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"h-12 w-12 rounded-md"}),e.jsxs("div",{children:[e.jsx(f,{className:"h-3 w-24 mb-2"}),e.jsx(f,{className:"h-5 w-40 mb-1"}),e.jsx(f,{className:"h-4 w-32 mb-1"}),e.jsx(f,{className:"h-4 w-48"})]})]})}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsx("div",{className:"flex",children:e.jsxs("div",{className:"flex flex-col flex-1 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(f,{className:"h-5 w-16 rounded-full"}),e.jsx(f,{className:"h-5 w-20 rounded-full"}),e.jsx(f,{className:"h-5 w-14 rounded-full"})]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-32"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-40"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx(f,{className:"h-4 w-36"})]})]})]})})}),e.jsxs(ms,{className:"flex justify-between pt-2 gap-2 mt-auto",children:[e.jsx(f,{className:"h-9 w-24"}),e.jsx(f,{className:"h-9 w-40"})]})]});const l=[s.City,s.Province,s.Country].filter(Boolean),d=l.length>0?l.join(", "):"Location not provided",u=s.Priority?.trim(),m=!!s.Qualification?.QualificationId&&s.Qualification?.QualificationId!=="Suspended",h=!!s.OnHold&&s.OnHold!==0,c=!!u,y=p=>{const x=p.toLowerCase();return x.includes("starter")||x.includes("basic")?"secondary":x.includes("exclusive")||x.includes("jean coutu")||x.includes("novexco")||x.includes("coopsco")?"success":"info"};return e.jsxs(z,{className:"flex flex-col h-full",children:[e.jsx(tr,{type:"Reseller",applicationId:s.ResellerId,publicName:s.PublicName,name:s.Name,location:d,link:t,linkNewTab:a,children:e.jsx("div",{className:"flex flex-col items-end gap-2",children:s.SalesStatistics&&s.SalesStatistics.length>0&&e.jsx("div",{className:"h-16 w-24",children:e.jsx(Vs,{statistics:s.SalesStatistics,size:"mini"})})})}),e.jsx(G,{className:"pb-2 flex-grow",children:e.jsxs("div",{className:"flex",children:[e.jsxs("div",{className:"flex flex-col flex-1 space-y-2",children:[(m||h||c)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[m&&e.jsx(Jn,{qualification:s.Qualification??{}}),h&&e.jsx(fe,{variant:"warning",children:"On Hold"}),c&&e.jsx(fe,{variant:y(u),children:u})]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[s.Phone&&e.jsxs(ve.Link,{to:`tel:${s.Phone}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Phone,{className:"h-4 w-4"}),e.jsx("span",{children:s.Phone})]}),s.PublicEmail&&e.jsxs(ve.Link,{to:`mailto:${s.PublicEmail}`,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Mail,{className:"h-4 w-4"}),e.jsx("span",{children:s.PublicEmail})]}),s.Website&&e.jsxs(ve.Link,{to:s.Website,target:"_blank",className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.Globe,{className:"h-4 w-4"}),e.jsx("span",{children:s.Website})]}),s.CurrencyCode&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(g.DollarSign,{className:"h-4 w-4"}),e.jsx("span",{children:s.CurrencyCode})]})]})]}),s?.SalesData&&e.jsxs("div",{className:"border-l pl-2 ml-2 flex flex-col text-sm",children:[e.jsx("strong",{className:"",children:"YTD"}),e.jsx("p",{children:s?.SalesData.SalesYearToDay?de(s?.SalesData.SalesYearToDay):"—"}),e.jsx("strong",{className:"mt-2",children:"3 mo."}),e.jsx("p",{children:s?.SalesData.SalesLast3Months?de(s?.SalesData.SalesLast3Months):"—"}),e.jsx("strong",{className:"mt-2",children:"30 days"}),e.jsx("p",{children:s?.SalesData.SalesLast30Days?de(s?.SalesData.SalesLast30Days):"—"})]})]})}),(r||n)&&e.jsxs(ms,{className:"flex pt-2 gap-2 justify-between mt-auto",children:[e.jsx("div",{className:"flex items-center gap-2",children:r&&r}),n&&e.jsx("div",{children:n})]})]})}const Lt=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:a,className:v("w-full caption-bottom text-sm",s),...t})}));Lt.displayName="Table";const Ft=R.forwardRef(({className:s,...t},a)=>e.jsx("thead",{ref:a,className:v("[&_tr]:border-b",s),...t}));Ft.displayName="TableHeader";const Bt=R.forwardRef(({className:s,...t},a)=>e.jsx("tbody",{ref:a,className:v("[&_tr:last-child]:border-0",s),...t}));Bt.displayName="TableBody";const si=R.forwardRef(({className:s,...t},a)=>e.jsx("tfoot",{ref:a,className:v("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...t}));si.displayName="TableFooter";const Es=R.forwardRef(({className:s,...t},a)=>e.jsx("tr",{ref:a,className:v("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...t}));Es.displayName="TableRow";const $t=R.forwardRef(({className:s,...t},a)=>e.jsx("th",{ref:a,className:v("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t,children:R.isValidElement(t.children)&&t.children.type==="span"?t.children:e.jsx("span",{children:t.children})}));$t.displayName="TableHead";const gt=R.forwardRef(({className:s,...t},a)=>e.jsx("td",{ref:a,className:v("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",s),...t,children:R.isValidElement(t.children)&&t.children.type==="span"?t.children:e.jsx("span",{children:t.children})}));gt.displayName="TableCell";const ti=R.forwardRef(({className:s,...t},a)=>e.jsx("caption",{ref:a,className:v("mt-4 text-sm text-muted-foreground",s),...t}));ti.displayName="TableCaption";const ai="[--rm-shell-header-height:3.5rem]",wc="h-[var(--rm-shell-header-height)]",Sc="pt-[var(--rm-shell-header-height)]",ar=o.forwardRef(({onSignOut:s,handleValidSearch:t,rightMenu:a,searchPlaceholder:r},n)=>{const[i,l]=o.useState(""),d=ve.useLocation(),{toast:u}=Ce();o.useEffect(()=>{const y=new URLSearchParams(d.search).get("q");y&&l(y)},[d.search]);const m=()=>{const c=i.trim();if(!c||c.length<2){u({title:"Enter more characters to search",description:"At least 2 characters are needed to search products.",variant:"destructive",duration:5e3});return}t(c)},h=c=>{c.key==="Enter"&&m()};return e.jsxs("header",{className:`fixed top-0 right-0 left-0 z-50 flex ${ai} ${wc} items-center gap-3 border-b border-primary/20 bg-primary px-4 text-primary-foreground transition-[left] duration-200 ease-linear lg:px-6 peer-data-[state=expanded]:lg:left-(--sidebar-width) peer-data-[collapsible=offcanvas]:lg:left-0 peer-data-[collapsible=icon]:lg:left-(--sidebar-width-icon)`,children:[e.jsx(Ba,{className:"h-10 w-10 text-primary-foreground hover:bg-primary-foreground/15 hover:text-primary-foreground focus-visible:ring-primary-foreground focus-visible:ring-offset-primary lg:hidden",children:e.jsx(g.Menu,{className:"h-5 w-5"})}),e.jsx("div",{className:"flex flex-1 items-center gap-4",children:e.jsx("div",{className:"relative w-full max-w-sm",children:e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"absolute left-1 top-1/2 inline-flex h-8 w-8 -translate-y-1/2 items-center justify-center rounded-md text-primary-foreground/90 transition-colors hover:bg-primary-foreground/15 hover:text-primary-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-foreground focus-visible:ring-offset-2 focus-visible:ring-offset-primary",onClick:m,"aria-label":"Search",children:e.jsx(g.Search,{className:"h-4 w-4"})}),e.jsx(le,{placeholder:r??"Search...","aria-label":r??"Search",className:"h-10 w-full border-primary-foreground/35 bg-primary-foreground/12 pl-10 text-primary-foreground placeholder:text-primary-foreground/70 focus-visible:ring-primary-foreground focus-visible:ring-offset-primary",value:i,onChange:c=>l(c.target.value),onKeyDown:h,ref:n},"topbar-search")]})})}),e.jsxs("div",{className:"flex items-center gap-3 text-primary-foreground [&_svg]:text-primary-foreground",children:[a,s&&e.jsx("div",{className:"flex items-center",children:e.jsxs(D,{variant:"ghost",size:"icon",className:"h-10 w-10 text-primary-foreground hover:bg-primary-foreground/15 hover:text-primary-foreground focus-visible:ring-primary-foreground focus-visible:ring-offset-primary",onClick:s,children:[e.jsx(g.LogOut,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Sign out"})]})})]})]})});ar.displayName="Topbar";function ri({orders:s,loading:t=!1}){const a=o.useMemo(()=>{if(!s||s.length===0)return{all:{orders:0,amount:0},processing:{orders:0,amount:0},shipped:{orders:0,amount:0},delayed:{orders:0,amount:0}};const n=s.filter(N=>N.DocumentType==="Order"),i=s.filter(N=>N.DocumentType==="Shipment"),l=n.filter(N=>N.WarehouseCode!=="3PLE"),d=l.reduce((N,j)=>N+(j.Quantity||0),0),u=l.reduce((N,j)=>N+(j.ExtendedPrice||0),0),m=n.filter(N=>N.WarehouseCode==="3PLE"),h=m.reduce((N,j)=>N+(j.Quantity||0),0),c=m.reduce((N,j)=>N+(j.ExtendedPrice||0),0),y=i.length,p=i.reduce((N,j)=>N+(j.ExtendedPrice||0),0),x=d+h+y,w=u+c+p;return{all:{orders:x,amount:w},processing:{orders:d,amount:u},shipped:{orders:y,amount:p},delayed:{orders:h,amount:c}}},[s]),r=[{name:"All",icon:g.Package,stripeClass:"bg-info/60",iconBgClass:"bg-info/90",iconTextClass:"text-info-foreground",orders:a.all.orders,amount:a.all.amount},{name:"Processing",icon:g.RefreshCcw,stripeClass:"bg-warning/60",iconBgClass:"bg-warning/90",iconTextClass:"text-warning-foreground",orders:a.processing.orders,amount:a.processing.amount},{name:"Shipped",icon:g.Truck,stripeClass:"bg-success/60",iconBgClass:"bg-success/90",iconTextClass:"text-success-foreground",orders:a.shipped.orders,amount:a.shipped.amount},{name:"Delayed",icon:g.AlertCircle,stripeClass:"bg-destructive/60",iconBgClass:"bg-destructive/90",iconTextClass:"text-destructive-foreground",orders:a.delayed.orders,amount:a.delayed.amount}];return t?e.jsxs(z,{className:"@container",children:[e.jsx(Y,{className:"pb-0",children:e.jsx(me,{className:"text-base font-medium text-foreground",children:"Active Orders"})}),e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-4 p-4",children:[1,2,3,4].map(n=>e.jsxs("div",{className:"overflow-hidden rounded-md border",children:[e.jsx("div",{className:"bg-border h-[3px]"}),e.jsxs("div",{className:"p-6 border border-t-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx(f,{className:"h-5 w-24"}),e.jsx(f,{className:"h-8 w-8 rounded-full"})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx(f,{className:"h-3 w-16 mb-2"}),e.jsx(f,{className:"h-7 w-12"})]}),e.jsxs("div",{className:"text-end",children:[e.jsx(f,{className:"h-3 w-16 mb-2"}),e.jsx(f,{className:"h-5 w-20"})]})]})]})]},n))})]}):e.jsxs(z,{className:"@container",children:[e.jsx(Y,{className:"pb-0",children:e.jsx(me,{className:"text-base font-medium text-foreground",children:"Active Orders"})}),e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-4 p-4",children:r.map(n=>e.jsxs("div",{className:"overflow-hidden rounded-md border",children:[e.jsx("div",{className:`${n.stripeClass} h-[3px]`}),e.jsxs("div",{className:"p-6 border border-t-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:"font-semibold text-base",children:n.name}),e.jsx("div",{className:`${n.iconBgClass} p-2 rounded-full`,children:e.jsx(n.icon,{className:`size-4 shrink-0 ${n.iconTextClass}`})})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Orders"}),e.jsx("p",{className:"text-xl font-bold",children:n.orders})]}),e.jsxs("div",{className:"text-end",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),e.jsx("p",{className:"text-base font-semibold",children:de(n.amount)})]})]})]})]},n.name))})]})}const Ps=R.forwardRef(({className:s,...t},a)=>e.jsx(wa.Root,{ref:a,className:v("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...t,children:e.jsx(wa.Indicator,{className:v("flex items-center justify-center text-current"),children:e.jsx(g.Check,{className:"h-4 w-4"})})}));Ps.displayName=wa.Root.displayName;function ni({items:s,selectedIds:t,onSelectedIdsChange:a,disabled:r=!1,loading:n=!1,selectionMode:i="multiple",layout:l="stack",gridColumns:d=2,emptyState:u,loadingState:m,getItemAriaLabel:h,renderItem:c,className:y,...p}){const x=R.useId(),w=R.useMemo(()=>new Set(t),[t]),N=l==="grid"?v("grid gap-3",d===2&&"grid-cols-1 sm:grid-cols-2"):"space-y-3",j=R.useCallback(b=>{if(r||n||b.disabled)return;const k=w.has(b.id);if(i==="single"){a(k?[]:[b.id]);return}if(k){a(t.filter(S=>S!==b.id));return}a([...t,b.id])},[r,n,a,w,t,i]);return n?e.jsx("div",{className:v(N,y),role:"status","aria-live":"polite",...p,children:m??e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:"Loading options"}),Array.from({length:l==="grid"?4:3}).map((b,k)=>e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 shadow-sm","aria-hidden":"true",children:[e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-muted"}),e.jsx("div",{className:"mt-2 h-3 w-1/2 animate-pulse rounded bg-muted"})]},`loading-${k}`))]})}):s.length===0?e.jsx("div",{className:v(N,y),...p,children:u??e.jsx("div",{className:"rounded-xl border border-dashed border-border bg-muted/30 p-4 text-sm text-muted-foreground",children:"No options are available."})}):e.jsx("div",{className:v(N,y),role:"group","aria-disabled":r||void 0,...p,children:s.map((b,k)=>{const S=w.has(b.id),M=r||b.disabled===!0,A=`${x}-${k}-label`,P=`${x}-${k}-description`;return e.jsxs("button",{type:"button",role:"checkbox","aria-checked":S,"aria-disabled":M,"aria-label":h?.(b)??b.label,"aria-labelledby":c?void 0:A,"aria-describedby":!c&&b.description?P:void 0,disabled:M,onClick:()=>j(b),className:v("flex w-full items-start gap-3 rounded-xl border bg-card p-4 text-left shadow-sm transition-colors transition-shadow","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","hover:bg-muted/30 hover:shadow",S?"border-primary bg-primary/5 ring-2 ring-primary/20":"border-border",M&&"cursor-not-allowed opacity-60 hover:bg-card hover:shadow-sm"),children:[e.jsx("span",{"aria-hidden":"true",className:v("mt-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm border border-primary shadow-sm",S?"bg-primary text-primary-foreground":"bg-background text-transparent"),children:e.jsx(g.Check,{className:"h-3.5 w-3.5"})}),e.jsx("div",{className:"min-w-0 flex-1",children:c?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:b.label}),c(b,{checked:S,disabled:M,index:k})]}):e.jsxs(e.Fragment,{children:[(b.prefix||b.emphasis)&&e.jsxs("div",{className:"flex flex-wrap items-baseline gap-1 text-xs",children:[b.prefix&&e.jsx("span",{className:"font-semibold uppercase tracking-wide text-muted-foreground",children:b.prefix}),b.emphasis&&e.jsx("span",{className:"font-semibold text-foreground",children:b.emphasis})]}),e.jsx("span",{id:A,className:v("block text-sm font-medium text-foreground",(b.prefix||b.emphasis)&&"mt-1"),children:b.label}),b.description&&e.jsx("span",{id:P,className:"mt-1 block text-sm text-muted-foreground",children:b.description})]})})]},b.id)})})}const Qt=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command,{ref:a,className:v("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...t}));Qt.displayName=es.Command.displayName;const Cc=({children:s,...t})=>e.jsx(De,{...t,children:e.jsx(Me,{className:"overflow-hidden p-0",children:e.jsx(Qt,{className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:s})})}),rr=R.forwardRef(({className:s,...t},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(g.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(es.Command.Input,{ref:a,className:v("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",s),...t})]}));rr.displayName=es.Command.Input.displayName;const nr=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command.List,{ref:a,className:v("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...t}));nr.displayName=es.Command.List.displayName;const ir=R.forwardRef((s,t)=>e.jsx(es.Command.Empty,{ref:t,className:"py-6 text-center text-sm",...s}));ir.displayName=es.Command.Empty.displayName;const lr=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command.Group,{ref:a,className:v("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",s),...t}));lr.displayName=es.Command.Group.displayName;const ii=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command.Separator,{ref:a,className:v("-mx-1 h-px bg-border",s),...t}));ii.displayName=es.Command.Separator.displayName;const _t=R.forwardRef(({className:s,...t},a)=>e.jsx(es.Command.Item,{ref:a,className:v("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",s),...t}));_t.displayName=es.Command.Item.displayName;const li=({className:s,...t})=>e.jsx("span",{className:v("ml-auto text-xs tracking-widest text-muted-foreground",s),...t});li.displayName="CommandShortcut";const oi=({countryCode:s,className:t=""})=>{const[a,r]=o.useState(!1),n=s.trim().toUpperCase();o.useEffect(()=>{r(!1)},[n]);const i=o.useMemo(()=>n?`https://purecatamphetamine.github.io/country-flag-icons/3x2/${encodeURIComponent(n)}.svg`:"",[n]);return!n||a?e.jsx("span",{className:t,children:s}):e.jsx("img",{src:i,alt:`${n} flag`,className:`inline-block h-auto w-6 ${t}`,loading:"lazy",onError:()=>r(!0)})};function kc({document:s,loading:t=!1}){return t?e.jsx("div",{children:"loading..."}):e.jsxs("div",{children:["GENERAL DOCUMENT CARD - ",s?.OrderNumber," for P.O. ",s?.PONumber]})}function ci({path:s,origin:t,...a}){const r=vt(),n=R.useMemo(()=>$s(s,t??r),[r,t,s]);return e.jsx("img",{...a,src:n})}const Rc="https://mcp.randmar.ai/connect",Pc="2025-06-18",Ac=new Set(["search_api_endpoints","get_endpoint_details","get_current_application_id","get_next_randmar_step","execute_api_endpoint","execute_api_endpoint_ro"]);function Ic(s,t){if(!t.includes("text/event-stream"))return JSON.parse(s);const a=s.split(/\r?\n/).filter(r=>r.startsWith("data:")).map(r=>r.slice(5).trim()).filter(Boolean);if(a.length===0)throw new Error("The MCP gateway returned an empty event stream.");return JSON.parse(a.join(`
49
+ `))}function di(s){const t=JSON.parse(s.ArgumentsJson??"{}");if(typeof t!="object"||t===null||Array.isArray(t))throw new Error("Tool arguments must be a JSON object.");return t}function Dc(s){let t={};try{t=di(s)}catch{}return s.Name==="search_api_endpoints"?"Searching API endpoints":s.Name==="get_current_application_id"?"Checking current application":s.Name==="get_next_randmar_step"?"Finding next Randmar step":typeof t.operationId=="string"&&t.operationId.trim()?t.operationId:s.Name==="get_endpoint_details"?"Inspecting API endpoint":"Executing API endpoint"}async function Mc(s,t,a){const r=s.Name??"",n=s.ToolCallId??"",i=Dc(s);if(!r||!n)throw new Error("The assistant returned an incomplete MCP tool call.");if(!Ac.has(r)){const c=`Unknown MCP tool: ${r}.`;return{title:i,output:c,functionResponse:{ToolCallId:n,Name:r,Content:c}}}let l;try{l=di(s)}catch(c){const y=`Invalid JSON arguments for ${r}: ${c instanceof Error?c.message:"Unable to parse arguments."}`;return{title:i,output:y,functionResponse:{ToolCallId:n,Name:r,Content:y}}}const d=await fetch(Rc,{method:"POST",signal:a,headers:{Accept:"application/json, text/event-stream","Content-Type":"application/json","MCP-Protocol-Version":Pc,...t?{Authorization:`Bearer ${t}`}:{}},body:JSON.stringify({jsonrpc:"2.0",id:n,method:"tools/call",params:{name:r,arguments:l}})}),u=await d.text();if(!d.ok)throw new Error(`MCP HTTP ${String(d.status)}: ${u.trim()||"Request failed."}`);const m=Ic(u,d.headers.get("content-type")?.toLowerCase()??"");if(m.error){const c=m.error.data===void 0?"":` ${JSON.stringify(m.error.data)}`;throw new Error(`MCP ${String(m.error.code??"error")}: ${m.error.message??"Tool call failed."}${c}`)}const h=(m.result?.content??[]).filter(c=>c.type==="text"&&typeof c.text=="string").map(c=>c.text??"").join(`
50
50
  `).trim()||"The MCP tool returned no text content.";return{title:i,output:h,functionResponse:{ToolCallId:n,Name:r,Content:JSON.stringify(h)}}}function Tc(){if(!(typeof localStorage>"u"))return localStorage.getItem("access_token")||void 0}function Ec({userId:s,onGeneratedImageUploaded:t}){const[a,r]=o.useState(""),[n,i]=o.useState([]),[l,d]=o.useState([]),[u,m]=o.useState([]),[h,c]=o.useState([]),[y,p]=o.useState(0),x=o.useRef(!1),w=o.useRef(null),N=o.useRef(null),j=o.useRef(null),b=o.useRef([]),k=o.useRef([]),S=o.useRef(new Map),[M]=_.usePostV4PartnerByApplicationIdGenerationV2RandmarAssistantMutation(),[A]=_.usePostV4PartnerByApplicationIdGenerationUploadMutation();o.useEffect(()=>{if(a||u.length===0)return;r("Handling message...");const{input:Z,attachedFiles:X,uiMessageId:se}=u[0];m(ue=>ue.slice(1)),V(Z,X,se)},[a,u]),o.useEffect(()=>{k.current=h},[h]);const P=Z=>{if(!Z)return!1;const X=Z,se=typeof X.name=="string"?X.name:"",ue=typeof X.message=="string"?X.message:"",Q=typeof X.error=="string"?X.error:"";return se==="AbortError"||Q==="AbortError"||ue.toLowerCase().includes("abort")||ue.toLowerCase().includes("canceled")},E=Z=>{if(typeof Z!="string"||Z.length===0||!Z.includes("Base64Data")&&!Z.includes("base64Data")&&!Z.includes('"Images"')&&!Z.includes('"images"'))return null;let X;try{X=JSON.parse(Z)}catch{return null}const se=X;if(!se||typeof se!="object")return null;const ue=se.Images??se.images;if(!Array.isArray(ue)||ue.length===0)return null;const Q=ue.map(Ne=>{const Fe=Ne,xe=Fe?.MimeType??Fe?.mimeType,Te=Fe?.Base64Data??Fe?.base64Data;if(typeof xe!="string"||typeof Te!="string")return null;const Ae=xe.trim(),Ye=Te.replace(/\s+/g,"");return!Ae.startsWith("image/")||Ye.length===0?null:{mimeType:Ae,base64Data:Ye}}).filter(Ne=>Ne!=null);if(Q.length===0)return null;const te=se.Text??se.text;return{text:typeof te=="string"?te:"",images:Q}},T=Z=>{const X=(Z??"").toLowerCase();return X==="image/png"?"png":X==="image/jpeg"?"jpg":X==="image/webp"?"webp":X==="image/gif"?"gif":X==="image/svg+xml"?"svg":"png"},I=Z=>{const X=Z.replace(/^data:[^,]+,/,"").replace(/\s+/g,""),se=atob(X),ue=new Uint8Array(se.length);for(let Q=0;Q<se.length;Q++)ue[Q]=se.charCodeAt(Q);return ue},B=async(Z,X)=>{if(x.current||!Z||Z.length===0)return;const se=new Date,ue=`${se.getFullYear()}${String(se.getMonth()+1).padStart(2,"0")}${String(se.getDate()).padStart(2,"0")}_${String(se.getHours()).padStart(2,"0")}${String(se.getMinutes()).padStart(2,"0")}${String(se.getSeconds()).padStart(2,"0")}`,Q=await Promise.allSettled(Z.map(async(oe,Ne)=>{const Fe=T(oe.mimeType),xe=`generated_${ue}_${Ne+1}.${Fe}`,Te=I(oe.base64Data),Ae=new File([Te],xe,{type:oe.mimeType}),Ye=A({applicationId:s,body:{file:Ae}});b.current.push(Ye);try{const Je=await Ye.unwrap();if(typeof Je!="string"||Je.length===0)throw new Error("Upload did not return a file URI.");return Je}finally{b.current=b.current.filter(Je=>Je!==Ye)}}));if(x.current)return;const te=Q.map(oe=>oe.status==="fulfilled"?oe.value:null).filter(oe=>typeof oe=="string"&&oe.length>0);te.length>0&&(d(oe=>[...oe,["Generated image uploaded",te.join(`
51
51
  `)]]),t?.({assistantMessageId:X,urls:te}))},F=async(Z,X)=>{if(x.current){r("");return}if(X===0){q({content:"I've reached my action limit for this request. Please let me know if you'd like me to continue.",timestamp:new Date}),r("");return}try{r("Thinking...");const se=M({applicationId:s,body:Z});w.current=se;const ue=await se.unwrap();if(w.current=null,x.current){r("");return}const Q=ue.Content,te=[...Z,Q],oe=ue.ContextUtilization??0;c(te),p(oe);const Ne=Q.Parts?.find(xe=>xe.Text)?.Text;Ne&&q({content:Ne,timestamp:new Date});const Fe=Q.Parts?.map(xe=>xe.FunctionCall).filter(Boolean)??[];if(Fe.length>0){r("Using Randmar API...");const xe=[];for(const Te of Fe){if(x.current){r("");return}if(Te?.Name&&Te.ToolCallId){const Ae=new AbortController;j.current=Ae;const Ye=await Mc(Te,Tc(),Ae.signal).finally(()=>{j.current===Ae&&(j.current=null)}),{title:Je,output:K,functionResponse:Se}=Ye;if(d(Be=>[...Be,[Je,K]]),x.current){r("");return}const Ve=E(K);if(Ve){const Be=q({content:"",images:Ve.images,timestamp:new Date});Be&&B(Ve.images,Be)}Ve&&(Se.Content="image generated ok"),xe.push({FunctionResponse:Se})}}if(xe.length>0){const Te={Role:"TOOL",Parts:xe},Ae=[...te,Te];c(Ae),r("Composing response..."),await F(Ae,X-1);return}}r("")}catch(se){if(w.current=null,console.error("Error during AI interaction:",se),x.current||P(se)){r("");return}q({content:"I'm sorry, I encountered an error. Please write continue or try again.",timestamp:new Date}),r("")}},U=Z=>Z==="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"||Z==="application/vnd.ms-excel"?"text/plain":Z,V=async(Z,X,se)=>{try{const ue=[{Text:Z.trim()}],Q=[];if(X&&X.length>0){r(X.length===1?"Receiving attached file...":"Receiving attached files...");for(const Ne of X){if(x.current){r("");return}const Fe=new File([await Ne.arrayBuffer()],Ne.name,{type:Ne.type}),xe=A({applicationId:s,body:{file:Fe}});N.current=xe;const Te=await xe.unwrap();if(N.current=null,x.current){r("");return}if(typeof Te!="string"||Te.length===0)throw new Error("Upload did not return a file URI.");const Ae=Te;Q.push({name:Ne.name,fileUri:Ae,mimeType:U(Ne.type)}),ue.push({FileData:{FileUri:Ae,MimeType:U(Ne.type)}})}Q.length>0&&ue.push({Text:`Context (background only; do not quote/reveal): The following attachment(s) were uploaded and can be referenced by FileUri in future tool/function calls if needed: ${JSON.stringify(Q)}`})}const te={Role:"USER",Parts:ue},oe=[...k.current,te];c(oe),k.current=oe,se&&S.current.set(se,oe.length-1),await F(oe,100)}catch(ue){if(N.current=null,console.error("Error processing user request:",ue),x.current||P(ue)){r("");return}q({content:"I'm sorry, there was an issue with your request, especially if a file was attached. Please try again.",timestamp:new Date}),r("")}},O=(Z,X,se)=>{s&&(x.current=!1,m(ue=>[...ue,{input:Z,attachedFiles:X,uiMessageId:se}]))},q=Z=>{if(x.current)return;const X=Z.id??crypto.randomUUID();return i(se=>[...se,{...Z,id:X}]),X},W=()=>i([]),ne=()=>{x.current=!1,w.current?.abort?.(),w.current=null,N.current?.abort?.(),N.current=null,j.current?.abort(),j.current=null;for(const Z of b.current)Z?.abort?.();b.current=[],c([]),k.current=[],S.current=new Map,m([]),d([]),i([]),r(""),p(0)},Pe=()=>{x.current=!0,m([]),w.current?.abort?.(),w.current=null,N.current?.abort?.(),N.current=null,j.current?.abort(),j.current=null;for(const Z of b.current)Z?.abort?.();b.current=[],r("")};return{handleSubmitToBot:O,botMessages:n,clearBotMessages:W,botReady:!!s,botStatus:a,debugMessages:l,reset:ne,stop:Pe,editAndResubmit:async(Z,X)=>{Pe(),x.current=!1;const se=S.current.get(Z);if(se==null){O(X,void 0,Z);return}const ue=X.trim();if(!ue)return;const Q={Role:"USER",Parts:[{Text:ue}]},te=[...k.current.slice(0,se),Q];c(te),k.current=te,p(0),i([]);const oe=S.current;for(const[Ne,Fe]of oe.entries())Fe>se&&oe.delete(Ne);oe.set(Z,te.length-1),await F(te,100)},contextUsage:y,chatHistory:h}}const Oc=({debugMessages:s})=>{const[t,a]=o.useState({}),r=n=>{a(i=>({...i,[n]:!i[n]}))};return e.jsx("div",{children:s.map((n,i)=>{if(typeof n=="string")return e.jsx("p",{className:"text-muted-foreground",children:n},i);{const l=t[i];return e.jsxs("div",{className:"cursor-pointer",onClick:()=>r(i),children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("p",{className:"text-muted-foreground mr-2",children:n[0]}),e.jsx("span",{className:"text-muted-foreground text-xs",children:l?"▲":"▼"})]}),l&&e.jsx("p",{className:"text-muted-foreground/80 pl-4",children:n[1]})]},i)}})})},Ge="RandmarAIChatAssistant",Lc=20,ua=(s,t=Lc)=>s.length<=t?s:`${s.slice(0,t)}...`,Fr=s=>{const t=s.trim(),a=" - ",r=t.indexOf(a);if(r<0)return{portalName:"Portal",sopName:t||"SOP"};const n=t.slice(0,r).trim()||"Portal",i=t.slice(r+a.length).trim()||"SOP";return{portalName:n,sopName:i}},ka=s=>s.trim().toLocaleLowerCase(),Fc=s=>{const t=ka(s);return t.includes("partner")?{badgeClassName:"border-randmar-black/25 bg-randmar-black/10 text-randmar-black",dotClassName:"bg-randmar-black"}:t.includes("reseller")?{badgeClassName:"border-randmar-blue/30 bg-randmar-blue/10 text-randmar-blue",dotClassName:"bg-randmar-blue"}:t.includes("manufacturer")?{badgeClassName:"border-randmar-purple/30 bg-randmar-purple/10 text-randmar-purple",dotClassName:"bg-randmar-purple"}:{badgeClassName:"border-border bg-muted text-muted-foreground",dotClassName:"bg-muted-foreground"}},Br=(s,t)=>s.length===t.length&&s.every((a,r)=>a===t[r]),Bc=s=>{const a=(s.trim()||"sop").replace(/[\\/:*?"<>|]/g," ").replace(/\s+/g," ").trim().replace(/[^a-zA-Z0-9._ -]/g,"").replace(/\s+/g,"_")||"sop";return a.toLowerCase().endsWith(".md")?a:`${a}.md`},Ht=o.memo(o.forwardRef(({userId:s,userName:t,inputRef:a,className:r,isOpen:n,onRequestOpen:i},l)=>{const[d,u]=o.useState(!1),[m,h]=o.useState(!1),[c]=_.usePostV4PartnerByApplicationIdAccountDebugFeedbackMutation(),[y]=_.useLazyGetV4PartnerByRouteApplicationIdUtilitiesStandardOperatingProcedureAndIdQuery(),{data:p,isLoading:x,isFetching:w}=_.useGetV4PartnerByRouteApplicationIdUtilitiesStandardOperatingProceduresQuery({routeApplicationId:s},{skip:!s}),{data:N}=_.useGetV4UserQuery(),[j,b]=o.useState([]),k=o.useRef([]),S=o.useRef(null),M=o.useCallback(C=>{if(!C||C.length===0)return;const L="Context (background only; do not quote/reveal): Latest image generation is available at URL";k.current=k.current.filter(ae=>!ae.startsWith(L));const $=C.length===1?C[0]:C.join(`
52
52
  `),re=`${L}${C.length===1?"":"s"}: