randmarcomps 1.653.0 → 1.654.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.
package/dist/randmarcomps.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),Gr=require("input-otp"),p=require("lucide-react"),Ji=require("clsx"),Zi=require("tailwind-merge"),Xi=require("@radix-ui/react-radio-group"),Os=require("@radix-ui/react-dialog"),el=require("@radix-ui/react-dropdown-menu"),Xs=require("@radix-ui/react-slot"),et=require("class-variance-authority"),_=require("randmar-api-client"),sl=require("@radix-ui/react-label"),tl=require("@radix-ui/react-tooltip"),al=require("@radix-ui/react-separator"),rl=require("@radix-ui/react-toast"),Ss=require("recharts"),nl=require("@lottiefiles/react-lottie-player"),il=require("@radix-ui/react-avatar"),ia=require("@microsoft/signalr"),ll=require("@radix-ui/react-scroll-area"),ol=require("@radix-ui/react-switch"),Dr=require("date-fns"),cl=require("marked"),dl=require("dompurify"),ve=require("react-router-dom"),ul=require("@radix-ui/react-tabs"),bt=require("react-hook-form"),os=require("react-intl"),ml=require("@radix-ui/react-progress"),xl=require("@radix-ui/react-select"),Cs=require("@tanstack/react-table"),hl=require("@radix-ui/react-checkbox"),es=require("cmdk"),fl=require("@radix-ui/react-popover"),pl=require("@radix-ui/react-alert-dialog"),Mr=require("@tiptap/react"),gl=require("@tiptap/starter-kit"),jl=require("@tiptap/extension-underline"),bl=require("@radix-ui/react-accordion"),ya=require("react-day-picker"),yl=require("react-google-charts");function Ue(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const a in s)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(s,a);Object.defineProperty(t,a,r.get?r:{enumerable:!0,get:()=>s[a]})}}return t.default=s,Object.freeze(t)}const R=Ue(o),jt=Ue(Xi),we=Ue(Os),Ae=Ue(el),Nl=Ue(sl),Gs=Ue(tl),Wr=Ue(al),as=Ue(rl),st=Ue(il),Ls=Ue(ll),Na=Ue(ol),_s=Ue(ul),va=Ue(ml),Oe=Ue(xl),wa=Ue(hl),Ws=Ue(fl),Ke=Ue(pl),Fs=Ue(bl);function v(...s){return Zi.twMerge(Ji.clsx(s))}const ls=(s,t)=>new Intl.NumberFormat("en-CA",t).format(s),ce=(s,t)=>{const a={style:"currency",currency:"CAD",minimumFractionDigits:2,maximumFractionDigits:2,...t};return new Intl.NumberFormat("en-CA",a).format(s)},Ks=s=>{if(s===null||typeof s>"u")return"—";const t=s.toString();if(t.length===8){const a=t.substring(0,4),r=t.substring(4,6),n=t.substring(6,8);return`${a}-${r}-${n}`}return t};function vl({className:s,containerClassName:t,...a}){return e.jsx(Gr.OTPInput,{"data-slot":"input-otp",containerClassName:v("flex items-center gap-2 has-disabled:opacity-50",t),className:v("disabled:cursor-not-allowed",s),...a})}function wl({className:s,...t}){return e.jsx("div",{"data-slot":"input-otp-group",className:v("flex items-center",s),...t})}function Sl({index:s,className:t,...a}){const r=R.useContext(Gr.OTPInputContext),{char:n,hasFakeCaret:i,isActive:l}=r?.slots[s]??{};return e.jsxs("div",{"data-slot":"input-otp-slot","data-active":l,className:v("border-input data-[active=true]:border-ring data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:ring-destructive/20 aria-invalid:border-destructive data-[active=true]:aria-invalid:border-destructive relative flex h-9 w-9 items-center justify-center border-y border-r text-sm shadow-xs transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md data-[active=true]:z-10 data-[active=true]:ring-[3px]",t),...a,children:[n,i&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"animate-caret-blink bg-foreground h-4 w-px duration-1000"})})]})}function Cl({...s}){return e.jsx("div",{"data-slot":"input-otp-separator",role:"separator",...s,children:e.jsx(p.MinusIcon,{})})}const Hs=R.forwardRef(({className:s,...t},a)=>e.jsx(jt.Root,{className:v("grid gap-2",s),...t,ref:a}));Hs.displayName=jt.Root.displayName;const xs=R.forwardRef(({className:s,...t},a)=>e.jsx(jt.Item,{ref:a,className:v("aspect-square h-4 w-4 rounded-full border border-primary text-primary shadow-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s),...t,children:e.jsx(jt.Indicator,{className:"flex items-center justify-center",children:e.jsx(p.Circle,{className:"h-3.5 w-3.5 fill-primary"})})}));xs.displayName=jt.Item.displayName;const Ie=({modal:s=!1,...t})=>e.jsx(we.Root,{modal:s,...t});Ie.displayName=we.Root.displayName;const Ys=we.Trigger,Kr=we.Portal,Sa=we.Close,Da=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Overlay,{ref:a,className:v("fixed inset-0 z-50 bg-foreground/80 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]:opacity-0 data-[state=closed]:pointer-events-none",s),...t}));Da.displayName=we.Overlay.displayName;const De=R.forwardRef(({className:s,children:t,animateExit:a=!0,overlayClassName:r,showOverlay:n,onPointerDownOutside:i,onInteractOutside:l,...d},x)=>{const c=!!(r&&n);return e.jsxs(Kr,{forceMount:d.forceMount,children:[c?e.jsx(we.Close,{asChild:!0,children:e.jsx("div",{"aria-hidden":"true",className:v("fixed inset-0 z-[10000] pointer-events-auto",r)})}):null,e.jsx(Da,{className:r,forceMount:d.forceMount}),e.jsxs(we.Content,{ref:x,className:v("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-2xl shadow-primary duration-200 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",a&&"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%]",s),onPointerDownOutside:u=>{c&&u.preventDefault(),i?.(u)},onInteractOutside:u=>{c&&u.preventDefault(),l?.(u)},...d,children:[t,e.jsxs(we.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(p.X,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});De.displayName=we.Content.displayName;const Le=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-1.5 text-center sm:text-left",s),...t});Le.displayName="DialogHeader";const ze=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});ze.displayName="DialogFooter";const $e=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Title,{ref:a,className:v("text-lg font-semibold leading-none tracking-tight",s),...t}));$e.displayName=we.Title.displayName;const _e=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Description,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));_e.displayName=we.Description.displayName;const Yr=Ae.Root,Jr=Ae.Trigger,kl=Ae.Group,Rl=Ae.Portal,Pl=Ae.Sub,Al=Ae.RadioGroup,Zr=R.forwardRef(({className:s,inset:t,children:a,...r},n)=>e.jsxs(Ae.SubTrigger,{ref:n,className:v("flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t&&"pl-8",s),...r,children:[a,e.jsx(p.ChevronRight,{className:"ml-auto"})]}));Zr.displayName=Ae.SubTrigger.displayName;const Xr=R.forwardRef(({className:s,...t},a)=>e.jsx(Ae.SubContent,{ref:a,className:v("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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-dropdown-menu-content-transform-origin]",s),...t}));Xr.displayName=Ae.SubContent.displayName;const Ma=R.forwardRef(({className:s,sideOffset:t=4,...a},r)=>e.jsx(Ae.Portal,{children:e.jsx(Ae.Content,{ref:r,sideOffset:t,className:v("z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 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-dropdown-menu-content-transform-origin]",s),...a})}));Ma.displayName=Ae.Content.displayName;const ft=R.forwardRef(({className:s,inset:t,...a},r)=>e.jsx(Ae.Item,{ref:r,className:v("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",s),...a}));ft.displayName=Ae.Item.displayName;const en=R.forwardRef(({className:s,children:t,checked:a,...r},n)=>e.jsxs(Ae.CheckboxItem,{ref:n,className:v("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:a,...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Ae.ItemIndicator,{children:e.jsx(p.Check,{className:"h-4 w-4"})})}),t]}));en.displayName=Ae.CheckboxItem.displayName;const sn=R.forwardRef(({className:s,children:t,...a},r)=>e.jsxs(Ae.RadioItem,{ref:r,className:v("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Ae.ItemIndicator,{children:e.jsx(p.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));sn.displayName=Ae.RadioItem.displayName;const tn=R.forwardRef(({className:s,inset:t,...a},r)=>e.jsx(Ae.Label,{ref:r,className:v("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",s),...a}));tn.displayName=Ae.Label.displayName;const an=R.forwardRef(({className:s,...t},a)=>e.jsx(Ae.Separator,{ref:a,className:v("-mx-1 my-1 h-px bg-muted",s),...t}));an.displayName=Ae.Separator.displayName;const rn=({className:s,...t})=>e.jsx("span",{className:v("ml-auto text-xs tracking-widest opacity-60",s),...t});rn.displayName="DropdownMenuShortcut";const Bs=et.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 cursor-pointer",{variants:{variant:{default:"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-xs hover:bg-destructive/90",outline:"border border-input text-foreground bg-background shadow-xs hover:bg-accent hover:text-accent-foreground",defaultOutline:"border border-destructive/30 text-destructive bg-background shadow-xs hover:bg-destructive/5 ",secondary:"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline",blue:"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90",red:"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90",purple:"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90",none:""},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),D=R.forwardRef(({className:s,variant:t,size:a,asChild:r=!1,confirmationDialog:n,onClick:i,...l},d)=>{const x=r?Xs.Slot:"button";if(!n)return e.jsx(x,{className:v(Bs({variant:t,size:a,className:s})),ref:d,onClick:i,...l});i&&console.warn("Button: You provided both onClick and confirmationDialog props. The onClick prop will be ignored. Use the onConfirm callback in confirmationDialog instead.");const{title:c,content:u,onConfirm:m,confirmText:f="Confirm",cancelText:g="Cancel"}=n,b=()=>{m()};return e.jsxs(Ie,{children:[e.jsx(Ys,{asChild:!0,children:e.jsx(x,{className:v(Bs({variant:t,size:a,className:s})),ref:d,...l})}),e.jsxs(De,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:c}),e.jsx(_e,{children:u})]}),e.jsxs(ze,{className:"flex justify-end gap-2 pt-4",children:[e.jsx(Sa,{asChild:!0,children:e.jsx(D,{variant:"outline",children:g})}),e.jsx(Sa,{asChild:!0,children:e.jsx(D,{onClick:b,children:f})})]})]})]})});D.displayName="Button";function J({className:s,...t}){return e.jsx(Nl.Root,{"data-slot":"label",className:v("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",s),...t})}const ye=Gs.Provider,ge=Gs.Root,je=Gs.Trigger,pe=R.forwardRef(({className:s,sideOffset:t=4,...a},r)=>e.jsx(Gs.Portal,{children:e.jsx(Gs.Content,{ref:r,sideOffset:t,className:v("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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",s),...a})}));pe.displayName=Gs.Content.displayName;const ie=R.forwardRef(({className:s,type:t,mask:a,onChange:r,placeholder:n,...i},l)=>{const[d,x]=R.useState(!1),c=R.useRef(null),m=n||(a==="phone"?"(999) 999-9999":a==="postal-code-ca"?"A9A 9A9":a==="zip-code-us"?"99999":""),f=()=>a==="phone"?"Only enter numbers. Formatting will be added automatically.":a==="postal-code-ca"?"Enter letters and numbers only. Spacing will be applied automatically.":a==="zip-code-us"?"Only enter numbers. Formatting will be added automatically.":"",g=()=>{x(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{x(!1)},3e3)};R.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const b=w=>{if(a){const N=w.target.value;let j=N;if(N.length>0){const y=N[N.length-1];/[^a-zA-Z0-9]/.test(y)&&(console.log("Non-alphanumeric detected:",y),g())}if(a==="phone"){const y=N.replace(/\D/g,"");y.length<=3?j=y:y.length<=6?j=`(${y.slice(0,3)}) ${y.slice(3)}`:j=`(${y.slice(0,3)}) ${y.slice(3,6)}-${y.slice(6,10)}`}else if(a==="postal-code-ca"){const y=N.replace(/[^a-zA-Z0-9]/g,"").toUpperCase();let k="";for(let S=0;S<Math.min(y.length,6);S++){const M=y[S];S===0||S===2||S===4?/[A-Z]/.test(M)&&(k+=M):(S===1||S===3||S===5)&&/[0-9]/.test(M)&&(k+=M)}k.length<=3?j=k:j=`${k.slice(0,3)} ${k.slice(3,6)}`}else if(a==="zip-code-us"){const y=N.replace(/\D/g,"");y.length<=5?j=y:j=`${y.slice(0,5)}-${y.slice(5,9)}`}w.target.value=j}r?.(w)};return e.jsx(ye,{children:e.jsxs(ge,{open:d&&!!a,children:[e.jsx(je,{asChild:!0,children:e.jsx("input",{type:t,className:v("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground 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 md:text-sm",s),onChange:b,placeholder:m,ref:l,...i})}),e.jsx(pe,{side:"top",className:"bg-sidebar text-sidebar-foreground",children:f()})]})})});ie.displayName="Input";function nn(s){const{data:t,refetch:a,isFetching:r,isLoading:n}=_.useGetV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQuery({routeManufacturerId:s.userId,resellerId:s.partnerId,withSpecification:!1}),[i,l]=o.useState(!1),[d,x]=o.useState(!1),[c,u]=o.useState(!1),[m,f]=o.useState(!1),g=!t||n||r,b=t?.Qualifications?.some(w=>w.ManufacturerId===s.userId&&w.QualificationId!="Suspended"&&w.QualificationId!="Do Not Sell")??!1;return o.useEffect(()=>{if(d){f(!0);return}m&&(a(),f(!1))},[d,a,m]),e.jsxs(e.Fragment,{children:[e.jsxs(Yr,{modal:!1,children:[e.jsx(Jr,{asChild:!0,children:e.jsx(D,{disabled:g,children:"Actions"})}),e.jsxs(Ma,{className:v("",s.className),children:[e.jsx(ft,{onClick:()=>setTimeout(()=>l(!0),200),children:"Sales Report"}),e.jsx(ft,{onClick:()=>setTimeout(()=>x(!0),200),children:"Qualification Status"}),e.jsx(ft,{disabled:!b,onClick:()=>setTimeout(()=>u(!0),200),children:"Add to Opportunity"})]})]}),e.jsx(Il,{open:i,onOpenChange:l,manufacturerId:s.userId,resellerId:s.partnerId}),e.jsx(Dl,{isAdmin:s.isAdmin,open:d,onOpenChange:x,manufacturerId:s.userId,resellerId:s.partnerId}),e.jsx(Ml,{open:c,onOpenChange:u,manufacturerId:s.userId,resellerId:s.partnerId})]})}function Il(s){const[t,a]=o.useState(""),[r,n]=o.useState(null),[i,l]=o.useState(null),{toast:d}=Ce(),[x,{isLoading:c}]=_.usePostV4ManufacturerByRouteManufacturerIdReportSalesAndResellerIdEmailMutation(),u=async()=>{if(!c)try{await x({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,emailAddress:t,startDate:r,endDate:i}).unwrap(),d({title:"Report Requested",description:"The sales report will be emailed within five minutes.",variant:"success"}),s.onOpenChange(!1)}catch{d({title:"Error",description:"There was an error generating the sales report.",variant:"destructive"})}};return e.jsx(e.Fragment,{children:e.jsx(Ie,{open:s.open,onOpenChange:s.onOpenChange,children:e.jsxs(De,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Generate Sales Report"}),e.jsx(_e,{children:"The report will be sent via email within the next five minutes."})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid w-full items-center gap-1.5",children:[e.jsx(J,{htmlFor:"email",children:"Email"}),e.jsx(ie,{type:"email",id:"email",value:t,onChange:m=>a(m.target.value),autoFocus:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid w-full items-center gap-1.5",children:[e.jsx(J,{htmlFor:"dateStart",children:"Start Date"}),e.jsx(ie,{type:"date",id:"dateStart",value:r||"",onChange:m=>n(m.target.value)})]}),e.jsxs("div",{className:"grid w-full items-center gap-1.5",children:[e.jsx(J,{htmlFor:"dateEnd",children:"End Date"}),e.jsx(ie,{type:"date",id:"dateEnd",value:i||"",onChange:m=>l(m.target.value)})]})]})]}),e.jsxs(ze,{children:[e.jsx(Os.DialogClose,{asChild:!0,children:e.jsx(D,{variant:"outline",children:"Cancel"})}),e.jsx(D,{onClick:u,disabled:c,children:"Generate Report"})]})]})})})}function Dl(s){const{toast:t}=Ce(),[a,{isLoading:r}]=_.usePutV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQualificationMutation(),[n,{isLoading:i}]=_.useDeleteV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQualificationMutation(),[l,d]=o.useState("undefined"),[x,c]=o.useState("Qualified"),{data:u,isLoading:m}=_.useGetV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQuery({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,withSpecification:!1});o.useEffect(()=>{if(!u||m)return;const g=u?.Qualifications?.find(b=>b.ManufacturerId===s.manufacturerId);switch(g?.QualificationId){case"Do Not Sell":d("do-not-sell");break;case"Suspended":s.isAdmin?d("do-not-sell"):d("suspended");break;case void 0:case null:d("undefined");break;default:d("qualified"),c(g?.QualificationId||"Qualified");break}},[u,m,s.manufacturerId]);const f=async()=>{if(!(r||i||m))try{let g=!1;if(l==="qualified")g=await a({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,newValue:x===""?"Qualified":x}).unwrap();else if(l==="do-not-sell")g=await a({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,newValue:"Do Not Sell"}).unwrap();else if(l==="suspended")g=await a({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,newValue:"Suspended"}).unwrap();else if(l==="undefined")g=await n({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId}).unwrap();else throw new Error("Invalid status");if(!g)throw new Error("Failed to update qualification status");t({title:"Qualification Updated",description:"The qualification status has been successfully updated.",variant:"success"}),s.onOpenChange(!1)}catch{t({title:"Error",description:"There was an error updating the qualification status.",variant:"destructive"})}};return e.jsx(e.Fragment,{children:e.jsx(Ie,{open:s.open,onOpenChange:s.onOpenChange,children:e.jsxs(De,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Change qualification status"}),e.jsx(_e,{children:"Allow or restrict the sale of your products to this partner."})]}),e.jsxs(Hs,{value:l,onValueChange:d,className:"grid gap-4",disabled:r||i||m,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xs,{value:"undefined",id:"r1"}),e.jsx(J,{htmlFor:"r1",children:"No Status Chosen Yet"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xs,{value:"qualified",id:"r2"}),e.jsx(J,{htmlFor:"r2",children:"Qualified"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xs,{value:"do-not-sell",id:"r3"}),e.jsx(J,{htmlFor:"r3",children:"Do Not Sell"})]}),s.isAdmin&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xs,{value:"suspended",id:"r4"}),e.jsx(J,{htmlFor:"r4",children:"Suspended"})]})]}),e.jsx(J,{className:"mt-4",htmlFor:"qualificationId",children:"Qualification ID"}),e.jsx(ie,{disabled:l!=="qualified",id:"qualificationId",value:x,onChange:g=>c(g.target.value)}),e.jsxs(ze,{children:[e.jsx(Os.DialogClose,{asChild:!0,children:e.jsx(D,{variant:"outline",disabled:r||i,children:"Cancel"})}),e.jsx(D,{onClick:f,disabled:r||i||m,children:"Save"})]})]})})})}function Ml(s){const{toast:t}=Ce(),{data:a,isLoading:r}=_.useGetV4ManufacturerByRouteManufacturerIdOpportunitiesQuery({routeManufacturerId:s.manufacturerId}),n=Array.isArray(a)?a:[],[i,{isLoading:l}]=_.usePutV4ManufacturerByRouteManufacturerIdOpportunityAndBidNumberResellerResellerIdMutation(),[d,x]=o.useState(""),c=async()=>{if(!(l||r))try{if(!await i({routeManufacturerId:s.manufacturerId,bidNumber:d,resellerId:s.resellerId}).unwrap())throw new Error("Failed to add reseller to opportunity");t({title:"Reseller Added",description:"The reseller has been successfully added to the opportunity.",variant:"success"}),s.onOpenChange(!1)}catch{t({title:"Error",description:"There was an error adding the reseller to the opportunity.",variant:"destructive"})}};return e.jsx(e.Fragment,{children:e.jsx(Ie,{open:s.open,onOpenChange:s.onOpenChange,children:e.jsxs(De,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Add to Opportunity"}),e.jsx(_e,{children:"Let a reseller benefit from an opportunity."})]}),e.jsxs(ks,{value:d,onValueChange:x,children:[e.jsx(ps,{children:e.jsx(Rs,{placeholder:"Select an opportunity"})}),e.jsx(gs,{children:n.map(u=>e.jsxs(Xe,{value:u.BidNumber||"",children:[e.jsx("b",{children:u.BidNumber})," | ",u.Opportunity]},"Opportunity"+u.BidNumber))})]}),e.jsxs(ze,{children:[e.jsx(Os.DialogClose,{asChild:!0,children:e.jsx(D,{variant:"outline",disabled:l,children:"Cancel"})}),e.jsx(D,{onClick:c,disabled:l||r,children:"Confirm"})]})]})})})}function Ta({inventory:s,showBinLocation:t,className:a}){const r=(y,k,S=!1,M=!0)=>{const P=y.WarehouseType==="Fulfillment Center",A=P?"bg-background":"bg-background/70 text-muted-foreground",T=M&&k>0?"border-t":"",E=S?"border-r":"",I=y.Status??"Unknown",F=I==="Active";let $="bg-secondary text-secondary-foreground ring-1 ring-border";switch(y.WarehouseType){case"Fulfillment Center":$="bg-randmar-black text-primary-foreground ring-1 ring-randmar-black/40";break;case"Last Mile":$="bg-randmar-blue text-primary-foreground ring-1 ring-randmar-blue/40";break;case"First Mile":$="bg-randmar-purple text-primary-foreground ring-1 ring-randmar-purple/40";break}switch(I){case"Opening":$="bg-success text-success-foreground ring-1 ring-success/40";break;case"Closing":$="bg-warning text-warning-foreground ring-1 ring-warning/40";break;case"Closed":$="bg-destructive text-destructive-foreground ring-1 ring-destructive/40";break}return e.jsxs("article",{"aria-labelledby":`wh-${y.WarehouseId}-name`,className:`p-3 text-sm ${T} ${E} ${A}`,children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{id:`wh-${y.WarehouseId}-name`,className:"text-sm font-medium text-foreground",children:y.Name}),e.jsxs("span",{className:`inline-flex items-center gap-2 rounded-full px-2 py-0.5 text-xs font-semibold ${$}`,"aria-hidden":"false",title:F?P?"Fulfillment Center":"Satellite Warehouse":`Status: ${I}`,children:[P?e.jsx(p.Warehouse,{className:"h-3 w-3","aria-hidden":"true"}):e.jsx(p.Truck,{className:`h-3 w-3 ${F?"opacity-80":"opacity-95"}`,"aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:F?y.WarehouseType?`${y.WarehouseType} warehouse`:"Warehouse":`Status: ${I}`}),e.jsx("span",{"aria-hidden":"true",children:F?y.WarehouseType||(P?"Fulfillment Center":"Satellite"):I})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("div",{className:"text-sm font-medium",children:ls(y.AvailableQuantity??0)})})]}),e.jsxs("div",{className:"flex justify-between mt-1 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Expecting"}),e.jsx("span",{children:y.PurchaseOrderQuantity?ls(y.PurchaseOrderQuantity):"—"})]}),t&&e.jsxs("div",{className:"flex justify-between mt-1 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Bin Location"}),e.jsx("span",{children:y.BinLocation||"—"})]})]},`warehouse-${y.WarehouseId}`)},n=["Z0FP4Z","TOR","MTL"],i=["VAN","EDM"],l=[...s].sort((y,k)=>(y.Name||"").localeCompare(k.Name||"")),d=l.filter(y=>y.Country==="US"),x=l.filter(y=>y.Country==="CA"),c=l.filter(y=>i.includes(y.WarehouseId||"")),u=l.filter(y=>n.includes(y.WarehouseId||"")),m=x.filter(y=>!n.includes(y.WarehouseId||"")&&!i.includes(y.WarehouseId||"")),f=y=>y.reduce((k,S)=>k+(S.AvailableQuantity||0),0),g=f(x),b=f(u),w=f(c),N=f(d),j=g+N;return e.jsxs("div",{className:`border rounded-md overflow-hidden ${a??""}`,children:[x.length>0&&d.length>0&&e.jsxs("div",{className:"grid grid-cols-2 border-b",children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"Total"}),e.jsx("span",{children:j})]}),e.jsx("div",{className:"p-3"})]}),x.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 border-b bg-muted/30",children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"Canada"}),e.jsx("span",{children:ls(g)})]}),e.jsx("div",{className:"p-3"})]}),e.jsxs("div",{className:"grid grid-cols-2",children:[e.jsxs("div",{className:"border-r",children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"West"}),e.jsx("span",{children:ls(w)})]}),c.map((y,k)=>r(y,k))]}),e.jsxs("div",{children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"East"}),e.jsx("span",{children:ls(b)})]}),u.map((y,k)=>r(y,k))]})]}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t p-3 font-semibold text-sm",children:e.jsx("span",{children:"Other"})}),e.jsx("div",{className:"grid grid-cols-2",children:m.map((y,k)=>r(y,k,k%2===0,!0))})]})]}),d.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 border-t bg-muted/30",children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"United States"}),e.jsx("span",{children:ls(N)})]}),e.jsx("div",{className:"p-3"})]}),e.jsx("div",{className:"grid grid-cols-2",children:d.map((y,k)=>r(y,k,k%2===0,!0))})]}),s.length===0&&e.jsx("div",{className:"p-6 text-center text-muted-foreground",children:"No inventory information available"})]})}const yt=R.forwardRef(({className:s,orientation:t="horizontal",decorative:a=!0,...r},n)=>e.jsx(Wr.Root,{ref:n,decorative:a,orientation:t,className:v("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...r}));yt.displayName=Wr.Root.displayName;const ln=we.Root,Tl=we.Trigger,El=we.Close,on=we.Portal,Ea=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Overlay,{className:v("fixed inset-0 z-50 bg-foreground/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...t,ref:a}));Ea.displayName=we.Overlay.displayName;const Ol=et.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Oa=R.forwardRef(({side:s="right",className:t,children:a,...r},n)=>e.jsxs(on,{children:[e.jsx(Ea,{}),e.jsxs(we.Content,{ref:n,className:v(Ol({side:s}),t),...r,children:[e.jsxs(we.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[e.jsx(p.X,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),a]})]}));Oa.displayName=we.Content.displayName;const cn=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-2 text-center sm:text-left",s),...t});cn.displayName="SheetHeader";const dn=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});dn.displayName="SheetFooter";const un=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Title,{ref:a,className:v("text-lg font-semibold text-foreground",s),...t}));un.displayName=we.Title.displayName;const mn=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Description,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));mn.displayName=we.Description.displayName;function zt({elementRef:s,threshold:t=0,rootMargin:a="0px",freezeOnceVisible:r=!1}){const[n,i]=o.useState(!1);return o.useEffect(()=>{const l=s.current;if(!l){i(!1);return}const d=new IntersectionObserver(([x])=>{const c=x.isIntersecting;r&&c?(i(!0),d.unobserve(l)):i(c)},{threshold:t,rootMargin:a});return d.observe(l),()=>{d.unobserve(l)}},[s,t,a,r]),n}const us=({id:s,name:t,width:a=64,height:r=64,align:n="",className:i})=>{const l=o.useRef(null),d=zt({elementRef:l,threshold:.1,rootMargin:"100px",freezeOnceVisible:!0}),{data:x,isFetching:c,isSuccess:u}=_.useGetV4PartnerByApplicationIdAccountLogoExistsQuery({applicationId:s??""},{skip:!s||!d}),{data:m,isFetching:f}=_.useGetV4PartnerByApplicationIdAccountLogoQuery({applicationId:s??"",width:a,height:r,align:n},{skip:!u||x!=!0}),g=t||(s?`Partner ID: ${s}`:"Logo not available (no ID)"),b=()=>!d||c||f?e.jsx(h,{className:"h-full w-full rounded-sm"}):m?e.jsx("img",{src:m,alt:g,className:"h-full w-full object-contain rounded-sm"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center rounded-sm bg-muted/20 p-1",title:g,children:e.jsx(p.Handshake,{className:"text-primary fill-background min-h-full"})});return e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx("div",{className:v("flex h-full w-full cursor-default",i),ref:l,children:b()})}),e.jsx(pe,{side:"top",align:"center",children:g})]})})};function Ll({onClick:s,publicName:t,applicationName:a,partnerId:r}){return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-muted "+(s!==void 0?"cursor-pointer":""),children:e.jsx(D,{asChild:!0,size:"icon",onClick:s,children:e.jsx("div",{className:"h-9 w-9 object-cover !bg-sidebar",children:e.jsx(us,{id:r,width:64,height:64})})})}),e.jsxs("div",{className:"flex flex-1 flex-col",children:[e.jsx("span",{className:"text-sm font-medium",children:t||"Partner"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a})]})]})}const la=1024;function xn(){const[s,t]=R.useState(void 0);return R.useEffect(()=>{const a=window.matchMedia(`(max-width: ${la-1}px)`),r=()=>{t(window.innerWidth<la)};return a.addEventListener("change",r),t(window.innerWidth<la),()=>a.removeEventListener("change",r)},[]),!!s}const hn=R.createContext(null);function tt(){const s=R.useContext(hn);if(!s)throw new Error("useSidebar must be used within a SidebarProvider.");return s}function h({className:s,...t}){return e.jsx("div",{className:v("animate-pulse rounded-md bg-primary/20",s),...t})}const Fl="sidebar:state",Bl=3600*24*7,$l="16rem",_l="3rem",Vl="b",La=R.forwardRef(({defaultOpen:s=!0,defaultOpenMobile:t=!1,isMobileOverride:a,open:r,onOpenChange:n,className:i,style:l,children:d,...x},c)=>{const u=xn(),m=a??u,[f,g]=R.useState(t),[b,w]=R.useState(s),N=r??b,j=R.useCallback(M=>{const P=typeof M=="function"?M(N):M;n?n(P):w(P),document.cookie=`${Fl}=${P}; path=/; max-age=${Bl}`},[n,N]),y=R.useCallback(()=>m?g(M=>!M):j(M=>!M),[m,j,g]);R.useEffect(()=>{const M=P=>{P.key===Vl&&(P.metaKey||P.ctrlKey)&&(P.preventDefault(),y())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[y]);const k=N?"expanded":"collapsed",S=R.useMemo(()=>({state:k,open:N,setOpen:j,isMobile:m,openMobile:f,setOpenMobile:g,toggleSidebar:y}),[k,N,j,m,f,g,y]);return e.jsx(hn.Provider,{value:S,children:e.jsx(ye,{delayDuration:0,children:e.jsx("div",{style:{"--sidebar-width":$l,"--sidebar-width-icon":_l,...l},className:v("group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",i),ref:c,...x,children:d})})})});La.displayName="SidebarProvider";const Fa=R.forwardRef(({side:s="left",variant:t="sidebar",collapsible:a="offcanvas",className:r,children:n,...i},l)=>{const{isMobile:d,state:x,openMobile:c,setOpenMobile:u}=tt();return a==="none"?e.jsx("div",{className:v("flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",r),ref:l,...i,children:n}):d?e.jsx(ln,{open:c,onOpenChange:u,...i,children:e.jsx(Oa,{"data-sidebar":"sidebar","data-mobile":"true",className:v("inset-0 h-svh w-screen max-w-none border-0 bg-sidebar p-0 text-sidebar-foreground sm:max-w-none","[&>button]:right-4 [&>button]:top-4 [&>button]:h-11 [&>button]:w-11 [&>button]:rounded-md [&>button]:opacity-100","[&>button]:text-sidebar-foreground [&>button]:ring-offset-sidebar [&>button]:hover:bg-sidebar-accent [&>button]:hover:text-sidebar-accent-foreground [&>button]:focus-visible:ring-sidebar-ring",r),side:s,children:e.jsx("div",{className:"flex h-full w-full flex-col",children:n})})}):e.jsxs("div",{ref:l,className:"group peer hidden md:block text-sidebar-foreground","data-state":x,"data-collapsible":x==="collapsed"?a:"","data-variant":t,"data-side":s,children:[e.jsx("div",{className:v("duration-200 relative h-svh w-(--sidebar-width) bg-transparent transition-[width] ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon)")}),e.jsx("div",{className:v("duration-200 fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] ease-linear md:flex",s==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",r),...i,children:e.jsx("div",{"data-sidebar":"sidebar",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm",children:n})})]})});Fa.displayName="Sidebar";const Ba=R.forwardRef(({className:s,onClick:t,...a},r)=>{const{toggleSidebar:n}=tt();return e.jsxs(D,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:v("h-7 w-7 text-sidebar-foreground",s),onClick:i=>{t?.(i),n()},...a,children:[e.jsx(p.PanelLeft,{}),e.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});Ba.displayName="SidebarTrigger";const fn=R.forwardRef(({className:s,...t},a)=>{const{toggleSidebar:r}=tt();return e.jsx("button",{ref:a,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:v("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex","in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",s),...t})});fn.displayName="SidebarRail";const pn=R.forwardRef(({className:s,...t},a)=>e.jsx("main",{ref:a,className:v("relative flex min-h-svh flex-1 flex-col bg-background","peer-data-[variant=inset]:min-h-[calc(100svh-(--spacing(4)))] md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm",s),...t}));pn.displayName="SidebarInset";const gn=R.forwardRef(({className:s,...t},a)=>e.jsx(ie,{ref:a,"data-sidebar":"input",className:v("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",s),...t}));gn.displayName="SidebarInput";const $a=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"header",className:v("flex flex-col gap-2 p-2",s),...t}));$a.displayName="SidebarHeader";const _a=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"footer",className:v("flex flex-col gap-2 p-2",s),...t}));_a.displayName="SidebarFooter";const jn=R.forwardRef(({className:s,...t},a)=>e.jsx(yt,{ref:a,"data-sidebar":"separator",className:v("mx-2 w-auto bg-sidebar-border",s),...t}));jn.displayName="SidebarSeparator";const Va=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"content",className:v("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",s),...t}));Va.displayName="SidebarContent";const bn=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"group",className:v("relative flex w-full min-w-0 flex-col p-2",s),...t}));bn.displayName="SidebarGroup";const yn=R.forwardRef(({className:s,asChild:t=!1,...a},r)=>{const n=t?Xs.Slot:"div";return e.jsx(n,{ref:r,"data-sidebar":"group-label",className:v("duration-200 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-hidden ring-sidebar-ring transition-[margin,opa] ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",s),...a})});yn.displayName="SidebarGroupLabel";const Nn=R.forwardRef(({className:s,asChild:t=!1,...a},r)=>{const n=t?Xs.Slot:"button";return e.jsx(n,{ref:r,"data-sidebar":"group-action",className:v("absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 md:after:hidden","group-data-[collapsible=icon]:hidden",s),...a})});Nn.displayName="SidebarGroupAction";const vn=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"group-content",className:v("w-full text-sm",s),...t}));vn.displayName="SidebarGroupContent";const za=R.forwardRef(({className:s,...t},a)=>e.jsx("ul",{ref:a,"data-sidebar":"menu",className:v("flex w-full min-w-0 flex-col gap-1",s),...t}));za.displayName="SidebarMenu";const Ua=R.forwardRef(({className:s,...t},a)=>e.jsx("li",{ref:a,"data-sidebar":"menu-item",className:v("group/menu-item relative",s),...t}));Ua.displayName="SidebarMenuItem";const zl=et.cva("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:p-0!"}},defaultVariants:{variant:"default",size:"default"}}),qa=R.forwardRef(({asChild:s=!1,isActive:t=!1,variant:a="default",size:r="default",tooltip:n,className:i,...l},d)=>{const x=s?Xs.Slot:"button",{isMobile:c,state:u}=tt(),m=e.jsx(x,{ref:d,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:v(zl({variant:a,size:r}),i),...l});return n?(typeof n=="string"&&(n={children:n}),e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:m}),e.jsx(pe,{side:"right",align:"center",hidden:u!=="collapsed"||c,...n})]})):m});qa.displayName="SidebarMenuButton";const wn=R.forwardRef(({className:s,asChild:t=!1,showOnHover:a=!1,...r},n)=>{const i=t?Xs.Slot:"button";return e.jsx(i,{ref:n,"data-sidebar":"menu-action",className:v("absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 md:after:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",a&&"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",s),...r})});wn.displayName="SidebarMenuAction";const Sn=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"menu-badge",className:v("absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground select-none pointer-events-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",s),...t}));Sn.displayName="SidebarMenuBadge";const Cn=R.forwardRef(({className:s,showIcon:t=!1,...a},r)=>{const n=R.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return e.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:v("rounded-md h-8 flex gap-2 px-2 items-center",s),...a,children:[t&&e.jsx(h,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),e.jsx(h,{className:"h-4 flex-1 max-w-(--skeleton-width)","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":n}})]})});Cn.displayName="SidebarMenuSkeleton";const kn=R.forwardRef(({className:s,...t},a)=>e.jsx("ul",{ref:a,"data-sidebar":"menu-sub",className:v("mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",s),...t}));kn.displayName="SidebarMenuSub";const Rn=R.forwardRef(({...s},t)=>e.jsx("li",{ref:t,...s}));Rn.displayName="SidebarMenuSubItem";const Pn=R.forwardRef(({asChild:s=!1,size:t="md",isActive:a,className:r,...n},i)=>{const l=s?Xs.Slot:"a";return e.jsx(l,{ref:i,"data-sidebar":"menu-sub-button","data-size":t,"data-active":a,className:v("flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-hidden ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",r),...n})});Pn.displayName="SidebarMenuSubButton";const An=as.Provider,Qa=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Viewport,{ref:a,className:v("fixed top-0 z-[11000] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",s),...t}));Qa.displayName=as.Viewport.displayName;const Ul=et.cva("group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full sm:data-[state=open]:slide-in-from-bottom-full",{variants:{variant:{default:"border bg-background text-foreground",destructive:"destructive group border-destructive bg-destructive text-destructive-foreground",success:"border-success bg-success text-success-foreground",warning:"border-warning bg-warning text-warning-foreground",info:"border-info bg-info text-info-foreground",secondary:"border-secondary bg-secondary text-secondary-foreground",outline:"border-input bg-background text-foreground hover:bg-accent hover:text-accent-foreground"}},defaultVariants:{variant:"default"}}),Ha=R.forwardRef(({className:s,variant:t,...a},r)=>e.jsx(as.Root,{ref:r,className:v(Ul({variant:t}),s),...a}));Ha.displayName=as.Root.displayName;const Ga=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Action,{ref:a,className:v("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 hover:group-[.destructive]:border-destructive/30 hover:group-[.destructive]:bg-destructive hover:group-[.destructive]:text-destructive-foreground",s),...t}));Ga.displayName=as.Action.displayName;const Wa=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Close,{ref:a,className:v("absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 group-hover:opacity-100 group-[.destructive]:text-destructive-foreground/70 hover:group-[.destructive]:text-destructive-foreground",s),"toast-close":"",...t,children:e.jsx(p.X,{className:"h-4 w-4"})}));Wa.displayName=as.Close.displayName;const Ka=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Title,{ref:a,className:v("text-sm font-semibold [&+div]:text-xs",s),...t}));Ka.displayName=as.Title.displayName;const Ya=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Description,{ref:a,className:v("text-sm opacity-90",s),...t}));Ya.displayName=as.Description.displayName;const ql=1,Ql=1e6;let oa=0;function Hl(){return oa=(oa+1)%Number.MAX_SAFE_INTEGER,oa.toString()}const ca=new Map,Tr=s=>{if(ca.has(s))return;const t=setTimeout(()=>{ca.delete(s),pt({type:"REMOVE_TOAST",toastId:s})},Ql);ca.set(s,t)},Gl=(s,t)=>{switch(t.type){case"ADD_TOAST":return{...s,toasts:[t.toast,...s.toasts].slice(0,ql)};case"UPDATE_TOAST":return{...s,toasts:s.toasts.map(a=>a.id===t.toast.id?{...a,...t.toast}:a)};case"DISMISS_TOAST":{const{toastId:a}=t;return a?Tr(a):s.toasts.forEach(r=>Tr(r.id)),{...s,toasts:s.toasts.map(r=>r.id===a||a===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return{...s,toasts:t.toastId?s.toasts.filter(a=>a.id!==t.toastId):[]}}},Tt=[];let Et={toasts:[]};function pt(s){Et=Gl(Et,s),Tt.forEach(t=>t(Et))}function In({...s}){const t=Hl(),a=n=>pt({type:"UPDATE_TOAST",toast:{...n,id:t}}),r=()=>pt({type:"DISMISS_TOAST",toastId:t});return pt({type:"ADD_TOAST",toast:{...s,id:t,open:!0,onOpenChange:n=>{n||r()}}}),{id:t,dismiss:r,update:a}}function Ce(){const[s,t]=R.useState(Et);return R.useEffect(()=>(Tt.push(t),()=>{const a=Tt.indexOf(t);a>-1&&Tt.splice(a,1)}),[]),{...s,toast:In,dismiss:a=>pt({type:"DISMISS_TOAST",toastId:a})}}function Dn(){const{toasts:s}=Ce();return e.jsxs(An,{children:[s.map(function({id:t,title:a,description:r,action:n,...i}){return e.jsxs(Ha,{...i,children:[e.jsxs("div",{className:"grid gap-1",children:[a&&e.jsx(Ka,{children:a}),r&&e.jsx(Ya,{children:r})]}),n,e.jsx(Wa,{})]},t)}),e.jsx(Qa,{})]})}const Ja=o.createContext(void 0),Wl=({children:s})=>{const t=o.useRef(null),a=(l,d,x)=>t.current?(t.current.sendMessageToAssistant(l??null,d??null,x??null),!0):!1,r=(l,d,x)=>t.current?(t.current.sendMessageToAssistantWithClear(l??null,d??null,x??null),!0):!1,[n,i]=o.useState(!1);return e.jsx(Ja.Provider,{value:{sendMessage:a,sendMessageWithClear:r,chatRef:t,hasUnreads:n,setHasUnreads:i},children:s})},Js=()=>{const s=o.useContext(Ja);if(s===void 0)throw new Error("useChat must be used within a ChatProvider");return s},Mn=()=>o.useContext(Ja),Kl=[{value:"az",label:"A–Z"},{value:"recent",label:"Recently added"},{value:"sales30Desc",label:"Sales last 30 days: High to low"},{value:"sales30Asc",label:"Sales last 30 days: Low to high"}];function Tn(s){return s.trim().toLocaleLowerCase()}function Ca(s){return(s??"").split(/[;,|]/g).map(t=>t.trim()).filter(Boolean)}function Dt(s){return s.PublicName??s.Name??""}function Yl(s){return Ca(s.Tags).map(Tn)}function Jl(s){const t=s.Opportunities;if(Array.isArray(t)){const a=new Date;a.setHours(0,0,0,0);const r=n=>{if(typeof n=="number"&&Number.isFinite(n)){const i=Math.trunc(n);if(i>1e7){const l=String(i).padStart(8,"0"),d=Number(l.slice(0,4)),x=Number(l.slice(4,6)),c=Number(l.slice(6,8));if(d>=1900&&x>=1&&x<=12&&c>=1&&c<=31)return new Date(d,x-1,c)}}if(typeof n=="string"){const i=new Date(n);if(!Number.isNaN(i.getTime()))return i}return null};return t.some(n=>{if(!(n?.Active===!0||n?.IsActive===!0||n?.State==="Active"))return!1;const l=n?.EndDate??n?.End??n?.ExpiryDate??n?.ExpiresOn,d=r(l);return d?(d.setHours(0,0,0,0),d>=a):!0})}return(s.NumberOfOpportunities??0)>0}function Zl({appID:s,manufPath:t,withBot:a}){const[r,n]=o.useState(!1),{data:i,isLoading:l}=_.useGetV4PartnerByRouteApplicationIdManufacturersQuery({routeApplicationId:s??"",withSpecification:!1});o.useEffect(()=>{n(!1)},[s]),o.useEffect(()=>{!r&&!l&&n(!0)},[l,r]);const{data:d}=_.useGetV4PartnerByRouteApplicationIdManufacturersQuery({routeApplicationId:s??"",withSpecification:!0},{skip:!r}),x=o.useMemo(()=>(d??i)?.slice()??[],[i,d]),[c,u]=o.useState(""),[m,f]=o.useState([]),[g,b]=o.useState("az"),[w,N]=o.useState(!1),[j,y]=o.useState(!1),k=o.useMemo(()=>{const E=new Map;for(const I of x)for(const F of Ca(I.Tags)){const $=Tn(F);E.has($)||E.set($,F)}return Array.from(E.entries()).map(([I,F])=>({key:I,label:F})).sort((I,F)=>I.label.localeCompare(F.label,void 0,{sensitivity:"base"}))},[x]),S=c.trim().length>0||m.length>0||g!=="az"||w||j,M=o.useCallback(()=>{u(""),f([]),b("az"),N(!1),y(!1)},[]),{sendMessage:P}=Js(),A=o.useCallback(E=>{const I=E?.trim().length>0?E.trim():"this manufacturer";P(`Search for ${I} and tell me more about this manufacturer.`)},[P]),T=o.useMemo(()=>{const E=c.trim().toLocaleLowerCase(),I=new Set(m),$=x.filter(V=>{if(w&&!V.OpenToWork||j&&!Jl(V))return!1;const z=Yl(V);if(I.size>0&&!z.some(O=>I.has(O)))return!1;if(E.length>0){const O=Dt(V).toLocaleLowerCase(),H=Ca(V.Tags).map(de=>de.toLocaleLowerCase());if(!(O.includes(E)||H.some(de=>de.includes(E))))return!1}return!0}).slice();return $.sort((V,z)=>g==="az"?Dt(V).localeCompare(Dt(z),void 0,{sensitivity:"base"}):g==="recent"?(z.CreationDate??0)-(V.CreationDate??0):g==="sales30Desc"?(z.SalesData?.SalesLast30Days??0)-(V.SalesData?.SalesLast30Days??0):(V.SalesData?.SalesLast30Days??0)-(z.SalesData?.SalesLast30Days??0)),$},[x,j,w,c,m,g]);return e.jsxs("div",{className:"w-full space-y-6 p-4 sm:p-6",children:[e.jsx(U,{children:e.jsxs(G,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"manufacturer-search",children:"Search manufacturers"}),e.jsx(ie,{id:"manufacturer-search",value:c,onChange:E=>u(E.target.value),placeholder:"Search by name, or category"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{id:"manufacturer-categories-label",className:"text-sm font-medium leading-none",children:"Categories"}),S&&e.jsx(D,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2",onClick:M,children:"Clear filters"})]}),e.jsx("div",{role:"group","aria-labelledby":"manufacturer-categories-label","aria-describedby":"manufacturer-categories-help",className:"flex flex-wrap gap-2",children:k.length===0?e.jsx("span",{className:"text-sm text-muted-foreground",children:"No categories available."}):k.map(({key:E,label:I})=>{const F=m.includes(E);return e.jsx(D,{type:"button",variant:F?"secondary":"outline",className:"rounded-full","aria-pressed":F,onClick:()=>{f($=>$.includes(E)?$.filter(V=>V!==E):[...$,E])},children:I},E)})}),e.jsx("p",{id:"manufacturer-categories-help",className:"text-xs text-muted-foreground",children:"Tap to include or remove categories"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{id:"manufacturer-sort-label",className:"text-sm font-medium leading-none",children:"Sort by"}),e.jsxs(ks,{value:g,onValueChange:E=>b(E),children:[e.jsx(ps,{"aria-labelledby":"manufacturer-sort-label",children:e.jsx(Rs,{placeholder:"A–Z"})}),e.jsx(gs,{children:Kl.map(E=>e.jsx(Xe,{value:E.value,children:E.label},E.value))})]})]})]}),e.jsx("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs("label",{htmlFor:"only-open-to-work",className:"flex items-center gap-2 rounded-md border px-3 py-2 text-sm cursor-pointer select-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",children:[e.jsx(Ps,{id:"only-open-to-work",checked:w,onCheckedChange:E=>N(E===!0)}),e.jsx("span",{children:"Open to work"})]}),e.jsxs("label",{htmlFor:"only-active-opportunities",className:"flex items-center gap-2 rounded-md border px-3 py-2 text-sm cursor-pointer select-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",children:[e.jsx(Ps,{id:"only-active-opportunities",checked:j,onCheckedChange:E=>y(E===!0)}),e.jsx("span",{children:"Active opportunities"})]})]})})]})}),e.jsxs("div",{className:"@container space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",T.length," of ",x.length," manufacturers"]}),l&&x.length===0?e.jsx("div",{className:"grid grid-cols-1 @md:grid-cols-1 @lg:grid-cols-2 @xl:grid-cols-3 gap-4",children:Array.from({length:9}).map((E,I)=>e.jsx(Zs,{loading:!0},I))}):T.length>0?e.jsx("div",{className:"grid grid-cols-1 @md:grid-cols-1 @lg:grid-cols-2 @xl:grid-cols-3 gap-4",children:T.map((E,I)=>{const F=Dt(E);return e.jsx(Zs,{appID:s,manufacturer:E,linkNewTab:!1,link:t(E.ManufacturerId||""),actions:a?e.jsx(D,{type:"button",variant:"outline",size:"icon","aria-label":`Assistant: ${F||"manufacturer"}`,onClick:()=>A(F),children:e.jsx(p.Bot,{})}):void 0,mainAction:e.jsx(or,{applicationId:s,manufacturer:E})},E.ManufacturerId??`${F}-${I}`)})}):e.jsx(U,{children:e.jsxs(G,{className:"p-8 text-center space-y-3",children:[e.jsx("p",{className:"text-muted-foreground",children:"No manufacturers match your current filters."}),e.jsx(D,{type:"button",variant:"outline",onClick:M,disabled:!S,children:"Reset filters"})]})})]})]})}const En="https://api.randmar.io",Xl="/swagger/V4/swagger.json",On=`${En}${Xl}`,Ln=o.createContext({swaggerJsonUrl:On});function eo({swaggerJsonUrl:s,children:t}){const a=o.useMemo(()=>({swaggerJsonUrl:s??On}),[s]);return e.jsx(Ln.Provider,{value:a,children:t})}function Fn(){return o.useContext(Ln)}function so({active:s,payload:t,label:a,series:r}){if(s&&t?.length){const n=new Map(r.map(i=>[i.name,i]));return e.jsxs("div",{className:"rounded-lg border bg-background p-2 text-sm shadow-sm",children:[e.jsx("div",{className:"mb-1 font-medium",children:a}),e.jsx("div",{className:"space-y-1",children:t.map(i=>{if(typeof i.dataKey!="string"||i.value===null||i.value===void 0)return null;const l=n.get(i.dataKey);if(!l)return null;const d=l.format==="money"&&typeof i.value=="number"?ce(i.value):l.format==="integer"&&typeof i.value=="number"?ls(i.value,{maximumFractionDigits:2}):l.unitsPosition==="left"?`${l.units||""}${i.value}`:`${i.value}${l.units?` ${l.units}`:""}`;return e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:v("mr-2 h-2.5 w-2.5 rounded-full",l.dotClassName??"bg-foreground")}),e.jsx("span",{className:"text-muted-foreground",children:l.label||i.name})]}),e.jsx("span",{className:"font-medium",children:d})]},i.dataKey)})})]})}return null}function Bn({data:s,series:t,height:a,className:r,size:n="default"}){if(!s?.length||!t?.length)return e.jsx("div",{className:v("flex items-center justify-center text-muted-foreground",r),style:n==="default"?{height:a}:{},children:"No data available"});const i=Object.keys(s[0])[0],l=n==="mini",d=t.filter(m=>m.yAxisId==="left"||!m.yAxisId),x=t.filter(m=>m.yAxisId==="right"),c=m=>{const f=d[0];return f?.format==="money"?ce(m,{minimumFractionDigits:0,maximumFractionDigits:0}):f?.units?f.unitsPosition==="left"?`${f.units}${m}`:`${m}${f.units}`:String(m)},u=m=>{const f=x[0];return f?.format==="money"?ce(m,{minimumFractionDigits:0,maximumFractionDigits:0}):f?.units?f.unitsPosition==="left"?`${f.units}${m}`:`${m}${f.units}`:String(m)};return e.jsx("div",{className:v("w-full",r),style:{height:a?`${a}px`:"100%"},children:e.jsx(Ss.ResponsiveContainer,{width:"100%",height:"100%",children:e.jsxs(Ss.AreaChart,{data:s,margin:l?{top:0,right:0,left:0,bottom:0}:{top:10,right:30,left:0,bottom:0},children:[e.jsx("defs",{children:t.map(m=>e.jsxs("linearGradient",{id:`gradient-${m.name}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:m.color,stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:m.color,stopOpacity:.1})]},m.name))}),!l&&e.jsx(Ss.CartesianGrid,{strokeDasharray:"3 3",className:"stroke-border/50"}),!l&&e.jsx(Ss.XAxis,{dataKey:i,className:"text-xs text-muted-foreground",tickLine:!1,axisLine:!1}),!l&&d.length>0&&e.jsx(Ss.YAxis,{yAxisId:"left",className:"text-xs text-muted-foreground",tickLine:!1,axisLine:!1,tickFormatter:c}),!l&&x.length>0&&e.jsx(Ss.YAxis,{yAxisId:"right",orientation:"right",className:"text-xs text-muted-foreground",tickLine:!1,axisLine:!1,tickFormatter:u}),!l&&e.jsx(Ss.Tooltip,{content:e.jsx(so,{series:t}),cursor:{stroke:"var(--muted)",strokeWidth:1}}),t.map(m=>e.jsx(Ss.Area,{yAxisId:m.yAxisId||"left",type:"monotone",dataKey:m.name,stroke:m.color,fillOpacity:.6,fill:`url(#gradient-${m.name})`,strokeWidth:l?1:2},m.name))]})})})}const to="5.12.1",ao=59.9400024414062,ro=0,no=660.000026882351,io=1080,lo=1080,oo="Comp 1",co=0,uo=[{id:"comp_0",nm:"randmar pulse",fr:59.9400024414062,layers:[{ddd:0,ind:1,ty:4,nm:"Shape Layer 3",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:21,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:42,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:52,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:107,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:134,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:163,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:223,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:250,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:279,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:339,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:366,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:395,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:455,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:482,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:511,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:571,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:598,s:[105,105,100]},{t:627.000025538234,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ind:0,ty:"sh",ix:1,ks:{a:0,k:{i:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],o:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],v:[[149.125,-150.875],[-152.875,-150.875],[-152.875,151.125],[-92,151.125],[-92,-90],[149.125,-90]],c:!0},ix:2},nm:"Path 1",mn:"ADBE Vector Shape - Group",hd:!1},{ty:"fl",c:{a:0,k:[.172549019608,.172549019608,.172549019608,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[0,0],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Shape 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:21.0000008553475,op:660.000026882351,st:21.0000008553475,ct:1,bm:0},{ddd:0,ind:2,ty:4,nm:"Shape Layer 2",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:10,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:31,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:41,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:96,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:123,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:152,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:212,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:239,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:268,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:328,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:355,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:384,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:444,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:471,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:500,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:560,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:587,s:[105,105,100]},{t:616.000025090194,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ind:0,ty:"sh",ix:1,ks:{a:0,k:{i:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],o:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],v:[[148,-29.5],[-32,-29.5],[-31.75,150.5],[27.5,150.5],[28,30.5],[148.5,30.5]],c:!0},ix:2},nm:"Path 1",mn:"ADBE Vector Shape - Group",hd:!1},{ty:"fl",c:{a:0,k:[.172549019608,.172549019608,.172549019608,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[0,0],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Shape 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:10.0000004073083,op:660.000026882351,st:10.0000004073083,ct:1,bm:0},{ddd:0,ind:3,ty:4,nm:"Shape Layer 1",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:4,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:25,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:35,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:90,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:117,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:146,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:206,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:233,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:262,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:322,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:349,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:378,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:438,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:465,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:494,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:554,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:581,s:[105,105,100]},{t:610.000024845809,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ty:"rc",d:1,s:{a:0,k:[60,60],ix:2},p:{a:0,k:[0,0],ix:3},r:{a:0,k:0,ix:4},nm:"Rectangle Path 1",mn:"ADBE Vector Shape - Rect",hd:!1},{ty:"fl",c:{a:0,k:[.172549019608,.172549019608,.172549019608,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[117.75,119.75],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Rectangle 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:0,op:660.000026882351,st:0,ct:1,bm:0}]}],mo=[{ddd:0,ind:1,ty:0,nm:"randmar pulse",refId:"comp_0",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[540,540,0],ix:2,l:2},a:{a:0,k:[960,540,0],ix:1,l:2},s:{a:0,k:[308,308,100],ix:6,l:2}},ao:0,ef:[{ty:5,nm:"Hue/Saturation",np:11,mn:"ADBE HUE SATURATION",ix:1,en:1,ef:[{ty:7,nm:"Channel Control",mn:"ADBE HUE SATURATION-0002",ix:1,v:{a:0,k:1,ix:1}},{},{ty:0,nm:"Master Hue",mn:"ADBE HUE SATURATION-0004",ix:3,v:{a:0,k:0,ix:3}},{ty:0,nm:"Master Saturation",mn:"ADBE HUE SATURATION-0005",ix:4,v:{a:0,k:0,ix:4}},{ty:0,nm:"Master Lightness",mn:"ADBE HUE SATURATION-0006",ix:5,v:{a:0,k:0,ix:5}},{ty:7,nm:"Colorize",mn:"ADBE HUE SATURATION-0007",ix:6,v:{a:0,k:0,ix:6}},{ty:0,nm:"Colorize Hue",mn:"ADBE HUE SATURATION-0008",ix:7,v:{a:0,k:0,ix:7}},{ty:0,nm:"Colorize Saturation",mn:"ADBE HUE SATURATION-0009",ix:8,v:{a:0,k:25,ix:8}},{ty:0,nm:"Colorize Lightness",mn:"ADBE HUE SATURATION-0010",ix:9,v:{a:0,k:0,ix:9}}]}],w:1920,h:1080,ip:0,op:660.000026882351,st:0,bm:0}],xo=[],ho={},Er={v:to,fr:ao,ip:ro,op:no,w:io,h:lo,nm:oo,ddd:co,assets:uo,layers:mo,markers:xo,props:ho},fo="5.12.1",po=59.9400024414062,go=0,jo=660.000026882351,bo=1080,yo=1080,No="Comp 1",vo=0,wo=[{id:"comp_0",nm:"randmar pulse",fr:59.9400024414062,layers:[{ddd:0,ind:1,ty:4,nm:"Shape Layer 3",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:21,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:42,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:52,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:107,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:134,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:163,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:223,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:250,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:279,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:339,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:366,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:395,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:455,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:482,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:511,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:571,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:598,s:[105,105,100]},{t:627.000025538234,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ind:0,ty:"sh",ix:1,ks:{a:0,k:{i:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],o:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],v:[[149.125,-150.875],[-152.875,-150.875],[-152.875,151.125],[-92,151.125],[-92,-90],[149.125,-90]],c:!0},ix:2},nm:"Path 1",mn:"ADBE Vector Shape - Group",hd:!1},{ty:"fl",c:{a:0,k:[1,1,1,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[0,0],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Shape 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:21.0000008553475,op:660.000026882351,st:21.0000008553475,ct:1,bm:0},{ddd:0,ind:2,ty:4,nm:"Shape Layer 2",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:10,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:31,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:41,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:96,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:123,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:152,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:212,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:239,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:268,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:328,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:355,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:384,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:444,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:471,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:500,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:560,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:587,s:[105,105,100]},{t:616.000025090194,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ind:0,ty:"sh",ix:1,ks:{a:0,k:{i:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],o:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],v:[[148,-29.5],[-32,-29.5],[-31.75,150.5],[27.5,150.5],[28,30.5],[148.5,30.5]],c:!0},ix:2},nm:"Path 1",mn:"ADBE Vector Shape - Group",hd:!1},{ty:"fl",c:{a:0,k:[1,1,1,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[0,0],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Shape 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:10.0000004073083,op:660.000026882351,st:10.0000004073083,ct:1,bm:0},{ddd:0,ind:3,ty:4,nm:"Shape Layer 1",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:4,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:25,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:35,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:90,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:117,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:146,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:206,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:233,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:262,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:322,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:349,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:378,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:438,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:465,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:494,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:554,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:581,s:[105,105,100]},{t:610.000024845809,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ty:"rc",d:1,s:{a:0,k:[60,60],ix:2},p:{a:0,k:[0,0],ix:3},r:{a:0,k:0,ix:4},nm:"Rectangle Path 1",mn:"ADBE Vector Shape - Rect",hd:!1},{ty:"fl",c:{a:0,k:[1,1,1,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[117.75,119.75],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Rectangle 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:0,op:660.000026882351,st:0,ct:1,bm:0}]}],So=[{ddd:0,ind:1,ty:0,nm:"randmar pulse",refId:"comp_0",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[540,540,0],ix:2,l:2},a:{a:0,k:[960,540,0],ix:1,l:2},s:{a:0,k:[308,308,100],ix:6,l:2}},ao:0,ef:[{ty:5,nm:"Hue/Saturation",np:11,mn:"ADBE HUE SATURATION",ix:1,en:1,ef:[{ty:7,nm:"Channel Control",mn:"ADBE HUE SATURATION-0002",ix:1,v:{a:0,k:1,ix:1}},{},{ty:0,nm:"Master Hue",mn:"ADBE HUE SATURATION-0004",ix:3,v:{a:0,k:0,ix:3}},{ty:0,nm:"Master Saturation",mn:"ADBE HUE SATURATION-0005",ix:4,v:{a:0,k:0,ix:4}},{ty:0,nm:"Master Lightness",mn:"ADBE HUE SATURATION-0006",ix:5,v:{a:0,k:0,ix:5}},{ty:7,nm:"Colorize",mn:"ADBE HUE SATURATION-0007",ix:6,v:{a:0,k:0,ix:6}},{ty:0,nm:"Colorize Hue",mn:"ADBE HUE SATURATION-0008",ix:7,v:{a:0,k:0,ix:7}},{ty:0,nm:"Colorize Saturation",mn:"ADBE HUE SATURATION-0009",ix:8,v:{a:0,k:25,ix:8}},{ty:0,nm:"Colorize Lightness",mn:"ADBE HUE SATURATION-0010",ix:9,v:{a:0,k:0,ix:9}}]},{ty:5,nm:"Change to Color",np:13,mn:"ADBE Change To Color",ix:2,en:1,ef:[{ty:2,nm:"From",mn:"ADBE Change To Color-0001",ix:1,v:{a:0,k:[.72549021244,.184313729405,.184313729405,1],ix:1}},{ty:2,nm:"To",mn:"ADBE Change To Color-0002",ix:2,v:{a:0,k:[1,1,1,1],ix:2}},{ty:7,nm:"Change",mn:"ADBE Change To Color-0003",ix:3,v:{a:0,k:4,ix:3}},{ty:7,nm:"Change By",mn:"ADBE Change To Color-0004",ix:4,v:{a:0,k:1,ix:4}},{ty:6,nm:"Tolerance",mn:"ADBE Change To Color-0010",ix:5,v:0},{ty:0,nm:"Hue",mn:"ADBE Change To Color-0005",ix:6,v:{a:0,k:.1,ix:6}},{ty:0,nm:"Lightness",mn:"ADBE Change To Color-0006",ix:7,v:{a:0,k:1,ix:7}},{ty:0,nm:"Saturation",mn:"ADBE Change To Color-0007",ix:8,v:{a:0,k:1,ix:8}},{ty:6,nm:"Saturation",mn:"ADBE Change To Color-0011",ix:9,v:0},{ty:0,nm:"Softness",mn:"ADBE Change To Color-0008",ix:10,v:{a:0,k:.5,ix:10}},{ty:7,nm:"View Correction Matte",mn:"ADBE Change To Color-0009",ix:11,v:{a:0,k:0,ix:11}}]}],w:1920,h:1080,ip:0,op:660.000026882351,st:0,bm:0}],Co=[],ko={},Ro={v:fo,fr:po,ip:go,op:jo,w:bo,h:yo,nm:No,ddd:vo,assets:wo,layers:So,markers:Co,props:ko},Po=s=>{const{color:t}=s;return e.jsx("div",{className:"flex justify-center",children:e.jsx(nl.Player,{autoplay:!0,loop:!0,speed:1,style:{width:200,aspectRatio:"1 / 1"},src:t==="white"?Ro:Er})})};function Ao({text:s,color:t="white",className:a}){return e.jsxs("div",{className:v("h-screen w-screen flex items-center justify-center flex-col gap-6 z-50",a),children:[e.jsx(Po,{color:t}),s&&e.jsx("div",{className:v("text-center text-xl font-medium",t==="black"?"text-foreground":"text-primary-foreground"),children:s})]})}const Nt=R.forwardRef(({className:s,...t},a)=>e.jsx(st.Root,{ref:a,className:v("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...t}));Nt.displayName=st.Root.displayName;const $n=R.forwardRef(({className:s,...t},a)=>e.jsx(st.Image,{ref:a,className:v("aspect-square h-full w-full",s),...t}));$n.displayName=st.Image.displayName;const _n=R.forwardRef(({className:s,...t},a)=>e.jsx(st.Fallback,{ref:a,className:v("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...t}));_n.displayName=st.Fallback.displayName;const da=new Map,Mt=new Map;function Io(s,t){const a=s.trim();if(t==="text")return a;const r=/^```(?:\w+\n)?([\s\S]+)\n```$/,n=a.match(r);return n?n[1].trim():a}const Vn=async(s,t,a,r,n,i=3)=>{const x=`Analyze the following prompt and ${n==="html"?`Provide a helpful, concise response formatted in simple HTML.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),Gr=require("input-otp"),g=require("lucide-react"),Ji=require("clsx"),Zi=require("tailwind-merge"),Xi=require("@radix-ui/react-radio-group"),Os=require("@radix-ui/react-dialog"),el=require("@radix-ui/react-dropdown-menu"),Xs=require("@radix-ui/react-slot"),et=require("class-variance-authority"),_=require("randmar-api-client"),sl=require("@radix-ui/react-label"),tl=require("@radix-ui/react-tooltip"),al=require("@radix-ui/react-separator"),rl=require("@radix-ui/react-toast"),Ss=require("recharts"),nl=require("@lottiefiles/react-lottie-player"),il=require("@radix-ui/react-avatar"),ia=require("@microsoft/signalr"),ll=require("@radix-ui/react-scroll-area"),ol=require("@radix-ui/react-switch"),Dr=require("date-fns"),cl=require("marked"),dl=require("dompurify"),ve=require("react-router-dom"),ul=require("@radix-ui/react-tabs"),bt=require("react-hook-form"),os=require("react-intl"),ml=require("@radix-ui/react-progress"),xl=require("@radix-ui/react-select"),Cs=require("@tanstack/react-table"),hl=require("@radix-ui/react-checkbox"),es=require("cmdk"),fl=require("@radix-ui/react-popover"),pl=require("@radix-ui/react-alert-dialog"),Mr=require("@tiptap/react"),gl=require("@tiptap/starter-kit"),jl=require("@tiptap/extension-underline"),bl=require("@radix-ui/react-accordion"),ya=require("react-day-picker"),yl=require("react-google-charts");function Ue(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const a in s)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(s,a);Object.defineProperty(t,a,r.get?r:{enumerable:!0,get:()=>s[a]})}}return t.default=s,Object.freeze(t)}const R=Ue(o),jt=Ue(Xi),we=Ue(Os),Ie=Ue(el),Nl=Ue(sl),Gs=Ue(tl),Wr=Ue(al),as=Ue(rl),st=Ue(il),Ls=Ue(ll),Na=Ue(ol),_s=Ue(ul),va=Ue(ml),Oe=Ue(xl),wa=Ue(hl),Ws=Ue(fl),Ke=Ue(pl),Fs=Ue(bl);function v(...s){return Zi.twMerge(Ji.clsx(s))}const ls=(s,t)=>new Intl.NumberFormat("en-CA",t).format(s),de=(s,t)=>{const a={style:"currency",currency:"CAD",minimumFractionDigits:2,maximumFractionDigits:2,...t};return new Intl.NumberFormat("en-CA",a).format(s)},Ks=s=>{if(s===null||typeof s>"u")return"—";const t=s.toString();if(t.length===8){const a=t.substring(0,4),r=t.substring(4,6),n=t.substring(6,8);return`${a}-${r}-${n}`}return t};function vl({className:s,containerClassName:t,...a}){return e.jsx(Gr.OTPInput,{"data-slot":"input-otp",containerClassName:v("flex items-center gap-2 has-disabled:opacity-50",t),className:v("disabled:cursor-not-allowed",s),...a})}function wl({className:s,...t}){return e.jsx("div",{"data-slot":"input-otp-group",className:v("flex items-center",s),...t})}function Sl({index:s,className:t,...a}){const r=R.useContext(Gr.OTPInputContext),{char:n,hasFakeCaret:i,isActive:l}=r?.slots[s]??{};return e.jsxs("div",{"data-slot":"input-otp-slot","data-active":l,className:v("border-input data-[active=true]:border-ring data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:ring-destructive/20 aria-invalid:border-destructive data-[active=true]:aria-invalid:border-destructive relative flex h-9 w-9 items-center justify-center border-y border-r text-sm shadow-xs transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md data-[active=true]:z-10 data-[active=true]:ring-[3px]",t),...a,children:[n,i&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"animate-caret-blink bg-foreground h-4 w-px duration-1000"})})]})}function Cl({...s}){return e.jsx("div",{"data-slot":"input-otp-separator",role:"separator",...s,children:e.jsx(g.MinusIcon,{})})}const Hs=R.forwardRef(({className:s,...t},a)=>e.jsx(jt.Root,{className:v("grid gap-2",s),...t,ref:a}));Hs.displayName=jt.Root.displayName;const xs=R.forwardRef(({className:s,...t},a)=>e.jsx(jt.Item,{ref:a,className:v("aspect-square h-4 w-4 rounded-full border border-primary text-primary shadow-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s),...t,children:e.jsx(jt.Indicator,{className:"flex items-center justify-center",children:e.jsx(g.Circle,{className:"h-3.5 w-3.5 fill-primary"})})}));xs.displayName=jt.Item.displayName;const De=({modal:s=!1,...t})=>e.jsx(we.Root,{modal:s,...t});De.displayName=we.Root.displayName;const Ys=we.Trigger,Kr=we.Portal,Sa=we.Close,Da=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Overlay,{ref:a,className:v("fixed inset-0 z-50 bg-foreground/80 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]:opacity-0 data-[state=closed]:pointer-events-none",s),...t}));Da.displayName=we.Overlay.displayName;const Me=R.forwardRef(({className:s,children:t,animateExit:a=!0,overlayClassName:r,showOverlay:n,onPointerDownOutside:i,onInteractOutside:l,...d},u)=>{const m=!!(r&&n);return e.jsxs(Kr,{forceMount:d.forceMount,children:[m?e.jsx(we.Close,{asChild:!0,children:e.jsx("div",{"aria-hidden":"true",className:v("fixed inset-0 z-[10000] pointer-events-auto",r)})}):null,e.jsx(Da,{className:r,forceMount:d.forceMount}),e.jsxs(we.Content,{ref:u,className:v("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-2xl shadow-primary duration-200 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",a&&"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%]",s),onPointerDownOutside:h=>{m&&h.preventDefault(),i?.(h)},onInteractOutside:h=>{m&&h.preventDefault(),l?.(h)},...d,children:[t,e.jsxs(we.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(g.X,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});Me.displayName=we.Content.displayName;const Le=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-1.5 text-center sm:text-left",s),...t});Le.displayName="DialogHeader";const ze=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});ze.displayName="DialogFooter";const $e=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Title,{ref:a,className:v("text-lg font-semibold leading-none tracking-tight",s),...t}));$e.displayName=we.Title.displayName;const _e=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Description,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));_e.displayName=we.Description.displayName;const Yr=Ie.Root,Jr=Ie.Trigger,kl=Ie.Group,Rl=Ie.Portal,Pl=Ie.Sub,Al=Ie.RadioGroup,Zr=R.forwardRef(({className:s,inset:t,children:a,...r},n)=>e.jsxs(Ie.SubTrigger,{ref:n,className:v("flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t&&"pl-8",s),...r,children:[a,e.jsx(g.ChevronRight,{className:"ml-auto"})]}));Zr.displayName=Ie.SubTrigger.displayName;const Xr=R.forwardRef(({className:s,...t},a)=>e.jsx(Ie.SubContent,{ref:a,className:v("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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-dropdown-menu-content-transform-origin]",s),...t}));Xr.displayName=Ie.SubContent.displayName;const Ma=R.forwardRef(({className:s,sideOffset:t=4,...a},r)=>e.jsx(Ie.Portal,{children:e.jsx(Ie.Content,{ref:r,sideOffset:t,className:v("z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 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-dropdown-menu-content-transform-origin]",s),...a})}));Ma.displayName=Ie.Content.displayName;const ft=R.forwardRef(({className:s,inset:t,...a},r)=>e.jsx(Ie.Item,{ref:r,className:v("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",s),...a}));ft.displayName=Ie.Item.displayName;const en=R.forwardRef(({className:s,children:t,checked:a,...r},n)=>e.jsxs(Ie.CheckboxItem,{ref:n,className:v("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:a,...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Ie.ItemIndicator,{children:e.jsx(g.Check,{className:"h-4 w-4"})})}),t]}));en.displayName=Ie.CheckboxItem.displayName;const sn=R.forwardRef(({className:s,children:t,...a},r)=>e.jsxs(Ie.RadioItem,{ref:r,className:v("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Ie.ItemIndicator,{children:e.jsx(g.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));sn.displayName=Ie.RadioItem.displayName;const tn=R.forwardRef(({className:s,inset:t,...a},r)=>e.jsx(Ie.Label,{ref:r,className:v("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",s),...a}));tn.displayName=Ie.Label.displayName;const an=R.forwardRef(({className:s,...t},a)=>e.jsx(Ie.Separator,{ref:a,className:v("-mx-1 my-1 h-px bg-muted",s),...t}));an.displayName=Ie.Separator.displayName;const rn=({className:s,...t})=>e.jsx("span",{className:v("ml-auto text-xs tracking-widest opacity-60",s),...t});rn.displayName="DropdownMenuShortcut";const Bs=et.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 cursor-pointer",{variants:{variant:{default:"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-xs hover:bg-destructive/90",outline:"border border-input text-foreground bg-background shadow-xs hover:bg-accent hover:text-accent-foreground",defaultOutline:"border border-destructive/30 text-destructive bg-background shadow-xs hover:bg-destructive/5 ",secondary:"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline",blue:"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90",red:"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90",purple:"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90",none:""},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),D=R.forwardRef(({className:s,variant:t,size:a,asChild:r=!1,confirmationDialog:n,onClick:i,...l},d)=>{const u=r?Xs.Slot:"button";if(!n)return e.jsx(u,{className:v(Bs({variant:t,size:a,className:s})),ref:d,onClick:i,...l});i&&console.warn("Button: You provided both onClick and confirmationDialog props. The onClick prop will be ignored. Use the onConfirm callback in confirmationDialog instead.");const{title:m,content:h,onConfirm:c,confirmText:y="Confirm",cancelText:p="Cancel"}=n,x=()=>{c()};return e.jsxs(De,{children:[e.jsx(Ys,{asChild:!0,children:e.jsx(u,{className:v(Bs({variant:t,size:a,className:s})),ref:d,...l})}),e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:m}),e.jsx(_e,{children:h})]}),e.jsxs(ze,{className:"flex justify-end gap-2 pt-4",children:[e.jsx(Sa,{asChild:!0,children:e.jsx(D,{variant:"outline",children:p})}),e.jsx(Sa,{asChild:!0,children:e.jsx(D,{onClick:x,children:y})})]})]})]})});D.displayName="Button";function J({className:s,...t}){return e.jsx(Nl.Root,{"data-slot":"label",className:v("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",s),...t})}const ye=Gs.Provider,ge=Gs.Root,je=Gs.Trigger,pe=R.forwardRef(({className:s,sideOffset:t=4,...a},r)=>e.jsx(Gs.Portal,{children:e.jsx(Gs.Content,{ref:r,sideOffset:t,className:v("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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",s),...a})}));pe.displayName=Gs.Content.displayName;const le=R.forwardRef(({className:s,type:t,mask:a,onChange:r,placeholder:n,...i},l)=>{const[d,u]=R.useState(!1),m=R.useRef(null),c=n||(a==="phone"?"(999) 999-9999":a==="postal-code-ca"?"A9A 9A9":a==="zip-code-us"?"99999":""),y=()=>a==="phone"?"Only enter numbers. Formatting will be added automatically.":a==="postal-code-ca"?"Enter letters and numbers only. Spacing will be applied automatically.":a==="zip-code-us"?"Only enter numbers. Formatting will be added automatically.":"",p=()=>{u(!0),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{u(!1)},3e3)};R.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]);const x=w=>{if(a){const N=w.target.value;let j=N;if(N.length>0){const b=N[N.length-1];/[^a-zA-Z0-9]/.test(b)&&(console.log("Non-alphanumeric detected:",b),p())}if(a==="phone"){const b=N.replace(/\D/g,"");b.length<=3?j=b:b.length<=6?j=`(${b.slice(0,3)}) ${b.slice(3)}`:j=`(${b.slice(0,3)}) ${b.slice(3,6)}-${b.slice(6,10)}`}else if(a==="postal-code-ca"){const b=N.replace(/[^a-zA-Z0-9]/g,"").toUpperCase();let k="";for(let S=0;S<Math.min(b.length,6);S++){const M=b[S];S===0||S===2||S===4?/[A-Z]/.test(M)&&(k+=M):(S===1||S===3||S===5)&&/[0-9]/.test(M)&&(k+=M)}k.length<=3?j=k:j=`${k.slice(0,3)} ${k.slice(3,6)}`}else if(a==="zip-code-us"){const b=N.replace(/\D/g,"");b.length<=5?j=b:j=`${b.slice(0,5)}-${b.slice(5,9)}`}w.target.value=j}r?.(w)};return e.jsx(ye,{children:e.jsxs(ge,{open:d&&!!a,children:[e.jsx(je,{asChild:!0,children:e.jsx("input",{type:t,className:v("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground 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 md:text-sm",s),onChange:x,placeholder:c,ref:l,...i})}),e.jsx(pe,{side:"top",className:"bg-sidebar text-sidebar-foreground",children:y()})]})})});le.displayName="Input";function nn(s){const{data:t,refetch:a,isFetching:r,isLoading:n}=_.useGetV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQuery({routeManufacturerId:s.userId,resellerId:s.partnerId,withSpecification:!1}),[i,l]=o.useState(!1),[d,u]=o.useState(!1),[m,h]=o.useState(!1),[c,y]=o.useState(!1),p=!t||n||r,x=t?.Qualifications?.some(w=>w.ManufacturerId===s.userId&&w.QualificationId!="Suspended"&&w.QualificationId!="Do Not Sell")??!1;return o.useEffect(()=>{if(d){y(!0);return}c&&(a(),y(!1))},[d,a,c]),e.jsxs(e.Fragment,{children:[e.jsxs(Yr,{modal:!1,children:[e.jsx(Jr,{asChild:!0,children:e.jsx(D,{disabled:p,children:"Actions"})}),e.jsxs(Ma,{className:v("",s.className),children:[e.jsx(ft,{onClick:()=>setTimeout(()=>l(!0),200),children:"Sales Report"}),e.jsx(ft,{onClick:()=>setTimeout(()=>u(!0),200),children:"Qualification Status"}),e.jsx(ft,{disabled:!x,onClick:()=>setTimeout(()=>h(!0),200),children:"Add to Opportunity"})]})]}),e.jsx(Il,{open:i,onOpenChange:l,manufacturerId:s.userId,resellerId:s.partnerId}),e.jsx(Dl,{isAdmin:s.isAdmin,open:d,onOpenChange:u,manufacturerId:s.userId,resellerId:s.partnerId}),e.jsx(Ml,{open:m,onOpenChange:h,manufacturerId:s.userId,resellerId:s.partnerId})]})}function Il(s){const[t,a]=o.useState(""),[r,n]=o.useState(null),[i,l]=o.useState(null),{toast:d}=Ce(),[u,{isLoading:m}]=_.usePostV4ManufacturerByRouteManufacturerIdReportSalesAndResellerIdEmailMutation(),h=async()=>{if(!m)try{await u({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,emailAddress:t,startDate:r,endDate:i}).unwrap(),d({title:"Report Requested",description:"The sales report will be emailed within five minutes.",variant:"success"}),s.onOpenChange(!1)}catch{d({title:"Error",description:"There was an error generating the sales report.",variant:"destructive"})}};return e.jsx(e.Fragment,{children:e.jsx(De,{open:s.open,onOpenChange:s.onOpenChange,children:e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Generate Sales Report"}),e.jsx(_e,{children:"The report will be sent via email within the next five minutes."})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid w-full items-center gap-1.5",children:[e.jsx(J,{htmlFor:"email",children:"Email"}),e.jsx(le,{type:"email",id:"email",value:t,onChange:c=>a(c.target.value),autoFocus:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid w-full items-center gap-1.5",children:[e.jsx(J,{htmlFor:"dateStart",children:"Start Date"}),e.jsx(le,{type:"date",id:"dateStart",value:r||"",onChange:c=>n(c.target.value)})]}),e.jsxs("div",{className:"grid w-full items-center gap-1.5",children:[e.jsx(J,{htmlFor:"dateEnd",children:"End Date"}),e.jsx(le,{type:"date",id:"dateEnd",value:i||"",onChange:c=>l(c.target.value)})]})]})]}),e.jsxs(ze,{children:[e.jsx(Os.DialogClose,{asChild:!0,children:e.jsx(D,{variant:"outline",children:"Cancel"})}),e.jsx(D,{onClick:h,disabled:m,children:"Generate Report"})]})]})})})}function Dl(s){const{toast:t}=Ce(),[a,{isLoading:r}]=_.usePutV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQualificationMutation(),[n,{isLoading:i}]=_.useDeleteV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQualificationMutation(),[l,d]=o.useState("undefined"),[u,m]=o.useState("Qualified"),{data:h,isLoading:c}=_.useGetV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQuery({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,withSpecification:!1});o.useEffect(()=>{if(!h||c)return;const p=h?.Qualifications?.find(x=>x.ManufacturerId===s.manufacturerId);switch(p?.QualificationId){case"Do Not Sell":d("do-not-sell");break;case"Suspended":s.isAdmin?d("do-not-sell"):d("suspended");break;case void 0:case null:d("undefined");break;default:d("qualified"),m(p?.QualificationId||"Qualified");break}},[h,c,s.manufacturerId]);const y=async()=>{if(!(r||i||c))try{let p=!1;if(l==="qualified")p=await a({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,newValue:u===""?"Qualified":u}).unwrap();else if(l==="do-not-sell")p=await a({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,newValue:"Do Not Sell"}).unwrap();else if(l==="suspended")p=await a({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,newValue:"Suspended"}).unwrap();else if(l==="undefined")p=await n({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId}).unwrap();else throw new Error("Invalid status");if(!p)throw new Error("Failed to update qualification status");t({title:"Qualification Updated",description:"The qualification status has been successfully updated.",variant:"success"}),s.onOpenChange(!1)}catch{t({title:"Error",description:"There was an error updating the qualification status.",variant:"destructive"})}};return e.jsx(e.Fragment,{children:e.jsx(De,{open:s.open,onOpenChange:s.onOpenChange,children:e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Change qualification status"}),e.jsx(_e,{children:"Allow or restrict the sale of your products to this partner."})]}),e.jsxs(Hs,{value:l,onValueChange:d,className:"grid gap-4",disabled:r||i||c,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xs,{value:"undefined",id:"r1"}),e.jsx(J,{htmlFor:"r1",children:"No Status Chosen Yet"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xs,{value:"qualified",id:"r2"}),e.jsx(J,{htmlFor:"r2",children:"Qualified"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xs,{value:"do-not-sell",id:"r3"}),e.jsx(J,{htmlFor:"r3",children:"Do Not Sell"})]}),s.isAdmin&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(xs,{value:"suspended",id:"r4"}),e.jsx(J,{htmlFor:"r4",children:"Suspended"})]})]}),e.jsx(J,{className:"mt-4",htmlFor:"qualificationId",children:"Qualification ID"}),e.jsx(le,{disabled:l!=="qualified",id:"qualificationId",value:u,onChange:p=>m(p.target.value)}),e.jsxs(ze,{children:[e.jsx(Os.DialogClose,{asChild:!0,children:e.jsx(D,{variant:"outline",disabled:r||i,children:"Cancel"})}),e.jsx(D,{onClick:y,disabled:r||i||c,children:"Save"})]})]})})})}function Ml(s){const{toast:t}=Ce(),{data:a,isLoading:r}=_.useGetV4ManufacturerByRouteManufacturerIdOpportunitiesQuery({routeManufacturerId:s.manufacturerId}),n=Array.isArray(a)?a:[],[i,{isLoading:l}]=_.usePutV4ManufacturerByRouteManufacturerIdOpportunityAndBidNumberResellerResellerIdMutation(),[d,u]=o.useState(""),m=async()=>{if(!(l||r))try{if(!await i({routeManufacturerId:s.manufacturerId,bidNumber:d,resellerId:s.resellerId}).unwrap())throw new Error("Failed to add reseller to opportunity");t({title:"Reseller Added",description:"The reseller has been successfully added to the opportunity.",variant:"success"}),s.onOpenChange(!1)}catch{t({title:"Error",description:"There was an error adding the reseller to the opportunity.",variant:"destructive"})}};return e.jsx(e.Fragment,{children:e.jsx(De,{open:s.open,onOpenChange:s.onOpenChange,children:e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Add to Opportunity"}),e.jsx(_e,{children:"Let a reseller benefit from an opportunity."})]}),e.jsxs(ks,{value:d,onValueChange:u,children:[e.jsx(ps,{children:e.jsx(Rs,{placeholder:"Select an opportunity"})}),e.jsx(gs,{children:n.map(h=>e.jsxs(Xe,{value:h.BidNumber||"",children:[e.jsx("b",{children:h.BidNumber})," | ",h.Opportunity]},"Opportunity"+h.BidNumber))})]}),e.jsxs(ze,{children:[e.jsx(Os.DialogClose,{asChild:!0,children:e.jsx(D,{variant:"outline",disabled:l,children:"Cancel"})}),e.jsx(D,{onClick:m,disabled:l||r,children:"Confirm"})]})]})})})}function Ta({inventory:s,showBinLocation:t,className:a}){const r=(b,k,S=!1,M=!0)=>{const A=b.WarehouseType==="Fulfillment Center",P=A?"bg-background":"bg-background/70 text-muted-foreground",E=M&&k>0?"border-t":"",T=S?"border-r":"",I=b.Status??"Unknown",B=I==="Active";let F="bg-secondary text-secondary-foreground ring-1 ring-border";switch(b.WarehouseType){case"Fulfillment Center":F="bg-randmar-black text-primary-foreground ring-1 ring-randmar-black/40";break;case"Last Mile":F="bg-randmar-blue text-primary-foreground ring-1 ring-randmar-blue/40";break;case"First Mile":F="bg-randmar-purple text-primary-foreground ring-1 ring-randmar-purple/40";break}switch(I){case"Opening":F="bg-success text-success-foreground ring-1 ring-success/40";break;case"Closing":F="bg-warning text-warning-foreground ring-1 ring-warning/40";break;case"Closed":F="bg-destructive text-destructive-foreground ring-1 ring-destructive/40";break}return e.jsxs("article",{"aria-labelledby":`wh-${b.WarehouseId}-name`,className:`p-3 text-sm ${E} ${T} ${P}`,children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{id:`wh-${b.WarehouseId}-name`,className:"text-sm font-medium text-foreground",children:b.Name}),e.jsxs("span",{className:`inline-flex items-center gap-2 rounded-full px-2 py-0.5 text-xs font-semibold ${F}`,"aria-hidden":"false",title:B?A?"Fulfillment Center":"Satellite Warehouse":`Status: ${I}`,children:[A?e.jsx(g.Warehouse,{className:"h-3 w-3","aria-hidden":"true"}):e.jsx(g.Truck,{className:`h-3 w-3 ${B?"opacity-80":"opacity-95"}`,"aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:B?b.WarehouseType?`${b.WarehouseType} warehouse`:"Warehouse":`Status: ${I}`}),e.jsx("span",{"aria-hidden":"true",children:B?b.WarehouseType||(A?"Fulfillment Center":"Satellite"):I})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("div",{className:"text-sm font-medium",children:ls(b.AvailableQuantity??0)})})]}),e.jsxs("div",{className:"flex justify-between mt-1 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Expecting"}),e.jsx("span",{children:b.PurchaseOrderQuantity?ls(b.PurchaseOrderQuantity):"—"})]}),t&&e.jsxs("div",{className:"flex justify-between mt-1 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Bin Location"}),e.jsx("span",{children:b.BinLocation||"—"})]})]},`warehouse-${b.WarehouseId}`)},n=["Z0FP4Z","TOR","MTL"],i=["VAN","EDM"],l=[...s].sort((b,k)=>(b.Name||"").localeCompare(k.Name||"")),d=l.filter(b=>b.Country==="US"),u=l.filter(b=>b.Country==="CA"),m=l.filter(b=>i.includes(b.WarehouseId||"")),h=l.filter(b=>n.includes(b.WarehouseId||"")),c=u.filter(b=>!n.includes(b.WarehouseId||"")&&!i.includes(b.WarehouseId||"")),y=b=>b.reduce((k,S)=>k+(S.AvailableQuantity||0),0),p=y(u),x=y(h),w=y(m),N=y(d),j=p+N;return e.jsxs("div",{className:`border rounded-md overflow-hidden ${a??""}`,children:[u.length>0&&d.length>0&&e.jsxs("div",{className:"grid grid-cols-2 border-b",children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"Total"}),e.jsx("span",{children:j})]}),e.jsx("div",{className:"p-3"})]}),u.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 border-b bg-muted/30",children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"Canada"}),e.jsx("span",{children:ls(p)})]}),e.jsx("div",{className:"p-3"})]}),e.jsxs("div",{className:"grid grid-cols-2",children:[e.jsxs("div",{className:"border-r",children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"West"}),e.jsx("span",{children:ls(w)})]}),m.map((b,k)=>r(b,k))]}),e.jsxs("div",{children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"East"}),e.jsx("span",{children:ls(x)})]}),h.map((b,k)=>r(b,k))]})]}),c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t p-3 font-semibold text-sm",children:e.jsx("span",{children:"Other"})}),e.jsx("div",{className:"grid grid-cols-2",children:c.map((b,k)=>r(b,k,k%2===0,!0))})]})]}),d.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 border-t bg-muted/30",children:[e.jsxs("div",{className:"p-3 font-semibold text-sm flex justify-between",children:[e.jsx("span",{children:"United States"}),e.jsx("span",{children:ls(N)})]}),e.jsx("div",{className:"p-3"})]}),e.jsx("div",{className:"grid grid-cols-2",children:d.map((b,k)=>r(b,k,k%2===0,!0))})]}),s.length===0&&e.jsx("div",{className:"p-6 text-center text-muted-foreground",children:"No inventory information available"})]})}const yt=R.forwardRef(({className:s,orientation:t="horizontal",decorative:a=!0,...r},n)=>e.jsx(Wr.Root,{ref:n,decorative:a,orientation:t,className:v("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",s),...r}));yt.displayName=Wr.Root.displayName;const ln=we.Root,Tl=we.Trigger,El=we.Close,on=we.Portal,Ea=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Overlay,{className:v("fixed inset-0 z-50 bg-foreground/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...t,ref:a}));Ea.displayName=we.Overlay.displayName;const Ol=et.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Oa=R.forwardRef(({side:s="right",className:t,children:a,...r},n)=>e.jsxs(on,{children:[e.jsx(Ea,{}),e.jsxs(we.Content,{ref:n,className:v(Ol({side:s}),t),...r,children:[e.jsxs(we.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[e.jsx(g.X,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]}),a]})]}));Oa.displayName=we.Content.displayName;const cn=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-2 text-center sm:text-left",s),...t});cn.displayName="SheetHeader";const dn=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});dn.displayName="SheetFooter";const un=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Title,{ref:a,className:v("text-lg font-semibold text-foreground",s),...t}));un.displayName=we.Title.displayName;const mn=R.forwardRef(({className:s,...t},a)=>e.jsx(we.Description,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));mn.displayName=we.Description.displayName;function zt({elementRef:s,threshold:t=0,rootMargin:a="0px",freezeOnceVisible:r=!1}){const[n,i]=o.useState(!1);return o.useEffect(()=>{const l=s.current;if(!l){i(!1);return}const d=new IntersectionObserver(([u])=>{const m=u.isIntersecting;r&&m?(i(!0),d.unobserve(l)):i(m)},{threshold:t,rootMargin:a});return d.observe(l),()=>{d.unobserve(l)}},[s,t,a,r]),n}const us=({id:s,name:t,width:a=64,height:r=64,align:n="",className:i})=>{const l=o.useRef(null),d=zt({elementRef:l,threshold:.1,rootMargin:"100px",freezeOnceVisible:!0}),{data:u,isFetching:m,isSuccess:h}=_.useGetV4PartnerByApplicationIdAccountLogoExistsQuery({applicationId:s??""},{skip:!s||!d}),{data:c,isFetching:y}=_.useGetV4PartnerByApplicationIdAccountLogoQuery({applicationId:s??"",width:a,height:r,align:n},{skip:!h||u!=!0}),p=t||(s?`Partner ID: ${s}`:"Logo not available (no ID)"),x=()=>!d||m||y?e.jsx(f,{className:"h-full w-full rounded-sm"}):c?e.jsx("img",{src:c,alt:p,className:"h-full w-full object-contain rounded-sm"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center rounded-sm bg-muted/20 p-1",title:p,children:e.jsx(g.Handshake,{className:"text-primary fill-background min-h-full"})});return e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx("div",{className:v("flex h-full w-full cursor-default",i),ref:l,children:x()})}),e.jsx(pe,{side:"top",align:"center",children:p})]})})};function Ll({onClick:s,publicName:t,applicationName:a,partnerId:r}){return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-muted "+(s!==void 0?"cursor-pointer":""),children:e.jsx(D,{asChild:!0,size:"icon",onClick:s,children:e.jsx("div",{className:"h-9 w-9 object-cover !bg-sidebar",children:e.jsx(us,{id:r,width:64,height:64})})})}),e.jsxs("div",{className:"flex flex-1 flex-col",children:[e.jsx("span",{className:"text-sm font-medium",children:t||"Partner"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a})]})]})}const la=1024;function xn(){const[s,t]=R.useState(void 0);return R.useEffect(()=>{const a=window.matchMedia(`(max-width: ${la-1}px)`),r=()=>{t(window.innerWidth<la)};return a.addEventListener("change",r),t(window.innerWidth<la),()=>a.removeEventListener("change",r)},[]),!!s}const hn=R.createContext(null);function tt(){const s=R.useContext(hn);if(!s)throw new Error("useSidebar must be used within a SidebarProvider.");return s}function f({className:s,...t}){return e.jsx("div",{className:v("animate-pulse rounded-md bg-primary/20",s),...t})}const Fl="sidebar:state",Bl=3600*24*7,$l="16rem",_l="3rem",Vl="b",La=R.forwardRef(({defaultOpen:s=!0,defaultOpenMobile:t=!1,isMobileOverride:a,open:r,onOpenChange:n,className:i,style:l,children:d,...u},m)=>{const h=xn(),c=a??h,[y,p]=R.useState(t),[x,w]=R.useState(s),N=r??x,j=R.useCallback(M=>{const A=typeof M=="function"?M(N):M;n?n(A):w(A),document.cookie=`${Fl}=${A}; path=/; max-age=${Bl}`},[n,N]),b=R.useCallback(()=>c?p(M=>!M):j(M=>!M),[c,j,p]);R.useEffect(()=>{const M=A=>{A.key===Vl&&(A.metaKey||A.ctrlKey)&&(A.preventDefault(),b())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[b]);const k=N?"expanded":"collapsed",S=R.useMemo(()=>({state:k,open:N,setOpen:j,isMobile:c,openMobile:y,setOpenMobile:p,toggleSidebar:b}),[k,N,j,c,y,p,b]);return e.jsx(hn.Provider,{value:S,children:e.jsx(ye,{delayDuration:0,children:e.jsx("div",{style:{"--sidebar-width":$l,"--sidebar-width-icon":_l,...l},className:v("group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",i),ref:m,...u,children:d})})})});La.displayName="SidebarProvider";const Fa=R.forwardRef(({side:s="left",variant:t="sidebar",collapsible:a="offcanvas",className:r,children:n,...i},l)=>{const{isMobile:d,state:u,openMobile:m,setOpenMobile:h}=tt();return a==="none"?e.jsx("div",{className:v("flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",r),ref:l,...i,children:n}):d?e.jsx(ln,{open:m,onOpenChange:h,...i,children:e.jsx(Oa,{"data-sidebar":"sidebar","data-mobile":"true",className:v("inset-0 h-svh w-screen max-w-none border-0 bg-sidebar p-0 text-sidebar-foreground sm:max-w-none","[&>button]:right-4 [&>button]:top-4 [&>button]:h-11 [&>button]:w-11 [&>button]:rounded-md [&>button]:opacity-100","[&>button]:text-sidebar-foreground [&>button]:ring-offset-sidebar [&>button]:hover:bg-sidebar-accent [&>button]:hover:text-sidebar-accent-foreground [&>button]:focus-visible:ring-sidebar-ring",r),side:s,children:e.jsx("div",{className:"flex h-full w-full flex-col",children:n})})}):e.jsxs("div",{ref:l,className:"group peer hidden md:block text-sidebar-foreground","data-state":u,"data-collapsible":u==="collapsed"?a:"","data-variant":t,"data-side":s,children:[e.jsx("div",{className:v("duration-200 relative h-svh w-(--sidebar-width) bg-transparent transition-[width] ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon)")}),e.jsx("div",{className:v("duration-200 fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] ease-linear md:flex",s==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",r),...i,children:e.jsx("div",{"data-sidebar":"sidebar",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm",children:n})})]})});Fa.displayName="Sidebar";const Ba=R.forwardRef(({className:s,onClick:t,...a},r)=>{const{toggleSidebar:n}=tt();return e.jsxs(D,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:v("h-7 w-7 text-sidebar-foreground",s),onClick:i=>{t?.(i),n()},...a,children:[e.jsx(g.PanelLeft,{}),e.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});Ba.displayName="SidebarTrigger";const fn=R.forwardRef(({className:s,...t},a)=>{const{toggleSidebar:r}=tt();return e.jsx("button",{ref:a,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:v("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex","in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",s),...t})});fn.displayName="SidebarRail";const pn=R.forwardRef(({className:s,...t},a)=>e.jsx("main",{ref:a,className:v("relative flex min-h-svh flex-1 flex-col bg-background","peer-data-[variant=inset]:min-h-[calc(100svh-(--spacing(4)))] md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm",s),...t}));pn.displayName="SidebarInset";const gn=R.forwardRef(({className:s,...t},a)=>e.jsx(le,{ref:a,"data-sidebar":"input",className:v("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",s),...t}));gn.displayName="SidebarInput";const $a=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"header",className:v("flex flex-col gap-2 p-2",s),...t}));$a.displayName="SidebarHeader";const _a=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"footer",className:v("flex flex-col gap-2 p-2",s),...t}));_a.displayName="SidebarFooter";const jn=R.forwardRef(({className:s,...t},a)=>e.jsx(yt,{ref:a,"data-sidebar":"separator",className:v("mx-2 w-auto bg-sidebar-border",s),...t}));jn.displayName="SidebarSeparator";const Va=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"content",className:v("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",s),...t}));Va.displayName="SidebarContent";const bn=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"group",className:v("relative flex w-full min-w-0 flex-col p-2",s),...t}));bn.displayName="SidebarGroup";const yn=R.forwardRef(({className:s,asChild:t=!1,...a},r)=>{const n=t?Xs.Slot:"div";return e.jsx(n,{ref:r,"data-sidebar":"group-label",className:v("duration-200 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-hidden ring-sidebar-ring transition-[margin,opa] ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",s),...a})});yn.displayName="SidebarGroupLabel";const Nn=R.forwardRef(({className:s,asChild:t=!1,...a},r)=>{const n=t?Xs.Slot:"button";return e.jsx(n,{ref:r,"data-sidebar":"group-action",className:v("absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 md:after:hidden","group-data-[collapsible=icon]:hidden",s),...a})});Nn.displayName="SidebarGroupAction";const vn=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"group-content",className:v("w-full text-sm",s),...t}));vn.displayName="SidebarGroupContent";const za=R.forwardRef(({className:s,...t},a)=>e.jsx("ul",{ref:a,"data-sidebar":"menu",className:v("flex w-full min-w-0 flex-col gap-1",s),...t}));za.displayName="SidebarMenu";const Ua=R.forwardRef(({className:s,...t},a)=>e.jsx("li",{ref:a,"data-sidebar":"menu-item",className:v("group/menu-item relative",s),...t}));Ua.displayName="SidebarMenuItem";const zl=et.cva("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:p-0!"}},defaultVariants:{variant:"default",size:"default"}}),qa=R.forwardRef(({asChild:s=!1,isActive:t=!1,variant:a="default",size:r="default",tooltip:n,className:i,...l},d)=>{const u=s?Xs.Slot:"button",{isMobile:m,state:h}=tt(),c=e.jsx(u,{ref:d,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:v(zl({variant:a,size:r}),i),...l});return n?(typeof n=="string"&&(n={children:n}),e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:c}),e.jsx(pe,{side:"right",align:"center",hidden:h!=="collapsed"||m,...n})]})):c});qa.displayName="SidebarMenuButton";const wn=R.forwardRef(({className:s,asChild:t=!1,showOnHover:a=!1,...r},n)=>{const i=t?Xs.Slot:"button";return e.jsx(i,{ref:n,"data-sidebar":"menu-action",className:v("absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 md:after:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",a&&"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",s),...r})});wn.displayName="SidebarMenuAction";const Sn=R.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"menu-badge",className:v("absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground select-none pointer-events-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",s),...t}));Sn.displayName="SidebarMenuBadge";const Cn=R.forwardRef(({className:s,showIcon:t=!1,...a},r)=>{const n=R.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return e.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:v("rounded-md h-8 flex gap-2 px-2 items-center",s),...a,children:[t&&e.jsx(f,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),e.jsx(f,{className:"h-4 flex-1 max-w-(--skeleton-width)","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":n}})]})});Cn.displayName="SidebarMenuSkeleton";const kn=R.forwardRef(({className:s,...t},a)=>e.jsx("ul",{ref:a,"data-sidebar":"menu-sub",className:v("mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",s),...t}));kn.displayName="SidebarMenuSub";const Rn=R.forwardRef(({...s},t)=>e.jsx("li",{ref:t,...s}));Rn.displayName="SidebarMenuSubItem";const Pn=R.forwardRef(({asChild:s=!1,size:t="md",isActive:a,className:r,...n},i)=>{const l=s?Xs.Slot:"a";return e.jsx(l,{ref:i,"data-sidebar":"menu-sub-button","data-size":t,"data-active":a,className:v("flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-hidden ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",r),...n})});Pn.displayName="SidebarMenuSubButton";const An=as.Provider,Qa=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Viewport,{ref:a,className:v("fixed top-0 z-[11000] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",s),...t}));Qa.displayName=as.Viewport.displayName;const Ul=et.cva("group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full sm:data-[state=open]:slide-in-from-bottom-full",{variants:{variant:{default:"border bg-background text-foreground",destructive:"destructive group border-destructive bg-destructive text-destructive-foreground",success:"border-success bg-success text-success-foreground",warning:"border-warning bg-warning text-warning-foreground",info:"border-info bg-info text-info-foreground",secondary:"border-secondary bg-secondary text-secondary-foreground",outline:"border-input bg-background text-foreground hover:bg-accent hover:text-accent-foreground"}},defaultVariants:{variant:"default"}}),Ha=R.forwardRef(({className:s,variant:t,...a},r)=>e.jsx(as.Root,{ref:r,className:v(Ul({variant:t}),s),...a}));Ha.displayName=as.Root.displayName;const Ga=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Action,{ref:a,className:v("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 hover:group-[.destructive]:border-destructive/30 hover:group-[.destructive]:bg-destructive hover:group-[.destructive]:text-destructive-foreground",s),...t}));Ga.displayName=as.Action.displayName;const Wa=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Close,{ref:a,className:v("absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 group-hover:opacity-100 group-[.destructive]:text-destructive-foreground/70 hover:group-[.destructive]:text-destructive-foreground",s),"toast-close":"",...t,children:e.jsx(g.X,{className:"h-4 w-4"})}));Wa.displayName=as.Close.displayName;const Ka=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Title,{ref:a,className:v("text-sm font-semibold [&+div]:text-xs",s),...t}));Ka.displayName=as.Title.displayName;const Ya=R.forwardRef(({className:s,...t},a)=>e.jsx(as.Description,{ref:a,className:v("text-sm opacity-90",s),...t}));Ya.displayName=as.Description.displayName;const ql=1,Ql=1e6;let oa=0;function Hl(){return oa=(oa+1)%Number.MAX_SAFE_INTEGER,oa.toString()}const ca=new Map,Tr=s=>{if(ca.has(s))return;const t=setTimeout(()=>{ca.delete(s),pt({type:"REMOVE_TOAST",toastId:s})},Ql);ca.set(s,t)},Gl=(s,t)=>{switch(t.type){case"ADD_TOAST":return{...s,toasts:[t.toast,...s.toasts].slice(0,ql)};case"UPDATE_TOAST":return{...s,toasts:s.toasts.map(a=>a.id===t.toast.id?{...a,...t.toast}:a)};case"DISMISS_TOAST":{const{toastId:a}=t;return a?Tr(a):s.toasts.forEach(r=>Tr(r.id)),{...s,toasts:s.toasts.map(r=>r.id===a||a===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return{...s,toasts:t.toastId?s.toasts.filter(a=>a.id!==t.toastId):[]}}},Tt=[];let Et={toasts:[]};function pt(s){Et=Gl(Et,s),Tt.forEach(t=>t(Et))}function In({...s}){const t=Hl(),a=n=>pt({type:"UPDATE_TOAST",toast:{...n,id:t}}),r=()=>pt({type:"DISMISS_TOAST",toastId:t});return pt({type:"ADD_TOAST",toast:{...s,id:t,open:!0,onOpenChange:n=>{n||r()}}}),{id:t,dismiss:r,update:a}}function Ce(){const[s,t]=R.useState(Et);return R.useEffect(()=>(Tt.push(t),()=>{const a=Tt.indexOf(t);a>-1&&Tt.splice(a,1)}),[]),{...s,toast:In,dismiss:a=>pt({type:"DISMISS_TOAST",toastId:a})}}function Dn(){const{toasts:s}=Ce();return e.jsxs(An,{children:[s.map(function({id:t,title:a,description:r,action:n,...i}){return e.jsxs(Ha,{...i,children:[e.jsxs("div",{className:"grid gap-1",children:[a&&e.jsx(Ka,{children:a}),r&&e.jsx(Ya,{children:r})]}),n,e.jsx(Wa,{})]},t)}),e.jsx(Qa,{})]})}const Ja=o.createContext(void 0),Wl=({children:s})=>{const t=o.useRef(null),a=(l,d,u)=>t.current?(t.current.sendMessageToAssistant(l??null,d??null,u??null),!0):!1,r=(l,d,u)=>t.current?(t.current.sendMessageToAssistantWithClear(l??null,d??null,u??null),!0):!1,[n,i]=o.useState(!1);return e.jsx(Ja.Provider,{value:{sendMessage:a,sendMessageWithClear:r,chatRef:t,hasUnreads:n,setHasUnreads:i},children:s})},Js=()=>{const s=o.useContext(Ja);if(s===void 0)throw new Error("useChat must be used within a ChatProvider");return s},Mn=()=>o.useContext(Ja),Kl=[{value:"az",label:"A–Z"},{value:"recent",label:"Recently added"},{value:"sales30Desc",label:"Sales last 30 days: High to low"},{value:"sales30Asc",label:"Sales last 30 days: Low to high"}];function Tn(s){return s.trim().toLocaleLowerCase()}function Ca(s){return(s??"").split(/[;,|]/g).map(t=>t.trim()).filter(Boolean)}function Dt(s){return s.PublicName??s.Name??""}function Yl(s){return Ca(s.Tags).map(Tn)}function Jl(s){const t=s.Opportunities;if(Array.isArray(t)){const a=new Date;a.setHours(0,0,0,0);const r=n=>{if(typeof n=="number"&&Number.isFinite(n)){const i=Math.trunc(n);if(i>1e7){const l=String(i).padStart(8,"0"),d=Number(l.slice(0,4)),u=Number(l.slice(4,6)),m=Number(l.slice(6,8));if(d>=1900&&u>=1&&u<=12&&m>=1&&m<=31)return new Date(d,u-1,m)}}if(typeof n=="string"){const i=new Date(n);if(!Number.isNaN(i.getTime()))return i}return null};return t.some(n=>{if(!(n?.Active===!0||n?.IsActive===!0||n?.State==="Active"))return!1;const l=n?.EndDate??n?.End??n?.ExpiryDate??n?.ExpiresOn,d=r(l);return d?(d.setHours(0,0,0,0),d>=a):!0})}return(s.NumberOfOpportunities??0)>0}function Zl({appID:s,manufPath:t,withBot:a}){const[r,n]=o.useState(!1),{data:i,isLoading:l}=_.useGetV4PartnerByRouteApplicationIdManufacturersQuery({routeApplicationId:s??"",withSpecification:!1});o.useEffect(()=>{n(!1)},[s]),o.useEffect(()=>{!r&&!l&&n(!0)},[l,r]);const{data:d}=_.useGetV4PartnerByRouteApplicationIdManufacturersQuery({routeApplicationId:s??"",withSpecification:!0},{skip:!r}),u=o.useMemo(()=>(d??i)?.slice()??[],[i,d]),[m,h]=o.useState(""),[c,y]=o.useState([]),[p,x]=o.useState("az"),[w,N]=o.useState(!1),[j,b]=o.useState(!1),k=o.useMemo(()=>{const T=new Map;for(const I of u)for(const B of Ca(I.Tags)){const F=Tn(B);T.has(F)||T.set(F,B)}return Array.from(T.entries()).map(([I,B])=>({key:I,label:B})).sort((I,B)=>I.label.localeCompare(B.label,void 0,{sensitivity:"base"}))},[u]),S=m.trim().length>0||c.length>0||p!=="az"||w||j,M=o.useCallback(()=>{h(""),y([]),x("az"),N(!1),b(!1)},[]),{sendMessage:A}=Js(),P=o.useCallback(T=>{const I=T?.trim().length>0?T.trim():"this manufacturer";A(`Search for ${I} and tell me more about this manufacturer.`)},[A]),E=o.useMemo(()=>{const T=m.trim().toLocaleLowerCase(),I=new Set(c),F=u.filter(U=>{if(w&&!U.OpenToWork||j&&!Jl(U))return!1;const V=Yl(U);if(I.size>0&&!V.some(O=>I.has(O)))return!1;if(T.length>0){const O=Dt(U).toLocaleLowerCase(),q=Ca(U.Tags).map(ne=>ne.toLocaleLowerCase());if(!(O.includes(T)||q.some(ne=>ne.includes(T))))return!1}return!0}).slice();return F.sort((U,V)=>p==="az"?Dt(U).localeCompare(Dt(V),void 0,{sensitivity:"base"}):p==="recent"?(V.CreationDate??0)-(U.CreationDate??0):p==="sales30Desc"?(V.SalesData?.SalesLast30Days??0)-(U.SalesData?.SalesLast30Days??0):(U.SalesData?.SalesLast30Days??0)-(V.SalesData?.SalesLast30Days??0)),F},[u,j,w,m,c,p]);return e.jsxs("div",{className:"w-full space-y-6 p-4 sm:p-6",children:[e.jsx(z,{children:e.jsxs(G,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"manufacturer-search",children:"Search manufacturers"}),e.jsx(le,{id:"manufacturer-search",value:m,onChange:T=>h(T.target.value),placeholder:"Search by name, or category"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{id:"manufacturer-categories-label",className:"text-sm font-medium leading-none",children:"Categories"}),S&&e.jsx(D,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2",onClick:M,children:"Clear filters"})]}),e.jsx("div",{role:"group","aria-labelledby":"manufacturer-categories-label","aria-describedby":"manufacturer-categories-help",className:"flex flex-wrap gap-2",children:k.length===0?e.jsx("span",{className:"text-sm text-muted-foreground",children:"No categories available."}):k.map(({key:T,label:I})=>{const B=c.includes(T);return e.jsx(D,{type:"button",variant:B?"secondary":"outline",className:"rounded-full","aria-pressed":B,onClick:()=>{y(F=>F.includes(T)?F.filter(U=>U!==T):[...F,T])},children:I},T)})}),e.jsx("p",{id:"manufacturer-categories-help",className:"text-xs text-muted-foreground",children:"Tap to include or remove categories"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{id:"manufacturer-sort-label",className:"text-sm font-medium leading-none",children:"Sort by"}),e.jsxs(ks,{value:p,onValueChange:T=>x(T),children:[e.jsx(ps,{"aria-labelledby":"manufacturer-sort-label",children:e.jsx(Rs,{placeholder:"A–Z"})}),e.jsx(gs,{children:Kl.map(T=>e.jsx(Xe,{value:T.value,children:T.label},T.value))})]})]})]}),e.jsx("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs("label",{htmlFor:"only-open-to-work",className:"flex items-center gap-2 rounded-md border px-3 py-2 text-sm cursor-pointer select-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",children:[e.jsx(Ps,{id:"only-open-to-work",checked:w,onCheckedChange:T=>N(T===!0)}),e.jsx("span",{children:"Open to work"})]}),e.jsxs("label",{htmlFor:"only-active-opportunities",className:"flex items-center gap-2 rounded-md border px-3 py-2 text-sm cursor-pointer select-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",children:[e.jsx(Ps,{id:"only-active-opportunities",checked:j,onCheckedChange:T=>b(T===!0)}),e.jsx("span",{children:"Active opportunities"})]})]})})]})}),e.jsxs("div",{className:"@container space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",E.length," of ",u.length," manufacturers"]}),l&&u.length===0?e.jsx("div",{className:"grid grid-cols-1 @md:grid-cols-1 @lg:grid-cols-2 @xl:grid-cols-3 gap-4",children:Array.from({length:9}).map((T,I)=>e.jsx(Zs,{loading:!0},I))}):E.length>0?e.jsx("div",{className:"grid grid-cols-1 @md:grid-cols-1 @lg:grid-cols-2 @xl:grid-cols-3 gap-4",children:E.map((T,I)=>{const B=Dt(T);return e.jsx(Zs,{appID:s,manufacturer:T,linkNewTab:!1,link:t(T.ManufacturerId||""),actions:a?e.jsx(D,{type:"button",variant:"outline",size:"icon","aria-label":`Assistant: ${B||"manufacturer"}`,onClick:()=>P(B),children:e.jsx(g.Bot,{})}):void 0,mainAction:e.jsx(or,{applicationId:s,manufacturer:T})},T.ManufacturerId??`${B}-${I}`)})}):e.jsx(z,{children:e.jsxs(G,{className:"p-8 text-center space-y-3",children:[e.jsx("p",{className:"text-muted-foreground",children:"No manufacturers match your current filters."}),e.jsx(D,{type:"button",variant:"outline",onClick:M,disabled:!S,children:"Reset filters"})]})})]})]})}const En="https://api.randmar.io",Xl="/swagger/V4/swagger.json",On=`${En}${Xl}`,Ln=o.createContext({swaggerJsonUrl:On});function eo({swaggerJsonUrl:s,children:t}){const a=o.useMemo(()=>({swaggerJsonUrl:s??On}),[s]);return e.jsx(Ln.Provider,{value:a,children:t})}function Fn(){return o.useContext(Ln)}function so({active:s,payload:t,label:a,series:r}){if(s&&t?.length){const n=new Map(r.map(i=>[i.name,i]));return e.jsxs("div",{className:"rounded-lg border bg-background p-2 text-sm shadow-sm",children:[e.jsx("div",{className:"mb-1 font-medium",children:a}),e.jsx("div",{className:"space-y-1",children:t.map(i=>{if(typeof i.dataKey!="string"||i.value===null||i.value===void 0)return null;const l=n.get(i.dataKey);if(!l)return null;const d=l.format==="money"&&typeof i.value=="number"?de(i.value):l.format==="integer"&&typeof i.value=="number"?ls(i.value,{maximumFractionDigits:2}):l.unitsPosition==="left"?`${l.units||""}${i.value}`:`${i.value}${l.units?` ${l.units}`:""}`;return e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:v("mr-2 h-2.5 w-2.5 rounded-full",l.dotClassName??"bg-foreground")}),e.jsx("span",{className:"text-muted-foreground",children:l.label||i.name})]}),e.jsx("span",{className:"font-medium",children:d})]},i.dataKey)})})]})}return null}function Bn({data:s,series:t,height:a,className:r,size:n="default"}){if(!s?.length||!t?.length)return e.jsx("div",{className:v("flex items-center justify-center text-muted-foreground",r),style:n==="default"?{height:a}:{},children:"No data available"});const i=Object.keys(s[0])[0],l=n==="mini",d=t.filter(c=>c.yAxisId==="left"||!c.yAxisId),u=t.filter(c=>c.yAxisId==="right"),m=c=>{const y=d[0];return y?.format==="money"?de(c,{minimumFractionDigits:0,maximumFractionDigits:0}):y?.units?y.unitsPosition==="left"?`${y.units}${c}`:`${c}${y.units}`:String(c)},h=c=>{const y=u[0];return y?.format==="money"?de(c,{minimumFractionDigits:0,maximumFractionDigits:0}):y?.units?y.unitsPosition==="left"?`${y.units}${c}`:`${c}${y.units}`:String(c)};return e.jsx("div",{className:v("w-full",r),style:{height:a?`${a}px`:"100%"},children:e.jsx(Ss.ResponsiveContainer,{width:"100%",height:"100%",children:e.jsxs(Ss.AreaChart,{data:s,margin:l?{top:0,right:0,left:0,bottom:0}:{top:10,right:30,left:0,bottom:0},children:[e.jsx("defs",{children:t.map(c=>e.jsxs("linearGradient",{id:`gradient-${c.name}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:c.color,stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:c.color,stopOpacity:.1})]},c.name))}),!l&&e.jsx(Ss.CartesianGrid,{strokeDasharray:"3 3",className:"stroke-border/50"}),!l&&e.jsx(Ss.XAxis,{dataKey:i,className:"text-xs text-muted-foreground",tickLine:!1,axisLine:!1}),!l&&d.length>0&&e.jsx(Ss.YAxis,{yAxisId:"left",className:"text-xs text-muted-foreground",tickLine:!1,axisLine:!1,tickFormatter:m}),!l&&u.length>0&&e.jsx(Ss.YAxis,{yAxisId:"right",orientation:"right",className:"text-xs text-muted-foreground",tickLine:!1,axisLine:!1,tickFormatter:h}),!l&&e.jsx(Ss.Tooltip,{content:e.jsx(so,{series:t}),cursor:{stroke:"var(--muted)",strokeWidth:1}}),t.map(c=>e.jsx(Ss.Area,{yAxisId:c.yAxisId||"left",type:"monotone",dataKey:c.name,stroke:c.color,fillOpacity:.6,fill:`url(#gradient-${c.name})`,strokeWidth:l?1:2},c.name))]})})})}const to="5.12.1",ao=59.9400024414062,ro=0,no=660.000026882351,io=1080,lo=1080,oo="Comp 1",co=0,uo=[{id:"comp_0",nm:"randmar pulse",fr:59.9400024414062,layers:[{ddd:0,ind:1,ty:4,nm:"Shape Layer 3",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:21,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:42,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:52,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:107,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:134,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:163,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:223,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:250,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:279,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:339,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:366,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:395,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:455,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:482,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:511,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:571,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:598,s:[105,105,100]},{t:627.000025538234,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ind:0,ty:"sh",ix:1,ks:{a:0,k:{i:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],o:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],v:[[149.125,-150.875],[-152.875,-150.875],[-152.875,151.125],[-92,151.125],[-92,-90],[149.125,-90]],c:!0},ix:2},nm:"Path 1",mn:"ADBE Vector Shape - Group",hd:!1},{ty:"fl",c:{a:0,k:[.172549019608,.172549019608,.172549019608,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[0,0],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Shape 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:21.0000008553475,op:660.000026882351,st:21.0000008553475,ct:1,bm:0},{ddd:0,ind:2,ty:4,nm:"Shape Layer 2",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:10,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:31,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:41,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:96,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:123,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:152,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:212,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:239,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:268,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:328,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:355,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:384,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:444,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:471,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:500,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:560,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:587,s:[105,105,100]},{t:616.000025090194,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ind:0,ty:"sh",ix:1,ks:{a:0,k:{i:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],o:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],v:[[148,-29.5],[-32,-29.5],[-31.75,150.5],[27.5,150.5],[28,30.5],[148.5,30.5]],c:!0},ix:2},nm:"Path 1",mn:"ADBE Vector Shape - Group",hd:!1},{ty:"fl",c:{a:0,k:[.172549019608,.172549019608,.172549019608,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[0,0],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Shape 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:10.0000004073083,op:660.000026882351,st:10.0000004073083,ct:1,bm:0},{ddd:0,ind:3,ty:4,nm:"Shape Layer 1",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:4,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:25,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:35,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:90,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:117,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:146,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:206,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:233,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:262,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:322,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:349,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:378,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:438,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:465,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:494,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:554,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:581,s:[105,105,100]},{t:610.000024845809,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ty:"rc",d:1,s:{a:0,k:[60,60],ix:2},p:{a:0,k:[0,0],ix:3},r:{a:0,k:0,ix:4},nm:"Rectangle Path 1",mn:"ADBE Vector Shape - Rect",hd:!1},{ty:"fl",c:{a:0,k:[.172549019608,.172549019608,.172549019608,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[117.75,119.75],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Rectangle 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:0,op:660.000026882351,st:0,ct:1,bm:0}]}],mo=[{ddd:0,ind:1,ty:0,nm:"randmar pulse",refId:"comp_0",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[540,540,0],ix:2,l:2},a:{a:0,k:[960,540,0],ix:1,l:2},s:{a:0,k:[308,308,100],ix:6,l:2}},ao:0,ef:[{ty:5,nm:"Hue/Saturation",np:11,mn:"ADBE HUE SATURATION",ix:1,en:1,ef:[{ty:7,nm:"Channel Control",mn:"ADBE HUE SATURATION-0002",ix:1,v:{a:0,k:1,ix:1}},{},{ty:0,nm:"Master Hue",mn:"ADBE HUE SATURATION-0004",ix:3,v:{a:0,k:0,ix:3}},{ty:0,nm:"Master Saturation",mn:"ADBE HUE SATURATION-0005",ix:4,v:{a:0,k:0,ix:4}},{ty:0,nm:"Master Lightness",mn:"ADBE HUE SATURATION-0006",ix:5,v:{a:0,k:0,ix:5}},{ty:7,nm:"Colorize",mn:"ADBE HUE SATURATION-0007",ix:6,v:{a:0,k:0,ix:6}},{ty:0,nm:"Colorize Hue",mn:"ADBE HUE SATURATION-0008",ix:7,v:{a:0,k:0,ix:7}},{ty:0,nm:"Colorize Saturation",mn:"ADBE HUE SATURATION-0009",ix:8,v:{a:0,k:25,ix:8}},{ty:0,nm:"Colorize Lightness",mn:"ADBE HUE SATURATION-0010",ix:9,v:{a:0,k:0,ix:9}}]}],w:1920,h:1080,ip:0,op:660.000026882351,st:0,bm:0}],xo=[],ho={},Er={v:to,fr:ao,ip:ro,op:no,w:io,h:lo,nm:oo,ddd:co,assets:uo,layers:mo,markers:xo,props:ho},fo="5.12.1",po=59.9400024414062,go=0,jo=660.000026882351,bo=1080,yo=1080,No="Comp 1",vo=0,wo=[{id:"comp_0",nm:"randmar pulse",fr:59.9400024414062,layers:[{ddd:0,ind:1,ty:4,nm:"Shape Layer 3",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:21,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:42,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:52,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:107,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:134,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:163,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:223,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:250,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:279,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:339,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:366,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:395,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:455,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:482,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:511,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:571,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:598,s:[105,105,100]},{t:627.000025538234,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ind:0,ty:"sh",ix:1,ks:{a:0,k:{i:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],o:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],v:[[149.125,-150.875],[-152.875,-150.875],[-152.875,151.125],[-92,151.125],[-92,-90],[149.125,-90]],c:!0},ix:2},nm:"Path 1",mn:"ADBE Vector Shape - Group",hd:!1},{ty:"fl",c:{a:0,k:[1,1,1,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[0,0],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Shape 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:21.0000008553475,op:660.000026882351,st:21.0000008553475,ct:1,bm:0},{ddd:0,ind:2,ty:4,nm:"Shape Layer 2",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:10,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:31,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:41,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:96,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:123,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:152,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:212,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:239,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:268,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:328,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:355,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:384,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:444,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:471,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:500,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:560,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:587,s:[105,105,100]},{t:616.000025090194,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ind:0,ty:"sh",ix:1,ks:{a:0,k:{i:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],o:[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],v:[[148,-29.5],[-32,-29.5],[-31.75,150.5],[27.5,150.5],[28,30.5],[148.5,30.5]],c:!0},ix:2},nm:"Path 1",mn:"ADBE Vector Shape - Group",hd:!1},{ty:"fl",c:{a:0,k:[1,1,1,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[0,0],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Shape 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:10.0000004073083,op:660.000026882351,st:10.0000004073083,ct:1,bm:0},{ddd:0,ind:3,ty:4,nm:"Shape Layer 1",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[960,540,0],ix:2,l:2},a:{a:0,k:[0,0,0],ix:1,l:2},s:{a:1,k:[{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:4,s:[0,0,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:25,s:[111,111,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:35,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:90,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:117,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:146,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:206,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:233,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:262,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:322,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:349,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:378,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:438,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:465,s:[105,105,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:494,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:554,s:[100,100,100]},{i:{x:[.667,.667,.667],y:[1,1,1]},o:{x:[.333,.333,.333],y:[0,0,0]},t:581,s:[105,105,100]},{t:610.000024845809,s:[0,0,100]}],ix:6,l:2}},ao:0,shapes:[{ty:"gr",it:[{ty:"rc",d:1,s:{a:0,k:[60,60],ix:2},p:{a:0,k:[0,0],ix:3},r:{a:0,k:0,ix:4},nm:"Rectangle Path 1",mn:"ADBE Vector Shape - Rect",hd:!1},{ty:"fl",c:{a:0,k:[1,1,1,1],ix:4},o:{a:0,k:100,ix:5},r:1,bm:0,nm:"Fill 1",mn:"ADBE Vector Graphic - Fill",hd:!1},{ty:"tr",p:{a:0,k:[117.75,119.75],ix:2},a:{a:0,k:[0,0],ix:1},s:{a:0,k:[100,100],ix:3},r:{a:0,k:0,ix:6},o:{a:0,k:100,ix:7},sk:{a:0,k:0,ix:4},sa:{a:0,k:0,ix:5},nm:"Transform"}],nm:"Rectangle 1",np:3,cix:2,bm:0,ix:1,mn:"ADBE Vector Group",hd:!1}],ip:0,op:660.000026882351,st:0,ct:1,bm:0}]}],So=[{ddd:0,ind:1,ty:0,nm:"randmar pulse",refId:"comp_0",sr:1,ks:{o:{a:0,k:100,ix:11},r:{a:0,k:0,ix:10},p:{a:0,k:[540,540,0],ix:2,l:2},a:{a:0,k:[960,540,0],ix:1,l:2},s:{a:0,k:[308,308,100],ix:6,l:2}},ao:0,ef:[{ty:5,nm:"Hue/Saturation",np:11,mn:"ADBE HUE SATURATION",ix:1,en:1,ef:[{ty:7,nm:"Channel Control",mn:"ADBE HUE SATURATION-0002",ix:1,v:{a:0,k:1,ix:1}},{},{ty:0,nm:"Master Hue",mn:"ADBE HUE SATURATION-0004",ix:3,v:{a:0,k:0,ix:3}},{ty:0,nm:"Master Saturation",mn:"ADBE HUE SATURATION-0005",ix:4,v:{a:0,k:0,ix:4}},{ty:0,nm:"Master Lightness",mn:"ADBE HUE SATURATION-0006",ix:5,v:{a:0,k:0,ix:5}},{ty:7,nm:"Colorize",mn:"ADBE HUE SATURATION-0007",ix:6,v:{a:0,k:0,ix:6}},{ty:0,nm:"Colorize Hue",mn:"ADBE HUE SATURATION-0008",ix:7,v:{a:0,k:0,ix:7}},{ty:0,nm:"Colorize Saturation",mn:"ADBE HUE SATURATION-0009",ix:8,v:{a:0,k:25,ix:8}},{ty:0,nm:"Colorize Lightness",mn:"ADBE HUE SATURATION-0010",ix:9,v:{a:0,k:0,ix:9}}]},{ty:5,nm:"Change to Color",np:13,mn:"ADBE Change To Color",ix:2,en:1,ef:[{ty:2,nm:"From",mn:"ADBE Change To Color-0001",ix:1,v:{a:0,k:[.72549021244,.184313729405,.184313729405,1],ix:1}},{ty:2,nm:"To",mn:"ADBE Change To Color-0002",ix:2,v:{a:0,k:[1,1,1,1],ix:2}},{ty:7,nm:"Change",mn:"ADBE Change To Color-0003",ix:3,v:{a:0,k:4,ix:3}},{ty:7,nm:"Change By",mn:"ADBE Change To Color-0004",ix:4,v:{a:0,k:1,ix:4}},{ty:6,nm:"Tolerance",mn:"ADBE Change To Color-0010",ix:5,v:0},{ty:0,nm:"Hue",mn:"ADBE Change To Color-0005",ix:6,v:{a:0,k:.1,ix:6}},{ty:0,nm:"Lightness",mn:"ADBE Change To Color-0006",ix:7,v:{a:0,k:1,ix:7}},{ty:0,nm:"Saturation",mn:"ADBE Change To Color-0007",ix:8,v:{a:0,k:1,ix:8}},{ty:6,nm:"Saturation",mn:"ADBE Change To Color-0011",ix:9,v:0},{ty:0,nm:"Softness",mn:"ADBE Change To Color-0008",ix:10,v:{a:0,k:.5,ix:10}},{ty:7,nm:"View Correction Matte",mn:"ADBE Change To Color-0009",ix:11,v:{a:0,k:0,ix:11}}]}],w:1920,h:1080,ip:0,op:660.000026882351,st:0,bm:0}],Co=[],ko={},Ro={v:fo,fr:po,ip:go,op:jo,w:bo,h:yo,nm:No,ddd:vo,assets:wo,layers:So,markers:Co,props:ko},Po=s=>{const{color:t}=s;return e.jsx("div",{className:"flex justify-center",children:e.jsx(nl.Player,{autoplay:!0,loop:!0,speed:1,style:{width:200,aspectRatio:"1 / 1"},src:t==="white"?Ro:Er})})};function Ao({text:s,color:t="white",className:a}){return e.jsxs("div",{className:v("h-screen w-screen flex items-center justify-center flex-col gap-6 z-50",a),children:[e.jsx(Po,{color:t}),s&&e.jsx("div",{className:v("text-center text-xl font-medium",t==="black"?"text-foreground":"text-primary-foreground"),children:s})]})}const Nt=R.forwardRef(({className:s,...t},a)=>e.jsx(st.Root,{ref:a,className:v("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...t}));Nt.displayName=st.Root.displayName;const $n=R.forwardRef(({className:s,...t},a)=>e.jsx(st.Image,{ref:a,className:v("aspect-square h-full w-full",s),...t}));$n.displayName=st.Image.displayName;const _n=R.forwardRef(({className:s,...t},a)=>e.jsx(st.Fallback,{ref:a,className:v("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...t}));_n.displayName=st.Fallback.displayName;const da=new Map,Mt=new Map;function Io(s,t){const a=s.trim();if(t==="text")return a;const r=/^```(?:\w+\n)?([\s\S]+)\n```$/,n=a.match(r);return n?n[1].trim():a}const Vn=async(s,t,a,r,n,i=3)=>{const u=`Analyze the following prompt and ${n==="html"?`Provide a helpful, concise response formatted in simple HTML.
|
|
2
2
|
- Use <p> tags for paragraphs.
|
|
3
3
|
- Use <strong> for emphasis.
|
|
4
4
|
- You can also use ordered (<ol>) and unordered (<ul>) lists with list items (<li>).
|
|
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:
|
|
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`
|
|
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.
|
|
@@ -25,12 +25,12 @@ Prompt: "${a}"`;try{return(await s({applicationId:t,body:[{Role:"user",Parts:[{T
|
|
|
25
25
|
\`\`\`json
|
|
26
26
|
${JSON.stringify(t,null,2)}
|
|
27
27
|
\`\`\`
|
|
28
|
-
`}function zn(s){const t=(s??"").trim();if(t)try{return new URL(t).origin}catch{return}}function vt(){const s=Fn();return o.useMemo(()=>zn(s.swaggerJsonUrl)??En,[s.swaggerJsonUrl])}function $s(s,t){const a=(s??"").trim();if(!a)return"";if(a.startsWith("http://")||a.startsWith("https://")||a.startsWith("data:")||a.startsWith("blob:"))return a;const r=zn(t),n=a.startsWith("/")?a:`/${a}`;if(!r)return n;try{return new URL(n,r).toString()}catch{return n}}const hs=R.forwardRef(({className:s,children:t,orientation:a,...r},n)=>e.jsxs(Ls.Root,{ref:n,className:v("relative overflow-hidden",s),...r,children:[e.jsxs(Ls.Viewport,{className:"h-full w-full rounded-[inherit] [&>div]:!block [&>div]:!h-full",children:[" ",t]}),e.jsx(Ut,{orientation:a||"vertical"}),e.jsx(Ls.Corner,{})]}));hs.displayName=Ls.Root.displayName;const Ut=R.forwardRef(({className:s,orientation:t="vertical",...a},r)=>e.jsx(Ls.ScrollAreaScrollbar,{ref:r,orientation:t,className:v("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",s),...a,children:e.jsx(Ls.ScrollAreaThumb,{className:"relative flex-1 rounded-full bg-border"})}));Ut.displayName=Ls.ScrollAreaScrollbar.displayName;function To({appID:s,chats:t,activeChat:a,onSelectChat:r}){return e.jsx("div",{className:"space-y-1.5",children:t.slice().sort((n,i)=>(n.pending?-10:0)+((i.lastMessageTime??"")>(n.lastMessageTime??"")?1:-1)).map(n=>{const i=e.jsx(e.Fragment,{children:e.jsx(us,{id:n.partner1===s?n.partner2:n.partner1,width:72,height:72})});return Lo(n,a,r,i)})})}function Eo(s){if(!s)return"never";const t=new Date(s+"Z");if(Number.isNaN(t.getTime()))return"never";const a=new Date,r=new Date(a.getFullYear(),a.getMonth(),a.getDate()),n=new Date(r);n.setDate(n.getDate()+1);const i=new Date(r);i.setDate(i.getDate()-1);const l=t>=r&&t<n,d=t>=i&&t<r;if(l){const
|
|
29
|
-
`);if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(t),!0}catch{return!1}const a=document.createElement("textarea");a.value=t,a.style.position="fixed",a.style.left="-9999px",document.body.appendChild(a),a.focus(),a.select();const r=document.execCommand("copy");return document.body.removeChild(a),r}function Un(s){const t=cl.marked(s,{async:!1});return dl.sanitize(t,{ALLOWED_TAGS:["h1","h2","h3","h4","h5","h6","b","strong","i","em","u","s","sub","sup","mark","blockquote","q","ul","ol","li","dl","dt","dd","p","div","span","br","hr","table","thead","tbody","tfoot","tr","th","td"]})}function qn(s){const t=new Date(s);return Dr.isToday(t)?t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0}):Dr.isYesterday(t)?`Yesterday, ${t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})}`:`${t.toLocaleDateString([],{month:"short",day:"numeric"})} ${t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})}`}function $o({botStatus:s}){return e.jsx("div",{className:"relative w-full rounded-lg border-l-2 border-primary/40 pr-6 pl-5 py-3",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-150"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-300"})]}),e.jsx("span",{className:"font-medium text-foreground/80",children:s}),e.jsx("span",{className:"ml-auto whitespace-nowrap",children:new Date().toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})})]})})}function _o({botStatus:s}){return e.jsx("div",{className:"flex items-start mt-2 mb-2",children:e.jsx("div",{className:"flex flex-col max-w-[70%]",children:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("div",{className:"rounded-md p-3 break-words bg-background border border-border rounded-tl-none",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-150"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-300"}),e.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:s})]})}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:new Date().toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})})]})})})}const Vo=o.memo(function({message:t,isCurrentUser:a,hideSenderName:r,canEdit:n,canRetry:i,canCopy:l,isCopied:d,isEditing:x,editValue:c,onEditValueChange:u,onStartEdit:m,onCancelEdit:f,onSaveEdit:g,onRetry:b,onCopy:w}){const N=o.useMemo(()=>Un(t.content),[t.content]),j=N.trim().length>0,y=o.useMemo(()=>(t.images??[]).map(S=>{const M=typeof S?.mimeType=="string"?S.mimeType.trim():"",P=typeof S?.base64Data=="string"?S.base64Data.replace(/\s+/g,""):"";return!M.startsWith("image/")||P.length===0?null:`data:${M};base64,${P}`}).filter(S=>!!S),[t.images]);return e.jsx("div",{className:v("group w-full rounded-lg border-l-2 pr-6 pl-5 py-3 transition-colors","hover:bg-primary/5",a?"border-primary":"border-transparent"),children:e.jsxs("div",{className:v("flex gap-3",x&&"w-full"),children:[e.jsxs("div",{className:v("min-w-0 flex-1",x&&"w-full"),children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[!r&&t.senderName?.trim()?e.jsx("p",{className:v("text-sm font-semibold",a?"text-primary":"text-foreground"),children:t.senderName}):e.jsx("span",{className:"sr-only",children:t.senderName}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:qn(t.timestamp)})]}),e.jsxs("div",{className:v("mt-1 break-words text-[15px] leading-relaxed text-foreground","[&_p]:my-2 [&_p]:leading-relaxed first:[&_p]:mt-0 last:[&_p]:mb-0","[&_li]:ml-6 [&_li]:list-disc [&_h1]:text-base [&_h1]:font-semibold [&_h1]:mt-4 [&_h2]:text-base [&_h2]:font-semibold [&_h2]:mt-4 [&_h3]:text-sm [&_h3]:font-semibold [&_h3]:mt-3",x&&"mt-2"),children:[x?e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background p-3",children:[e.jsx(fs,{className:"w-full min-h-14 max-h-[30em] resize-none field-sizing-content bg-background p-2 text-sm text-foreground border-0 shadow-none focus-visible:ring-0",value:c,onChange:k=>u(k.target.value)}),e.jsxs("div",{className:"mt-3 flex justify-end gap-2",children:[e.jsxs(D,{size:"sm",variant:"outline",onClick:f,children:[e.jsx(p.X,{className:"h-4 w-4"})," Cancel"]}),e.jsxs(D,{size:"sm",onClick:g,children:[e.jsx(p.Check,{className:"h-4 w-4"})," Save"]})]})]}):j&&e.jsx("div",{dangerouslySetInnerHTML:{__html:N}}),y.length>0&&e.jsx("div",{className:"mt-3 space-y-3",children:y.map((k,S)=>e.jsx("img",{src:k,alt:`${t.senderName||(a?"User":"Assistant")} image ${S+1}`,className:"max-w-full h-auto rounded-xl border border-border/60 bg-background",loading:"lazy",draggable:!1},`${t.id}-img-${S}`))})]})]}),e.jsxs("div",{className:v("flex items-start gap-1 pt-0.5",l||n||i?"opacity-0 group-hover:opacity-100":"opacity-0","transition-opacity",x&&"opacity-100"),children:[l&&!x&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:w,"aria-label":d?"Copied message":"Copy message",children:d?e.jsx(p.Check,{className:"h-4 w-4"}):e.jsx(p.Copy,{className:"h-4 w-4"})}),(n||i)&&!x&&e.jsxs(e.Fragment,{children:[n&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:m,"aria-label":"Edit message",children:e.jsx(p.Pencil,{className:"h-4 w-4"})}),i&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:b,"aria-label":"Retry message",children:e.jsx(p.RotateCcw,{className:"h-4 w-4"})})]})]})]})})},(s,t)=>s.isCurrentUser===t.isCurrentUser&&s.hideSenderName===t.hideSenderName&&s.canEdit===t.canEdit&&s.canRetry===t.canRetry&&s.canCopy===t.canCopy&&s.isCopied===t.isCopied&&s.isEditing===t.isEditing&&s.editValue===t.editValue&&s.message.id===t.message.id&&s.message.senderName===t.message.senderName&&s.message.content===t.message.content&&s.message.images===t.message.images&&s.message.timestamp===t.message.timestamp&&s.message.fromPartnerID===t.message.fromPartnerID&&s.message.toPartnerID===t.message.toPartnerID),zo=o.memo(function({message:t,isCurrentUser:a,hideSenderName:r,canEdit:n,canRetry:i,canCopy:l,isCopied:d,isEditing:x,editValue:c,onEditValueChange:u,onStartEdit:m,onCancelEdit:f,onSaveEdit:g,onRetry:b,onCopy:w}){const N=o.useMemo(()=>Un(t.content),[t.content]),j=N.trim().length>0,y=o.useMemo(()=>(t.images??[]).map(S=>{const M=typeof S?.mimeType=="string"?S.mimeType.trim():"",P=typeof S?.base64Data=="string"?S.base64Data.replace(/\s+/g,""):"";return!M.startsWith("image/")||P.length===0?null:`data:${M};base64,${P}`}).filter(S=>!!S),[t.images]);return e.jsx("div",{className:v("flex items-start gap-2 mt-2 mb-2",a&&"flex-row-reverse"),children:e.jsxs("div",{className:v("flex flex-col",x?"w-full max-w-none":"max-w-[70%]"),children:[!r&&!!t.senderName?.trim()&&e.jsx("p",{className:v("mb-1 flex",a&&"flex-row-reverse"),children:t.senderName}),e.jsxs("div",{className:v("flex items-baseline gap-2",a&&"flex-row-reverse",x&&"w-full"),children:[e.jsxs("div",{className:v("rounded-md p-3 break-words [&_li]:ml-6 [&_li]:list-disc [&_h1]:text-lg [&_h1]:font-bold [&_h1]:mt-4 [&_h2]:font-bold [&_h2]:mt-4 [&_h3]:mt-4 ",x&&"flex-1 w-full",x?a?"bg-background border border-border text-foreground rounded-tr-none":"bg-background border border-border rounded-tl-none":a?"bg-primary text-primary-foreground rounded-tr-none":"bg-background border border-border rounded-tl-none"),children:[x?e.jsxs("div",{children:[e.jsx(fs,{className:"w-full min-h-14 max-h-[30em] resize-none field-sizing-content bg-background p-2 text-sm text-foreground",value:c,onChange:k=>u(k.target.value)}),e.jsxs("div",{className:"mt-2 flex justify-end gap-2",children:[e.jsxs(D,{size:"sm",variant:"outline",onClick:f,children:[e.jsx(p.X,{className:"h-4 w-4"})," Cancel"]}),e.jsxs(D,{size:"sm",onClick:g,children:[e.jsx(p.Check,{className:"h-4 w-4"})," Save"]})]})]}):j&&e.jsx("div",{dangerouslySetInnerHTML:{__html:N}}),y.length>0&&e.jsx("div",{className:"mt-2 space-y-2",children:y.map((k,S)=>e.jsx("img",{src:k,alt:`${t.senderName||(a?"User":"Assistant")} image ${S+1}`,className:"max-w-full h-auto rounded-md border border-border bg-background",loading:"lazy",draggable:!1},`${t.id}-img-${S}`))})]}),e.jsxs("div",{className:v("flex items-center gap-1",a&&"flex-row-reverse"),children:[l&&!x&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:w,"aria-label":d?"Copied message":"Copy message",children:d?e.jsx(p.Check,{className:"h-4 w-4"}):e.jsx(p.Copy,{className:"h-4 w-4"})}),(n||i)&&!x&&e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[n&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:m,"aria-label":"Edit message",children:e.jsx(p.Pencil,{className:"h-4 w-4"})}),i&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:b,"aria-label":"Retry message",children:e.jsx(p.RotateCcw,{className:"h-4 w-4"})})]}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:qn(t.timestamp)})]})]})]})},t.id)},(s,t)=>s.isCurrentUser===t.isCurrentUser&&s.hideSenderName===t.hideSenderName&&s.canEdit===t.canEdit&&s.canRetry===t.canRetry&&s.canCopy===t.canCopy&&s.isCopied===t.isCopied&&s.isEditing===t.isEditing&&s.editValue===t.editValue&&s.message.id===t.message.id&&s.message.senderName===t.message.senderName&&s.message.content===t.message.content&&s.message.images===t.message.images&&s.message.timestamp===t.message.timestamp&&s.message.fromPartnerID===t.message.fromPartnerID&&s.message.toPartnerID===t.message.toPartnerID),Qn=o.memo(function({messages:t,appID:a,botStatus:r,isAssistantChat:n,variant:i,hideSenderNames:l=!1,editableUserMessages:d=!1,editingMessageId:x=null,editingDraft:c="",onEditingDraftChange:u=()=>{},onStartEditUserMessage:m,onCancelEditUserMessage:f,onSaveEditUserMessage:g,onRetryUserMessage:b}){const[w,N]=o.useState(null),j=o.useRef(null);o.useEffect(()=>()=>{j.current!=null&&window.clearTimeout(j.current)},[]);const y=o.useCallback(async(A,T)=>{await Bo(T)&&(N(A),j.current!=null&&window.clearTimeout(j.current),j.current=window.setTimeout(()=>N(null),2e3))},[]),k=o.useMemo(()=>{const A=new Set;let T=null;for(const E of t){const I=(E.senderName??"").trim();I&&(T===I?A.add(E.id):T=I)}return A},[t]),S=i??(n?"assistant":"dashboard"),M=S==="assistant"?zo:Vo,P=S==="assistant"?_o:$o;return e.jsxs("div",{className:S==="dashboard"?"py-3":"",children:[t.map(A=>{const T=A.fromPartnerID===a,E=!!(d&&n&&T&&m&&g&&f),I=!!(d&&n&&T&&b),F=!!(n&&!T&&(A.content??"").trim().length>0),$=x===A.id;return e.jsx(M,{message:A,isCurrentUser:T,hideSenderName:l||k.has(A.id),canEdit:E,canRetry:I,canCopy:F,isCopied:w===A.id,isEditing:$,editValue:$?c:"",onEditValueChange:u,onStartEdit:()=>m?.(A),onCancelEdit:()=>f?.(),onSaveEdit:()=>g?.(A.id,c),onRetry:()=>b?.(A),onCopy:()=>{y(A.id,A.content)}},A.id)}),r!==""&&e.jsx(P,{botStatus:r}),t.length===0&&!n&&e.jsxs("div",{className:"mt-1 text-xl",children:[e.jsx(p.Send,{className:"w-full h-32"}),e.jsx("p",{className:"text-center",children:"No messages yet... Say hello!"})]})]})});function Uo({activeChat:s,activeChatObj:t,appID:a,messagesEndRef:r,inputRef:n,content:i,setContent:l,handleSendMessage:d,isPostBizDevConvoLoading:x,acceptChat:c}){return e.jsx("div",{className:"flex-5 flex flex-col min-w-0 bg-background",children:s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-border/60",children:[e.jsx(Nt,{className:"h-8 w-8 flex-shrink-0 rounded-lg",children:e.jsx(us,{id:s[0]===a?s[1]:s[0],width:72,height:72})}),e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"truncate text-sm font-semibold",children:t?.name})})]}),t?.pending&&t.partner1==a?e.jsx("p",{className:"mx-auto mt-12 max-w-md px-6 text-center text-sm text-muted-foreground",children:"This conversation is awaiting approval by the other party — please check back later."}):e.jsxs(e.Fragment,{children:[e.jsxs(hs,{className:"flex-1 bg-background",children:[e.jsx("div",{className:t?.messages===null?"opacity-0":"",children:e.jsx(Qn,{messages:t?.messages??[],appID:a,isAssistantChat:!1,botStatus:""})}),e.jsx("div",{ref:r})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-border/60 flex items-end gap-3",children:[t?.pending&&e.jsxs(e.Fragment,{children:[e.jsxs(D,{disabled:x,onClick:()=>c(),children:[e.jsx(p.HandshakeIcon,{}),"Accept Conversation Request"]}),e.jsxs(D,{disabled:!0,className:"ml-2",children:[e.jsx(p.ThumbsDownIcon,{}),"Block Partner"]})]}),e.jsx(fs,{ref:n,placeholder:"Type a message...",value:i,onChange:u=>l(u.target.value),onKeyDown:u=>{u.key!=="Enter"||u.shiftKey||(u.preventDefault(),d())},className:t?.pending?"collapse":"flex-1 resize-none field-sizing-content max-h-[30em] rounded-xl border border-border/60 bg-muted/20 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",disabled:t?.pending}),e.jsx("div",{className:"flex items-center",children:e.jsx(D,{size:"icon",variant:"default",className:t?.pending?"collapse":"h-10 w-10 rounded-xl",disabled:t?.pending,onClick:d,children:e.jsx(p.Send,{className:"h-6 w-6"})})})]})]})]}):e.jsxs("div",{className:"flex flex-col m-auto text-xl",children:[e.jsx(p.MousePointerClick,{className:"w-full h-32"}),e.jsx("p",{children:"Select a chat from the left menu to start messaging"})]})})}function qo({activeChatObj:s,appID:t,sendChatToAssistant:a,isAnalyzingPartnership:r,analyzePartnership:n}){const i=s?[s.partner1,s.partner2]:void 0;return e.jsx("aside",{className:"w-[340px] shrink-0 border-l border-border/60 bg-background",children:e.jsxs("div",{className:"h-full flex flex-col gap-7 px-5 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Actions"}),e.jsx(ve.Link,{className:"block",inert:i===void 0,to:`/${t}/Partner/${i?.[0]===t?i[1]:i?.[0]}`,children:e.jsxs(D,{variant:"ghost",className:"w-full justify-start px-2",disabled:i===void 0,children:[e.jsx(p.ExternalLink,{className:"h-4 w-4"}),"View Partner"]})}),e.jsxs(D,{variant:"ghost",className:"w-full justify-start px-2",disabled:(s?.messages??[]).length<1,onClick:()=>a(s.messages),children:[e.jsx(p.Bot,{className:"h-4 w-4"}),"Export to Randmar Assistant"]}),e.jsx(D,{className:"w-full",disabled:i===void 0||r,onClick:n,children:r?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Analyzing..."]}):"Analyze Partnership"})]}),e.jsx(nn,{userId:t,partnerId:i?.[0]===t?i[1]:i?.[0]||"",isAdmin:!1}),e.jsx(Qo,{appID:t,activeChatObj:s}),e.jsx(Ho,{appID:t,activeChatObj:s})]})})}const Qo=({appID:s,activeChatObj:t})=>{const a=t?.conversationID??-1,r=!t||a===-1,{data:n,isLoading:i,isError:l,refetch:d,isFetching:x}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdPeopleQuery({routeApplicationId:s,conversationId:a},{skip:r}),c=n??[];return e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"People"}),r?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a chat to see participants."}):i||x?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading people..."}):l?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Could not load people."}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>d(),children:"Retry"})]}):c.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No participants found."}):e.jsx("ul",{className:"flex flex-col gap-1",children:c.map((u,m)=>{const f=u.ApplicationId??`${u.Name??"person"}-${m}`,g=u.LastAuthentication?new Date(u.LastAuthentication).toLocaleString():void 0;return e.jsxs("li",{className:"rounded-lg px-2 py-2 text-sm hover:bg-primary/5",children:[e.jsx("p",{className:"font-medium leading-tight",children:u.Name??"Unknown person"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u.Role??"Role unavailable"}),g?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last auth ",g]}):null]},f)})})]})},Ho=({appID:s,activeChatObj:t})=>{const[a,r]=o.useState(!1),n=t?.conversationID,i=n===void 0||n===-1,{data:l,isLoading:d}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdLinksQuery({routeApplicationId:s,conversationId:n??-1},{skip:i}),[x]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdLinkMutation(),[c]=_.useDeleteV4PartnerByRouteApplicationIdBusinessDevelopmentConversationLinkAndLinkIdMutation();return e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Links"}),e.jsxs("div",{className:"flex flex-col gap-1",children:[d?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading links..."}):l?.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No links attached."}):null,l?.map(u=>e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg px-2 py-2 hover:bg-primary/5",children:[e.jsx("a",{href:u.URL,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline underline-offset-4 break-all",children:u.Title}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>c({routeApplicationId:s,linkId:u.LinkId}),"aria-label":"Delete link",children:e.jsx(p.Trash2,{className:"h-4 w-4"})})]},u.LinkId))]}),e.jsxs(Ie,{open:a,onOpenChange:r,children:[e.jsx(Os.DialogTrigger,{asChild:!0,children:e.jsxs(D,{variant:"link",className:"h-auto p-0 justify-start",disabled:i,children:[e.jsx(p.Plus,{className:"h-4 w-4"}),"Add link"]})}),e.jsxs(De,{children:[e.jsxs(Le,{children:[e.jsx(Os.DialogTitle,{children:"Add Link"}),e.jsx(Os.DialogDescription,{children:"Please enter the details for the new link."})]}),e.jsxs("form",{className:"space-y-4",onSubmit:u=>{u.preventDefault();const m=document.getElementById("link-title").value,f=document.getElementById("link-url").value;n===void 0||n===-1||(x({routeApplicationId:s,conversationId:n,createLinkRequest:{Title:m,Url:f}}),r(!1))},children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"link-title",children:"Title"}),e.jsx(ie,{id:"link-title",required:!0,minLength:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"link-url",children:"URL"}),e.jsx(ie,{id:"link-url",type:"url",required:!0,minLength:2,placeholder:"https://"})]}),e.jsx(D,{type:"submit",disabled:i,children:"Add Link"})]})]})]})]})},Go=s=>{const[t]=_.usePostV4UserByFieldNameMutation(),[a,r]=o.useState(""),[n,i]=o.useState(""),[l,d]=o.useState(!1),[x]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation();return e.jsxs("div",{className:"mx-auto mt-2",children:[e.jsx("p",{className:"mb-4",children:"Before you can start chatting, please set up your profile."}),e.jsxs("form",{className:"space-y-2",onSubmit:c=>{l||(d(!0),c.preventDefault(),t({fieldName:"Name",newValue:a}).then(()=>{x({routeApplicationId:s.appID,partnerId:"2"})}),t({fieldName:"Role",newValue:n}))},children:[e.jsx(J,{htmlFor:"name",children:"Name"}),e.jsx(ie,{id:"name",required:!0,minLength:2,value:a,onChange:c=>r(c.target.value)}),e.jsx(J,{htmlFor:"role",children:"Role"}),e.jsx(ie,{id:"role",required:!0,minLength:2,value:n,onChange:c=>i(c.target.value)}),e.jsx(D,{type:"submit",disabled:l,children:l?"Saving...":"Save"})]})]})},xt=(s,t)=>s.unread>0&&t.unread===0?-1:t.unread>0&&s.unread===0?1:s.name.localeCompare(t.name);function Wo({appID:s,inputRef:t,className:a}){const{setHasUnreads:r}=Js(),n=vt(),{data:i,refetch:l}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationsQuery({routeApplicationId:s}),[d,x]=o.useState(!1),[c,u]=o.useState(!1),[m,f]=o.useState(!1),[g,{isLoading:b}]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),w=o.useRef(null),[N]=_.useLazyGetV4PartnerByApplicationIdAccountQuery(),{sendPrompt:j}=Do({applicationId:s,outputFormat:"text",useProModel:!0}),[y,k]=o.useState(!1),[S]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),[M]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdReadMutation(),[P]=_.useLazyGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdMessagesQuery(),[A]=_.useLazyGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery(),[T,E]=o.useState(!1);o.useEffect(()=>{i&&(K(Q=>{const ee=i.map(ne=>{const he=Q.find(ke=>ke.conversationID===ne.ConversationId);return{partner1:ne.Participant1,partner2:ne.Participant2,name:ne.Participant?.PublicName??"missing public name",unread:he?.unread??0,pending:ne.Status!=="Approved",messages:he?.messages??null,conversationID:ne.ConversationId,lastMessageTime:ne.LastMessageTime??null}});return ee.sort(xt),ee}),x(!0),setTimeout(()=>ue.current?.focus(),50))},[i,s]);const[I,F]=o.useState(void 0),[$,V]=o.useState(""),[z,O]=o.useState(null),[H,K]=o.useState([]),[de,Me]=o.useState(null),qe=o.useRef(null),Z=o.useRef(null),[X,se]=o.useState([]),ue=t||Z,q=o.useRef(null),{toast:te}=Ce(),le=()=>H.find(Q=>Q.partner1===I?.[0]&&Q.partner2===I?.[1]),Ne=o.useCallback(async()=>{if(c)return;u(!0);const Q=I;try{se([]),O(null);const he=((await l()).data??[]).map(Re=>({partner1:Re.Participant1,partner2:Re.Participant2,name:Re.Participant?.PublicName??"missing public name",unread:0,pending:Re.Status!=="Approved",messages:null,conversationID:Re.ConversationId,lastMessageTime:Re.LastMessageTime??null})),ke=new Map;await Promise.allSettled(he.map(async Re=>{if(Re.conversationID<=0)return;const Ds=((await P({routeApplicationId:s,conversationId:Re.conversationID})).data??[]).reduce((zs,lt)=>lt.Read||!lt.SenderId||lt.SenderId===s?zs:zs+1,0);ke.set(Re.conversationID,Ds)}));const ts=he.map(Re=>({...Re,unread:ke.get(Re.conversationID)??0})).sort(xt);if(K(ts),Q){const Re=ts.find(Ee=>Ee.partner1===Q[0]&&Ee.partner2===Q[1]||Ee.partner1===Q[1]&&Ee.partner2===Q[0]);F(Re?[Re.partner1,Re.partner2]:void 0)}te({title:"Refreshed",description:"Chat state reinitialized."})}catch(ee){console.error("Error refreshing chat state:",ee),te({title:"Refresh failed",description:"Could not refresh chat state. Please try again.",variant:"destructive"})}finally{u(!1)}},[I,s,P,c,l,te]),Fe=o.useCallback(async()=>{if(!m){f(!0);try{const Q=H.map(ee=>ee.conversationID).filter(ee=>ee>0);await Promise.allSettled(Q.map(async ee=>{await M({routeApplicationId:s,conversationId:ee}).unwrap()})),K(ee=>ee.map(ne=>({...ne,unread:0})).sort(xt)),te({title:"All read",description:"All conversations marked as read."})}catch(Q){console.error("Error marking all conversations as read:",Q),te({title:"Action failed",description:"Could not mark all conversations as read. Please try again.",variant:"destructive"})}finally{f(!1)}}},[s,H,m,M,te]);function xe(){const Q=le();Q&&M({routeApplicationId:s,conversationId:Q.conversationID})}const Te=Q=>se(ee=>[...ee,Q]);o.useEffect(()=>{if(X.length==0)return;console.log(X.length,"unprocessedMessages detected");const Q=(ne,he)=>he.partner1===ne.toPartnerID&&he.partner2===ne.fromPartnerID||he.partner2===ne.toPartnerID&&he.partner1===ne.fromPartnerID;let ee=!1;X.forEach(ne=>{if(!H.some(he=>Q(ne,he))){console.log("message received for unknown convo ID - need to refetch!"),ee=!0;return}K(he=>he.map(ke=>{if(!Q(ne,ke))return ke;const ts=ke.messages??[];if(ts.some(Ds=>Ds.id===ne.id))return ke;let Re=1;const Ee=document.activeElement&&document.activeElement===ue.current;return I?.[0]==ke.partner1&&I[1]==ke.partner2&&Ee&&(Ee&&(Re=0,xe()),setTimeout(()=>qe.current?.scrollIntoView({behavior:"smooth"}),50)),{...ke,pending:!1,unread:ke.unread+Re,messages:[...ts,ne]}}).sort(xt))}),console.log("need refetch:",ee),ee&&l(),se([])},[X,se,K,F,I]),o.useEffect(()=>{const Q=new ia.HubConnectionBuilder().withUrl($s("/hub",n),{accessTokenFactory:()=>localStorage.getItem("access_token"),headers:{"X-Impersonated-Id":s}}).configureLogging(ia.LogLevel.Information).withAutomaticReconnect().withHubProtocol(new ia.JsonHubProtocol).build();return Q.on("ReceiveMessage",Te),Q.start().catch(ee=>console.error("Error connecting to SignalR hub:",ee)),Me(Q),()=>{Q&&Q.stop()}},[s,n]),o.useEffect(()=>{!I||!le()||(ue.current?.focus(),setTimeout(()=>qe.current?.scrollIntoView({behavior:"smooth"}),50))},[I]),o.useEffect(()=>{if(!I)return;const Q=le();Q&&Q.conversationID!==-1&&(async()=>{try{const ne=(await P({routeApplicationId:s,conversationId:Q.conversationID})).data?.map(he=>({id:"history"+he.MessageId,fromPartnerID:he.SenderId,toPartnerID:he.SenderId==Q.partner1?Q.partner2:Q.partner1,senderName:he.SenderName??"missing name",timestamp:new Date(he.SentDate+"Z").getTime(),content:he.Content??"no content"}))??[];K(he=>he.map(ke=>ke.conversationID===Q.conversationID?{...ke,messages:ne}:ke).sort(xt))}catch(ee){console.error("Error fetching conversation messages:",ee)}})()},[I,P,s]),o.useEffect(()=>{if(!I)return;const Q=le();if(!Q)return;const ee=document.activeElement&&document.activeElement===ue.current;Q.unread>0&&ee&&(xe(),K(ne=>ne.map(he=>he.partner1===I[0]&&he.partner2===I[1]?{...he,unread:0}:he)))},[I,H]);const{sendMessage:Pe}=Js(),Ye=o.useCallback(Q=>{Pe(`We have been talking with another Randmar partner and would like you to have the conversation as context for follow-up questions. Please acknowledge your reception of this chat history (one line summary of recent messages will do) and let me know that you're ready to answer questions: ${JSON.stringify(Q,null,2)}`)},[Pe]),Je=o.useCallback(async()=>{if(I)try{E(!0);const Q=await N({applicationId:s}),ee=I[0]===s?I[1]:I[0],ne=await A({routeApplicationId:s,partnerId:ee,withSpecification:!0}),he=Mo(Q.data,ne.data);he?Pe(he):te({title:"Missing data",description:"We couldn't load enough data to analyze this partnership yet. Please try again shortly.",variant:"destructive"})}catch(Q){console.error("Error preparing partnership analysis:",Q),te({title:"Error",description:"Could not analyze the partnership. Please try again later.",variant:"destructive"})}finally{E(!1)}},[I,N,A,Pe,te,s]);o.useEffect(()=>{r(H.some(Q=>Q.unread>0))},[H,r]);const W=(Q,ee)=>{ee=ee.replace(/\n/g,`
|
|
30
|
-
`),console.log("doSend",ee),console.log("target",
|
|
28
|
+
`}function zn(s){const t=(s??"").trim();if(t)try{return new URL(t).origin}catch{return}}function vt(){const s=Fn();return o.useMemo(()=>zn(s.swaggerJsonUrl)??En,[s.swaggerJsonUrl])}function $s(s,t){const a=(s??"").trim();if(!a)return"";if(a.startsWith("http://")||a.startsWith("https://")||a.startsWith("data:")||a.startsWith("blob:"))return a;const r=zn(t),n=a.startsWith("/")?a:`/${a}`;if(!r)return n;try{return new URL(n,r).toString()}catch{return n}}const hs=R.forwardRef(({className:s,children:t,orientation:a,...r},n)=>e.jsxs(Ls.Root,{ref:n,className:v("relative overflow-hidden",s),...r,children:[e.jsxs(Ls.Viewport,{className:"h-full w-full rounded-[inherit] [&>div]:!block [&>div]:!h-full",children:[" ",t]}),e.jsx(Ut,{orientation:a||"vertical"}),e.jsx(Ls.Corner,{})]}));hs.displayName=Ls.Root.displayName;const Ut=R.forwardRef(({className:s,orientation:t="vertical",...a},r)=>e.jsx(Ls.ScrollAreaScrollbar,{ref:r,orientation:t,className:v("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",s),...a,children:e.jsx(Ls.ScrollAreaThumb,{className:"relative flex-1 rounded-full bg-border"})}));Ut.displayName=Ls.ScrollAreaScrollbar.displayName;function To({appID:s,chats:t,activeChat:a,onSelectChat:r}){return e.jsx("div",{className:"space-y-1.5",children:t.slice().sort((n,i)=>(n.pending?-10:0)+((i.lastMessageTime??"")>(n.lastMessageTime??"")?1:-1)).map(n=>{const i=e.jsx(e.Fragment,{children:e.jsx(us,{id:n.partner1===s?n.partner2:n.partner1,width:72,height:72})});return Lo(n,a,r,i)})})}function Eo(s){if(!s)return"never";const t=new Date(s+"Z");if(Number.isNaN(t.getTime()))return"never";const a=new Date,r=new Date(a.getFullYear(),a.getMonth(),a.getDate()),n=new Date(r);n.setDate(n.getDate()+1);const i=new Date(r);i.setDate(i.getDate()-1);const l=t>=r&&t<n,d=t>=i&&t<r;if(l){const u=a.getTime()-t.getTime();return u>=0&&u<15e3?"a few seconds ago":u>=0&&t.getHours()===a.getHours()?"earlier this hour":"earlier today"}return d?"yesterday":t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Oo(s,t){return s?s[0]===t[0]&&s[1]===t[1]||s[0]===t[1]&&s[1]===t[0]:!1}function Lo(s,t,a,r){return e.jsxs("button",{className:v("relative w-full flex items-center gap-3 rounded-xl px-3 py-2.5 text-left transition-colors","hover:bg-primary/5",Oo(t,[s.partner1,s.partner2])&&"bg-primary/10 before:content-[''] before:absolute before:left-1 before:top-2 before:bottom-2 before:w-1 before:rounded-full before:bg-primary",s.pending?"bg-primary/5":""),onClick:()=>a([s.partner1,s.partner2]),children:[e.jsx(Nt,{className:"h-8 w-8 flex-shrink-0 rounded-lg",children:s.pending?e.jsx(g.MessageSquareLock,{className:"h-4 w-4 text-primary"}):e.jsx(e.Fragment,{children:r})}),e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsx("div",{className:"text-xs text-muted-foreground truncate text-ellipsis",children:Eo(s.lastMessageTime)})]}),s.unread>0&&e.jsx("div",{className:"ml-auto min-w-5 px-1 bg-destructive text-destructive-foreground text-[11px] rounded-full h-5 flex items-center justify-center",children:s.unread})]},s.partner1+" and "+s.partner2)}const at=R.forwardRef(({className:s,...t},a)=>e.jsx(Na.Root,{className:v("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-hidden 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=unchecked]:bg-input",s),...t,ref:a,children:e.jsx(Na.Thumb,{className:v("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));at.displayName=Na.Root.displayName;function Fo({appID:s,chats:t,chatWithRandmarButton:a,isStartingChat:r,isRefreshingChats:n,isMarkingAllRead:i,handleChatWithRandmar:l,onFullRefreshChats:d,onMarkAllRead:u,setActiveChat:m,activeChat:h}){const[c,y]=o.useState(""),[p,x]=o.useState(null),[w,N]=o.useState(null),j=o.useMemo(()=>t.filter(U=>{const V=s===U.partner1?U.partner2:U.partner1;return U.name.toLowerCase().includes(c.toLowerCase())||V.toLocaleLowerCase().includes(c.toLowerCase())}),[s,t,c]),{toast:b}=Ce(),{data:k,isLoading:S}=_.useGetV4UserQuery(),M=k?.Name||k?.EmailAddress||"User",A=k?.Role||"Partner",[P]=_.usePostV4UserByFieldNameMutation(),[E]=_.usePutV4PartnerByRouteApplicationIdUserAndEmailAddressNotificationNotificationTypeMutation(),[T]=_.useDeleteV4PartnerByRouteApplicationIdUserAndEmailAddressNotificationNotificationTypeMutation(),I=U=>{if(!k?.ApplicationId||!k.EmailAddress){b({title:"Not ready",description:"Please wait for your user profile to finish loading.",variant:"destructive"});return}U?E({routeApplicationId:k.ApplicationId,emailAddress:k.EmailAddress,notificationType:"PartnerChatNotifications"}):T({routeApplicationId:k.ApplicationId,emailAddress:k.EmailAddress,notificationType:"PartnerChatNotifications"})};o.useEffect(()=>{p===null&&M&&x(M)},[p,M]),o.useEffect(()=>{w===null&&A&&N(A)},[w,A]);const B=()=>{p&&p!==M&&p.trim()!==""&&P({fieldName:"Name",newValue:p}).unwrap().then(()=>{b({title:"Success",description:"Name updated successfully"})})},F=()=>{w&&w!==A&&w.trim()!==""&&P({fieldName:"Role",newValue:w}).unwrap().then(()=>{b({title:"Success",description:"Role updated successfully"})})};return e.jsxs("div",{className:"w-[300px] shrink-0 px-4 py-4 flex flex-col border-r border-border/60 bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 pb-3",children:[e.jsx("span",{className:"text-sm font-semibold tracking-tight",children:"Communications"}),e.jsx(ye,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{type:"button",variant:"ghost",size:"icon","aria-label":"Refresh chat state",disabled:!!n||!!r,onClick:d,children:n?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.RefreshCw,{className:"h-4 w-4"})})}),e.jsx(pe,{side:"bottom",className:"bg-popover text-popover-foreground",children:"Full refresh"})]}),e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{type:"button",variant:"ghost",size:"icon","aria-label":"Mark all messages as read",disabled:!!i||!!r||t.length===0,onClick:u,children:i?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.CheckCheck,{className:"h-4 w-4"})})}),e.jsx(pe,{side:"bottom",className:"bg-popover text-popover-foreground",children:"Mark all read"})]})]})})]}),t.length>1&&e.jsx(e.Fragment,{children:e.jsx("div",{className:"px-2 pb-3",children:e.jsxs("div",{className:"relative",children:[e.jsx(g.Search,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"Search chats...",className:"h-10 pl-8 rounded-xl bg-muted/40 border-transparent shadow-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:c,onChange:U=>y(U.target.value)})]})})}),e.jsx("div",{className:"mt-1 mb-1",children:t.findIndex(U=>U.partner1==="2"||U.partner2==="2")<0?e.jsx(D,{className:"w-full rounded-xl",ref:a,disabled:r,onClick:l,children:r?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Starting Chat..."]}):"Chat with Randmar"},"b1"):null}),e.jsx(hs,{className:"flex-1",children:t.length>0&&e.jsx(To,{appID:s,chats:j,activeChat:h,onSelectChat:m})}),e.jsx(yt,{className:"mt-4"}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Name"}),e.jsx(le,{value:p??"",onChange:U=>x(U.target.value),onBlur:B,className:"mt-1 h-8 border-0 bg-transparent px-0 text-sm font-medium shadow-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Role"}),e.jsx(le,{value:w??"",onChange:U=>N(U.target.value),onBlur:F,className:"mt-1 h-8 border-0 bg-transparent px-0 text-sm font-medium shadow-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Email notifications"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Conversation updates"})]}),e.jsx(at,{disabled:S||!k,onCheckedChange:I,checked:k?.Notifications?.find(U=>U.NotificationType==="PartnerChatNotifications")!==void 0})]})]})]})}const fs=R.forwardRef(({className:s,...t},a)=>e.jsx("textarea",{className:v("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs 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 md:text-sm",s),ref:a,...t}));fs.displayName="Textarea";async function Bo(s){const t=s.replace(/ {2}\n/g,`
|
|
29
|
+
`);if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(t),!0}catch{return!1}const a=document.createElement("textarea");a.value=t,a.style.position="fixed",a.style.left="-9999px",document.body.appendChild(a),a.focus(),a.select();const r=document.execCommand("copy");return document.body.removeChild(a),r}function Un(s){const t=cl.marked(s,{async:!1});return dl.sanitize(t,{ALLOWED_TAGS:["h1","h2","h3","h4","h5","h6","b","strong","i","em","u","s","sub","sup","mark","blockquote","q","ul","ol","li","dl","dt","dd","p","div","span","br","hr","table","thead","tbody","tfoot","tr","th","td"]})}function qn(s){const t=new Date(s);return Dr.isToday(t)?t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0}):Dr.isYesterday(t)?`Yesterday, ${t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})}`:`${t.toLocaleDateString([],{month:"short",day:"numeric"})} ${t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})}`}function $o({botStatus:s}){return e.jsx("div",{className:"relative w-full rounded-lg border-l-2 border-primary/40 pr-6 pl-5 py-3",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-150"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-300"})]}),e.jsx("span",{className:"font-medium text-foreground/80",children:s}),e.jsx("span",{className:"ml-auto whitespace-nowrap",children:new Date().toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})})]})})}function _o({botStatus:s}){return e.jsx("div",{className:"flex items-start mt-2 mb-2",children:e.jsx("div",{className:"flex flex-col max-w-[70%]",children:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("div",{className:"rounded-md p-3 break-words bg-background border border-border rounded-tl-none",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-150"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-primary animate-pulse delay-300"}),e.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:s})]})}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:new Date().toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0})})]})})})}const Vo=o.memo(function({message:t,isCurrentUser:a,hideSenderName:r,canEdit:n,canRetry:i,canCopy:l,isCopied:d,isEditing:u,editValue:m,onEditValueChange:h,onStartEdit:c,onCancelEdit:y,onSaveEdit:p,onRetry:x,onCopy:w}){const N=o.useMemo(()=>Un(t.content),[t.content]),j=N.trim().length>0,b=o.useMemo(()=>(t.images??[]).map(S=>{const M=typeof S?.mimeType=="string"?S.mimeType.trim():"",A=typeof S?.base64Data=="string"?S.base64Data.replace(/\s+/g,""):"";return!M.startsWith("image/")||A.length===0?null:`data:${M};base64,${A}`}).filter(S=>!!S),[t.images]);return e.jsx("div",{className:v("group w-full rounded-lg border-l-2 pr-6 pl-5 py-3 transition-colors","hover:bg-primary/5",a?"border-primary":"border-transparent"),children:e.jsxs("div",{className:v("flex gap-3",u&&"w-full"),children:[e.jsxs("div",{className:v("min-w-0 flex-1",u&&"w-full"),children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[!r&&t.senderName?.trim()?e.jsx("p",{className:v("text-sm font-semibold",a?"text-primary":"text-foreground"),children:t.senderName}):e.jsx("span",{className:"sr-only",children:t.senderName}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:qn(t.timestamp)})]}),e.jsxs("div",{className:v("mt-1 break-words text-[15px] leading-relaxed text-foreground","[&_p]:my-2 [&_p]:leading-relaxed first:[&_p]:mt-0 last:[&_p]:mb-0","[&_li]:ml-6 [&_li]:list-disc [&_h1]:text-base [&_h1]:font-semibold [&_h1]:mt-4 [&_h2]:text-base [&_h2]:font-semibold [&_h2]:mt-4 [&_h3]:text-sm [&_h3]:font-semibold [&_h3]:mt-3",u&&"mt-2"),children:[u?e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background p-3",children:[e.jsx(fs,{className:"w-full min-h-14 max-h-[30em] resize-none field-sizing-content bg-background p-2 text-sm text-foreground border-0 shadow-none focus-visible:ring-0",value:m,onChange:k=>h(k.target.value)}),e.jsxs("div",{className:"mt-3 flex justify-end gap-2",children:[e.jsxs(D,{size:"sm",variant:"outline",onClick:y,children:[e.jsx(g.X,{className:"h-4 w-4"})," Cancel"]}),e.jsxs(D,{size:"sm",onClick:p,children:[e.jsx(g.Check,{className:"h-4 w-4"})," Save"]})]})]}):j&&e.jsx("div",{dangerouslySetInnerHTML:{__html:N}}),b.length>0&&e.jsx("div",{className:"mt-3 space-y-3",children:b.map((k,S)=>e.jsx("img",{src:k,alt:`${t.senderName||(a?"User":"Assistant")} image ${S+1}`,className:"max-w-full h-auto rounded-xl border border-border/60 bg-background",loading:"lazy",draggable:!1},`${t.id}-img-${S}`))})]})]}),e.jsxs("div",{className:v("flex items-start gap-1 pt-0.5",l||n||i?"opacity-0 group-hover:opacity-100":"opacity-0","transition-opacity",u&&"opacity-100"),children:[l&&!u&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:w,"aria-label":d?"Copied message":"Copy message",children:d?e.jsx(g.Check,{className:"h-4 w-4"}):e.jsx(g.Copy,{className:"h-4 w-4"})}),(n||i)&&!u&&e.jsxs(e.Fragment,{children:[n&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:c,"aria-label":"Edit message",children:e.jsx(g.Pencil,{className:"h-4 w-4"})}),i&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:x,"aria-label":"Retry message",children:e.jsx(g.RotateCcw,{className:"h-4 w-4"})})]})]})]})})},(s,t)=>s.isCurrentUser===t.isCurrentUser&&s.hideSenderName===t.hideSenderName&&s.canEdit===t.canEdit&&s.canRetry===t.canRetry&&s.canCopy===t.canCopy&&s.isCopied===t.isCopied&&s.isEditing===t.isEditing&&s.editValue===t.editValue&&s.message.id===t.message.id&&s.message.senderName===t.message.senderName&&s.message.content===t.message.content&&s.message.images===t.message.images&&s.message.timestamp===t.message.timestamp&&s.message.fromPartnerID===t.message.fromPartnerID&&s.message.toPartnerID===t.message.toPartnerID),zo=o.memo(function({message:t,isCurrentUser:a,hideSenderName:r,canEdit:n,canRetry:i,canCopy:l,isCopied:d,isEditing:u,editValue:m,onEditValueChange:h,onStartEdit:c,onCancelEdit:y,onSaveEdit:p,onRetry:x,onCopy:w}){const N=o.useMemo(()=>Un(t.content),[t.content]),j=N.trim().length>0,b=o.useMemo(()=>(t.images??[]).map(S=>{const M=typeof S?.mimeType=="string"?S.mimeType.trim():"",A=typeof S?.base64Data=="string"?S.base64Data.replace(/\s+/g,""):"";return!M.startsWith("image/")||A.length===0?null:`data:${M};base64,${A}`}).filter(S=>!!S),[t.images]);return e.jsx("div",{className:v("flex items-start gap-2 mt-2 mb-2",a&&"flex-row-reverse"),children:e.jsxs("div",{className:v("flex flex-col",u?"w-full max-w-none":"max-w-[70%]"),children:[!r&&!!t.senderName?.trim()&&e.jsx("p",{className:v("mb-1 flex",a&&"flex-row-reverse"),children:t.senderName}),e.jsxs("div",{className:v("flex items-baseline gap-2",a&&"flex-row-reverse",u&&"w-full"),children:[e.jsxs("div",{className:v("rounded-md p-3 break-words [&_li]:ml-6 [&_li]:list-disc [&_h1]:text-lg [&_h1]:font-bold [&_h1]:mt-4 [&_h2]:font-bold [&_h2]:mt-4 [&_h3]:mt-4 ",u&&"flex-1 w-full",u?a?"bg-background border border-border text-foreground rounded-tr-none":"bg-background border border-border rounded-tl-none":a?"bg-primary text-primary-foreground rounded-tr-none":"bg-background border border-border rounded-tl-none"),children:[u?e.jsxs("div",{children:[e.jsx(fs,{className:"w-full min-h-14 max-h-[30em] resize-none field-sizing-content bg-background p-2 text-sm text-foreground",value:m,onChange:k=>h(k.target.value)}),e.jsxs("div",{className:"mt-2 flex justify-end gap-2",children:[e.jsxs(D,{size:"sm",variant:"outline",onClick:y,children:[e.jsx(g.X,{className:"h-4 w-4"})," Cancel"]}),e.jsxs(D,{size:"sm",onClick:p,children:[e.jsx(g.Check,{className:"h-4 w-4"})," Save"]})]})]}):j&&e.jsx("div",{dangerouslySetInnerHTML:{__html:N}}),b.length>0&&e.jsx("div",{className:"mt-2 space-y-2",children:b.map((k,S)=>e.jsx("img",{src:k,alt:`${t.senderName||(a?"User":"Assistant")} image ${S+1}`,className:"max-w-full h-auto rounded-md border border-border bg-background",loading:"lazy",draggable:!1},`${t.id}-img-${S}`))})]}),e.jsxs("div",{className:v("flex items-center gap-1",a&&"flex-row-reverse"),children:[l&&!u&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:w,"aria-label":d?"Copied message":"Copy message",children:d?e.jsx(g.Check,{className:"h-4 w-4"}):e.jsx(g.Copy,{className:"h-4 w-4"})}),(n||i)&&!u&&e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[n&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:c,"aria-label":"Edit message",children:e.jsx(g.Pencil,{className:"h-4 w-4"})}),i&&e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:x,"aria-label":"Retry message",children:e.jsx(g.RotateCcw,{className:"h-4 w-4"})})]}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:qn(t.timestamp)})]})]})]})},t.id)},(s,t)=>s.isCurrentUser===t.isCurrentUser&&s.hideSenderName===t.hideSenderName&&s.canEdit===t.canEdit&&s.canRetry===t.canRetry&&s.canCopy===t.canCopy&&s.isCopied===t.isCopied&&s.isEditing===t.isEditing&&s.editValue===t.editValue&&s.message.id===t.message.id&&s.message.senderName===t.message.senderName&&s.message.content===t.message.content&&s.message.images===t.message.images&&s.message.timestamp===t.message.timestamp&&s.message.fromPartnerID===t.message.fromPartnerID&&s.message.toPartnerID===t.message.toPartnerID),Qn=o.memo(function({messages:t,appID:a,botStatus:r,isAssistantChat:n,variant:i,hideSenderNames:l=!1,editableUserMessages:d=!1,editingMessageId:u=null,editingDraft:m="",onEditingDraftChange:h=()=>{},onStartEditUserMessage:c,onCancelEditUserMessage:y,onSaveEditUserMessage:p,onRetryUserMessage:x}){const[w,N]=o.useState(null),j=o.useRef(null);o.useEffect(()=>()=>{j.current!=null&&window.clearTimeout(j.current)},[]);const b=o.useCallback(async(P,E)=>{await Bo(E)&&(N(P),j.current!=null&&window.clearTimeout(j.current),j.current=window.setTimeout(()=>N(null),2e3))},[]),k=o.useMemo(()=>{const P=new Set;let E=null;for(const T of t){const I=(T.senderName??"").trim();I&&(E===I?P.add(T.id):E=I)}return P},[t]),S=i??(n?"assistant":"dashboard"),M=S==="assistant"?zo:Vo,A=S==="assistant"?_o:$o;return e.jsxs("div",{className:S==="dashboard"?"py-3":"",children:[t.map(P=>{const E=P.fromPartnerID===a,T=!!(d&&n&&E&&c&&p&&y),I=!!(d&&n&&E&&x),B=!!(n&&!E&&(P.content??"").trim().length>0),F=u===P.id;return e.jsx(M,{message:P,isCurrentUser:E,hideSenderName:l||k.has(P.id),canEdit:T,canRetry:I,canCopy:B,isCopied:w===P.id,isEditing:F,editValue:F?m:"",onEditValueChange:h,onStartEdit:()=>c?.(P),onCancelEdit:()=>y?.(),onSaveEdit:()=>p?.(P.id,m),onRetry:()=>x?.(P),onCopy:()=>{b(P.id,P.content)}},P.id)}),r!==""&&e.jsx(A,{botStatus:r}),t.length===0&&!n&&e.jsxs("div",{className:"mt-1 text-xl",children:[e.jsx(g.Send,{className:"w-full h-32"}),e.jsx("p",{className:"text-center",children:"No messages yet... Say hello!"})]})]})});function Uo({activeChat:s,activeChatObj:t,appID:a,messagesEndRef:r,inputRef:n,content:i,setContent:l,handleSendMessage:d,isPostBizDevConvoLoading:u,acceptChat:m}){return e.jsx("div",{className:"flex-5 flex flex-col min-w-0 bg-background",children:s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-border/60",children:[e.jsx(Nt,{className:"h-8 w-8 flex-shrink-0 rounded-lg",children:e.jsx(us,{id:s[0]===a?s[1]:s[0],width:72,height:72})}),e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"truncate text-sm font-semibold",children:t?.name})})]}),t?.pending&&t.partner1==a?e.jsx("p",{className:"mx-auto mt-12 max-w-md px-6 text-center text-sm text-muted-foreground",children:"This conversation is awaiting approval by the other party — please check back later."}):e.jsxs(e.Fragment,{children:[e.jsxs(hs,{className:"flex-1 bg-background",children:[e.jsx("div",{className:t?.messages===null?"opacity-0":"",children:e.jsx(Qn,{messages:t?.messages??[],appID:a,isAssistantChat:!1,botStatus:""})}),e.jsx("div",{ref:r})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-border/60 flex items-end gap-3",children:[t?.pending&&e.jsxs(e.Fragment,{children:[e.jsxs(D,{disabled:u,onClick:()=>m(),children:[e.jsx(g.HandshakeIcon,{}),"Accept Conversation Request"]}),e.jsxs(D,{disabled:!0,className:"ml-2",children:[e.jsx(g.ThumbsDownIcon,{}),"Block Partner"]})]}),e.jsx(fs,{ref:n,placeholder:"Type a message...",value:i,onChange:h=>l(h.target.value),onKeyDown:h=>{h.key!=="Enter"||h.shiftKey||(h.preventDefault(),d())},className:t?.pending?"collapse":"flex-1 resize-none field-sizing-content max-h-[30em] rounded-xl border border-border/60 bg-muted/20 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",disabled:t?.pending}),e.jsx("div",{className:"flex items-center",children:e.jsx(D,{size:"icon",variant:"default",className:t?.pending?"collapse":"h-10 w-10 rounded-xl",disabled:t?.pending,onClick:d,children:e.jsx(g.Send,{className:"h-6 w-6"})})})]})]})]}):e.jsxs("div",{className:"flex flex-col m-auto text-xl",children:[e.jsx(g.MousePointerClick,{className:"w-full h-32"}),e.jsx("p",{children:"Select a chat from the left menu to start messaging"})]})})}function qo({activeChatObj:s,appID:t,sendChatToAssistant:a,isAnalyzingPartnership:r,analyzePartnership:n}){const i=s?[s.partner1,s.partner2]:void 0;return e.jsx("aside",{className:"w-[340px] shrink-0 border-l border-border/60 bg-background",children:e.jsxs("div",{className:"h-full flex flex-col gap-7 px-5 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Actions"}),e.jsx(ve.Link,{className:"block",inert:i===void 0,to:`/${t}/Partner/${i?.[0]===t?i[1]:i?.[0]}`,children:e.jsxs(D,{variant:"ghost",className:"w-full justify-start px-2",disabled:i===void 0,children:[e.jsx(g.ExternalLink,{className:"h-4 w-4"}),"View Partner"]})}),e.jsxs(D,{variant:"ghost",className:"w-full justify-start px-2",disabled:(s?.messages??[]).length<1,onClick:()=>a(s.messages),children:[e.jsx(g.Bot,{className:"h-4 w-4"}),"Export to Randmar Assistant"]}),e.jsx(D,{className:"w-full",disabled:i===void 0||r,onClick:n,children:r?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Analyzing..."]}):"Analyze Partnership"})]}),e.jsx(nn,{userId:t,partnerId:i?.[0]===t?i[1]:i?.[0]||"",isAdmin:!1}),e.jsx(Qo,{appID:t,activeChatObj:s}),e.jsx(Ho,{appID:t,activeChatObj:s})]})})}const Qo=({appID:s,activeChatObj:t})=>{const a=t?.conversationID??-1,r=!t||a===-1,{data:n,isLoading:i,isError:l,refetch:d,isFetching:u}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdPeopleQuery({routeApplicationId:s,conversationId:a},{skip:r}),m=n??[];return e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"People"}),r?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a chat to see participants."}):i||u?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading people..."}):l?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Could not load people."}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>d(),children:"Retry"})]}):m.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No participants found."}):e.jsx("ul",{className:"flex flex-col gap-1",children:m.map((h,c)=>{const y=h.ApplicationId??`${h.Name??"person"}-${c}`,p=h.LastAuthentication?new Date(h.LastAuthentication).toLocaleString():void 0;return e.jsxs("li",{className:"rounded-lg px-2 py-2 text-sm hover:bg-primary/5",children:[e.jsx("p",{className:"font-medium leading-tight",children:h.Name??"Unknown person"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h.Role??"Role unavailable"}),p?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last auth ",p]}):null]},y)})})]})},Ho=({appID:s,activeChatObj:t})=>{const[a,r]=o.useState(!1),n=t?.conversationID,i=n===void 0||n===-1,{data:l,isLoading:d}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdLinksQuery({routeApplicationId:s,conversationId:n??-1},{skip:i}),[u]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdLinkMutation(),[m]=_.useDeleteV4PartnerByRouteApplicationIdBusinessDevelopmentConversationLinkAndLinkIdMutation();return e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Links"}),e.jsxs("div",{className:"flex flex-col gap-1",children:[d?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading links..."}):l?.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No links attached."}):null,l?.map(h=>e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg px-2 py-2 hover:bg-primary/5",children:[e.jsx("a",{href:h.URL,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline underline-offset-4 break-all",children:h.Title}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>m({routeApplicationId:s,linkId:h.LinkId}),"aria-label":"Delete link",children:e.jsx(g.Trash2,{className:"h-4 w-4"})})]},h.LinkId))]}),e.jsxs(De,{open:a,onOpenChange:r,children:[e.jsx(Os.DialogTrigger,{asChild:!0,children:e.jsxs(D,{variant:"link",className:"h-auto p-0 justify-start",disabled:i,children:[e.jsx(g.Plus,{className:"h-4 w-4"}),"Add link"]})}),e.jsxs(Me,{children:[e.jsxs(Le,{children:[e.jsx(Os.DialogTitle,{children:"Add Link"}),e.jsx(Os.DialogDescription,{children:"Please enter the details for the new link."})]}),e.jsxs("form",{className:"space-y-4",onSubmit:h=>{h.preventDefault();const c=document.getElementById("link-title").value,y=document.getElementById("link-url").value;n===void 0||n===-1||(u({routeApplicationId:s,conversationId:n,createLinkRequest:{Title:c,Url:y}}),r(!1))},children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"link-title",children:"Title"}),e.jsx(le,{id:"link-title",required:!0,minLength:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"link-url",children:"URL"}),e.jsx(le,{id:"link-url",type:"url",required:!0,minLength:2,placeholder:"https://"})]}),e.jsx(D,{type:"submit",disabled:i,children:"Add Link"})]})]})]})]})},Go=s=>{const[t]=_.usePostV4UserByFieldNameMutation(),[a,r]=o.useState(""),[n,i]=o.useState(""),[l,d]=o.useState(!1),[u]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation();return e.jsxs("div",{className:"mx-auto mt-2",children:[e.jsx("p",{className:"mb-4",children:"Before you can start chatting, please set up your profile."}),e.jsxs("form",{className:"space-y-2",onSubmit:m=>{l||(d(!0),m.preventDefault(),t({fieldName:"Name",newValue:a}).then(()=>{u({routeApplicationId:s.appID,partnerId:"2"})}),t({fieldName:"Role",newValue:n}))},children:[e.jsx(J,{htmlFor:"name",children:"Name"}),e.jsx(le,{id:"name",required:!0,minLength:2,value:a,onChange:m=>r(m.target.value)}),e.jsx(J,{htmlFor:"role",children:"Role"}),e.jsx(le,{id:"role",required:!0,minLength:2,value:n,onChange:m=>i(m.target.value)}),e.jsx(D,{type:"submit",disabled:l,children:l?"Saving...":"Save"})]})]})},xt=(s,t)=>s.unread>0&&t.unread===0?-1:t.unread>0&&s.unread===0?1:s.name.localeCompare(t.name);function Wo({appID:s,inputRef:t,className:a}){const{setHasUnreads:r}=Js(),n=vt(),{data:i,refetch:l}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationsQuery({routeApplicationId:s}),[d,u]=o.useState(!1),[m,h]=o.useState(!1),[c,y]=o.useState(!1),[p,{isLoading:x}]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),w=o.useRef(null),[N]=_.useLazyGetV4PartnerByApplicationIdAccountQuery(),{sendPrompt:j}=Do({applicationId:s,outputFormat:"text",useProModel:!0}),[b,k]=o.useState(!1),[S]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),[M]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdReadMutation(),[A]=_.useLazyGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdMessagesQuery(),[P]=_.useLazyGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery(),[E,T]=o.useState(!1);o.useEffect(()=>{i&&(W(H=>{const ee=i.map(ie=>{const he=H.find(ke=>ke.conversationID===ie.ConversationId);return{partner1:ie.Participant1,partner2:ie.Participant2,name:ie.Participant?.PublicName??"missing public name",unread:he?.unread??0,pending:ie.Status!=="Approved",messages:he?.messages??null,conversationID:ie.ConversationId,lastMessageTime:ie.LastMessageTime??null}});return ee.sort(xt),ee}),u(!0),setTimeout(()=>ue.current?.focus(),50))},[i,s]);const[I,B]=o.useState(void 0),[F,U]=o.useState(""),[V,O]=o.useState(null),[q,W]=o.useState([]),[ne,Pe]=o.useState(null),qe=o.useRef(null),Z=o.useRef(null),[X,se]=o.useState([]),ue=t||Z,Q=o.useRef(null),{toast:te}=Ce(),oe=()=>q.find(H=>H.partner1===I?.[0]&&H.partner2===I?.[1]),Ne=o.useCallback(async()=>{if(m)return;h(!0);const H=I;try{se([]),O(null);const he=((await l()).data??[]).map(Re=>({partner1:Re.Participant1,partner2:Re.Participant2,name:Re.Participant?.PublicName??"missing public name",unread:0,pending:Re.Status!=="Approved",messages:null,conversationID:Re.ConversationId,lastMessageTime:Re.LastMessageTime??null})),ke=new Map;await Promise.allSettled(he.map(async Re=>{if(Re.conversationID<=0)return;const Ds=((await A({routeApplicationId:s,conversationId:Re.conversationID})).data??[]).reduce((zs,lt)=>lt.Read||!lt.SenderId||lt.SenderId===s?zs:zs+1,0);ke.set(Re.conversationID,Ds)}));const ts=he.map(Re=>({...Re,unread:ke.get(Re.conversationID)??0})).sort(xt);if(W(ts),H){const Re=ts.find(Ee=>Ee.partner1===H[0]&&Ee.partner2===H[1]||Ee.partner1===H[1]&&Ee.partner2===H[0]);B(Re?[Re.partner1,Re.partner2]:void 0)}te({title:"Refreshed",description:"Chat state reinitialized."})}catch(ee){console.error("Error refreshing chat state:",ee),te({title:"Refresh failed",description:"Could not refresh chat state. Please try again.",variant:"destructive"})}finally{h(!1)}},[I,s,A,m,l,te]),Fe=o.useCallback(async()=>{if(!c){y(!0);try{const H=q.map(ee=>ee.conversationID).filter(ee=>ee>0);await Promise.allSettled(H.map(async ee=>{await M({routeApplicationId:s,conversationId:ee}).unwrap()})),W(ee=>ee.map(ie=>({...ie,unread:0})).sort(xt)),te({title:"All read",description:"All conversations marked as read."})}catch(H){console.error("Error marking all conversations as read:",H),te({title:"Action failed",description:"Could not mark all conversations as read. Please try again.",variant:"destructive"})}finally{y(!1)}}},[s,q,c,M,te]);function xe(){const H=oe();H&&M({routeApplicationId:s,conversationId:H.conversationID})}const Te=H=>se(ee=>[...ee,H]);o.useEffect(()=>{if(X.length==0)return;console.log(X.length,"unprocessedMessages detected");const H=(ie,he)=>he.partner1===ie.toPartnerID&&he.partner2===ie.fromPartnerID||he.partner2===ie.toPartnerID&&he.partner1===ie.fromPartnerID;let ee=!1;X.forEach(ie=>{if(!q.some(he=>H(ie,he))){console.log("message received for unknown convo ID - need to refetch!"),ee=!0;return}W(he=>he.map(ke=>{if(!H(ie,ke))return ke;const ts=ke.messages??[];if(ts.some(Ds=>Ds.id===ie.id))return ke;let Re=1;const Ee=document.activeElement&&document.activeElement===ue.current;return I?.[0]==ke.partner1&&I[1]==ke.partner2&&Ee&&(Ee&&(Re=0,xe()),setTimeout(()=>qe.current?.scrollIntoView({behavior:"smooth"}),50)),{...ke,pending:!1,unread:ke.unread+Re,messages:[...ts,ie]}}).sort(xt))}),console.log("need refetch:",ee),ee&&l(),se([])},[X,se,W,B,I]),o.useEffect(()=>{const H=new ia.HubConnectionBuilder().withUrl($s("/hub",n),{accessTokenFactory:()=>localStorage.getItem("access_token"),headers:{"X-Impersonated-Id":s}}).configureLogging(ia.LogLevel.Information).withAutomaticReconnect().withHubProtocol(new ia.JsonHubProtocol).build();return H.on("ReceiveMessage",Te),H.start().catch(ee=>console.error("Error connecting to SignalR hub:",ee)),Pe(H),()=>{H&&H.stop()}},[s,n]),o.useEffect(()=>{!I||!oe()||(ue.current?.focus(),setTimeout(()=>qe.current?.scrollIntoView({behavior:"smooth"}),50))},[I]),o.useEffect(()=>{if(!I)return;const H=oe();H&&H.conversationID!==-1&&(async()=>{try{const ie=(await A({routeApplicationId:s,conversationId:H.conversationID})).data?.map(he=>({id:"history"+he.MessageId,fromPartnerID:he.SenderId,toPartnerID:he.SenderId==H.partner1?H.partner2:H.partner1,senderName:he.SenderName??"missing name",timestamp:new Date(he.SentDate+"Z").getTime(),content:he.Content??"no content"}))??[];W(he=>he.map(ke=>ke.conversationID===H.conversationID?{...ke,messages:ie}:ke).sort(xt))}catch(ee){console.error("Error fetching conversation messages:",ee)}})()},[I,A,s]),o.useEffect(()=>{if(!I)return;const H=oe();if(!H)return;const ee=document.activeElement&&document.activeElement===ue.current;H.unread>0&&ee&&(xe(),W(ie=>ie.map(he=>he.partner1===I[0]&&he.partner2===I[1]?{...he,unread:0}:he)))},[I,q]);const{sendMessage:Ae}=Js(),Ye=o.useCallback(H=>{Ae(`We have been talking with another Randmar partner and would like you to have the conversation as context for follow-up questions. Please acknowledge your reception of this chat history (one line summary of recent messages will do) and let me know that you're ready to answer questions: ${JSON.stringify(H,null,2)}`)},[Ae]),Je=o.useCallback(async()=>{if(I)try{T(!0);const H=await N({applicationId:s}),ee=I[0]===s?I[1]:I[0],ie=await P({routeApplicationId:s,partnerId:ee,withSpecification:!0}),he=Mo(H.data,ie.data);he?Ae(he):te({title:"Missing data",description:"We couldn't load enough data to analyze this partnership yet. Please try again shortly.",variant:"destructive"})}catch(H){console.error("Error preparing partnership analysis:",H),te({title:"Error",description:"Could not analyze the partnership. Please try again later.",variant:"destructive"})}finally{T(!1)}},[I,N,P,Ae,te,s]);o.useEffect(()=>{r(q.some(H=>H.unread>0))},[q,r]);const K=(H,ee)=>{ee=ee.replace(/\n/g,`
|
|
30
|
+
`),console.log("doSend",ee),console.log("target",H);const ie={id:crypto.randomUUID(),senderName:Be?.Name??Be?.EmailAddress??"User",fromPartnerID:s,toPartnerID:H.partner1===s?H.partner2:H.partner1,content:ee,timestamp:Date.now()};Te(ie),ne.invoke("NewMessage",ie).catch(he=>console.error("Error sending message:",he)),U(""),Q.current&&(Q.current.value="")},Se=()=>{const H=F.trim();!Ns||!H||!I||!ne||(Ns.unread>0&&(xe(),W(ee=>ee.map(ie=>ie.partner1===I[0]&&ie.partner2===I[1]?{...ie,unread:0}:ie))),K(Ns,H))},Ve=(H,ee)=>O([H,ee]);o.useEffect(()=>{if(V===null)return;const H=q.find(ie=>ie.conversationID===V[0]);if(!H||(B([H.partner1,H.partner2]),!ne))return;const ee=V[1];O(null),ee&&K(H,ee)},[V,q,B,ne]);const{data:Be,isLoading:ss}=_.useGetV4UserQuery();if(!d||ss)return e.jsx(g.Loader2,{className:"h-12 w-12 animate-spin mx-auto mb-4"});if(!Be?.Name)return e.jsx(Go,{appID:Be?.ApplicationId??""});const ea=async()=>{w.current&&(w.current.disabled=!0),k(!0);try{const H=await N({applicationId:s}),ee=H.data?.About??"a new business venture",ie=[];H.data?.IsManufacturer&&ie.push("Manufacturer"),H.data?.IsReseller&&ie.push("Reseller"),H.data?.IsSalesAgency&&ie.push("Sales Agency");const ke=`
|
|
31
31
|
Your task is to draft a ready-to-send opening message from a user to the Randmar team.
|
|
32
32
|
|
|
33
|
-
**Your Persona:** You are an entrepreneur and a ${
|
|
33
|
+
**Your Persona:** You are an entrepreneur and a ${ie.length>0?ie.join("/"):"Entrepreneur"}.
|
|
34
34
|
**Your Company's Description:**
|
|
35
35
|
\`\`\`html
|
|
36
36
|
${ee}
|
|
@@ -43,36 +43,36 @@ Prompt: "${a}"`;try{return(await s({applicationId:t,body:[{Role:"user",Parts:[{T
|
|
|
43
43
|
- **Crucially, do not use any placeholders, brackets, or instructions for the user to fill in.** Use the context provided to craft the final text.
|
|
44
44
|
- Keep it to 1-2 concise, engaging sentences.
|
|
45
45
|
- Output only the plain text of the message itself.
|
|
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(Q){console.error("Error during 'Chat with Randmar' initiation:",Q),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&&g({routeApplicationId:s,partnerId:I[0]==s?I[1]:I[0]})},Ns=le();return e.jsxs("div",{className:v("flex grow-1 overflow-hidden",a),children:[e.jsx(Fo,{appID:s,activeChat:I,chats:H,chatWithRandmarButton:w,isStartingChat:y,isRefreshingChats:c,isMarkingAllRead:m,handleChatWithRandmar:ea,onFullRefreshChats:Ne,onMarkAllRead:Fe,setActiveChat:F}),e.jsx(Uo,{activeChat:I,activeChatObj:Ns,appID:s,messagesEndRef:qe,inputRef:ue,content:$,setContent:V,handleSendMessage:Se,isPostBizDevConvoLoading:b,acceptChat:Is}),e.jsx(qo,{activeChatObj:Ns,appID:s,sendChatToAssistant:Ye,isAnalyzingPartnership:T,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(Ie,{open:s,onOpenChange:t,children:e.jsxs(De,{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:x})=>{const c=d.pathname!==x.pathname||d.search!==x.search||d.hash!==x.hash;return s()&&c},[s]));o.useEffect(()=>{r.state==="blocked"&&a(!0)},[r]),o.useEffect(()=>{const d=x=>{if(s())return x.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({}),x=o.useMemo(()=>({accountsPayableRep:s?.ContactName??"",representativeEmail:s?.RepresentativeEmail??"",phone:s?.Phone??"",creditLimit:s?.CreditLimit??0,terms:s?.Terms??""}),[s]),{register:c,handleSubmit:u,reset:m,watch:f,formState:{errors:g,isSubmitting:b}}=bt.useForm({defaultValues:x}),w=f(),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&&(m(x),d(x))},[s,m,x]);const j=async y=>{if(t)return;let k=!0,S=!1;const M=[{key:"accountsPayableRep",apiKey:"ContactName",value:y.accountsPayableRep},{key:"representativeEmail",apiKey:"RepresentativeEmail",value:y.representativeEmail},{key:"phone",apiKey:"Phone",value:y.phone},{key:"terms",apiKey:"Terms",value:y.terms}];for(const P of M){const A=P.value,T=s?.[P.apiKey];if(A!==T&&A!==void 0){S=!0;try{await i({applicationId:s?.ManufacturerId??"",fieldName:P.apiKey,newValue:String(A)}).unwrap()||(k=!1,console.error(`Failed to update ${P.apiKey}`))}catch(E){console.error(`Error updating ${P.apiKey}:`,E),k=!1}}}k&&S?(n({title:"Billing info",description:"Information updated successfully",variant:"success"}),d({...y}),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(U,{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(h,{className:"h-4 w-48"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-36"}),e.jsx(h,{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(h,{className:"h-4 w-16"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-24"}),e.jsx(h,{className:"h-10 w-full"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-16"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsx(h,{className:"h-10 w-20"})]}):e.jsxs("form",{onSubmit:u(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(ie,{id:"accountsPayableRep",placeholder:"John Doe",...c("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(ie,{id:"representativeEmail",placeholder:"john.doe@company.com",...c("representativeEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),readOnly:t}),g.representativeEmail&&e.jsx("p",{className:"text-destructive text-sm",children:g.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(ie,{id:"phone",placeholder:"(555) 123-4567",...c("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(ie,{id:"terms",placeholder:"NET 30 DAYS",...c("terms"),readOnly:!0})]}),!t&&e.jsx("div",{className:"flex justify-end",children:e.jsx(D,{type:"submit",disabled:b,className:"w-full sm:w-auto",children:b?e.jsxs(e.Fragment,{children:[e.jsx(p.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 x=async c=>{if(!t)try{await n({applicationId:s?.ManufacturerId??"",fieldName:"OpenToWork",newValue:c?"true":"false"}).unwrap()&&r({title:"Open to work info",description:"Information updated successfully",variant:"success"})}catch(u){console.error("Error updating",u)}};return e.jsxs(U,{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(h,{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:c=>x(c),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([]),[x,c]=o.useState({}),u=o.useMemo(()=>({publicName:s?.PublicName??"",website:s?.Website??"",customerServiceEmail:s?.PublicEmail??"",publicResources:s?.PublicResourcesLink??""}),[s]),{register:m,handleSubmit:f,reset:g,watch:b,formState:{errors:w,isSubmitting:N}}=bt.useForm({defaultValues:u}),j=b(),y=o.useCallback(()=>t||!x?!1:JSON.stringify(j)!==JSON.stringify(x),[t,j,x]);o.useEffect(()=>{r&&r(y())},[y,r]),o.useEffect(()=>{s&&(g(u),d(s.Tags?s.Tags.split(",").map(P=>P.trim()):[]),c(u))},[s,g,u]);const k=async P=>{if(t)return;let A=!0,T=!1;const E=[{key:"publicName",apiKey:"PublicName",value:P.publicName},{key:"website",apiKey:"Website",value:P.website},{key:"manufacturerCategories",apiKey:"Tags",value:l.join(", ")},{key:"customerServiceEmail",apiKey:"PublicEmail",value:P.customerServiceEmail},{key:"publicResources",apiKey:"PublicResourcesLink",value:P.publicResources}];for(const I of E){const F=I.value,$=s?.[I.apiKey],V=typeof $=="boolean"?String($):$;if(F!==V&&F!==void 0){T=!0;try{await i({applicationId:s?.ManufacturerId??"",fieldName:I.apiKey,newValue:String(F)}).unwrap()||(A=!1)}catch(z){console.error(`Error updating ${I.apiKey}:`,z),A=!1}}}A&&T?(n({title:"Public info",description:"Information updated successfully",variant:"success"}),c({...P}),r&&r(!1)):A||n({title:"Update error",description:"Failed to update",variant:"destructive"})},S=P=>!P||P.trim()==="",M=P=>{d(P)};return e.jsxs(U,{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(h,{className:"h-4 w-40"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-24"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(h,{className:"h-5 w-10"}),e.jsx(h,{className:"h-4 w-48"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-40"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-40"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-32"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsx(h,{className:"h-10 w-20"})]}):e.jsxs(e.Fragment,{children:[(S(b("publicName"))||S(b("website"))||S(b("customerServiceEmail")))&&e.jsxs(js,{variant:"destructive",className:"mb-6",children:[e.jsx(p.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:f(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(ie,{id:"publicName",placeholder:"Company Name",...m("publicName",{}),className:S(b("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(ie,{id:"website",placeholder:"https://company.com",...m("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:S(b("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(ie,{id:"customerServiceEmail",placeholder:"support@company.com",...m("customerServiceEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:S(b("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(ie,{id:"publicResources",placeholder:"https://resources.company.com",...m("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(p.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({}),x=o.useMemo(()=>({partnerPortal:s?.PartnerPortal??"",partnerRegistrationLink:s?.PartnerRegistrationLink??""}),[s]),{register:c,handleSubmit:u,reset:m,watch:f,formState:{errors:g,isSubmitting:b}}=bt.useForm({defaultValues:x}),w=f(),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&&(m(x),d(x))},[s,m,x]);const j=async k=>{if(t)return!1;let S=!0,M=!1;const P=[{key:"partnerPortal",apiKey:"PartnerPortal",value:k.partnerPortal},{key:"partnerRegistrationLink",apiKey:"PartnerRegistrationLink",value:k.partnerRegistrationLink}];for(const A of P){const T=A.value,E=s?.[A.apiKey];if(T!==E&&T!==void 0){M=!0;try{await i({applicationId:s?.ManufacturerId??"",fieldName:A.apiKey,newValue:String(T)}).unwrap()||(S=!1,console.error(`Failed to update ${A.apiKey}`))}catch(I){console.error(`Error updating ${A.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"})},y=/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?(\?[^\s#]*)??(#[^\s]*)?$/i;return e.jsxs(U,{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(h,{className:"h-4 w-32"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-48"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsx(h,{className:"h-10 w-20"})]}):e.jsxs("form",{onSubmit:u(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(ie,{id:"partnerPortal",placeholder:"https://partner.example.com",...c("partnerPortal",{pattern:{value:y,message:"Invalid URL format"}}),readOnly:t}),g.partnerPortal&&e.jsx("p",{className:"text-destructive text-sm",children:g.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(ie,{id:"partnerRegistrationLink",placeholder:"https://register.example.com",...c("partnerRegistrationLink",{pattern:{value:y,message:"Invalid URL format"}}),readOnly:t}),g.partnerRegistrationLink&&e.jsx("p",{className:"text-destructive text-sm",children:g.partnerRegistrationLink.message})]}),!t&&e.jsx("div",{className:"flex justify-end",children:e.jsx(D,{type:"submit",disabled:b,className:"w-full sm:w-auto",children:b?e.jsxs(e.Fragment,{children:[e.jsx(p.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),[x,c]=o.useState(!1),[u,m]=o.useState(),[f,g]=o.useState(),b=[{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:p.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:p.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:p.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:p.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:p.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:p.ClipboardList}]}],[w,{isLoading:N}]=_.usePostV4ManufacturerByRouteManufacturerIdReportOpenOrdersEmailMutation(),[j,{isLoading:y}]=_.usePostV4ManufacturerByRouteManufacturerIdReportSalesEmailMutation(),[k,{isLoading:S}]=_.usePostV4ManufacturerByRouteManufacturerIdReportPurchasedOrdersEmailMutation(),[M,{isLoading:P}]=_.usePostV4ManufacturerByRouteManufacturerIdReportReorderEmailMutation(),[A,{isLoading:T}]=_.usePostV4ManufacturerByRouteManufacturerIdReportInventoryEmailMutation(),[E,{isLoading:I}]=_.usePostV4ManufacturerByRouteManufacturerIdReportProductsEmailMutation(),F=N||y||S||P||T||I,$=H=>{i(H),c(!0)},V=H=>{c(H),H||(m(void 0),g(void 0))},z=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:u?.toISOString(),endDate:f?.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 A({routeManufacturerId:s,emailAddress:l,inventoryDate:u?.toISOString()}).unwrap();break;case"Products":await E({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"}),V(!1)}catch(H){console.error("Error requesting report:",H),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(U,{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((H,K)=>e.jsxs("div",{className:"space-y-4",children:[e.jsx(h,{className:"h-6 w-48"}),Array.from({length:2}).map((de,Me)=>e.jsxs("div",{className:"flex items-start gap-4 rounded-lg border p-4",children:[e.jsx(h,{className:"h-9 w-9 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(h,{className:"mb-2 h-5 w-40"}),e.jsx(h,{className:"h-4 w-full"})]}),e.jsx(h,{className:"h-9 w-24"})]},Me))]},K)):b.map(H=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:H.name}),H.reports.map(K=>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(K.icon,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"text-sm font-semibold",children:K.title}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:K.description})]}),e.jsxs(D,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>$(K),children:[e.jsx(p.Download,{className:"h-4 w-4"}),"Request"]})]},K.id))]},H.name))}),e.jsx(Ie,{open:x,onOpenChange:V,children:e.jsxs(De,{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(ie,{id:"email",value:l,onChange:H=>d(H.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:u,onDateChange:m}),e.jsx(Ot,{label:"End Date",id:"end-date",date:f,onDateChange:g})]}),n?.id==="Inventory"&&e.jsx(Ot,{label:"Inventory Date",id:"inventory-date",date:u,onDateChange:m})]}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>V(!1),children:"Cancel"}),e.jsx(D,{onClick:z,disabled:!l||F||n?.id==="Sales"&&(!u||!f)||n?.id==="Inventory"&&!u,children:F?e.jsxs(e.Fragment,{children:[e.jsx(p.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 x=n.filter(S=>S.DocumentType==="Order"),c=n.filter(S=>S.DocumentType==="Shipment"),u=x.filter(S=>S.WarehouseCode!=="3PLE"),m=u.reduce((S,M)=>S+(M.Quantity||0),0),f=u.reduce((S,M)=>S+(M.ExtendedPrice||0),0),g=x.filter(S=>S.WarehouseCode==="3PLE"),b=g.reduce((S,M)=>S+(M.Quantity||0),0),w=g.reduce((S,M)=>S+(M.ExtendedPrice||0),0),N=c.length,j=c.reduce((S,M)=>S+(M.ExtendedPrice||0),0),y=m+b+N,k=f+w+j;return{all:{orders:y,amount:k},processing:{orders:m,amount:f},shipped:{orders:N,amount:j},delayed:{orders:b,amount:w}}})(),d=[{name:"All",icon:p.Package,stripeClass:"bg-info/60",iconBgClass:"bg-info/90",iconTextClass:"text-info-foreground",orders:l.all.orders,amount:l.all.amount},{name:"Processing",icon:p.RefreshCcw,stripeClass:"bg-warning/60",iconBgClass:"bg-warning/90",iconTextClass:"text-warning-foreground",orders:l.processing.orders,amount:l.processing.amount},{name:"Shipped",icon:p.Truck,stripeClass:"bg-success/60",iconBgClass:"bg-success/90",iconTextClass:"text-success-foreground",orders:l.shipped.orders,amount:l.shipped.amount},{name:"Delayed",icon:p.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(U,{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(h,{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(x=>e.jsx(h,{className:"h-32 w-full"},x))})]})]}):r?e.jsxs(U,{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(p.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(U,{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(x=>e.jsx(U,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:e.jsxs(G,{className:"p-0",children:[e.jsx("div",{className:`${x.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:x.name}),e.jsx("div",{className:`${x.iconBgClass} p-2 rounded-full`,children:e.jsx(x.icon,{className:`size-4 shrink-0 ${x.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:x.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:x.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},x.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(U,{children:[e.jsxs(Y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(h,{className:"h-5 w-24"}),e.jsx(h,{className:"h-8 w-8 rounded-full"})]}),e.jsxs(G,{children:[e.jsx(h,{className:"h-8 w-32 mb-1"}),e.jsx(h,{className:"h-4 w-24"})]})]}),e.jsxs(U,{children:[e.jsxs(Y,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(h,{className:"h-5 w-28"}),e.jsx(h,{className:"h-8 w-8 rounded-full"})]}),e.jsxs(G,{children:[e.jsx(h,{className:"h-8 w-32 mb-1"}),e.jsx(h,{className:"h-4 w-24"})]})]}),e.jsxs(U,{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(h,{className:"h-5 w-36"}),e.jsx(h,{className:"h-8 w-8 rounded-full"})]}),e.jsxs(G,{children:[e.jsx(h,{className:"h-8 w-32 mb-1"}),e.jsx(h,{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(U,{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(p.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(U,{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(p.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(U,{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(p.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 U=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}));U.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((c,u)=>c+(u.InventoryValue||0),0),d=i-l,x=i>0?Math.round(l/i*100):0;return t||r||n?e.jsxs(U,{children:[e.jsxs(Y,{children:[e.jsx(h,{className:"h-7 w-3/4"}),e.jsx(h,{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(h,{className:"h-5 w-1/3"}),e.jsx(h,{className:"h-5 w-1/4"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{className:"h-5 w-1/3"}),e.jsx(h,{className:"h-5 w-1/4"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{className:"h-5 w-1/3"}),e.jsx(h,{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(h,{className:"h-5 w-1/3"}),e.jsx(h,{className:"h-5 w-16"})]}),e.jsx(h,{className:"h-2 w-full"})]})]})]}):e.jsxs(U,{children:[e.jsxs(Y,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(p.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:ce(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:ce(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:ce(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:[x,"%"]}),x>80&&e.jsx(p.AlertCircle,{className:"h-4 w-4 text-warning"})]})}),e.jsx(pe,{children:e.jsx("p",{children:x>80?"High usage alert":"Budget usage"})})]})})]}),e.jsx(nt,{value:x,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(U,{children:[e.jsxs(Y,{children:[e.jsx(h,{className:"h-7 w-3/4"}),e.jsx(h,{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(h,{className:"h-5 w-1/3"}),e.jsx(h,{className:"h-5 w-1/4"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{className:"h-5 w-1/3"}),e.jsx(h,{className:"h-5 w-1/4"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{className:"h-5 w-1/3"}),e.jsx(h,{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(h,{className:"h-5 w-1/3"}),e.jsx(h,{className:"h-5 w-16"})]}),e.jsx(h,{className:"h-2 w-full"})]})]})]}):e.jsxs(U,{children:[e.jsxs(Y,{children:[e.jsxs(me,{className:"flex items-center gap-2",children:[e.jsx(p.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:ce(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:ce(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:ce(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(p.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(U,{className:v("w-full",n),children:[e.jsx(Y,{children:e.jsx(h,{className:"h-7 w-48 rounded-md"})}),e.jsxs(G,{children:[e.jsx("div",{style:{height:r},children:e.jsx(h,{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(h,{className:"h-5 w-10 rounded-full"}),e.jsx(h,{className:"h-4 w-40 rounded-md"})]})]})]}):e.jsxs(U,{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}),[x,c]=o.useState({publicInfo:{hasUnsavedChanges:!1},qualifications:{hasUnsavedChanges:!1},billingInfo:{hasUnsavedChanges:!1}}),u=o.useCallback(()=>t?!1:x.publicInfo.hasUnsavedChanges||x.qualifications.hasUnsavedChanges||x.billingInfo.hasUnsavedChanges,[t,x]),m=o.useCallback((b,w)=>{c(N=>N[b]?.hasUnsavedChanges!==w.hasUnsavedChanges?(console.log(`Updating form state for ${b}:`,w.hasUnsavedChanges),{...N,[b]:w}):N)},[]),{NavigationGuardDialog:f}=Hn(u),g=r??i;return e.jsxs("div",{className:"@container",children:[d?e.jsx(U,{className:"p-6",children:e.jsxs(js,{variant:"destructive",children:[e.jsx(p.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:g?.FiscalYearMonthStart,salesData:g?.SalesData,isLoading:l}),e.jsxs("div",{className:"grid @2xl:grid-cols-2 gap-6",children:[e.jsx(Xa,{statistics:g?.SalesStatistics??[],loading:l}),e.jsx(tc,{manufacturerId:g?.ManufacturerId??"",activeOrders:g?.ActiveOrderDetails??void 0,isLoading:l}),a&&e.jsx(rc,{manufacturer:g,isLoading:l}),a&&e.jsx(nc,{manufacturer:g,isLoading:l}),a&&e.jsx(xi,{manufacturer:g??{},onSave:()=>{},loading:l,readonly:t}),a&&e.jsx(Xo,{manufacturer:g,readonly:t,isLoading:l,onUnsavedChanges:b=>m("publicInfo",{hasUnsavedChanges:b})}),a&&e.jsx(Jo,{manufacturer:g,readonly:t,isLoading:l}),a&&e.jsx(Yo,{manufacturer:g,readonly:t,isLoading:l,onUnsavedChanges:b=>m("billingInfo",{hasUnsavedChanges:b})}),a&&e.jsx(ec,{manufacturer:g,readonly:t,isLoading:l,onUnsavedChanges:b=>m("qualifications",{hasUnsavedChanges:b})})]}),a&&e.jsx(sc,{manufacturerId:g?.ManufacturerId??"",userEmail:n,isLoading:l})]}),e.jsx(f,{})]})}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(p.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(U,{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(U,{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(U,{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(p.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(p.Star,{className:"h-5 w-5 fill-warning text-warning"}):e.jsx(p.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(p.RefreshCw,{className:"size-4 text-success"}):e.jsx(p.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(p.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(p.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(p.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(p.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 P=t.Categories?.[0]?.CategoryCode??"";if(typeof window>"u")return P;const A=new URLSearchParams(window.location.search).get("category")?.trim();return A&&t.Categories?.some(E=>E.CategoryCode===A)?A:P}),[l,d]=o.useState(!1),[x,c]=o.useState(!1),[u,m]=o.useState("percentile"),[f,g]=o.useState(!1),{toast:b}=Ce(),{data:w,isLoading:N,isFetching:j}=_.useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:s,manufacturerId:t.ManufacturerId,categoryCode:n??""},{skip:!t.ManufacturerId||!n}),y=async()=>{try{d(!0),c(!1),await r({routeResellerId:s,manufacturerId:t.ManufacturerId??"",categoryCode:n,shopifyHostName:a}).unwrap()&&b({title:"Success",description:"Category synced to Shopify successfully",variant:"success"})}catch(P){console.error("Error syncing to Shopify:",P),b({title:"Error",description:"Error syncing category to Shopify.",variant:"destructive"})}finally{d(!1)}},k=()=>t.Categories?.find(P=>P.CategoryCode===n)?.CategoryName||n,S=o.useMemo(()=>w?.Products?[...w.Products].sort((P,A)=>u==="price-asc"?(P.MAP??0)-(A.MAP??0):u==="price-desc"?(A.MAP??0)-(P.MAP??0):u==="name"?(P.Title??"").localeCompare(A.Title??""):u==="percentile"?(A.OverallPercentileRank??0)-(P.OverallPercentileRank??0):0):[],[w?.Products,u]),M=o.useMemo(()=>f?S.filter(P=>{const A=P.Distribution?.Inventory;return!Array.isArray(A)||A.length===0?!1:A.reduce((E,I)=>E+(I?.AvailableQuantity??0),0)>0}):S,[f,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(P=>P.AvailableToBuy)!==-1&&e.jsx(D,{className:"bg-success text-success-foreground hover:bg-success/90",disabled:l,onClick:()=>c(!0),children:l?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.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(P=>P.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:u,onValueChange:m,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:f,onCheckedChange:P=>g(P===!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((P,A)=>e.jsx(Vt,{},A)):M.length>0?M.map(P=>e.jsx(Vt,{applicationId:s,product:P,viewProductLink:`/${s}/Product/${P.RandmarSKU}`,shopifyHostname:a},P.RandmarSKU)):e.jsxs(js,{variant:"warning",className:"col-span-1 @md:col-span-2",children:[e.jsx(p.AlertCircleIcon,{className:"h-4 w-4"}),e.jsx(bs,{children:"Warning"}),e.jsx(ys,{children:f&&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(Ie,{open:x,onOpenChange:c,children:e.jsxs(De,{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:()=>c(!1),children:"Cancel"}),e.jsx(D,{className:"bg-success text-success-foreground hover:bg-success/90",onClick:y,disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(p.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:x}=Ce(),[c]=_.usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(),[u,m]=o.useState(!1),[f,g]=o.useState(!1),b=async()=>{try{m(!0),g(!1),await c({routeResellerId:s??"",manufacturerId:t??"",shopifyHostName:r}).unwrap()&&x({title:"Success",description:"Manufacturer synced to Shopify successfully",variant:"success"})}catch(y){console.error("Error syncing to Shopify:",y),x({title:"Error",description:"Error syncing manufacturer to Shopify.",variant:"destructive"})}finally{m(!1)}},w=()=>i?.Manufacturer?"products":i?.Reseller?"reseller-overview":"",N=()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("tab"),j=()=>{const y=N();return y==="reseller-overview"&&i?.Reseller?"reseller-overview":y==="manufacturer-overview"&&i?.Manufacturer?"manufacturer-overview":y==="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(y=>y.AvailableToBuy)!==-1&&e.jsxs(Ie,{open:f,onOpenChange:g,children:[e.jsx(Ys,{asChild:!0,children:e.jsx(D,{className:"ml-2 bg-success text-success-foreground hover:bg-success/90",disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.ShoppingCart,{className:"mr-2 h-4 w-4"}),"Sync Manufacturer to Shopify"]})})}),e.jsxs(De,{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:()=>g(!1),children:"Cancel"}),e.jsx(D,{className:"bg-success text-success-foreground hover:bg-success/90",onClick:b,disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsx(p.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(p.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(p.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,x]=o.useState({}),c=o.useMemo(()=>({publicEmail:s.PublicEmail??"",contactName:s.ContactName??"",phone:s.Phone??"",website:s.Website??""}),[s]),{register:u,handleSubmit:m,reset:f,watch:g,formState:{errors:b,isSubmitting:w}}=bt.useForm({defaultValues:c}),N=g(),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&&(f(c),x(c))},[s,f,c]);const y=async S=>{let M=!0,P=!1;const A=Object.keys(S).map(T=>({key:T,keyApi:T.charAt(0).toUpperCase()+T.slice(1)}));for(const T of A){const E=S[T.key],I=s[T.keyApi];if(E!==I&&E!==void 0){P=!0;try{await l({applicationId:t,fieldName:T.keyApi,newValue:String(E)}).unwrap()||(M=!1)}catch(F){console.error(`Error updating ${T.keyApi}:`,F),M=!1}}}M&&P?(i({title:"Public info",description:"Information updated successfully",variant:"success"}),x({...S}),n&&n(!1)):M||i({title:"Updation error",description:"Failed to update",variant:"destructive"})},k=S=>!S||S.trim()==="";return a?e.jsxs(U,{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(h,{className:"h-4 w-32"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-24"}),e.jsx(h,{className:"h-10 w-full"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-20"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-28"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(h,{className:"h-10 w-20"})})]})})]}):e.jsxs(U,{children:[e.jsx(Y,{children:e.jsxs(me,{className:"text-1xl font-bold",children:["Public Information ",r?"(read only)":""]})}),e.jsxs(G,{children:[(k(g("contactName"))||k(g("publicEmail"))||k(g("website"))||k(g("phone")))&&e.jsxs(js,{variant:"destructive",className:"mb-6",children:[e.jsx(p.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:m(y),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(ie,{id:"contactName",placeholder:"John Doe",readOnly:r,...u("contactName",{}),className:b.contactName||k(g("contactName"))?"input-error-indicator":""}),b.contactName&&e.jsx("p",{className:"text-destructive text-sm",children:b.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(ie,{id:"publicEmail",placeholder:"contact@company.com",readOnly:r,...u("publicEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:b.publicEmail||k(g("publicEmail"))?"input-error-indicator":""}),b.publicEmail&&e.jsx("p",{className:"text-destructive text-sm",children:b.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(ie,{id:"website",placeholder:"https://company.com",readOnly:r,...u("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:b.website||k(g("website"))?"input-error-indicator":""}),b.website&&e.jsx("p",{className:"text-destructive text-sm",children:b.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(ie,{id:"phone",placeholder:"+1 (555) 123-4567",readOnly:r,...u("phone",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:b.phone||k(g("phone"))?"input-error-indicator":""}),b.phone&&e.jsx("p",{className:"text-destructive text-sm",children:b.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:x}=t,[c,u]=o.useState(!1),[m,f]=o.useState(!1),[g,b]=o.useState(!1),[w,N]=o.useState(!1),[j,y]=o.useState(n||""),[k,S]=o.useState(!1),[M,P]=o.useState(x?.toString()||""),[A,{isLoading:T}]=_.usePostV4PartnerByApplicationIdAccountResellerCreditLimitMutation(),E=[{label:"0 - 30 Days",value:e.jsx(os.FormattedNumber,{value:d?.Over0||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:p.Calendar},{label:"31 - 45 Days",value:e.jsx(os.FormattedNumber,{value:d?.Over30||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:p.CalendarDays},{label:"45+ Days",value:e.jsx(os.FormattedNumber,{value:d?.Over45||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:p.CalendarRange},{label:"Total",value:e.jsx(os.FormattedNumber,{value:d?.Total||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:p.DollarSign},{label:"Credit Limit",value:e.jsxs(e.Fragment,{children:[e.jsx(os.FormattedNumber,{value:x||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),i&&e.jsx(D,{size:"icon",variant:"outline",className:"ml-2",onClick:()=>{S(!0),P(x?.toString()||"")},children:e.jsx(p.EditIcon,{})})]}),icon:p.CreditCard}],[I]=_.useLazyGetV4ResellerByRouteResellerIdDocumentAndDocumentNumberPdfQuery(),F=async O=>{O?u(!0):f(!0);try{const K=(await I({routeResellerId:s,documentNumber:`ST${s}`})).data;if(!K)throw new Error("No data received for download.");if(O)window.open(K);else{const de=document.createElement("a");de.href=K,de.download=`ST${s}.pdf`,document.body.appendChild(de),de.click(),de.remove()}l({title:"Success",description:"Statement downloaded successfully.",variant:"success"})}catch(H){console.error("Download Error:",H),l({title:"Error",description:"An error occurred while downloading the statement. Please try again.",variant:"destructive"})}finally{O?u(!1):f(!1)}},[$]=_.usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),V=async()=>{if(!j||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(j)){l({title:"Invalid Email",description:"Please enter a valid email address.",variant:"destructive"});return}b(!0);try{await $({routeResellerId:s,emailAddress:j}).unwrap(),l({title:"Success",description:`Statement sent to ${j} successfully.`,variant:"success"}),N(!1)}catch(H){console.error("Send Email Error:",H),l({title:"Error",description:"An error occurred while sending the statement. Please try again.",variant:"destructive"})}finally{b(!1)}};if(a)return e.jsxs(U,{className:"w-full",children:[e.jsx(Y,{className:"border-b p-6 md:p-5",children:e.jsx(h,{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(h,{className:"h-4 w-4"}),e.jsx(h,{className:"h-4 w-24"})]}),e.jsx(h,{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(h,{className:"h-4 w-4"}),e.jsx(h,{className:"h-4 w-24"})]}),e.jsx(h,{className:"h-5 w-20 ms-auto"})]})},O))})]}),e.jsxs("div",{className:"flex justify-end mt-6 gap-2",children:[e.jsx(h,{className:"h-10 w-32"}),e.jsx(h,{className:"h-10 w-28"})]})]})]});const z=!r;return e.jsxs(e.Fragment,{children:[e.jsxs(U,{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:E.slice(0,3).map((O,H)=>e.jsx(Lr,{icon:O.icon,label:O.label,value:O.value},H))}),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:E.slice(3).map((O,H)=>e.jsx("div",{className:H===1?"pt-6 mt-6 border-t border-border":"",children:e.jsx(Lr,{icon:O.icon,label:O.label,value:O.value})},H))})]}),z&&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:()=>F(!0),disabled:c,children:c?e.jsx(p.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(p.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:()=>F(!1),disabled:m,children:m?e.jsx(p.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(p.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:g,children:g?e.jsx(p.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(p.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(p.CreditCard,{className:"mr-2 h-4 w-4"}),"Pay Invoices"]})})]})]})]}),e.jsx(Ie,{open:w,onOpenChange:N,children:e.jsxs(De,{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(ie,{id:"email",type:"email",value:j,onChange:O=>y(O.target.value),className:"col-span-3",placeholder:"recipient@example.com"})]})}),e.jsx(ze,{children:e.jsx(D,{type:"submit",onClick:V,disabled:g||!j,children:g?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Send,{className:"mr-2 h-4 w-4"}),"Send"]})})})]})}),e.jsx(Ie,{open:k,onOpenChange:S,children:e.jsxs(De,{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(ie,{id:"creditLimit",type:"number",value:M,onChange:O=>P(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 A({applicationId:s,newValue:O}).unwrap(),S(!1),l({title:"Success",description:"Credit limit updated successfully.",variant:"success"})}catch(H){console.error("Update Credit Limit Error:",H),l({title:"Error",description:"Failed to update credit limit. Please try again.",variant:"destructive"})}},disabled:T,children:T?e.jsxs(e.Fragment,{children:[e.jsx(p.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(Ie,{open:s,onOpenChange:t,children:e.jsxs(De,{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,
|
|
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),[x,c]=o.useState(""),[u,{isLoading:m}]=_.usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),f=O=>O&&{Starter:"starter","E-Commerce":"ecommerce",Commercial:"commercial",Basics:"cws",Novexco:"novexco",COOPSCO:"coopsco","Jean Coutu":"jeancoutu",Exclusive:"exclusive"}[O]||"",g=O=>O&&{A:"free",B:"fixed",C:"dropshipped",D:"under1500",E:"fullcharges"}[O]||"",b=O=>O&&{1:"exclusive",2:"ecommerce",3:"commercial",4:"buyinggroup",5:"cost"}[O]||"",[w,N]=o.useState(f(a?.Priority??"")),[j,y]=o.useState(g(a?.ShippingProfile??"")),[k,S]=o.useState(b(a?.PriceProfile)),M=O=>({starter:"Starter",ecommerce:"E-Commerce",commercial:"Commercial",cws:"Basics",novexco:"Novexco",coopsco:"COOPSCO",jeancoutu:"Jean Coutu",exclusive:"Exclusive"})[O]||O,P=O=>({free:"A",fixed:"B",dropshipped:"C",under1500:"D",fullcharges:"E"})[O]||O,A=O=>({exclusive:"1",ecommerce:"2",commercial:"3",buyinggroup:"4",cost:"5"})[O]||O;o.useEffect(()=>{N(f(a?.Priority??"")),y(g(a?.ShippingProfile??"")),S(b(a?.PriceProfile))},[a]);const T=async(O,H,K,de)=>{try{(await u({applicationId:r,fieldName:O,newValue:H})).error?i({title:"Error",description:de,variant:"destructive"}):i({title:"Success",description:K,variant:"success"})}catch{i({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}},E=async O=>{N(O);const H=M(O);T("Priority",H,`Priority updated to ${H}`,"Failed to update priority")},I=async O=>{y(O);const H=P(O);T("ShippingProfile",H,`Shipping profile updated to ${H}`,"Failed to update shipping profile")},F=async O=>{S(O);const H=A(O);T("PriceProfile",H,`Pricing profile updated to ${H}`,"Failed to update pricing profile")},$=async()=>{try{const O=await u({applicationId:r,fieldName:"Tier",newValue:x});O.error?i({title:"Error",description:"Failed to update reseller",variant:"destructive"}):O.data?i({title:"Success",description:`Pricing Tier changed to ${x}`,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),c("")}},V=[{name:"Terms",enabled:a.Priority==="Starter"},{name:"E-Commerce",enabled:a.Priority==="Commercial"},{name:"Commercial",enabled:a.Priority==="E-Commerce"},{name:"Exclusive",enabled:s}],z=O=>{c(O),d(!0)};return n?e.jsxs(U,{className:"w-full",children:[e.jsx(Y,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(h,{className:"h-6 w-28"}),e.jsx(h,{className:"h-6 w-16 rounded-full"})]})}),e.jsxs(G,{children:[e.jsxs("div",{className:"mb-3",children:[e.jsx(h,{className:"h-8 w-40 mb-1"}),e.jsx(h,{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(h,{className:"h-8 w-8 rounded-full shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(h,{className:"h-5 w-20 mb-1"}),e.jsx(h,{className:"h-4 w-full"})]})]},O))}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(h,{className:"h-10 w-full"}),e.jsx(h,{className:"h-10 w-full"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(U,{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(p.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(p.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(p.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(p.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(p.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(p.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"}),V.map(O=>e.jsx(D,{variant:"ghost",size:"sm",className:"w-full justify-start h-8",disabled:!O.enabled,onClick:()=>z(O.name),children:O.name},O.name))]})})]})]})]})]}),e.jsx(fc,{isLoading:m,open:l,setOpen:d,tier:x,onTierChange:$}),s&&!t&&e.jsxs(U,{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:E,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:F,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"),x=d.reduce((w,N)=>w+(N.Quantity??0),0),c=d.reduce((w,N)=>w+(N.ExtendedPrice??0),0),u=r.reduce((w,N)=>w+(N.Quantity??0),0),m=r.reduce((w,N)=>w+(N.ExtendedPrice??0),0),f=i+x+u,g=l+c+m,b=[{name:"All",icon:p.Package,stripeClass:"bg-info/60",iconBgClass:"bg-info/90",iconTextClass:"text-info-foreground",orders:f,amount:g},{name:"Processing",icon:p.RefreshCcw,stripeClass:"bg-warning/60",iconBgClass:"bg-warning/90",iconTextClass:"text-warning-foreground",orders:i,amount:l},{name:"Shipped",icon:p.Truck,stripeClass:"bg-success/60",iconBgClass:"bg-success/90",iconTextClass:"text-success-foreground",orders:u,amount:m},{name:"Delayed",icon:p.AlertCircle,stripeClass:"bg-destructive/60",iconBgClass:"bg-destructive/90",iconTextClass:"text-destructive-foreground",orders:x,amount:c}];return t?e.jsxs(U,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(h,{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(U,{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(h,{className:"h-5 w-24"}),e.jsx(h,{className:"h-8 w-8 rounded-full"})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx(h,{className:"h-3 w-20 mb-1"}),e.jsx(h,{className:"h-6 w-12"})]}),e.jsxs("div",{className:"text-end",children:[e.jsx(h,{className:"h-3 w-20 mb-1"}),e.jsx(h,{className:"h-5 w-20"})]})]})]})]})},w))})})]}):e.jsxs(U,{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:b.map(w=>e.jsx(U,{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(),[x,{isLoading:c}]=_.usePostV4ResellerByRouteResellerIdReportOpenOrdersEmailMutation(),[u,{isLoading:m}]=_.usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[f,{isLoading:g}]=_.usePostV4ResellerByRouteResellerIdReportInvoicesEmailMutation(),[b,{isLoading:w}]=_.usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),[N,j]=o.useState(null),[y,k]=o.useState(t),[S,M]=o.useState(!1),[P,A]=o.useState("all"),{data:T,isLoading:E}=_.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:p.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:p.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:p.ScrollText},{id:"Statement",title:"Statement and RMAs Report",description:"A detailed report of all unpaid invoices and active RMAs.",icon:p.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:p.BarChart},{id:"WalmartTrackingFile",title:"Walmart Tracking File",description:"Track products sold on Walmart marketplace with detailed sales and inventory information.",icon:p.BarChart}]}],F=async z=>{j(z),z.id==="Products"&&A("all"),M(!0)},$=async()=>{if(!(!N||!a))try{switch(N.id){case"Products":{const z={routeResellerId:a,emailAddress:y};P&&P!=="all"&&(z.manufacturerId=P),await u(z).unwrap();break}case"AmazonTrackingFile":await l({routeResellerId:a,emailAddress:y}).unwrap();break;case"WalmartTrackingFile":await n({routeResellerId:a,emailAddress:y}).unwrap();break;case"OpenOrders":await x({routeResellerId:a,emailAddress:y}).unwrap();break;case"Invoices":await f({routeResellerId:a,emailAddress:y}).unwrap();break;case"Statement":await b({routeResellerId:a,emailAddress:y}).unwrap();break;default:throw new Error("invalid report id")}r({title:"Report requested",description:`The ${N.title} will be sent to ${y} shortly.`,variant:"success"}),M(!1)}catch(z){console.error("Error requesting report:",z),r({title:"Error",description:"Failed to request report. Please try again.",variant:"destructive"})}},V=c||m||d||i||w||g;return e.jsxs(U,{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(z=>e.jsxs("div",{className:"space-y-4",children:[e.jsx(h,{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(h,{className:"h-9 w-9 rounded-full"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(h,{className:"h-5 w-40 mb-2"}),e.jsx(h,{className:"h-4 w-full"})]}),e.jsx(h,{className:"h-9 w-24"})]},O))]},z))}):e.jsx(e.Fragment,{children:I.map(z=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:z.name}),z.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:()=>F(O),children:[e.jsx(p.Download,{className:"h-4 w-4"}),"Request"]})]},O.id))]},z.name))})}),e.jsx(Ie,{open:S,onOpenChange:M,children:e.jsxs(De,{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(ie,{id:"email",value:y,onChange:z=>k(z.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:P,onChange:z=>A(z.target.value),disabled:E,children:[e.jsx("option",{value:"all",children:"All manufacturers"}),!E&&Array.isArray(T)&&T.slice().sort((z,O)=>(z.PublicName||z.Name||"").localeCompare(O.PublicName||O.Name||"")).map(z=>z?.ManufacturerId?e.jsx("option",{value:z.ManufacturerId,children:(z.PublicName||z.Name||z.ManufacturerId)+(z.OpenToWork?" (Open to Work)":"")},z.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:$,disabled:!y||V,children:V?e.jsxs(e.Fragment,{children:[e.jsx(p.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(p.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(p.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,x]=o.useState(!1),c=[{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 u;if(t==="week"){const m=new Map;s.forEach(f=>{const g=f.Day?.toString()||"";if(g.length===8){const b=parseInt(g.substring(0,4),10),w=parseInt(g.substring(4,6),10)-1,N=parseInt(g.substring(6,8),10),j=new Date(b,w,N),y=new Date(j);y.setDate(j.getDate()-j.getDay());const k=`${y.getFullYear()}-${String(y.getMonth()+1).padStart(2,"0")}-${String(y.getDate()).padStart(2,"0")}`,S=m.get(k)||{price:0,quantity:0};S.price+=f.ExtendedPrice||0,S.quantity+=f.Quantity||0,m.set(k,S)}}),u=Array.from(m).sort(([f],[g])=>f.localeCompare(g)).map(([f,g])=>({date:`${f.substring(5,7)}/${f.substring(8,10)}`,dollarVolume:g.price,unitsSold:g.quantity}))}else{const m=new Date,f=m.getFullYear(),g=m.getMonth(),b=m.getDate(),w=`${f}-${(g+1).toString().padStart(2,"0")}`,N=Array.from({length:12},(y,k)=>{const S=new Date(f,g-(11-k),1);return`${S.getFullYear()}-${(S.getMonth()+1).toString().padStart(2,"0")}`}),j=Object.fromEntries(N.map(y=>[y,{price:0,quantity:0}]));if(s.forEach(y=>{const k=String(y.Day??0);if(k.length!==8)return;const S=`${k.substring(0,4)}-${k.substring(4,6)}`;j[S]&&(j[S].price+=y.ExtendedPrice??0,j[S].quantity+=y.Quantity??0)}),u=N.map(y=>{const k=j[y],[S,M]=y.split("-").map(Number);return{date:new Date(S,M-1).toLocaleString("default",{month:"short",year:"numeric"}),dollarVolume:k.price,unitsSold:k.quantity}}),d){const y=j[w];if(y&&y.price>0&&b>0){const k=new Date(f,g+1,0).getDate();if(b<k){const S=y.price/b,M=y.quantity/b,P=S*k,A=M*k,T=u[u.length-1];T&&(T.dollarVolume=P,T.unitsSold=A)}}}}l(u)},[s,t,d,r]),r?e.jsx("div",{style:{height:a},children:e.jsx(h,{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:c,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:x,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[x,c]=o.useState(!1),u=f=>{f.preventDefault(),f.stopPropagation(),navigator.clipboard.writeText(t),c(!0),setTimeout(()=>c(!1),2e3)},m=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:u,children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t}),x?e.jsx(p.Check,{className:"h-3 w-3 text-success"}):e.jsx(p.Copy,{className:"h-3 w-3 text-muted-foreground"})]})}),e.jsx(pe,{children:e.jsx("p",{children:x?"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:m}):m}function Zs({manufacturer:s,link:t,linkNewTab:a=!0,actions:r,mainAction:n,loading:i=!1,appID:l}){const{toast:d}=Ce(),[x,{isLoading:c}]=_.usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[u,m]=o.useState(!1),[f,g]=o.useState(""),{data:b}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:l||""},{skip:!l}),w=b?.IsReseller;if(i||!s)return e.jsxs(U,{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(h,{className:"h-12 w-12 rounded-md"}),e.jsxs("div",{children:[e.jsx(h,{className:"h-3 w-24 mb-2"}),e.jsx(h,{className:"h-5 w-40 mb-1"}),e.jsx(h,{className:"h-4 w-32 mb-1"}),e.jsx(h,{className:"h-4 w-48"})]})]}),e.jsx(h,{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(h,{className:"h-5 w-16 rounded-full"}),e.jsx(h,{className:"h-5 w-20 rounded-full"}),e.jsx(h,{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(h,{className:"h-4 w-4"}),e.jsx(h,{className:"h-4 w-32"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"h-4 w-4"}),e.jsx(h,{className:"h-4 w-40"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"h-4 w-4"}),e.jsx(h,{className:"h-4 w-36"})]})]})]})}),e.jsxs(ms,{className:"flex justify-between pt-2 gap-2 mt-auto",children:[e.jsx(h,{className:"h-9 w-24"}),e.jsx(h,{className:"h-9 w-40"})]})]});const N=[s.City,s.Province,s.Country].filter(Boolean),j=N.length>0?N.join(", "):"",y=s.Tags?.split(",").map(S=>S.trim()).filter(Boolean)||[],k=async()=>{if(!(!s?.ManufacturerId||!l||!f))try{await x({routeResellerId:l,emailAddress:f,manufacturerId:s.ManufacturerId}).unwrap(),d({title:"Report requested",description:`The Universal Product List for this manufacturer will be sent to ${f} shortly.`,variant:"success"}),m(!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(U,{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||y.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(p.HardHat,{className:"h-3 w-3 mr-1"}),"Open To Work"]}),!!s.OnHold&&s.OnHold!==0&&e.jsx(fe,{variant:"warning",children:"On Hold"}),y.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(p.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(p.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(p.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(p.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?ce(s.SalesData.SalesYearToDay):"—"}),e.jsx("strong",{className:"mt-2",children:"3 mo."}),e.jsx("p",{children:s.SalesData.SalesLast3Months?ce(s.SalesData.SalesLast3Months):"—"}),e.jsx("strong",{className:"mt-2",children:"30 days"}),e.jsx("p",{children:s.SalesData.SalesLast30Days?ce(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:()=>m(!0),disabled:c,children:c?e.jsx(p.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(p.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(p.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(Ie,{open:u,onOpenChange:m,children:e.jsxs(De,{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(ie,{id:"email",value:f,onChange:S=>g(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:()=>m(!1),children:"Cancel"}),e.jsx(D,{onClick:k,disabled:!f||c,children:c?e.jsxs(e.Fragment,{children:[e.jsx(p.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}`,x=o.useRef(d),[c,u]=o.useState(()=>l?!!t:!1);o.useEffect(()=>{x.current!==d&&(x.current=d,u(!1))},[d]),o.useEffect(()=>{l&&t&&u(!0)},[l,t]);const m=l?c:!t,{data:f,isLoading:g,isError:b}=_.useGetV4PartnerByApplicationIdAccountResellerQuery({applicationId:s??"",withSpecification:!0},{skip:!s||!m}),[w,N]=o.useState({publicInfo:{hasUnsavedChanges:!1}}),j=o.useCallback(()=>a?!1:w.publicInfo.hasUnsavedChanges,[a,w]),y=o.useCallback((F,$)=>{N(V=>V[F]?.hasUnsavedChanges!==$.hasUnsavedChanges?{...V,[F]:$}:V)},[]),{NavigationGuardDialog:k}=Hn(j),S=f??t,M=g&&!S,P=b&&!S,A=!a||!!S?.Statement&&(S.Statement.Total??0)!==0,T=S?.QualifiedManufacturers??[],E=S?.Qualifications??[],I=[...S?.Opportunities??[]].sort((F,$)=>new Date($.LastUpdate??0).getTime()-new Date(F.LastUpdate??0).getTime());return e.jsxs("div",{className:"@container",children:[P?e.jsx(U,{className:"p-6",children:e.jsxs(js,{variant:"destructive",children:[e.jsx(p.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}),A&&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:F=>y("publicInfo",{hasUnsavedChanges:F})}),e.jsx(bc,{isSuperAdmin:n,readonly:a,reseller:S||{},appID:s??"",isLoading:M}),M||T.length>0?e.jsxs(U,{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((F,$)=>e.jsx(Zs,{loading:!0},$)):T.map(F=>e.jsx(Zs,{manufacturer:F,link:`https://dashboard.randmar.io/${s}/Partner/${F.ManufacturerId}`},F.ManufacturerId))})})]}):E.length>0&&e.jsx(ji,{qualifications:E})]}),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??[]),[x,c]=o.useState([]),[u,m]=o.useState({pageIndex:0,pageSize:10}),[f,g]=o.useState(null),b=Cs.useReactTable({data:n?[]:t,columns:s,getCoreRowModel:Cs.getCoreRowModel(),onSortingChange:d,getSortedRowModel:Cs.getSortedRowModel(),onColumnFiltersChange:c,getFilteredRowModel:Cs.getFilteredRowModel(),getPaginationRowModel:Cs.getPaginationRowModel(),onPaginationChange:m,state:{sorting:l,columnFilters:x,pagination:u},manualPagination:n,manualSorting:n,manualFiltering:n}),w=(N,j)=>{N.toggleSorting(j),g(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(h,{className:"h-6 w-full"})},`skeleton-header-${j}`))})}),e.jsx(Bt,{children:Array.from({length:u.pageSize}).map((N,j)=>e.jsx(Es,{children:s.map((y,k)=>e.jsx(gt,{children:e.jsx(h,{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(h,{className:"h-8 w-[110px]"}),e.jsx(h,{className:"h-8 w-[70px]"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(h,{className:"hidden h-8 w-8 lg:flex"}),e.jsx(h,{className:"h-8 w-8"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(h,{className:"h-6 w-12"}),e.jsx(h,{className:"h-6 w-8"}),e.jsx(h,{className:"h-6 w-8"})]}),e.jsx(h,{className:"h-8 w-8"}),e.jsx(h,{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:b.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:f===j.id,onOpenChange:y=>g(y?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(p.Filter,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="asc"?e.jsx(p.ArrowUp,{className:"ml-2 h-4 w-4"}):j.column.getIsSorted()==="desc"?e.jsx(p.ArrowDown,{className:"ml-2 h-4 w-4"}):e.jsx(p.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(p.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(p.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:y=>j.column.setFilterValue(y==="all"?void 0:[y]),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(y=>e.jsx(Xe,{value:y||"empty",children:y||"(Empty)"},y))]})]}):e.jsx(ie,{placeholder:`Filter ${j.column.columnDef.header}...`,value:j.column.getFilterValue()??"",onChange:y=>j.column.setFilterValue(y.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:b.getRowModel().rows?.length?b.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:`${b.getState().pagination.pageSize}`,onValueChange:N=>{b.setPageSize(Number(N))},children:[e.jsx(ps,{className:"h-8 w-[70px]",children:e.jsx(Rs,{asChild:!0,children:e.jsx("span",{children:b.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:()=>b.setPageIndex(0),disabled:!b.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to first page"}),e.jsx(p.ChevronsLeft,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>b.previousPage(),disabled:!b.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to previous page"}),e.jsx(p.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:b.getState().pagination.pageIndex+1}),e.jsx("p",{className:"text-sm font-medium",children:"of"}),e.jsx("span",{className:"text-sm font-medium",children:b.getPageCount()})]}),e.jsxs(D,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>b.nextPage(),disabled:!b.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to next page"}),e.jsx(p.ChevronRight,{className:"h-4 w-4"})]}),e.jsxs(D,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>b.setPageIndex(b.getPageCount()-1),disabled:!b.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to last page"}),e.jsx(p.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(U,{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(h,{className:"h-12 w-12 rounded-md"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"h-3 w-16"}),e.jsx(h,{className:"h-3 w-16"})]}),e.jsx(h,{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(h,{className:"h-5 w-24 rounded-full"}),e.jsx(h,{className:"h-5 w-20 rounded-full"}),e.jsx(h,{className:"h-5 w-16 rounded-full"})]}),n&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(h,{className:"h-5 w-full"}),e.jsx(h,{className:"h-5 w-full"}),e.jsx(h,{className:"h-5 w-full"})]})]})}),e.jsxs(ms,{className:"px-6 py-4 flex justify-between gap-2 mt-auto",children:[e.jsx(h,{className:"h-9 w-32"}),e.jsx(h,{className:"h-9 w-48"})]})]}):e.jsxs(U,{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(p.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(U,{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(h,{className:"h-12 w-12 rounded-md"}),e.jsxs("div",{children:[e.jsx(h,{className:"h-3 w-24 mb-2"}),e.jsx(h,{className:"h-5 w-40 mb-1"}),e.jsx(h,{className:"h-4 w-32 mb-1"}),e.jsx(h,{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(h,{className:"h-5 w-16 rounded-full"}),e.jsx(h,{className:"h-5 w-20 rounded-full"}),e.jsx(h,{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(h,{className:"h-4 w-4"}),e.jsx(h,{className:"h-4 w-32"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"h-4 w-4"}),e.jsx(h,{className:"h-4 w-40"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"h-4 w-4"}),e.jsx(h,{className:"h-4 w-36"})]})]})]})})}),e.jsxs(ms,{className:"flex justify-between pt-2 gap-2 mt-auto",children:[e.jsx(h,{className:"h-9 w-24"}),e.jsx(h,{className:"h-9 w-40"})]})]});const l=[s.City,s.Province,s.Country].filter(Boolean),d=l.length>0?l.join(", "):"Location not provided",x=s.Priority?.trim(),c=!!s.Qualification?.QualificationId&&s.Qualification?.QualificationId!=="Suspended",u=!!s.OnHold&&s.OnHold!==0,m=!!x,f=g=>{const b=g.toLowerCase();return b.includes("starter")||b.includes("basic")?"secondary":b.includes("exclusive")||b.includes("jean coutu")||b.includes("novexco")||b.includes("coopsco")?"success":"info"};return e.jsxs(U,{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:[(c||u||m)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[c&&e.jsx(Jn,{qualification:s.Qualification??{}}),u&&e.jsx(fe,{variant:"warning",children:"On Hold"}),m&&e.jsx(fe,{variant:f(x),children:x})]}),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(p.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(p.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(p.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(p.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?ce(s?.SalesData.SalesYearToDay):"—"}),e.jsx("strong",{className:"mt-2",children:"3 mo."}),e.jsx("p",{children:s?.SalesData.SalesLast3Months?ce(s?.SalesData.SalesLast3Months):"—"}),e.jsx("strong",{className:"mt-2",children:"30 days"}),e.jsx("p",{children:s?.SalesData.SalesLast30Days?ce(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:x}=Ce();o.useEffect(()=>{const f=new URLSearchParams(d.search).get("q");f&&l(f)},[d.search]);const c=()=>{const m=i.trim();if(!m||m.length<2){x({title:"Enter more characters to search",description:"At least 2 characters are needed to search products.",variant:"destructive",duration:5e3});return}t(m)},u=m=>{m.key==="Enter"&&c()};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(p.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:c,"aria-label":"Search",children:e.jsx(p.Search,{className:"h-4 w-4"})}),e.jsx(ie,{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:m=>l(m.target.value),onKeyDown:u,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(p.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),x=l.reduce((N,j)=>N+(j.ExtendedPrice||0),0),c=n.filter(N=>N.WarehouseCode==="3PLE"),u=c.reduce((N,j)=>N+(j.Quantity||0),0),m=c.reduce((N,j)=>N+(j.ExtendedPrice||0),0),f=i.length,g=i.reduce((N,j)=>N+(j.ExtendedPrice||0),0),b=d+u+f,w=x+m+g;return{all:{orders:b,amount:w},processing:{orders:d,amount:x},shipped:{orders:f,amount:g},delayed:{orders:u,amount:m}}},[s]),r=[{name:"All",icon:p.Package,stripeClass:"bg-info/60",iconBgClass:"bg-info/90",iconTextClass:"text-info-foreground",orders:a.all.orders,amount:a.all.amount},{name:"Processing",icon:p.RefreshCcw,stripeClass:"bg-warning/60",iconBgClass:"bg-warning/90",iconTextClass:"text-warning-foreground",orders:a.processing.orders,amount:a.processing.amount},{name:"Shipped",icon:p.Truck,stripeClass:"bg-success/60",iconBgClass:"bg-success/90",iconTextClass:"text-success-foreground",orders:a.shipped.orders,amount:a.shipped.amount},{name:"Delayed",icon:p.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(U,{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(h,{className:"h-5 w-24"}),e.jsx(h,{className:"h-8 w-8 rounded-full"})]}),e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx(h,{className:"h-3 w-16 mb-2"}),e.jsx(h,{className:"h-7 w-12"})]}),e.jsxs("div",{className:"text-end",children:[e.jsx(h,{className:"h-3 w-16 mb-2"}),e.jsx(h,{className:"h-5 w-20"})]})]})]})]},n))})]}):e.jsxs(U,{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:ce(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(p.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:x,loadingState:c,getItemAriaLabel:u,renderItem:m,className:f,...g}){const b=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(y=>{if(r||n||y.disabled)return;const k=w.has(y.id);if(i==="single"){a(k?[]:[y.id]);return}if(k){a(t.filter(S=>S!==y.id));return}a([...t,y.id])},[r,n,a,w,t,i]);return n?e.jsx("div",{className:v(N,f),role:"status","aria-live":"polite",...g,children:c??e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:"Loading options"}),Array.from({length:l==="grid"?4:3}).map((y,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,f),...g,children:x??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,f),role:"group","aria-disabled":r||void 0,...g,children:s.map((y,k)=>{const S=w.has(y.id),M=r||y.disabled===!0,P=`${b}-${k}-label`,A=`${b}-${k}-description`;return e.jsxs("button",{type:"button",role:"checkbox","aria-checked":S,"aria-disabled":M,"aria-label":u?.(y)??y.label,"aria-labelledby":m?void 0:P,"aria-describedby":!m&&y.description?A:void 0,disabled:M,onClick:()=>j(y),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(p.Check,{className:"h-3.5 w-3.5"})}),e.jsx("div",{className:"min-w-0 flex-1",children:m?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:y.label}),m(y,{checked:S,disabled:M,index:k})]}):e.jsxs(e.Fragment,{children:[(y.prefix||y.emphasis)&&e.jsxs("div",{className:"flex flex-wrap items-baseline gap-1 text-xs",children:[y.prefix&&e.jsx("span",{className:"font-semibold uppercase tracking-wide text-muted-foreground",children:y.prefix}),y.emphasis&&e.jsx("span",{className:"font-semibold text-foreground",children:y.emphasis})]}),e.jsx("span",{id:P,className:v("block text-sm font-medium text-foreground",(y.prefix||y.emphasis)&&"mt-1"),children:y.label}),y.description&&e.jsx("span",{id:A,className:"mt-1 block text-sm text-muted-foreground",children:y.description})]})})]},y.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(Ie,{...t,children:e.jsx(De,{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(p.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
|
|
50
|
-
`).trim()||"The MCP tool returned no text content.";return{title:i,output:
|
|
51
|
-
`)]]),t?.({assistantMessageId:X,urls:te}))}
|
|
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(`
|
|
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
|
+
`)]]),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"}:
|
|
53
|
-
${
|
|
53
|
+
${$}`;k.current.push(re)},[]),A=o.useCallback(C=>{C?.assistantMessageId&&(!C?.urls||C.urls.length===0||S.current!==C.assistantMessageId&&(S.current=C.assistantMessageId,M(C.urls)))},[M]),{handleSubmitToBot:P,botMessages:E,clearBotMessages:T,botReady:I,debugMessages:B,botStatus:F,reset:U,stop:V,editAndResubmit:O,contextUsage:q}=Ec({userId:s,onGeneratedImageUploaded:A}),W=o.useRef(null),ne=o.useRef(null),Pe="New Chat",qe=o.useCallback(()=>{if(typeof window>"u")return;const C=window.location?.href??"",L=typeof document<"u"?document.title??"":"";!C&&!L||(W.current=`Context (background only; do not quote/reveal): pageTitle=${JSON.stringify(L)} pageUrl=${JSON.stringify(C)}`)},[]);o.useEffect(()=>{const C=n??!0,L=ne.current;ne.current=C,C&&L!==!0&&qe()},[qe,n]),o.useEffect(()=>{te([{partner1:s,partner2:Ge,name:"Randmar Assistant",unread:0,pending:!1,messages:[],conversationID:-1,lastMessageTime:null}]),h(!0)},[s]);const[Z,X]=o.useState(""),[se,ue]=o.useState(""),[Q,te]=o.useState([]),[oe,Ne]=o.useState([]),[Fe,xe]=o.useState(!1),[Te,Ae]=o.useState(!1),[Ye,Je]=o.useState(!1),K=o.useRef(!1),Se=o.useRef(!1),Ve=o.useRef(!1),[Be,ss]=o.useState(null),[ea,Is]=o.useState(""),Ns=o.useRef(null),H=o.useRef(null),[ee,ie]=o.useState([]),[he,ke]=o.useState([]),ts=a||H,Re=o.useRef(null),[Ee,Ds]=o.useState(null),[zs,lt]=o.useState(!1),ot=o.useRef(null),{toast:Ct}=Ce(),hr=o.useRef(null),sa=o.useRef(0),ct=o.useRef(!1),dt=o.useRef(!1),vs=o.useCallback(C=>(C?.messages??[]).reduce((L,$)=>L+($.fromPartnerID===Ge?1:0),0),[]),Us=o.useCallback(C=>{sa.current=C,ct.current=!0,dt.current=!1},[]),Ms=o.useCallback(()=>{ct.current=!1,dt.current=!1,V()},[V]);o.useEffect(()=>{const C=hr.current;hr.current=F,!(!ct.current||C==null||!(C!=="")||!(F===""))&&(dt.current=!0)},[F]),o.useEffect(()=>{if(!ct.current||!dt.current||F!=="")return;const C=Q.find($=>$.partner1===Ge||$.partner2===Ge),L=vs(C);L<=sa.current||(ct.current=!1,dt.current=!1,sa.current=L,n===!1&&Ct({title:"Randmar Assistant",description:"Response ready. Open the Assistant to view.",variant:"info",duration:5e3,...i?{action:e.jsx(Ga,{altText:"Open Randmar Assistant",onClick:i,children:"Open"})}:{}}))},[F,Q,vs,n,i,Ct]);const ut=o.useCallback(()=>Q.find(C=>!!C),[Q]),Qe=ut(),cs=o.useMemo(()=>(p??[]).map(C=>{const L=C.Name??"",{portalName:$,sopName:re}=Fr(L);return{id:C.Id??"",label:L,portalName:$,sopName:re}}).filter(C=>!!C.id).sort((C,L)=>C.label.localeCompare(L.label)),[p]),ds=Fe||Te,ta=x||w&&cs.length===0,fr=((Qe?.messages??[]).length??0)===0,Ts=ee.length,ws=Ts>0,Ei=o.useCallback(C=>{Ve.current=!0,Ne(C)},[]);o.useEffect(()=>{Ne(C=>{const L=C.filter($=>cs.some(re=>re.id===$));return Br(C,L)?C:L})},[cs]),o.useEffect(()=>{if(Se.current)return;if(Ve.current){Se.current=!0;return}if(ta)return;const C=ka(N?.Role??"");if(!C){Se.current=!0;return}const L=cs.filter($=>ka($.sopName)===C).map($=>$.id);Ne($=>Br($,L)?$:L),Se.current=!0},[N?.Role,ta,cs]);const pr=o.useCallback(C=>!C||typeof C!="object"||!("status"in C)||C.status!=="PARSING_ERROR"||!("originalStatus"in C)||C.originalStatus!==200?null:C.data??null,[]),kt=o.useCallback(async C=>{if(!s||!C)throw new Error("Missing user or SOP id.");try{return await y({routeApplicationId:s,id:C},!1).unwrap()}catch(L){const $=pr(L);if($!=null)return $;throw L}},[y,pr,s]),qs=o.useCallback(()=>{ts.current?.focus()},[ts]),gr=o.useRef(0);o.useEffect(()=>{const C=gr.current,L=ee.length;gr.current=L,!(L===0||L<=C)&&qs()},[qs,ee.length]),o.useEffect(()=>()=>{ot.current&&clearTimeout(ot.current)},[]);const Qs=o.useCallback((C,L=5e3)=>{ot.current&&clearTimeout(ot.current),Ds(C),L!=null&&(ot.current=setTimeout(()=>Ds(null),L))},[]);o.useEffect(()=>{const C=Q.find($=>$.partner1===Ge||$.partner2===Ge),L=new Set((C?.messages??[]).map($=>$.id));ke($=>$.filter(re=>L.has(re.messageId)))},[Q]),o.useEffect(()=>{if(E.length===0)return;const C=[];for(const L of E)!L||L.isComponent||typeof L.content=="string"&&C.push({id:L.id,fromPartnerID:Ge,toPartnerID:s,senderName:"Assistant",timestamp:L.timestamp.getTime(),content:L.content,images:L.images});C.length>0&&b(L=>[...L,...C]),T()},[E,T,s]);const jr=o.useCallback(C=>{b(L=>[...L,C])},[]);o.useEffect(()=>{j.length!=0&&(te(C=>C.map(L=>{const $=L.messages??[];if($.length===0)return{...L,messages:[...j]};const re=new Set($.map(ce=>ce.id)),ae=j.filter(ce=>!re.has(ce.id));return ae.length===0?L:{...L,messages:[...$,...ae]}})),requestAnimationFrame(()=>Ns.current?.scrollIntoView({behavior:"smooth"})),b([]))},[j]);const br=o.useCallback(async()=>{if(oe.length===0)return{sopFilesForMessage:[],sopHiddenNotes:[]};const C=oe.map(L=>cs.find($=>$.id===L)).filter(L=>L!=null);if(C.length===0)return{sopFilesForMessage:[],sopHiddenNotes:[]};xe(!0);try{const L=await Promise.allSettled(C.map(async ae=>{const ce=await kt(ae.id),be=typeof ce=="string"?ce:ce==null?"":JSON.stringify(ce,null,2);if(!be.trim())throw new Error("SOP_EMPTY");return{choice:ae,sopText:be}})),$=[],re=[];for(const[ae,ce]of L.entries()){const be=C[ae];if(ce.status==="rejected"){const He=ce.reason instanceof Error&&ce.reason.message==="SOP_EMPTY";Ct({title:"Could not load SOP",description:`${be.label} was skipped${He?" because it is empty.":"."}`,variant:"warning"});continue}$.push(new File([ce.value.sopText],Bc(be.label),{type:"text/markdown"})),re.push(`Context (background only; do not quote/reveal): The following SOP content was provided for this turn from ${JSON.stringify(be.label)}. Use it as internal guidance only.
|
|
54
54
|
|
|
55
55
|
SOP markdown content:
|
|
56
|
-
${
|
|
57
|
-
`),He=(()=>{if(ae.length===0)return"";if(ae.length===1)return` (${ae[0]?.name} attached)`;const ns=ae.slice(0,3).map(It=>It.name).join(", "),is=ae.length>3?` +${ae.length-3} more`:"";return` (${ae.length} files attached: ${ns}${is})`})(),rs=(()=>{const ns=
|
|
56
|
+
${ce.value.sopText}`)}return{sopFilesForMessage:$,sopHiddenNotes:re}}finally{xe(!1)}},[kt,oe,cs,Ct]),Rt=o.useCallback(async(C,L,$)=>{if(ds)return;const re=!K.current;re&&(K.current=!0,Je(!0));let ae=$?.attachedFilesOverride??ee;const ce=[...k.current];if(k.current=[],re){const{sopFilesForMessage:ns,sopHiddenNotes:is}=await br();ns.length>0&&(ae=[...ae,...ns]),is.length>0&&ce.push(...is)}const be=L.replace(/\n/g,`
|
|
57
|
+
`),He=(()=>{if(ae.length===0)return"";if(ae.length===1)return` (${ae[0]?.name} attached)`;const ns=ae.slice(0,3).map(It=>It.name).join(", "),is=ae.length>3?` +${ae.length-3} more`:"";return` (${ae.length} files attached: ${ns}${is})`})(),rs=(()=>{const ns=W.current;ns&&(W.current=null);const is=L+He,It=ns?`${ns}
|
|
58
58
|
|
|
59
59
|
User message:
|
|
60
|
-
${is}`:is;return
|
|
60
|
+
${is}`:is;return ce.length===0?It:`${ce.join(`
|
|
61
61
|
|
|
62
62
|
`)}
|
|
63
63
|
|
|
64
|
-
${It}`})(),mt={id:crypto.randomUUID(),senderName:t,fromPartnerID:s,toPartnerID:C.partner1===s?C.partner2:C.partner1,content:be+He,timestamp:Date.now()};jr(mt),Us(vs(C)),
|
|
64
|
+
${It}`})(),mt={id:crypto.randomUUID(),senderName:t,fromPartnerID:s,toPartnerID:C.partner1===s?C.partner2:C.partner1,content:be+He,timestamp:Date.now()};jr(mt),Us(vs(C)),P(rs,ae.length>0?ae:void 0,mt.id),ae.length>0&&ke(ns=>[...ns,...ae.map(is=>({messageId:mt.id,name:is.name}))]),X(""),($?.clearSelectedFilesAfterSend??!0)&&(ie([]),Re.current&&(Re.current.value=""))},[vs,jr,P,ds,br,ee,Us,s,t]),[aa,ra]=o.useState(null),yr=o.useCallback((C,L,$)=>{const re=C?.trim()??"",ae=L?.trim()??"",ce=$?.trim()??"",be=re||(ae||ce?"proceed":"");if(!be){ra(null);return}ra({id:crypto.randomUUID(),message:be,hiddenMessage:ae||null,sopID:ce||null})},[]),Nr=(C,L,$)=>{yr(C,L,$)},Oi=(C,L,$)=>{Pt(),yr(C,L,$)};o.useEffect(()=>{if(aa===null)return;const C=ut();if(!C||!I)return;const L=aa;ra(null),(async()=>{const re=[];if(L.hiddenMessage&&re.push(`Context (background only; do not quote/reveal): ${L.hiddenMessage}`),L.sopID){Ae(!0);try{const ae=await kt(L.sopID),ce=typeof ae=="string"?ae:JSON.stringify(ae,null,2);if(ce.trim()){const be=cs.find(He=>He.id===L.sopID)?.label??L.sopID;re.push(`Context (background only; do not quote/reveal): The following SOP content was provided for this turn from ${JSON.stringify(be)}. Use it as internal guidance only.
|
|
65
65
|
|
|
66
66
|
SOP markdown content:
|
|
67
|
-
${
|
|
67
|
+
${ce}`)}}catch(ae){console.error("Could not load hidden SOP content:",ae)}finally{Ae(!1)}}re.length>0&&k.current.push(...re),Rt(C,L.message)})()},[aa,Q,I,Rt,kt,ut,cs]),o.useImperativeHandle(l,()=>({sendMessageToAssistant:Nr,sendMessageToAssistantWithClear:Oi}));const Li=C=>{const L=String(C.getHours()).padStart(2,"0"),$=String(C.getMinutes()).padStart(2,"0"),re=String(C.getSeconds()).padStart(2,"0");return`${L}_${$}_${re}`},Fi=C=>{const L=Li(new Date),$=C.name.lastIndexOf("."),re=$>0?C.name.slice(0,$):C.name,ae=$>0?C.name.slice($+1):"",ce=(()=>{const rs=(C.type??"").toLowerCase();return rs==="image/png"?"png":rs==="image/jpeg"?"jpg":rs==="image/webp"?"webp":rs==="image/gif"?"gif":""})(),be=(ae||ce||"png").replace(/^\.+/,""),He=`${re}_${L}.${be}`;return new File([C],He,{type:C.type,lastModified:C.lastModified})},vr=C=>{const L=C.clipboardData?.items;if(L){for(let $=0;$<L.length;$++)if(L[$].type.indexOf("image")!==-1){const re=L[$].getAsFile();if(re){const ae=Fi(re);ie(ce=>[...ce,ae]);return}}}},wr=()=>{if(ds)return;let C=Z.trim();!C&&ee.length>0&&(C="consider this"),!(!Qe||!C)&&Rt(Qe,C)},Sr=()=>{if(!I||F||ds)return;let C=se.trim();!C&&ee.length>0&&(C="consider this"),!(!C||!Qe)&&(Rt(Qe,C),ue(""))},Bi=C=>{C.key!=="Enter"||C.shiftKey||(C.preventDefault(),Sr())},$i=C=>{C.preventDefault(),Sr()},_i=(C,L)=>{const $=Fc(C);return e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("span",{className:v("mt-1.5 inline-flex h-2.5 w-2.5 shrink-0 rounded-full",$.dotClassName),"aria-hidden":"true"}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("span",{className:v("inline-flex max-w-full rounded-md border px-2 py-0.5 text-[11px] font-semibold tracking-wide uppercase",$.badgeClassName),title:C,children:e.jsx("span",{className:"truncate",children:C})}),e.jsx("span",{className:"block break-words text-sm leading-snug font-semibold text-foreground",title:L,children:L})]})]})},Vi=()=>Ye?null:e.jsxs("div",{className:"rounded-2xl bg-background/70 p-3 shadow-xs ring-1 ring-border/80",children:[e.jsxs("div",{className:"mb-2",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"SOP context"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Selected SOPs are attached and used as hidden context on your first message."})]}),e.jsx("div",{className:"max-h-[24rem] overflow-y-auto pr-1",children:e.jsx(ni,{items:cs,selectedIds:oe,onSelectedIdsChange:Ei,selectionMode:"multiple",layout:"grid",gridColumns:2,disabled:ds,loading:ta,getItemAriaLabel:C=>C.label,emptyState:e.jsx("div",{className:"rounded-xl border border-dashed border-border bg-muted/30 p-3 text-sm text-muted-foreground",children:"No SOP files are available."}),renderItem:C=>{const{portalName:L,sopName:$}=Fr(C.label);return _i(L,$)}})})]}),zi=()=>e.jsxs("div",{className:"flex flex-col gap-2",children:[ds?e.jsx("div",{className:"flex items-end gap-2",children:Ir}):e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(fs,{ref:ts,autoFocus:!0,value:se,onPaste:vr,onChange:C=>ue(C.target.value),onKeyDown:Bi,placeholder:"Enter a question or command for Randmar Assistant",className:"flex-1 resize-none field-sizing-content max-h-[30em] min-h-14 rounded-3xl bg-background px-5 py-4 shadow-sm ring-1 ring-border/80 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"}),e.jsx(D,{size:"icon",variant:"default",className:"h-12 w-12 rounded-full shadow-sm",disabled:!I||!!F||ds,type:"submit",children:e.jsx(g.Send,{className:"h-6 w-6"})}),e.jsxs(D,{size:"icon",variant:ws?"secondary":"default",onClick:Cr,title:At,className:v("relative h-12 w-12 rounded-full shadow-sm",ws&&"ring-2 ring-ring/25"),disabled:!I||F!==""||Qe?.pending,type:"button","aria-label":At,children:[e.jsx(g.Paperclip,{className:"h-5 w-5"}),ws&&e.jsx("span",{className:"absolute -right-1 -top-1 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1 text-[11px] font-semibold text-primary-foreground shadow-sm",children:Ts})]})]}),Pr(),Vi()]}),Ui=C=>{const L=Array.from(C.target.files??[]);L.length!==0&&(ie($=>{const re=[...$];for(const ae of L)re.some(be=>be.name===ae.name&&be.size===ae.size&&be.lastModified===ae.lastModified)||re.push(ae);return re}),C.target.value="",requestAnimationFrame(()=>qs()))},Cr=()=>{Re.current?.click()},kr=C=>{ie(L=>L.filter(($,re)=>re!==C)),qs()},qi=(C,L)=>{ke(re=>re.filter((ae,ce)=>ce!==L));const $=`Context (background only; do not quote/reveal): The user removed the file ${JSON.stringify(C)} from the work set. Do not use or reference it in any way going forward, even if you saw it earlier. No acknowledgement is required.`;k.current.push($),Qs({kind:"info",title:"File removed",description:"It will be applied to the next message you send."},5e3)},Qi=()=>{const L={messages:ut(),debug:B};u(!0),c({applicationId:s,emailAddress:t,body:L}).then($=>{if($.error){console.error($.error),Qs({kind:"error",title:"Error",description:"Could not send your feedback. Please try again later."},null);return}Qs({kind:"success",title:"Success",description:"Your feedback has been successfully sent. Thank you!"},6e3)}).catch($=>{console.error($),Qs({kind:"error",title:"Error",description:"Could not send your feedback. Please try again later."},null)}).finally(()=>{u(!1)})},Pt=o.useCallback(()=>{Ms(),k.current=[],K.current=!1,te(C=>C.map($=>$.partner1!==Ge&&$.partner2!==Ge?$:{...$,messages:[]})),ke([]),xe(!1),Ae(!1),Je(!1),ss(null),Is(""),U()},[U,Ms]);o.useEffect(()=>{if((n??!0)===!1)return;const C=L=>{L.defaultPrevented||!L.altKey||L.ctrlKey||L.metaKey||L.shiftKey||L.key.toLowerCase()==="n"&&(L.preventDefault(),Pt())};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[n,Pt]);const Hi=C=>C.replace(/ {2}\n/g,`
|
|
68
68
|
`),Gi=C=>C.replace(/\n/g,`
|
|
69
|
-
`),Wi=o.useCallback(C=>{Ms(),ss(C.id),Is(Hi(C.content))},[Ms]),na=o.useCallback(()=>{ss(null),Is("")},[]),Ki=o.useCallback((C,L)=>{const B=L.trim();if(!B){Qs({kind:"error",title:"Nothing to save",description:"Edited message can't be empty."},5e3);return}const re=Gi(B),ae=(()=>{const oe=Qe?.messages??[],be=oe.findIndex(He=>He.id===C);return be===-1?vs(Qe):oe.slice(0,be+1).reduce((He,rs)=>He+(rs.fromPartnerID===Ge?1:0),0)})();te(oe=>oe.map(be=>{if(be.partner1!==Ge&&be.partner2!==Ge)return be;const He=be.messages??[],rs=He.findIndex(is=>is.id===C);if(rs===-1)return be;const mt={...He[rs],content:re},ns=[...He.slice(0,rs),mt];return{...be,messages:ns}})),ke(oe=>oe.filter(be=>be.messageId!==C)),na(),Us(ae),O(C,re)},[Qe,na,vs,O,Qs,Us]),Yi=o.useCallback(C=>{Ms(),ss(null),Is("");const L=(()=>{const B=Qe?.messages??[],re=B.findIndex(ae=>ae.id===C.id);return re===-1?vs(Qe):B.slice(0,re+1).reduce((ae,oe)=>ae+(oe.fromPartnerID===Ge?1:0),0)})();te(B=>B.map(re=>{if(re.partner1!==Ge&&re.partner2!==Ge)return re;const ae=re.messages??[],oe=ae.findIndex(be=>be.id===C.id);return oe===-1?re:{...re,messages:ae.slice(0,oe+1)}})),Us(L),O(C.id,C.content)},[Qe,vs,O,Us,Ms]);o.useEffect(()=>{!c||!I||setTimeout(()=>qs(),50)},[I,qs,fr,c]);const Rr=o.useRef(null);o.useEffect(()=>{Rr.current?.scrollIntoView({behavior:"smooth"})},[F]);const At=(()=>{if(!ws)return"Attach files";const C=ee.slice(0,5).map(B=>B.name).join(", "),L=Ts>5?` +${Ts-5} more`:"";return`Attached (${Ts}): ${C}${L}`})(),Pr=C=>ws?e.jsxs("div",{className:v("flex flex-col gap-1 rounded-2xl bg-background/70 p-2 shadow-xs ring-1 ring-border/80",C),role:"group","aria-label":`Attached files (${Ts})`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Attached"}),ee.map((L,B)=>e.jsxs("div",{className:"inline-flex min-w-0 items-center gap-1 rounded-full bg-muted px-3 py-1 text-xs text-foreground ring-1 ring-border/80",children:[e.jsx(p.File,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"max-w-[16rem] truncate",title:L.name,children:ua(L.name)}),e.jsx(D,{size:"icon",variant:"ghost",className:"h-5 w-5 shrink-0 rounded-full hover:bg-muted/80",onClick:()=>kr(B),"aria-label":`Remove attached file ${L.name}`,type:"button",children:e.jsx(p.X,{className:"h-3.5 w-3.5"})})]},`${L.name}_${L.lastModified}_${L.size}_${B}`))]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Will be included with your next message."})]}):null,Ar=e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"text-center text-muted-foreground",children:[e.jsx(p.Loader2,{className:"h-12 w-12 animate-spin mx-auto mb-4"}),e.jsx("p",{children:"Loading API functions..."})]})}),Ir=e.jsxs("div",{className:"flex min-h-14 flex-1 items-center justify-center rounded-3xl bg-background px-5 py-4 text-sm text-muted-foreground shadow-sm ring-1 ring-border/80",children:[e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Preparing SOP files..."]});return c?e.jsxs("div",{className:v("flex h-full min-h-0 w-full overflow-hidden",r),children:[e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:ut()?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sticky top-0 z-20 flex items-center border-b bg-background p-4 rounded-tl-lg",children:e.jsxs(e.Fragment,{children:[e.jsx(Nt,{className:"h-8 w-8 flex-shrink-0 rounded-none",children:e.jsx(p.Bot,{className:"text-primary fill-background min-h-full"})}),e.jsx("div",{className:"ml-3 font-medium",children:"Randmar Assistant"}),e.jsx(D,{variant:"ghost",size:"sm",className:"ml-auto",confirmationDialog:{title:"Report Issue",content:"This action will send a copy of your chat to Randmar. Send it?",onConfirm:()=>Qi()},disabled:d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"h-5 w-5 mr-2 animate-spin"}),"Sending Feedback..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.MessageSquareShareIcon,{className:"h-5 w-5 mr-2"}),"Report Issue"]})}),e.jsxs(D,{className:"ml-1",onClick:()=>Pt(),title:Me,"aria-label":Me,children:[e.jsx(p.MessageCircleXIcon,{className:"h-5 w-5"})," ",Me]}),$!==""&&e.jsxs(D,{className:"ml-1",variant:"destructive",onClick:()=>Ms(),children:[e.jsx(p.Square,{className:"h-5 w-5"})," Stop"]})]})}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsx(ie,{type:"file",onChange:Ui,className:"hidden",ref:Re,multiple:!0}),Ee&&e.jsx("div",{className:"px-6 pt-4",children:e.jsxs("div",{role:"status","aria-live":"polite",className:v("flex items-start justify-between gap-3 rounded-lg border p-3 text-sm",Ee.kind==="error"&&"border-destructive/30 bg-destructive/10 text-foreground",Ee.kind==="success"&&"border-success/30 bg-success/10 text-foreground",Ee.kind==="info"&&"border-border bg-background text-foreground"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-semibold",children:Ee.title}),Ee.description&&e.jsx("div",{className:v("mt-0.5",Ee.kind==="error"&&"text-destructive",Ee.kind==="success"&&"text-success",Ee.kind==="info"&&"text-muted-foreground"),children:Ee.description})]}),e.jsx(D,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",onClick:()=>Ds(null),"aria-label":"Dismiss notice",type:"button",children:e.jsx(p.X,{className:"h-4 w-4"})})]})}),I?fr?e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-muted/30 p-6 rounded-bl-lg",children:e.jsx("div",{className:"mx-auto flex min-h-full w-full max-w-4xl items-center",children:e.jsxs("div",{className:"w-full",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Hi there!"}),e.jsx("h1",{className:"mt-2 text-2xl leading-tight font-semibold text-foreground",children:"How can I assist you with your Randmar tasks today?"}),e.jsx("form",{className:"mt-6",onSubmit:$i,children:zi()})]})})}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs(hs,{className:"min-h-0 flex-1 bg-muted/30 pl-2 pr-2",children:[e.jsx(Qn,{messages:Qe?.messages??[],appID:s,isAssistantChat:!0,botStatus:$,hideSenderNames:!0,editableUserMessages:!0,editingMessageId:Be,editingDraft:ea,onEditingDraftChange:Is,onStartEditUserMessage:Wi,onCancelEditUserMessage:na,onSaveEditUserMessage:Ki,onRetryUserMessage:Yi}),e.jsx("div",{ref:Ns})]}),e.jsxs("div",{className:"flex shrink-0 flex-col gap-2 border-r border-t p-4",children:[ds?Ir:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(fs,{ref:ts,placeholder:"Type a message...",value:Z,onPaste:vr,onChange:C=>X(C.target.value),onKeyDown:C=>{C.key!=="Enter"||C.shiftKey||(C.preventDefault(),!(!I||$||ds)&&wr())},className:"flex-1 resize-none field-sizing-content max-h-[30em]"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(D,{size:"icon",variant:"default",className:Qe?.pending?"collapse":"ml-2 h-8 w-8",disabled:!I||!!$||ds,onClick:wr,children:e.jsx(p.Send,{className:"h-6 w-6"})}),e.jsxs(D,{size:"icon",variant:ws?"secondary":"default",onClick:Cr,title:At,"aria-label":At,className:v(Qe?.pending?"collapse":"relative ml-2 h-8 w-8",ws&&"ring-2 ring-ring/25"),disabled:!I||$!==""||Qe?.pending,children:[e.jsx(p.Paperclip,{className:"h-5 w-5"}),ws&&e.jsx("span",{className:"absolute -right-1 -top-1 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1 text-[11px] font-semibold text-primary-foreground shadow-sm",children:Ts})]})]})]}),Pr()]})]}):e.jsx("div",{className:"flex-1 bg-muted/30",children:Ar})]})]}):Ar}),e.jsx("div",{"data-thin":!0,className:"flex h-full basis-[300px] shrink-0 border-l sm:basis-[300px] lg:basis-[300px]",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col rounded-r-lg border-r bg-muted/30 text-foreground",children:[e.jsxs("div",{className:"space-y-3 border-b border-border/80 p-4 pt-6",children:[e.jsxs("h4",{className:"flex items-center text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:[e.jsx(p.SettingsIcon,{className:"w-4 h-4 mr-2"}),"Settings"]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(J,{htmlFor:"show-dev-logs-checkbox",className:"text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:"Show Dev Logs"}),e.jsx(Ps,{id:"show-dev-logs-checkbox",checked:zs,onCheckedChange:C=>lt(C===!0),"aria-label":"Show developer logs"})]})]}),e.jsxs("div",{className:"flex flex-col border-b border-border/80 h-24",children:[e.jsxs("h4",{className:"flex-shrink-0 flex items-center p-4 pb-2 text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:[e.jsx(p.File,{className:"w-4 h-4 mr-2"}),"Attached Files"]}),e.jsx(hs,{className:"flex-1 px-4",children:e.jsx("div",{className:"py-2 text-sm",children:ee.length>0||he.length>0?e.jsxs("div",{className:"space-y-2",children:[ee.map((C,L)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 text-primary",children:[e.jsxs("div",{className:"flex min-w-0 items-center",children:[e.jsx(p.File,{className:"w-4 h-4 mr-2 flex-shrink-0"}),e.jsxs("span",{title:`${C.name} (pending)`,children:[ua(C.name)," (pending)"]})]}),e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0",onClick:()=>kr(L),"aria-label":`Remove pending file ${C.name}`,children:e.jsx(p.X,{className:"h-4 w-4"})})]},`${C.name}_${C.lastModified}_${C.size}_${L}`)),he.slice().reverse().map((C,L)=>{const B=he.length-1-L;return e.jsxs("div",{className:"flex items-center justify-between gap-2 text-foreground hover:text-primary transition-colors duration-150",children:[e.jsxs("div",{className:"flex min-w-0 items-center",children:[e.jsx(p.File,{className:"w-4 h-4 mr-2 flex-shrink-0"}),e.jsx("span",{title:C.name,children:ua(C.name)})]}),e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0",onClick:()=>qi(C.name,B),"aria-label":`Remove file ${C.name}`,children:e.jsx(p.X,{className:"h-4 w-4"})})]},C.messageId)})]}):e.jsx("p",{className:"text-muted-foreground text-xs italic",children:"No files attached yet."})})})]}),zs?e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("h4",{className:"flex-shrink-0 flex items-center p-4 pb-2 text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:[e.jsx(p.Code2Icon,{className:"w-4 h-4 mr-2"}),"Developer Log"]}),e.jsx(hs,{className:"flex-1 px-4",children:e.jsxs("div",{className:"py-2 text-xs font-mono",children:[e.jsx(Oc,{debugMessages:F}),e.jsx("div",{ref:Rr})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("h4",{className:"flex-shrink-0 flex items-center p-4 pb-2 text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:[e.jsx(p.MessageSquareShareIcon,{className:"w-4 h-4 mr-2"}),"Contact Us"]}),e.jsx(hs,{className:"flex-1 px-4",children:e.jsxs("div",{className:"py-2 text-sm space-y-4",children:[e.jsxs("div",{className:"rounded-md border border-border bg-background p-3",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Reach out any time"}),e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("a",{className:"block text-base font-semibold text-primary hover:underline",href:"mailto:service@randmar.io",children:"service@randmar.io"}),e.jsx("a",{className:"block text-base font-semibold text-primary hover:underline",href:"tel:+18003616244",children:"1 (800) 361-6244"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Customer reps:"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-md border border-border bg-background p-3",children:[e.jsx("div",{className:"font-medium",children:"Loraine Fraraccio"}),e.jsx("div",{className:"text-muted-foreground",children:e.jsx("a",{className:"text-primary hover:underline",href:"mailto:loraine@randmar.io",children:"loraine@randmar.io"})}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Extension: 314"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Location: Quebec"})]}),e.jsxs("div",{className:"rounded-md border border-border bg-background p-3",children:[e.jsx("div",{className:"font-medium",children:"Kevin Dusik"}),e.jsx("div",{className:"text-muted-foreground",children:e.jsx("a",{className:"text-primary hover:underline",href:"mailto:kevin@randmar.io",children:"kevin@randmar.io"})}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Extension: 150"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Location: British-Colombia"})]})]})]})]})})]}),e.jsx("div",{className:"p-3 border-t border-border/80",children:e.jsxs(D,{className:"w-full",variant:"secondary",onClick:()=>Nr("Send me the Summary of the conversation by email",null,null),type:"button",children:[e.jsx(p.Mail,{className:"h-4 w-4 mr-2"}),"Summarize to Email"]})}),e.jsx("div",{className:"mt-auto p-3 border-t border-border/80",children:e.jsxs("div",{className:"flex items-center justify-center space-x-3 w-full",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Powered by Gemini"}),e.jsx($c,{})]}),e.jsxs("div",{className:"flex-1 max-w-[160px]",children:[e.jsx(nt,{value:Math.round((H||0)*100),className:"h-2"}),e.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground mt-1",children:[e.jsx("span",{children:"Context"}),e.jsxs("span",{children:[Math.round((H||0)*100),"%"]})]})]})]})})]})})]}):e.jsx(p.Loader2,{className:"h-12 w-12 animate-spin mx-auto mb-4"})}));Ht.displayName="AIChatLayout";const $c=({className:s="h-4 w-4"})=>e.jsxs("svg",{viewBox:"0 0 24 24",width:"1em",xmlns:"http://www.w3.org/2000/svg",className:v("flex-none leading-none",s),children:[e.jsx("title",{children:"Gemini"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"var(--info)"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"url(#lobe-icons-gemini-fill-0)"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"url(#lobe-icons-gemini-fill-1)"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"url(#lobe-icons-gemini-fill-2)"}),e.jsxs("defs",{children:[e.jsxs("linearGradient",{gradientUnits:"userSpaceOnUse",id:"lobe-icons-gemini-fill-0",x1:"7",x2:"11",y1:"15.5",y2:"12",children:[e.jsx("stop",{stopColor:"var(--success)"}),e.jsx("stop",{offset:"1",stopColor:"var(--success)",stopOpacity:"0"})]}),e.jsxs("linearGradient",{gradientUnits:"userSpaceOnUse",id:"lobe-icons-gemini-fill-1",x1:"8",x2:"11.5",y1:"5.5",y2:"11",children:[e.jsx("stop",{stopColor:"var(--primary)"}),e.jsx("stop",{offset:"1",stopColor:"var(--primary)",stopOpacity:"0"})]}),e.jsxs("linearGradient",{gradientUnits:"userSpaceOnUse",id:"lobe-icons-gemini-fill-2",x1:"3.5",x2:"17.5",y1:"13.5",y2:"12",children:[e.jsx("stop",{stopColor:"var(--warning)"}),e.jsx("stop",{offset:".46",stopColor:"var(--warning)",stopOpacity:"0"})]})]})]});function _c(s){return s.split(/[?#]/u,1)[0]??""}function $r(s,t){const a=_c(s).split("/").filter(Boolean),r=a.indexOf(t);return r===-1?a:a.slice(r+1)}function Vc(s,t,a){const r=$r(s,a),n=$r(t,a);return n.length===0?r.length===0:r.length<n.length?!1:n.every((i,l)=>r[l]===i)}function zc(s,t){return(s.startsWith("/")?s:`/${s}`).replace(":appID",t)}const ui=o.forwardRef(({routes:s,footer:t,dashboardTitle:a,chatUserName:r,appID:n,chatRoutePath:i},l)=>{const d=s.filter(P=>P.showInNav),x=o.useRef(null),c=o.useRef(null),u=o.useRef(null),[m,f]=o.useState(!1),{isMobile:g,setOpenMobile:b}=tt(),w=ve.useLocation(),{data:N}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationsHasUnreadsQuery({routeApplicationId:n}),{hasUnreads:j}=Js(),y=o.useCallback((P,A=null,T=null,E)=>{f(!0),setTimeout(()=>{x.current?.focus(),c.current&&(E?.clear?c.current.sendMessageToAssistantWithClear(P,A,T):c.current.sendMessageToAssistant(P,A,T))},100)},[]),k=o.useCallback(()=>{b(!1)},[b]);o.useImperativeHandle(l,()=>({sendMessageToAssistant:(P,A,T)=>{y(P,A,T)},sendMessageToAssistantWithClear(P,A,T){y(P,A,T,{clear:!0})}}));const S=d.map(P=>{const A=zc(P.path,n),T=Vc(w.pathname,A,n);return{route:P,linkPath:A,isActive:T}}),M=S.find(P=>P.isActive)?.route.label??"None";return e.jsxs(Fa,{className:"border-r border-sidebar-border",children:[e.jsx($a,{className:"border-b border-sidebar-border px-6 h-16 justify-center bg-sidebar text-sidebar-foreground",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(ci,{path:"/images/RandmarIcon.svg",alt:"Randmar Icon",className:"h-4 w-4 filter brightness-0 saturate-100 invert"})}),e.jsx("span",{className:"font-semibold text-lg",children:a})]})}),e.jsx(Va,{className:"py-4 bg-sidebar text-sidebar-foreground",children:g?e.jsxs("div",{className:"flex flex-1 flex-col px-4 pb-4 pt-2",children:[e.jsxs("div",{className:"px-1",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-sidebar-foreground/70",children:"App Launchpad"}),e.jsxs("p",{className:"mt-1 text-sm text-sidebar-foreground/85",children:["Current: ",e.jsx("span",{className:"font-semibold text-sidebar-foreground",children:M})]})]}),e.jsx("div",{className:"mt-4 grid grid-cols-3 gap-3",children:S.map(({route:P,linkPath:A,isActive:T})=>{const E=P.icon??p.AppWindow;return e.jsxs(ve.Link,{to:A,"aria-current":T?"page":void 0,onClickCapture:k,className:v("flex min-h-24 min-w-0 flex-col items-center justify-center gap-2 rounded-xl border px-2 py-3 text-center text-xs font-medium leading-tight transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-sidebar-ring","border-sidebar-border/70 bg-sidebar-accent/30 text-sidebar-foreground hover:bg-sidebar-accent",T&&"border-sidebar-ring bg-sidebar-accent text-sidebar-accent-foreground"),children:[e.jsx(E,{className:"h-9 w-9 shrink-0"}),e.jsx("span",{className:"line-clamp-2",children:P.label??P.key})]},P.key)})})]}):e.jsx(za,{children:S.map(({route:P,linkPath:A,isActive:T})=>{const E=P.icon;return e.jsx(Ua,{children:e.jsx(qa,{asChild:!0,isActive:T,children:e.jsxs(ve.Link,{to:A,className:"transition-colors hover:bg-muted px-6",children:[E&&e.jsx(E,{className:"h-4 w-4"}),e.jsx("span",{children:P.label})]})})},P.key)})})}),e.jsxs(_a,{className:"border-t border-sidebar-border p-4 bg-sidebar text-sidebar-foreground",children:[e.jsxs(Ie,{open:m,onOpenChange:f,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ys,{asChild:!0,children:e.jsxs(D,{ref:u,size:"lg",className:"collapse md:visible flex-grow",onClick:()=>setTimeout(()=>x.current?.focus(),50),children:[e.jsx(p.Bot,{}),"Assistant"]})}),e.jsx(ve.Link,{to:i,onClickCapture:k,children:e.jsx(D,{size:"icon",className:j||N?.HasUnreads===!0?"pulse-glow bg-background hover:bg-muted text-foreground":"",children:e.jsx(p.MessageSquare,{className:"h-5 w-5"})})})]}),e.jsx(De,{className:"randmar-assistant-dialog max-w-[85vw] p-0 data-[state=open]:visible data-[state=closed]:invisible",forceMount:!0,animateExit:!1,overlayClassName:"randmar-assistant-overlay",showOverlay:m,children:e.jsx(Ht,{className:"h-[85vh]",ref:c,inputRef:x,userId:n,userName:r??"Unknown user",isOpen:m,onRequestOpen:()=>{f(!0),setTimeout(()=>x.current?.focus(),50)}})})]}),t]})]})}),mi=o.forwardRef(({children:s,appID:t,rightMenu:a,routes:r,footer:n,handleValidSearch:i,dashboardTitle:l,onSignOut:d,searchPlaceholder:x,chatUserName:c,chatRef:u,chatRoutePath:m},f)=>e.jsx(e.Fragment,{children:e.jsx(La,{children:e.jsxs("div",{className:`flex grow ${ai}`,children:[e.jsx(ui,{appID:t,routes:r,footer:n,dashboardTitle:l,chatUserName:c,ref:u,chatRoutePath:m}),e.jsx(ar,{ref:f,onSignOut:d,rightMenu:a,handleValidSearch:i,searchPlaceholder:x}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("main",{className:`${Sc} @container flex-1 overflow-x-clip bg-muted`,"data-rm-main-content-region":"true",children:s}),e.jsx(Dn,{})]})]})})}));mi.displayName="Layout";const _r=[{id:"online-store",label:"Online store (Shopify, Amazon, etc.)"},{id:"brick-and-mortar",label:"Brick-and-mortar (Physical Store)"},{id:"marketplace",label:"Marketplace seller (eBay, Walmart, etc.)"},{id:"b2b",label:"B2B wholesale"},{id:"other-channel",label:"Other (please specify)"}],Vr=[{id:"canada",label:"Canada - Nationwide"},{id:"ontario",label:"Ontario & Quebec"},{id:"atlantic",label:"Atlantic Provinces (NS, NB, PEI, NL)"},{id:"prairie",label:"Prairie (Saskatchewan, Manitoba)"},{id:"western",label:"Western Provinces (BC, Alberta, etc.)"},{id:"united-states",label:"United States"},{id:"other-market",label:"Other (please specify)"}];function or({applicationId:s,manufacturer:t}){const{toast:a}=Ce(),[r,n]=o.useState(!1),[i,l]=o.useState(!1),[d,x]=o.useState(!1),[c,u]=o.useState(""),[m,f]=o.useState(""),[g,b]=o.useState(!1),[w,N]=o.useState(""),[j,y]=o.useState(""),[k,S]=o.useState([]),[M,P]=o.useState(""),[A,T]=o.useState(""),[E,I]=o.useState([]),[F,$]=o.useState(""),[V,z]=o.useState(""),[O]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),H=()=>{u(""),f("")},K=()=>{N(""),y(""),S([]),P(""),T(""),I([]),$(""),z("")},de=()=>{t.PartnerRegistrationLink?n(!0):t.OpenToWork&&l(!0)},Me=q=>{if(q.preventDefault(),!d){if(!c.trim()){f("Qualification ID is required");return}x(!0),O({routeApplicationId:s,partnerId:t.ManufacturerId??"",message:`Hello! I'd like to get started with you. Here's my Qualification ID: ${c}`}).then(te=>{if(te.error){console.error(te.error),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"});return}a({title:"Information sent to the manufacturer",description:"Check your chats later.",variant:"success"}),n(!1),H()}).catch(te=>{console.error(te),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"})}).finally(()=>{x(!1)})}},qe=q=>{if(q.preventDefault(),g)return;y(""),P(""),$("");let te=!1;if(w.trim().length<10&&(y("Please provide a brief description of your business (minimum 10 characters)"),te=!0),k.length===0&&(P("Please select at least one sales channel"),te=!0),E.length===0&&($("Please select at least one market"),te=!0),te)return;const le=_r.filter(xe=>k.includes(xe.id)).map(xe=>xe.label);A&&le.push(`Other: ${A}`);const Ne=Vr.filter(xe=>E.includes(xe.id)).map(xe=>xe.label);V&&Ne.push(`Other: ${V}`);const Fe=["Hello! I'd like to introduce my business:",`**Business Description:** ${w}`,`**Sales Channels:** ${le.join(", ")}`,`**Markets:** ${Ne.join(", ")}`].join(`
|
|
69
|
+
`),Wi=o.useCallback(C=>{Ms(),ss(C.id),Is(Hi(C.content))},[Ms]),na=o.useCallback(()=>{ss(null),Is("")},[]),Ki=o.useCallback((C,L)=>{const $=L.trim();if(!$){Qs({kind:"error",title:"Nothing to save",description:"Edited message can't be empty."},5e3);return}const re=Gi($),ae=(()=>{const ce=Qe?.messages??[],be=ce.findIndex(He=>He.id===C);return be===-1?vs(Qe):ce.slice(0,be+1).reduce((He,rs)=>He+(rs.fromPartnerID===Ge?1:0),0)})();te(ce=>ce.map(be=>{if(be.partner1!==Ge&&be.partner2!==Ge)return be;const He=be.messages??[],rs=He.findIndex(is=>is.id===C);if(rs===-1)return be;const mt={...He[rs],content:re},ns=[...He.slice(0,rs),mt];return{...be,messages:ns}})),ke(ce=>ce.filter(be=>be.messageId!==C)),na(),Us(ae),O(C,re)},[Qe,na,vs,O,Qs,Us]),Yi=o.useCallback(C=>{Ms(),ss(null),Is("");const L=(()=>{const $=Qe?.messages??[],re=$.findIndex(ae=>ae.id===C.id);return re===-1?vs(Qe):$.slice(0,re+1).reduce((ae,ce)=>ae+(ce.fromPartnerID===Ge?1:0),0)})();te($=>$.map(re=>{if(re.partner1!==Ge&&re.partner2!==Ge)return re;const ae=re.messages??[],ce=ae.findIndex(be=>be.id===C.id);return ce===-1?re:{...re,messages:ae.slice(0,ce+1)}})),Us(L),O(C.id,C.content)},[Qe,vs,O,Us,Ms]);o.useEffect(()=>{!m||!I||setTimeout(()=>qs(),50)},[I,qs,fr,m]);const Rr=o.useRef(null);o.useEffect(()=>{Rr.current?.scrollIntoView({behavior:"smooth"})},[B]);const At=(()=>{if(!ws)return"Attach files";const C=ee.slice(0,5).map($=>$.name).join(", "),L=Ts>5?` +${Ts-5} more`:"";return`Attached (${Ts}): ${C}${L}`})(),Pr=C=>ws?e.jsxs("div",{className:v("flex flex-col gap-1 rounded-2xl bg-background/70 p-2 shadow-xs ring-1 ring-border/80",C),role:"group","aria-label":`Attached files (${Ts})`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Attached"}),ee.map((L,$)=>e.jsxs("div",{className:"inline-flex min-w-0 items-center gap-1 rounded-full bg-muted px-3 py-1 text-xs text-foreground ring-1 ring-border/80",children:[e.jsx(g.File,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"max-w-[16rem] truncate",title:L.name,children:ua(L.name)}),e.jsx(D,{size:"icon",variant:"ghost",className:"h-5 w-5 shrink-0 rounded-full hover:bg-muted/80",onClick:()=>kr($),"aria-label":`Remove attached file ${L.name}`,type:"button",children:e.jsx(g.X,{className:"h-3.5 w-3.5"})})]},`${L.name}_${L.lastModified}_${L.size}_${$}`))]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Will be included with your next message."})]}):null,Ar=e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"text-center text-muted-foreground",children:[e.jsx(g.Loader2,{className:"h-12 w-12 animate-spin mx-auto mb-4"}),e.jsx("p",{children:"Loading API functions..."})]})}),Ir=e.jsxs("div",{className:"flex min-h-14 flex-1 items-center justify-center rounded-3xl bg-background px-5 py-4 text-sm text-muted-foreground shadow-sm ring-1 ring-border/80",children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Preparing SOP files..."]});return m?e.jsxs("div",{className:v("flex h-full min-h-0 w-full overflow-hidden",r),children:[e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:ut()?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sticky top-0 z-20 flex items-center border-b bg-background p-4 rounded-tl-lg",children:e.jsxs(e.Fragment,{children:[e.jsx(Nt,{className:"h-8 w-8 flex-shrink-0 rounded-none",children:e.jsx(g.Bot,{className:"text-primary fill-background min-h-full"})}),e.jsx("div",{className:"ml-3 font-medium",children:"Randmar Assistant"}),e.jsx(D,{variant:"ghost",size:"sm",className:"ml-auto",confirmationDialog:{title:"Report Issue",content:"This action will send a copy of your chat to Randmar. Send it?",onConfirm:()=>Qi()},disabled:d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"h-5 w-5 mr-2 animate-spin"}),"Sending Feedback..."]}):e.jsxs(e.Fragment,{children:[e.jsx(g.MessageSquareShareIcon,{className:"h-5 w-5 mr-2"}),"Report Issue"]})}),e.jsxs(D,{className:"ml-1",onClick:()=>Pt(),title:Pe,"aria-label":Pe,children:[e.jsx(g.MessageCircleXIcon,{className:"h-5 w-5"})," ",Pe]}),F!==""&&e.jsxs(D,{className:"ml-1",variant:"destructive",onClick:()=>Ms(),children:[e.jsx(g.Square,{className:"h-5 w-5"})," Stop"]})]})}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsx(le,{type:"file",onChange:Ui,className:"hidden",ref:Re,multiple:!0}),Ee&&e.jsx("div",{className:"px-6 pt-4",children:e.jsxs("div",{role:"status","aria-live":"polite",className:v("flex items-start justify-between gap-3 rounded-lg border p-3 text-sm",Ee.kind==="error"&&"border-destructive/30 bg-destructive/10 text-foreground",Ee.kind==="success"&&"border-success/30 bg-success/10 text-foreground",Ee.kind==="info"&&"border-border bg-background text-foreground"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-semibold",children:Ee.title}),Ee.description&&e.jsx("div",{className:v("mt-0.5",Ee.kind==="error"&&"text-destructive",Ee.kind==="success"&&"text-success",Ee.kind==="info"&&"text-muted-foreground"),children:Ee.description})]}),e.jsx(D,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",onClick:()=>Ds(null),"aria-label":"Dismiss notice",type:"button",children:e.jsx(g.X,{className:"h-4 w-4"})})]})}),I?fr?e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-muted/30 p-6 rounded-bl-lg",children:e.jsx("div",{className:"mx-auto flex min-h-full w-full max-w-4xl items-center",children:e.jsxs("div",{className:"w-full",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Hi there!"}),e.jsx("h1",{className:"mt-2 text-2xl leading-tight font-semibold text-foreground",children:"How can I assist you with your Randmar tasks today?"}),e.jsx("form",{className:"mt-6",onSubmit:$i,children:zi()})]})})}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs(hs,{className:"min-h-0 flex-1 bg-muted/30 pl-2 pr-2",children:[e.jsx(Qn,{messages:Qe?.messages??[],appID:s,isAssistantChat:!0,botStatus:F,hideSenderNames:!0,editableUserMessages:!0,editingMessageId:Be,editingDraft:ea,onEditingDraftChange:Is,onStartEditUserMessage:Wi,onCancelEditUserMessage:na,onSaveEditUserMessage:Ki,onRetryUserMessage:Yi}),e.jsx("div",{ref:Ns})]}),e.jsxs("div",{className:"flex shrink-0 flex-col gap-2 border-r border-t p-4",children:[ds?Ir:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(fs,{ref:ts,placeholder:"Type a message...",value:Z,onPaste:vr,onChange:C=>X(C.target.value),onKeyDown:C=>{C.key!=="Enter"||C.shiftKey||(C.preventDefault(),!(!I||F||ds)&&wr())},className:"flex-1 resize-none field-sizing-content max-h-[30em]"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(D,{size:"icon",variant:"default",className:Qe?.pending?"collapse":"ml-2 h-8 w-8",disabled:!I||!!F||ds,onClick:wr,children:e.jsx(g.Send,{className:"h-6 w-6"})}),e.jsxs(D,{size:"icon",variant:ws?"secondary":"default",onClick:Cr,title:At,"aria-label":At,className:v(Qe?.pending?"collapse":"relative ml-2 h-8 w-8",ws&&"ring-2 ring-ring/25"),disabled:!I||F!==""||Qe?.pending,children:[e.jsx(g.Paperclip,{className:"h-5 w-5"}),ws&&e.jsx("span",{className:"absolute -right-1 -top-1 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1 text-[11px] font-semibold text-primary-foreground shadow-sm",children:Ts})]})]})]}),Pr()]})]}):e.jsx("div",{className:"flex-1 bg-muted/30",children:Ar})]})]}):Ar}),e.jsx("div",{"data-thin":!0,className:"flex h-full basis-[300px] shrink-0 border-l sm:basis-[300px] lg:basis-[300px]",children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col rounded-r-lg border-r bg-muted/30 text-foreground",children:[e.jsxs("div",{className:"space-y-3 border-b border-border/80 p-4 pt-6",children:[e.jsxs("h4",{className:"flex items-center text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:[e.jsx(g.SettingsIcon,{className:"w-4 h-4 mr-2"}),"Settings"]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(J,{htmlFor:"show-dev-logs-checkbox",className:"text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:"Show Dev Logs"}),e.jsx(Ps,{id:"show-dev-logs-checkbox",checked:zs,onCheckedChange:C=>lt(C===!0),"aria-label":"Show developer logs"})]})]}),e.jsxs("div",{className:"flex flex-col border-b border-border/80 h-24",children:[e.jsxs("h4",{className:"flex-shrink-0 flex items-center p-4 pb-2 text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:[e.jsx(g.File,{className:"w-4 h-4 mr-2"}),"Attached Files"]}),e.jsx(hs,{className:"flex-1 px-4",children:e.jsx("div",{className:"py-2 text-sm",children:ee.length>0||he.length>0?e.jsxs("div",{className:"space-y-2",children:[ee.map((C,L)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 text-primary",children:[e.jsxs("div",{className:"flex min-w-0 items-center",children:[e.jsx(g.File,{className:"w-4 h-4 mr-2 flex-shrink-0"}),e.jsxs("span",{title:`${C.name} (pending)`,children:[ua(C.name)," (pending)"]})]}),e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0",onClick:()=>kr(L),"aria-label":`Remove pending file ${C.name}`,children:e.jsx(g.X,{className:"h-4 w-4"})})]},`${C.name}_${C.lastModified}_${C.size}_${L}`)),he.slice().reverse().map((C,L)=>{const $=he.length-1-L;return e.jsxs("div",{className:"flex items-center justify-between gap-2 text-foreground hover:text-primary transition-colors duration-150",children:[e.jsxs("div",{className:"flex min-w-0 items-center",children:[e.jsx(g.File,{className:"w-4 h-4 mr-2 flex-shrink-0"}),e.jsx("span",{title:C.name,children:ua(C.name)})]}),e.jsx(D,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0",onClick:()=>qi(C.name,$),"aria-label":`Remove file ${C.name}`,children:e.jsx(g.X,{className:"h-4 w-4"})})]},C.messageId)})]}):e.jsx("p",{className:"text-muted-foreground text-xs italic",children:"No files attached yet."})})})]}),zs?e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("h4",{className:"flex-shrink-0 flex items-center p-4 pb-2 text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:[e.jsx(g.Code2Icon,{className:"w-4 h-4 mr-2"}),"Developer Log"]}),e.jsx(hs,{className:"flex-1 px-4",children:e.jsxs("div",{className:"py-2 text-xs font-mono",children:[e.jsx(Oc,{debugMessages:B}),e.jsx("div",{ref:Rr})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("h4",{className:"flex-shrink-0 flex items-center p-4 pb-2 text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:[e.jsx(g.MessageSquareShareIcon,{className:"w-4 h-4 mr-2"}),"Contact Us"]}),e.jsx(hs,{className:"flex-1 px-4",children:e.jsxs("div",{className:"py-2 text-sm space-y-4",children:[e.jsxs("div",{className:"rounded-md border border-border bg-background p-3",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Reach out any time"}),e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("a",{className:"block text-base font-semibold text-primary hover:underline",href:"mailto:service@randmar.io",children:"service@randmar.io"}),e.jsx("a",{className:"block text-base font-semibold text-primary hover:underline",href:"tel:+18003616244",children:"1 (800) 361-6244"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Customer reps:"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-md border border-border bg-background p-3",children:[e.jsx("div",{className:"font-medium",children:"Loraine Fraraccio"}),e.jsx("div",{className:"text-muted-foreground",children:e.jsx("a",{className:"text-primary hover:underline",href:"mailto:loraine@randmar.io",children:"loraine@randmar.io"})}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Extension: 314"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Location: Quebec"})]}),e.jsxs("div",{className:"rounded-md border border-border bg-background p-3",children:[e.jsx("div",{className:"font-medium",children:"Kevin Dusik"}),e.jsx("div",{className:"text-muted-foreground",children:e.jsx("a",{className:"text-primary hover:underline",href:"mailto:kevin@randmar.io",children:"kevin@randmar.io"})}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Extension: 150"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Location: British-Colombia"})]})]})]})]})})]}),e.jsx("div",{className:"p-3 border-t border-border/80",children:e.jsxs(D,{className:"w-full",variant:"secondary",onClick:()=>Nr("Send me the Summary of the conversation by email",null,null),type:"button",children:[e.jsx(g.Mail,{className:"h-4 w-4 mr-2"}),"Summarize to Email"]})}),e.jsx("div",{className:"mt-auto p-3 border-t border-border/80",children:e.jsxs("div",{className:"flex items-center justify-center space-x-3 w-full",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Powered by Gemini"}),e.jsx($c,{})]}),e.jsxs("div",{className:"flex-1 max-w-[160px]",children:[e.jsx(nt,{value:Math.round((q||0)*100),className:"h-2"}),e.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground mt-1",children:[e.jsx("span",{children:"Context"}),e.jsxs("span",{children:[Math.round((q||0)*100),"%"]})]})]})]})})]})})]}):e.jsx(g.Loader2,{className:"h-12 w-12 animate-spin mx-auto mb-4"})}));Ht.displayName="AIChatLayout";const $c=({className:s="h-4 w-4"})=>e.jsxs("svg",{viewBox:"0 0 24 24",width:"1em",xmlns:"http://www.w3.org/2000/svg",className:v("flex-none leading-none",s),children:[e.jsx("title",{children:"Gemini"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"var(--info)"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"url(#lobe-icons-gemini-fill-0)"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"url(#lobe-icons-gemini-fill-1)"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"url(#lobe-icons-gemini-fill-2)"}),e.jsxs("defs",{children:[e.jsxs("linearGradient",{gradientUnits:"userSpaceOnUse",id:"lobe-icons-gemini-fill-0",x1:"7",x2:"11",y1:"15.5",y2:"12",children:[e.jsx("stop",{stopColor:"var(--success)"}),e.jsx("stop",{offset:"1",stopColor:"var(--success)",stopOpacity:"0"})]}),e.jsxs("linearGradient",{gradientUnits:"userSpaceOnUse",id:"lobe-icons-gemini-fill-1",x1:"8",x2:"11.5",y1:"5.5",y2:"11",children:[e.jsx("stop",{stopColor:"var(--primary)"}),e.jsx("stop",{offset:"1",stopColor:"var(--primary)",stopOpacity:"0"})]}),e.jsxs("linearGradient",{gradientUnits:"userSpaceOnUse",id:"lobe-icons-gemini-fill-2",x1:"3.5",x2:"17.5",y1:"13.5",y2:"12",children:[e.jsx("stop",{stopColor:"var(--warning)"}),e.jsx("stop",{offset:".46",stopColor:"var(--warning)",stopOpacity:"0"})]})]})]});function _c(s){return s.split(/[?#]/u,1)[0]??""}function $r(s,t){const a=_c(s).split("/").filter(Boolean),r=a.indexOf(t);return r===-1?a:a.slice(r+1)}function Vc(s,t,a){const r=$r(s,a),n=$r(t,a);return n.length===0?r.length===0:r.length<n.length?!1:n.every((i,l)=>r[l]===i)}function zc(s,t){return(s.startsWith("/")?s:`/${s}`).replace(":appID",t)}const ui=o.forwardRef(({routes:s,footer:t,dashboardTitle:a,chatUserName:r,appID:n,chatRoutePath:i},l)=>{const d=s.filter(A=>A.showInNav),u=o.useRef(null),m=o.useRef(null),h=o.useRef(null),[c,y]=o.useState(!1),{isMobile:p,setOpenMobile:x}=tt(),w=ve.useLocation(),{data:N}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationsHasUnreadsQuery({routeApplicationId:n}),{hasUnreads:j}=Js(),b=o.useCallback((A,P=null,E=null,T)=>{y(!0),setTimeout(()=>{u.current?.focus(),m.current&&(T?.clear?m.current.sendMessageToAssistantWithClear(A,P,E):m.current.sendMessageToAssistant(A,P,E))},100)},[]),k=o.useCallback(()=>{x(!1)},[x]);o.useImperativeHandle(l,()=>({sendMessageToAssistant:(A,P,E)=>{b(A,P,E)},sendMessageToAssistantWithClear(A,P,E){b(A,P,E,{clear:!0})}}));const S=d.map(A=>{const P=zc(A.path,n),E=Vc(w.pathname,P,n);return{route:A,linkPath:P,isActive:E}}),M=S.find(A=>A.isActive)?.route.label??"None";return e.jsxs(Fa,{className:"border-r border-sidebar-border",children:[e.jsx($a,{className:"border-b border-sidebar-border px-6 h-16 justify-center bg-sidebar text-sidebar-foreground",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(ci,{path:"/images/RandmarIcon.svg",alt:"Randmar Icon",className:"h-4 w-4 filter brightness-0 saturate-100 invert"})}),e.jsx("span",{className:"font-semibold text-lg",children:a})]})}),e.jsx(Va,{className:"py-4 bg-sidebar text-sidebar-foreground",children:p?e.jsxs("div",{className:"flex flex-1 flex-col px-4 pb-4 pt-2",children:[e.jsxs("div",{className:"px-1",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-sidebar-foreground/70",children:"App Launchpad"}),e.jsxs("p",{className:"mt-1 text-sm text-sidebar-foreground/85",children:["Current: ",e.jsx("span",{className:"font-semibold text-sidebar-foreground",children:M})]})]}),e.jsx("div",{className:"mt-4 grid grid-cols-3 gap-3",children:S.map(({route:A,linkPath:P,isActive:E})=>{const T=A.icon??g.AppWindow;return e.jsxs(ve.Link,{to:P,"aria-current":E?"page":void 0,onClickCapture:k,className:v("flex min-h-24 min-w-0 flex-col items-center justify-center gap-2 rounded-xl border px-2 py-3 text-center text-xs font-medium leading-tight transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-sidebar-ring","border-sidebar-border/70 bg-sidebar-accent/30 text-sidebar-foreground hover:bg-sidebar-accent",E&&"border-sidebar-ring bg-sidebar-accent text-sidebar-accent-foreground"),children:[e.jsx(T,{className:"h-9 w-9 shrink-0"}),e.jsx("span",{className:"line-clamp-2",children:A.label??A.key})]},A.key)})})]}):e.jsx(za,{children:S.map(({route:A,linkPath:P,isActive:E})=>{const T=A.icon;return e.jsx(Ua,{children:e.jsx(qa,{asChild:!0,isActive:E,children:e.jsxs(ve.Link,{to:P,className:"transition-colors hover:bg-muted px-6",children:[T&&e.jsx(T,{className:"h-4 w-4"}),e.jsx("span",{children:A.label})]})})},A.key)})})}),e.jsxs(_a,{className:"border-t border-sidebar-border p-4 bg-sidebar text-sidebar-foreground",children:[e.jsxs(De,{open:c,onOpenChange:y,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ys,{asChild:!0,children:e.jsxs(D,{ref:h,size:"lg",className:"collapse md:visible flex-grow",onClick:()=>setTimeout(()=>u.current?.focus(),50),children:[e.jsx(g.Bot,{}),"Assistant"]})}),e.jsx(ve.Link,{to:i,onClickCapture:k,children:e.jsx(D,{size:"icon",className:j||N?.HasUnreads===!0?"pulse-glow bg-background hover:bg-muted text-foreground":"",children:e.jsx(g.MessageSquare,{className:"h-5 w-5"})})})]}),e.jsx(Me,{className:"randmar-assistant-dialog max-w-[85vw] p-0 data-[state=open]:visible data-[state=closed]:invisible",forceMount:!0,animateExit:!1,overlayClassName:"randmar-assistant-overlay",showOverlay:c,children:e.jsx(Ht,{className:"h-[85vh]",ref:m,inputRef:u,userId:n,userName:r??"Unknown user",isOpen:c,onRequestOpen:()=>{y(!0),setTimeout(()=>u.current?.focus(),50)}})})]}),t]})]})}),mi=o.forwardRef(({children:s,appID:t,rightMenu:a,routes:r,footer:n,handleValidSearch:i,dashboardTitle:l,onSignOut:d,searchPlaceholder:u,chatUserName:m,chatRef:h,chatRoutePath:c},y)=>e.jsx(e.Fragment,{children:e.jsx(La,{children:e.jsxs("div",{className:`flex grow ${ai}`,children:[e.jsx(ui,{appID:t,routes:r,footer:n,dashboardTitle:l,chatUserName:m,ref:h,chatRoutePath:c}),e.jsx(ar,{ref:y,onSignOut:d,rightMenu:a,handleValidSearch:i,searchPlaceholder:u}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("main",{className:`${Sc} @container flex-1 overflow-x-clip bg-muted`,"data-rm-main-content-region":"true",children:s}),e.jsx(Dn,{})]})]})})}));mi.displayName="Layout";const _r=[{id:"online-store",label:"Online store (Shopify, Amazon, etc.)"},{id:"brick-and-mortar",label:"Brick-and-mortar (Physical Store)"},{id:"marketplace",label:"Marketplace seller (eBay, Walmart, etc.)"},{id:"b2b",label:"B2B wholesale"},{id:"other-channel",label:"Other (please specify)"}],Vr=[{id:"canada",label:"Canada - Nationwide"},{id:"ontario",label:"Ontario & Quebec"},{id:"atlantic",label:"Atlantic Provinces (NS, NB, PEI, NL)"},{id:"prairie",label:"Prairie (Saskatchewan, Manitoba)"},{id:"western",label:"Western Provinces (BC, Alberta, etc.)"},{id:"united-states",label:"United States"},{id:"other-market",label:"Other (please specify)"}];function or({applicationId:s,manufacturer:t}){const{toast:a}=Ce(),[r,n]=o.useState(!1),[i,l]=o.useState(!1),[d,u]=o.useState(!1),[m,h]=o.useState(""),[c,y]=o.useState(""),[p,x]=o.useState(!1),[w,N]=o.useState(""),[j,b]=o.useState(""),[k,S]=o.useState([]),[M,A]=o.useState(""),[P,E]=o.useState(""),[T,I]=o.useState([]),[B,F]=o.useState(""),[U,V]=o.useState(""),[O]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),q=()=>{h(""),y("")},W=()=>{N(""),b(""),S([]),A(""),E(""),I([]),F(""),V("")},ne=()=>{t.PartnerRegistrationLink?n(!0):t.OpenToWork&&l(!0)},Pe=Q=>{if(Q.preventDefault(),!d){if(!m.trim()){y("Qualification ID is required");return}u(!0),O({routeApplicationId:s,partnerId:t.ManufacturerId??"",message:`Hello! I'd like to get started with you. Here's my Qualification ID: ${m}`}).then(te=>{if(te.error){console.error(te.error),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"});return}a({title:"Information sent to the manufacturer",description:"Check your chats later.",variant:"success"}),n(!1),q()}).catch(te=>{console.error(te),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"})}).finally(()=>{u(!1)})}},qe=Q=>{if(Q.preventDefault(),p)return;b(""),A(""),F("");let te=!1;if(w.trim().length<10&&(b("Please provide a brief description of your business (minimum 10 characters)"),te=!0),k.length===0&&(A("Please select at least one sales channel"),te=!0),T.length===0&&(F("Please select at least one market"),te=!0),te)return;const oe=_r.filter(xe=>k.includes(xe.id)).map(xe=>xe.label);P&&oe.push(`Other: ${P}`);const Ne=Vr.filter(xe=>T.includes(xe.id)).map(xe=>xe.label);U&&Ne.push(`Other: ${U}`);const Fe=["Hello! I'd like to introduce my business:",`**Business Description:** ${w}`,`**Sales Channels:** ${oe.join(", ")}`,`**Markets:** ${Ne.join(", ")}`].join(`
|
|
70
70
|
|
|
71
|
-
`);b(!0),O({routeApplicationId:s,partnerId:t.ManufacturerId??"",message:Fe}).then(xe=>{if(xe.error){console.error(xe.error),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"});return}a({title:"Information sent to the manufacturer",description:"Check your chats later.",variant:"success"}),l(!1),K()}).catch(xe=>{console.error(xe),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"})}).finally(()=>{b(!1)})},Z=(q,te)=>{S(le=>te?[...le,q]:le.filter(Ne=>Ne!==q)),P("")},X=(q,te)=>{I(le=>te?[...le,q]:le.filter(Ne=>Ne!==q)),$("")},se=k.includes("other-channel"),ue=E.includes("other-market");return e.jsxs(e.Fragment,{children:[!t.Qualification&&e.jsxs(D,{onClick:de,disabled:!t.PartnerRegistrationLink&&!t.OpenToWork,children:[e.jsx(p.Check,{className:"mr-2 h-4 w-4"}),"Get Started"]}),t.PartnerRegistrationLink&&e.jsx(Ie,{open:r,onOpenChange:q=>{n(q)},children:e.jsxs(De,{className:"sm:max-w-[400px]",children:[e.jsxs(Le,{children:[e.jsx($e,{children:t.PublicName}),e.jsxs(_e,{children:[e.jsx("span",{className:"font-bold",children:"Already qualified?"})," Provide your Qualification ID."]})]}),e.jsxs("form",{onSubmit:Me,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"qualificationId",children:"Qualification ID"}),e.jsx(ie,{id:"qualificationId",placeholder:"Enter your qualification ID",value:c,onChange:q=>{u(q.target.value),f("")}}),m&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:m})]}),e.jsx(ze,{children:e.jsx(D,{type:"submit",className:"w-full",disabled:d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Applying..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Check,{className:"mr-2 h-4 w-4"}),"Apply for Qualification"]})})})]}),e.jsx(yt,{className:"my-4"}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Don't have a qualification ID?"}),e.jsx(ve.Link,{to:t.PartnerRegistrationLink,target:"_blank",children:e.jsxs(D,{variant:"outline",className:"w-full",disabled:!t.PartnerRegistrationLink,children:[e.jsx(p.ExternalLink,{className:"mr-2 h-4 w-4"}),"Register here"]})})]})]})}),e.jsx(Ie,{open:i,onOpenChange:q=>{l(q)},children:e.jsxs(De,{className:"sm:max-w-[768px]",children:[e.jsx(Le,{children:e.jsx($e,{children:"Introduce Yourself"})}),e.jsxs("form",{onSubmit:qe,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{htmlFor:"businessDescription",children:["Tell Us About Your Business ",e.jsx("span",{className:"text-sm text-muted-foreground",children:"(Briefly describe your business)"})]}),e.jsx(fs,{id:"businessDescription",placeholder:"We are an online retailer specializing in office supplies, serving businesses since 2018...",className:"min-h-[100px]",value:w,onChange:q=>{N(q.target.value),y("")}}),j&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:j})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:["Sales Channel(s) ",e.jsx("span",{className:"text-sm text-muted-foreground",children:"(Multi-Select where you currently sell your products)"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:_r.map(q=>e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx(Ps,{id:`channel-${q.id}`,checked:k.includes(q.id),onCheckedChange:te=>Z(q.id,te===!0)}),e.jsx(J,{htmlFor:`channel-${q.id}`,className:"text-sm font-normal",children:q.label})]},q.id))}),se&&e.jsx(ie,{placeholder:"Please specify",value:A,onChange:q=>T(q.target.value)}),M&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:M})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:["Your Primary Market(s) ",e.jsx("span",{className:"text-sm text-muted-foreground",children:"(Multi-Select which regions you sell to)"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Vr.map(q=>e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx(Ps,{id:`market-${q.id}`,checked:E.includes(q.id),onCheckedChange:te=>X(q.id,te===!0)}),e.jsx(J,{htmlFor:`market-${q.id}`,className:"text-sm font-normal",children:q.label})]},q.id))}),ue&&e.jsx(ie,{placeholder:"Please specify",value:V,onChange:q=>z(q.target.value)}),F&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:F})]}),e.jsx(ze,{children:e.jsx(D,{type:"submit",disabled:g,children:g?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Submitting..."]}):"Submit"})})]})]})})]})}const ma=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function xi({manufacturer:s,onSave:t,loading:a=!1,saving:r=!1,readonly:n=!1}){const[i,l]=o.useState({...s}),[d,x]=o.useState({...s});o.useEffect(()=>{x({...s}),l({...s})},[s]);const c=(j,y)=>{n||l(k=>({...k,[j]:y}))},u=(j,y)=>{n||l(k=>({...k,[j]:y}))},m=(j,y)=>{n||l(k=>({...k,[j]:y}))},f=()=>{const j={};return Object.keys(i).forEach(y=>{const k=y;JSON.stringify(i[k])!==JSON.stringify(d[k])&&(j[k]=i[k])}),j},g=()=>{if(!r&&!n){const j=f();Object.keys(j).length>0&&t(j)}},b=j=>j===-1?"ASAP":j===void 0||j<0||j>6?"Sunday":ma[j],w=j=>j==="ASAP"?-1:ma.indexOf(j),N=Object.keys(f()).length>0;return e.jsxs(U,{children:[e.jsxs(Y,{children:[a?e.jsx(h,{className:"h-8 w-32"}):e.jsx(me,{className:"text-lg font-bold",children:"Reordering"}),a?e.jsx(h,{className:"h-4 w-full mt-2"}):e.jsx(rt,{className:"text-sm",children:"Adjust your reordering settings to control lead times, stocking weeks, minimum orders, and reorder dates, enhancing efficiency in restocking processes."})]}),e.jsx(G,{className:"space-y-6",children:a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(h,{className:"h-5 w-10"}),e.jsx(h,{className:"h-5 w-40"})]}),e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-5 w-40"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-5 w-40"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(h,{className:"h-10 w-full"}),e.jsx("div",{className:"ml-2 w-12"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-5 w-40"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-5 w-40"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(h,{className:"h-10 w-full"}),e.jsx("div",{className:"ml-2 w-12"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-5 w-40"}),e.jsx(h,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-5 w-40"}),e.jsx(h,{className:"h-10 w-full"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(at,{id:"automatic-reordering",checked:i.AutoUpdate,onCheckedChange:j=>c("AutoUpdate",j),disabled:r||n}),e.jsx(J,{htmlFor:"automatic-reordering",children:"Automatic Reordering"})]}),e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"reorder-date",children:"Automatic Reorder Date"}),e.jsxs(ks,{value:b(i.AutoReorderDate),onValueChange:j=>u("AutoReorderDate",w(j)),disabled:r||n,children:[e.jsx(ps,{id:"reorder-date",children:e.jsx(Rs,{placeholder:"Select day"})}),e.jsxs(gs,{children:[e.jsx(Xe,{value:"ASAP",children:"ASAP"}),ma.map(j=>e.jsx(Xe,{value:j,children:j},j))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"weeks-stocking",children:"Default Weeks of Stocking"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(ie,{id:"weeks-stocking",type:"number",value:i.DefaultWeeksOfStocking||"",onChange:j=>u("DefaultWeeksOfStocking",Number(j.target.value)),disabled:r||n}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"weeks"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"minimum-order",children:"Default Minimum Order"}),e.jsxs("div",{className:"flex items-center relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2",children:"$"}),e.jsx(ie,{id:"minimum-order",type:"number",className:"pl-6",value:i.DefaultMinimumOrder||"",onChange:j=>u("DefaultMinimumOrder",Number(j.target.value)),disabled:r||n})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"lead-time",children:"Default Lead Time"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(ie,{id:"lead-time",type:"number",value:i.DefaultLeadTime||"",onChange:j=>u("DefaultLeadTime",Number(j.target.value)),disabled:r||n}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"days"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"maximum-inventory-value",children:"Default Maximum Inventory Value"}),e.jsxs("div",{className:"flex items-center relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2",children:"$"}),e.jsx(ie,{id:"maximum-inventory-value",type:"number",className:"pl-6",value:i.DefaultMaxInventoryValue||"",onChange:j=>u("DefaultMaxInventoryValue",Number(j.target.value)),disabled:r||n})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"order-confirmations",children:"Send Order Confirmations To"}),e.jsx(ie,{id:"order-confirmations",type:"email",value:i.POEmail||"",onChange:j=>m("POEmail",j.target.value),placeholder:"email@example.com",disabled:r||n})]})]})]})}),!n&&e.jsx(ms,{className:"flex justify-end",children:a?e.jsx(h,{className:"h-10 w-20"}):e.jsxs(D,{onClick:g,disabled:r||!N,children:[r&&e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Save"]})})]})}const wt=Ws.Root,St=Ws.Trigger,Uc=Ws.Anchor,it=R.forwardRef(({className:s,align:t="center",sideOffset:a=4,...r},n)=>e.jsx(Ws.Portal,{children:e.jsx(Ws.Content,{ref:n,align:t,sideOffset:a,className:v("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none 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-popover-content-transform-origin]",s),...r})}));it.displayName=Ws.Content.displayName;function hi({options:s,selected:t,onChange:a,placeholder:r="Select items...",disabled:n=!1}){const[i,l]=R.useState(!1),[d,x]=R.useState(""),c=R.useRef(null),[u,m]=R.useState(void 0),f=R.useCallback(()=>{c.current&&m(c.current.offsetWidth)},[]);R.useLayoutEffect(()=>{f()},[f]),R.useEffect(()=>(window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)),[f]);const g=N=>{a(t.filter(j=>j!==N))},b=N=>{l(!1),t.includes(N)?a(t.filter(j=>j!==N)):a([...t,N])},w=N=>{N.key==="Enter"&&d&&!s.includes(d)&&!t.includes(d)&&(N.preventDefault(),b(d),x(""))};return e.jsxs(wt,{open:i,onOpenChange:l,children:[e.jsx(St,{asChild:!0,children:e.jsxs(D,{ref:c,variant:"outline",role:"combobox","aria-expanded":i,className:"w-full justify-between h-auto min-h-[40px] py-2",disabled:n,children:[e.jsx("div",{className:"flex flex-wrap gap-1 items-center",children:t.length>0?t.map(N=>e.jsxs(fe,{variant:"outline",className:"mr-1 mb-1",children:[N,e.jsx("span",{className:"ml-1 cursor-pointer rounded-full outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",onClick:j=>{j.preventDefault(),j.stopPropagation(),g(N)},children:e.jsx(p.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},N)):e.jsx("span",{className:"text-muted-foreground",children:r})}),e.jsx(p.ChevronsUpDown,{className:"h-4 w-4 shrink-0 opacity-50 ml-2"})]})}),e.jsx(it,{className:"w-full p-0",style:{width:u},children:e.jsxs(Qt,{onKeyDown:w,children:[e.jsx(rr,{placeholder:"Search or add custom item...",value:d,onValueChange:x}),e.jsxs(nr,{children:[e.jsx(ir,{children:"No item found."}),e.jsxs(lr,{children:[s.filter(N=>!t.includes(N)).map(N=>e.jsxs(_t,{onSelect:()=>b(N),children:[e.jsx(p.Check,{className:v("mr-2 h-4 w-4",t.includes(N)?"opacity-100":"opacity-0")}),N]},N)),d&&!s.includes(d)&&!t.includes(d)&&e.jsxs(_t,{onSelect:()=>b(d),children:['Add "',d,'"']})]})]})]})})]})}const qc={sm:100,md:200,lg:300,xl:400};function Qc(s){return s==null?null:Array.isArray(s)?s:s&&typeof s=="object"&&"Images"in s&&Array.isArray(s.Images)?s.Images:[]}function Hc(s){return(s.Description??"").trimStart().startsWith("Shopify Picture")}function Ra(s,t,a){try{const r=new URL(s);return r.searchParams.set("width",String(Math.round(t))),r.searchParams.set("height",String(Math.round(a))),r.toString()}catch{return s}}function zr({apiOrigin:s,randmarSKU:t,image:a,width:r,height:n}){const i=(a.Url??"").trim();if(i){if(i.startsWith("data:"))return i;try{const x=new URL($s(i,s)),c=x.pathname.split("/").filter(Boolean),u=t.trim().toLowerCase(),m=w=>{try{return decodeURIComponent(w).toLowerCase()===u}catch{return w.toLowerCase()===u}},f=c.slice(-3),g=c.slice(-4);return f.length===3&&f[0]?.toLowerCase()==="product"&&m(f[1]??"")&&f[2]?.toLowerCase()==="image"||g.length===4&&g[0]?.toLowerCase()==="product"&&m(g[1]??"")&&g[2]?.toLowerCase()==="image"?Ra(x.toString(),r,n):x.toString()}catch{}}const d=a.ImageId!==void 0&&a.ImageId!==null&&String(a.ImageId).trim()!==""?`/Product/${encodeURIComponent(t)}/Image/${encodeURIComponent(String(a.ImageId))}`:`/Product/${encodeURIComponent(t)}/Image`;return Ra($s(d,s),r,n)}function Gc({apiOrigin:s,randmarSKU:t,width:a,height:r}){return Ra($s(`/Product/${encodeURIComponent(t)}/Image`,s),a,r)}const xa=({size:s,alt:t})=>e.jsx("div",{className:"rounded-md bg-muted flex items-center justify-center",style:{width:s,height:s},"aria-label":t,children:e.jsx(p.ImageOff,{className:"h-1/2 w-1/2 text-muted-foreground"})});function fi({randmarSKU:s,size:t="md",alt:a,className:r,fallback:n}){const i=qc[t],l=R.useRef(null),d=zt({elementRef:l,threshold:.1,rootMargin:"100px"}),x=vt(),{data:c,isError:u,isFetching:m}=_.useGetProductByRandmarSkuImagesQuery({randmarSku:s},{skip:!s||!d,refetchOnMountOrArgChange:!0}),f=R.useMemo(()=>Qc(c),[c]),g=R.useMemo(()=>f?.filter(K=>!Hc(K))??null,[f]),[b,w]=R.useState(0),[N,j]=R.useState(!1),y=R.useRef(!1),k=R.useRef(new Set);R.useEffect(()=>{w(0),j(!1),y.current=!1,k.current.clear()},[s]);const S=R.useMemo(()=>g?[...g].sort((K,de)=>{const Me=K.SortOrder??Number.POSITIVE_INFINITY,qe=de.SortOrder??Number.POSITIVE_INFINITY;if(Me!==qe)return Me-qe;const Z=K.IsPrimary===!0?0:1,X=de.IsPrimary===!0?0:1;return Z-X}):null,[g]),M=f!==null&&f.length>0&&g?.length===0,P=R.useMemo(()=>{if(!S?.length)return 0;const K=S.findIndex(de=>de.IsPrimary===!0);return K>=0?K:0},[S]);R.useEffect(()=>{S?.length&&(y.current||(w(P),y.current=!0))},[P,S]);const A=S?.length??0,T=R.useMemo(()=>{const K=(a??"").trim();return K?`${K} (Product ${s})`:`Product ${s}`},[a,s]),E=R.useCallback(K=>A>1?`${T} image ${K+1}`:T,[T,A]),I=S?.[b],F=R.useMemo(()=>I?zr({apiOrigin:x,randmarSKU:s,image:I,width:i*1.5,height:i*1.5}):null,[I,x,i,s]),$=R.useCallback(K=>{if(A<=0)return;const de=(K%A+A)%A;w(de)},[A]),V=R.useCallback(()=>$(b-1),[b,$]),z=R.useCallback(()=>$(b+1),[b,$]),O=R.useCallback(K=>{if(!(A<=1))switch(K.key){case"ArrowLeft":K.preventDefault(),V();break;case"ArrowRight":K.preventDefault(),z();break;case"Home":K.preventDefault(),$(0);break;case"End":K.preventDefault(),$(A-1);break}},[z,V,$,A]);if(R.useEffect(()=>{if(!S?.length||A<=1)return;const K=(b-1+A)%A,de=(b+1)%A,Me=[K,de];for(const qe of Me){const Z=S[qe];if(!Z)continue;const X=zr({apiOrigin:x,randmarSKU:s,image:Z,width:i*1.5,height:i*1.5});if(k.current.has(X))continue;k.current.add(X);const se=new Image;se.src=X}},[b,x,i,s,A,S]),u)return e.jsx(e.Fragment,{children:n??null});if(g===null&&d&&m)return e.jsx("div",{className:r,ref:l,children:e.jsx(h,{className:"rounded-md",style:{width:i,height:i}})});if(S&&S.length===0){if(M)return e.jsx("div",{className:r,ref:l,children:e.jsx(xa,{size:i,alt:T})});if(n!=null)return e.jsx(e.Fragment,{children:n});const K=Gc({apiOrigin:x,randmarSKU:s,width:i*1.5,height:i*1.5});return e.jsx("div",{className:r,ref:l,children:e.jsx("div",{className:"relative rounded-md overflow-hidden bg-muted",style:{width:i,height:i},"aria-label":T,children:N?e.jsx(xa,{size:i,alt:T}):e.jsx("img",{alt:T,className:"w-full h-full object-contain",src:K,width:i,height:i,loading:"eager",onError:()=>j(!0)})})})}return F?e.jsx("div",{className:r,ref:l,children:e.jsxs("div",{className:"group relative rounded-md overflow-hidden bg-muted",style:{width:i,height:i},role:"region","aria-roledescription":"carousel","aria-label":`Product images for ${s}`,tabIndex:A>1?0:-1,onKeyDown:O,children:[e.jsx("img",{alt:E(b),className:"w-full h-full object-contain",src:F,width:i,height:i,loading:"eager"}),A>1&&e.jsxs(e.Fragment,{children:[e.jsx(D,{type:"button",variant:"secondary",size:"icon",className:"absolute left-2 top-1/2 -translate-y-1/2 bg-background/80 text-foreground shadow-sm ring-1 ring-border/50 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100",onClick:V,"aria-label":"Previous image",children:e.jsx(p.ChevronLeft,{className:"h-4 w-4"})}),e.jsx(D,{type:"button",variant:"secondary",size:"icon",className:"absolute right-2 top-1/2 -translate-y-1/2 bg-background/80 text-foreground shadow-sm ring-1 ring-border/50 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100",onClick:z,"aria-label":"Next image",children:e.jsx(p.ChevronRight,{className:"h-4 w-4"})}),e.jsx("div",{className:"absolute bottom-2 left-1/2 -translate-x-1/2 flex items-center gap-1 rounded-full bg-background/80 px-2 py-1",children:Array.from({length:A}).map((K,de)=>{const Me=de===b;return e.jsx("button",{type:"button",className:["h-1.5 w-1.5 rounded-full transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",Me?"bg-foreground":"bg-muted-foreground/40 hover:bg-muted-foreground/60"].join(" "),onClick:()=>$(de),"aria-label":`Go to image ${de+1} of ${A}`,"aria-current":Me?"true":void 0},de)})})]})]})}):e.jsx("div",{className:r,ref:l,children:e.jsx(xa,{size:i,alt:T})})}function pi({applicationId:s,randmarSku:t,inventory:a,buttonSize:r="default",buttonClassName:n}){const i=o.useRef(null),l=zt({elementRef:i,threshold:.1,rootMargin:"100px",freezeOnceVisible:!0}),{toast:d}=Ce(),[x,c]=o.useState(!1),[u,m]=o.useState(!1),[f,g]=o.useState(!1),{data:b,isLoading:w,isFetching:N}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:s},{skip:!s||!l}),{data:j,isLoading:y,isFetching:k}=_.useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:s,randmarSku:t,withSpecification:!1},{skip:!!a||!l}),[S]=_.usePutV4ResellerByRouteResellerIdProductAndRandmarSkuRequisitionMutation(),M=a??j?.Distribution?.Inventory;o.useEffect(()=>{c(!1)},[t]);const{inventoryQuantity:P,totalIncomingQuantity:A}=o.useMemo(()=>{if(!M||M.length===0)return{inventoryQuantity:0,totalIncomingQuantity:0};const F=M.reduce((V,z)=>V+(z.AvailableQuantity||0),0),$=M.reduce((V,z)=>V+(z.PurchaseOrderQuantity||0),0);return{inventoryQuantity:F,totalIncomingQuantity:$}},[M]);if(w||N||y||k)return e.jsx("div",{ref:i,children:e.jsx(h,{className:v("h-10 w-36 rounded-md",n)})});const E=()=>{f||!b?.IsReseller||(g(!0),S({routeResellerId:s??"",randmarSku:t??""}).then(F=>{F.error||F.data===!1?d({title:"Warning",description:"Reorder is pending or requires manual approval. Contact the Randmar team for details.",variant:"warning"}):d({title:"Success",description:"Qualification successfully submitted.",variant:"success"}),m(!1)}).catch(F=>{console.error(F),d({title:"Error",description:"Error submitting your qualification.",variant:"destructive"})}).finally(()=>{g(!1)}))};if(!M)return e.jsx("div",{ref:i,children:e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx("span",{tabIndex:0,children:e.jsxs(D,{disabled:!0,size:r,variant:"outline",className:v("text-sm",n),children:[e.jsx(p.LucideWarehouse,{size:"16",className:"mr-2"}),"No data"]})})}),e.jsx(pe,{children:e.jsx("p",{children:"No inventory data could be found for this product."})})]})})});if(b?.IsReseller&&P<=0&&A<=0)return e.jsx("div",{ref:i,children:e.jsxs(Ie,{open:u,onOpenChange:m,children:[e.jsx(Ys,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:r,className:v("text-sm text-primary",n),children:[e.jsx(p.LucideWarehouse,{size:"16",className:"mr-2"}),"Request to stock"]})}),e.jsxs(De,{className:"max-w-md",children:[e.jsx(Le,{children:e.jsx($e,{children:"Request to stock"})}),e.jsx("p",{className:"py-4",children:"Are you sure you want to request this product to be stocked?"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(D,{variant:"outline",onClick:()=>m(!1),disabled:f,children:"Cancel"}),e.jsx(D,{onClick:E,disabled:f,children:f?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"h-4 w-4 animate-spin mr-2"}),"Requesting..."]}):"Confirm"})]})]})]})});const I=P<=0&&A>0;return e.jsx("div",{ref:i,children:e.jsxs(Ie,{open:x,onOpenChange:c,children:[e.jsx(Ys,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:r,className:v("text-sm",I?"text-info":P>0?"text-success":"text-destructive",n),children:[e.jsx(p.LucideWarehouse,{size:"16",className:"mr-2"}),I?e.jsxs(e.Fragment,{children:[ls(A)," Incoming"]}):P>0?e.jsxs(e.Fragment,{children:[ls(P)," in stock"]}):e.jsx(e.Fragment,{children:"Out of stock"})]})}),e.jsxs(De,{className:"max-w-4xl",children:[e.jsx(Le,{children:e.jsxs($e,{className:"flex items-center",children:[e.jsx(p.LucideWarehouse,{className:"mr-2",size:18}),"Inventory Information"]})}),e.jsx(Ta,{inventory:M})]})]})})}const gi=()=>new Date().toISOString().split("T")[0],Wc=s=>s.StartDate?s.StartDate.split("T")[0]>gi():!1,Ur=s=>{if(s.Active!==!0)return!1;const t=gi();return!(s.EndDate&&s.EndDate.split("T")[0]<t||s.StartDate&&s.StartDate.split("T")[0]>t)};function Vt({applicationId:s,product:t,viewProductLink:a,defaultOpportunityNumber:r="",onAddToCart:n,addingToCart:i=!1,shopifyHostname:l,customAction:d=e.jsx(e.Fragment,{}),showUsdLabelOnCost:x=!1}){const c=ve.useNavigate(),{toast:u}=Ce(),[m,f]=o.useState(1),[g,b]=o.useState(null),[w,N]=o.useState(0),[j,y]=o.useState(!1),[k]=_.usePostV4ResellerByRouteResellerIdProductAndRandmarSkuShopifyMutation(),[S,M]=o.useState(!1),[P,A]=o.useState(null),[T,E]=o.useState("idle"),[I,F]=o.useState(null),[$]=_.useLazyGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery(),V=t?.Distribution?.Cost||0,z=t?.Distribution?.RegularPrice||0,O=t?.Distribution?.Price||0,H=!!(s&&t?.RandmarSKU);o.useEffect(()=>{f(1),b(null),N(0)},[t?.RandmarSKU]),o.useEffect(()=>{if(t&&r){const W=t.Opportunities?.find(Se=>Se.BidNumber==r);W&&Ur(W)&&b(W)}},[t,r]),o.useEffect(()=>{if(!t)return;const W=g?.Price?g.Price:O;N(z>0?Math.round((z-W)/z*100):0)},[t,g,O,z]),o.useEffect(()=>{i||f(1)},[i]),o.useEffect(()=>{if(!S){A(null),E("idle"),F(null);return}if(!s||!t?.RandmarSKU){E("error"),F("Missing identifiers to load performance data.");return}let W=!1;const Se=t.RandmarSKU;return(async()=>{E("summary"),F(null);try{const Be=await $({routeApplicationId:s,randmarSku:Se,withSpecification:!1});if(W)return;if("error"in Be&&Be.error)throw Be.error;A(Be.data??null),E("detailed");const ss=await $({routeApplicationId:s,randmarSku:Se,withSpecification:!0});if(W)return;if("error"in ss&&ss.error)throw ss.error;A(ss.data??Be.data??null),E("complete")}catch(Be){if(W)return;console.error("Failed to load performance data for product modal",Be),E("error"),F("We couldn't load the performance details. Please try again.")}})(),()=>{W=!0}},[s,$,S,t?.RandmarSKU]);const K=W=>W>=90?{label:"Top 10% Bestseller",color:"text-primary",bgColor:"bg-primary/10"}:W>=75?{label:"Bestseller",color:"text-info",bgColor:"bg-info/10"}:W>=33?{label:"Popular",color:"text-success",bgColor:"bg-success/10"}:{label:"Rising",color:"text-muted-foreground",bgColor:"bg-muted/30"},de=T!=="complete"&&T!=="error",Me=T==="summary"?40:T==="detailed"?80:10,qe=P?.SalesStatistics??[],Z=de?[]:qe,X=P?.RandmarTitle??t?.RandmarTitle??t?.RandmarSKU??"this product",se=P?.RandmarSKU??t?.RandmarSKU,ue=s&&t?.ManufacturerId?`/${encodeURIComponent(s)}/Partner/${encodeURIComponent(t.ManufacturerId)}?tab=manufacturer-overview`:null;if(!t)return e.jsx(U,{className:"flex h-full w-full flex-col",children:e.jsxs(G,{className:"flex h-full flex-col p-6",children:[e.jsxs("div",{className:"flex justify-between items-start mb-3",children:[e.jsx(h,{className:"h-7 w-3/4"}),e.jsx("div",{className:"h-10 w-24 flex items-center justify-end ml-4",children:e.jsx(h,{className:"h-10 w-24 rounded-md"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[e.jsx(h,{className:"h-6 w-20 rounded-full"}),e.jsx(h,{className:"h-6 w-24 rounded-full"}),e.jsx(h,{className:"h-6 w-28 rounded-full"})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-6 flex-1",children:[e.jsxs("div",{children:[e.jsx(h,{className:"h-4 w-12 mb-1"}),e.jsx(h,{className:"h-5 w-20"})]}),e.jsxs("div",{children:[e.jsx(h,{className:"h-4 w-12 mb-1"}),e.jsx(h,{className:"h-5 w-24"})]}),e.jsxs("div",{children:[e.jsx(h,{className:"h-4 w-20 mb-1"}),e.jsx(h,{className:"h-5 w-16"})]}),e.jsxs("div",{children:[e.jsx(h,{className:"h-4 w-12 mb-1"}),e.jsx(h,{className:"h-5 w-20"})]})]}),e.jsx("div",{className:"flex flex-col",children:e.jsx("div",{className:"w-60 h-40",children:e.jsx(h,{className:"w-full h-full rounded-lg"})})})]}),e.jsxs("div",{className:"flex gap-6 mt-4",children:[e.jsx("div",{className:"flex flex-1",children:e.jsxs("div",{className:"w-full",children:[e.jsx(h,{className:"h-4 w-24 mb-3"}),e.jsx(h,{className:"h-16 w-full rounded-md"})]})}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(h,{className:"h-10 w-32 rounded-md"}),e.jsx(h,{className:"h-5 w-24 mt-4"})]})]}),e.jsxs("div",{className:"flex gap-6 mt-4",children:[e.jsxs("div",{className:"flex flex-col items-start gap-1 mb-2",children:[e.jsx(h,{className:"h-8 w-32"}),e.jsx(h,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[e.jsx(h,{className:"h-10 w-24 rounded-md"}),e.jsx(h,{className:"h-10 flex-1 rounded-md"})]})]})]})});const q=t?.Opportunities||[],te=q.length>0,le=()=>{if(m==null){f(1);return}m>1&&f(m-1)},Ne=()=>{if(m==null){f(1);return}f(m+1)},Fe=W=>{const Se=Number.parseInt(W.target.value,10);if(!isNaN(Se)&&Se>0){f(Se);return}f(void 0)},xe=()=>{(m==null||m<1)&&f(1)},Te=W=>{try{return new Date(W).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch(Se){return console.error(Se),W.split("T")[0]||"N/A"}},Pe=W=>{const Se=typeof t?.MSRP=="number"&&t.MSRP>0?t.MSRP:typeof t?.MAP=="number"&&t.MAP>0?t.MAP:null;if(Se===null)return null;const Ve=W.Price??t?.Distribution?.Price;if(typeof Ve!="number")return null;const Be=W.Rebate??0,ss=Math.max(Ve-Be,0);return Se-ss},Ye=()=>{typeof n<"u"&&n({quantity:m??1,bidNumber:g?.BidNumber??null})},Je=()=>{j||!l||(y(!0),k({routeResellerId:s??"",randmarSku:t.RandmarSKU??"",shopifyHostName:l}).then(W=>{if(W.error){console.error("Error syncing to Shopify:",W.error),u({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"});return}u({title:"Product synced",description:"Product synced to Shopify successfully",variant:"success"})}).catch(W=>{console.error("Error syncing to Shopify:",W),u({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"})}).finally(()=>{y(!1)}))};return e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"flex h-full w-full flex-col hover:shadow-lg transition-shadow @container",children:e.jsxs(G,{className:"flex h-full flex-col p-6",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-4",children:[e.jsxs("div",{className:"flex justify-between items-start mb-3",children:[e.jsx("h3",{className:"font-semibold text-xl",children:t.Title||t.RandmarTitle}),e.jsx("div",{className:"w-24 h-10 flex items-center justify-end ml-4 flex-shrink-0",children:ue?e.jsx(ve.Link,{to:ue,"aria-label":`Open manufacturer overview for ${t.ManufacturerName??"this manufacturer"}`,className:"block h-full w-full",children:e.jsx(us,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40,className:"cursor-pointer"},`partner_logo_${t.ManufacturerId}`)}):e.jsx(us,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40},`partner_logo_${t.ManufacturerId}`)})]}),e.jsxs("div",{className:"flex flex-col @[36rem]:flex-row gap-6",children:[e.jsxs("div",{className:"flex-1 @[36rem]:order-1 order-2 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 items-center justify-center @[36rem]:items-start @[36rem]:justify-start",children:[t.State&&e.jsxs(fe,{variant:t.State==="Active"?"success":"destructive",className:"rounded-full px-3",children:[e.jsx(p.CheckIcon,{size:"12",className:"mr-1.5"})," ",t.State]}),e.jsxs(fe,{variant:t.SerialNumber?"success":"warning",className:"rounded-full px-3",children:[e.jsx(p.QrCodeIcon,{size:"12",className:"mr-1.5"})," ",t.SerialNumber?"Serialized":"Unserialized"]}),t.TransparencyCode&&e.jsxs(fe,{variant:"info",className:"rounded-full px-3",children:[e.jsx(p.CircleDashedIcon,{size:"12",className:"mr-1.5"})," Transparency Code"]}),t.AvailableToBuy!==void 0&&e.jsxs(fe,{variant:t.AvailableToBuy?"success":"destructive",className:"rounded-full px-3",children:[e.jsx(p.ShoppingCart,{size:"12",className:"mr-1.5"})," ",t.AvailableToBuy?"Available":"Unavailable"]}),t.ManufacturerCategory!==void 0&&t.ManufacturerCategory?.QualificationRequired&&e.jsxs(fe,{variant:t.ManufacturerCategory?.QualificationRequired?"info":"secondary",className:"rounded-full px-3",children:[e.jsx(p.ShieldCheckIcon,{size:"12",className:"mr-1.5"})," ",t.ManufacturerCategory?.QualificationRequired?"Qualified Only":"Available to all"]}),t.OpportunityOnly&&e.jsxs(fe,{variant:"info",className:"rounded-full px-3",children:[e.jsx(p.ShieldCheckIcon,{size:"12",className:"mr-1.5"})," ","Requires Opportunity"]}),t.ManufacturerId&&e.jsxs(fe,{variant:t.AutoUpdate?"info":"secondary",className:"rounded-full px-3",children:[e.jsx(p.RefreshCwIcon,{size:"12",className:"mr-1.5"})," ",t.AutoUpdate?`Automatic Reorder (${t.MasterCarton})`:"Manually Reorders"]}),e.jsxs(fe,{variant:t.BodyHTML&&t.Title&&t.MAP?"success":"warning",className:"rounded-full px-3",children:[e.jsx(p.StoreIcon,{size:"12",className:"mr-1.5"})," ",t.BodyHTML&&t.Title&&t.MAP?"Shopify Ready":"Not Shopify Ready"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-4 flex-1",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"MPN"}),e.jsx("div",{className:"font-medium",children:t.MPN||"N/A"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"UPC"}),e.jsx("div",{className:"font-medium",children:t.UPC||"N/A"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Unit Weight"}),e.jsx("div",{className:"font-medium",children:t.UnitWeight?`${ls(t.UnitWeight)} lbs`:"N/A"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["MAP",e.jsx("span",{className:"text-primary",children:" / "}),"MSRP"]}),e.jsxs("div",{className:"font-medium",children:[t.MAP?ce(t.MAP):"N/A",e.jsx("span",{className:"text-primary",children:" / "}),t.MSRP?ce(t.MSRP):"N/A"]})]}),!!t.OverallPercentileRank&&!!t.ManufacturerPercentileRank&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"Bestseller Status"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Global: "}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(fe,{variant:"outline",className:`rounded-full px-3 w-fit ${K(t.OverallPercentileRank).bgColor} ${K(t.OverallPercentileRank).color} hover:${K(t.OverallPercentileRank).bgColor}`,children:K(t.OverallPercentileRank).label})}),e.jsx(pe,{children:e.jsxs("p",{children:["Percentile Rank: ",t.OverallPercentileRank]})})]})})]}),e.jsxs("div",{children:[e.jsxs("span",{children:[t.ManufacturerName,": "]}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(fe,{variant:"outline",className:`rounded-full px-3 w-fit ${K(t.ManufacturerPercentileRank).bgColor} ${K(t.ManufacturerPercentileRank).color} hover:${K(t.ManufacturerPercentileRank).bgColor}`,children:K(t.ManufacturerPercentileRank).label})}),e.jsx(pe,{children:e.jsxs("p",{children:["Percentile Rank: ",t.ManufacturerPercentileRank]})})]})})]})]})]}),t.CountryCodeOfOrigin&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Origin"}),e.jsxs("div",{className:"font-medium flex items-center",children:[e.jsx(oi,{countryCode:t.CountryCodeOfOrigin,className:"mr-2"}),t.CountryCodeOfOrigin]})]})]})]}),e.jsx("div",{className:"flex flex-col @[36rem]:order-2 order-1 items-center",children:e.jsx(fi,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||"",fallback:e.jsx(cr,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||"",sceneName:t.SceneName},`product_image_fallback_${t.RandmarSKU}`)},`product_image_${t.RandmarSKU}`)})]}),e.jsx("div",{className:"flex flex-col @[36rem]:flex-row gap-6 mt-4",children:e.jsx("div",{className:"flex flex-1 @[36rem]:order-1 order-2",children:te&&t.Distribution&&e.jsxs("div",{className:"w-full",children:[e.jsx("div",{className:"flex items-center",children:"You have "+q.length+(q.length>1?" opportunities":" opportunity")+" for this product:"}),e.jsx(ye,{children:e.jsx("div",{className:"space-y-2 max-h-[200px] overflow-y-auto p-2 mt-1",children:q.map((W,Se)=>{const Ve=Pe(W);return Ur(W)?e.jsxs("div",{className:`flex justify-between items-center rounded-lg transition-colors py-2 px-4 border cursor-pointer ${W.BidNumber==g?.BidNumber?"bg-primary/10 border-2 border-primary":"bg-background border-border hover:bg-muted/30"}`,onClick:()=>{b(W.BidNumber!==g?.BidNumber?W:null)},children:[e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-sm",children:W.Opportunity}),e.jsx("span",{className:"text-xs text-foreground",children:W.BidNumber})]})}),e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-semibold",children:ce(W.Price??0)}),W.Rebate&&W.Rebate>0&&e.jsxs("span",{className:"text-xs text-success",children:["Rebate: ",ce(W.Rebate)]}),Ve!==null&&e.jsxs("span",{className:"text-xs text-info",children:["Potential Revenue: ",ce(Ve)]}),W.EndDate&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Ends: ",Te(W.EndDate)]})]})]},Se):e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsxs("div",{className:"flex justify-between items-center rounded-lg transition-colors py-2 px-4 bg-muted/30 border border-border cursor-pointer hover:bg-muted/40",onClick:()=>{W.BidNumber&&c(`/${s}/Opportunity/${W.ManufacturerId}/${W.BidNumber}`)},children:[e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-sm",children:W.Opportunity}),e.jsxs("span",{className:"text-xs text-foreground",children:[W.BidNumber," ",e.jsx(fe,{variant:"secondary",className:"text-xs mx-1 h-5",children:Wc(W)&&W.StartDate?`Starts ${Te(W.StartDate)}`:"Currently unavailable"})]})]})}),e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-semibold",children:ce(W.Price??0)}),W.Rebate&&W.Rebate>0&&e.jsxs("span",{className:"text-xs text-success",children:["Rebate: ",ce(W.Rebate)]}),Ve!==null&&e.jsxs("span",{className:"text-xs text-info",children:["Potential Revenue: ",ce(Ve)]}),W.EndDate&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Ends: ",Te(W.EndDate)]})]})]})}),e.jsx(pe,{children:e.jsx("p",{children:"View Opportunity"})})]},Se)})})})]})})})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-row flex-wrap justify-between items-end gap-4",children:[e.jsx("div",{className:"flex flex-col gap-3 flex-1",children:t.Distribution&&e.jsx("div",{className:"flex flex-col gap-1",children:V>0?e.jsx("div",{className:"flex items-center",children:e.jsxs("span",{className:"text-2xl font-bold whitespace-nowrap",children:["Cost: ",ce(V),x?" USD":""]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center flex-wrap",children:[z>0&&e.jsx(e.Fragment,{children:e.jsx("span",{className:"text-2xl font-bold whitespace-nowrap",children:ce((g?t.Opportunities?.find(W=>W.BidNumber==g.BidNumber)?.Price:O)??0)})}),w>0&&e.jsx("span",{className:"text-muted-foreground line-through ml-2 whitespace-nowrap",children:ce(z)})]}),w>0&&e.jsx("div",{className:"flex items-center",children:e.jsxs(fe,{variant:"info",className:"rounded-full px-3 whitespace-nowrap",children:[e.jsxs("span",{children:[w,"% OFF"]}),t.InstantRebate?.EndDate&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1.5",children:"●"})," Ends ",t.InstantRebate.EndDate.split("T")[0]]}),g?.EndDate&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1.5",children:"●"})," Ends ",g.EndDate.split("T")[0]]})]})})]})})}),e.jsxs("div",{className:"flex flex-col justify-center @[36rem]:justify-end items-end gap-2 w-full @[36rem]:w-auto",children:[l&&e.jsx(D,{className:"gap-2 whitespace-nowrap",onClick:Je,disabled:j,children:j?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"h-4 w-4 animate-spin"}),"Syncing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.ShoppingCartIcon,{className:"mr-2"}),"Sync to Shopify"]})}),d,typeof n<"u"&&e.jsxs("div",{className:"flex gap-2 whitespace-nowrap",children:[e.jsxs("div",{className:"flex items-center border rounded-md",children:[e.jsx(D,{variant:"ghost",size:"icon",className:"rounded-r-none",onClick:le,disabled:typeof m<"u"&&(m<=1||!t.AvailableToBuy||i),children:"-"}),e.jsx("input",{value:m,onChange:Fe,onBlur:xe,onClick:W=>W.currentTarget.select(),className:`w-6 @[36rem]:w-12 text-center border-0 bg-transparent text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${!t.AvailableToBuy||i?"text-muted-foreground":""}`,disabled:!t.AvailableToBuy||i}),e.jsx(D,{variant:"ghost",size:"icon",className:"rounded-l-none",onClick:Ne,disabled:!t.AvailableToBuy||i,children:"+"})]}),e.jsx(D,{className:"gap-2 whitespace-nowrap",onClick:Ye,disabled:!t.AvailableToBuy||i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.ShoppingCartIcon,{className:"mr-2"}),"Add to Cart"]})})]})]})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 @[36rem]:flex-row",children:[e.jsx("div",{className:"flex-1 min-w-[10rem]",children:e.jsxs(D,{variant:"outline",type:"button",className:"h-11 px-4 text-sm font-medium justify-start w-full",onClick:()=>M(!0),disabled:!H,children:[e.jsx(p.LineChart,{className:"mr-2"}),"View statistics"]})}),e.jsx("div",{className:"flex-1 min-w-[10rem]",children:e.jsx(pi,{applicationId:s??"",randmarSku:t.RandmarSKU??"",inventory:t.Distribution?.Inventory,buttonSize:"lg",buttonClassName:"w-full h-11 justify-start"})}),a&&e.jsx(ve.Link,{to:a,className:"flex-1 min-w-[10rem]",children:e.jsxs(D,{variant:"outline",className:"h-11 px-4 text-sm font-medium justify-start w-full",children:[e.jsx(p.LucideEye,{className:"mr-2"}),"View Product"]})})]})]})]})}),e.jsx(Ie,{open:S,onOpenChange:M,children:e.jsxs(De,{className:"w-[min(95vw,1100px)] max-w-5xl space-y-6",children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Monthly Sales Performance"}),e.jsxs(_e,{children:["Expanded product insights for ",X,se?` (SKU ${se})`:""]})]}),e.jsx("div",{className:"space-y-6",children:I?e.jsxs(js,{variant:"destructive",children:[e.jsx(bs,{children:"Unable to load details"}),e.jsx(ys,{children:I})]}):e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"mb-4 space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Rolling 12-month sales dollars and units sold pulled from the detailed endpoint."}),de&&e.jsx("div",{"aria-live":"polite","aria-busy":"true",children:e.jsx(nt,{value:Me,className:"h-2 w-full animate-pulse","aria-label":"Loading performance data"})})]}),e.jsx(Vs,{statistics:Z,mode:"month",chartHeight:320}),de&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Gathering product summary and sales statistics..."})]})})]})})]})}const Kc={sm:100,md:200,lg:300,xl:400},Yc=({size:s})=>e.jsx("div",{className:"rounded-md bg-muted flex items-center justify-center",style:{width:s,height:s},"aria-label":"Image not available",children:e.jsx(p.ImageOff,{className:"h-1/2 w-1/2 text-muted-foreground"})}),Jc=()=>e.jsx(h,{className:"w-full",style:{aspectRatio:"16/9"}});function cr({randmarSKU:s,sceneName:t,size:a="md",alt:r,secondaryContent:n}){const[i,l]=R.useState(!1),[d,x]=R.useState(!1),{sendMessageWithClear:c}=Js(),u=vt(),m=Kc[a],f=o.useRef(null),g=zt({elementRef:f,threshold:.1,rootMargin:"100px"}),{data:b,isFetching:w}=_.useGetProductByProductNumberImageExistsQuery({productNumber:s},{skip:!s||!g}),{data:N,isFetching:j}=_.useGetProductByRandmarSkuImageQuery({randmarSku:s,width:m*1.5,height:m*1.5},{skip:!b}),{data:y}=_.useGetProductByProductNumberVideoExistsQuery({productNumber:s},{skip:!s||!g}),{data:k,isFetching:S}=_.useGetProductByProductNumberVideoQuery({productNumber:s},{skip:!y||!i}),M=w||j;function P(){if(k)try{const I=document.createElement("a");I.href=k,I.download=`${s||"product"}-video.mp4`,I.target="_blank",I.rel="noopener noreferrer",document.body.appendChild(I),I.click(),document.body.removeChild(I)}catch(I){console.error("Error downloading video:",I)}}function A(){const I=`/Product/${encodeURIComponent(s)}/Video`;navigator.clipboard.writeText($s(I,u)),x(!0),setTimeout(()=>x(!1),2e3)}function T(){y&&l(!0)}const E=R.useCallback(()=>{if(!N)return;const I=(t??"").trim(),F=I?`Use this concept as a background/stage scene: "${I}".`:"Use a modern and clean office as the background/stage, with no people present.";c(`Help me generate product images for (Randmar SKU: ${s}).
|
|
71
|
+
`);x(!0),O({routeApplicationId:s,partnerId:t.ManufacturerId??"",message:Fe}).then(xe=>{if(xe.error){console.error(xe.error),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"});return}a({title:"Information sent to the manufacturer",description:"Check your chats later.",variant:"success"}),l(!1),W()}).catch(xe=>{console.error(xe),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"})}).finally(()=>{x(!1)})},Z=(Q,te)=>{S(oe=>te?[...oe,Q]:oe.filter(Ne=>Ne!==Q)),A("")},X=(Q,te)=>{I(oe=>te?[...oe,Q]:oe.filter(Ne=>Ne!==Q)),F("")},se=k.includes("other-channel"),ue=T.includes("other-market");return e.jsxs(e.Fragment,{children:[!t.Qualification&&e.jsxs(D,{onClick:ne,disabled:!t.PartnerRegistrationLink&&!t.OpenToWork,children:[e.jsx(g.Check,{className:"mr-2 h-4 w-4"}),"Get Started"]}),t.PartnerRegistrationLink&&e.jsx(De,{open:r,onOpenChange:Q=>{n(Q)},children:e.jsxs(Me,{className:"sm:max-w-[400px]",children:[e.jsxs(Le,{children:[e.jsx($e,{children:t.PublicName}),e.jsxs(_e,{children:[e.jsx("span",{className:"font-bold",children:"Already qualified?"})," Provide your Qualification ID."]})]}),e.jsxs("form",{onSubmit:Pe,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"qualificationId",children:"Qualification ID"}),e.jsx(le,{id:"qualificationId",placeholder:"Enter your qualification ID",value:m,onChange:Q=>{h(Q.target.value),y("")}}),c&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:c})]}),e.jsx(ze,{children:e.jsx(D,{type:"submit",className:"w-full",disabled:d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Applying..."]}):e.jsxs(e.Fragment,{children:[e.jsx(g.Check,{className:"mr-2 h-4 w-4"}),"Apply for Qualification"]})})})]}),e.jsx(yt,{className:"my-4"}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Don't have a qualification ID?"}),e.jsx(ve.Link,{to:t.PartnerRegistrationLink,target:"_blank",children:e.jsxs(D,{variant:"outline",className:"w-full",disabled:!t.PartnerRegistrationLink,children:[e.jsx(g.ExternalLink,{className:"mr-2 h-4 w-4"}),"Register here"]})})]})]})}),e.jsx(De,{open:i,onOpenChange:Q=>{l(Q)},children:e.jsxs(Me,{className:"sm:max-w-[768px]",children:[e.jsx(Le,{children:e.jsx($e,{children:"Introduce Yourself"})}),e.jsxs("form",{onSubmit:qe,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{htmlFor:"businessDescription",children:["Tell Us About Your Business ",e.jsx("span",{className:"text-sm text-muted-foreground",children:"(Briefly describe your business)"})]}),e.jsx(fs,{id:"businessDescription",placeholder:"We are an online retailer specializing in office supplies, serving businesses since 2018...",className:"min-h-[100px]",value:w,onChange:Q=>{N(Q.target.value),b("")}}),j&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:j})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:["Sales Channel(s) ",e.jsx("span",{className:"text-sm text-muted-foreground",children:"(Multi-Select where you currently sell your products)"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:_r.map(Q=>e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx(Ps,{id:`channel-${Q.id}`,checked:k.includes(Q.id),onCheckedChange:te=>Z(Q.id,te===!0)}),e.jsx(J,{htmlFor:`channel-${Q.id}`,className:"text-sm font-normal",children:Q.label})]},Q.id))}),se&&e.jsx(le,{placeholder:"Please specify",value:P,onChange:Q=>E(Q.target.value)}),M&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:M})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:["Your Primary Market(s) ",e.jsx("span",{className:"text-sm text-muted-foreground",children:"(Multi-Select which regions you sell to)"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Vr.map(Q=>e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx(Ps,{id:`market-${Q.id}`,checked:T.includes(Q.id),onCheckedChange:te=>X(Q.id,te===!0)}),e.jsx(J,{htmlFor:`market-${Q.id}`,className:"text-sm font-normal",children:Q.label})]},Q.id))}),ue&&e.jsx(le,{placeholder:"Please specify",value:U,onChange:Q=>V(Q.target.value)}),B&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:B})]}),e.jsx(ze,{children:e.jsx(D,{type:"submit",disabled:p,children:p?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Submitting..."]}):"Submit"})})]})]})})]})}const ma=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function xi({manufacturer:s,onSave:t,loading:a=!1,saving:r=!1,readonly:n=!1}){const[i,l]=o.useState({...s}),[d,u]=o.useState({...s});o.useEffect(()=>{u({...s}),l({...s})},[s]);const m=(j,b)=>{n||l(k=>({...k,[j]:b}))},h=(j,b)=>{n||l(k=>({...k,[j]:b}))},c=(j,b)=>{n||l(k=>({...k,[j]:b}))},y=()=>{const j={};return Object.keys(i).forEach(b=>{const k=b;JSON.stringify(i[k])!==JSON.stringify(d[k])&&(j[k]=i[k])}),j},p=()=>{if(!r&&!n){const j=y();Object.keys(j).length>0&&t(j)}},x=j=>j===-1?"ASAP":j===void 0||j<0||j>6?"Sunday":ma[j],w=j=>j==="ASAP"?-1:ma.indexOf(j),N=Object.keys(y()).length>0;return e.jsxs(z,{children:[e.jsxs(Y,{children:[a?e.jsx(f,{className:"h-8 w-32"}):e.jsx(me,{className:"text-lg font-bold",children:"Reordering"}),a?e.jsx(f,{className:"h-4 w-full mt-2"}):e.jsx(rt,{className:"text-sm",children:"Adjust your reordering settings to control lead times, stocking weeks, minimum orders, and reorder dates, enhancing efficiency in restocking processes."})]}),e.jsx(G,{className:"space-y-6",children:a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{className:"h-5 w-10"}),e.jsx(f,{className:"h-5 w-40"})]}),e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-5 w-40"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-5 w-40"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(f,{className:"h-10 w-full"}),e.jsx("div",{className:"ml-2 w-12"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-5 w-40"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-5 w-40"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(f,{className:"h-10 w-full"}),e.jsx("div",{className:"ml-2 w-12"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-5 w-40"}),e.jsx(f,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"h-5 w-40"}),e.jsx(f,{className:"h-10 w-full"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(at,{id:"automatic-reordering",checked:i.AutoUpdate,onCheckedChange:j=>m("AutoUpdate",j),disabled:r||n}),e.jsx(J,{htmlFor:"automatic-reordering",children:"Automatic Reordering"})]}),e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"reorder-date",children:"Automatic Reorder Date"}),e.jsxs(ks,{value:x(i.AutoReorderDate),onValueChange:j=>h("AutoReorderDate",w(j)),disabled:r||n,children:[e.jsx(ps,{id:"reorder-date",children:e.jsx(Rs,{placeholder:"Select day"})}),e.jsxs(gs,{children:[e.jsx(Xe,{value:"ASAP",children:"ASAP"}),ma.map(j=>e.jsx(Xe,{value:j,children:j},j))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"weeks-stocking",children:"Default Weeks of Stocking"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(le,{id:"weeks-stocking",type:"number",value:i.DefaultWeeksOfStocking||"",onChange:j=>h("DefaultWeeksOfStocking",Number(j.target.value)),disabled:r||n}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"weeks"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"minimum-order",children:"Default Minimum Order"}),e.jsxs("div",{className:"flex items-center relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2",children:"$"}),e.jsx(le,{id:"minimum-order",type:"number",className:"pl-6",value:i.DefaultMinimumOrder||"",onChange:j=>h("DefaultMinimumOrder",Number(j.target.value)),disabled:r||n})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"lead-time",children:"Default Lead Time"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(le,{id:"lead-time",type:"number",value:i.DefaultLeadTime||"",onChange:j=>h("DefaultLeadTime",Number(j.target.value)),disabled:r||n}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"days"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"maximum-inventory-value",children:"Default Maximum Inventory Value"}),e.jsxs("div",{className:"flex items-center relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2",children:"$"}),e.jsx(le,{id:"maximum-inventory-value",type:"number",className:"pl-6",value:i.DefaultMaxInventoryValue||"",onChange:j=>h("DefaultMaxInventoryValue",Number(j.target.value)),disabled:r||n})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"order-confirmations",children:"Send Order Confirmations To"}),e.jsx(le,{id:"order-confirmations",type:"email",value:i.POEmail||"",onChange:j=>c("POEmail",j.target.value),placeholder:"email@example.com",disabled:r||n})]})]})]})}),!n&&e.jsx(ms,{className:"flex justify-end",children:a?e.jsx(f,{className:"h-10 w-20"}):e.jsxs(D,{onClick:p,disabled:r||!N,children:[r&&e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Save"]})})]})}const wt=Ws.Root,St=Ws.Trigger,Uc=Ws.Anchor,it=R.forwardRef(({className:s,align:t="center",sideOffset:a=4,...r},n)=>e.jsx(Ws.Portal,{children:e.jsx(Ws.Content,{ref:n,align:t,sideOffset:a,className:v("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none 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-popover-content-transform-origin]",s),...r})}));it.displayName=Ws.Content.displayName;function hi({options:s,selected:t,onChange:a,placeholder:r="Select items...",disabled:n=!1}){const[i,l]=R.useState(!1),[d,u]=R.useState(""),m=R.useRef(null),[h,c]=R.useState(void 0),y=R.useCallback(()=>{m.current&&c(m.current.offsetWidth)},[]);R.useLayoutEffect(()=>{y()},[y]),R.useEffect(()=>(window.addEventListener("resize",y),()=>window.removeEventListener("resize",y)),[y]);const p=N=>{a(t.filter(j=>j!==N))},x=N=>{l(!1),t.includes(N)?a(t.filter(j=>j!==N)):a([...t,N])},w=N=>{N.key==="Enter"&&d&&!s.includes(d)&&!t.includes(d)&&(N.preventDefault(),x(d),u(""))};return e.jsxs(wt,{open:i,onOpenChange:l,children:[e.jsx(St,{asChild:!0,children:e.jsxs(D,{ref:m,variant:"outline",role:"combobox","aria-expanded":i,className:"w-full justify-between h-auto min-h-[40px] py-2",disabled:n,children:[e.jsx("div",{className:"flex flex-wrap gap-1 items-center",children:t.length>0?t.map(N=>e.jsxs(fe,{variant:"outline",className:"mr-1 mb-1",children:[N,e.jsx("span",{className:"ml-1 cursor-pointer rounded-full outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",onClick:j=>{j.preventDefault(),j.stopPropagation(),p(N)},children:e.jsx(g.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},N)):e.jsx("span",{className:"text-muted-foreground",children:r})}),e.jsx(g.ChevronsUpDown,{className:"h-4 w-4 shrink-0 opacity-50 ml-2"})]})}),e.jsx(it,{className:"w-full p-0",style:{width:h},children:e.jsxs(Qt,{onKeyDown:w,children:[e.jsx(rr,{placeholder:"Search or add custom item...",value:d,onValueChange:u}),e.jsxs(nr,{children:[e.jsx(ir,{children:"No item found."}),e.jsxs(lr,{children:[s.filter(N=>!t.includes(N)).map(N=>e.jsxs(_t,{onSelect:()=>x(N),children:[e.jsx(g.Check,{className:v("mr-2 h-4 w-4",t.includes(N)?"opacity-100":"opacity-0")}),N]},N)),d&&!s.includes(d)&&!t.includes(d)&&e.jsxs(_t,{onSelect:()=>x(d),children:['Add "',d,'"']})]})]})]})})]})}const qc={sm:100,md:200,lg:300,xl:400};function Qc(s){return s==null?null:Array.isArray(s)?s:s&&typeof s=="object"&&"Images"in s&&Array.isArray(s.Images)?s.Images:[]}function Hc(s){return(s.Description??"").trimStart().startsWith("Shopify Picture")}function Ra(s,t,a){try{const r=new URL(s);return r.searchParams.set("width",String(Math.round(t))),r.searchParams.set("height",String(Math.round(a))),r.toString()}catch{return s}}function zr({apiOrigin:s,randmarSKU:t,image:a,width:r,height:n}){const i=(a.Url??"").trim();if(i){if(i.startsWith("data:"))return i;try{const u=new URL($s(i,s)),m=u.pathname.split("/").filter(Boolean),h=t.trim().toLowerCase(),c=w=>{try{return decodeURIComponent(w).toLowerCase()===h}catch{return w.toLowerCase()===h}},y=m.slice(-3),p=m.slice(-4);return y.length===3&&y[0]?.toLowerCase()==="product"&&c(y[1]??"")&&y[2]?.toLowerCase()==="image"||p.length===4&&p[0]?.toLowerCase()==="product"&&c(p[1]??"")&&p[2]?.toLowerCase()==="image"?Ra(u.toString(),r,n):u.toString()}catch{}}const d=a.ImageId!==void 0&&a.ImageId!==null&&String(a.ImageId).trim()!==""?`/Product/${encodeURIComponent(t)}/Image/${encodeURIComponent(String(a.ImageId))}`:`/Product/${encodeURIComponent(t)}/Image`;return Ra($s(d,s),r,n)}function Gc({apiOrigin:s,randmarSKU:t,width:a,height:r}){return Ra($s(`/Product/${encodeURIComponent(t)}/Image`,s),a,r)}const xa=({size:s,alt:t})=>e.jsx("div",{className:"rounded-md bg-muted flex items-center justify-center",style:{width:s,height:s},"aria-label":t,children:e.jsx(g.ImageOff,{className:"h-1/2 w-1/2 text-muted-foreground"})});function fi({randmarSKU:s,size:t="md",alt:a,className:r,fallback:n}){const i=qc[t],l=R.useRef(null),d=zt({elementRef:l,threshold:.1,rootMargin:"100px"}),u=vt(),{data:m,isError:h,isFetching:c}=_.useGetProductByRandmarSkuImagesQuery({randmarSku:s},{skip:!s||!d,refetchOnMountOrArgChange:!0}),y=R.useMemo(()=>Qc(m),[m]),p=R.useMemo(()=>y?.filter(W=>!Hc(W))??null,[y]),[x,w]=R.useState(0),[N,j]=R.useState(!1),b=R.useRef(!1),k=R.useRef(new Set);R.useEffect(()=>{w(0),j(!1),b.current=!1,k.current.clear()},[s]);const S=R.useMemo(()=>p?[...p].sort((W,ne)=>{const Pe=W.SortOrder??Number.POSITIVE_INFINITY,qe=ne.SortOrder??Number.POSITIVE_INFINITY;if(Pe!==qe)return Pe-qe;const Z=W.IsPrimary===!0?0:1,X=ne.IsPrimary===!0?0:1;return Z-X}):null,[p]),M=y!==null&&y.length>0&&p?.length===0,A=R.useMemo(()=>{if(!S?.length)return 0;const W=S.findIndex(ne=>ne.IsPrimary===!0);return W>=0?W:0},[S]);R.useEffect(()=>{S?.length&&(b.current||(w(A),b.current=!0))},[A,S]);const P=S?.length??0,E=R.useMemo(()=>{const W=(a??"").trim();return W?`${W} (Product ${s})`:`Product ${s}`},[a,s]),T=R.useCallback(W=>P>1?`${E} image ${W+1}`:E,[E,P]),I=S?.[x],B=R.useMemo(()=>I?zr({apiOrigin:u,randmarSKU:s,image:I,width:i*1.5,height:i*1.5}):null,[I,u,i,s]),F=R.useCallback(W=>{if(P<=0)return;const ne=(W%P+P)%P;w(ne)},[P]),U=R.useCallback(()=>F(x-1),[x,F]),V=R.useCallback(()=>F(x+1),[x,F]),O=R.useCallback(W=>{if(!(P<=1))switch(W.key){case"ArrowLeft":W.preventDefault(),U();break;case"ArrowRight":W.preventDefault(),V();break;case"Home":W.preventDefault(),F(0);break;case"End":W.preventDefault(),F(P-1);break}},[V,U,F,P]);if(R.useEffect(()=>{if(!S?.length||P<=1)return;const W=(x-1+P)%P,ne=(x+1)%P,Pe=[W,ne];for(const qe of Pe){const Z=S[qe];if(!Z)continue;const X=zr({apiOrigin:u,randmarSKU:s,image:Z,width:i*1.5,height:i*1.5});if(k.current.has(X))continue;k.current.add(X);const se=new Image;se.src=X}},[x,u,i,s,P,S]),h)return e.jsx(e.Fragment,{children:n??null});if(p===null&&d&&c)return e.jsx("div",{className:r,ref:l,children:e.jsx(f,{className:"rounded-md",style:{width:i,height:i}})});if(S&&S.length===0){if(M)return e.jsx("div",{className:r,ref:l,children:e.jsx(xa,{size:i,alt:E})});if(n!=null)return e.jsx(e.Fragment,{children:n});const W=Gc({apiOrigin:u,randmarSKU:s,width:i*1.5,height:i*1.5});return e.jsx("div",{className:r,ref:l,children:e.jsx("div",{className:"relative rounded-md overflow-hidden bg-muted",style:{width:i,height:i},"aria-label":E,children:N?e.jsx(xa,{size:i,alt:E}):e.jsx("img",{alt:E,className:"w-full h-full object-contain",src:W,width:i,height:i,loading:"eager",onError:()=>j(!0)})})})}return B?e.jsx("div",{className:r,ref:l,children:e.jsxs("div",{className:"group relative rounded-md overflow-hidden bg-muted",style:{width:i,height:i},role:"region","aria-roledescription":"carousel","aria-label":`Product images for ${s}`,tabIndex:P>1?0:-1,onKeyDown:O,children:[e.jsx("img",{alt:T(x),className:"w-full h-full object-contain",src:B,width:i,height:i,loading:"eager"}),P>1&&e.jsxs(e.Fragment,{children:[e.jsx(D,{type:"button",variant:"secondary",size:"icon",className:"absolute left-2 top-1/2 -translate-y-1/2 bg-background/80 text-foreground shadow-sm ring-1 ring-border/50 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100",onClick:U,"aria-label":"Previous image",children:e.jsx(g.ChevronLeft,{className:"h-4 w-4"})}),e.jsx(D,{type:"button",variant:"secondary",size:"icon",className:"absolute right-2 top-1/2 -translate-y-1/2 bg-background/80 text-foreground shadow-sm ring-1 ring-border/50 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 focus-visible:opacity-100",onClick:V,"aria-label":"Next image",children:e.jsx(g.ChevronRight,{className:"h-4 w-4"})}),e.jsx("div",{className:"absolute bottom-2 left-1/2 -translate-x-1/2 flex items-center gap-1 rounded-full bg-background/80 px-2 py-1",children:Array.from({length:P}).map((W,ne)=>{const Pe=ne===x;return e.jsx("button",{type:"button",className:["h-1.5 w-1.5 rounded-full transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",Pe?"bg-foreground":"bg-muted-foreground/40 hover:bg-muted-foreground/60"].join(" "),onClick:()=>F(ne),"aria-label":`Go to image ${ne+1} of ${P}`,"aria-current":Pe?"true":void 0},ne)})})]})]})}):e.jsx("div",{className:r,ref:l,children:e.jsx(xa,{size:i,alt:E})})}function pi({applicationId:s,randmarSku:t,inventory:a,buttonSize:r="default",buttonClassName:n}){const i=o.useRef(null),l=zt({elementRef:i,threshold:.1,rootMargin:"100px",freezeOnceVisible:!0}),{toast:d}=Ce(),[u,m]=o.useState(!1),[h,c]=o.useState(!1),[y,p]=o.useState(!1),{data:x,isLoading:w,isFetching:N}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:s},{skip:!s||!l}),{data:j,isLoading:b,isFetching:k}=_.useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:s,randmarSku:t,withSpecification:!1},{skip:!!a||!l}),[S]=_.usePutV4ResellerByRouteResellerIdProductAndRandmarSkuRequisitionMutation(),M=a??j?.Distribution?.Inventory;o.useEffect(()=>{m(!1)},[t]);const{inventoryQuantity:A,totalIncomingQuantity:P}=o.useMemo(()=>{if(!M||M.length===0)return{inventoryQuantity:0,totalIncomingQuantity:0};const B=M.reduce((U,V)=>U+(V.AvailableQuantity||0),0),F=M.reduce((U,V)=>U+(V.PurchaseOrderQuantity||0),0);return{inventoryQuantity:B,totalIncomingQuantity:F}},[M]);if(w||N||b||k)return e.jsx("div",{ref:i,children:e.jsx(f,{className:v("h-10 w-36 rounded-md",n)})});const T=()=>{y||!x?.IsReseller||(p(!0),S({routeResellerId:s??"",randmarSku:t??""}).then(B=>{B.error||B.data===!1?d({title:"Warning",description:"Reorder is pending or requires manual approval. Contact the Randmar team for details.",variant:"warning"}):d({title:"Success",description:"Qualification successfully submitted.",variant:"success"}),c(!1)}).catch(B=>{console.error(B),d({title:"Error",description:"Error submitting your qualification.",variant:"destructive"})}).finally(()=>{p(!1)}))};if(!M)return e.jsx("div",{ref:i,children:e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx("span",{tabIndex:0,children:e.jsxs(D,{disabled:!0,size:r,variant:"outline",className:v("text-sm",n),children:[e.jsx(g.LucideWarehouse,{size:"16",className:"mr-2"}),"No data"]})})}),e.jsx(pe,{children:e.jsx("p",{children:"No inventory data could be found for this product."})})]})})});if(x?.IsReseller&&A<=0&&P<=0)return e.jsx("div",{ref:i,children:e.jsxs(De,{open:h,onOpenChange:c,children:[e.jsx(Ys,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:r,className:v("text-sm text-primary",n),children:[e.jsx(g.LucideWarehouse,{size:"16",className:"mr-2"}),"Request to stock"]})}),e.jsxs(Me,{className:"max-w-md",children:[e.jsx(Le,{children:e.jsx($e,{children:"Request to stock"})}),e.jsx("p",{className:"py-4",children:"Are you sure you want to request this product to be stocked?"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(D,{variant:"outline",onClick:()=>c(!1),disabled:y,children:"Cancel"}),e.jsx(D,{onClick:T,disabled:y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin mr-2"}),"Requesting..."]}):"Confirm"})]})]})]})});const I=A<=0&&P>0;return e.jsx("div",{ref:i,children:e.jsxs(De,{open:u,onOpenChange:m,children:[e.jsx(Ys,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:r,className:v("text-sm",I?"text-info":A>0?"text-success":"text-destructive",n),children:[e.jsx(g.LucideWarehouse,{size:"16",className:"mr-2"}),I?e.jsxs(e.Fragment,{children:[ls(P)," Incoming"]}):A>0?e.jsxs(e.Fragment,{children:[ls(A)," in stock"]}):e.jsx(e.Fragment,{children:"Out of stock"})]})}),e.jsxs(Me,{className:"max-w-4xl",children:[e.jsx(Le,{children:e.jsxs($e,{className:"flex items-center",children:[e.jsx(g.LucideWarehouse,{className:"mr-2",size:18}),"Inventory Information"]})}),e.jsx(Ta,{inventory:M})]})]})})}const gi=()=>new Date().toISOString().split("T")[0],Wc=s=>s.StartDate?s.StartDate.split("T")[0]>gi():!1,Ur=s=>{if(s.Active!==!0)return!1;const t=gi();return!(s.EndDate&&s.EndDate.split("T")[0]<t||s.StartDate&&s.StartDate.split("T")[0]>t)};function Vt({applicationId:s,product:t,viewProductLink:a,defaultOpportunityNumber:r="",onAddToCart:n,addingToCart:i=!1,shopifyHostname:l,customAction:d=e.jsx(e.Fragment,{}),showUsdLabelOnCost:u=!1}){const m=ve.useNavigate(),{toast:h}=Ce(),[c,y]=o.useState(1),[p,x]=o.useState(null),[w,N]=o.useState(0),[j,b]=o.useState(!1),[k]=_.usePostV4ResellerByRouteResellerIdProductAndRandmarSkuShopifyMutation(),[S,M]=o.useState(!1),[A,P]=o.useState(null),[E,T]=o.useState("idle"),[I,B]=o.useState(null),[F]=_.useLazyGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery(),U=t?.Distribution?.Cost||0,V=t?.Distribution?.RegularPrice||0,O=t?.Distribution?.Price||0,q=!!(s&&t?.RandmarSKU);o.useEffect(()=>{y(1),x(null),N(0)},[t?.RandmarSKU]),o.useEffect(()=>{if(t&&r){const K=t.Opportunities?.find(Se=>Se.BidNumber==r);K&&Ur(K)&&x(K)}},[t,r]),o.useEffect(()=>{if(!t)return;const K=p?.Price?p.Price:O;N(V>0?Math.round((V-K)/V*100):0)},[t,p,O,V]),o.useEffect(()=>{i||y(1)},[i]),o.useEffect(()=>{if(!S){P(null),T("idle"),B(null);return}if(!s||!t?.RandmarSKU){T("error"),B("Missing identifiers to load performance data.");return}let K=!1;const Se=t.RandmarSKU;return(async()=>{T("summary"),B(null);try{const Be=await F({routeApplicationId:s,randmarSku:Se,withSpecification:!1});if(K)return;if("error"in Be&&Be.error)throw Be.error;P(Be.data??null),T("detailed");const ss=await F({routeApplicationId:s,randmarSku:Se,withSpecification:!0});if(K)return;if("error"in ss&&ss.error)throw ss.error;P(ss.data??Be.data??null),T("complete")}catch(Be){if(K)return;console.error("Failed to load performance data for product modal",Be),T("error"),B("We couldn't load the performance details. Please try again.")}})(),()=>{K=!0}},[s,F,S,t?.RandmarSKU]);const W=K=>K>=90?{label:"Top 10% Bestseller",color:"text-primary",bgColor:"bg-primary/10"}:K>=75?{label:"Bestseller",color:"text-info",bgColor:"bg-info/10"}:K>=33?{label:"Popular",color:"text-success",bgColor:"bg-success/10"}:{label:"Rising",color:"text-muted-foreground",bgColor:"bg-muted/30"},ne=E!=="complete"&&E!=="error",Pe=E==="summary"?40:E==="detailed"?80:10,qe=A?.SalesStatistics??[],Z=ne?[]:qe,X=A?.RandmarTitle??t?.RandmarTitle??t?.RandmarSKU??"this product",se=A?.RandmarSKU??t?.RandmarSKU,ue=s&&t?.ManufacturerId?`/${encodeURIComponent(s)}/Partner/${encodeURIComponent(t.ManufacturerId)}?tab=manufacturer-overview`:null;if(!t)return e.jsx(z,{className:"flex h-full w-full flex-col",children:e.jsxs(G,{className:"flex h-full flex-col p-6",children:[e.jsxs("div",{className:"flex justify-between items-start mb-3",children:[e.jsx(f,{className:"h-7 w-3/4"}),e.jsx("div",{className:"h-10 w-24 flex items-center justify-end ml-4",children:e.jsx(f,{className:"h-10 w-24 rounded-md"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[e.jsx(f,{className:"h-6 w-20 rounded-full"}),e.jsx(f,{className:"h-6 w-24 rounded-full"}),e.jsx(f,{className:"h-6 w-28 rounded-full"})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-6 flex-1",children:[e.jsxs("div",{children:[e.jsx(f,{className:"h-4 w-12 mb-1"}),e.jsx(f,{className:"h-5 w-20"})]}),e.jsxs("div",{children:[e.jsx(f,{className:"h-4 w-12 mb-1"}),e.jsx(f,{className:"h-5 w-24"})]}),e.jsxs("div",{children:[e.jsx(f,{className:"h-4 w-20 mb-1"}),e.jsx(f,{className:"h-5 w-16"})]}),e.jsxs("div",{children:[e.jsx(f,{className:"h-4 w-12 mb-1"}),e.jsx(f,{className:"h-5 w-20"})]})]}),e.jsx("div",{className:"flex flex-col",children:e.jsx("div",{className:"w-60 h-40",children:e.jsx(f,{className:"w-full h-full rounded-lg"})})})]}),e.jsxs("div",{className:"flex gap-6 mt-4",children:[e.jsx("div",{className:"flex flex-1",children:e.jsxs("div",{className:"w-full",children:[e.jsx(f,{className:"h-4 w-24 mb-3"}),e.jsx(f,{className:"h-16 w-full rounded-md"})]})}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(f,{className:"h-10 w-32 rounded-md"}),e.jsx(f,{className:"h-5 w-24 mt-4"})]})]}),e.jsxs("div",{className:"flex gap-6 mt-4",children:[e.jsxs("div",{className:"flex flex-col items-start gap-1 mb-2",children:[e.jsx(f,{className:"h-8 w-32"}),e.jsx(f,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[e.jsx(f,{className:"h-10 w-24 rounded-md"}),e.jsx(f,{className:"h-10 flex-1 rounded-md"})]})]})]})});const Q=t?.Opportunities||[],te=Q.length>0,oe=()=>{if(c==null){y(1);return}c>1&&y(c-1)},Ne=()=>{if(c==null){y(1);return}y(c+1)},Fe=K=>{const Se=Number.parseInt(K.target.value,10);if(!isNaN(Se)&&Se>0){y(Se);return}y(void 0)},xe=()=>{(c==null||c<1)&&y(1)},Te=K=>{try{return new Date(K).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch(Se){return console.error(Se),K.split("T")[0]||"N/A"}},Ae=K=>{const Se=typeof t?.MSRP=="number"&&t.MSRP>0?t.MSRP:typeof t?.MAP=="number"&&t.MAP>0?t.MAP:null;if(Se===null)return null;const Ve=K.Price??t?.Distribution?.Price;if(typeof Ve!="number")return null;const Be=K.Rebate??0,ss=Math.max(Ve-Be,0);return Se-ss},Ye=()=>{typeof n<"u"&&n({quantity:c??1,bidNumber:p?.BidNumber??null})},Je=()=>{j||!l||(b(!0),k({routeResellerId:s??"",randmarSku:t.RandmarSKU??"",shopifyHostName:l}).then(K=>{if(K.error){console.error("Error syncing to Shopify:",K.error),h({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"});return}h({title:"Product synced",description:"Product synced to Shopify successfully",variant:"success"})}).catch(K=>{console.error("Error syncing to Shopify:",K),h({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"})}).finally(()=>{b(!1)}))};return e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"flex h-full w-full flex-col hover:shadow-lg transition-shadow @container",children:e.jsxs(G,{className:"flex h-full flex-col p-6",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-4",children:[e.jsxs("div",{className:"flex justify-between items-start mb-3",children:[e.jsx("h3",{className:"font-semibold text-xl",children:t.Title||t.RandmarTitle}),e.jsx("div",{className:"w-24 h-10 flex items-center justify-end ml-4 flex-shrink-0",children:ue?e.jsx(ve.Link,{to:ue,"aria-label":`Open manufacturer overview for ${t.ManufacturerName??"this manufacturer"}`,className:"block h-full w-full",children:e.jsx(us,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40,className:"cursor-pointer"},`partner_logo_${t.ManufacturerId}`)}):e.jsx(us,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40},`partner_logo_${t.ManufacturerId}`)})]}),e.jsxs("div",{className:"flex flex-col @[36rem]:flex-row gap-6",children:[e.jsxs("div",{className:"flex-1 @[36rem]:order-1 order-2 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 items-center justify-center @[36rem]:items-start @[36rem]:justify-start",children:[t.State&&e.jsxs(fe,{variant:t.State==="Active"?"success":"destructive",className:"rounded-full px-3",children:[e.jsx(g.CheckIcon,{size:"12",className:"mr-1.5"})," ",t.State]}),e.jsxs(fe,{variant:t.SerialNumber?"success":"warning",className:"rounded-full px-3",children:[e.jsx(g.QrCodeIcon,{size:"12",className:"mr-1.5"})," ",t.SerialNumber?"Serialized":"Unserialized"]}),t.TransparencyCode&&e.jsxs(fe,{variant:"info",className:"rounded-full px-3",children:[e.jsx(g.CircleDashedIcon,{size:"12",className:"mr-1.5"})," Transparency Code"]}),t.AvailableToBuy!==void 0&&e.jsxs(fe,{variant:t.AvailableToBuy?"success":"destructive",className:"rounded-full px-3",children:[e.jsx(g.ShoppingCart,{size:"12",className:"mr-1.5"})," ",t.AvailableToBuy?"Available":"Unavailable"]}),t.ManufacturerCategory!==void 0&&t.ManufacturerCategory?.QualificationRequired&&e.jsxs(fe,{variant:t.ManufacturerCategory?.QualificationRequired?"info":"secondary",className:"rounded-full px-3",children:[e.jsx(g.ShieldCheckIcon,{size:"12",className:"mr-1.5"})," ",t.ManufacturerCategory?.QualificationRequired?"Qualified Only":"Available to all"]}),t.OpportunityOnly&&e.jsxs(fe,{variant:"info",className:"rounded-full px-3",children:[e.jsx(g.ShieldCheckIcon,{size:"12",className:"mr-1.5"})," ","Requires Opportunity"]}),t.ManufacturerId&&e.jsxs(fe,{variant:t.AutoUpdate?"info":"secondary",className:"rounded-full px-3",children:[e.jsx(g.RefreshCwIcon,{size:"12",className:"mr-1.5"})," ",t.AutoUpdate?`Automatic Reorder (${t.MasterCarton})`:"Manually Reorders"]}),e.jsxs(fe,{variant:t.BodyHTML&&t.Title&&t.MAP?"success":"warning",className:"rounded-full px-3",children:[e.jsx(g.StoreIcon,{size:"12",className:"mr-1.5"})," ",t.BodyHTML&&t.Title&&t.MAP?"Shopify Ready":"Not Shopify Ready"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-4 flex-1",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"MPN"}),e.jsx("div",{className:"font-medium",children:t.MPN||"N/A"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"UPC"}),e.jsx("div",{className:"font-medium",children:t.UPC||"N/A"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Unit Weight"}),e.jsx("div",{className:"font-medium",children:t.UnitWeight?`${ls(t.UnitWeight)} lbs`:"N/A"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["MAP",e.jsx("span",{className:"text-primary",children:" / "}),"MSRP"]}),e.jsxs("div",{className:"font-medium",children:[t.MAP?de(t.MAP):"N/A",e.jsx("span",{className:"text-primary",children:" / "}),t.MSRP?de(t.MSRP):"N/A"]})]}),!!t.OverallPercentileRank&&!!t.ManufacturerPercentileRank&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"Bestseller Status"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Global: "}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(fe,{variant:"outline",className:`rounded-full px-3 w-fit ${W(t.OverallPercentileRank).bgColor} ${W(t.OverallPercentileRank).color} hover:${W(t.OverallPercentileRank).bgColor}`,children:W(t.OverallPercentileRank).label})}),e.jsx(pe,{children:e.jsxs("p",{children:["Percentile Rank: ",t.OverallPercentileRank]})})]})})]}),e.jsxs("div",{children:[e.jsxs("span",{children:[t.ManufacturerName,": "]}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(fe,{variant:"outline",className:`rounded-full px-3 w-fit ${W(t.ManufacturerPercentileRank).bgColor} ${W(t.ManufacturerPercentileRank).color} hover:${W(t.ManufacturerPercentileRank).bgColor}`,children:W(t.ManufacturerPercentileRank).label})}),e.jsx(pe,{children:e.jsxs("p",{children:["Percentile Rank: ",t.ManufacturerPercentileRank]})})]})})]})]})]}),t.CountryCodeOfOrigin&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Origin"}),e.jsxs("div",{className:"font-medium flex items-center",children:[e.jsx(oi,{countryCode:t.CountryCodeOfOrigin,className:"mr-2"}),t.CountryCodeOfOrigin]})]})]})]}),e.jsx("div",{className:"flex flex-col @[36rem]:order-2 order-1 items-center",children:e.jsx(fi,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||"",fallback:e.jsx(cr,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||"",sceneName:t.SceneName},`product_image_fallback_${t.RandmarSKU}`)},`product_image_${t.RandmarSKU}`)})]}),e.jsx("div",{className:"flex flex-col @[36rem]:flex-row gap-6 mt-4",children:e.jsx("div",{className:"flex flex-1 @[36rem]:order-1 order-2",children:te&&t.Distribution&&e.jsxs("div",{className:"w-full",children:[e.jsx("div",{className:"flex items-center",children:"You have "+Q.length+(Q.length>1?" opportunities":" opportunity")+" for this product:"}),e.jsx(ye,{children:e.jsx("div",{className:"space-y-2 max-h-[200px] overflow-y-auto p-2 mt-1",children:Q.map((K,Se)=>{const Ve=Ae(K);return Ur(K)?e.jsxs("div",{className:`flex justify-between items-center rounded-lg transition-colors py-2 px-4 border cursor-pointer ${K.BidNumber==p?.BidNumber?"bg-primary/10 border-2 border-primary":"bg-background border-border hover:bg-muted/30"}`,onClick:()=>{x(K.BidNumber!==p?.BidNumber?K:null)},children:[e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-sm",children:K.Opportunity}),e.jsx("span",{className:"text-xs text-foreground",children:K.BidNumber})]})}),e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-semibold",children:de(K.Price??0)}),K.Rebate&&K.Rebate>0&&e.jsxs("span",{className:"text-xs text-success",children:["Rebate: ",de(K.Rebate)]}),Ve!==null&&e.jsxs("span",{className:"text-xs text-info",children:["Potential Revenue: ",de(Ve)]}),K.EndDate&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Ends: ",Te(K.EndDate)]})]})]},Se):e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsxs("div",{className:"flex justify-between items-center rounded-lg transition-colors py-2 px-4 bg-muted/30 border border-border cursor-pointer hover:bg-muted/40",onClick:()=>{K.BidNumber&&m(`/${s}/Opportunity/${K.ManufacturerId}/${K.BidNumber}`)},children:[e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-sm",children:K.Opportunity}),e.jsxs("span",{className:"text-xs text-foreground",children:[K.BidNumber," ",e.jsx(fe,{variant:"secondary",className:"text-xs mx-1 h-5",children:Wc(K)&&K.StartDate?`Starts ${Te(K.StartDate)}`:"Currently unavailable"})]})]})}),e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-semibold",children:de(K.Price??0)}),K.Rebate&&K.Rebate>0&&e.jsxs("span",{className:"text-xs text-success",children:["Rebate: ",de(K.Rebate)]}),Ve!==null&&e.jsxs("span",{className:"text-xs text-info",children:["Potential Revenue: ",de(Ve)]}),K.EndDate&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Ends: ",Te(K.EndDate)]})]})]})}),e.jsx(pe,{children:e.jsx("p",{children:"View Opportunity"})})]},Se)})})})]})})})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-row flex-wrap justify-between items-end gap-4",children:[e.jsx("div",{className:"flex flex-col gap-3 flex-1",children:t.Distribution&&e.jsx("div",{className:"flex flex-col gap-1",children:U>0?e.jsx("div",{className:"flex items-center",children:e.jsxs("span",{className:"text-2xl font-bold whitespace-nowrap",children:["Cost: ",de(U),u?" USD":""]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center flex-wrap",children:[V>0&&e.jsx(e.Fragment,{children:e.jsx("span",{className:"text-2xl font-bold whitespace-nowrap",children:de((p?t.Opportunities?.find(K=>K.BidNumber==p.BidNumber)?.Price:O)??0)})}),w>0&&e.jsx("span",{className:"text-muted-foreground line-through ml-2 whitespace-nowrap",children:de(V)})]}),w>0&&e.jsx("div",{className:"flex items-center",children:e.jsxs(fe,{variant:"info",className:"rounded-full px-3 whitespace-nowrap",children:[e.jsxs("span",{children:[w,"% OFF"]}),t.InstantRebate?.EndDate&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1.5",children:"●"})," Ends ",t.InstantRebate.EndDate.split("T")[0]]}),p?.EndDate&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1.5",children:"●"})," Ends ",p.EndDate.split("T")[0]]})]})})]})})}),e.jsxs("div",{className:"flex flex-col justify-center @[36rem]:justify-end items-end gap-2 w-full @[36rem]:w-auto",children:[l&&e.jsx(D,{className:"gap-2 whitespace-nowrap",onClick:Je,disabled:j,children:j?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}),"Syncing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(g.ShoppingCartIcon,{className:"mr-2"}),"Sync to Shopify"]})}),d,typeof n<"u"&&e.jsxs("div",{className:"flex gap-2 whitespace-nowrap",children:[e.jsxs("div",{className:"flex items-center border rounded-md",children:[e.jsx(D,{variant:"ghost",size:"icon",className:"rounded-r-none",onClick:oe,disabled:typeof c<"u"&&(c<=1||!t.AvailableToBuy||i),children:"-"}),e.jsx("input",{value:c,onChange:Fe,onBlur:xe,onClick:K=>K.currentTarget.select(),className:`w-6 @[36rem]:w-12 text-center border-0 bg-transparent text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${!t.AvailableToBuy||i?"text-muted-foreground":""}`,disabled:!t.AvailableToBuy||i}),e.jsx(D,{variant:"ghost",size:"icon",className:"rounded-l-none",onClick:Ne,disabled:!t.AvailableToBuy||i,children:"+"})]}),e.jsx(D,{className:"gap-2 whitespace-nowrap",onClick:Ye,disabled:!t.AvailableToBuy||i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(g.ShoppingCartIcon,{className:"mr-2"}),"Add to Cart"]})})]})]})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 @[36rem]:flex-row",children:[e.jsx("div",{className:"flex-1 min-w-[10rem]",children:e.jsxs(D,{variant:"outline",type:"button",className:"h-11 px-4 text-sm font-medium justify-start w-full",onClick:()=>M(!0),disabled:!q,children:[e.jsx(g.LineChart,{className:"mr-2"}),"View statistics"]})}),e.jsx("div",{className:"flex-1 min-w-[10rem]",children:e.jsx(pi,{applicationId:s??"",randmarSku:t.RandmarSKU??"",inventory:t.Distribution?.Inventory,buttonSize:"lg",buttonClassName:"w-full h-11 justify-start"})}),a&&e.jsx(ve.Link,{to:a,className:"flex-1 min-w-[10rem]",children:e.jsxs(D,{variant:"outline",className:"h-11 px-4 text-sm font-medium justify-start w-full",children:[e.jsx(g.LucideEye,{className:"mr-2"}),"View Product"]})})]})]})]})}),e.jsx(De,{open:S,onOpenChange:M,children:e.jsxs(Me,{className:"w-[min(95vw,1100px)] max-w-5xl space-y-6",children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Monthly Sales Performance"}),e.jsxs(_e,{children:["Expanded product insights for ",X,se?` (SKU ${se})`:""]})]}),e.jsx("div",{className:"space-y-6",children:I?e.jsxs(js,{variant:"destructive",children:[e.jsx(bs,{children:"Unable to load details"}),e.jsx(ys,{children:I})]}):e.jsxs("div",{className:"rounded-xl border bg-background p-4",children:[e.jsxs("div",{className:"mb-4 space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Rolling 12-month sales dollars and units sold pulled from the detailed endpoint."}),ne&&e.jsx("div",{"aria-live":"polite","aria-busy":"true",children:e.jsx(nt,{value:Pe,className:"h-2 w-full animate-pulse","aria-label":"Loading performance data"})})]}),e.jsx(Vs,{statistics:Z,mode:"month",chartHeight:320}),ne&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Gathering product summary and sales statistics..."})]})})]})})]})}const Kc={sm:100,md:200,lg:300,xl:400},Yc=({size:s})=>e.jsx("div",{className:"rounded-md bg-muted flex items-center justify-center",style:{width:s,height:s},"aria-label":"Image not available",children:e.jsx(g.ImageOff,{className:"h-1/2 w-1/2 text-muted-foreground"})}),Jc=()=>e.jsx(f,{className:"w-full",style:{aspectRatio:"16/9"}});function cr({randmarSKU:s,sceneName:t,size:a="md",alt:r,secondaryContent:n}){const[i,l]=R.useState(!1),[d,u]=R.useState(!1),{sendMessageWithClear:m}=Js(),h=vt(),c=Kc[a],y=o.useRef(null),p=zt({elementRef:y,threshold:.1,rootMargin:"100px"}),{data:x,isFetching:w}=_.useGetProductByProductNumberImageExistsQuery({productNumber:s},{skip:!s||!p}),{data:N,isFetching:j}=_.useGetProductByRandmarSkuImageQuery({randmarSku:s,width:c*1.5,height:c*1.5},{skip:!x}),{data:b}=_.useGetProductByProductNumberVideoExistsQuery({productNumber:s},{skip:!s||!p}),{data:k,isFetching:S}=_.useGetProductByProductNumberVideoQuery({productNumber:s},{skip:!b||!i}),M=w||j;function A(){if(k)try{const I=document.createElement("a");I.href=k,I.download=`${s||"product"}-video.mp4`,I.target="_blank",I.rel="noopener noreferrer",document.body.appendChild(I),I.click(),document.body.removeChild(I)}catch(I){console.error("Error downloading video:",I)}}function P(){const I=`/Product/${encodeURIComponent(s)}/Video`;navigator.clipboard.writeText($s(I,h)),u(!0),setTimeout(()=>u(!1),2e3)}function E(){b&&l(!0)}const T=R.useCallback(()=>{if(!N)return;const I=(t??"").trim(),B=I?`Use this concept as a background/stage scene: "${I}".`:"Use a modern and clean office as the background/stage, with no people present.";m(`Help me generate product images for (Randmar SKU: ${s}).
|
|
72
72
|
|
|
73
|
-
${
|
|
73
|
+
${B}
|
|
74
74
|
|
|
75
|
-
Repeat and ask me what to change or improve until we are done creating pictures.`)},[N,s,t,c]);return e.jsxs(e.Fragment,{children:[e.jsx(Ie,{open:i,onOpenChange:l,children:e.jsx(De,{className:"max-w-4xl p-0 overflow-hidden",children:S||!k?e.jsx(Jc,{}):e.jsx(e.Fragment,{children:n?e.jsxs("div",{className:"flex flex-row",children:[e.jsxs("video",{className:"w-full rounded-l-lg max-h-[720px] object-contain",controls:!0,autoPlay:!0,muted:!0,loop:!0,children:[e.jsx("source",{src:k,type:"video/mp4"}),"Your browser does not support the video tag."]}),e.jsx("div",{className:"flex-grow min-w-[400px] h-[70vh] p-6",children:n})]}):e.jsxs("div",{className:"w-full relative",children:[e.jsxs("video",{className:"w-full max-h-[720px] object-contain",controls:!0,autoPlay:!0,children:[e.jsx("source",{src:k,type:"video/mp4"}),"Your browser does not support the video tag."]}),e.jsxs("div",{className:"absolute top-2 right-12 flex gap-1",children:[e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"secondary",size:"icon",onClick:A,"aria-label":"Copy video link",children:d?e.jsx(p.Check,{className:"h-4 w-4"}):e.jsx(p.Copy,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Copy video link"})})]})}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"secondary",size:"icon",onClick:P,"aria-label":"Download video",children:e.jsx(p.Download,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Download video"})})]})})]})]})})})}),e.jsxs("div",{className:"relative w-max h-max",ref:f,children:[M?e.jsx(h,{className:"rounded-md",style:{width:m,height:m}}):N?e.jsx("img",{alt:r||`Product ${s}`,className:`rounded-md ${y?"cursor-pointer":""}`,onClick:T,src:N,width:m,height:m}):e.jsx(Yc,{size:m}),e.jsxs("div",{className:"absolute top-2 right-2 flex flex-col gap-1",children:[y==!0&&e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"secondary",size:"icon",onClick:T,"aria-label":"Play product video",children:e.jsx(p.Play,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Play video"})})]})}),N?e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"secondary",size:"icon",onClick:E,"aria-label":"Ask AI to generate product images",children:e.jsx(p.Bot,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Ask AI to generate product images"})})]})}):null]})]})]})}function Zc({reseller:s,actions:t,loading:a=!1}){return a||!s?e.jsx(Xc,{}):e.jsx(ed,{reseller:s,actions:t})}function Xc(){return e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(me,{children:e.jsx(h,{className:"h-6 w-40"})})}),e.jsxs(G,{children:[e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsx("div",{className:"space-y-4",children:Array(3).fill(0).map((s,t)=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx(h,{className:"h-5 w-24"}),e.jsx(h,{className:"h-9 w-9 rounded-full"})]}),e.jsxs("div",{children:[e.jsx(h,{className:"h-4 w-20 mb-1"}),e.jsx(h,{className:"h-7 w-28"})]})]},t))}),e.jsx("div",{className:"space-y-4",children:Array(2).fill(0).map((s,t)=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx(h,{className:"h-5 w-24"}),e.jsx(h,{className:"h-9 w-9 rounded-full"})]}),e.jsxs("div",{children:[e.jsx(h,{className:"h-4 w-20 mb-1"}),e.jsx(h,{className:"h-7 w-28"})]})]},t))})]}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(h,{className:"h-10 w-28 rounded-md"})})]})]})}function ed({reseller:s,actions:t}){const a=s.Statement||{},r=[{title:"0 - 30 Days",amount:a.Over0||0,icon:e.jsx(p.Calendar,{className:"h-5 w-5 text-primary-foreground"}),color:"bg-primary"},{title:"31 - 45 Days",amount:a.Over30||0,icon:e.jsx(p.Calendar,{className:"h-5 w-5 text-primary-foreground"}),color:"bg-primary"},{title:"45+ Days",amount:a.Over45||0,icon:e.jsx(p.Calendar,{className:"h-5 w-5 text-primary-foreground"}),color:"bg-primary"}],n=[{title:"Total",amount:a.Total||0,icon:e.jsx(p.DollarSign,{className:"h-5 w-5 text-success-foreground"}),color:"bg-success"},{title:"Credit Limit",amount:s.CreditLimit||0,icon:e.jsx(p.CreditCard,{className:"h-5 w-5 text-info-foreground"}),color:"bg-info"}];return e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(me,{children:"Billing Overview"})}),e.jsxs(G,{children:[e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsx("div",{className:"space-y-4",children:r.map((i,l)=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-sm sm:text-base font-medium",children:i.title}),e.jsx("div",{className:`p-2 rounded-full ${i.color}`,children:i.icon})]}),e.jsx("div",{children:e.jsx("p",{className:"text-base sm:text-lg font-bold",children:ce(i.amount)})})]},l))}),e.jsx("div",{className:"space-y-4",children:n.map((i,l)=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-sm sm:text-base font-medium",children:i.title}),e.jsx("div",{className:`p-2 rounded-full ${i.color}`,children:i.icon})]}),e.jsx("div",{children:e.jsx("p",{className:"text-base sm:text-lg font-bold",children:ce(i.amount)})})]},l))})]}),t&&e.jsx("div",{className:"flex justify-end mt-4",children:t})]})]})}function ji({qualifications:s=[],loading:t=!1}){return t?e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(me,{children:"Qualifications"})}),e.jsx(G,{className:"p-6",children:e.jsx("div",{className:"grid grid-cols-2 @sm:grid-cols-3 @md:grid-cols-4 @lg:grid-cols-5 gap-4 gap-y-8",children:Array.from({length:10}).map((a,r)=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(h,{className:"h-12 w-24 rounded-md mb-2"}),e.jsx(h,{className:"h-5 w-16 rounded-full"})]},r))})})]}):e.jsxs(U,{children:[e.jsx(Y,{children:e.jsx(me,{children:"Qualifications"})}),e.jsx(G,{children:s&&s.length>0?e.jsx("div",{className:"p-6",children:e.jsx("div",{className:"flex grid grid-cols-2 @sm:grid-cols-3 @md:grid-cols-4 @lg:grid-cols-5 gap-4 gap-y-8",children:s.map((a,r)=>e.jsx(sd,{manufacturerId:a.ManufacturerId,opportunityNumber:a.DefaultOpportunityNumber},`${a.ManufacturerId}-${r}`))})}):e.jsx("p",{children:"No qualification available."})})]})}function sd({manufacturerId:s,opportunityNumber:t}){return e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"h-12 w-full items-center justify-center mb-2",children:e.jsx(us,{id:s,width:96,height:48})}),t&&e.jsx(fe,{variant:"outline",className:"text-xs",children:t})]})}function td({salesData:s,salesStatistics:t=[],loading:a=!1}){return a||!s?e.jsx(ad,{}):e.jsx(rd,{salesData:s,salesStatistics:t})}function ad(){return e.jsxs(U,{children:[e.jsx(Y,{className:"pb-0",children:e.jsx(me,{className:"text-lg @sm:text-xl",children:e.jsx(h,{className:"h-7 w-40"})})}),e.jsxs(G,{className:"pt-4 px-3 @sm:px-6",children:[e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 @lg:grid-cols-3 gap-4",children:Array(3).fill(0).map((s,t)=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx(h,{className:"h-5 w-24"}),e.jsx(h,{className:"h-9 w-9 rounded-full"})]}),e.jsxs("div",{children:[e.jsx(h,{className:"h-4 w-20 mb-1"}),e.jsx(h,{className:"h-7 w-28"})]})]},t))}),e.jsx("div",{className:"mt-6",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(h,{className:"h-5 w-32"}),e.jsx(h,{className:"h-[250px] w-full rounded-lg"})]})})]})]})}function rd({salesData:s,salesStatistics:t=[]}){const a=[{title:"Last 30 days",amount:s.SalesLast30Days||0,icon:e.jsx(p.Calendar,{className:"h-5 w-5 text-info-foreground"}),color:"bg-info"},{title:"Last 3 months",amount:s.SalesLast3Months||0,icon:e.jsx(p.Calendar,{className:"h-5 w-5 text-warning-foreground"}),color:"bg-warning"},{title:"Year to date",amount:s.SalesYearToDay||0,icon:e.jsx(p.Calendar,{className:"h-5 w-5 text-success-foreground"}),color:"bg-success"}];return e.jsxs(U,{children:[e.jsx(Y,{className:"pb-0",children:e.jsx(me,{className:"text-lg @sm:text-xl",children:"Sales Overview"})}),e.jsxs(G,{className:"pt-4 px-3 @sm:px-6",children:[e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 @lg:grid-cols-3 gap-4",children:a.map((r,n)=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:"text-sm @sm:text-base font-medium",children:r.title}),e.jsx("div",{className:`p-2 rounded-full ${r.color}`,children:r.icon})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),e.jsx("p",{className:"text-base @sm:text-lg font-bold",children:ce(r.amount)})]})]},n))}),e.jsx("div",{className:"mt-6",children:t&&t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"text-sm font-medium mb-4",children:"Sales Trend"}),e.jsx("div",{className:"space-y-6",children:e.jsx(Vs,{statistics:t,chartHeight:300,mode:"week"})})]})})]})]})}function nd({icon:s,contentType:t,identifier:a,description:r,fields:n,actions:i,highlightedHeader:l=!1,className:d,...x}){const c=R.Children.toArray(i).filter(Boolean);return e.jsxs(U,{className:v("flex flex-col h-full overflow-hidden",d),...x,children:[e.jsx("header",{className:v("space-y-3 p-6",l&&"rounded-t-md bg-primary text-primary-foreground"),children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(s,{"aria-hidden":"true",className:v("mt-0.5 h-5 w-5 shrink-0",l?"text-primary-foreground":"text-primary")}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("h3",{className:v("text-base font-medium",l?"text-primary-foreground":"text-foreground"),children:t}),e.jsx("span",{className:v("font-mono text-sm",l?"text-primary-foreground":"text-foreground"),children:a})]}),e.jsx("p",{className:v("mt-1 text-sm",l?"text-primary-foreground":"text-muted-foreground"),children:r})]})]})}),e.jsx("section",{className:"flex-1 bg-card p-6",children:e.jsx("dl",{className:"grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-2 lg:grid-cols-3",children:n.map((u,m)=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("dt",{className:"text-xs font-semibold text-muted-foreground",children:u.label}),e.jsx("dd",{className:"text-sm text-foreground",children:u.value??"-"})]},`${u.label}-${m}`))})}),c.length>0&&e.jsx("footer",{className:"border-t border-border p-6 pt-4",children:e.jsx("div",{className:"flex justify-end gap-3",children:c.map((u,m)=>e.jsx("div",{className:"flex items-center justify-center [&>*]:min-h-11 [&>*]:min-w-11",children:u},m))})})]})}const dr=Ke.Root,ur=Ke.Trigger,id=Ke.Portal,bi=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Overlay,{className:v("fixed inset-0 z-50 bg-foreground/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...t,ref:a}));bi.displayName=Ke.Overlay.displayName;const Gt=R.forwardRef(({className:s,...t},a)=>e.jsxs(id,{children:[e.jsx(bi,{}),e.jsx(Ke.Content,{ref:a,className:v("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...t})]}));Gt.displayName=Ke.Content.displayName;const Wt=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-2 text-center sm:text-left",s),...t});Wt.displayName="AlertDialogHeader";const Kt=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});Kt.displayName="AlertDialogFooter";const Yt=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Title,{ref:a,className:v("text-lg font-semibold",s),...t}));Yt.displayName=Ke.Title.displayName;const Jt=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Description,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));Jt.displayName=Ke.Description.displayName;const Zt=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Action,{ref:a,className:v(Bs(),s),...t}));Zt.displayName=Ke.Action.displayName;const Xt=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Cancel,{ref:a,className:v(Bs({variant:"outline"}),"mt-2 sm:mt-0",s),...t}));Xt.displayName=Ke.Cancel.displayName;const ld="https://randmar.ai";function od(s){if(s==null)return null;const t=s instanceof Date?s:new Date(s);return Number.isNaN(t.getTime())?null:t}function cd(s){const t=od(s);if(!t)return"Never";const a=new Date;return t.getFullYear()===a.getFullYear()&&t.getMonth()===a.getMonth()&&t.getDate()===a.getDate()?`Today at ${new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit",timeZoneName:"short"}).format(t)}`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",timeZoneName:"short"}).format(t)}function yi({lastRefreshAt:s,onRefresh:t,onProgressiveRefresh:a,onAssistantClick:r,isRefreshing:n=!1,refreshLabel:i="Refresh",assistantLabel:l="Assistant",className:d,disabled:x=!1}){const[c,u]=R.useState(!1),[m,f]=R.useState(s);R.useEffect(()=>{f(s)},[s]);const g=!!(t||a),b=n||c,w=s??m,N=R.useCallback(async()=>{if(!(!g||x||b)){u(!0);try{a?(await a(!1),await a(!0)):await t?.(),f(new Date)}finally{u(!1)}}},[g,x,b,a,t]);return e.jsxs("div",{className:v("flex w-full flex-wrap items-center justify-start gap-2 lg:w-auto lg:justify-end",d),children:[e.jsxs("p",{className:"w-full text-xs text-muted-foreground sm:text-sm lg:w-auto",children:["Last refresh:"," ",e.jsx("span",{className:"font-medium text-foreground",children:cd(w)})]}),e.jsxs(D,{type:"button",variant:"outline",className:"min-h-11",disabled:x||b||!g,onClick:N,children:[b?e.jsx(p.Loader2,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}):e.jsx(p.RefreshCw,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{children:i})]}),e.jsx(D,{asChild:!0,variant:"default",className:v("min-h-11 lg:hidden",x&&"pointer-events-none opacity-50"),children:e.jsxs("a",{href:ld,target:"_blank",rel:"noopener noreferrer","aria-disabled":x||void 0,onClick:x?j=>j.preventDefault():void 0,children:[e.jsx(p.Bot,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{children:l})]})}),e.jsxs(D,{type:"button",variant:"default",className:"hidden min-h-11 lg:inline-flex",disabled:x,onClick:r,children:[e.jsx(p.Bot,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{children:l})]})]})}function dd({onAssistantClick:s,assistantPromptOptions:t,onAssistantUnavailable:a,...r}){const n=Mn(),i=R.useCallback(()=>{if(s){s();return}if(t){if(!n){a?.();return}n.sendMessageWithClear(t.prompt,t.hiddenPrompt,t.sopID)||a?.();return}a?.()},[t,n,s,a]);return e.jsx(yi,{...r,onAssistantClick:i})}const qr="w-full max-w-none w-[100cqw] ml-[calc(50%-50cqw)] mr-[calc(50%-50cqw)]",Ni="px-4 lg:px-6",ud=`${Ni} py-4`,md=`${Ni} py-3`;function xd({item:s,isCurrent:t}){return!t&&s.href?e.jsx("a",{href:s.href,className:"text-xs font-medium text-muted-foreground underline-offset-4 transition-colors hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:s.label}):!t&&s.onClick?e.jsx("button",{type:"button",className:"text-xs font-medium text-muted-foreground underline-offset-4 transition-colors hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",onClick:s.onClick,children:s.label}):e.jsx("span",{"aria-current":t?"page":void 0,className:v("text-xs font-medium",t?"text-foreground":"text-muted-foreground"),children:s.label})}function hd({items:s}){return s.length===0?null:e.jsx("nav",{"aria-label":"Breadcrumb",className:"w-full",children:e.jsx("ol",{className:"flex flex-wrap items-center gap-1.5",children:s.map((t,a)=>{const r=a===s.length-1,n=t.key??`${String(t.label)}-${a}`;return e.jsxs("li",{className:"inline-flex items-center gap-1.5",children:[e.jsx(xd,{item:t,isCurrent:!!t.current||r}),r?null:e.jsx("span",{"aria-hidden":"true",className:"text-xs text-muted-foreground",children:"/"})]},n)})})})}function vi({title:s,subtitle:t,breadcrumbs:a,rightTopActions:r,rightBottomActions:n,secondaryRow:i,sticky:l=!1,stickyClassName:d,className:x,cardClassName:c,contentClassName:u}){const m=!!(r||n),f=e.jsxs("header",{className:v("w-full border-b border-border bg-background",x),children:[e.jsx("div",{className:v(ud,c),children:e.jsxs("div",{className:v("flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",u),children:[e.jsxs("div",{className:"space-y-1",children:[a?.length?e.jsx(hd,{items:a}):null,e.jsx("h1",{className:"text-2xl font-semibold leading-tight tracking-tight text-foreground",children:s}),t?e.jsx("p",{className:"text-sm text-muted-foreground",children:t}):null]}),m?e.jsxs("div",{className:"flex w-full flex-col items-start gap-2 lg:w-auto lg:min-w-[16rem] lg:items-end",children:[r?e.jsx("div",{className:"flex w-full flex-wrap items-center justify-start gap-2 lg:justify-end",children:r}):null,n?e.jsx("div",{className:"flex w-full flex-wrap items-center justify-start gap-2 lg:justify-end",children:n}):null]}):null]})}),i?e.jsx("div",{className:"border-t border-border bg-primary/5",children:e.jsx("div",{className:md,children:i})}):null]});return l?e.jsx("div",{className:qr,children:e.jsx("div",{className:v("sticky top-0 z-20",d),children:f})}):e.jsx("div",{className:qr,children:f})}function fd({title:s,children:t,className:a}){return e.jsx(vi,{title:s,rightBottomActions:t?e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:t}):void 0,cardClassName:a})}const wi="space-y-8",Si="px-4 py-4 sm:px-6 sm:py-6";function pd({header:s,children:t,className:a,contentClassName:r,contentProps:n,...i}){return e.jsxs("section",{className:v(wi,a),...i,children:[s,e.jsx("div",{className:v(Si,r),...n,children:t})]})}function gd({className:s,children:t,...a}){return e.jsx("section",{className:v("px-4 py-4 sm:px-6 sm:py-6",s),...a,children:t})}const jd=[{value:"paragraph",label:"Paragraph"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}],bd=`
|
|
75
|
+
Repeat and ask me what to change or improve until we are done creating pictures.`)},[N,s,t,m]);return e.jsxs(e.Fragment,{children:[e.jsx(De,{open:i,onOpenChange:l,children:e.jsx(Me,{className:"max-w-4xl p-0 overflow-hidden",children:S||!k?e.jsx(Jc,{}):e.jsx(e.Fragment,{children:n?e.jsxs("div",{className:"flex flex-row",children:[e.jsxs("video",{className:"w-full rounded-l-lg max-h-[720px] object-contain",controls:!0,autoPlay:!0,muted:!0,loop:!0,children:[e.jsx("source",{src:k,type:"video/mp4"}),"Your browser does not support the video tag."]}),e.jsx("div",{className:"flex-grow min-w-[400px] h-[70vh] p-6",children:n})]}):e.jsxs("div",{className:"w-full relative",children:[e.jsxs("video",{className:"w-full max-h-[720px] object-contain",controls:!0,autoPlay:!0,children:[e.jsx("source",{src:k,type:"video/mp4"}),"Your browser does not support the video tag."]}),e.jsxs("div",{className:"absolute top-2 right-12 flex gap-1",children:[e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"secondary",size:"icon",onClick:P,"aria-label":"Copy video link",children:d?e.jsx(g.Check,{className:"h-4 w-4"}):e.jsx(g.Copy,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Copy video link"})})]})}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"secondary",size:"icon",onClick:A,"aria-label":"Download video",children:e.jsx(g.Download,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Download video"})})]})})]})]})})})}),e.jsxs("div",{className:"relative w-max h-max",ref:y,children:[M?e.jsx(f,{className:"rounded-md",style:{width:c,height:c}}):N?e.jsx("img",{alt:r||`Product ${s}`,className:`rounded-md ${b?"cursor-pointer":""}`,onClick:E,src:N,width:c,height:c}):e.jsx(Yc,{size:c}),e.jsxs("div",{className:"absolute top-2 right-2 flex flex-col gap-1",children:[b==!0&&e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"secondary",size:"icon",onClick:E,"aria-label":"Play product video",children:e.jsx(g.Play,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Play video"})})]})}),N?e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"secondary",size:"icon",onClick:T,"aria-label":"Ask AI to generate product images",children:e.jsx(g.Bot,{className:"h-4 w-4"})})}),e.jsx(pe,{children:e.jsx("p",{children:"Ask AI to generate product images"})})]})}):null]})]})]})}function Zc({reseller:s,actions:t,loading:a=!1}){return a||!s?e.jsx(Xc,{}):e.jsx(ed,{reseller:s,actions:t})}function Xc(){return e.jsxs(z,{children:[e.jsx(Y,{children:e.jsx(me,{children:e.jsx(f,{className:"h-6 w-40"})})}),e.jsxs(G,{children:[e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsx("div",{className:"space-y-4",children:Array(3).fill(0).map((s,t)=>e.jsxs("div",{className:"border rounded-lg p-4",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-9 w-9 rounded-full"})]}),e.jsxs("div",{children:[e.jsx(f,{className:"h-4 w-20 mb-1"}),e.jsx(f,{className:"h-7 w-28"})]})]},t))}),e.jsx("div",{className:"space-y-4",children:Array(2).fill(0).map((s,t)=>e.jsxs("div",{className:"border rounded-lg p-4",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-9 w-9 rounded-full"})]}),e.jsxs("div",{children:[e.jsx(f,{className:"h-4 w-20 mb-1"}),e.jsx(f,{className:"h-7 w-28"})]})]},t))})]}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(f,{className:"h-10 w-28 rounded-md"})})]})]})}function ed({reseller:s,actions:t}){const a=s.Statement||{},r=[{title:"0 - 30 Days",amount:a.Over0||0,icon:e.jsx(g.Calendar,{className:"h-5 w-5 text-primary-foreground"}),color:"bg-primary"},{title:"31 - 45 Days",amount:a.Over30||0,icon:e.jsx(g.Calendar,{className:"h-5 w-5 text-primary-foreground"}),color:"bg-primary"},{title:"45+ Days",amount:a.Over45||0,icon:e.jsx(g.Calendar,{className:"h-5 w-5 text-primary-foreground"}),color:"bg-primary"}],n=[{title:"Total",amount:a.Total||0,icon:e.jsx(g.DollarSign,{className:"h-5 w-5 text-success-foreground"}),color:"bg-success"},{title:"Credit Limit",amount:s.CreditLimit||0,icon:e.jsx(g.CreditCard,{className:"h-5 w-5 text-info-foreground"}),color:"bg-info"}];return e.jsxs(z,{children:[e.jsx(Y,{children:e.jsx(me,{children:"Billing Overview"})}),e.jsxs(G,{children:[e.jsxs("div",{className:"grid grid-cols-1 @md:grid-cols-2 gap-4",children:[e.jsx("div",{className:"space-y-4",children:r.map((i,l)=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-sm sm:text-base font-medium",children:i.title}),e.jsx("div",{className:`p-2 rounded-full ${i.color}`,children:i.icon})]}),e.jsx("div",{children:e.jsx("p",{className:"text-base sm:text-lg font-bold",children:de(i.amount)})})]},l))}),e.jsx("div",{className:"space-y-4",children:n.map((i,l)=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-sm sm:text-base font-medium",children:i.title}),e.jsx("div",{className:`p-2 rounded-full ${i.color}`,children:i.icon})]}),e.jsx("div",{children:e.jsx("p",{className:"text-base sm:text-lg font-bold",children:de(i.amount)})})]},l))})]}),t&&e.jsx("div",{className:"flex justify-end mt-4",children:t})]})]})}function ji({qualifications:s=[],loading:t=!1}){return t?e.jsxs(z,{children:[e.jsx(Y,{children:e.jsx(me,{children:"Qualifications"})}),e.jsx(G,{className:"p-6",children:e.jsx("div",{className:"grid grid-cols-2 @sm:grid-cols-3 @md:grid-cols-4 @lg:grid-cols-5 gap-4 gap-y-8",children:Array.from({length:10}).map((a,r)=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(f,{className:"h-12 w-24 rounded-md mb-2"}),e.jsx(f,{className:"h-5 w-16 rounded-full"})]},r))})})]}):e.jsxs(z,{children:[e.jsx(Y,{children:e.jsx(me,{children:"Qualifications"})}),e.jsx(G,{children:s&&s.length>0?e.jsx("div",{className:"p-6",children:e.jsx("div",{className:"flex grid grid-cols-2 @sm:grid-cols-3 @md:grid-cols-4 @lg:grid-cols-5 gap-4 gap-y-8",children:s.map((a,r)=>e.jsx(sd,{manufacturerId:a.ManufacturerId,opportunityNumber:a.DefaultOpportunityNumber},`${a.ManufacturerId}-${r}`))})}):e.jsx("p",{children:"No qualification available."})})]})}function sd({manufacturerId:s,opportunityNumber:t}){return e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"h-12 w-full items-center justify-center mb-2",children:e.jsx(us,{id:s,width:96,height:48})}),t&&e.jsx(fe,{variant:"outline",className:"text-xs",children:t})]})}function td({salesData:s,salesStatistics:t=[],loading:a=!1}){return a||!s?e.jsx(ad,{}):e.jsx(rd,{salesData:s,salesStatistics:t})}function ad(){return e.jsxs(z,{children:[e.jsx(Y,{className:"pb-0",children:e.jsx(me,{className:"text-lg @sm:text-xl",children:e.jsx(f,{className:"h-7 w-40"})})}),e.jsxs(G,{className:"pt-4 px-3 @sm:px-6",children:[e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 @lg:grid-cols-3 gap-4",children:Array(3).fill(0).map((s,t)=>e.jsxs("div",{className:"border rounded-lg p-4",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-9 w-9 rounded-full"})]}),e.jsxs("div",{children:[e.jsx(f,{className:"h-4 w-20 mb-1"}),e.jsx(f,{className:"h-7 w-28"})]})]},t))}),e.jsx("div",{className:"mt-6",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(f,{className:"h-5 w-32"}),e.jsx(f,{className:"h-[250px] w-full rounded-lg"})]})})]})]})}function rd({salesData:s,salesStatistics:t=[]}){const a=[{title:"Last 30 days",amount:s.SalesLast30Days||0,icon:e.jsx(g.Calendar,{className:"h-5 w-5 text-info-foreground"}),color:"bg-info"},{title:"Last 3 months",amount:s.SalesLast3Months||0,icon:e.jsx(g.Calendar,{className:"h-5 w-5 text-warning-foreground"}),color:"bg-warning"},{title:"Year to date",amount:s.SalesYearToDay||0,icon:e.jsx(g.Calendar,{className:"h-5 w-5 text-success-foreground"}),color:"bg-success"}];return e.jsxs(z,{children:[e.jsx(Y,{className:"pb-0",children:e.jsx(me,{className:"text-lg @sm:text-xl",children:"Sales Overview"})}),e.jsxs(G,{className:"pt-4 px-3 @sm:px-6",children:[e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 @lg:grid-cols-3 gap-4",children:a.map((r,n)=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h3",{className:"text-sm @sm:text-base font-medium",children:r.title}),e.jsx("div",{className:`p-2 rounded-full ${r.color}`,children:r.icon})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Amount"}),e.jsx("p",{className:"text-base @sm:text-lg font-bold",children:de(r.amount)})]})]},n))}),e.jsx("div",{className:"mt-6",children:t&&t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"text-sm font-medium mb-4",children:"Sales Trend"}),e.jsx("div",{className:"space-y-6",children:e.jsx(Vs,{statistics:t,chartHeight:300,mode:"week"})})]})})]})]})}function nd({icon:s,contentType:t,identifier:a,description:r,fields:n,actions:i,highlightedHeader:l=!1,className:d,...u}){const m=R.Children.toArray(i).filter(Boolean);return e.jsxs(z,{className:v("flex flex-col h-full overflow-hidden",d),...u,children:[e.jsx("header",{className:v("space-y-3 p-6",l&&"rounded-t-md bg-primary text-primary-foreground"),children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(s,{"aria-hidden":"true",className:v("mt-0.5 h-5 w-5 shrink-0",l?"text-primary-foreground":"text-primary")}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("h3",{className:v("text-base font-medium",l?"text-primary-foreground":"text-foreground"),children:t}),e.jsx("span",{className:v("font-mono text-sm",l?"text-primary-foreground":"text-foreground"),children:a})]}),e.jsx("p",{className:v("mt-1 text-sm",l?"text-primary-foreground":"text-muted-foreground"),children:r})]})]})}),e.jsx("section",{className:"flex-1 bg-card p-6",children:e.jsx("dl",{className:"grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-2 lg:grid-cols-3",children:n.map((h,c)=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("dt",{className:"text-xs font-semibold text-muted-foreground",children:h.label}),e.jsx("dd",{className:"text-sm text-foreground",children:h.value??"-"})]},`${h.label}-${c}`))})}),m.length>0&&e.jsx("footer",{className:"border-t border-border p-6 pt-4",children:e.jsx("div",{className:"flex justify-end gap-3",children:m.map((h,c)=>e.jsx("div",{className:"flex items-center justify-center [&>*]:min-h-11 [&>*]:min-w-11",children:h},c))})})]})}const dr=Ke.Root,ur=Ke.Trigger,id=Ke.Portal,bi=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Overlay,{className:v("fixed inset-0 z-50 bg-foreground/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...t,ref:a}));bi.displayName=Ke.Overlay.displayName;const Gt=R.forwardRef(({className:s,...t},a)=>e.jsxs(id,{children:[e.jsx(bi,{}),e.jsx(Ke.Content,{ref:a,className:v("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...t})]}));Gt.displayName=Ke.Content.displayName;const Wt=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-2 text-center sm:text-left",s),...t});Wt.displayName="AlertDialogHeader";const Kt=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});Kt.displayName="AlertDialogFooter";const Yt=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Title,{ref:a,className:v("text-lg font-semibold",s),...t}));Yt.displayName=Ke.Title.displayName;const Jt=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Description,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));Jt.displayName=Ke.Description.displayName;const Zt=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Action,{ref:a,className:v(Bs(),s),...t}));Zt.displayName=Ke.Action.displayName;const Xt=R.forwardRef(({className:s,...t},a)=>e.jsx(Ke.Cancel,{ref:a,className:v(Bs({variant:"outline"}),"mt-2 sm:mt-0",s),...t}));Xt.displayName=Ke.Cancel.displayName;const ld="https://randmar.ai";function od(s){if(s==null)return null;const t=s instanceof Date?s:new Date(s);return Number.isNaN(t.getTime())?null:t}function cd(s){const t=od(s);if(!t)return"Never";const a=new Date;return t.getFullYear()===a.getFullYear()&&t.getMonth()===a.getMonth()&&t.getDate()===a.getDate()?`Today at ${new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit",timeZoneName:"short"}).format(t)}`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",timeZoneName:"short"}).format(t)}function yi({lastRefreshAt:s,onRefresh:t,onProgressiveRefresh:a,onAssistantClick:r,isRefreshing:n=!1,refreshLabel:i="Refresh",assistantLabel:l="Assistant",className:d,disabled:u=!1}){const[m,h]=R.useState(!1),[c,y]=R.useState(s);R.useEffect(()=>{y(s)},[s]);const p=!!(t||a),x=n||m,w=s??c,N=R.useCallback(async()=>{if(!(!p||u||x)){h(!0);try{a?(await a(!1),await a(!0)):await t?.(),y(new Date)}finally{h(!1)}}},[p,u,x,a,t]);return e.jsxs("div",{className:v("flex w-full flex-wrap items-center justify-start gap-2 lg:w-auto lg:justify-end",d),children:[e.jsxs("p",{className:"w-full text-xs text-muted-foreground sm:text-sm lg:w-auto",children:["Last refresh:"," ",e.jsx("span",{className:"font-medium text-foreground",children:cd(w)})]}),e.jsxs(D,{type:"button",variant:"outline",className:"min-h-11",disabled:u||x||!p,onClick:N,children:[x?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}):e.jsx(g.RefreshCw,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{children:i})]}),e.jsx(D,{asChild:!0,variant:"default",className:v("min-h-11 lg:hidden",u&&"pointer-events-none opacity-50"),children:e.jsxs("a",{href:ld,target:"_blank",rel:"noopener noreferrer","aria-disabled":u||void 0,onClick:u?j=>j.preventDefault():void 0,children:[e.jsx(g.Bot,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{children:l})]})}),e.jsxs(D,{type:"button",variant:"default",className:"hidden min-h-11 lg:inline-flex",disabled:u,onClick:r,children:[e.jsx(g.Bot,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{children:l})]})]})}function dd({onAssistantClick:s,assistantPromptOptions:t,onAssistantUnavailable:a,...r}){const n=Mn(),i=R.useCallback(()=>{if(s){s();return}if(t){if(!n){a?.();return}n.sendMessageWithClear(t.prompt,t.hiddenPrompt,t.sopID)||a?.();return}a?.()},[t,n,s,a]);return e.jsx(yi,{...r,onAssistantClick:i})}const qr="w-full max-w-none w-[100cqw] ml-[calc(50%-50cqw)] mr-[calc(50%-50cqw)]",Ni="px-4 lg:px-6",ud=`${Ni} py-4`,md=`${Ni} py-3`;function xd({item:s,isCurrent:t}){return!t&&s.href?e.jsx("a",{href:s.href,className:"text-xs font-medium text-muted-foreground underline-offset-4 transition-colors hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:s.label}):!t&&s.onClick?e.jsx("button",{type:"button",className:"text-xs font-medium text-muted-foreground underline-offset-4 transition-colors hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",onClick:s.onClick,children:s.label}):e.jsx("span",{"aria-current":t?"page":void 0,className:v("text-xs font-medium",t?"text-foreground":"text-muted-foreground"),children:s.label})}function hd({items:s}){return s.length===0?null:e.jsx("nav",{"aria-label":"Breadcrumb",className:"w-full",children:e.jsx("ol",{className:"flex flex-wrap items-center gap-1.5",children:s.map((t,a)=>{const r=a===s.length-1,n=t.key??`${String(t.label)}-${a}`;return e.jsxs("li",{className:"inline-flex items-center gap-1.5",children:[e.jsx(xd,{item:t,isCurrent:!!t.current||r}),r?null:e.jsx("span",{"aria-hidden":"true",className:"text-xs text-muted-foreground",children:"/"})]},n)})})})}function vi({title:s,subtitle:t,breadcrumbs:a,rightTopActions:r,rightBottomActions:n,secondaryRow:i,sticky:l=!1,stickyClassName:d,className:u,cardClassName:m,contentClassName:h}){const c=!!(r||n),y=e.jsxs("header",{className:v("w-full border-b border-border bg-background",u),children:[e.jsx("div",{className:v(ud,m),children:e.jsxs("div",{className:v("flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",h),children:[e.jsxs("div",{className:"space-y-1",children:[a?.length?e.jsx(hd,{items:a}):null,e.jsx("h1",{className:"text-2xl font-semibold leading-tight tracking-tight text-foreground",children:s}),t?e.jsx("p",{className:"text-sm text-muted-foreground",children:t}):null]}),c?e.jsxs("div",{className:"flex w-full flex-col items-start gap-2 lg:w-auto lg:min-w-[16rem] lg:items-end",children:[r?e.jsx("div",{className:"flex w-full flex-wrap items-center justify-start gap-2 lg:justify-end",children:r}):null,n?e.jsx("div",{className:"flex w-full flex-wrap items-center justify-start gap-2 lg:justify-end",children:n}):null]}):null]})}),i?e.jsx("div",{className:"border-t border-border bg-primary/5",children:e.jsx("div",{className:md,children:i})}):null]});return l?e.jsx("div",{className:qr,children:e.jsx("div",{className:v("sticky top-0 z-20",d),children:y})}):e.jsx("div",{className:qr,children:y})}function fd({title:s,children:t,className:a}){return e.jsx(vi,{title:s,rightBottomActions:t?e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:t}):void 0,cardClassName:a})}const wi="space-y-8",Si="px-4 py-4 sm:px-6 sm:py-6";function pd({header:s,children:t,className:a,contentClassName:r,contentProps:n,...i}){return e.jsxs("section",{className:v(wi,a),...i,children:[s,e.jsx("div",{className:v(Si,r),...n,children:t})]})}function gd({className:s,children:t,...a}){return e.jsx("section",{className:v("px-4 py-4 sm:px-6 sm:py-6",s),...a,children:t})}const jd=[{value:"paragraph",label:"Paragraph"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"},{value:"h5",label:"Heading 5"},{value:"h6",label:"Heading 6"}],bd=`
|
|
76
76
|
.ProseMirror {
|
|
77
77
|
min-height: 150px;
|
|
78
78
|
padding: 0.5rem;
|
|
@@ -126,6 +126,6 @@ Repeat and ask me what to change or improve until we are done creating pictures.
|
|
|
126
126
|
.ProseMirror p {
|
|
127
127
|
margin-bottom: 0.5em;
|
|
128
128
|
}
|
|
129
|
-
`;function yd({id:s,name:t,value:a,onChange:r,placeholder:n,className:i,...l}){const[d,x]=o.useState(!1),c=o.useRef(null),u=o.useRef(null),m=Mr.useEditor({extensions:[gl,jl],content:a,editorProps:{attributes:{class:"prose prose-sm sm:prose focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",id:s??"",name:t??""}},onUpdate:({editor:j})=>{const y=j.getHTML();r({target:{id:s,name:t,value:y}})}});o.useEffect(()=>{m&&a!==m.getHTML()&&m.commands.setContent(a)},[a,m]);const f=o.useCallback(j=>{if(m)if(m.chain().focus(),j==="paragraph")m.chain().setParagraph().run();else{const y=Number.parseInt(j.slice(1));m.chain().setHeading({level:y}).run()}},[m]),g=o.useCallback(j=>{if(m)switch(m.chain().focus(),j){case"bold":m.chain().toggleBold().run();break;case"italic":m.chain().toggleItalic().run();break;case"underline":m.chain().toggleUnderline().run();break;case"strike":m.chain().toggleStrike().run();break;case"bulletList":m.chain().toggleBulletList().run();break;case"orderedList":m.chain().toggleOrderedList().run();break}},[m]),b=o.useCallback(()=>{x(j=>!j)},[]),w=o.useCallback(j=>{const y=j.target.value;m&&m.commands.setContent(y),r({target:{id:s,name:t,value:y}})},[r,m,s,t]),N=o.useCallback(()=>{!d&&m&&m.commands.focus()},[d,m]);return m?e.jsxs("div",{ref:u,className:v("border border-input rounded-md overflow-hidden focus-within:outline-hidden focus-within:ring-1 focus-within:ring-ring",i),onClick:N,...l,children:[e.jsx("style",{children:bd}),e.jsxs("div",{className:"flex flex-wrap items-center p-2 border-b border-input gap-2 bg-background",children:[e.jsxs(ks,{onValueChange:f,disabled:d,children:[e.jsx(ps,{className:"w-[160px]",children:e.jsx(Rs,{placeholder:"Format"})}),e.jsx(gs,{children:jd.map(j=>e.jsx(Xe,{value:j.value,children:j.label},j.value))})]}),["bold","italic","underline","strike","bulletList","orderedList"].map(j=>e.jsxs(D,{type:"button",variant:"ghost",size:"sm",onClick:()=>g(j),className:m.isActive(j)?"bg-muted":"",disabled:d,children:[j==="bold"&&e.jsx(p.Bold,{className:"h-4 w-4"}),j==="italic"&&e.jsx(p.Italic,{className:"h-4 w-4"}),j==="underline"&&e.jsx(p.UnderlineIcon,{className:"h-4 w-4"}),j==="strike"&&e.jsx(p.Strikethrough,{className:"h-4 w-4"}),j==="bulletList"&&e.jsx(p.List,{className:"h-4 w-4"}),j==="orderedList"&&e.jsx(p.ListOrdered,{className:"h-4 w-4"})]},j)),e.jsx(D,{type:"button",variant:"ghost",size:"sm",onClick:b,className:d?"bg-muted":"",children:e.jsx(p.Code,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"p-3",children:d?e.jsx(fs,{ref:c,id:s,name:t,value:m.getHTML(),onChange:w,className:v("min-h-[150px] font-mono text-sm resize-none border-0 focus-visible:ring-0 focus-visible:ring-offset-0",i),placeholder:n}):e.jsx(Mr.EditorContent,{editor:m})})]}):null}function Pa({applicationId:s,orders:t=null,loading:a=!1,title:r="Order Details"}){const n=o.useMemo(()=>[{accessorKey:"OrderNumber",header:"Order Number",cell:({row:d})=>d.original.OrderNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/GeneralDocument/${d.original.OrderNumber}`,className:"font-medium text-primary hover:underline",children:d.original.OrderNumber})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for order ",d.original.OrderNumber]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentNumber",header:"Document Number",cell:({row:d})=>d.original.DocumentNumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentDate",header:"Document Date",cell:({row:d})=>Ks(d.original.DocumentDate),enableSorting:!0,enableFiltering:!1},{accessorKey:"PONumber",header:"PO Number",cell:({row:d})=>d.original.PONumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseCode",header:"Warehouse",cell:({row:d})=>d.original.WarehouseCode??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"MPN",header:"MPN",cell:({row:d})=>d.original.MPN?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Product/${d.original.MPN}`,className:"font-medium text-primary hover:underline",children:d.original.MPN})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for MPN ",d.original.MPN]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:d})=>d.original.Quantity??"N/A",enableSorting:!0,enableFiltering:!1},{accessorKey:"ShipToName",header:"Name",cell:({row:d})=>e.jsx("div",{className:"min-w-[150px]",children:d.original.ShipToName??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:d})=>d.original.UnitPrice?ce(d.original.UnitPrice):"N/A",enableSorting:!0,enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:d})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx(pi,{applicationId:s,randmarSku:d.original.RandmarSKU??"",buttonSize:"sm"})})}],[s]),i=o.useMemo(()=>{const d={};if(t){const x=Array.from(new Set(t.map(b=>b.WarehouseCode).filter(b=>b!=null)));d.WarehouseCode=x;const c=Array.from(new Set(t.map(b=>b.ShipToName).filter(b=>b!=null)));d.ShipToName=c;const u=Array.from(new Set(t.map(b=>b.DocumentNumber).filter(b=>b!=null)));d.DocumentNumber=u;const m=Array.from(new Set(t.map(b=>b.OrderNumber).filter(b=>b!=null)));d.OrderNumber=m;const f=Array.from(new Set(t.map(b=>b.PONumber).filter(b=>b!=null)));d.PONumber=f;const g=Array.from(new Set(t.map(b=>b.MPN).filter(b=>b!=null)));d.MPN=g}return d},[t]),l=t||[];return a?e.jsxs(U,{className:"w-full",children:[e.jsxs(Y,{children:[" ",e.jsx(h,{className:"h-7 w-48"})," "]}),e.jsxs(G,{className:"space-y-4",children:[e.jsx(h,{className:"h-12 w-full rounded-md border"}),e.jsx(h,{className:"h-10 w-full rounded-md border"}),e.jsx(h,{className:"h-10 w-full rounded-md border"}),e.jsx(h,{className:"h-10 w-full rounded-md border"}),e.jsxs("div",{className:"flex items-center justify-between pt-4",children:[e.jsx(h,{className:"h-9 w-[130px]"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(h,{className:"h-9 w-20"}),e.jsx(h,{className:"h-9 w-24"}),e.jsx(h,{className:"h-9 w-9"}),e.jsx(h,{className:"h-9 w-9"})]})]})]})]}):e.jsxs(U,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:r})}),e.jsx(G,{children:e.jsx(As,{columns:n,data:l,uniqueValues:i})})]})}function Nd({applicationId:s,receipts:t=null,loading:a=!1}){const r=o.useMemo(()=>[{accessorKey:"Location",header:"Location",cell:({row:l})=>l.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptDate",header:"Date",cell:({row:l})=>Ks(l.original.ReceiptDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptNumber",header:"Number",cell:({row:l})=>l.original.ReceiptNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Document/${l.original.ReceiptNumber}`,className:"font-medium text-primary hover:underline",children:l.original.ReceiptNumber})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for Receipt ",l.original.ReceiptNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:l})=>l.original.Quantity??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:l})=>l.original.UnitPrice?ce(l.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0}],[]),n=o.useMemo(()=>{const l={};if(t){const d=Array.from(new Set(t.map(c=>c.Location).filter(c=>c!=null)));l.Location=d;const x=Array.from(new Set(t.map(c=>Ks(c.ReceiptDate)).filter(c=>c!=="—"&&c!=="Invalid Date"))).sort((c,u)=>new Date(u).getTime()-new Date(c).getTime());l.ReceiptDate=x}return l},[t]),i=t||[];return e.jsx(As,{columns:r,data:i,uniqueValues:n,loading:a,tableClass:"bg-card text-card-foreground",initialSort:[{id:"ReceiptDate",desc:!0}]})}const ha=s=>{if(!s)return"N/A";try{const t=new Date(s);return isNaN(t.getTime())?"Invalid Date":t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}},vd=s=>{const t=s?.toLowerCase()||"";return t.includes("accepted")?"success":t.includes("error")||t.includes("rejected")?"destructive":"neutral"};function Ci({applicationId:s,returns:t=null,loading:a=!1}){const r=o.useMemo(()=>[{accessorKey:"ReturnNumber1",header:"RMA Number",cell:({row:l})=>{const d=l.original.ReturnNumber1||l.original.ReturnNumber;return d?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Return/${d}`,className:"font-medium text-primary hover:underline",children:d})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for return ",d]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestDate",header:"Request Date",cell:({row:l})=>ha(l.original.RequestDate),enableSorting:!0},{accessorKey:"InvoiceNumber",header:"Invoice Number",cell:({row:l})=>{const d=l.original.InvoiceNumber;return d?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Document/${d}`,className:"text-primary hover:underline",children:d})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for invoice ",d]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:l})=>l.original.Quantity??"0",enableSorting:!0},{accessorKey:"ReasonForReturn",header:"Return Reason",cell:({row:l})=>e.jsx("div",{className:"min-w-[150px]",children:l.original.ReasonForReturn??"—"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"Status",header:"Status",cell:({row:l})=>{const d=l.original.Status,x=vd(d),c=x==="success"?"success":x==="destructive"?"destructive":"secondary";return d?e.jsx(fe,{variant:c,className:"font-medium",children:d}):"—"},enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseLocation",header:"Warehouse",cell:({row:l})=>l.original.WarehouseLocation??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"LastUpdatedDate",header:"Last Update",cell:({row:l})=>ha(l.original.LastUpdatedDate)!=="N/A"?ha(l.original.LastUpdatedDate):"—",enableSorting:!0}],[s]),n=o.useMemo(()=>{const l={};if(t){const d=Array.from(new Set(t.map(u=>u.Status).filter(Boolean)));l.Status=d;const x=Array.from(new Set(t.map(u=>u.ReasonForReturn).filter(Boolean)));l.ReasonForReturn=x;const c=Array.from(new Set(t.map(u=>u.WarehouseLocation).filter(Boolean)));l.WarehouseLocation=c}return l},[t]),i=o.useMemo(()=>t?[...t].sort((d,x)=>(x.ReturnNumber1||x.ReturnNumber||"").localeCompare(d.ReturnNumber1||d.ReturnNumber||"")):[],[t]);return a?e.jsxs(U,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(h,{className:"h-7 w-48"})}),e.jsxs(G,{className:"space-y-4",children:[e.jsx(h,{className:"h-12 w-full rounded-md border"}),e.jsx(h,{className:"h-48 w-full rounded-md border"}),e.jsxs("div",{className:"flex items-center justify-between pt-4",children:[e.jsx(h,{className:"h-9 w-[130px]"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(h,{className:"h-9 w-20"}),e.jsx(h,{className:"h-9 w-24"}),e.jsx(h,{className:"h-9 w-9"}),e.jsx(h,{className:"h-9 w-9"})]})]})]})]}):e.jsxs(U,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-xl font-semibold text-foreground",children:"Returns"})}),e.jsx(G,{children:e.jsx(As,{columns:r,data:i,uniqueValues:n})})]})}function wd({applicationId:s,purchaseOrders:t=null,loading:a=!1}){const[r,n]=o.useState([]),[i]=_.usePostV4ManufacturerByRouteManufacturerIdPurchaseOrderAndPurchaseOrderNumberEditItemRandmarSkuMutation(),{toast:l}=Ce();o.useEffect(()=>{n(t||[])},[t]);const d=o.useMemo(()=>[{accessorKey:"PurchaseOrderNumber",header:"Number",cell:({row:c})=>c.original.PurchaseOrderNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Document/${c.original.PurchaseOrderNumber}`,className:"font-medium text-primary hover:underline",children:c.original.PurchaseOrderNumber})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for Purchase Order ",c.original.PurchaseOrderNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PurchaseOrderDate",header:"Date",cell:({row:c})=>Ks(c.original.PurchaseOrderDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:c})=>c.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PartNumber",header:"Part Number",cell:({row:c})=>c.original.MPN?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Product/${c.original.RandmarSKU}`,className:"font-medium text-primary hover:underline",children:c.original.MPN})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for Product ",c.original.RandmarSKU]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:c})=>c.original.QuantityOrdered??0,enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:c})=>c.original.UnitPrice?ce(c.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:u}){const[m,f]=o.useState(!1),g=u.original,b=()=>{f(!0),i({routeManufacturerId:s,purchaseOrderNumber:g.PurchaseOrderNumber??"",randmarSku:g.RandmarSKU??"",quantity:0}).then(()=>{n(w=>w.filter(N=>!(N.PurchaseOrderNumber===N.PurchaseOrderNumber&&N.MPN===N.MPN))),l({variant:"success",title:"Success",description:`Part ${g.MPN} has been successfully deleted from Purchase Order ${g.PurchaseOrderNumber}.`})}).catch(w=>{console.error(w),f(!0),l({variant:"destructive",title:"Error",description:"Something went wrong!"})})};return e.jsx("div",{className:"text-right",children:e.jsxs(dr,{children:[e.jsx(ur,{asChild:!0,children:e.jsx(D,{variant:"red",size:"sm",disabled:m,children:m?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting"]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})}),e.jsxs(Gt,{children:[e.jsxs(Wt,{children:[e.jsx(Yt,{children:"Confirmation"}),e.jsxs(Jt,{children:["Are you sure you want to delete part ",e.jsx("strong",{children:g.MPN})," from Purchase Order ",e.jsx("strong",{children:g.PurchaseOrderNumber}),"?."]})]}),e.jsxs(Kt,{children:[e.jsx(Xt,{disabled:m,children:"Cancel"}),e.jsxs(Zt,{onClick:b,disabled:m,children:[m&&e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}],[s]),x=o.useMemo(()=>{const c={};return r&&(c.PurchaseOrderNumber=Array.from(new Set(r.map(u=>u.PurchaseOrderNumber).filter(u=>u!=null))),c.PurchaseOrderDate=Array.from(new Set(r.map(u=>u.PurchaseOrderDate).filter(u=>u!=null).map(String))),c.Location=Array.from(new Set(r.map(u=>u.Location).filter(u=>u!=null))),c.PartNumber=Array.from(new Set(r.map(u=>u.MPN).filter(u=>u!=null))),c.QuantityOrdered=Array.from(new Set(r.map(u=>u.QuantityOrdered).filter(u=>u!=null).map(String))),c.UnitPrice=Array.from(new Set(r.map(u=>u.UnitPrice).filter(u=>u!=null).map(String)))),c},[r]);return e.jsx(As,{columns:d,data:r,uniqueValues:x,loading:a,tableClass:"bg-card text-card-foreground"})}function Sd({applicationId:s,requisitions:t=null,loading:a=!1}){const[r,n]=o.useState([]),[i]=_.useDeleteV4ManufacturerByRouteManufacturerIdRequisitionAndRequisitionNumberMutation(),{toast:l}=Ce();o.useEffect(()=>{n(t||[])},[t]);const d=o.useMemo(()=>[{accessorKey:"RequisitionNumber",header:"Number",cell:({row:c})=>c.original.RequisitionNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Document/${c.original.RequisitionNumber}`,className:"font-medium text-primary hover:underline",children:c.original.RequisitionNumber})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for Draft Purchase ",c.original.RequisitionNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequisitionDate",header:"Date",cell:({row:c})=>Ks(c.original.RequisitionDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:c})=>c.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:c})=>c.original.QuantityOrdered??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOutstanding",header:"Quantity Outstanding",cell:({row:c})=>c.original.QuantityOutstanding??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityReceived",header:"Quantity Received",cell:({row:c})=>c.original.QuantityReceived??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"SubTotal",header:"Sub Total",cell:({row:c})=>c.original.SubTotal?ce(c.original.SubTotal):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestedBy",header:"Requestor",cell:({row:c})=>c.original.RequestedBy??"—",enableSorting:!0,enableFiltering:!0},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:u}){const[m,f]=o.useState(!1),g=u.original,b=()=>{f(!0),i({routeManufacturerId:s,requisitionNumber:g.RequisitionNumber??""}).then(()=>{n(w=>w.filter(N=>N.RequisitionNumber!==N.RequisitionNumber)),l({variant:"success",title:"Success",description:`Draft Purchase ${g.RequisitionNumber} has been successfully cancelled.`})}).catch(w=>{console.error(w),f(!0),l({variant:"destructive",title:"Error",description:"Something went wrong!"})})};return e.jsx("div",{className:"text-right",children:e.jsxs(dr,{children:[e.jsx(ur,{asChild:!0,children:e.jsx(D,{variant:"red",size:"sm",disabled:m,children:m?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancelling"]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Trash2,{className:"mr-2 h-4 w-4"}),"Cancel"]})})}),e.jsxs(Gt,{children:[e.jsxs(Wt,{children:[e.jsx(Yt,{children:"Confirmation"}),e.jsxs(Jt,{children:["Are you sure you want to cancel Draft Purchase ",e.jsx("strong",{children:g.RequisitionNumber}),"?."]})]}),e.jsxs(Kt,{children:[e.jsx(Xt,{disabled:m,children:"Cancel"}),e.jsxs(Zt,{onClick:b,disabled:m,children:[m&&e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}],[s]),x=o.useMemo(()=>{const c={};return r&&(c.RequisitionNumber=Array.from(new Set(r.map(u=>u.RequisitionNumber).filter(u=>u!=null))),c.RequisitionDate=Array.from(new Set(r.map(u=>u.RequisitionDate).filter(u=>u!=null).map(String))),c.QuantityOrdered=Array.from(new Set(r.map(u=>u.QuantityOrdered).filter(u=>u!=null).map(String))),c.QuantityOutstanding=Array.from(new Set(r.map(u=>u.QuantityOutstanding).filter(u=>u!=null).map(String))),c.QuantityReceived=Array.from(new Set(r.map(u=>u.QuantityReceived).filter(u=>u!=null).map(String))),c.Location=Array.from(new Set(r.map(u=>u.Location).filter(u=>u!=null))),c.RequestedBy=Array.from(new Set(r.map(u=>u.RequestedBy).filter(u=>u!=null))),c.SubTotal=Array.from(new Set(r.map(u=>u.SubTotal).filter(u=>u!=null).map(String)))),c},[r]);return e.jsx(As,{columns:d,data:r,uniqueValues:x,loading:a,tableClass:"bg-card text-card-foreground"})}const Cd=new Intl.DateTimeFormat(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"});function Aa(s){if(!s)return null;const t=s.trim();if(!t)return null;if(/[zZ]$/.test(t)||/[+-]\d{2}:?\d{2}$/.test(t)){const j=new Date(t);return Number.isNaN(j.getTime())?null:j}const r=t.replace(" ","T"),[n,i]=r.split("T");if(!n)return null;const[l,d,x]=n.split("-"),c=Number.parseInt(l??"",10),u=Number.parseInt(d??"",10),m=Number.parseInt(x??"",10);if(!Number.isFinite(c)||!Number.isFinite(u)||!Number.isFinite(m))return null;let f=0,g=0,b=0,w=0;if(i){const j=i.trim(),[y,k,S]=j.split(":");if(f=Number.parseInt(y??"0",10),g=Number.parseInt(k??"0",10),S){const[M,P]=S.split(".");b=Number.parseInt(M??"0",10),P&&(w=Number.parseInt(P.slice(0,3).padEnd(3,"0"),10))}}if(!Number.isFinite(f)||!Number.isFinite(g)||!Number.isFinite(b)||!Number.isFinite(w))return null;const N=new Date(c,u-1,m,f,g,b,w);return Number.isNaN(N.getTime())||N.getFullYear()!==c||N.getMonth()!==u-1||N.getDate()!==m?null:N}function kd(s){const t=Aa(s);return t?Cd.format(t):"—"}function Rd({logs:s=null,loading:t=!1}){const a=o.useMemo(()=>[{accessorKey:"DateTime",header:"Date & Time",cell:({row:r})=>kd(r.original.DateTime),enableSorting:!0,enableFiltering:!1,sortingFn:(r,n,i)=>{const l=Aa(r.getValue(i)),d=Aa(n.getValue(i)),x=l?l.getTime():Number.NEGATIVE_INFINITY,c=d?d.getTime():Number.NEGATIVE_INFINITY;return x===c?0:x>c?1:-1}},{accessorKey:"Message",header:"Message",cell:({row:r})=>e.jsx("span",{className:"whitespace-pre-wrap break-words",children:r.original.Message??"—"}),enableSorting:!0,enableFiltering:!0}],[]);return e.jsx(As,{columns:a,data:s||[],uniqueValues:{},loading:t,tableClass:"bg-card text-card-foreground",initialSort:[{id:"DateTime",desc:!0}]})}function Pd({applicationId:s,sku:t,product:a,productDefaultOpportunityNumber:r="",productOnAddToCart:n,productAddingToCart:i=!1,productShopifyHostname:l,productCustomAction:d=e.jsx(e.Fragment,{})}){const{data:x,isLoading:c}=_.useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:s,randmarSku:t??"",withSpecification:!1},{skip:!!a||!s||!t}),{data:u,isLoading:m}=_.useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:s,randmarSku:t??"",withSpecification:!0},{skip:!!a||!s||!t}),f=a??u??x,{data:g}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:s}),b=g?.IsManufacturer&&g?.BillingInformation?.CurrencyCode?.toUpperCase()==="USD",[w,N]=o.useState("stats-tab"),[j,y]=o.useState(!1);o.useEffect(()=>{if(!a&&m){y(!1);return}const V={"stats-tab":(f?.SalesStatistics?.length??0)<=0,"inventory-tab":(f?.Distribution?.Inventory?.length??0)<=0,"opportunities-tab":(f?.Opportunities?.length??0)<=0,"active-orders-tab":(f?.ActiveOrderDetails?.length??0)<=0,"completed-orders-tab":(f?.CompletedOrderDetails?.length??0)<=0,"returns-tab":(f?.Returns?.length??0)<=0,"purchase-orders-tab":!g?.IsManufacturer||(f?.PurchaseOrders?.length??0)<=0&&(f?.Requisitions?.length??0)<=0,"warehouse-tab":(f?.Receipts?.length??0)<=0,"logs-tab":(f?.Logs?.length??0)<=0},z=Object.values(V).some(O=>!O);if(y(z),z&&V[w]){const O=Object.keys(V).find(H=>!V[H]);O&&N(O)}},[m,f,a,w,g?.IsManufacturer]);const k=!a&&(c||m),S=f?.Title||f?.RandmarTitle||f?.RandmarSKU||"Product",M=f?.VoiceoverCaption||"",P=typeof f?.MAP=="number"&&f.MAP>0?f.MAP:typeof f?.Distribution?.MAP=="number"&&f.Distribution.MAP>0?f.Distribution.MAP:null,A=typeof f?.MSRP=="number"&&f.MSRP>0?f.MSRP:typeof f?.Distribution?.MSRP=="number"&&f.Distribution.MSRP>0?f.Distribution.MSRP:null,T=r?f?.Opportunities?.find(V=>V.BidNumber===r)?.Price:null,E=typeof T=="number"&&T>0?T:typeof f?.Distribution?.Price=="number"&&f.Distribution.Price>0?f.Distribution.Price:null,I=k||typeof E=="number",F=typeof P=="number"&&typeof E=="number"?P-E:null,$=typeof F=="number"&&typeof P=="number"&&P>0?Math.round(F/P*100):null;return e.jsxs("div",{className:"@container",children:[e.jsxs("div",{className:"grid gap-4 grid-cols-1 @md:grid-cols-3",children:[e.jsxs(U,{className:"@md:col-span-2",children:[e.jsxs(Y,{className:"space-y-2",children:[e.jsx(me,{className:"text-2xl font-semibold leading-tight",children:k&&!f?e.jsx(h,{className:"h-7 w-2/3"}):S}),M?e.jsx("div",{className:"text-sm text-muted-foreground",children:M}):k&&!f?e.jsx(h,{className:"h-4 w-4/5"}):null]}),e.jsxs(G,{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[I?e.jsxs("div",{className:"flex flex-col gap-4 @sm:flex-row @sm:items-start @sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Your Price"}),e.jsx("div",{className:"mt-1 text-3xl font-semibold tracking-tight",children:typeof E=="number"?ce(E):k?e.jsx(h,{className:"h-9 w-40"}):null})]}),typeof F=="number"&&typeof $=="number"?e.jsxs("div",{className:"flex flex-col items-start @sm:items-end",children:[e.jsxs(fe,{variant:F>=0?"success":"destructive",className:"rounded-full px-3 py-1.5 text-sm font-semibold",children:[F>=0?"Potential Profit":"Below MAP",": ",ce(Math.abs(F))]}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:F>=0?`${$}% margin vs MAP`:`${Math.abs($)}% under MAP`})]}):null]}):null,e.jsx(ye,{children:e.jsxs("div",{className:`${I?"mt-5":"mt-0"} grid grid-cols-1 gap-4 @sm:grid-cols-2`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-md border bg-background/50 p-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx("button",{type:"button",className:"cursor-help bg-transparent p-0 underline decoration-dotted underline-offset-4",children:"MAP"})}),e.jsx(pe,{children:"Minimum Advertised Price — the lowest price you can publicly advertise."})]})}),e.jsx("div",{className:"font-medium",children:typeof P=="number"?ce(P):"—"})]}),typeof F=="number"&&typeof E=="number"&&typeof P=="number"?e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Profit vs MAP"}),e.jsxs("div",{className:"text-sm font-semibold",children:[ce(P)," - ",ce(E)," = ",ce(F)]})]}):null]}),e.jsx("div",{className:"flex items-start justify-between gap-4 rounded-md border bg-background/50 p-3",children:e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx("button",{type:"button",className:"cursor-help bg-transparent p-0 underline decoration-dotted underline-offset-4",children:"MSRP"})}),e.jsx(pe,{children:"Manufacturer's Suggested Retail Price — a reference retail list price."})]})}),e.jsx("div",{className:"font-medium",children:typeof A=="number"?ce(A):"—"})]})})]})})]}),f?.BodyHTML?e.jsx("div",{className:"prose prose-sm max-w-none leading-relaxed [&_p]:mb-4 [&_p:last-child]:mb-0",dangerouslySetInnerHTML:{__html:f.BodyHTML}}):e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx(p.Info,{className:"h-4 w-4 inline mr-2"}),"No product description available."]})]})]}),e.jsx("div",{className:"self-start @md:sticky @md:top-4",children:e.jsx(Vt,{applicationId:s,product:f,defaultOpportunityNumber:r,onAddToCart:n,addingToCart:i,shopifyHostname:l,customAction:d,showUsdLabelOnCost:b})})]}),e.jsx("div",{className:"my-4",children:c||m?e.jsx("div",{className:"mx-auto flex justify-center items-center h-32",children:e.jsx(p.Loader2,{className:"h-8 w-8 animate-spin text-primary"})}):j&&e.jsxs(Za,{value:w,onValueChange:N,children:[e.jsxs(qt,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[e.jsx(We,{value:"stats-tab",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",disabled:(f?.SalesStatistics?.length??0)<=0,children:"Statistics"}),e.jsx(We,{value:"inventory-tab",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",disabled:(f?.Distribution?.Inventory?.length??0)<=0,children:"Inventory"}),e.jsx(We,{value:"opportunities-tab",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",disabled:(f?.Opportunities?.length??0)<=0,children:"Opportunities"}),e.jsx(We,{value:"active-orders-tab",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",disabled:(f?.ActiveOrderDetails?.length??0)<=0,children:"Active Orders"}),e.jsx(We,{value:"completed-orders-tab",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",disabled:(f?.CompletedOrderDetails?.length??0)<=0,children:"Completed Orders"}),e.jsx(We,{value:"returns-tab",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",disabled:(f?.Returns?.length??0)<=0,children:"Returns"}),e.jsx(We,{value:"purchase-orders-tab",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",disabled:!g?.IsManufacturer||(f?.PurchaseOrders?.length??0)<=0&&(f?.Requisitions?.length??0)<=0,children:"Purchase Orders"}),e.jsx(We,{value:"warehouse-tab",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",disabled:(f?.Receipts?.length??0)<=0,children:"Latest Warehouse Receiving"}),e.jsx(We,{value:"logs-tab",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",disabled:(f?.Logs?.length??0)<=0,children:"Logs"})]}),e.jsx(Ze,{value:"stats-tab",children:e.jsx("div",{className:"mt-4",children:e.jsx(Xa,{statistics:f?.SalesStatistics??[],loading:m})})}),e.jsx(Ze,{value:"inventory-tab",children:e.jsx("div",{className:"mt-4",children:e.jsx(Ta,{inventory:f?.Distribution?.Inventory??[],className:"bg-card text-card-foreground"})})}),e.jsx(Ze,{value:"opportunities-tab",children:e.jsx("div",{className:"mt-4",children:e.jsx(mr,{applicationId:s,opportunities:f?.Opportunities,loading:m})})}),e.jsx(Ze,{value:"active-orders-tab",children:(f?.ActiveOrderDetails?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Pa,{applicationId:s,title:"Active Orders",orders:f?.ActiveOrderDetails,loading:m})})}),e.jsx(Ze,{value:"completed-orders-tab",children:(f?.CompletedOrderDetails?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Pa,{applicationId:s,title:"Completed Orders",orders:f?.CompletedOrderDetails,loading:m})})}),e.jsx(Ze,{value:"returns-tab",children:(f?.Returns?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Ci,{applicationId:s,returns:f?.Returns,loading:m})})}),e.jsxs(Ze,{value:"purchase-orders-tab",children:[(f?.PurchaseOrders?.length??0)>0&&e.jsxs(U,{className:"mt-4 w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Purchase Orders"})}),e.jsx(G,{children:e.jsx(wd,{applicationId:s,purchaseOrders:f?.PurchaseOrders,loading:m})})]}),(f?.Requisitions?.length??0)>0&&e.jsxs(U,{className:"mt-4 w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Draft Purchases"})}),e.jsx(G,{children:e.jsx(Sd,{applicationId:s,requisitions:f?.Requisitions,loading:m})})]})]}),e.jsx(Ze,{value:"warehouse-tab",children:(f?.Receipts?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsxs(U,{className:"mt-4 w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Receipts"})}),e.jsx(G,{children:e.jsx(Nd,{applicationId:s,receipts:f?.Receipts,loading:m})})]})})}),e.jsx(Ze,{value:"logs-tab",children:(f?.Logs?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsxs(U,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Logs"})}),e.jsx(G,{children:e.jsx(Rd,{logs:f?.Logs,loading:m})})]})})})]})})]})}const ht={base:{1:"grid-cols-1",2:"grid-cols-2",3:"grid-cols-3",4:"grid-cols-4",5:"grid-cols-5",6:"grid-cols-6"},sm:{1:"sm:grid-cols-1",2:"sm:grid-cols-2",3:"sm:grid-cols-3",4:"sm:grid-cols-4",5:"sm:grid-cols-5",6:"sm:grid-cols-6"},md:{1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3",4:"md:grid-cols-4",5:"md:grid-cols-5",6:"md:grid-cols-6"},lg:{1:"lg:grid-cols-1",2:"lg:grid-cols-2",3:"lg:grid-cols-3",4:"lg:grid-cols-4",5:"lg:grid-cols-5",6:"lg:grid-cols-6"},xl:{1:"xl:grid-cols-1",2:"xl:grid-cols-2",3:"xl:grid-cols-3",4:"xl:grid-cols-4",5:"xl:grid-cols-5",6:"xl:grid-cols-6"}},Ad=s=>{const t={base:1,md:2,...s};return["grid","gap-4",t.base?ht.base[t.base]:"",t.sm?ht.sm[t.sm]:"",t.md?ht.md[t.md]:"",t.lg?ht.lg[t.lg]:"",t.xl?ht.xl[t.xl]:""].filter(Boolean).join(" ")},Id=({results:s,groupBy:t,renderItem:a})=>{const r=t(s);return e.jsx(e.Fragment,{children:Object.entries(r).map(([n,i])=>{const{items:l,gridCols:d}=i;if(l.length===0)return null;const x=Ad(d);return e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight mb-4",children:n}),e.jsx("div",{className:x,children:l.map((c,u)=>a(c,u))})]},n)})})},Dd=["Use fewer words or remove punctuation from your query.","Try a broader term, then narrow down with filters.","Check SKU, brand, or document IDs for typos."];function ki({query:s,subtitle:t="We could not find matches for this query. Try adjusting the terms or ask Assistant for help.",tips:a=Dd,onReloadSearch:r,onAssistantClick:n,reloadLabel:i="Reload Search",assistantLabel:l="Assistant",icon:d,className:x}){const u=`No Results "${s.trim()}"`,m=a.length>0;return e.jsxs(U,{className:v("w-full border-border bg-card",x),children:[e.jsxs(Y,{className:"space-y-3",children:[e.jsx("div",{className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-border bg-muted text-muted-foreground",children:d??e.jsx(p.SearchX,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(me,{className:"text-xl leading-tight",children:u}),e.jsx(rt,{children:t})]})]}),e.jsx(G,{className:"border-t border-border pt-4",children:m?e.jsx("ul",{className:"space-y-2 text-sm text-foreground",children:a.map((f,g)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"mt-2 h-1.5 w-1.5 shrink-0 rounded-full bg-muted-foreground","aria-hidden":"true"}),e.jsx("span",{children:f})]},`search-no-results-tip-${g}`))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Try adjusting your search and reload to continue."})}),e.jsx(ms,{className:"border-t border-border pt-4",children:e.jsxs("div",{className:"flex w-full flex-wrap justify-end gap-3",children:[e.jsx(D,{type:"button",variant:"outline",onClick:r,disabled:!r,children:i}),e.jsx(D,{type:"button",variant:"default",onClick:n,disabled:!n,children:l})]})})]})}function Md(s){const t=s?.trim();return t?`Search Results for "${t}"`:"Search Results"}function Td({query:s,title:t,subtitle:a,actions:r,children:n,className:i,contentClassName:l}){const d=r??n;return e.jsx("header",{className:v("w-full",i),children:e.jsx(U,{className:"rounded-2xl border-border shadow-sm",children:e.jsxs("div",{className:v("flex flex-col gap-4 p-6 lg:flex-row lg:items-start lg:justify-between",l),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold leading-tight tracking-tight text-foreground",children:t??Md(s)}),a?e.jsx("p",{className:"text-sm text-muted-foreground",children:a}):null]}),d?e.jsx("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-2",children:d}):null]})})})}function Ed(){return e.jsxs(U,{className:"h-full border-border bg-card",children:[e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx(h,{className:"h-5 w-3/5 bg-muted"}),e.jsx(h,{className:"h-4 w-full bg-muted"}),e.jsx(h,{className:"h-4 w-4/5 bg-muted"})]}),e.jsx("div",{className:"border-t border-border p-6 pt-4",children:e.jsx(h,{className:"h-9 w-24 bg-muted"})})]})}function Qr({cardCount:s}){return e.jsxs("section",{className:"space-y-4",children:[e.jsx(h,{className:"h-6 w-44 bg-muted"}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:Array.from({length:s??6}).map((t,a)=>e.jsx(Ed,{},`search-cards-skeleton-${a}`))})]})}function Hr({tableRows:s}){return e.jsxs("section",{className:"space-y-4",children:[e.jsx(h,{className:"h-6 w-56 bg-muted"}),e.jsx(U,{className:"border-border bg-card p-4 sm:p-6",children:e.jsxs("div",{className:"overflow-hidden rounded-md border border-border",children:[e.jsxs("div",{className:"grid grid-cols-12 gap-4 border-b border-border bg-muted/40 px-4 py-3",children:[e.jsx(h,{className:"col-span-4 h-4 w-3/4 bg-muted"}),e.jsx(h,{className:"col-span-3 h-4 w-2/3 bg-muted"}),e.jsx(h,{className:"col-span-3 h-4 w-2/3 bg-muted"}),e.jsx(h,{className:"col-span-2 h-4 w-full bg-muted"})]}),Array.from({length:s??6}).map((t,a)=>e.jsxs("div",{className:"grid grid-cols-12 gap-4 border-b border-border px-4 py-3 last:border-b-0",children:[e.jsx(h,{className:"col-span-4 h-4 w-11/12 bg-muted"}),e.jsx(h,{className:"col-span-3 h-4 w-4/5 bg-muted"}),e.jsx(h,{className:"col-span-3 h-4 w-3/5 bg-muted"}),e.jsx(h,{className:"col-span-2 h-4 w-full bg-muted"})]},`search-table-skeleton-row-${a}`))]})})]})}function Ri({variant:s="mixed",cardCount:t=6,tableRows:a=6,className:r}){return e.jsxs("div",{className:v("space-y-6",r),role:"status","aria-live":"polite",children:[s==="cards"?e.jsx(Qr,{cardCount:t}):null,s==="table"?e.jsx(Hr,{tableRows:a}):null,s==="mixed"?e.jsxs(e.Fragment,{children:[e.jsx(Qr,{cardCount:Math.max(3,Math.min(t,6))}),e.jsx(Hr,{tableRows:a})]}):null,e.jsx("span",{className:"sr-only",children:"Loading search results"})]})}const Od=({query:s,results:t,isLoading:a,header:r,loadingState:n,noResultsState:i,initialState:l,className:d,resultsContainerClassName:x,children:c})=>{const u=Array.isArray(t)?t:[],m=s.trim().length>0,f=u.length>0;let g;return f?g=e.jsx("div",{className:v("grid grid-cols-3 gap-8",x),children:e.jsx("div",{className:"col-span-3",children:c})}):a?g=n??e.jsx(Ri,{}):m?g=i??e.jsx(ki,{query:s}):g=l??null,!r&&!g?null:e.jsxs("div",{className:v("w-full space-y-6",d),children:[r,g]})},Ld=Fs.Root,Pi=R.forwardRef(({className:s,...t},a)=>e.jsx(Fs.Item,{ref:a,className:v("border-b",s),...t}));Pi.displayName="AccordionItem";const Ai=R.forwardRef(({className:s,children:t,...a},r)=>e.jsx(Fs.Header,{className:"flex",children:e.jsxs(Fs.Trigger,{ref:r,className:v("flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline text-left [&[data-state=open]>svg]:rotate-180",s),...a,children:[t,e.jsx(p.ChevronDown,{className:"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200"})]})}));Ai.displayName=Fs.Trigger.displayName;const Ii=R.forwardRef(({className:s,children:t,...a},r)=>e.jsx(Fs.Content,{ref:r,className:"overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...a,children:e.jsx("div",{className:v("pb-4 pt-0",s),children:t})}));Ii.displayName=Fs.Content.displayName;function Di({className:s,classNames:t,showOutsideDays:a=!0,captionLayout:r="label",buttonVariant:n="ghost",formatters:i,components:l,...d}){const x=ya.getDefaultClassNames();return e.jsx(ya.DayPicker,{showOutsideDays:a,className:v("bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,s),captionLayout:r,formatters:{formatMonthDropdown:c=>c.toLocaleString("default",{month:"short"}),...i},classNames:{root:v("w-fit",x.root),months:v("relative flex flex-col gap-4 md:flex-row",x.months),month:v("flex w-full flex-col gap-4",x.month),nav:v("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",x.nav),button_previous:v(Bs({variant:n}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_previous),button_next:v(Bs({variant:n}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_next),month_caption:v("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",x.month_caption),dropdowns:v("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",x.dropdowns),dropdown_root:v("has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",x.dropdown_root),dropdown:v("bg-popover absolute inset-0 opacity-0",x.dropdown),caption_label:v("select-none font-medium",r==="label"?"text-sm":"[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",x.caption_label),table:"w-full border-collapse",weekdays:v("flex",x.weekdays),weekday:v("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",x.weekday),week:v("mt-2 flex w-full",x.week),week_number_header:v("w-[--cell-size] select-none",x.week_number_header),week_number:v("text-muted-foreground select-none text-[0.8rem]",x.week_number),day:v("group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",x.day),range_start:v("bg-accent rounded-l-md",x.range_start),range_middle:v("rounded-none",x.range_middle),range_end:v("bg-accent rounded-r-md",x.range_end),today:v("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",x.today),outside:v("text-muted-foreground aria-selected:text-muted-foreground",x.outside),disabled:v("text-muted-foreground opacity-50",x.disabled),hidden:v("invisible",x.hidden),...t},components:{Root:({className:c,rootRef:u,...m})=>e.jsx("div",{"data-slot":"calendar",ref:u,className:v(c),...m}),Chevron:({className:c,orientation:u,...m})=>u==="left"?e.jsx(p.ChevronLeftIcon,{className:v("size-4",c),...m}):u==="right"?e.jsx(p.ChevronRightIcon,{className:v("size-4",c),...m}):e.jsx(p.ChevronDownIcon,{className:v("size-4",c),...m}),DayButton:Fd,WeekNumber:({children:c,...u})=>e.jsx("td",{...u,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:c})}),...l},...d})}function Fd({className:s,day:t,modifiers:a,...r}){const n=ya.getDefaultClassNames(),i=R.useRef(null);return R.useEffect(()=>{a.focused&&i.current?.focus()},[a.focused]),e.jsx(D,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":a.selected&&!a.range_start&&!a.range_end&&!a.range_middle,"data-range-start":a.range_start,"data-range-end":a.range_end,"data-range-middle":a.range_middle,className:v("data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-auto w-full min-w-[--cell-size] flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70",n.day,s),...r})}function Bd(s){return e.jsx(U,{className:"max-w-6xl",children:e.jsx(Ht,{className:"h-[40em]",userId:s.userId,userName:s.userName,initialPrompt:s.initialPrompt})})}function fa(s){if(!s||!Ia(s))return"";const t=s.getTimezoneOffset()*6e4;return new Date(s.getTime()-t).toISOString().split("T")[0]}function Ia(s){return s instanceof Date&&!Number.isNaN(s.getTime())}function Ot({date:s,onDateChange:t,label:a,id:r,className:n}){const[i,l]=R.useState(!1),[d,x]=R.useState(s),[c,u]=R.useState(fa(s));R.useEffect(()=>{u(fa(s)),Ia(s)&&x(s)},[s]);const m=g=>{const w=g.target.value.replace(/\D/g,"").slice(0,8);let N=w;if(w.length>4&&(N=`${w.slice(0,4)}-${w.slice(4)}`),w.length>6&&(N=`${w.slice(0,4)}-${w.slice(4,6)}-${w.slice(6)}`),u(N),w.length===8){const j=new Date(N),y=new Date(j.getUTCFullYear(),j.getUTCMonth(),j.getUTCDate());Ia(y)?(t(y),x(y)):t(void 0)}else t(void 0)},f=g=>{g&&(t(g),u(fa(g))),l(!1)};return e.jsxs("div",{className:v("flex flex-col gap-2",n),children:[a&&e.jsx(J,{htmlFor:r,children:a}),e.jsxs("div",{className:"relative",children:[e.jsx(ie,{id:r,value:c,placeholder:"YYYY-MM-DD",className:"bg-background pr-10",onChange:m,onKeyDown:g=>{g.key==="ArrowDown"&&(g.preventDefault(),l(!0))}}),e.jsxs(wt,{open:i,onOpenChange:l,children:[e.jsx(St,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 h-7 w-7 -translate-y-1/2","aria-label":"Select date",children:e.jsx(p.CalendarIcon,{className:"h-4 w-4"})})}),e.jsx(it,{className:"w-auto min-w-[280px] p-0",align:"end",sideOffset:8,children:e.jsx(Di,{mode:"single",selected:s,onSelect:f,month:d,onMonthChange:x,initialFocus:!0,className:"w-full"})})]})]})]})}function $d({product:s,viewProductLink:t}){return s?e.jsx(U,{className:"@container border-dashed border-2 hover:shadow-md transition-shadow h-full",children:e.jsxs(G,{className:"p-6 flex flex-col h-full",children:[e.jsxs("div",{className:"flex justify-between items-start mb-4 @[36rem]:hidden",children:[e.jsx("h3",{className:"font-semibold text-lg pr-4 text-center w-full",children:s.Title||s.RandmarTitle}),e.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:e.jsx(us,{id:s.ManufacturerId,name:s.ManufacturerName,width:96,height:40})})]}),e.jsxs("div",{className:"flex flex-col gap-x-6 gap-y-4 flex-grow @[36rem]:flex-row",children:[e.jsx("div",{className:"mx-auto flex-shrink-0 @[36rem]:mx-0 @[36rem]:w-48",children:e.jsx(fi,{randmarSKU:s.RandmarSKU||"",alt:s.RandmarTitle||"",fallback:e.jsx(cr,{randmarSKU:s.RandmarSKU||"",alt:s.RandmarTitle||"",sceneName:s.SceneName})})}),e.jsxs("div",{className:"flex flex-1 flex-col text-center @[36rem]:text-left",children:[e.jsxs("div",{className:"hidden @[36rem]:flex justify-between items-start mb-4",children:[e.jsx("h3",{className:"font-semibold text-lg pr-4",children:s.Title||s.RandmarTitle}),e.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:e.jsx(us,{id:s.ManufacturerId,name:s.ManufacturerName,width:96,height:40})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @[36rem]:hidden",children:[e.jsxs(fe,{variant:"outline",className:"border-info/40 bg-info/10 text-info",children:[e.jsx(p.LucideTelescope,{className:"mr-2 h-3 w-3"}),e.jsx("span",{children:"External Product"})]}),e.jsxs(fe,{variant:"outline",className:"border-primary/40 bg-primary/10 text-primary",children:[e.jsx(p.LucideWarehouse,{className:"mr-2 h-3 w-3"}),e.jsxs("span",{children:["Held by ",e.jsx("b",{children:"Randmar"})]})]})]}),e.jsxs("div",{className:"hidden @[36rem]:grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center rounded-md bg-info/10 px-4 py-2 text-info border border-info text-sm",children:[e.jsx(p.LucideTelescope,{className:"mr-2 h-5 w-5 flex-shrink-0"}),e.jsx("span",{children:"External Product"})]}),e.jsxs("div",{className:"flex items-center rounded-md bg-primary/10 px-4 py-2 text-primary border border-primary text-sm",children:[e.jsx(p.LucideWarehouse,{className:"mr-2 h-5 w-5 flex-shrink-0"}),e.jsxs("span",{children:["Held by ",e.jsx("b",{children:"Randmar"})]})]})]}),t&&e.jsx("div",{className:"mt-auto pt-4 flex justify-center @[36rem]:justify-end",children:e.jsx(ve.Link,{to:t,children:e.jsxs(D,{variant:"secondary",className:"w-full @[36rem]:w-auto",children:[e.jsx(p.LucideEye,{className:"mr-2 h-4 w-4"}),"View Product"]})})})]})]})]})}):e.jsx(U,{className:"@container border-dashed border-2 h-full",children:e.jsx(G,{className:"p-6 flex flex-col h-full",children:e.jsxs("div",{className:"flex flex-col gap-6 flex-grow @[36rem]:flex-row",children:[e.jsx("div",{className:"flex-shrink-0 @[36rem]:w-48",children:e.jsx(h,{className:"aspect-square w-full h-auto"})}),e.jsxs("div",{className:"flex flex-1 flex-col gap-4",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsx(h,{className:"h-10 w-1/2"}),e.jsx(h,{className:"h-10 w-24 rounded"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @[36rem]:hidden",children:[e.jsx(h,{className:"h-6 w-36 rounded-full"}),e.jsx(h,{className:"h-6 w-36 rounded-full"})]}),e.jsxs("div",{className:"hidden @[36rem]:grid grid-cols-2 gap-2",children:[e.jsx(h,{className:"h-10 w-full rounded-md"}),e.jsx(h,{className:"h-10 w-full rounded-md"})]})]}),e.jsx("div",{className:"mt-auto pt-4 flex justify-center @[36rem]:justify-end",children:e.jsx(h,{className:"h-10 w-full @[36rem]:w-40"})})]})]})})})}function _d(s){if(!s)return{text:"No End Date",variant:"neutral",daysRemaining:null};const t=new Date(s);if(isNaN(t.getTime()))return{text:"Invalid Date",variant:"neutral",daysRemaining:null};const a=new Date,r=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=new Date(a.getFullYear(),a.getMonth(),a.getDate()),i=r.getTime()-n.getTime(),l=Math.ceil(i/(1e3*60*60*24));return l<0?{text:`Ended ${Math.abs(l)}d ago`,variant:"destructive",daysRemaining:l}:l===0?{text:"Ends today",variant:"destructive",daysRemaining:l}:l<=7?{text:`Ends in ${l}d`,variant:"destructive",daysRemaining:l}:l<=30?{text:`Ends in ${l}d`,variant:"warning",daysRemaining:l}:{text:`Ends in ${l}d`,variant:"neutral",daysRemaining:l}}const pa=s=>{if(!s)return"N/A";try{const t=new Date(s);return isNaN(t.getTime())?"Invalid Date":t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}};function mr({applicationId:s,opportunities:t=null,loading:a=!1}){const{toast:r}=Ce(),[n,i]=o.useState({}),[l,d]=o.useState(!1),[x,c]=o.useState(""),[u,m]=o.useState(null),{data:f}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:s},{skip:!s}),g=o.useCallback((A,T,E)=>{i(I=>({...I,[A]:{...I[A],[T]:E}}))},[]),[b]=_.usePutV4ResellerByRouteResellerIdOpportunityAndManufacturerIdDefaultMutation(),w=o.useCallback(async A=>{if(!f?.IsReseller)return;if(!A.BidNumber){r({title:"Error",description:"Bid Number is missing, cannot set default.",variant:"destructive"});return}const T=A.BidNumber;g(T,"isSettingDefault",!0),b({routeResellerId:s,manufacturerId:A.ManufacturerId??"",opportunityNumber:T}).unwrap().then(()=>{r({title:"Success",description:`Opportunity "${A.OpportunityName||A.Opportunity||T}" was successfully set as default.`,variant:"success"})}).catch(E=>{console.error("Set as default error:",E),r({title:"Error",description:E.data?.message||E.message||"An error occurred while setting this opportunity as default.",variant:"destructive"})}).finally(()=>{g(T,"isSettingDefault",!1)})},[s,b,r,g,f?.IsReseller]),[N]=_.usePostV4ResellerByRouteResellerIdOpportunityAndManufacturerIdBidNumberEmailMutation(),j=o.useCallback(A=>{if(f?.IsReseller){if(!A.BidNumber){r({title:"Error",description:"Bid Number is missing, cannot prepare report.",variant:"destructive"});return}m(A),c(""),d(!0)}},[r,f?.IsReseller]),y=o.useCallback(async()=>{if(!f?.IsReseller)return;if(!u||!u.BidNumber){r({title:"Error",description:"No opportunity selected or Bid Number is missing.",variant:"destructive"});return}if(!x.trim()||!/\S+@\S+\.\S+/.test(x)){r({title:"Validation Error",description:"Please enter a valid email address.",variant:"destructive"});return}const A=u.BidNumber;g(A,"isSendingReport",!0),N({routeResellerId:s,manufacturerId:u.ManufacturerId??"",bidNumber:A,emailAddress:x}).unwrap().then(()=>{r({title:"Success",description:`A report for "${u.OpportunityName||u.Opportunity||A}" was successfully sent to ${x}.`,variant:"success"}),d(!1)}).catch(T=>{console.error("Send report by email error:",T),r({title:"Error",description:T.data?.message||T.message||"An error occurred while sending the report by email.",variant:"destructive"})}).finally(()=>{g(A,"isSendingReport",!1),l||(m(null),c(""))})},[u,x,s,N,r,g,d]),k=o.useMemo(()=>[{accessorKey:"ManufacturerId",header:"Manuf.",cell:({row:A})=>e.jsx("div",{className:"w-20 h-8",children:e.jsx(us,{id:A.original.ManufacturerId,width:80,height:32})}),enableSorting:!0,enableFiltering:!0},{id:"opportunityDisplay",accessorFn:A=>A.OpportunityName||A.Opportunity,header:"Opportunity",cell:({getValue:A})=>e.jsx("div",{className:"min-w-[150px]",children:A()??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"BidNumber",header:"Bid Number",cell:({row:A})=>A.original.BidNumber??"N/A",enableSorting:!0,enableFiltering:!0},{id:"statusInfo",header:"Status",cell:({row:A})=>{const T=A.original,E=T.Active===!0,I=_d(T.EndDate),F=E?"success":"secondary",$=I.variant==="destructive"?"destructive":I.variant==="warning"?"warning":"secondary";return e.jsxs("div",{className:"flex items-center space-x-2 min-w-[200px]",children:[e.jsx(fe,{variant:F,className:"font-medium",children:E?"Active":"Inactive"}),T.EndDate&&e.jsx(fe,{variant:$,className:"font-medium",children:I.text}),e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0 data-[state=delayed-open]:bg-accent data-[state=instant-open]:bg-accent",children:e.jsx(p.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(pe,{side:"top",align:"center",className:"bg-popover text-popover-foreground p-2 rounded shadow-lg",children:e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Start:"})," ",pa(T.StartDate)]}),e.jsxs("p",{children:[e.jsx("strong",{children:"End:"})," ",pa(T.EndDate)]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Updated:"})," ",pa(T.LastUpdate)]})]})})]})})]})},enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:A})=>{const T=A.original;if(!T.BidNumber)return e.jsx("span",{className:"text-xs text-muted-foreground",children:"Actions unavailable"});const E=T.BidNumber,I=n[E]?.isSettingDefault,F=u?.BidNumber===E&&n[E]?.isSendingReport,$=I||F,V=T.CanBeSetAsDefault===!0,z=f?.IsManufacturer?`/${s}/Opportunity/${T.BidNumber}`:`/${s}/Opportunity/${T.ManufacturerId}/${T.BidNumber}`;return e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(ve.Link,{to:z,children:e.jsxs(D,{variant:"outline",size:"sm",className:"flex items-center",children:[e.jsx(p.Star,{className:"mr-2 h-4 w-4"})," View"]})}),f?.IsReseller&&e.jsxs(e.Fragment,{children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>w(T),disabled:$||!V,title:V?"Set as default":"This opportunity cannot be set as default",className:"flex items-center",children:[I?e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(p.Star,{className:"mr-2 h-4 w-4"})," Set Default"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>j(T),disabled:$,title:"Send report by email",className:"flex items-center",children:[F?e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(p.Send,{className:"mr-2 h-4 w-4"})," Send Report"]})]})]})}}],[n,w,j,u,f?.IsReseller,s]),S=o.useMemo(()=>{const A={};if(t){const T=Array.from(new Set(t.map(I=>I.ManufacturerId).filter(I=>I!=null)));A.ManufacturerId=T;const E=Array.from(new Set(t.map(I=>I.OpportunityName||I.Opportunity).filter(I=>I!=null)));A.opportunityDisplay=E}return A},[t]),M=t||[],P=u?.BidNumber?n[u.BidNumber]?.isSendingReport:!1;return a?e.jsxs(U,{className:"w-full",children:[e.jsxs(Y,{children:[" ",e.jsx(h,{className:"h-7 w-48"})," "]}),e.jsxs(G,{className:"space-y-4",children:[e.jsx(h,{className:"h-12 w-full rounded-md border"}),e.jsx(h,{className:"h-48 w-full rounded-md border"}),e.jsxs("div",{className:"flex items-center justify-between pt-4",children:[e.jsx(h,{className:"h-9 w-[130px]"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(h,{className:"h-9 w-20"})," ",e.jsx(h,{className:"h-9 w-24"})," ",e.jsx(h,{className:"h-9 w-9"})," ",e.jsx(h,{className:"h-9 w-9"})]})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"w-full",children:[e.jsxs(Y,{children:[" ",e.jsx(me,{className:"text-1xl font-bold",children:"Opportunities"})," "]}),e.jsx(G,{children:e.jsx(As,{columns:k,data:M,uniqueValues:S})})]}),e.jsx(Ie,{open:l,onOpenChange:A=>{d(A),A||(m(null),c(""))},children:e.jsxs(De,{className:"@sm:max-w-[425px]",children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Send Opportunity Report"}),e.jsxs(_e,{children:["Enter the email address to send the report for opportunity: ",e.jsx("br",{}),e.jsx("span",{className:"font-semibold",children:u?.OpportunityName||u?.Opportunity||"N/A"}),u?.BidNumber&&e.jsxs("span",{className:"block text-sm text-muted-foreground",children:["Bid Number: ",u.BidNumber]})]})]}),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(ie,{id:"email",type:"email",value:x,onChange:A=>c(A.target.value),placeholder:"recipient@example.com",className:"col-span-3",disabled:P})]})}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>d(!1),disabled:P,children:"Cancel"}),e.jsxs(D,{type:"submit",onClick:y,disabled:P,children:[P&&e.jsx(p.Loader2,{className:"mr-2 h-4 w-4 animate-spin"})," Send Report"]})]})]})})]})}function Vd(s){const t=s instanceof Date?new Date(s.getTime()):new Date(s);return Number.isNaN(t.getTime())?null:t}function zd(s){const t=s.getFullYear().toString(),a=(s.getMonth()+1).toString().padStart(2,"0"),r=s.getDate().toString().padStart(2,"0");return`${t}-${a}-${r}`}function Mi(s){const t=new Map;for(const a of s){const r=Vd(a.timestamp);if(!r)continue;const n=new Date(r.getFullYear(),r.getMonth(),r.getDate()),i=zd(n),l=t.get(i);if(l){l.entries.push({entry:a,timestamp:r});continue}t.set(i,{dayKey:i,day:n,entries:[{entry:a,timestamp:r}]})}return Array.from(t.values()).map(a=>({...a,entries:[...a.entries].sort((r,n)=>r.timestamp.getTime()-n.timestamp.getTime())})).sort((a,r)=>r.day.getTime()-a.day.getTime())}const Ud=new Intl.DateTimeFormat(void 0,{weekday:"long",month:"short",day:"numeric",year:"numeric"}),qd=new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit",second:"2-digit"});function Qd({entries:s,emptyStateText:t="No system log entries available.",className:a,formatDayLabel:r=i=>Ud.format(i),formatTimeLabel:n=i=>qd.format(i)}){const i=R.useMemo(()=>Mi(s),[s]);return i.length===0?e.jsx("p",{className:v("text-sm text-muted-foreground",a),children:t}):e.jsx("div",{className:v("space-y-6",a),children:i.map(l=>e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:r(l.day)}),e.jsx("div",{className:"space-y-2",children:l.entries.map((d,x)=>{const c=d.entry.id??`${l.dayKey}-${d.timestamp.getTime()}-${x}`;return e.jsxs("article",{className:"rounded-md border border-border bg-card p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:n(d.timestamp)}),e.jsx("pre",{className:"font-mono text-xs text-foreground whitespace-pre-wrap break-words",children:d.entry.payload})]},c)})})]},l.dayKey))})}function Hd(s){const t=s.match(/(\d+\.?\d*)\s*(\d+\.?\d*)%\s*(\d+\.?\d*)%/);return t?{h:parseFloat(t[1]),s:parseFloat(t[2]),l:parseFloat(t[3])}:null}function ga(s,t,a){a/=100;const r=t*Math.min(a,1-a)/100,n=i=>{const l=(i+s/30)%12,d=a-r*Math.max(Math.min(l-3,9-l,1),-1);return Math.round(255*d).toString(16).padStart(2,"0")};return`#${n(0)}${n(8)}${n(4)}`}const xr=R.forwardRef(({data:s,options:t,height:a="500px",className:r,loading:n,disableClick:i=!0,...l},d)=>{const x=R.useRef(null),[c,u]=R.useState(null);R.useEffect(()=>{if(!x.current)return;const g=x.current,b=()=>{const y=getComputedStyle(g).getPropertyValue("--primary").trim();if(y){const k=Hd(y);if(k){const{h:S,s:M,l:P}=k;u({minColor:ga(S,M,Math.min(100,P+50)),midColor:ga(S,M,Math.min(100,P+35)),maxColor:ga(S,M,Math.min(100,P+20))})}return!0}return!1};if(b())return;let w=0;const N=20,j=setInterval(()=>{(b()||w>=N)&&clearInterval(j),w++},100);return()=>{j&&clearInterval(j)}},[]);const m=R.useMemo(()=>{const g={headerHeight:0,fontSize:14,showScale:!1,isHtml:!0,backgroundColor:"transparent",generateTooltip:(b,w)=>{const N=s[b+1]?.[0];if(!N)return"";const j=ce(w);return`<div class="p-2 bg-background text-foreground border rounded-md shadow-lg">
|
|
129
|
+
`;function yd({id:s,name:t,value:a,onChange:r,placeholder:n,className:i,...l}){const[d,u]=o.useState(!1),m=o.useRef(null),h=o.useRef(null),c=Mr.useEditor({extensions:[gl,jl],content:a,editorProps:{attributes:{class:"prose prose-sm sm:prose focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",id:s??"",name:t??""}},onUpdate:({editor:j})=>{const b=j.getHTML();r({target:{id:s,name:t,value:b}})}});o.useEffect(()=>{c&&a!==c.getHTML()&&c.commands.setContent(a)},[a,c]);const y=o.useCallback(j=>{if(c)if(c.chain().focus(),j==="paragraph")c.chain().setParagraph().run();else{const b=Number.parseInt(j.slice(1));c.chain().setHeading({level:b}).run()}},[c]),p=o.useCallback(j=>{if(c)switch(c.chain().focus(),j){case"bold":c.chain().toggleBold().run();break;case"italic":c.chain().toggleItalic().run();break;case"underline":c.chain().toggleUnderline().run();break;case"strike":c.chain().toggleStrike().run();break;case"bulletList":c.chain().toggleBulletList().run();break;case"orderedList":c.chain().toggleOrderedList().run();break}},[c]),x=o.useCallback(()=>{u(j=>!j)},[]),w=o.useCallback(j=>{const b=j.target.value;c&&c.commands.setContent(b),r({target:{id:s,name:t,value:b}})},[r,c,s,t]),N=o.useCallback(()=>{!d&&c&&c.commands.focus()},[d,c]);return c?e.jsxs("div",{ref:h,className:v("border border-input rounded-md overflow-hidden focus-within:outline-hidden focus-within:ring-1 focus-within:ring-ring",i),onClick:N,...l,children:[e.jsx("style",{children:bd}),e.jsxs("div",{className:"flex flex-wrap items-center p-2 border-b border-input gap-2 bg-background",children:[e.jsxs(ks,{onValueChange:y,disabled:d,children:[e.jsx(ps,{className:"w-[160px]",children:e.jsx(Rs,{placeholder:"Format"})}),e.jsx(gs,{children:jd.map(j=>e.jsx(Xe,{value:j.value,children:j.label},j.value))})]}),["bold","italic","underline","strike","bulletList","orderedList"].map(j=>e.jsxs(D,{type:"button",variant:"ghost",size:"sm",onClick:()=>p(j),className:c.isActive(j)?"bg-muted":"",disabled:d,children:[j==="bold"&&e.jsx(g.Bold,{className:"h-4 w-4"}),j==="italic"&&e.jsx(g.Italic,{className:"h-4 w-4"}),j==="underline"&&e.jsx(g.UnderlineIcon,{className:"h-4 w-4"}),j==="strike"&&e.jsx(g.Strikethrough,{className:"h-4 w-4"}),j==="bulletList"&&e.jsx(g.List,{className:"h-4 w-4"}),j==="orderedList"&&e.jsx(g.ListOrdered,{className:"h-4 w-4"})]},j)),e.jsx(D,{type:"button",variant:"ghost",size:"sm",onClick:x,className:d?"bg-muted":"",children:e.jsx(g.Code,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"p-3",children:d?e.jsx(fs,{ref:m,id:s,name:t,value:c.getHTML(),onChange:w,className:v("min-h-[150px] font-mono text-sm resize-none border-0 focus-visible:ring-0 focus-visible:ring-offset-0",i),placeholder:n}):e.jsx(Mr.EditorContent,{editor:c})})]}):null}function Pa({applicationId:s,orders:t=null,loading:a=!1,title:r="Order Details"}){const n=o.useMemo(()=>[{accessorKey:"OrderNumber",header:"Order Number",cell:({row:d})=>d.original.OrderNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/GeneralDocument/${d.original.OrderNumber}`,className:"font-medium text-primary hover:underline",children:d.original.OrderNumber})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for order ",d.original.OrderNumber]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentNumber",header:"Document Number",cell:({row:d})=>d.original.DocumentNumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentDate",header:"Document Date",cell:({row:d})=>Ks(d.original.DocumentDate),enableSorting:!0,enableFiltering:!1},{accessorKey:"PONumber",header:"PO Number",cell:({row:d})=>d.original.PONumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseCode",header:"Warehouse",cell:({row:d})=>d.original.WarehouseCode??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"MPN",header:"MPN",cell:({row:d})=>d.original.MPN?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Product/${d.original.MPN}`,className:"font-medium text-primary hover:underline",children:d.original.MPN})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for MPN ",d.original.MPN]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:d})=>d.original.Quantity??"N/A",enableSorting:!0,enableFiltering:!1},{accessorKey:"ShipToName",header:"Name",cell:({row:d})=>e.jsx("div",{className:"min-w-[150px]",children:d.original.ShipToName??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:d})=>d.original.UnitPrice?de(d.original.UnitPrice):"N/A",enableSorting:!0,enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:d})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx(pi,{applicationId:s,randmarSku:d.original.RandmarSKU??"",buttonSize:"sm"})})}],[s]),i=o.useMemo(()=>{const d={};if(t){const u=Array.from(new Set(t.map(x=>x.WarehouseCode).filter(x=>x!=null)));d.WarehouseCode=u;const m=Array.from(new Set(t.map(x=>x.ShipToName).filter(x=>x!=null)));d.ShipToName=m;const h=Array.from(new Set(t.map(x=>x.DocumentNumber).filter(x=>x!=null)));d.DocumentNumber=h;const c=Array.from(new Set(t.map(x=>x.OrderNumber).filter(x=>x!=null)));d.OrderNumber=c;const y=Array.from(new Set(t.map(x=>x.PONumber).filter(x=>x!=null)));d.PONumber=y;const p=Array.from(new Set(t.map(x=>x.MPN).filter(x=>x!=null)));d.MPN=p}return d},[t]),l=t||[];return a?e.jsxs(z,{className:"w-full",children:[e.jsxs(Y,{children:[" ",e.jsx(f,{className:"h-7 w-48"})," "]}),e.jsxs(G,{className:"space-y-4",children:[e.jsx(f,{className:"h-12 w-full rounded-md border"}),e.jsx(f,{className:"h-10 w-full rounded-md border"}),e.jsx(f,{className:"h-10 w-full rounded-md border"}),e.jsx(f,{className:"h-10 w-full rounded-md border"}),e.jsxs("div",{className:"flex items-center justify-between pt-4",children:[e.jsx(f,{className:"h-9 w-[130px]"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{className:"h-9 w-20"}),e.jsx(f,{className:"h-9 w-24"}),e.jsx(f,{className:"h-9 w-9"}),e.jsx(f,{className:"h-9 w-9"})]})]})]})]}):e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:r})}),e.jsx(G,{children:e.jsx(As,{columns:n,data:l,uniqueValues:i})})]})}function Nd({applicationId:s,receipts:t=null,loading:a=!1}){const r=o.useMemo(()=>[{accessorKey:"Location",header:"Location",cell:({row:l})=>l.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptDate",header:"Date",cell:({row:l})=>Ks(l.original.ReceiptDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptNumber",header:"Number",cell:({row:l})=>l.original.ReceiptNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Document/${l.original.ReceiptNumber}`,className:"font-medium text-primary hover:underline",children:l.original.ReceiptNumber})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for Receipt ",l.original.ReceiptNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:l})=>l.original.Quantity??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:l})=>l.original.UnitPrice?de(l.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0}],[]),n=o.useMemo(()=>{const l={};if(t){const d=Array.from(new Set(t.map(m=>m.Location).filter(m=>m!=null)));l.Location=d;const u=Array.from(new Set(t.map(m=>Ks(m.ReceiptDate)).filter(m=>m!=="—"&&m!=="Invalid Date"))).sort((m,h)=>new Date(h).getTime()-new Date(m).getTime());l.ReceiptDate=u}return l},[t]),i=t||[];return e.jsx(As,{columns:r,data:i,uniqueValues:n,loading:a,tableClass:"bg-card text-card-foreground",initialSort:[{id:"ReceiptDate",desc:!0}]})}const ha=s=>{if(!s)return"N/A";try{const t=new Date(s);return isNaN(t.getTime())?"Invalid Date":t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}},vd=s=>{const t=s?.toLowerCase()||"";return t.includes("accepted")?"success":t.includes("error")||t.includes("rejected")?"destructive":"neutral"};function Ci({applicationId:s,returns:t=null,loading:a=!1}){const r=o.useMemo(()=>[{accessorKey:"ReturnNumber1",header:"RMA Number",cell:({row:l})=>{const d=l.original.ReturnNumber1||l.original.ReturnNumber;return d?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Return/${d}`,className:"font-medium text-primary hover:underline",children:d})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for return ",d]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestDate",header:"Request Date",cell:({row:l})=>ha(l.original.RequestDate),enableSorting:!0},{accessorKey:"InvoiceNumber",header:"Invoice Number",cell:({row:l})=>{const d=l.original.InvoiceNumber;return d?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Document/${d}`,className:"text-primary hover:underline",children:d})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for invoice ",d]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:l})=>l.original.Quantity??"0",enableSorting:!0},{accessorKey:"ReasonForReturn",header:"Return Reason",cell:({row:l})=>e.jsx("div",{className:"min-w-[150px]",children:l.original.ReasonForReturn??"—"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"Status",header:"Status",cell:({row:l})=>{const d=l.original.Status,u=vd(d),m=u==="success"?"success":u==="destructive"?"destructive":"secondary";return d?e.jsx(fe,{variant:m,className:"font-medium",children:d}):"—"},enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseLocation",header:"Warehouse",cell:({row:l})=>l.original.WarehouseLocation??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"LastUpdatedDate",header:"Last Update",cell:({row:l})=>ha(l.original.LastUpdatedDate)!=="N/A"?ha(l.original.LastUpdatedDate):"—",enableSorting:!0}],[s]),n=o.useMemo(()=>{const l={};if(t){const d=Array.from(new Set(t.map(h=>h.Status).filter(Boolean)));l.Status=d;const u=Array.from(new Set(t.map(h=>h.ReasonForReturn).filter(Boolean)));l.ReasonForReturn=u;const m=Array.from(new Set(t.map(h=>h.WarehouseLocation).filter(Boolean)));l.WarehouseLocation=m}return l},[t]),i=o.useMemo(()=>t?[...t].sort((d,u)=>(u.ReturnNumber1||u.ReturnNumber||"").localeCompare(d.ReturnNumber1||d.ReturnNumber||"")):[],[t]);return a?e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(f,{className:"h-7 w-48"})}),e.jsxs(G,{className:"space-y-4",children:[e.jsx(f,{className:"h-12 w-full rounded-md border"}),e.jsx(f,{className:"h-48 w-full rounded-md border"}),e.jsxs("div",{className:"flex items-center justify-between pt-4",children:[e.jsx(f,{className:"h-9 w-[130px]"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{className:"h-9 w-20"}),e.jsx(f,{className:"h-9 w-24"}),e.jsx(f,{className:"h-9 w-9"}),e.jsx(f,{className:"h-9 w-9"})]})]})]})]}):e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-xl font-semibold text-foreground",children:"Returns"})}),e.jsx(G,{children:e.jsx(As,{columns:r,data:i,uniqueValues:n})})]})}function wd({applicationId:s,purchaseOrders:t=null,loading:a=!1,readOnly:r=!1,linkTarget:n="_self"}){const[i,l]=o.useState([]),[d]=_.usePostV4ManufacturerByRouteManufacturerIdPurchaseOrderAndPurchaseOrderNumberEditItemRandmarSkuMutation(),{toast:u}=Ce();o.useEffect(()=>{l(t||[])},[t]);const m=o.useMemo(()=>[{accessorKey:"PurchaseOrderNumber",header:"Number",cell:({row:c})=>c.original.PurchaseOrderNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Document/${c.original.PurchaseOrderNumber}`,target:n,rel:n==="_blank"?"noopener noreferrer":void 0,className:"font-medium text-primary hover:underline",children:c.original.PurchaseOrderNumber})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for Purchase Order ",c.original.PurchaseOrderNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PurchaseOrderDate",header:"Date",cell:({row:c})=>Ks(c.original.PurchaseOrderDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:c})=>c.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PartNumber",header:"Part Number",cell:({row:c})=>c.original.MPN?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Product/${c.original.RandmarSKU}`,className:"font-medium text-primary hover:underline",children:c.original.MPN})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for Product ",c.original.RandmarSKU]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:c})=>c.original.QuantityOrdered??0,enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:c})=>c.original.UnitPrice?de(c.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0},...r?[]:[{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:y}){const[p,x]=o.useState(!1),w=y.original,N=()=>{x(!0),d({routeManufacturerId:s,purchaseOrderNumber:w.PurchaseOrderNumber??"",randmarSku:w.RandmarSKU??"",quantity:0}).then(()=>{l(j=>j.filter(b=>!(b.PurchaseOrderNumber===b.PurchaseOrderNumber&&b.MPN===b.MPN))),u({variant:"success",title:"Success",description:`Part ${w.MPN} has been successfully deleted from Purchase Order ${w.PurchaseOrderNumber}.`})}).catch(j=>{console.error(j),x(!0),u({variant:"destructive",title:"Error",description:"Something went wrong!"})})};return e.jsx("div",{className:"text-right",children:e.jsxs(dr,{children:[e.jsx(ur,{asChild:!0,children:e.jsx(D,{variant:"red",size:"sm",disabled:p,children:p?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting"]}):e.jsxs(e.Fragment,{children:[e.jsx(g.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})}),e.jsxs(Gt,{children:[e.jsxs(Wt,{children:[e.jsx(Yt,{children:"Confirmation"}),e.jsxs(Jt,{children:["Are you sure you want to delete part ",e.jsx("strong",{children:w.MPN})," from Purchase Order ",e.jsx("strong",{children:w.PurchaseOrderNumber}),"?."]})]}),e.jsxs(Kt,{children:[e.jsx(Xt,{disabled:p,children:"Cancel"}),e.jsxs(Zt,{onClick:N,disabled:p,children:[p&&e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}]],[s,d,n,r,u]),h=o.useMemo(()=>{const c={};return i&&(c.PurchaseOrderNumber=Array.from(new Set(i.map(y=>y.PurchaseOrderNumber).filter(y=>y!=null))),c.PurchaseOrderDate=Array.from(new Set(i.map(y=>y.PurchaseOrderDate).filter(y=>y!=null).map(String))),c.Location=Array.from(new Set(i.map(y=>y.Location).filter(y=>y!=null))),c.PartNumber=Array.from(new Set(i.map(y=>y.MPN).filter(y=>y!=null))),c.QuantityOrdered=Array.from(new Set(i.map(y=>y.QuantityOrdered).filter(y=>y!=null).map(String))),c.UnitPrice=Array.from(new Set(i.map(y=>y.UnitPrice).filter(y=>y!=null).map(String)))),c},[i]);return e.jsx(As,{columns:m,data:i,uniqueValues:h,loading:a,tableClass:"bg-card text-card-foreground"})}function Sd({applicationId:s,requisitions:t=null,loading:a=!1}){const[r,n]=o.useState([]),[i]=_.useDeleteV4ManufacturerByRouteManufacturerIdRequisitionAndRequisitionNumberMutation(),{toast:l}=Ce();o.useEffect(()=>{n(t||[])},[t]);const d=o.useMemo(()=>[{accessorKey:"RequisitionNumber",header:"Number",cell:({row:m})=>m.original.RequisitionNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(ve.Link,{to:`/${s}/Document/${m.original.RequisitionNumber}`,className:"font-medium text-primary hover:underline",children:m.original.RequisitionNumber})}),e.jsx(pe,{children:e.jsxs("p",{children:["View details for Draft Purchase ",m.original.RequisitionNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequisitionDate",header:"Date",cell:({row:m})=>Ks(m.original.RequisitionDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:m})=>m.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:m})=>m.original.QuantityOrdered??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOutstanding",header:"Quantity Outstanding",cell:({row:m})=>m.original.QuantityOutstanding??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityReceived",header:"Quantity Received",cell:({row:m})=>m.original.QuantityReceived??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"SubTotal",header:"Sub Total",cell:({row:m})=>m.original.SubTotal?de(m.original.SubTotal):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestedBy",header:"Requestor",cell:({row:m})=>m.original.RequestedBy??"—",enableSorting:!0,enableFiltering:!0},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:h}){const[c,y]=o.useState(!1),p=h.original,x=()=>{y(!0),i({routeManufacturerId:s,requisitionNumber:p.RequisitionNumber??""}).then(()=>{n(w=>w.filter(N=>N.RequisitionNumber!==N.RequisitionNumber)),l({variant:"success",title:"Success",description:`Draft Purchase ${p.RequisitionNumber} has been successfully cancelled.`})}).catch(w=>{console.error(w),y(!0),l({variant:"destructive",title:"Error",description:"Something went wrong!"})})};return e.jsx("div",{className:"text-right",children:e.jsxs(dr,{children:[e.jsx(ur,{asChild:!0,children:e.jsx(D,{variant:"red",size:"sm",disabled:c,children:c?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancelling"]}):e.jsxs(e.Fragment,{children:[e.jsx(g.Trash2,{className:"mr-2 h-4 w-4"}),"Cancel"]})})}),e.jsxs(Gt,{children:[e.jsxs(Wt,{children:[e.jsx(Yt,{children:"Confirmation"}),e.jsxs(Jt,{children:["Are you sure you want to cancel Draft Purchase ",e.jsx("strong",{children:p.RequisitionNumber}),"?."]})]}),e.jsxs(Kt,{children:[e.jsx(Xt,{disabled:c,children:"Cancel"}),e.jsxs(Zt,{onClick:x,disabled:c,children:[c&&e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}],[s]),u=o.useMemo(()=>{const m={};return r&&(m.RequisitionNumber=Array.from(new Set(r.map(h=>h.RequisitionNumber).filter(h=>h!=null))),m.RequisitionDate=Array.from(new Set(r.map(h=>h.RequisitionDate).filter(h=>h!=null).map(String))),m.QuantityOrdered=Array.from(new Set(r.map(h=>h.QuantityOrdered).filter(h=>h!=null).map(String))),m.QuantityOutstanding=Array.from(new Set(r.map(h=>h.QuantityOutstanding).filter(h=>h!=null).map(String))),m.QuantityReceived=Array.from(new Set(r.map(h=>h.QuantityReceived).filter(h=>h!=null).map(String))),m.Location=Array.from(new Set(r.map(h=>h.Location).filter(h=>h!=null))),m.RequestedBy=Array.from(new Set(r.map(h=>h.RequestedBy).filter(h=>h!=null))),m.SubTotal=Array.from(new Set(r.map(h=>h.SubTotal).filter(h=>h!=null).map(String)))),m},[r]);return e.jsx(As,{columns:d,data:r,uniqueValues:u,loading:a,tableClass:"bg-card text-card-foreground"})}const Cd=new Intl.DateTimeFormat(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"});function Aa(s){if(!s)return null;const t=s.trim();if(!t)return null;if(/[zZ]$/.test(t)||/[+-]\d{2}:?\d{2}$/.test(t)){const j=new Date(t);return Number.isNaN(j.getTime())?null:j}const r=t.replace(" ","T"),[n,i]=r.split("T");if(!n)return null;const[l,d,u]=n.split("-"),m=Number.parseInt(l??"",10),h=Number.parseInt(d??"",10),c=Number.parseInt(u??"",10);if(!Number.isFinite(m)||!Number.isFinite(h)||!Number.isFinite(c))return null;let y=0,p=0,x=0,w=0;if(i){const j=i.trim(),[b,k,S]=j.split(":");if(y=Number.parseInt(b??"0",10),p=Number.parseInt(k??"0",10),S){const[M,A]=S.split(".");x=Number.parseInt(M??"0",10),A&&(w=Number.parseInt(A.slice(0,3).padEnd(3,"0"),10))}}if(!Number.isFinite(y)||!Number.isFinite(p)||!Number.isFinite(x)||!Number.isFinite(w))return null;const N=new Date(m,h-1,c,y,p,x,w);return Number.isNaN(N.getTime())||N.getFullYear()!==m||N.getMonth()!==h-1||N.getDate()!==c?null:N}function kd(s){const t=Aa(s);return t?Cd.format(t):"—"}function Rd({logs:s=null,loading:t=!1}){const a=o.useMemo(()=>[{accessorKey:"DateTime",header:"Date & Time",cell:({row:r})=>kd(r.original.DateTime),enableSorting:!0,enableFiltering:!1,sortingFn:(r,n,i)=>{const l=Aa(r.getValue(i)),d=Aa(n.getValue(i)),u=l?l.getTime():Number.NEGATIVE_INFINITY,m=d?d.getTime():Number.NEGATIVE_INFINITY;return u===m?0:u>m?1:-1}},{accessorKey:"Message",header:"Message",cell:({row:r})=>e.jsx("span",{className:"whitespace-pre-wrap break-words",children:r.original.Message??"—"}),enableSorting:!0,enableFiltering:!0}],[]);return e.jsx(As,{columns:a,data:s||[],uniqueValues:{},loading:t,tableClass:"bg-card text-card-foreground",initialSort:[{id:"DateTime",desc:!0}]})}function Pd({applicationId:s,sku:t,product:a,productDefaultOpportunityNumber:r="",productOnAddToCart:n,productAddingToCart:i=!1,productShopifyHostname:l,productCustomAction:d=e.jsx(e.Fragment,{}),purchaseOrdersReadOnly:u=!1,purchaseOrderLinkTarget:m="_self"}){const{data:h,isLoading:c}=_.useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:s,randmarSku:t??"",withSpecification:!1},{skip:!!a||!s||!t}),{data:y,isLoading:p}=_.useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:s,randmarSku:t??"",withSpecification:!0},{skip:!!a||!s||!t}),x=a??y??h,{data:w}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:s}),N=w?.IsManufacturer&&w?.BillingInformation?.CurrencyCode?.toUpperCase()==="USD",j=!w?.IsManufacturer&&!u||(x?.PurchaseOrders?.length??0)<=0&&(!w?.IsManufacturer||(x?.Requisitions?.length??0)<=0),[b,k]=o.useState("stats-tab"),[S,M]=o.useState(!1);o.useEffect(()=>{if(!a&&p){M(!1);return}const q={"stats-tab":(x?.SalesStatistics?.length??0)<=0,"inventory-tab":(x?.Distribution?.Inventory?.length??0)<=0,"opportunities-tab":(x?.Opportunities?.length??0)<=0,"active-orders-tab":(x?.ActiveOrderDetails?.length??0)<=0,"completed-orders-tab":(x?.CompletedOrderDetails?.length??0)<=0,"returns-tab":(x?.Returns?.length??0)<=0,"purchase-orders-tab":j,"warehouse-tab":(x?.Receipts?.length??0)<=0,"logs-tab":(x?.Logs?.length??0)<=0},W=Object.values(q).some(ne=>!ne);if(M(W),W&&q[b]){const ne=Object.keys(q).find(Pe=>!q[Pe]);ne&&k(ne)}},[p,x,a,b,j]);const A=!a&&(c||p),P=x?.Title||x?.RandmarTitle||x?.RandmarSKU||"Product",E=x?.VoiceoverCaption||"",T=typeof x?.MAP=="number"&&x.MAP>0?x.MAP:typeof x?.Distribution?.MAP=="number"&&x.Distribution.MAP>0?x.Distribution.MAP:null,I=typeof x?.MSRP=="number"&&x.MSRP>0?x.MSRP:typeof x?.Distribution?.MSRP=="number"&&x.Distribution.MSRP>0?x.Distribution.MSRP:null,B=r?x?.Opportunities?.find(q=>q.BidNumber===r)?.Price:null,F=typeof B=="number"&&B>0?B:typeof x?.Distribution?.Price=="number"&&x.Distribution.Price>0?x.Distribution.Price:null,U=A||typeof F=="number",V=typeof T=="number"&&typeof F=="number"?T-F:null,O=typeof V=="number"&&typeof T=="number"&&T>0?Math.round(V/T*100):null;return e.jsxs("div",{className:"@container",children:[e.jsxs("div",{className:"grid gap-4 grid-cols-1 @md:grid-cols-3",children:[e.jsxs(z,{className:"@md:col-span-2",children:[e.jsxs(Y,{className:"space-y-2",children:[e.jsx(me,{className:"text-2xl font-semibold leading-tight",children:A&&!x?e.jsx(f,{className:"h-7 w-2/3"}):P}),E?e.jsx("div",{className:"text-sm text-muted-foreground",children:E}):A&&!x?e.jsx(f,{className:"h-4 w-4/5"}):null]}),e.jsxs(G,{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[U?e.jsxs("div",{className:"flex flex-col gap-4 @sm:flex-row @sm:items-start @sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Your Price"}),e.jsx("div",{className:"mt-1 text-3xl font-semibold tracking-tight",children:typeof F=="number"?de(F):A?e.jsx(f,{className:"h-9 w-40"}):null})]}),typeof V=="number"&&typeof O=="number"?e.jsxs("div",{className:"flex flex-col items-start @sm:items-end",children:[e.jsxs(fe,{variant:V>=0?"success":"destructive",className:"rounded-full px-3 py-1.5 text-sm font-semibold",children:[V>=0?"Potential Profit":"Below MAP",": ",de(Math.abs(V))]}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:V>=0?`${O}% margin vs MAP`:`${Math.abs(O)}% under MAP`})]}):null]}):null,e.jsx(ye,{children:e.jsxs("div",{className:`${U?"mt-5":"mt-0"} grid grid-cols-1 gap-4 @sm:grid-cols-2`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-md border bg-background/50 p-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx("button",{type:"button",className:"cursor-help bg-transparent p-0 underline decoration-dotted underline-offset-4",children:"MAP"})}),e.jsx(pe,{children:"Minimum Advertised Price — the lowest price you can publicly advertise."})]})}),e.jsx("div",{className:"font-medium",children:typeof T=="number"?de(T):"—"})]}),typeof V=="number"&&typeof F=="number"&&typeof T=="number"?e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Profit vs MAP"}),e.jsxs("div",{className:"text-sm font-semibold",children:[de(T)," - ",de(F)," = ",de(V)]})]}):null]}),e.jsx("div",{className:"flex items-start justify-between gap-4 rounded-md border bg-background/50 p-3",children:e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx("button",{type:"button",className:"cursor-help bg-transparent p-0 underline decoration-dotted underline-offset-4",children:"MSRP"})}),e.jsx(pe,{children:"Manufacturer's Suggested Retail Price — a reference retail list price."})]})}),e.jsx("div",{className:"font-medium",children:typeof I=="number"?de(I):"—"})]})})]})})]}),x?.BodyHTML?e.jsx("div",{className:"prose prose-sm max-w-none leading-relaxed [&_p]:mb-4 [&_p:last-child]:mb-0",dangerouslySetInnerHTML:{__html:x.BodyHTML}}):e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx(g.Info,{className:"h-4 w-4 inline mr-2"}),"No product description available."]})]})]}),e.jsx("div",{className:"self-start @md:sticky @md:top-4",children:e.jsx(Vt,{applicationId:s,product:x,defaultOpportunityNumber:r,onAddToCart:n,addingToCart:i,shopifyHostname:l,customAction:d,showUsdLabelOnCost:N})})]}),e.jsx("div",{className:"my-4",children:c||p?e.jsx("div",{className:"mx-auto flex justify-center items-center h-32",children:e.jsx(g.Loader2,{className:"h-8 w-8 animate-spin text-primary"})}):S&&e.jsxs(Za,{value:b,onValueChange:k,children:[e.jsxs(qt,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[e.jsx(We,{value:"stats-tab",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",disabled:(x?.SalesStatistics?.length??0)<=0,children:"Statistics"}),e.jsx(We,{value:"inventory-tab",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",disabled:(x?.Distribution?.Inventory?.length??0)<=0,children:"Inventory"}),e.jsx(We,{value:"opportunities-tab",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",disabled:(x?.Opportunities?.length??0)<=0,children:"Opportunities"}),e.jsx(We,{value:"active-orders-tab",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",disabled:(x?.ActiveOrderDetails?.length??0)<=0,children:"Active Orders"}),e.jsx(We,{value:"completed-orders-tab",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",disabled:(x?.CompletedOrderDetails?.length??0)<=0,children:"Completed Orders"}),e.jsx(We,{value:"returns-tab",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",disabled:(x?.Returns?.length??0)<=0,children:"Returns"}),e.jsx(We,{value:"purchase-orders-tab",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",disabled:j,children:"Purchase Orders"}),e.jsx(We,{value:"warehouse-tab",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",disabled:(x?.Receipts?.length??0)<=0,children:"Latest Warehouse Receiving"}),e.jsx(We,{value:"logs-tab",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",disabled:(x?.Logs?.length??0)<=0,children:"Logs"})]}),e.jsx(Ze,{value:"stats-tab",children:e.jsx("div",{className:"mt-4",children:e.jsx(Xa,{statistics:x?.SalesStatistics??[],loading:p})})}),e.jsx(Ze,{value:"inventory-tab",children:e.jsx("div",{className:"mt-4",children:e.jsx(Ta,{inventory:x?.Distribution?.Inventory??[],className:"bg-card text-card-foreground"})})}),e.jsx(Ze,{value:"opportunities-tab",children:e.jsx("div",{className:"mt-4",children:e.jsx(mr,{applicationId:s,opportunities:x?.Opportunities,loading:p})})}),e.jsx(Ze,{value:"active-orders-tab",children:(x?.ActiveOrderDetails?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Pa,{applicationId:s,title:"Active Orders",orders:x?.ActiveOrderDetails,loading:p})})}),e.jsx(Ze,{value:"completed-orders-tab",children:(x?.CompletedOrderDetails?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Pa,{applicationId:s,title:"Completed Orders",orders:x?.CompletedOrderDetails,loading:p})})}),e.jsx(Ze,{value:"returns-tab",children:(x?.Returns?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Ci,{applicationId:s,returns:x?.Returns,loading:p})})}),e.jsxs(Ze,{value:"purchase-orders-tab",children:[(x?.PurchaseOrders?.length??0)>0&&e.jsxs(z,{className:"mt-4 w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Purchase Orders"})}),e.jsx(G,{children:e.jsx(wd,{applicationId:s,purchaseOrders:x?.PurchaseOrders,loading:p,readOnly:u,linkTarget:m})})]}),(x?.Requisitions?.length??0)>0&&e.jsxs(z,{className:"mt-4 w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Draft Purchases"})}),e.jsx(G,{children:e.jsx(Sd,{applicationId:s,requisitions:x?.Requisitions,loading:p})})]})]}),e.jsx(Ze,{value:"warehouse-tab",children:(x?.Receipts?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsxs(z,{className:"mt-4 w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Receipts"})}),e.jsx(G,{children:e.jsx(Nd,{applicationId:s,receipts:x?.Receipts,loading:p})})]})})}),e.jsx(Ze,{value:"logs-tab",children:(x?.Logs?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsxs(z,{className:"w-full",children:[e.jsx(Y,{children:e.jsx(me,{className:"text-1xl font-bold",children:"Logs"})}),e.jsx(G,{children:e.jsx(Rd,{logs:x?.Logs,loading:p})})]})})})]})})]})}const ht={base:{1:"grid-cols-1",2:"grid-cols-2",3:"grid-cols-3",4:"grid-cols-4",5:"grid-cols-5",6:"grid-cols-6"},sm:{1:"sm:grid-cols-1",2:"sm:grid-cols-2",3:"sm:grid-cols-3",4:"sm:grid-cols-4",5:"sm:grid-cols-5",6:"sm:grid-cols-6"},md:{1:"md:grid-cols-1",2:"md:grid-cols-2",3:"md:grid-cols-3",4:"md:grid-cols-4",5:"md:grid-cols-5",6:"md:grid-cols-6"},lg:{1:"lg:grid-cols-1",2:"lg:grid-cols-2",3:"lg:grid-cols-3",4:"lg:grid-cols-4",5:"lg:grid-cols-5",6:"lg:grid-cols-6"},xl:{1:"xl:grid-cols-1",2:"xl:grid-cols-2",3:"xl:grid-cols-3",4:"xl:grid-cols-4",5:"xl:grid-cols-5",6:"xl:grid-cols-6"}},Ad=s=>{const t={base:1,md:2,...s};return["grid","gap-4",t.base?ht.base[t.base]:"",t.sm?ht.sm[t.sm]:"",t.md?ht.md[t.md]:"",t.lg?ht.lg[t.lg]:"",t.xl?ht.xl[t.xl]:""].filter(Boolean).join(" ")},Id=({results:s,groupBy:t,renderItem:a})=>{const r=t(s);return e.jsx(e.Fragment,{children:Object.entries(r).map(([n,i])=>{const{items:l,gridCols:d}=i;if(l.length===0)return null;const u=Ad(d);return e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight mb-4",children:n}),e.jsx("div",{className:u,children:l.map((m,h)=>a(m,h))})]},n)})})},Dd=["Use fewer words or remove punctuation from your query.","Try a broader term, then narrow down with filters.","Check SKU, brand, or document IDs for typos."];function ki({query:s,subtitle:t="We could not find matches for this query. Try adjusting the terms or ask Assistant for help.",tips:a=Dd,onReloadSearch:r,onAssistantClick:n,reloadLabel:i="Reload Search",assistantLabel:l="Assistant",icon:d,className:u}){const h=`No Results "${s.trim()}"`,c=a.length>0;return e.jsxs(z,{className:v("w-full border-border bg-card",u),children:[e.jsxs(Y,{className:"space-y-3",children:[e.jsx("div",{className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-border bg-muted text-muted-foreground",children:d??e.jsx(g.SearchX,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(me,{className:"text-xl leading-tight",children:h}),e.jsx(rt,{children:t})]})]}),e.jsx(G,{className:"border-t border-border pt-4",children:c?e.jsx("ul",{className:"space-y-2 text-sm text-foreground",children:a.map((y,p)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"mt-2 h-1.5 w-1.5 shrink-0 rounded-full bg-muted-foreground","aria-hidden":"true"}),e.jsx("span",{children:y})]},`search-no-results-tip-${p}`))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Try adjusting your search and reload to continue."})}),e.jsx(ms,{className:"border-t border-border pt-4",children:e.jsxs("div",{className:"flex w-full flex-wrap justify-end gap-3",children:[e.jsx(D,{type:"button",variant:"outline",onClick:r,disabled:!r,children:i}),e.jsx(D,{type:"button",variant:"default",onClick:n,disabled:!n,children:l})]})})]})}function Md(s){const t=s?.trim();return t?`Search Results for "${t}"`:"Search Results"}function Td({query:s,title:t,subtitle:a,actions:r,children:n,className:i,contentClassName:l}){const d=r??n;return e.jsx("header",{className:v("w-full",i),children:e.jsx(z,{className:"rounded-2xl border-border shadow-sm",children:e.jsxs("div",{className:v("flex flex-col gap-4 p-6 lg:flex-row lg:items-start lg:justify-between",l),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold leading-tight tracking-tight text-foreground",children:t??Md(s)}),a?e.jsx("p",{className:"text-sm text-muted-foreground",children:a}):null]}),d?e.jsx("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-2",children:d}):null]})})})}function Ed(){return e.jsxs(z,{className:"h-full border-border bg-card",children:[e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx(f,{className:"h-5 w-3/5 bg-muted"}),e.jsx(f,{className:"h-4 w-full bg-muted"}),e.jsx(f,{className:"h-4 w-4/5 bg-muted"})]}),e.jsx("div",{className:"border-t border-border p-6 pt-4",children:e.jsx(f,{className:"h-9 w-24 bg-muted"})})]})}function Qr({cardCount:s}){return e.jsxs("section",{className:"space-y-4",children:[e.jsx(f,{className:"h-6 w-44 bg-muted"}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:Array.from({length:s??6}).map((t,a)=>e.jsx(Ed,{},`search-cards-skeleton-${a}`))})]})}function Hr({tableRows:s}){return e.jsxs("section",{className:"space-y-4",children:[e.jsx(f,{className:"h-6 w-56 bg-muted"}),e.jsx(z,{className:"border-border bg-card p-4 sm:p-6",children:e.jsxs("div",{className:"overflow-hidden rounded-md border border-border",children:[e.jsxs("div",{className:"grid grid-cols-12 gap-4 border-b border-border bg-muted/40 px-4 py-3",children:[e.jsx(f,{className:"col-span-4 h-4 w-3/4 bg-muted"}),e.jsx(f,{className:"col-span-3 h-4 w-2/3 bg-muted"}),e.jsx(f,{className:"col-span-3 h-4 w-2/3 bg-muted"}),e.jsx(f,{className:"col-span-2 h-4 w-full bg-muted"})]}),Array.from({length:s??6}).map((t,a)=>e.jsxs("div",{className:"grid grid-cols-12 gap-4 border-b border-border px-4 py-3 last:border-b-0",children:[e.jsx(f,{className:"col-span-4 h-4 w-11/12 bg-muted"}),e.jsx(f,{className:"col-span-3 h-4 w-4/5 bg-muted"}),e.jsx(f,{className:"col-span-3 h-4 w-3/5 bg-muted"}),e.jsx(f,{className:"col-span-2 h-4 w-full bg-muted"})]},`search-table-skeleton-row-${a}`))]})})]})}function Ri({variant:s="mixed",cardCount:t=6,tableRows:a=6,className:r}){return e.jsxs("div",{className:v("space-y-6",r),role:"status","aria-live":"polite",children:[s==="cards"?e.jsx(Qr,{cardCount:t}):null,s==="table"?e.jsx(Hr,{tableRows:a}):null,s==="mixed"?e.jsxs(e.Fragment,{children:[e.jsx(Qr,{cardCount:Math.max(3,Math.min(t,6))}),e.jsx(Hr,{tableRows:a})]}):null,e.jsx("span",{className:"sr-only",children:"Loading search results"})]})}const Od=({query:s,results:t,isLoading:a,header:r,loadingState:n,noResultsState:i,initialState:l,className:d,resultsContainerClassName:u,children:m})=>{const h=Array.isArray(t)?t:[],c=s.trim().length>0,y=h.length>0;let p;return y?p=e.jsx("div",{className:v("grid grid-cols-3 gap-8",u),children:e.jsx("div",{className:"col-span-3",children:m})}):a?p=n??e.jsx(Ri,{}):c?p=i??e.jsx(ki,{query:s}):p=l??null,!r&&!p?null:e.jsxs("div",{className:v("w-full space-y-6",d),children:[r,p]})},Ld=Fs.Root,Pi=R.forwardRef(({className:s,...t},a)=>e.jsx(Fs.Item,{ref:a,className:v("border-b",s),...t}));Pi.displayName="AccordionItem";const Ai=R.forwardRef(({className:s,children:t,...a},r)=>e.jsx(Fs.Header,{className:"flex",children:e.jsxs(Fs.Trigger,{ref:r,className:v("flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline text-left [&[data-state=open]>svg]:rotate-180",s),...a,children:[t,e.jsx(g.ChevronDown,{className:"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200"})]})}));Ai.displayName=Fs.Trigger.displayName;const Ii=R.forwardRef(({className:s,children:t,...a},r)=>e.jsx(Fs.Content,{ref:r,className:"overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...a,children:e.jsx("div",{className:v("pb-4 pt-0",s),children:t})}));Ii.displayName=Fs.Content.displayName;function Di({className:s,classNames:t,showOutsideDays:a=!0,captionLayout:r="label",buttonVariant:n="ghost",formatters:i,components:l,...d}){const u=ya.getDefaultClassNames();return e.jsx(ya.DayPicker,{showOutsideDays:a,className:v("bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,s),captionLayout:r,formatters:{formatMonthDropdown:m=>m.toLocaleString("default",{month:"short"}),...i},classNames:{root:v("w-fit",u.root),months:v("relative flex flex-col gap-4 md:flex-row",u.months),month:v("flex w-full flex-col gap-4",u.month),nav:v("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",u.nav),button_previous:v(Bs({variant:n}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",u.button_previous),button_next:v(Bs({variant:n}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",u.button_next),month_caption:v("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",u.month_caption),dropdowns:v("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",u.dropdowns),dropdown_root:v("has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",u.dropdown_root),dropdown:v("bg-popover absolute inset-0 opacity-0",u.dropdown),caption_label:v("select-none font-medium",r==="label"?"text-sm":"[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",u.caption_label),table:"w-full border-collapse",weekdays:v("flex",u.weekdays),weekday:v("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",u.weekday),week:v("mt-2 flex w-full",u.week),week_number_header:v("w-[--cell-size] select-none",u.week_number_header),week_number:v("text-muted-foreground select-none text-[0.8rem]",u.week_number),day:v("group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",u.day),range_start:v("bg-accent rounded-l-md",u.range_start),range_middle:v("rounded-none",u.range_middle),range_end:v("bg-accent rounded-r-md",u.range_end),today:v("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",u.today),outside:v("text-muted-foreground aria-selected:text-muted-foreground",u.outside),disabled:v("text-muted-foreground opacity-50",u.disabled),hidden:v("invisible",u.hidden),...t},components:{Root:({className:m,rootRef:h,...c})=>e.jsx("div",{"data-slot":"calendar",ref:h,className:v(m),...c}),Chevron:({className:m,orientation:h,...c})=>h==="left"?e.jsx(g.ChevronLeftIcon,{className:v("size-4",m),...c}):h==="right"?e.jsx(g.ChevronRightIcon,{className:v("size-4",m),...c}):e.jsx(g.ChevronDownIcon,{className:v("size-4",m),...c}),DayButton:Fd,WeekNumber:({children:m,...h})=>e.jsx("td",{...h,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:m})}),...l},...d})}function Fd({className:s,day:t,modifiers:a,...r}){const n=ya.getDefaultClassNames(),i=R.useRef(null);return R.useEffect(()=>{a.focused&&i.current?.focus()},[a.focused]),e.jsx(D,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":a.selected&&!a.range_start&&!a.range_end&&!a.range_middle,"data-range-start":a.range_start,"data-range-end":a.range_end,"data-range-middle":a.range_middle,className:v("data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-auto w-full min-w-[--cell-size] flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70",n.day,s),...r})}function Bd(s){return e.jsx(z,{className:"max-w-6xl",children:e.jsx(Ht,{className:"h-[40em]",userId:s.userId,userName:s.userName,initialPrompt:s.initialPrompt})})}function fa(s){if(!s||!Ia(s))return"";const t=s.getTimezoneOffset()*6e4;return new Date(s.getTime()-t).toISOString().split("T")[0]}function Ia(s){return s instanceof Date&&!Number.isNaN(s.getTime())}function Ot({date:s,onDateChange:t,label:a,id:r,className:n}){const[i,l]=R.useState(!1),[d,u]=R.useState(s),[m,h]=R.useState(fa(s));R.useEffect(()=>{h(fa(s)),Ia(s)&&u(s)},[s]);const c=p=>{const w=p.target.value.replace(/\D/g,"").slice(0,8);let N=w;if(w.length>4&&(N=`${w.slice(0,4)}-${w.slice(4)}`),w.length>6&&(N=`${w.slice(0,4)}-${w.slice(4,6)}-${w.slice(6)}`),h(N),w.length===8){const j=new Date(N),b=new Date(j.getUTCFullYear(),j.getUTCMonth(),j.getUTCDate());Ia(b)?(t(b),u(b)):t(void 0)}else t(void 0)},y=p=>{p&&(t(p),h(fa(p))),l(!1)};return e.jsxs("div",{className:v("flex flex-col gap-2",n),children:[a&&e.jsx(J,{htmlFor:r,children:a}),e.jsxs("div",{className:"relative",children:[e.jsx(le,{id:r,value:m,placeholder:"YYYY-MM-DD",className:"bg-background pr-10",onChange:c,onKeyDown:p=>{p.key==="ArrowDown"&&(p.preventDefault(),l(!0))}}),e.jsxs(wt,{open:i,onOpenChange:l,children:[e.jsx(St,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 h-7 w-7 -translate-y-1/2","aria-label":"Select date",children:e.jsx(g.CalendarIcon,{className:"h-4 w-4"})})}),e.jsx(it,{className:"w-auto min-w-[280px] p-0",align:"end",sideOffset:8,children:e.jsx(Di,{mode:"single",selected:s,onSelect:y,month:d,onMonthChange:u,initialFocus:!0,className:"w-full"})})]})]})]})}function $d({product:s,viewProductLink:t}){return s?e.jsx(z,{className:"@container border-dashed border-2 hover:shadow-md transition-shadow h-full",children:e.jsxs(G,{className:"p-6 flex flex-col h-full",children:[e.jsxs("div",{className:"flex justify-between items-start mb-4 @[36rem]:hidden",children:[e.jsx("h3",{className:"font-semibold text-lg pr-4 text-center w-full",children:s.Title||s.RandmarTitle}),e.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:e.jsx(us,{id:s.ManufacturerId,name:s.ManufacturerName,width:96,height:40})})]}),e.jsxs("div",{className:"flex flex-col gap-x-6 gap-y-4 flex-grow @[36rem]:flex-row",children:[e.jsx("div",{className:"mx-auto flex-shrink-0 @[36rem]:mx-0 @[36rem]:w-48",children:e.jsx(fi,{randmarSKU:s.RandmarSKU||"",alt:s.RandmarTitle||"",fallback:e.jsx(cr,{randmarSKU:s.RandmarSKU||"",alt:s.RandmarTitle||"",sceneName:s.SceneName})})}),e.jsxs("div",{className:"flex flex-1 flex-col text-center @[36rem]:text-left",children:[e.jsxs("div",{className:"hidden @[36rem]:flex justify-between items-start mb-4",children:[e.jsx("h3",{className:"font-semibold text-lg pr-4",children:s.Title||s.RandmarTitle}),e.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:e.jsx(us,{id:s.ManufacturerId,name:s.ManufacturerName,width:96,height:40})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @[36rem]:hidden",children:[e.jsxs(fe,{variant:"outline",className:"border-info/40 bg-info/10 text-info",children:[e.jsx(g.LucideTelescope,{className:"mr-2 h-3 w-3"}),e.jsx("span",{children:"External Product"})]}),e.jsxs(fe,{variant:"outline",className:"border-primary/40 bg-primary/10 text-primary",children:[e.jsx(g.LucideWarehouse,{className:"mr-2 h-3 w-3"}),e.jsxs("span",{children:["Held by ",e.jsx("b",{children:"Randmar"})]})]})]}),e.jsxs("div",{className:"hidden @[36rem]:grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center rounded-md bg-info/10 px-4 py-2 text-info border border-info text-sm",children:[e.jsx(g.LucideTelescope,{className:"mr-2 h-5 w-5 flex-shrink-0"}),e.jsx("span",{children:"External Product"})]}),e.jsxs("div",{className:"flex items-center rounded-md bg-primary/10 px-4 py-2 text-primary border border-primary text-sm",children:[e.jsx(g.LucideWarehouse,{className:"mr-2 h-5 w-5 flex-shrink-0"}),e.jsxs("span",{children:["Held by ",e.jsx("b",{children:"Randmar"})]})]})]}),t&&e.jsx("div",{className:"mt-auto pt-4 flex justify-center @[36rem]:justify-end",children:e.jsx(ve.Link,{to:t,children:e.jsxs(D,{variant:"secondary",className:"w-full @[36rem]:w-auto",children:[e.jsx(g.LucideEye,{className:"mr-2 h-4 w-4"}),"View Product"]})})})]})]})]})}):e.jsx(z,{className:"@container border-dashed border-2 h-full",children:e.jsx(G,{className:"p-6 flex flex-col h-full",children:e.jsxs("div",{className:"flex flex-col gap-6 flex-grow @[36rem]:flex-row",children:[e.jsx("div",{className:"flex-shrink-0 @[36rem]:w-48",children:e.jsx(f,{className:"aspect-square w-full h-auto"})}),e.jsxs("div",{className:"flex flex-1 flex-col gap-4",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsx(f,{className:"h-10 w-1/2"}),e.jsx(f,{className:"h-10 w-24 rounded"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @[36rem]:hidden",children:[e.jsx(f,{className:"h-6 w-36 rounded-full"}),e.jsx(f,{className:"h-6 w-36 rounded-full"})]}),e.jsxs("div",{className:"hidden @[36rem]:grid grid-cols-2 gap-2",children:[e.jsx(f,{className:"h-10 w-full rounded-md"}),e.jsx(f,{className:"h-10 w-full rounded-md"})]})]}),e.jsx("div",{className:"mt-auto pt-4 flex justify-center @[36rem]:justify-end",children:e.jsx(f,{className:"h-10 w-full @[36rem]:w-40"})})]})]})})})}function _d(s){if(!s)return{text:"No End Date",variant:"neutral",daysRemaining:null};const t=new Date(s);if(isNaN(t.getTime()))return{text:"Invalid Date",variant:"neutral",daysRemaining:null};const a=new Date,r=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=new Date(a.getFullYear(),a.getMonth(),a.getDate()),i=r.getTime()-n.getTime(),l=Math.ceil(i/(1e3*60*60*24));return l<0?{text:`Ended ${Math.abs(l)}d ago`,variant:"destructive",daysRemaining:l}:l===0?{text:"Ends today",variant:"destructive",daysRemaining:l}:l<=7?{text:`Ends in ${l}d`,variant:"destructive",daysRemaining:l}:l<=30?{text:`Ends in ${l}d`,variant:"warning",daysRemaining:l}:{text:`Ends in ${l}d`,variant:"neutral",daysRemaining:l}}const pa=s=>{if(!s)return"N/A";try{const t=new Date(s);return isNaN(t.getTime())?"Invalid Date":t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}};function mr({applicationId:s,opportunities:t=null,loading:a=!1}){const{toast:r}=Ce(),[n,i]=o.useState({}),[l,d]=o.useState(!1),[u,m]=o.useState(""),[h,c]=o.useState(null),{data:y}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:s},{skip:!s}),p=o.useCallback((P,E,T)=>{i(I=>({...I,[P]:{...I[P],[E]:T}}))},[]),[x]=_.usePutV4ResellerByRouteResellerIdOpportunityAndManufacturerIdDefaultMutation(),w=o.useCallback(async P=>{if(!y?.IsReseller)return;if(!P.BidNumber){r({title:"Error",description:"Bid Number is missing, cannot set default.",variant:"destructive"});return}const E=P.BidNumber;p(E,"isSettingDefault",!0),x({routeResellerId:s,manufacturerId:P.ManufacturerId??"",opportunityNumber:E}).unwrap().then(()=>{r({title:"Success",description:`Opportunity "${P.OpportunityName||P.Opportunity||E}" was successfully set as default.`,variant:"success"})}).catch(T=>{console.error("Set as default error:",T),r({title:"Error",description:T.data?.message||T.message||"An error occurred while setting this opportunity as default.",variant:"destructive"})}).finally(()=>{p(E,"isSettingDefault",!1)})},[s,x,r,p,y?.IsReseller]),[N]=_.usePostV4ResellerByRouteResellerIdOpportunityAndManufacturerIdBidNumberEmailMutation(),j=o.useCallback(P=>{if(y?.IsReseller){if(!P.BidNumber){r({title:"Error",description:"Bid Number is missing, cannot prepare report.",variant:"destructive"});return}c(P),m(""),d(!0)}},[r,y?.IsReseller]),b=o.useCallback(async()=>{if(!y?.IsReseller)return;if(!h||!h.BidNumber){r({title:"Error",description:"No opportunity selected or Bid Number is missing.",variant:"destructive"});return}if(!u.trim()||!/\S+@\S+\.\S+/.test(u)){r({title:"Validation Error",description:"Please enter a valid email address.",variant:"destructive"});return}const P=h.BidNumber;p(P,"isSendingReport",!0),N({routeResellerId:s,manufacturerId:h.ManufacturerId??"",bidNumber:P,emailAddress:u}).unwrap().then(()=>{r({title:"Success",description:`A report for "${h.OpportunityName||h.Opportunity||P}" was successfully sent to ${u}.`,variant:"success"}),d(!1)}).catch(E=>{console.error("Send report by email error:",E),r({title:"Error",description:E.data?.message||E.message||"An error occurred while sending the report by email.",variant:"destructive"})}).finally(()=>{p(P,"isSendingReport",!1),l||(c(null),m(""))})},[h,u,s,N,r,p,d]),k=o.useMemo(()=>[{accessorKey:"ManufacturerId",header:"Manuf.",cell:({row:P})=>e.jsx("div",{className:"w-20 h-8",children:e.jsx(us,{id:P.original.ManufacturerId,width:80,height:32})}),enableSorting:!0,enableFiltering:!0},{id:"opportunityDisplay",accessorFn:P=>P.OpportunityName||P.Opportunity,header:"Opportunity",cell:({getValue:P})=>e.jsx("div",{className:"min-w-[150px]",children:P()??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"BidNumber",header:"Bid Number",cell:({row:P})=>P.original.BidNumber??"N/A",enableSorting:!0,enableFiltering:!0},{id:"statusInfo",header:"Status",cell:({row:P})=>{const E=P.original,T=E.Active===!0,I=_d(E.EndDate),B=T?"success":"secondary",F=I.variant==="destructive"?"destructive":I.variant==="warning"?"warning":"secondary";return e.jsxs("div",{className:"flex items-center space-x-2 min-w-[200px]",children:[e.jsx(fe,{variant:B,className:"font-medium",children:T?"Active":"Inactive"}),E.EndDate&&e.jsx(fe,{variant:F,className:"font-medium",children:I.text}),e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0 data-[state=delayed-open]:bg-accent data-[state=instant-open]:bg-accent",children:e.jsx(g.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(pe,{side:"top",align:"center",className:"bg-popover text-popover-foreground p-2 rounded shadow-lg",children:e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Start:"})," ",pa(E.StartDate)]}),e.jsxs("p",{children:[e.jsx("strong",{children:"End:"})," ",pa(E.EndDate)]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Updated:"})," ",pa(E.LastUpdate)]})]})})]})})]})},enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:P})=>{const E=P.original;if(!E.BidNumber)return e.jsx("span",{className:"text-xs text-muted-foreground",children:"Actions unavailable"});const T=E.BidNumber,I=n[T]?.isSettingDefault,B=h?.BidNumber===T&&n[T]?.isSendingReport,F=I||B,U=E.CanBeSetAsDefault===!0,V=y?.IsManufacturer?`/${s}/Opportunity/${E.BidNumber}`:`/${s}/Opportunity/${E.ManufacturerId}/${E.BidNumber}`;return e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(ve.Link,{to:V,children:e.jsxs(D,{variant:"outline",size:"sm",className:"flex items-center",children:[e.jsx(g.Star,{className:"mr-2 h-4 w-4"})," View"]})}),y?.IsReseller&&e.jsxs(e.Fragment,{children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>w(E),disabled:F||!U,title:U?"Set as default":"This opportunity cannot be set as default",className:"flex items-center",children:[I?e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(g.Star,{className:"mr-2 h-4 w-4"})," Set Default"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>j(E),disabled:F,title:"Send report by email",className:"flex items-center",children:[B?e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(g.Send,{className:"mr-2 h-4 w-4"})," Send Report"]})]})]})}}],[n,w,j,h,y?.IsReseller,s]),S=o.useMemo(()=>{const P={};if(t){const E=Array.from(new Set(t.map(I=>I.ManufacturerId).filter(I=>I!=null)));P.ManufacturerId=E;const T=Array.from(new Set(t.map(I=>I.OpportunityName||I.Opportunity).filter(I=>I!=null)));P.opportunityDisplay=T}return P},[t]),M=t||[],A=h?.BidNumber?n[h.BidNumber]?.isSendingReport:!1;return a?e.jsxs(z,{className:"w-full",children:[e.jsxs(Y,{children:[" ",e.jsx(f,{className:"h-7 w-48"})," "]}),e.jsxs(G,{className:"space-y-4",children:[e.jsx(f,{className:"h-12 w-full rounded-md border"}),e.jsx(f,{className:"h-48 w-full rounded-md border"}),e.jsxs("div",{className:"flex items-center justify-between pt-4",children:[e.jsx(f,{className:"h-9 w-[130px]"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{className:"h-9 w-20"})," ",e.jsx(f,{className:"h-9 w-24"})," ",e.jsx(f,{className:"h-9 w-9"})," ",e.jsx(f,{className:"h-9 w-9"})]})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(z,{className:"w-full",children:[e.jsxs(Y,{children:[" ",e.jsx(me,{className:"text-1xl font-bold",children:"Opportunities"})," "]}),e.jsx(G,{children:e.jsx(As,{columns:k,data:M,uniqueValues:S})})]}),e.jsx(De,{open:l,onOpenChange:P=>{d(P),P||(c(null),m(""))},children:e.jsxs(Me,{className:"@sm:max-w-[425px]",children:[e.jsxs(Le,{children:[e.jsx($e,{children:"Send Opportunity Report"}),e.jsxs(_e,{children:["Enter the email address to send the report for opportunity: ",e.jsx("br",{}),e.jsx("span",{className:"font-semibold",children:h?.OpportunityName||h?.Opportunity||"N/A"}),h?.BidNumber&&e.jsxs("span",{className:"block text-sm text-muted-foreground",children:["Bid Number: ",h.BidNumber]})]})]}),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:u,onChange:P=>m(P.target.value),placeholder:"recipient@example.com",className:"col-span-3",disabled:A})]})}),e.jsxs(ze,{children:[e.jsx(D,{variant:"outline",onClick:()=>d(!1),disabled:A,children:"Cancel"}),e.jsxs(D,{type:"submit",onClick:b,disabled:A,children:[A&&e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"})," Send Report"]})]})]})})]})}function Vd(s){const t=s instanceof Date?new Date(s.getTime()):new Date(s);return Number.isNaN(t.getTime())?null:t}function zd(s){const t=s.getFullYear().toString(),a=(s.getMonth()+1).toString().padStart(2,"0"),r=s.getDate().toString().padStart(2,"0");return`${t}-${a}-${r}`}function Mi(s){const t=new Map;for(const a of s){const r=Vd(a.timestamp);if(!r)continue;const n=new Date(r.getFullYear(),r.getMonth(),r.getDate()),i=zd(n),l=t.get(i);if(l){l.entries.push({entry:a,timestamp:r});continue}t.set(i,{dayKey:i,day:n,entries:[{entry:a,timestamp:r}]})}return Array.from(t.values()).map(a=>({...a,entries:[...a.entries].sort((r,n)=>r.timestamp.getTime()-n.timestamp.getTime())})).sort((a,r)=>r.day.getTime()-a.day.getTime())}const Ud=new Intl.DateTimeFormat(void 0,{weekday:"long",month:"short",day:"numeric",year:"numeric"}),qd=new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit",second:"2-digit"});function Qd({entries:s,emptyStateText:t="No system log entries available.",className:a,formatDayLabel:r=i=>Ud.format(i),formatTimeLabel:n=i=>qd.format(i)}){const i=R.useMemo(()=>Mi(s),[s]);return i.length===0?e.jsx("p",{className:v("text-sm text-muted-foreground",a),children:t}):e.jsx("div",{className:v("space-y-6",a),children:i.map(l=>e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:r(l.day)}),e.jsx("div",{className:"space-y-2",children:l.entries.map((d,u)=>{const m=d.entry.id??`${l.dayKey}-${d.timestamp.getTime()}-${u}`;return e.jsxs("article",{className:"rounded-md border border-border bg-card p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:n(d.timestamp)}),e.jsx("pre",{className:"font-mono text-xs text-foreground whitespace-pre-wrap break-words",children:d.entry.payload})]},m)})})]},l.dayKey))})}function Hd(s){const t=s.match(/(\d+\.?\d*)\s*(\d+\.?\d*)%\s*(\d+\.?\d*)%/);return t?{h:parseFloat(t[1]),s:parseFloat(t[2]),l:parseFloat(t[3])}:null}function ga(s,t,a){a/=100;const r=t*Math.min(a,1-a)/100,n=i=>{const l=(i+s/30)%12,d=a-r*Math.max(Math.min(l-3,9-l,1),-1);return Math.round(255*d).toString(16).padStart(2,"0")};return`#${n(0)}${n(8)}${n(4)}`}const xr=R.forwardRef(({data:s,options:t,height:a="500px",className:r,loading:n,disableClick:i=!0,...l},d)=>{const u=R.useRef(null),[m,h]=R.useState(null);R.useEffect(()=>{if(!u.current)return;const p=u.current,x=()=>{const b=getComputedStyle(p).getPropertyValue("--primary").trim();if(b){const k=Hd(b);if(k){const{h:S,s:M,l:A}=k;h({minColor:ga(S,M,Math.min(100,A+50)),midColor:ga(S,M,Math.min(100,A+35)),maxColor:ga(S,M,Math.min(100,A+20))})}return!0}return!1};if(x())return;let w=0;const N=20,j=setInterval(()=>{(x()||w>=N)&&clearInterval(j),w++},100);return()=>{j&&clearInterval(j)}},[]);const c=R.useMemo(()=>{const p={headerHeight:0,fontSize:14,showScale:!1,isHtml:!0,backgroundColor:"transparent",generateTooltip:(x,w)=>{const N=s[x+1]?.[0];if(!N)return"";const j=de(w);return`<div class="p-2 bg-background text-foreground border rounded-md shadow-lg">
|
|
130
130
|
<strong>${N}</strong><br>Value: ${j}
|
|
131
|
-
</div>`}};return c&&(!t||!t.colorAxis)&&(g.minColor=c.minColor,g.midColor=c.midColor,g.maxColor=c.maxColor),{...g,...t}},[s,t,c]),f=R.useMemo(()=>i?[{eventName:"select",callback:({chartWrapper:b})=>{b.getChart().setSelection(null)}}]:void 0,[i]);return R.useImperativeHandle(d,()=>x.current,[]),n?e.jsx("div",{ref:x,className:v("w-full",r),style:{height:a},...l,children:e.jsx(h,{className:"h-full w-full"})}):!s||s.length<=2?e.jsx("div",{ref:x,className:v("w-full flex items-center justify-center text-muted-foreground",r),style:{height:a},...l,children:"No data available"}):e.jsx("div",{ref:x,className:v("w-full",r),style:{height:a},...l,children:e.jsx(yl.Chart,{chartType:"TreeMap",width:"100%",height:"100%",data:s,options:m,chartEvents:f,loader:e.jsx(h,{className:"h-full w-full"})})})});xr.displayName="Treemap";const Gd=({data:s,topPercent:t=80,title:a,loading:r,...n})=>{const i=R.useMemo(()=>{if(!s||s.length===0)return[["ID","Parent","Value"],["Root",null,0]];const d=[...s].sort((b,w)=>w.value-b.value),c=d.reduce((b,w)=>b+w.value,0)*(t/100),u=[["ID","Parent","Value"],["Root",null,0]],m=[],f=[];let g=0;for(const b of d)g<c?(m.push(b),g+=b.value):f.push(b);if(m.forEach(b=>{u.push([b.name,"Root",b.value])}),f.length>0){const b=`More... (${f.length} items)`;u.push([b,"Root",0]),f.forEach(w=>{u.push([w.name,b,w.value])})}return u},[s,t]),l=R.useMemo(()=>({title:a,maxDepth:1,backgroundColor:"transparent"}),[a]);return e.jsx(xr,{data:i,options:l,className:v("h-full",n.className),loading:r,disableClick:!1,...n})},ja=["central-theme","partner-theme","reseller-theme","manufacturer-theme","shopify-theme"],Wd={central:"central-theme",partner:"partner-theme",reseller:"reseller-theme",manufacturer:"manufacturer-theme",shopify:"shopify-theme"},Kd=10;function Ti(s,t,a=0){const r=s.trim();return!r||a>Kd||!r.includes("var(")?r:r.replace(/var\(\s*(--[\w-]+)\s*(?:,\s*([^)]+))?\)/g,(n,i,l)=>{const x=t.getPropertyValue(i).trim()||l?.trim()||"";return x?Ti(x,t,a+1):""}).trim()}function Yd(s){if(typeof document>"u")return null;const t=document.body??document.documentElement;if(!t)return null;const a=document.createElement("span");if(a.style.color="",a.style.color=s,!a.style.color)return null;a.style.position="absolute",a.style.pointerEvents="none",a.style.opacity="0",a.style.inset="-9999px",t.appendChild(a);const r=getComputedStyle(a).color.trim();return a.remove(),r||null}function ba(s){const t=getComputedStyle(s),a=t.getPropertyValue("--primary").trim();if(!a)return null;const r=Ti(a,t)||a;return Yd(r)}function Jd(){if(typeof document>"u")return null;const s=document.head;if(!s)return null;const t=Array.from(s.querySelectorAll('meta[name="theme-color"]')),a=t.length>0,[r,...n]=t;for(const l of n)l.remove();if(r)return{metaTag:r,existedBeforeEnsure:a};const i=document.createElement("meta");return i.setAttribute("name","theme-color"),s.appendChild(i),{metaTag:i,existedBeforeEnsure:a}}function Zd(s){if(!s)return"default";const t=s.toLowerCase();switch(t){case"default":case"central":case"partner":case"reseller":case"manufacturer":case"shopify":return t;default:return"default"}}function Xd({theme:s,applyTo:t="documentElement",children:a}){const r=o.useMemo(()=>Zd(s),[s]),n=o.useRef(null),i=o.useRef(null),l=o.useRef(!1),d=o.useRef(null),x=o.useRef(!1);return o.useEffect(()=>{if(typeof document>"u")return;const c=t==="body"?document.body??document.documentElement:document.documentElement??document.body;if(c){n.current||(n.current=ja.filter(u=>c.classList.contains(u)));for(const u of ja)c.classList.remove(u);return r!=="default"&&c.classList.add(Wd[r]),()=>{for(const u of ja)c.classList.remove(u);for(const u of n.current??[])c.classList.add(u)}}},[t,r]),o.useEffect(()=>{if(typeof document>"u")return;const c=t==="body"?document.body??document.documentElement:document.documentElement??document.body;if(!c)return;const u=Jd();if(!u)return;const{metaTag:m,existedBeforeEnsure:f}=u;i.current?i.current!==m&&(i.current=m):(i.current=m,l.current=!f,x.current=m.hasAttribute("content"),d.current=m.getAttribute("content"));const g=ba(c)??ba(document.documentElement)??ba(document.body??document.documentElement);g&&m.setAttribute("content",g)},[t,r]),o.useEffect(()=>()=>{if(typeof document>"u")return;const c=i.current;if(!(!c||!c.isConnected)){if(l.current){c.remove();return}x.current?c.setAttribute("content",d.current??""):c.removeAttribute("content")}},[]),a}exports.AIChatLayout=Ht;exports.Accordion=Ld;exports.AccordionContent=Ii;exports.AccordionItem=Pi;exports.AccordionTrigger=Ai;exports.ActiveOrdersCard=ri;exports.Alert=js;exports.AlertDescription=ys;exports.AlertDialog=dr;exports.AlertDialogAction=Zt;exports.AlertDialogCancel=Xt;exports.AlertDialogContent=Gt;exports.AlertDialogDescription=Jt;exports.AlertDialogFooter=Kt;exports.AlertDialogHeader=Wt;exports.AlertDialogTitle=Yt;exports.AlertDialogTrigger=ur;exports.AlertTitle=bs;exports.ApiImage=ci;exports.AreaChart=Bn;exports.AssistantChat=Bd;exports.Avatar=Nt;exports.AvatarFallback=_n;exports.AvatarFooter=Ll;exports.AvatarImage=$n;exports.Badge=fe;exports.Button=D;exports.Calendar=Di;exports.Card=U;exports.CardContent=G;exports.CardDescription=rt;exports.CardFooter=ms;exports.CardHeader=Y;exports.CardTitle=me;exports.ChatLayout=Wo;exports.ChatProvider=Wl;exports.Checkbox=Ps;exports.CheckboxCardList=ni;exports.Command=Qt;exports.CommandDialog=Cc;exports.CommandEmpty=ir;exports.CommandGroup=lr;exports.CommandInput=rr;exports.CommandItem=_t;exports.CommandList=nr;exports.CommandSeparator=ii;exports.CommandShortcut=li;exports.CountryFlag=oi;exports.DataRefreshAssistantCluster=dd;exports.DataTable=As;exports.DatePicker=Ot;exports.Dialog=Ie;exports.DialogClose=Sa;exports.DialogContent=De;exports.DialogDescription=_e;exports.DialogFooter=ze;exports.DialogHeader=Le;exports.DialogOverlay=Da;exports.DialogPortal=Kr;exports.DialogTitle=$e;exports.DialogTrigger=Ys;exports.DropdownMenu=Yr;exports.DropdownMenuCheckboxItem=en;exports.DropdownMenuContent=Ma;exports.DropdownMenuGroup=kl;exports.DropdownMenuItem=ft;exports.DropdownMenuLabel=tn;exports.DropdownMenuPortal=Rl;exports.DropdownMenuRadioGroup=Al;exports.DropdownMenuRadioItem=sn;exports.DropdownMenuSeparator=an;exports.DropdownMenuShortcut=rn;exports.DropdownMenuSub=Pl;exports.DropdownMenuSubContent=Xr;exports.DropdownMenuSubTrigger=Zr;exports.DropdownMenuTrigger=Jr;exports.ExploreManufacturers=Zl;exports.ExternalProductCard=$d;exports.GeneralDocumentCard=kc;exports.Input=ie;exports.InputOTP=vl;exports.InputOTPGroup=wl;exports.InputOTPSeparator=Cl;exports.InputOTPSlot=Sl;exports.Label=J;exports.Layout=mi;exports.ManufacturerCard=Zs;exports.ManufacturerGetStartedButton=or;exports.ManufacturerOverviewPage=Wn;exports.ManufacturerReorderingCard=xi;exports.MultiSelect=hi;exports.Navbar=ui;exports.OpportunitiesTable=mr;exports.OrdersCard=Pa;exports.PARTNER_PAGE_SHELL_CONTENT_CLASS_NAME=Si;exports.PARTNER_PAGE_SHELL_STACK_CLASS_NAME=wi;exports.PageHeader=fd;exports.PartnerActions=nn;exports.PartnerCard=Xn;exports.PartnerPageShell=pd;exports.PartnerRelationshipPage=mc;exports.Popover=wt;exports.PopoverAnchor=Uc;exports.PopoverContent=it;exports.PopoverTrigger=St;exports.PortalThemeProvider=Xd;exports.Preloader=Ao;exports.ProductCard=Vt;exports.ProductImage=cr;exports.ProductInventoryGrid=Ta;exports.ProductOverviewPage=Pd;exports.Progress=nt;exports.RadioGroup=Hs;exports.RadioGroupItem=xs;exports.RandmarApiConfigProvider=eo;exports.RefreshCluster=yi;exports.ResellerBillingOverviewCard=Zc;exports.ResellerCard=ei;exports.ResellerOverview=Zn;exports.ResellerQualificationsCard=ji;exports.ReturnsTable=Ci;exports.RichTextEditor=yd;exports.RmBodyZone=gd;exports.RmPageHeader=vi;exports.SalesChart=Vs;exports.SalesOverviewCard=td;exports.ScrollArea=hs;exports.ScrollBar=Ut;exports.SearchNoResultsCard=ki;exports.SearchPage=Od;exports.SearchPageGrid=Id;exports.SearchResultsHeader=Td;exports.SearchResultsSkeleton=Ri;exports.Select=ks;exports.SelectContent=gs;exports.SelectGroup=cc;exports.SelectItem=Xe;exports.SelectLabel=Yn;exports.SelectScrollDownButton=sr;exports.SelectScrollUpButton=er;exports.SelectTrigger=ps;exports.SelectValue=Rs;exports.Separator=yt;exports.Sheet=ln;exports.SheetClose=El;exports.SheetContent=Oa;exports.SheetDescription=mn;exports.SheetFooter=dn;exports.SheetHeader=cn;exports.SheetOverlay=Ea;exports.SheetPortal=on;exports.SheetTitle=un;exports.SheetTrigger=Tl;exports.Sidebar=Fa;exports.SidebarContent=Va;exports.SidebarFooter=_a;exports.SidebarGroup=bn;exports.SidebarGroupAction=Nn;exports.SidebarGroupContent=vn;exports.SidebarGroupLabel=yn;exports.SidebarHeader=$a;exports.SidebarInput=gn;exports.SidebarInset=pn;exports.SidebarMenu=za;exports.SidebarMenuAction=wn;exports.SidebarMenuBadge=Sn;exports.SidebarMenuButton=qa;exports.SidebarMenuItem=Ua;exports.SidebarMenuSkeleton=Cn;exports.SidebarMenuSub=kn;exports.SidebarMenuSubButton=Pn;exports.SidebarMenuSubItem=Rn;exports.SidebarProvider=La;exports.SidebarRail=fn;exports.SidebarSeparator=jn;exports.SidebarTrigger=Ba;exports.Skeleton=h;exports.SummaryOverviewCard=nd;exports.Switch=at;exports.SystemLogFeed=Qd;exports.Table=Lt;exports.TableBody=Bt;exports.TableCaption=ti;exports.TableCell=gt;exports.TableFooter=si;exports.TableHead=$t;exports.TableHeader=Ft;exports.TableRow=Es;exports.Tabs=Za;exports.TabsContent=Ze;exports.TabsList=qt;exports.TabsTrigger=We;exports.Textarea=fs;exports.Toast=Ha;exports.ToastAction=Ga;exports.ToastClose=Wa;exports.ToastDescription=Ya;exports.ToastProvider=An;exports.ToastTitle=Ka;exports.ToastViewport=Qa;exports.Toaster=Dn;exports.Tooltip=ge;exports.TooltipContent=pe;exports.TooltipProvider=ye;exports.TooltipTrigger=je;exports.TopPercentTreemap=Gd;exports.Topbar=ar;exports.Treemap=xr;exports.badgeVariants=Kn;exports.buildApiUrl=$s;exports.buttonVariants=Bs;exports.formatMoney=ce;exports.formatNumber=ls;exports.formatYYYYMMDDIntToDateString=Ks;exports.groupSystemLogEntries=Mi;exports.toast=In;exports.useApiOrigin=vt;exports.useChat=Js;exports.useIsMobile=xn;exports.useOptionalChat=Mn;exports.useRandmarApiConfig=Fn;exports.useSidebar=tt;exports.useToast=Ce;
|
|
131
|
+
</div>`}};return m&&(!t||!t.colorAxis)&&(p.minColor=m.minColor,p.midColor=m.midColor,p.maxColor=m.maxColor),{...p,...t}},[s,t,m]),y=R.useMemo(()=>i?[{eventName:"select",callback:({chartWrapper:x})=>{x.getChart().setSelection(null)}}]:void 0,[i]);return R.useImperativeHandle(d,()=>u.current,[]),n?e.jsx("div",{ref:u,className:v("w-full",r),style:{height:a},...l,children:e.jsx(f,{className:"h-full w-full"})}):!s||s.length<=2?e.jsx("div",{ref:u,className:v("w-full flex items-center justify-center text-muted-foreground",r),style:{height:a},...l,children:"No data available"}):e.jsx("div",{ref:u,className:v("w-full",r),style:{height:a},...l,children:e.jsx(yl.Chart,{chartType:"TreeMap",width:"100%",height:"100%",data:s,options:c,chartEvents:y,loader:e.jsx(f,{className:"h-full w-full"})})})});xr.displayName="Treemap";const Gd=({data:s,topPercent:t=80,title:a,loading:r,...n})=>{const i=R.useMemo(()=>{if(!s||s.length===0)return[["ID","Parent","Value"],["Root",null,0]];const d=[...s].sort((x,w)=>w.value-x.value),m=d.reduce((x,w)=>x+w.value,0)*(t/100),h=[["ID","Parent","Value"],["Root",null,0]],c=[],y=[];let p=0;for(const x of d)p<m?(c.push(x),p+=x.value):y.push(x);if(c.forEach(x=>{h.push([x.name,"Root",x.value])}),y.length>0){const x=`More... (${y.length} items)`;h.push([x,"Root",0]),y.forEach(w=>{h.push([w.name,x,w.value])})}return h},[s,t]),l=R.useMemo(()=>({title:a,maxDepth:1,backgroundColor:"transparent"}),[a]);return e.jsx(xr,{data:i,options:l,className:v("h-full",n.className),loading:r,disableClick:!1,...n})},ja=["central-theme","partner-theme","reseller-theme","manufacturer-theme","shopify-theme"],Wd={central:"central-theme",partner:"partner-theme",reseller:"reseller-theme",manufacturer:"manufacturer-theme",shopify:"shopify-theme"},Kd=10;function Ti(s,t,a=0){const r=s.trim();return!r||a>Kd||!r.includes("var(")?r:r.replace(/var\(\s*(--[\w-]+)\s*(?:,\s*([^)]+))?\)/g,(n,i,l)=>{const u=t.getPropertyValue(i).trim()||l?.trim()||"";return u?Ti(u,t,a+1):""}).trim()}function Yd(s){if(typeof document>"u")return null;const t=document.body??document.documentElement;if(!t)return null;const a=document.createElement("span");if(a.style.color="",a.style.color=s,!a.style.color)return null;a.style.position="absolute",a.style.pointerEvents="none",a.style.opacity="0",a.style.inset="-9999px",t.appendChild(a);const r=getComputedStyle(a).color.trim();return a.remove(),r||null}function ba(s){const t=getComputedStyle(s),a=t.getPropertyValue("--primary").trim();if(!a)return null;const r=Ti(a,t)||a;return Yd(r)}function Jd(){if(typeof document>"u")return null;const s=document.head;if(!s)return null;const t=Array.from(s.querySelectorAll('meta[name="theme-color"]')),a=t.length>0,[r,...n]=t;for(const l of n)l.remove();if(r)return{metaTag:r,existedBeforeEnsure:a};const i=document.createElement("meta");return i.setAttribute("name","theme-color"),s.appendChild(i),{metaTag:i,existedBeforeEnsure:a}}function Zd(s){if(!s)return"default";const t=s.toLowerCase();switch(t){case"default":case"central":case"partner":case"reseller":case"manufacturer":case"shopify":return t;default:return"default"}}function Xd({theme:s,applyTo:t="documentElement",children:a}){const r=o.useMemo(()=>Zd(s),[s]),n=o.useRef(null),i=o.useRef(null),l=o.useRef(!1),d=o.useRef(null),u=o.useRef(!1);return o.useEffect(()=>{if(typeof document>"u")return;const m=t==="body"?document.body??document.documentElement:document.documentElement??document.body;if(m){n.current||(n.current=ja.filter(h=>m.classList.contains(h)));for(const h of ja)m.classList.remove(h);return r!=="default"&&m.classList.add(Wd[r]),()=>{for(const h of ja)m.classList.remove(h);for(const h of n.current??[])m.classList.add(h)}}},[t,r]),o.useEffect(()=>{if(typeof document>"u")return;const m=t==="body"?document.body??document.documentElement:document.documentElement??document.body;if(!m)return;const h=Jd();if(!h)return;const{metaTag:c,existedBeforeEnsure:y}=h;i.current?i.current!==c&&(i.current=c):(i.current=c,l.current=!y,u.current=c.hasAttribute("content"),d.current=c.getAttribute("content"));const p=ba(m)??ba(document.documentElement)??ba(document.body??document.documentElement);p&&c.setAttribute("content",p)},[t,r]),o.useEffect(()=>()=>{if(typeof document>"u")return;const m=i.current;if(!(!m||!m.isConnected)){if(l.current){m.remove();return}u.current?m.setAttribute("content",d.current??""):m.removeAttribute("content")}},[]),a}exports.AIChatLayout=Ht;exports.Accordion=Ld;exports.AccordionContent=Ii;exports.AccordionItem=Pi;exports.AccordionTrigger=Ai;exports.ActiveOrdersCard=ri;exports.Alert=js;exports.AlertDescription=ys;exports.AlertDialog=dr;exports.AlertDialogAction=Zt;exports.AlertDialogCancel=Xt;exports.AlertDialogContent=Gt;exports.AlertDialogDescription=Jt;exports.AlertDialogFooter=Kt;exports.AlertDialogHeader=Wt;exports.AlertDialogTitle=Yt;exports.AlertDialogTrigger=ur;exports.AlertTitle=bs;exports.ApiImage=ci;exports.AreaChart=Bn;exports.AssistantChat=Bd;exports.Avatar=Nt;exports.AvatarFallback=_n;exports.AvatarFooter=Ll;exports.AvatarImage=$n;exports.Badge=fe;exports.Button=D;exports.Calendar=Di;exports.Card=z;exports.CardContent=G;exports.CardDescription=rt;exports.CardFooter=ms;exports.CardHeader=Y;exports.CardTitle=me;exports.ChatLayout=Wo;exports.ChatProvider=Wl;exports.Checkbox=Ps;exports.CheckboxCardList=ni;exports.Command=Qt;exports.CommandDialog=Cc;exports.CommandEmpty=ir;exports.CommandGroup=lr;exports.CommandInput=rr;exports.CommandItem=_t;exports.CommandList=nr;exports.CommandSeparator=ii;exports.CommandShortcut=li;exports.CountryFlag=oi;exports.DataRefreshAssistantCluster=dd;exports.DataTable=As;exports.DatePicker=Ot;exports.Dialog=De;exports.DialogClose=Sa;exports.DialogContent=Me;exports.DialogDescription=_e;exports.DialogFooter=ze;exports.DialogHeader=Le;exports.DialogOverlay=Da;exports.DialogPortal=Kr;exports.DialogTitle=$e;exports.DialogTrigger=Ys;exports.DropdownMenu=Yr;exports.DropdownMenuCheckboxItem=en;exports.DropdownMenuContent=Ma;exports.DropdownMenuGroup=kl;exports.DropdownMenuItem=ft;exports.DropdownMenuLabel=tn;exports.DropdownMenuPortal=Rl;exports.DropdownMenuRadioGroup=Al;exports.DropdownMenuRadioItem=sn;exports.DropdownMenuSeparator=an;exports.DropdownMenuShortcut=rn;exports.DropdownMenuSub=Pl;exports.DropdownMenuSubContent=Xr;exports.DropdownMenuSubTrigger=Zr;exports.DropdownMenuTrigger=Jr;exports.ExploreManufacturers=Zl;exports.ExternalProductCard=$d;exports.GeneralDocumentCard=kc;exports.Input=le;exports.InputOTP=vl;exports.InputOTPGroup=wl;exports.InputOTPSeparator=Cl;exports.InputOTPSlot=Sl;exports.Label=J;exports.Layout=mi;exports.ManufacturerCard=Zs;exports.ManufacturerGetStartedButton=or;exports.ManufacturerOverviewPage=Wn;exports.ManufacturerReorderingCard=xi;exports.MultiSelect=hi;exports.Navbar=ui;exports.OpportunitiesTable=mr;exports.OrdersCard=Pa;exports.PARTNER_PAGE_SHELL_CONTENT_CLASS_NAME=Si;exports.PARTNER_PAGE_SHELL_STACK_CLASS_NAME=wi;exports.PageHeader=fd;exports.PartnerActions=nn;exports.PartnerCard=Xn;exports.PartnerPageShell=pd;exports.PartnerRelationshipPage=mc;exports.Popover=wt;exports.PopoverAnchor=Uc;exports.PopoverContent=it;exports.PopoverTrigger=St;exports.PortalThemeProvider=Xd;exports.Preloader=Ao;exports.ProductCard=Vt;exports.ProductImage=cr;exports.ProductInventoryGrid=Ta;exports.ProductOverviewPage=Pd;exports.Progress=nt;exports.RadioGroup=Hs;exports.RadioGroupItem=xs;exports.RandmarApiConfigProvider=eo;exports.RefreshCluster=yi;exports.ResellerBillingOverviewCard=Zc;exports.ResellerCard=ei;exports.ResellerOverview=Zn;exports.ResellerQualificationsCard=ji;exports.ReturnsTable=Ci;exports.RichTextEditor=yd;exports.RmBodyZone=gd;exports.RmPageHeader=vi;exports.SalesChart=Vs;exports.SalesOverviewCard=td;exports.ScrollArea=hs;exports.ScrollBar=Ut;exports.SearchNoResultsCard=ki;exports.SearchPage=Od;exports.SearchPageGrid=Id;exports.SearchResultsHeader=Td;exports.SearchResultsSkeleton=Ri;exports.Select=ks;exports.SelectContent=gs;exports.SelectGroup=cc;exports.SelectItem=Xe;exports.SelectLabel=Yn;exports.SelectScrollDownButton=sr;exports.SelectScrollUpButton=er;exports.SelectTrigger=ps;exports.SelectValue=Rs;exports.Separator=yt;exports.Sheet=ln;exports.SheetClose=El;exports.SheetContent=Oa;exports.SheetDescription=mn;exports.SheetFooter=dn;exports.SheetHeader=cn;exports.SheetOverlay=Ea;exports.SheetPortal=on;exports.SheetTitle=un;exports.SheetTrigger=Tl;exports.Sidebar=Fa;exports.SidebarContent=Va;exports.SidebarFooter=_a;exports.SidebarGroup=bn;exports.SidebarGroupAction=Nn;exports.SidebarGroupContent=vn;exports.SidebarGroupLabel=yn;exports.SidebarHeader=$a;exports.SidebarInput=gn;exports.SidebarInset=pn;exports.SidebarMenu=za;exports.SidebarMenuAction=wn;exports.SidebarMenuBadge=Sn;exports.SidebarMenuButton=qa;exports.SidebarMenuItem=Ua;exports.SidebarMenuSkeleton=Cn;exports.SidebarMenuSub=kn;exports.SidebarMenuSubButton=Pn;exports.SidebarMenuSubItem=Rn;exports.SidebarProvider=La;exports.SidebarRail=fn;exports.SidebarSeparator=jn;exports.SidebarTrigger=Ba;exports.Skeleton=f;exports.SummaryOverviewCard=nd;exports.Switch=at;exports.SystemLogFeed=Qd;exports.Table=Lt;exports.TableBody=Bt;exports.TableCaption=ti;exports.TableCell=gt;exports.TableFooter=si;exports.TableHead=$t;exports.TableHeader=Ft;exports.TableRow=Es;exports.Tabs=Za;exports.TabsContent=Ze;exports.TabsList=qt;exports.TabsTrigger=We;exports.Textarea=fs;exports.Toast=Ha;exports.ToastAction=Ga;exports.ToastClose=Wa;exports.ToastDescription=Ya;exports.ToastProvider=An;exports.ToastTitle=Ka;exports.ToastViewport=Qa;exports.Toaster=Dn;exports.Tooltip=ge;exports.TooltipContent=pe;exports.TooltipProvider=ye;exports.TooltipTrigger=je;exports.TopPercentTreemap=Gd;exports.Topbar=ar;exports.Treemap=xr;exports.badgeVariants=Kn;exports.buildApiUrl=$s;exports.buttonVariants=Bs;exports.formatMoney=de;exports.formatNumber=ls;exports.formatYYYYMMDDIntToDateString=Ks;exports.groupSystemLogEntries=Mi;exports.toast=In;exports.useApiOrigin=vt;exports.useChat=Js;exports.useIsMobile=xn;exports.useOptionalChat=Mn;exports.useRandmarApiConfig=Fn;exports.useSidebar=tt;exports.useToast=Ce;
|