randmarcomps 1.638.0 → 1.640.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.
@@ -0,0 +1,131 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),Xr=require("input-otp"),g=require("lucide-react"),Zi=require("clsx"),Xi=require("tailwind-merge"),el=require("@radix-ui/react-radio-group"),Fs=require("@radix-ui/react-dialog"),sl=require("@radix-ui/react-dropdown-menu"),st=require("@radix-ui/react-slot"),tt=require("class-variance-authority"),_=require("randmar-api-client"),tl=require("@radix-ui/react-label"),al=require("@radix-ui/react-tooltip"),rl=require("@radix-ui/react-separator"),nl=require("@radix-ui/react-toast"),Rs=require("recharts"),il=require("@lottiefiles/react-lottie-player"),ll=require("@radix-ui/react-avatar"),da=require("@microsoft/signalr"),ol=require("@radix-ui/react-scroll-area"),cl=require("@radix-ui/react-switch"),Lr=require("date-fns"),dl=require("marked"),ul=require("dompurify"),Ce=require("react-router-dom"),ml=require("@radix-ui/react-tabs"),Nt=require("react-hook-form"),us=require("react-intl"),xl=require("@radix-ui/react-progress"),hl=require("@radix-ui/react-select"),Ps=require("@tanstack/react-table"),fl=require("@radix-ui/react-checkbox"),rs=require("cmdk"),pl=require("js-md5"),gl=require("@radix-ui/react-popover"),jl=require("@radix-ui/react-alert-dialog"),Fr=require("@tiptap/react"),bl=require("@tiptap/starter-kit"),yl=require("@tiptap/extension-underline"),Nl=require("@radix-ui/react-accordion"),wa=require("react-day-picker"),vl=require("react-google-charts");function Qe(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 P=Qe(o),bt=Qe(el),ke=Qe(Fs),Ie=Qe(sl),wl=Qe(tl),Ks=Qe(al),en=Qe(rl),ns=Qe(nl),at=Qe(ll),Bs=Qe(ol),Sa=Qe(cl),Vs=Qe(ml),Ca=Qe(xl),Be=Qe(hl),ka=Qe(fl),Ys=Qe(gl),Ze=Qe(jl),$s=Qe(Nl);function v(...s){return Xi.twMerge(Zi.clsx(s))}const ds=(s,t)=>new Intl.NumberFormat("en-CA",t).format(s),oe=(s,t)=>{const a={style:"currency",currency:"CAD",minimumFractionDigits:2,maximumFractionDigits:2,...t};return new Intl.NumberFormat("en-CA",a).format(s)},Js=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 Sl({className:s,containerClassName:t,...a}){return e.jsx(Xr.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 Cl({className:s,...t}){return e.jsx("div",{"data-slot":"input-otp-group",className:v("flex items-center",s),...t})}function kl({index:s,className:t,...a}){const r=P.useContext(Xr.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 Rl({...s}){return e.jsx("div",{"data-slot":"input-otp-separator",role:"separator",...s,children:e.jsx(g.MinusIcon,{})})}const Ws=P.forwardRef(({className:s,...t},a)=>e.jsx(bt.Root,{className:v("grid gap-2",s),...t,ref:a}));Ws.displayName=bt.Root.displayName;const ps=P.forwardRef(({className:s,...t},a)=>e.jsx(bt.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(bt.Indicator,{className:"flex items-center justify-center",children:e.jsx(g.Circle,{className:"h-3.5 w-3.5 fill-primary"})})}));ps.displayName=bt.Item.displayName;const De=({modal:s=!1,...t})=>e.jsx(ke.Root,{modal:s,...t});De.displayName=ke.Root.displayName;const Zs=ke.Trigger,sn=ke.Portal,Ra=ke.Close,Ea=P.forwardRef(({className:s,...t},a)=>e.jsx(ke.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}));Ea.displayName=ke.Overlay.displayName;const Me=P.forwardRef(({className:s,children:t,animateExit:a=!0,overlayClassName:r,showOverlay:n,onPointerDownOutside:i,onInteractOutside:l,...u},x)=>{const d=!!(r&&n);return e.jsxs(sn,{forceMount:u.forceMount,children:[d?e.jsx(ke.Close,{asChild:!0,children:e.jsx("div",{"aria-hidden":"true",className:v("fixed inset-0 z-[10000] pointer-events-auto",r)})}):null,e.jsx(Ea,{className:r,forceMount:u.forceMount}),e.jsxs(ke.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:c=>{d&&c.preventDefault(),i?.(c)},onInteractOutside:c=>{d&&c.preventDefault(),l?.(c)},...u,children:[t,e.jsxs(ke.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=ke.Content.displayName;const $e=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-1.5 text-center sm:text-left",s),...t});$e.displayName="DialogHeader";const qe=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});qe.displayName="DialogFooter";const _e=P.forwardRef(({className:s,...t},a)=>e.jsx(ke.Title,{ref:a,className:v("text-lg font-semibold leading-none tracking-tight",s),...t}));_e.displayName=ke.Title.displayName;const ze=P.forwardRef(({className:s,...t},a)=>e.jsx(ke.Description,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));ze.displayName=ke.Description.displayName;const tn=Ie.Root,an=Ie.Trigger,Pl=Ie.Group,Al=Ie.Portal,Il=Ie.Sub,Dl=Ie.RadioGroup,rn=P.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"})]}));rn.displayName=Ie.SubTrigger.displayName;const nn=P.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}));nn.displayName=Ie.SubContent.displayName;const Oa=P.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})}));Oa.displayName=Ie.Content.displayName;const pt=P.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}));pt.displayName=Ie.Item.displayName;const ln=P.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]}));ln.displayName=Ie.CheckboxItem.displayName;const on=P.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]}));on.displayName=Ie.RadioItem.displayName;const cn=P.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}));cn.displayName=Ie.Label.displayName;const dn=P.forwardRef(({className:s,...t},a)=>e.jsx(Ie.Separator,{ref:a,className:v("-mx-1 my-1 h-px bg-muted",s),...t}));dn.displayName=Ie.Separator.displayName;const un=({className:s,...t})=>e.jsx("span",{className:v("ml-auto text-xs tracking-widest opacity-60",s),...t});un.displayName="DropdownMenuShortcut";const _s=tt.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"}}),E=P.forwardRef(({className:s,variant:t,size:a,asChild:r=!1,confirmationDialog:n,onClick:i,...l},u)=>{const x=r?st.Slot:"button";if(!n)return e.jsx(x,{className:v(_s({variant:t,size:a,className:s})),ref:u,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:d,content:c,onConfirm:m,confirmText:f="Confirm",cancelText:p="Cancel"}=n,N=()=>{m()};return e.jsxs(De,{children:[e.jsx(Zs,{asChild:!0,children:e.jsx(x,{className:v(_s({variant:t,size:a,className:s})),ref:u,...l})}),e.jsxs(Me,{children:[e.jsxs($e,{children:[e.jsx(_e,{children:d}),e.jsx(ze,{children:c})]}),e.jsxs(qe,{className:"flex justify-end gap-2 pt-4",children:[e.jsx(Ra,{asChild:!0,children:e.jsx(E,{variant:"outline",children:p})}),e.jsx(Ra,{asChild:!0,children:e.jsx(E,{onClick:N,children:f})})]})]})]})});E.displayName="Button";function Z({className:s,...t}){return e.jsx(wl.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=Ks.Provider,ge=Ks.Root,je=Ks.Trigger,fe=P.forwardRef(({className:s,sideOffset:t=4,...a},r)=>e.jsx(Ks.Portal,{children:e.jsx(Ks.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})}));fe.displayName=Ks.Content.displayName;const ne=P.forwardRef(({className:s,type:t,mask:a,onChange:r,placeholder:n,...i},l)=>{const[u,x]=P.useState(!1),d=P.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.":"",p=()=>{x(!0),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{x(!1)},3e3)};P.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);const N=w=>{if(a){const y=w.target.value;let j=y;if(y.length>0){const b=y[y.length-1];/[^a-zA-Z0-9]/.test(b)&&(console.log("Non-alphanumeric detected:",b),p())}if(a==="phone"){const b=y.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=y.replace(/[^a-zA-Z0-9]/g,"").toUpperCase();let C="";for(let S=0;S<Math.min(b.length,6);S++){const A=b[S];S===0||S===2||S===4?/[A-Z]/.test(A)&&(C+=A):(S===1||S===3||S===5)&&/[0-9]/.test(A)&&(C+=A)}C.length<=3?j=C:j=`${C.slice(0,3)} ${C.slice(3,6)}`}else if(a==="zip-code-us"){const b=y.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:u&&!!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:N,placeholder:m,ref:l,...i})}),e.jsx(fe,{side:"top",className:"bg-sidebar text-sidebar-foreground",children:f()})]})})});ne.displayName="Input";function mn(s){const{data:t,refetch:a,isFetching:r,isLoading:n}=_.useGetV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQuery({routeManufacturerId:s.userId,resellerId:s.partnerId,withSpecification:!1}),[i,l]=o.useState(!1),[u,x]=o.useState(!1),[d,c]=o.useState(!1),[m,f]=o.useState(!1),p=!t||n||r,N=t?.Qualifications?.some(w=>w.ManufacturerId===s.userId&&w.QualificationId!="Suspended"&&w.QualificationId!="Do Not Sell")??!1;return o.useEffect(()=>{if(u){f(!0);return}m&&(a(),f(!1))},[u,a,m]),e.jsxs(e.Fragment,{children:[e.jsxs(tn,{modal:!1,children:[e.jsx(an,{asChild:!0,children:e.jsx(E,{disabled:p,children:"Actions"})}),e.jsxs(Oa,{className:v("",s.className),children:[e.jsx(pt,{onClick:()=>setTimeout(()=>l(!0),200),children:"Sales Report"}),e.jsx(pt,{onClick:()=>setTimeout(()=>x(!0),200),children:"Qualification Status"}),e.jsx(pt,{disabled:!N,onClick:()=>setTimeout(()=>c(!0),200),children:"Add to Opportunity"})]})]}),e.jsx(Ml,{open:i,onOpenChange:l,manufacturerId:s.userId,resellerId:s.partnerId}),e.jsx(Tl,{isAdmin:s.isAdmin,open:u,onOpenChange:x,manufacturerId:s.userId,resellerId:s.partnerId}),e.jsx(El,{open:d,onOpenChange:c,manufacturerId:s.userId,resellerId:s.partnerId})]})}function Ml(s){const[t,a]=o.useState(""),[r,n]=o.useState(null),[i,l]=o.useState(null),{toast:u}=Pe(),[x,{isLoading:d}]=_.usePostV4ManufacturerByRouteManufacturerIdReportSalesAndResellerIdEmailMutation(),c=async()=>{if(!d)try{await x({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,emailAddress:t,startDate:r,endDate:i}).unwrap(),u({title:"Report Requested",description:"The sales report will be emailed within five minutes.",variant:"success"}),s.onOpenChange(!1)}catch{u({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($e,{children:[e.jsx(_e,{children:"Generate Sales Report"}),e.jsx(ze,{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(Z,{htmlFor:"email",children:"Email"}),e.jsx(ne,{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(Z,{htmlFor:"dateStart",children:"Start Date"}),e.jsx(ne,{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(Z,{htmlFor:"dateEnd",children:"End Date"}),e.jsx(ne,{type:"date",id:"dateEnd",value:i||"",onChange:m=>l(m.target.value)})]})]})]}),e.jsxs(qe,{children:[e.jsx(Fs.DialogClose,{asChild:!0,children:e.jsx(E,{variant:"outline",children:"Cancel"})}),e.jsx(E,{onClick:c,disabled:d,children:"Generate Report"})]})]})})})}function Tl(s){const{toast:t}=Pe(),[a,{isLoading:r}]=_.usePutV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQualificationMutation(),[n,{isLoading:i}]=_.useDeleteV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQualificationMutation(),[l,u]=o.useState("undefined"),[x,d]=o.useState("Qualified"),{data:c,isLoading:m}=_.useGetV4ManufacturerByRouteManufacturerIdResellerAndResellerIdQuery({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,withSpecification:!1});o.useEffect(()=>{if(!c||m)return;const p=c?.Qualifications?.find(N=>N.ManufacturerId===s.manufacturerId);switch(p?.QualificationId){case"Do Not Sell":u("do-not-sell");break;case"Suspended":s.isAdmin?u("do-not-sell"):u("suspended");break;case void 0:case null:u("undefined");break;default:u("qualified"),d(p?.QualificationId||"Qualified");break}},[c,m,s.manufacturerId]);const f=async()=>{if(!(r||i||m))try{let p=!1;if(l==="qualified")p=await a({routeManufacturerId:s.manufacturerId,resellerId:s.resellerId,newValue:x===""?"Qualified":x}).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($e,{children:[e.jsx(_e,{children:"Change qualification status"}),e.jsx(ze,{children:"Allow or restrict the sale of your products to this partner."})]}),e.jsxs(Ws,{value:l,onValueChange:u,className:"grid gap-4",disabled:r||i||m,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ps,{value:"undefined",id:"r1"}),e.jsx(Z,{htmlFor:"r1",children:"No Status Chosen Yet"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ps,{value:"qualified",id:"r2"}),e.jsx(Z,{htmlFor:"r2",children:"Qualified"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ps,{value:"do-not-sell",id:"r3"}),e.jsx(Z,{htmlFor:"r3",children:"Do Not Sell"})]}),s.isAdmin&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ps,{value:"suspended",id:"r4"}),e.jsx(Z,{htmlFor:"r4",children:"Suspended"})]})]}),e.jsx(Z,{className:"mt-4",htmlFor:"qualificationId",children:"Qualification ID"}),e.jsx(ne,{disabled:l!=="qualified",id:"qualificationId",value:x,onChange:p=>d(p.target.value)}),e.jsxs(qe,{children:[e.jsx(Fs.DialogClose,{asChild:!0,children:e.jsx(E,{variant:"outline",disabled:r||i,children:"Cancel"})}),e.jsx(E,{onClick:f,disabled:r||i||m,children:"Save"})]})]})})})}function El(s){const{toast:t}=Pe(),{data:a,isLoading:r}=_.useGetV4ManufacturerByRouteManufacturerIdOpportunitiesQuery({routeManufacturerId:s.manufacturerId}),n=Array.isArray(a)?a:[],[i,{isLoading:l}]=_.usePutV4ManufacturerByRouteManufacturerIdOpportunityAndBidNumberResellerResellerIdMutation(),[u,x]=o.useState(""),d=async()=>{if(!(l||r))try{if(!await i({routeManufacturerId:s.manufacturerId,bidNumber:u,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($e,{children:[e.jsx(_e,{children:"Add to Opportunity"}),e.jsx(ze,{children:"Let a reseller benefit from an opportunity."})]}),e.jsxs(As,{value:u,onValueChange:x,children:[e.jsx(ys,{children:e.jsx(Is,{placeholder:"Select an opportunity"})}),e.jsx(Ns,{children:n.map(c=>e.jsxs(as,{value:c.BidNumber||"",children:[e.jsx("b",{children:c.BidNumber})," | ",c.Opportunity]},"Opportunity"+c.BidNumber))})]}),e.jsxs(qe,{children:[e.jsx(Fs.DialogClose,{asChild:!0,children:e.jsx(E,{variant:"outline",disabled:l,children:"Cancel"})}),e.jsx(E,{onClick:d,disabled:l||r,children:"Confirm"})]})]})})})}function La({inventory:s,showBinLocation:t,className:a}){const r=(b,C,S=!1,A=!0)=>{const k=b.WarehouseType==="Fulfillment Center",D=k?"bg-background":"bg-background/70 text-muted-foreground",O=A&&C>0?"border-t":"",M=S?"border-r":"",I=b.Status??"Unknown",F=I==="Active";let Q="bg-secondary text-secondary-foreground ring-1 ring-border";switch(b.WarehouseType){case"Last Mile":Q="bg-info text-info-foreground ring-1 ring-info/40";break;case"First Mile":Q="bg-accent text-accent-foreground ring-1 ring-border";break}switch(I){case"Closing":Q="bg-warning text-warning-foreground ring-1 ring-warning/40";break;case"Closed":Q="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 ${O} ${M} ${D}`,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 ${Q}`,"aria-hidden":"false",title:F?k?"Fulfillment Center":"Satellite Warehouse":`Status: ${I}`,children:[k?e.jsx(g.Warehouse,{className:"h-3 w-3","aria-hidden":"true"}):e.jsx(g.Truck,{className:`h-3 w-3 ${F?"opacity-80":"opacity-95"}`,"aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:F?b.WarehouseType?`${b.WarehouseType} warehouse`:"Warehouse":`Status: ${I}`}),e.jsx("span",{"aria-hidden":"true",children:F?b.WarehouseType||(k?"Fulfillment Center":"Satellite"):I})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("div",{className:"text-sm font-medium",children:ds(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?ds(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=["MTL","TOR"],i=["VAN","EDM"],l=[...s].sort((b,C)=>(b.Name||"").localeCompare(C.Name||"")),u=l.filter(b=>b.Country==="US"),x=l.filter(b=>b.Country==="CA"),d=l.filter(b=>i.includes(b.WarehouseId||"")),c=l.filter(b=>n.includes(b.WarehouseId||"")),m=x.filter(b=>!n.includes(b.WarehouseId||"")&&!i.includes(b.WarehouseId||"")),f=b=>b.reduce((C,S)=>C+(S.AvailableQuantity||0),0),p=f(x),N=f(c),w=f(d),y=f(u),j=p+y;return e.jsxs("div",{className:`border rounded-md overflow-hidden ${a??""}`,children:[x.length>0&&u.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:ds(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:ds(w)})]}),d.map((b,C)=>r(b,C))]}),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:ds(N)})]}),c.map((b,C)=>r(b,C))]})]}),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((b,C)=>r(b,C,C%2===0,!0))})]})]}),u.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:ds(y)})]}),e.jsx("div",{className:"p-3"})]}),e.jsx("div",{className:"grid grid-cols-2",children:u.map((b,C)=>r(b,C,C%2===0,!0))})]}),s.length===0&&e.jsx("div",{className:"p-6 text-center text-muted-foreground",children:"No inventory information available"})]})}const vt=P.forwardRef(({className:s,orientation:t="horizontal",decorative:a=!0,...r},n)=>e.jsx(en.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}));vt.displayName=en.Root.displayName;const xn=ke.Root,Ol=ke.Trigger,Ll=ke.Close,hn=ke.Portal,Fa=P.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}));Fa.displayName=ke.Overlay.displayName;const Fl=tt.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"}}),Ba=P.forwardRef(({side:s="right",className:t,children:a,...r},n)=>e.jsxs(hn,{children:[e.jsx(Fa,{}),e.jsxs(ke.Content,{ref:n,className:v(Fl({side:s}),t),...r,children:[e.jsxs(ke.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]})]}));Ba.displayName=ke.Content.displayName;const fn=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-2 text-center sm:text-left",s),...t});fn.displayName="SheetHeader";const pn=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});pn.displayName="SheetFooter";const gn=P.forwardRef(({className:s,...t},a)=>e.jsx(ke.Title,{ref:a,className:v("text-lg font-semibold text-foreground",s),...t}));gn.displayName=ke.Title.displayName;const jn=P.forwardRef(({className:s,...t},a)=>e.jsx(ke.Description,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));jn.displayName=ke.Description.displayName;function Gt({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 u=new IntersectionObserver(([x])=>{const d=x.isIntersecting;r&&d?(i(!0),u.unobserve(l)):i(d)},{threshold:t,rootMargin:a});return u.observe(l),()=>{u.unobserve(l)}},[s,t,a,r]),n}const hs=({id:s,name:t,width:a=64,height:r=64,align:n="",className:i})=>{const l=o.useRef(null),u=Gt({elementRef:l,threshold:.1,rootMargin:"100px",freezeOnceVisible:!0}),{data:x,isFetching:d,isSuccess:c}=_.useGetV4PartnerByApplicationIdAccountLogoExistsQuery({applicationId:s??""},{skip:!s||!u}),{data:m,isFetching:f}=_.useGetV4PartnerByApplicationIdAccountLogoQuery({applicationId:s??"",width:a,height:r,align:n},{skip:!c||x!=!0}),p=t||(s?`Partner ID: ${s}`:"Logo not available (no ID)"),N=()=>!u||d||f?e.jsx(h,{className:"h-full w-full rounded-sm"}):m?e.jsx("img",{src:m,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:N()})}),e.jsx(fe,{side:"top",align:"center",children:p})]})})};function Bl({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(E,{asChild:!0,size:"icon",onClick:s,children:e.jsx("div",{className:"h-9 w-9 object-cover !bg-sidebar",children:e.jsx(hs,{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 ua=1024;function bn(){const[s,t]=P.useState(void 0);return P.useEffect(()=>{const a=window.matchMedia(`(max-width: ${ua-1}px)`),r=()=>{t(window.innerWidth<ua)};return a.addEventListener("change",r),t(window.innerWidth<ua),()=>a.removeEventListener("change",r)},[]),!!s}const yn=P.createContext(null);function rt(){const s=P.useContext(yn);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 $l="sidebar:state",_l=3600*24*7,Vl="16rem",zl="3rem",Ul="b",$a=P.forwardRef(({defaultOpen:s=!0,defaultOpenMobile:t=!1,isMobileOverride:a,open:r,onOpenChange:n,className:i,style:l,children:u,...x},d)=>{const c=bn(),m=a??c,[f,p]=P.useState(t),[N,w]=P.useState(s),y=r??N,j=P.useCallback(A=>{const k=typeof A=="function"?A(y):A;n?n(k):w(k),document.cookie=`${$l}=${k}; path=/; max-age=${_l}`},[n,y]),b=P.useCallback(()=>m?p(A=>!A):j(A=>!A),[m,j,p]);P.useEffect(()=>{const A=k=>{k.key===Ul&&(k.metaKey||k.ctrlKey)&&(k.preventDefault(),b())};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[b]);const C=y?"expanded":"collapsed",S=P.useMemo(()=>({state:C,open:y,setOpen:j,isMobile:m,openMobile:f,setOpenMobile:p,toggleSidebar:b}),[C,y,j,m,f,p,b]);return e.jsx(yn.Provider,{value:S,children:e.jsx(ye,{delayDuration:0,children:e.jsx("div",{style:{"--sidebar-width":Vl,"--sidebar-width-icon":zl,...l},className:v("group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",i),ref:d,...x,children:u})})})});$a.displayName="SidebarProvider";const _a=P.forwardRef(({side:s="left",variant:t="sidebar",collapsible:a="offcanvas",className:r,children:n,...i},l)=>{const{isMobile:u,state:x,openMobile:d,setOpenMobile:c}=rt();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}):u?e.jsx(xn,{open:d,onOpenChange:c,...i,children:e.jsx(Ba,{"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})})]})});_a.displayName="Sidebar";const Va=P.forwardRef(({className:s,onClick:t,...a},r)=>{const{toggleSidebar:n}=rt();return e.jsxs(E,{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"})]})});Va.displayName="SidebarTrigger";const Nn=P.forwardRef(({className:s,...t},a)=>{const{toggleSidebar:r}=rt();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})});Nn.displayName="SidebarRail";const vn=P.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}));vn.displayName="SidebarInset";const wn=P.forwardRef(({className:s,...t},a)=>e.jsx(ne,{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}));wn.displayName="SidebarInput";const za=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"header",className:v("flex flex-col gap-2 p-2",s),...t}));za.displayName="SidebarHeader";const Ua=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"footer",className:v("flex flex-col gap-2 p-2",s),...t}));Ua.displayName="SidebarFooter";const Sn=P.forwardRef(({className:s,...t},a)=>e.jsx(vt,{ref:a,"data-sidebar":"separator",className:v("mx-2 w-auto bg-sidebar-border",s),...t}));Sn.displayName="SidebarSeparator";const qa=P.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}));qa.displayName="SidebarContent";const Cn=P.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}));Cn.displayName="SidebarGroup";const kn=P.forwardRef(({className:s,asChild:t=!1,...a},r)=>{const n=t?st.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})});kn.displayName="SidebarGroupLabel";const Rn=P.forwardRef(({className:s,asChild:t=!1,...a},r)=>{const n=t?st.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})});Rn.displayName="SidebarGroupAction";const Pn=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,"data-sidebar":"group-content",className:v("w-full text-sm",s),...t}));Pn.displayName="SidebarGroupContent";const Qa=P.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}));Qa.displayName="SidebarMenu";const Ha=P.forwardRef(({className:s,...t},a)=>e.jsx("li",{ref:a,"data-sidebar":"menu-item",className:v("group/menu-item relative",s),...t}));Ha.displayName="SidebarMenuItem";const ql=tt.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"}}),Ga=P.forwardRef(({asChild:s=!1,isActive:t=!1,variant:a="default",size:r="default",tooltip:n,className:i,...l},u)=>{const x=s?st.Slot:"button",{isMobile:d,state:c}=rt(),m=e.jsx(x,{ref:u,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:v(ql({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(fe,{side:"right",align:"center",hidden:c!=="collapsed"||d,...n})]})):m});Ga.displayName="SidebarMenuButton";const An=P.forwardRef(({className:s,asChild:t=!1,showOnHover:a=!1,...r},n)=>{const i=t?st.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})});An.displayName="SidebarMenuAction";const In=P.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}));In.displayName="SidebarMenuBadge";const Dn=P.forwardRef(({className:s,showIcon:t=!1,...a},r)=>{const n=P.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}})]})});Dn.displayName="SidebarMenuSkeleton";const Mn=P.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}));Mn.displayName="SidebarMenuSub";const Tn=P.forwardRef(({...s},t)=>e.jsx("li",{ref:t,...s}));Tn.displayName="SidebarMenuSubItem";const En=P.forwardRef(({asChild:s=!1,size:t="md",isActive:a,className:r,...n},i)=>{const l=s?st.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})});En.displayName="SidebarMenuSubButton";const On=ns.Provider,Wa=P.forwardRef(({className:s,...t},a)=>e.jsx(ns.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}));Wa.displayName=ns.Viewport.displayName;const Ql=tt.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"}}),Ka=P.forwardRef(({className:s,variant:t,...a},r)=>e.jsx(ns.Root,{ref:r,className:v(Ql({variant:t}),s),...a}));Ka.displayName=ns.Root.displayName;const Ya=P.forwardRef(({className:s,...t},a)=>e.jsx(ns.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}));Ya.displayName=ns.Action.displayName;const Ja=P.forwardRef(({className:s,...t},a)=>e.jsx(ns.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"})}));Ja.displayName=ns.Close.displayName;const Za=P.forwardRef(({className:s,...t},a)=>e.jsx(ns.Title,{ref:a,className:v("text-sm font-semibold [&+div]:text-xs",s),...t}));Za.displayName=ns.Title.displayName;const Xa=P.forwardRef(({className:s,...t},a)=>e.jsx(ns.Description,{ref:a,className:v("text-sm opacity-90",s),...t}));Xa.displayName=ns.Description.displayName;const Hl=1,Gl=1e6;let ma=0;function Wl(){return ma=(ma+1)%Number.MAX_SAFE_INTEGER,ma.toString()}const xa=new Map,Br=s=>{if(xa.has(s))return;const t=setTimeout(()=>{xa.delete(s),gt({type:"REMOVE_TOAST",toastId:s})},Gl);xa.set(s,t)},Kl=(s,t)=>{switch(t.type){case"ADD_TOAST":return{...s,toasts:[t.toast,...s.toasts].slice(0,Hl)};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?Br(a):s.toasts.forEach(r=>Br(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):[]}}},Lt=[];let Ft={toasts:[]};function gt(s){Ft=Kl(Ft,s),Lt.forEach(t=>t(Ft))}function Ln({...s}){const t=Wl(),a=n=>gt({type:"UPDATE_TOAST",toast:{...n,id:t}}),r=()=>gt({type:"DISMISS_TOAST",toastId:t});return gt({type:"ADD_TOAST",toast:{...s,id:t,open:!0,onOpenChange:n=>{n||r()}}}),{id:t,dismiss:r,update:a}}function Pe(){const[s,t]=P.useState(Ft);return P.useEffect(()=>(Lt.push(t),()=>{const a=Lt.indexOf(t);a>-1&&Lt.splice(a,1)}),[]),{...s,toast:Ln,dismiss:a=>gt({type:"DISMISS_TOAST",toastId:a})}}function Fn(){const{toasts:s}=Pe();return e.jsxs(On,{children:[s.map(function({id:t,title:a,description:r,action:n,...i}){return e.jsxs(Ka,{...i,children:[e.jsxs("div",{className:"grid gap-1",children:[a&&e.jsx(Za,{children:a}),r&&e.jsx(Xa,{children:r})]}),n,e.jsx(Ja,{})]},t)}),e.jsx(Wa,{})]})}const er=o.createContext(void 0),Yl=({children:s})=>{const t=o.useRef(null),a=(l,u,x)=>t.current?(t.current.sendMessageToAssistant(l??null,u??null,x??null),!0):!1,r=(l,u,x)=>t.current?(t.current.sendMessageToAssistantWithClear(l??null,u??null,x??null),!0):!1,[n,i]=o.useState(!1);return e.jsx(er.Provider,{value:{sendMessage:a,sendMessageWithClear:r,chatRef:t,hasUnreads:n,setHasUnreads:i},children:s})},Xs=()=>{const s=o.useContext(er);if(s===void 0)throw new Error("useChat must be used within a ChatProvider");return s},Bn=()=>o.useContext(er),Jl=[{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 $n(s){return s.trim().toLocaleLowerCase()}function Pa(s){return(s??"").split(/[;,|]/g).map(t=>t.trim()).filter(Boolean)}function Tt(s){return s.PublicName??s.Name??""}function Zl(s){return Pa(s.Tags).map($n)}function Xl(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"),u=Number(l.slice(0,4)),x=Number(l.slice(4,6)),d=Number(l.slice(6,8));if(u>=1900&&x>=1&&x<=12&&d>=1&&d<=31)return new Date(u,x-1,d)}}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,u=r(l);return u?(u.setHours(0,0,0,0),u>=a):!0})}return(s.NumberOfOpportunities??0)>0}function eo({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:u}=_.useGetV4PartnerByRouteApplicationIdManufacturersQuery({routeApplicationId:s??"",withSpecification:!0},{skip:!r}),x=o.useMemo(()=>(u??i)?.slice()??[],[i,u]),[d,c]=o.useState(""),[m,f]=o.useState([]),[p,N]=o.useState("az"),[w,y]=o.useState(!1),[j,b]=o.useState(!1),C=o.useMemo(()=>{const M=new Map;for(const I of x)for(const F of Pa(I.Tags)){const Q=$n(F);M.has(Q)||M.set(Q,F)}return Array.from(M.entries()).map(([I,F])=>({key:I,label:F})).sort((I,F)=>I.label.localeCompare(F.label,void 0,{sensitivity:"base"}))},[x]),S=d.trim().length>0||m.length>0||p!=="az"||w||j,A=o.useCallback(()=>{c(""),f([]),N("az"),y(!1),b(!1)},[]),{sendMessage:k}=Xs(),D=o.useCallback(M=>{const I=M?.trim().length>0?M.trim():"this manufacturer";k(`Search for ${I} and tell me more about this manufacturer.`)},[k]),O=o.useMemo(()=>{const M=d.trim().toLocaleLowerCase(),I=new Set(m),Q=x.filter($=>{if(w&&!$.OpenToWork||j&&!Xl($))return!1;const z=Zl($);if(I.size>0&&!z.some(T=>I.has(T)))return!1;if(M.length>0){const T=Tt($).toLocaleLowerCase(),V=Pa($.Tags).map(de=>de.toLocaleLowerCase());if(!(T.includes(M)||V.some(de=>de.includes(M))))return!1}return!0}).slice();return Q.sort(($,z)=>p==="az"?Tt($).localeCompare(Tt(z),void 0,{sensitivity:"base"}):p==="recent"?(z.CreationDate??0)-($.CreationDate??0):p==="sales30Desc"?(z.SalesData?.SalesLast30Days??0)-($.SalesData?.SalesLast30Days??0):($.SalesData?.SalesLast30Days??0)-(z.SalesData?.SalesLast30Days??0)),Q},[x,j,w,d,m,p]);return e.jsxs("div",{className:"w-full space-y-6 p-4 sm:p-6",children:[e.jsx(q,{children:e.jsxs(W,{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(Z,{htmlFor:"manufacturer-search",children:"Search manufacturers"}),e.jsx(ne,{id:"manufacturer-search",value:d,onChange:M=>c(M.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(E,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2",onClick:A,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:C.length===0?e.jsx("span",{className:"text-sm text-muted-foreground",children:"No categories available."}):C.map(({key:M,label:I})=>{const F=m.includes(M);return e.jsx(E,{type:"button",variant:F?"secondary":"outline",className:"rounded-full","aria-pressed":F,onClick:()=>{f(Q=>Q.includes(M)?Q.filter($=>$!==M):[...Q,M])},children:I},M)})}),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(As,{value:p,onValueChange:M=>N(M),children:[e.jsx(ys,{"aria-labelledby":"manufacturer-sort-label",children:e.jsx(Is,{placeholder:"A–Z"})}),e.jsx(Ns,{children:Jl.map(M=>e.jsx(as,{value:M.value,children:M.label},M.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(Ds,{id:"only-open-to-work",checked:w,onCheckedChange:M=>y(M===!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(Ds,{id:"only-active-opportunities",checked:j,onCheckedChange:M=>b(M===!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 ",O.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((M,I)=>e.jsx(et,{loading:!0},I))}):O.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:O.map((M,I)=>{const F=Tt(M);return e.jsx(et,{appID:s,manufacturer:M,linkNewTab:!1,link:t(M.ManufacturerId||""),actions:a?e.jsx(E,{type:"button",variant:"outline",size:"icon","aria-label":`Assistant: ${F||"manufacturer"}`,onClick:()=>D(F),children:e.jsx(g.Bot,{})}):void 0,mainAction:e.jsx(mr,{applicationId:s,manufacturer:M})},M.ManufacturerId??`${F}-${I}`)})}):e.jsx(q,{children:e.jsxs(W,{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(E,{type:"button",variant:"outline",onClick:A,disabled:!S,children:"Reset filters"})]})})]})]})}const _n="https://api.randmar.io",so="/swagger/V4/swagger.json",$t=`${_n}${so}`,Vn=o.createContext({swaggerJsonUrl:$t});function to({swaggerJsonUrl:s,children:t}){const a=o.useMemo(()=>({swaggerJsonUrl:s??$t}),[s]);return e.jsx(Vn.Provider,{value:a,children:t})}function sr(){return o.useContext(Vn)}function ao({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 u=l.format==="money"&&typeof i.value=="number"?oe(i.value):l.format==="integer"&&typeof i.value=="number"?ds(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:u})]},i.dataKey)})})]})}return null}function zn({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",u=t.filter(m=>m.yAxisId==="left"||!m.yAxisId),x=t.filter(m=>m.yAxisId==="right"),d=m=>{const f=u[0];return f?.format==="money"?oe(m,{minimumFractionDigits:0,maximumFractionDigits:0}):f?.units?f.unitsPosition==="left"?`${f.units}${m}`:`${m}${f.units}`:String(m)},c=m=>{const f=x[0];return f?.format==="money"?oe(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(Rs.ResponsiveContainer,{width:"100%",height:"100%",children:e.jsxs(Rs.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(Rs.CartesianGrid,{strokeDasharray:"3 3",className:"stroke-border/50"}),!l&&e.jsx(Rs.XAxis,{dataKey:i,className:"text-xs text-muted-foreground",tickLine:!1,axisLine:!1}),!l&&u.length>0&&e.jsx(Rs.YAxis,{yAxisId:"left",className:"text-xs text-muted-foreground",tickLine:!1,axisLine:!1,tickFormatter:d}),!l&&x.length>0&&e.jsx(Rs.YAxis,{yAxisId:"right",orientation:"right",className:"text-xs text-muted-foreground",tickLine:!1,axisLine:!1,tickFormatter:c}),!l&&e.jsx(Rs.Tooltip,{content:e.jsx(ao,{series:t}),cursor:{stroke:"var(--muted)",strokeWidth:1}}),t.map(m=>e.jsx(Rs.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 ro="5.12.1",no=59.9400024414062,io=0,lo=660.000026882351,oo=1080,co=1080,uo="Comp 1",mo=0,xo=[{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}]}],ho=[{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}],fo=[],po={},$r={v:ro,fr:no,ip:io,op:lo,w:oo,h:co,nm:uo,ddd:mo,assets:xo,layers:ho,markers:fo,props:po},go="5.12.1",jo=59.9400024414062,bo=0,yo=660.000026882351,No=1080,vo=1080,wo="Comp 1",So=0,Co=[{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}]}],ko=[{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}],Ro=[],Po={},Ao={v:go,fr:jo,ip:bo,op:yo,w:No,h:vo,nm:wo,ddd:So,assets:Co,layers:ko,markers:Ro,props:Po},Io=s=>{const{color:t}=s;return e.jsx("div",{className:"flex justify-center",children:e.jsx(il.Player,{autoplay:!0,loop:!0,speed:1,style:{width:200,aspectRatio:"1 / 1"},src:t==="white"?Ao:$r})})};function Do({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(Io,{color:t}),s&&e.jsx("div",{className:v("text-center text-xl font-medium",t==="black"?"text-foreground":"text-primary-foreground"),children:s})]})}const wt=P.forwardRef(({className:s,...t},a)=>e.jsx(at.Root,{ref:a,className:v("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...t}));wt.displayName=at.Root.displayName;const Un=P.forwardRef(({className:s,...t},a)=>e.jsx(at.Image,{ref:a,className:v("aspect-square h-full w-full",s),...t}));Un.displayName=at.Image.displayName;const qn=P.forwardRef(({className:s,...t},a)=>e.jsx(at.Fallback,{ref:a,className:v("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...t}));qn.displayName=at.Fallback.displayName;const ha=new Map,Et=new Map;function Mo(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 Qn=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.
2
+ - Use <p> tags for paragraphs.
3
+ - Use <strong> for emphasis.
4
+ - You can also use ordered (<ol>) and unordered (<ul>) lists with list items (<li>).
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
+ ${r?"Think carefully and be thorough, but stay concise.":"Be concise."}
7
+ ---
8
+ Prompt: "${a}"`;try{return(await s({applicationId:t,body:[{Role:"user",Parts:[{Text:x}]}]}).unwrap()).Content?.Parts?.find(m=>m.Text)?.Text??"Sorry, I couldn't generate a response for this."}catch(d){if(console.error("Error fetching AI response:",d),i>0)return await new Promise(c=>setTimeout(c,(4-i)*500)),Qn(s,t,a,r,n,i-1);throw new Error("An error occurred while generating the response.")}},To=s=>{const{applicationId:t,useProModel:a=!1,outputFormat:r="html"}=s,[n,i]=o.useState(null),[l,u]=o.useState(!1),[x,d]=o.useState(null),[c]=_.usePostV4PartnerByApplicationIdGenerationRandmarAssistantMutation(),m=o.useRef(null),f=o.useCallback(async p=>{if(!t?.trim()){d("applicationId is required.");return}m.current=p;const N=`${t}::${p}::${r}`;if(ha.has(N)){const y=ha.get(N);return m.current===p&&(i(y),u(!1),d(null)),y}if(Et.has(N)){u(!0);try{return await Et.get(N)}catch(y){m.current===p&&d(y instanceof Error?y.message:"An unknown error occurred.");return}finally{m.current===p&&u(!1)}}u(!0),d(null);const w=Qn(c,t,p,a,r).then(y=>{const j=Mo(y,r);return ha.set(N,j),j}).finally(()=>{Et.delete(N)});Et.set(N,w);try{const y=await w;return m.current===p&&i(y),y}catch(y){m.current===p&&d(y instanceof Error?y.message:"An unknown error occurred.");return}finally{m.current===p&&u(!1)}},[t,c,a,r]);return{response:n,isLoading:l,error:x,sendPrompt:f}};function Eo(s,t){if(!s||!t)return"";const a=s?.PublicName??"Our Company",r=t?.PublicName??"Partner";return`
9
+ Act as a business analyst. Your task is to provide a short, high-level summary
10
+ of the relationship between the two companies described in the JSON data below.
11
+ Suggest how these two entities can best work together.
12
+ What are the key opportunities, potential challenges, and strategic advantages of this partnership?
13
+
14
+ **Formatting Rules:**
15
+ - The entire response must be under 600 words.
16
+ - Use natural, professional language.
17
+ - **Crucially, do not mention the names of any data fields, keys, or the JSON structure.** For example, instead of saying 'The "IsReseller" flag is true', say 'The company is a reseller'.
18
+
19
+ **Our Company Data (${a}):**
20
+ \`\`\`json
21
+ ${JSON.stringify(s,null,2)}
22
+ \`\`\`
23
+
24
+ **Partner Company Data (${r}):**
25
+ \`\`\`json
26
+ ${JSON.stringify(t,null,2)}
27
+ \`\`\`
28
+ `}function _t(s){const t=(s??"").trim();if(t)try{return new URL(t).origin}catch{return}}function St(){const s=sr();return o.useMemo(()=>_t(s.swaggerJsonUrl)??_n,[s.swaggerJsonUrl])}function js(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=_t(t),n=a.startsWith("/")?a:`/${a}`;if(!r)return n;try{return new URL(n,r).toString()}catch{return n}}const gs=P.forwardRef(({className:s,children:t,orientation:a,...r},n)=>e.jsxs(Bs.Root,{ref:n,className:v("relative overflow-hidden",s),...r,children:[e.jsxs(Bs.Viewport,{className:"h-full w-full rounded-[inherit] [&>div]:!block [&>div]:!h-full",children:[" ",t]}),e.jsx(Wt,{orientation:a||"vertical"}),e.jsx(Bs.Corner,{})]}));gs.displayName=Bs.Root.displayName;const Wt=P.forwardRef(({className:s,orientation:t="vertical",...a},r)=>e.jsx(Bs.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(Bs.ScrollAreaThumb,{className:"relative flex-1 rounded-full bg-border"})}));Wt.displayName=Bs.ScrollAreaScrollbar.displayName;function Oo({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(hs,{id:n.partner1===s?n.partner2:n.partner1,width:72,height:72})});return Bo(n,a,r,i)})})}function Lo(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,u=t>=i&&t<r;if(l){const x=a.getTime()-t.getTime();return x>=0&&x<15e3?"a few seconds ago":x>=0&&t.getHours()===a.getHours()?"earlier this hour":"earlier today"}return u?"yesterday":t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Fo(s,t){return s?s[0]===t[0]&&s[1]===t[1]||s[0]===t[1]&&s[1]===t[0]:!1}function Bo(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",Fo(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(wt,{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:Lo(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 nt=P.forwardRef(({className:s,...t},a)=>e.jsx(Sa.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(Sa.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")})}));nt.displayName=Sa.Root.displayName;function $o({appID:s,chats:t,chatWithRandmarButton:a,isStartingChat:r,isRefreshingChats:n,isMarkingAllRead:i,handleChatWithRandmar:l,onFullRefreshChats:u,onMarkAllRead:x,setActiveChat:d,activeChat:c}){const[m,f]=o.useState(""),[p,N]=o.useState(null),[w,y]=o.useState(null),j=o.useMemo(()=>t.filter($=>{const z=s===$.partner1?$.partner2:$.partner1;return $.name.toLowerCase().includes(m.toLowerCase())||z.toLocaleLowerCase().includes(m.toLowerCase())}),[s,t,m]),{toast:b}=Pe(),{data:C,isLoading:S}=_.useGetV4UserQuery(),A=C?.Name||C?.EmailAddress||"User",k=C?.Role||"Partner",[D]=_.usePostV4UserByFieldNameMutation(),[O]=_.usePutV4PartnerByRouteApplicationIdUserAndEmailAddressNotificationNotificationTypeMutation(),[M]=_.useDeleteV4PartnerByRouteApplicationIdUserAndEmailAddressNotificationNotificationTypeMutation(),I=$=>{if(!C?.ApplicationId||!C.EmailAddress){b({title:"Not ready",description:"Please wait for your user profile to finish loading.",variant:"destructive"});return}$?O({routeApplicationId:C.ApplicationId,emailAddress:C.EmailAddress,notificationType:"PartnerChatNotifications"}):M({routeApplicationId:C.ApplicationId,emailAddress:C.EmailAddress,notificationType:"PartnerChatNotifications"})};o.useEffect(()=>{p===null&&A&&N(A)},[p,A]),o.useEffect(()=>{w===null&&k&&y(k)},[w,k]);const F=()=>{p&&p!==A&&p.trim()!==""&&D({fieldName:"Name",newValue:p}).unwrap().then(()=>{b({title:"Success",description:"Name updated successfully"})})},Q=()=>{w&&w!==k&&w.trim()!==""&&D({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(E,{type:"button",variant:"ghost",size:"icon","aria-label":"Refresh chat state",disabled:!!n||!!r,onClick:u,children:n?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.RefreshCw,{className:"h-4 w-4"})})}),e.jsx(fe,{side:"bottom",className:"bg-popover text-popover-foreground",children:"Full refresh"})]}),e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(E,{type:"button",variant:"ghost",size:"icon","aria-label":"Mark all messages as read",disabled:!!i||!!r||t.length===0,onClick:x,children:i?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.CheckCheck,{className:"h-4 w-4"})})}),e.jsx(fe,{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(ne,{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:m,onChange:$=>f($.target.value)})]})})}),e.jsx("div",{className:"mt-1 mb-1",children:t.findIndex($=>$.partner1==="2"||$.partner2==="2")<0?e.jsx(E,{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(gs,{className:"flex-1",children:t.length>0&&e.jsx(Oo,{appID:s,chats:j,activeChat:c,onSelectChat:d})}),e.jsx(vt,{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(ne,{value:p??"",onChange:$=>N($.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",{children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Role"}),e.jsx(ne,{value:w??"",onChange:$=>y($.target.value),onBlur:Q,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(nt,{disabled:S||!C,onCheckedChange:I,checked:C?.Notifications?.find($=>$.NotificationType==="PartnerChatNotifications")!==void 0})]})]})]})}const bs=P.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}));bs.displayName="Textarea";async function _o(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 Hn(s){const t=dl.marked(s,{async:!1});return ul.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 Gn(s){const t=new Date(s);return Lr.isToday(t)?t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0}):Lr.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 Vo({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 zo({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 Uo=o.memo(function({message:t,isCurrentUser:a,hideSenderName:r,canEdit:n,canRetry:i,canCopy:l,isCopied:u,isEditing:x,editValue:d,onEditValueChange:c,onStartEdit:m,onCancelEdit:f,onSaveEdit:p,onRetry:N,onCopy:w}){const y=o.useMemo(()=>Hn(t.content),[t.content]),j=y.trim().length>0,b=o.useMemo(()=>(t.images??[]).map(S=>{const A=typeof S?.mimeType=="string"?S.mimeType.trim():"",k=typeof S?.base64Data=="string"?S.base64Data.replace(/\s+/g,""):"";return!A.startsWith("image/")||k.length===0?null:`data:${A};base64,${k}`}).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:Gn(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(bs,{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:d,onChange:C=>c(C.target.value)}),e.jsxs("div",{className:"mt-3 flex justify-end gap-2",children:[e.jsxs(E,{size:"sm",variant:"outline",onClick:f,children:[e.jsx(g.X,{className:"h-4 w-4"})," Cancel"]}),e.jsxs(E,{size:"sm",onClick:p,children:[e.jsx(g.Check,{className:"h-4 w-4"})," Save"]})]})]}):j&&e.jsx("div",{dangerouslySetInnerHTML:{__html:y}}),b.length>0&&e.jsx("div",{className:"mt-3 space-y-3",children:b.map((C,S)=>e.jsx("img",{src:C,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(E,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:w,"aria-label":u?"Copied message":"Copy message",children:u?e.jsx(g.Check,{className:"h-4 w-4"}):e.jsx(g.Copy,{className:"h-4 w-4"})}),(n||i)&&!x&&e.jsxs(e.Fragment,{children:[n&&e.jsx(E,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:m,"aria-label":"Edit message",children:e.jsx(g.Pencil,{className:"h-4 w-4"})}),i&&e.jsx(E,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:N,"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),qo=o.memo(function({message:t,isCurrentUser:a,hideSenderName:r,canEdit:n,canRetry:i,canCopy:l,isCopied:u,isEditing:x,editValue:d,onEditValueChange:c,onStartEdit:m,onCancelEdit:f,onSaveEdit:p,onRetry:N,onCopy:w}){const y=o.useMemo(()=>Hn(t.content),[t.content]),j=y.trim().length>0,b=o.useMemo(()=>(t.images??[]).map(S=>{const A=typeof S?.mimeType=="string"?S.mimeType.trim():"",k=typeof S?.base64Data=="string"?S.base64Data.replace(/\s+/g,""):"";return!A.startsWith("image/")||k.length===0?null:`data:${A};base64,${k}`}).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(bs,{className:"w-full min-h-14 max-h-[30em] resize-none field-sizing-content bg-background p-2 text-sm text-foreground",value:d,onChange:C=>c(C.target.value)}),e.jsxs("div",{className:"mt-2 flex justify-end gap-2",children:[e.jsxs(E,{size:"sm",variant:"outline",onClick:f,children:[e.jsx(g.X,{className:"h-4 w-4"})," Cancel"]}),e.jsxs(E,{size:"sm",onClick:p,children:[e.jsx(g.Check,{className:"h-4 w-4"})," Save"]})]})]}):j&&e.jsx("div",{dangerouslySetInnerHTML:{__html:y}}),b.length>0&&e.jsx("div",{className:"mt-2 space-y-2",children:b.map((C,S)=>e.jsx("img",{src:C,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(E,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:w,"aria-label":u?"Copied message":"Copy message",children:u?e.jsx(g.Check,{className:"h-4 w-4"}):e.jsx(g.Copy,{className:"h-4 w-4"})}),(n||i)&&!x&&e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[n&&e.jsx(E,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:m,"aria-label":"Edit message",children:e.jsx(g.Pencil,{className:"h-4 w-4"})}),i&&e.jsx(E,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:N,"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:Gn(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),Wn=o.memo(function({messages:t,appID:a,botStatus:r,isAssistantChat:n,variant:i,hideSenderNames:l=!1,editableUserMessages:u=!1,editingMessageId:x=null,editingDraft:d="",onEditingDraftChange:c=()=>{},onStartEditUserMessage:m,onCancelEditUserMessage:f,onSaveEditUserMessage:p,onRetryUserMessage:N}){const[w,y]=o.useState(null),j=o.useRef(null);o.useEffect(()=>()=>{j.current!=null&&window.clearTimeout(j.current)},[]);const b=o.useCallback(async(D,O)=>{await _o(O)&&(y(D),j.current!=null&&window.clearTimeout(j.current),j.current=window.setTimeout(()=>y(null),2e3))},[]),C=o.useMemo(()=>{const D=new Set;let O=null;for(const M of t){const I=(M.senderName??"").trim();I&&(O===I?D.add(M.id):O=I)}return D},[t]),S=i??(n?"assistant":"dashboard"),A=S==="assistant"?qo:Uo,k=S==="assistant"?zo:Vo;return e.jsxs("div",{className:S==="dashboard"?"py-3":"",children:[t.map(D=>{const O=D.fromPartnerID===a,M=!!(u&&n&&O&&m&&p&&f),I=!!(u&&n&&O&&N),F=!!(n&&!O&&(D.content??"").trim().length>0),Q=x===D.id;return e.jsx(A,{message:D,isCurrentUser:O,hideSenderName:l||C.has(D.id),canEdit:M,canRetry:I,canCopy:F,isCopied:w===D.id,isEditing:Q,editValue:Q?d:"",onEditValueChange:c,onStartEdit:()=>m?.(D),onCancelEdit:()=>f?.(),onSaveEdit:()=>p?.(D.id,d),onRetry:()=>N?.(D),onCopy:()=>{b(D.id,D.content)}},D.id)}),r!==""&&e.jsx(k,{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 Qo({activeChat:s,activeChatObj:t,appID:a,messagesEndRef:r,inputRef:n,content:i,setContent:l,handleSendMessage:u,isPostBizDevConvoLoading:x,acceptChat:d}){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(wt,{className:"h-8 w-8 flex-shrink-0 rounded-lg",children:e.jsx(hs,{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(gs,{className:"flex-1 bg-background",children:[e.jsx("div",{className:t?.messages===null?"opacity-0":"",children:e.jsx(Wn,{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(E,{disabled:x,onClick:()=>d(),children:[e.jsx(g.HandshakeIcon,{}),"Accept Conversation Request"]}),e.jsxs(E,{disabled:!0,className:"ml-2",children:[e.jsx(g.ThumbsDownIcon,{}),"Block Partner"]})]}),e.jsx(bs,{ref:n,placeholder:"Type a message...",value:i,onChange:c=>l(c.target.value),onKeyDown:c=>{c.key!=="Enter"||c.shiftKey||(c.preventDefault(),u())},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(E,{size:"icon",variant:"default",className:t?.pending?"collapse":"h-10 w-10 rounded-xl",disabled:t?.pending,onClick:u,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 Ho({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(Ce.Link,{className:"block",inert:i===void 0,to:`/${t}/Partner/${i?.[0]===t?i[1]:i?.[0]}`,children:e.jsxs(E,{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(E,{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(E,{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(mn,{userId:t,partnerId:i?.[0]===t?i[1]:i?.[0]||"",isAdmin:!1}),e.jsx(Go,{appID:t,activeChatObj:s}),e.jsx(Wo,{appID:t,activeChatObj:s})]})})}const Go=({appID:s,activeChatObj:t})=>{const a=t?.conversationID??-1,r=!t||a===-1,{data:n,isLoading:i,isError:l,refetch:u,isFetching:x}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdPeopleQuery({routeApplicationId:s,conversationId:a},{skip:r}),d=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(E,{variant:"ghost",size:"sm",onClick:()=>u(),children:"Retry"})]}):d.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:d.map((c,m)=>{const f=c.ApplicationId??`${c.Name??"person"}-${m}`,p=c.LastAuthentication?new Date(c.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:c.Name??"Unknown person"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c.Role??"Role unavailable"}),p?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last auth ",p]}):null]},f)})})]})},Wo=({appID:s,activeChatObj:t})=>{const[a,r]=o.useState(!1),n=t?.conversationID,i=n===void 0||n===-1,{data:l,isLoading:u}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdLinksQuery({routeApplicationId:s,conversationId:n??-1},{skip:i}),[x]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdLinkMutation(),[d]=_.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:[u?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(c=>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:c.URL,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline underline-offset-4 break-all",children:c.Title}),e.jsx(E,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>d({routeApplicationId:s,linkId:c.LinkId}),"aria-label":"Delete link",children:e.jsx(g.Trash2,{className:"h-4 w-4"})})]},c.LinkId))]}),e.jsxs(De,{open:a,onOpenChange:r,children:[e.jsx(Fs.DialogTrigger,{asChild:!0,children:e.jsxs(E,{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($e,{children:[e.jsx(Fs.DialogTitle,{children:"Add Link"}),e.jsx(Fs.DialogDescription,{children:"Please enter the details for the new link."})]}),e.jsxs("form",{className:"space-y-4",onSubmit:c=>{c.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(Z,{htmlFor:"link-title",children:"Title"}),e.jsx(ne,{id:"link-title",required:!0,minLength:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{htmlFor:"link-url",children:"URL"}),e.jsx(ne,{id:"link-url",type:"url",required:!0,minLength:2,placeholder:"https://"})]}),e.jsx(E,{type:"submit",disabled:i,children:"Add Link"})]})]})]})]})},Ko=s=>{const[t]=_.usePostV4UserByFieldNameMutation(),[a,r]=o.useState(""),[n,i]=o.useState(""),[l,u]=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:d=>{l||(u(!0),d.preventDefault(),t({fieldName:"Name",newValue:a}).then(()=>{x({routeApplicationId:s.appID,partnerId:"2"})}),t({fieldName:"Role",newValue:n}))},children:[e.jsx(Z,{htmlFor:"name",children:"Name"}),e.jsx(ne,{id:"name",required:!0,minLength:2,value:a,onChange:d=>r(d.target.value)}),e.jsx(Z,{htmlFor:"role",children:"Role"}),e.jsx(ne,{id:"role",required:!0,minLength:2,value:n,onChange:d=>i(d.target.value)}),e.jsx(E,{type:"submit",disabled:l,children:l?"Saving...":"Save"})]})]})},ht=(s,t)=>s.unread>0&&t.unread===0?-1:t.unread>0&&s.unread===0?1:s.name.localeCompare(t.name);function Yo({appID:s,inputRef:t,className:a}){const{setHasUnreads:r}=Xs(),n=St(),{data:i,refetch:l}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationsQuery({routeApplicationId:s}),[u,x]=o.useState(!1),[d,c]=o.useState(!1),[m,f]=o.useState(!1),[p,{isLoading:N}]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),w=o.useRef(null),[y]=_.useLazyGetV4PartnerByApplicationIdAccountQuery(),{sendPrompt:j}=To({applicationId:s,outputFormat:"text",useProModel:!0}),[b,C]=o.useState(!1),[S]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),[A]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdReadMutation(),[k]=_.useLazyGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationAndConversationIdMessagesQuery(),[D]=_.useLazyGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery(),[O,M]=o.useState(!1);o.useEffect(()=>{i&&(ae(G=>{const ie=i.map(X=>{const xe=G.find(Te=>Te.conversationID===X.ConversationId);return{partner1:X.Participant1,partner2:X.Participant2,name:X.Participant?.PublicName??"missing public name",unread:xe?.unread??0,pending:X.Status!=="Approved",messages:xe?.messages??null,conversationID:X.ConversationId,lastMessageTime:X.LastMessageTime??null}});return ie.sort(ht),ie}),x(!0),setTimeout(()=>Ke.current?.focus(),50))},[i,s]);const[I,F]=o.useState(void 0),[Q,$]=o.useState(""),[z,T]=o.useState(null),[V,ae]=o.useState([]),[de,Oe]=o.useState(null),Ne=o.useRef(null),Ve=o.useRef(null),[Le,Ue]=o.useState([]),Ke=t||Ve,re=o.useRef(null),{toast:ue}=Pe(),H=()=>V.find(G=>G.partner1===I?.[0]&&G.partner2===I?.[1]),K=o.useCallback(async()=>{if(d)return;c(!0);const G=I;try{Ue([]),T(null);const xe=((await l()).data??[]).map(Ae=>({partner1:Ae.Participant1,partner2:Ae.Participant2,name:Ae.Participant?.PublicName??"missing public name",unread:0,pending:Ae.Status!=="Approved",messages:null,conversationID:Ae.ConversationId,lastMessageTime:Ae.LastMessageTime??null})),Te=new Map;await Promise.allSettled(xe.map(async Ae=>{if(Ae.conversationID<=0)return;const ss=((await k({routeApplicationId:s,conversationId:Ae.conversationID})).data??[]).reduce((Ts,qs)=>qs.Read||!qs.SenderId||qs.SenderId===s?Ts:Ts+1,0);Te.set(Ae.conversationID,ss)}));const es=xe.map(Ae=>({...Ae,unread:Te.get(Ae.conversationID)??0})).sort(ht);if(ae(es),G){const Ae=es.find(He=>He.partner1===G[0]&&He.partner2===G[1]||He.partner1===G[1]&&He.partner2===G[0]);F(Ae?[Ae.partner1,Ae.partner2]:void 0)}ue({title:"Refreshed",description:"Chat state reinitialized."})}catch(ie){console.error("Error refreshing chat state:",ie),ue({title:"Refresh failed",description:"Could not refresh chat state. Please try again.",variant:"destructive"})}finally{c(!1)}},[I,s,k,d,l,ue]),Y=o.useCallback(async()=>{if(!m){f(!0);try{const G=V.map(ie=>ie.conversationID).filter(ie=>ie>0);await Promise.allSettled(G.map(async ie=>{await A({routeApplicationId:s,conversationId:ie}).unwrap()})),ae(ie=>ie.map(X=>({...X,unread:0})).sort(ht)),ue({title:"All read",description:"All conversations marked as read."})}catch(G){console.error("Error marking all conversations as read:",G),ue({title:"Action failed",description:"Could not mark all conversations as read. Please try again.",variant:"destructive"})}finally{f(!1)}}},[s,V,m,A,ue]);function ee(){const G=H();G&&A({routeApplicationId:s,conversationId:G.conversationID})}const pe=G=>Ue(ie=>[...ie,G]);o.useEffect(()=>{if(Le.length==0)return;console.log(Le.length,"unprocessedMessages detected");const G=(X,xe)=>xe.partner1===X.toPartnerID&&xe.partner2===X.fromPartnerID||xe.partner2===X.toPartnerID&&xe.partner1===X.fromPartnerID;let ie=!1;Le.forEach(X=>{if(!V.some(xe=>G(X,xe))){console.log("message received for unknown convo ID - need to refetch!"),ie=!0;return}ae(xe=>xe.map(Te=>{if(!G(X,Te))return Te;const es=Te.messages??[];if(es.some(ss=>ss.id===X.id))return Te;let Ae=1;const He=document.activeElement&&document.activeElement===Ke.current;return I?.[0]==Te.partner1&&I[1]==Te.partner2&&He&&(He&&(Ae=0,ee()),setTimeout(()=>Ne.current?.scrollIntoView({behavior:"smooth"}),50)),{...Te,pending:!1,unread:Te.unread+Ae,messages:[...es,X]}}).sort(ht))}),console.log("need refetch:",ie),ie&&l(),Ue([])},[Le,Ue,ae,F,I]),o.useEffect(()=>{const G=new da.HubConnectionBuilder().withUrl(js("/hub",n),{accessTokenFactory:()=>localStorage.getItem("access_token"),headers:{"X-Impersonated-Id":s}}).configureLogging(da.LogLevel.Information).withAutomaticReconnect().withHubProtocol(new da.JsonHubProtocol).build();return G.on("ReceiveMessage",pe),G.start().catch(ie=>console.error("Error connecting to SignalR hub:",ie)),Oe(G),()=>{G&&G.stop()}},[s,n]),o.useEffect(()=>{!I||!H()||(Ke.current?.focus(),setTimeout(()=>Ne.current?.scrollIntoView({behavior:"smooth"}),50))},[I]),o.useEffect(()=>{if(!I)return;const G=H();G&&G.conversationID!==-1&&(async()=>{try{const X=(await k({routeApplicationId:s,conversationId:G.conversationID})).data?.map(xe=>({id:"history"+xe.MessageId,fromPartnerID:xe.SenderId,toPartnerID:xe.SenderId==G.partner1?G.partner2:G.partner1,senderName:xe.SenderName??"missing name",timestamp:new Date(xe.SentDate+"Z").getTime(),content:xe.Content??"no content"}))??[];ae(xe=>xe.map(Te=>Te.conversationID===G.conversationID?{...Te,messages:X}:Te).sort(ht))}catch(ie){console.error("Error fetching conversation messages:",ie)}})()},[I,k,s]),o.useEffect(()=>{if(!I)return;const G=H();if(!G)return;const ie=document.activeElement&&document.activeElement===Ke.current;G.unread>0&&ie&&(ee(),ae(X=>X.map(xe=>xe.partner1===I[0]&&xe.partner2===I[1]?{...xe,unread:0}:xe)))},[I,V]);const{sendMessage:Re}=Xs(),ve=o.useCallback(G=>{Re(`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(G,null,2)}`)},[Re]),Ee=o.useCallback(async()=>{if(I)try{M(!0);const G=await y({applicationId:s}),ie=I[0]===s?I[1]:I[0],X=await D({routeApplicationId:s,partnerId:ie,withSpecification:!0}),xe=Eo(G.data,X.data);xe?Re(xe):ue({title:"Missing data",description:"We couldn't load enough data to analyze this partnership yet. Please try again shortly.",variant:"destructive"})}catch(G){console.error("Error preparing partnership analysis:",G),ue({title:"Error",description:"Could not analyze the partnership. Please try again later.",variant:"destructive"})}finally{M(!1)}},[I,y,D,Re,ue,s]);o.useEffect(()=>{r(V.some(G=>G.unread>0))},[V,r]);const U=(G,ie)=>{ie=ie.replace(/\n/g,`
30
+ `),console.log("doSend",ie),console.log("target",G);const X={id:crypto.randomUUID(),senderName:Se?.Name??Se?.EmailAddress??"User",fromPartnerID:s,toPartnerID:G.partner1===s?G.partner2:G.partner1,content:ie,timestamp:Date.now()};pe(X),de.invoke("NewMessage",X).catch(xe=>console.error("Error sending message:",xe)),$(""),re.current&&(re.current.value="")},me=()=>{const G=Q.trim();!os||!G||!I||!de||(os.unread>0&&(ee(),ae(ie=>ie.map(X=>X.partner1===I[0]&&X.partner2===I[1]?{...X,unread:0}:X))),U(os,G))},we=(G,ie)=>T([G,ie]);o.useEffect(()=>{if(z===null)return;const G=V.find(X=>X.conversationID===z[0]);if(!G||(F([G.partner1,G.partner2]),!de))return;const ie=z[1];T(null),ie&&U(G,ie)},[z,V,F,de]);const{data:Se,isLoading:Fe}=_.useGetV4UserQuery();if(!u||Fe)return e.jsx(g.Loader2,{className:"h-12 w-12 animate-spin mx-auto mb-4"});if(!Se?.Name)return e.jsx(Ko,{appID:Se?.ApplicationId??""});const Xe=async()=>{w.current&&(w.current.disabled=!0),C(!0);try{const G=await y({applicationId:s}),ie=G.data?.About??"a new business venture",X=[];G.data?.IsManufacturer&&X.push("Manufacturer"),G.data?.IsReseller&&X.push("Reseller"),G.data?.IsSalesAgency&&X.push("Sales Agency");const Te=`
31
+ Your task is to draft a ready-to-send opening message from a user to the Randmar team.
32
+
33
+ **Your Persona:** You are an entrepreneur and a ${X.length>0?X.join("/"):"Entrepreneur"}.
34
+ **Your Company's Description:**
35
+ \`\`\`html
36
+ ${ie}
37
+ \`\`\`
38
+
39
+ **Instructions:**
40
+ - Write a short, funny, yet professional greeting message.
41
+ - The tone should be from one entrepreneur to another, aiming to break the ice.
42
+ - The message must be complete and ready to send.
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
+ - Keep it to 1-2 concise, engaging sentences.
45
+ - Output only the plain text of the message itself.
46
+ `,es=await j(Te);if(es){const He=(await S({routeApplicationId:s,partnerId:"2"})).data?.ConversationId;if(He)await l(),we(He,es);else throw new Error("Failed to retrieve conversation ID after creation.")}}catch(G){console.error("Error during 'Chat with Randmar' initiation:",G),ue({title:"Error",description:"Could not initiate chat. Please try again later.",variant:"destructive"})}finally{w.current&&(w.current.disabled=!1),C(!1)}},Us=()=>{I&&p({routeApplicationId:s,partnerId:I[0]==s?I[1]:I[0]})},os=H();return e.jsxs("div",{className:v("flex grow-1 overflow-hidden",a),children:[e.jsx($o,{appID:s,activeChat:I,chats:V,chatWithRandmarButton:w,isStartingChat:b,isRefreshingChats:d,isMarkingAllRead:m,handleChatWithRandmar:Xe,onFullRefreshChats:K,onMarkAllRead:Y,setActiveChat:F}),e.jsx(Qo,{activeChat:I,activeChatObj:os,appID:s,messagesEndRef:Ne,inputRef:Ke,content:Q,setContent:$,handleSendMessage:me,isPostBizDevConvoLoading:N,acceptChat:Us}),e.jsx(Ho,{activeChatObj:os,appID:s,sendChatToAssistant:ve,isAnalyzingPartnership:O,analyzePartnership:Ee})]})}const tr=Vs.Root,Kt=P.forwardRef(({className:s,...t},a)=>e.jsx(Vs.List,{ref:a,className:v("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",s),...t}));Kt.displayName=Vs.List.displayName;const Je=P.forwardRef(({className:s,...t},a)=>e.jsx(Vs.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}));Je.displayName=Vs.Trigger.displayName;const ts=P.forwardRef(({className:s,...t},a)=>e.jsx(Vs.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}));ts.displayName=Vs.Content.displayName;function Jo({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($e,{children:[e.jsx(_e,{children:r}),e.jsx(ze,{children:n})]}),e.jsxs(qe,{children:[e.jsx(E,{variant:"outline",onClick:t,children:l}),e.jsx(E,{onClick:a,children:i})]})]})})}function Kn(s){const[t,a]=o.useState(!1),r=Ce.useBlocker(o.useCallback(({currentLocation:u,nextLocation:x})=>{const d=u.pathname!==x.pathname||u.search!==x.search||u.hash!==x.hash;return s()&&d},[s]));o.useEffect(()=>{r.state==="blocked"&&a(!0)},[r]),o.useEffect(()=>{const u=x=>{if(s())return x.preventDefault(),"You have unsaved changes. Are you sure you want to leave?"};return window.addEventListener("beforeunload",u),()=>{window.removeEventListener("beforeunload",u)}},[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(Jo,{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 Zo({manufacturer:s,readonly:t=!1,isLoading:a,onUnsavedChanges:r}){const{toast:n}=Pe(),[i]=_.usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[l,u]=o.useState({}),x=o.useMemo(()=>({accountsPayableRep:s?.ContactName??"",representativeEmail:s?.RepresentativeEmail??"",phone:s?.Phone??"",creditLimit:s?.CreditLimit??0,terms:s?.Terms??""}),[s]),{register:d,handleSubmit:c,reset:m,watch:f,formState:{errors:p,isSubmitting:N}}=Nt.useForm({defaultValues:x}),w=f(),y=o.useCallback(()=>t||!l?!1:JSON.stringify(w)!==JSON.stringify(l),[t,w,l]);o.useEffect(()=>{r&&r(y())},[y,r]),o.useEffect(()=>{s&&(m(x),u(x))},[s,m,x]);const j=async b=>{if(t)return;let C=!0,S=!1;const A=[{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 k of A){const D=k.value,O=s?.[k.apiKey];if(D!==O&&D!==void 0){S=!0;try{await i({applicationId:s?.ManufacturerId??"",fieldName:k.apiKey,newValue:String(D)}).unwrap()||(C=!1,console.error(`Failed to update ${k.apiKey}`))}catch(M){console.error(`Error updating ${k.apiKey}:`,M),C=!1}}}C&&S?(n({title:"Billing info",description:"Information updated successfully",variant:"success"}),u({...b}),r&&r(!1)):C?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(q,{children:[e.jsx(J,{children:e.jsx(ce,{className:"text-1xl font-bold",children:"Billing, Credit, & Rebates"})}),e.jsx(W,{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:c(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(Z,{className:"text-sm font-medium leading-none",htmlFor:"accountsPayableRep",children:"Accounts Payable Representative"}),e.jsx(ne,{id:"accountsPayableRep",placeholder:"John Doe",...d("accountsPayableRep"),readOnly:t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{className:"text-sm font-medium leading-none",htmlFor:"representativeEmail",children:"Representative Email"}),e.jsx(ne,{id:"representativeEmail",placeholder:"john.doe@company.com",...d("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(Z,{className:"text-sm font-medium leading-none",htmlFor:"phone",children:"Phone"}),e.jsx(ne,{id:"phone",placeholder:"(555) 123-4567",...d("phone"),readOnly:t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{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(us.FormattedNumber,{value:s?.CreditLimit||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{className:"text-sm font-medium leading-none",htmlFor:"terms",children:"Terms"}),e.jsx(ne,{id:"terms",placeholder:"NET 30 DAYS",...d("terms"),readOnly:!0})]}),!t&&e.jsx("div",{className:"flex justify-end",children:e.jsx(E,{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 Xo({manufacturer:s,readonly:t=!1,isLoading:a}){const{toast:r}=Pe(),[n]=_.usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),i=o.useMemo(()=>({openToWork:s?.OpenToWork??!1}),[s]),{reset:l,watch:u}=Nt.useForm({defaultValues:i});o.useEffect(()=>{s&&l(i)},[s,l,i]);const x=async d=>{if(!t)try{await n({applicationId:s?.ManufacturerId??"",fieldName:"OpenToWork",newValue:d?"true":"false"}).unwrap()&&r({title:"Open to work info",description:"Information updated successfully",variant:"success"})}catch(c){console.error("Error updating",c)}};return e.jsxs(q,{children:[e.jsx(J,{children:e.jsx(ce,{className:"text-1xl font-bold",children:"Open to Work with Resellers"})}),e.jsx(W,{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(nt,{id:"openToWork",checked:u("openToWork"),onCheckedChange:d=>x(d),disabled:t}),e.jsx(Z,{htmlFor:"openToWork",children:"Open to work with Resellers"})]})]})})]})}const ec=["Arts and Crafts","Cleaning Solutions","Clothing","Electronics","Generic Compatible Toner","Ink","Luggage and Bags","Miscellaneous","Networking Devices","Paper Products","Printers","Printing Supplies","Toner"];function sc({manufacturer:s,readonly:t=!1,isLoading:a,onUnsavedChanges:r}){const{toast:n}=Pe(),[i]=_.usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[l,u]=o.useState([]),[x,d]=o.useState({}),c=o.useMemo(()=>({publicName:s?.PublicName??"",website:s?.Website??"",customerServiceEmail:s?.PublicEmail??"",publicResources:s?.PublicResourcesLink??""}),[s]),{register:m,handleSubmit:f,reset:p,watch:N,formState:{errors:w,isSubmitting:y}}=Nt.useForm({defaultValues:c}),j=N(),b=o.useCallback(()=>t||!x?!1:JSON.stringify(j)!==JSON.stringify(x),[t,j,x]);o.useEffect(()=>{r&&r(b())},[b,r]),o.useEffect(()=>{s&&(p(c),u(s.Tags?s.Tags.split(",").map(k=>k.trim()):[]),d(c))},[s,p,c]);const C=async k=>{if(t)return;let D=!0,O=!1;const M=[{key:"publicName",apiKey:"PublicName",value:k.publicName},{key:"website",apiKey:"Website",value:k.website},{key:"manufacturerCategories",apiKey:"Tags",value:l.join(", ")},{key:"customerServiceEmail",apiKey:"PublicEmail",value:k.customerServiceEmail},{key:"publicResources",apiKey:"PublicResourcesLink",value:k.publicResources}];for(const I of M){const F=I.value,Q=s?.[I.apiKey],$=typeof Q=="boolean"?String(Q):Q;if(F!==$&&F!==void 0){O=!0;try{await i({applicationId:s?.ManufacturerId??"",fieldName:I.apiKey,newValue:String(F)}).unwrap()||(D=!1)}catch(z){console.error(`Error updating ${I.apiKey}:`,z),D=!1}}}D&&O?(n({title:"Public info",description:"Information updated successfully",variant:"success"}),d({...k}),r&&r(!1)):D||n({title:"Update error",description:"Failed to update",variant:"destructive"})},S=k=>!k||k.trim()==="",A=k=>{u(k)};return e.jsxs(q,{children:[e.jsx(J,{children:e.jsx(ce,{className:"text-1xl font-bold",children:"Public Information"})}),e.jsx(W,{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(N("publicName"))||S(N("website"))||S(N("customerServiceEmail")))&&e.jsxs(vs,{variant:"destructive",className:"mb-6",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(ws,{children:"Missing information"}),e.jsx(Ss,{children:"All fields are required to get started at working with Resellers."})]}),e.jsxs("form",{onSubmit:f(C),className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{className:"text-sm font-medium leading-none",htmlFor:"publicName",children:"Public Manufacturer Name *"}),e.jsx(ne,{id:"publicName",placeholder:"Company Name",...m("publicName",{}),className:S(N("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(Z,{className:"text-sm font-medium leading-none",htmlFor:"website",children:"Website *"}),e.jsx(ne,{id:"website",placeholder:"https://company.com",...m("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:S(N("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(Z,{className:"text-sm font-medium leading-none",htmlFor:"manufacturerCategories",children:"Manufacturer Categories"}),e.jsx(gi,{options:ec,selected:l,onChange:A,placeholder:"Select or type categories...",disabled:t})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{className:"text-sm font-medium leading-none",htmlFor:"customerServiceEmail",children:"Customer Service Email *"}),e.jsx(ne,{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(N("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(Z,{className:"text-sm font-medium leading-none",htmlFor:"publicResources",children:"Public Resources"}),e.jsx(ne,{id:"publicResources",placeholder:"https://resources.company.com",...m("publicResources"),readOnly:t})]}),!t&&e.jsx("div",{className:"flex justify-end",children:e.jsx(E,{type:"submit",disabled:y,className:"w-full sm:w-auto",children:y?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})]})})]})}function tc({manufacturer:s,readonly:t=!1,isLoading:a,onUnsavedChanges:r}){const{toast:n}=Pe(),[i]=_.usePostV4PartnerByApplicationIdAccountManufacturerAndFieldNameMutation(),[l,u]=o.useState({}),x=o.useMemo(()=>({partnerPortal:s?.PartnerPortal??"",partnerRegistrationLink:s?.PartnerRegistrationLink??""}),[s]),{register:d,handleSubmit:c,reset:m,watch:f,formState:{errors:p,isSubmitting:N}}=Nt.useForm({defaultValues:x}),w=f(),y=o.useCallback(()=>t||!l?!1:JSON.stringify(w)!==JSON.stringify(l),[t,w,l]);o.useEffect(()=>{r&&r(y())},[y,r]),o.useEffect(()=>{s&&(m(x),u(x))},[s,m,x]);const j=async C=>{if(t)return!1;let S=!0,A=!1;const k=[{key:"partnerPortal",apiKey:"PartnerPortal",value:C.partnerPortal},{key:"partnerRegistrationLink",apiKey:"PartnerRegistrationLink",value:C.partnerRegistrationLink}];for(const D of k){const O=D.value,M=s?.[D.apiKey];if(O!==M&&O!==void 0){A=!0;try{await i({applicationId:s?.ManufacturerId??"",fieldName:D.apiKey,newValue:String(O)}).unwrap()||(S=!1,console.error(`Failed to update ${D.apiKey}`))}catch(I){console.error(`Error updating ${D.apiKey}:`,I),S=!1}}}S&&A?(n({title:"Qualifications info",description:"Information updated successfully",variant:"success"}),u({...C}),r&&r(!1)):S?A||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(q,{children:[e.jsx(J,{children:e.jsx(ce,{className:"text-1xl font-bold",children:"Qualifications"})}),e.jsx(W,{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:c(j),className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{className:"text-sm font-medium leading-none",htmlFor:"partnerPortal",children:"Partner Portal"}),e.jsx(ne,{id:"partnerPortal",placeholder:"https://partner.example.com",...d("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(Z,{className:"text-sm font-medium leading-none",htmlFor:"partnerRegistrationLink",children:"Partner Registration Link"}),e.jsx(ne,{id:"partnerRegistrationLink",placeholder:"https://register.example.com",...d("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(E,{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 ac({manufacturerId:s,userEmail:t,isLoading:a}){const{toast:r}=Pe(),[n,i]=o.useState(null),[l,u]=o.useState(t),[x,d]=o.useState(!1),[c,m]=o.useState(),[f,p]=o.useState(),N=[{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:y}]=_.usePostV4ManufacturerByRouteManufacturerIdReportOpenOrdersEmailMutation(),[j,{isLoading:b}]=_.usePostV4ManufacturerByRouteManufacturerIdReportSalesEmailMutation(),[C,{isLoading:S}]=_.usePostV4ManufacturerByRouteManufacturerIdReportPurchasedOrdersEmailMutation(),[A,{isLoading:k}]=_.usePostV4ManufacturerByRouteManufacturerIdReportReorderEmailMutation(),[D,{isLoading:O}]=_.usePostV4ManufacturerByRouteManufacturerIdReportInventoryEmailMutation(),[M,{isLoading:I}]=_.usePostV4ManufacturerByRouteManufacturerIdReportProductsEmailMutation(),F=y||b||S||k||O||I,Q=V=>{i(V),d(!0)},$=V=>{d(V),V||(m(void 0),p(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:c?.toISOString(),endDate:f?.toISOString()}).unwrap();break;case"PurchasedOrders":await C({routeManufacturerId:s,emailAddress:l}).unwrap();break;case"Reorder":await A({routeManufacturerId:s,emailAddress:l}).unwrap();break;case"Inventory":await D({routeManufacturerId:s,emailAddress:l,inventoryDate:c?.toISOString()}).unwrap();break;case"Products":await M({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"}),$(!1)}catch(V){console.error("Error requesting report:",V),r({title:"Error",description:"Failed to request the report. Please try again.",variant:"destructive"})}},T=()=>{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(q,{children:[e.jsxs(J,{children:[e.jsx(ce,{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(W,{className:"space-y-6",children:a?Array.from({length:3}).map((V,ae)=>e.jsxs("div",{className:"space-y-4",children:[e.jsx(h,{className:"h-6 w-48"}),Array.from({length:2}).map((de,Oe)=>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"})]},Oe))]},ae)):N.map(V=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:V.name}),V.reports.map(ae=>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(ae.icon,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"text-sm font-semibold",children:ae.title}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:ae.description})]}),e.jsxs(E,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>Q(ae),children:[e.jsx(g.Download,{className:"h-4 w-4"}),"Request"]})]},ae.id))]},V.name))}),e.jsx(De,{open:x,onOpenChange:$,children:e.jsxs(Me,{children:[e.jsxs($e,{children:[e.jsxs(_e,{children:["Request ",n?.title]}),e.jsx(ze,{children:T()})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(Z,{htmlFor:"email",children:"Email"}),e.jsx(ne,{id:"email",value:l,onChange:V=>u(V.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(Bt,{label:"Start Date",id:"start-date",date:c,onDateChange:m}),e.jsx(Bt,{label:"End Date",id:"end-date",date:f,onDateChange:p})]}),n?.id==="Inventory"&&e.jsx(Bt,{label:"Inventory Date",id:"inventory-date",date:c,onDateChange:m})]}),e.jsxs(qe,{children:[e.jsx(E,{variant:"outline",onClick:()=>$(!1),children:"Cancel"}),e.jsx(E,{onClick:z,disabled:!l||F||n?.id==="Sales"&&(!c||!f)||n?.id==="Inventory"&&!c,children:F?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function rc(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"),d=n.filter(S=>S.DocumentType==="Shipment"),c=x.filter(S=>S.WarehouseCode!=="3PLE"),m=c.reduce((S,A)=>S+(A.Quantity||0),0),f=c.reduce((S,A)=>S+(A.ExtendedPrice||0),0),p=x.filter(S=>S.WarehouseCode==="3PLE"),N=p.reduce((S,A)=>S+(A.Quantity||0),0),w=p.reduce((S,A)=>S+(A.ExtendedPrice||0),0),y=d.length,j=d.reduce((S,A)=>S+(A.ExtendedPrice||0),0),b=m+N+y,C=f+w+j;return{all:{orders:b,amount:C},processing:{orders:m,amount:f},shipped:{orders:y,amount:j},delayed:{orders:N,amount:w}}})(),u=[{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(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-base font-medium text-foreground",children:"Reseller Orders"})}),e.jsxs(W,{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(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-base font-medium text-foreground",children:"Reseller Orders"})}),e.jsx(W,{children:e.jsxs(vs,{variant:"destructive",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(ws,{children:"Error"}),e.jsx(Ss,{children:"Failed to load reseller orders. Please try again later."})]})})]}):e.jsxs(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-base font-medium text-foreground",children:"Reseller Orders"})}),e.jsxs(W,{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:u.map(x=>e.jsx(q,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:e.jsxs(W,{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(us.FormattedNumber,{value:x.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},x.name))})]})]})}function nc(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 Yn({fiscalYearMonthStart:s,salesData:t,isLoading:a}){const r=t?.SalesLast30Days??0,n=t?.SalesLast3Months??0,i=t?.SalesYearToDay??0,l=nc(s);return a?e.jsxs("div",{className:"grid gap-4 @xl:grid-cols-2 @2xl:grid-cols-3 mb-4",children:[e.jsxs(q,{children:[e.jsxs(J,{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(W,{children:[e.jsx(h,{className:"h-8 w-32 mb-1"}),e.jsx(h,{className:"h-4 w-24"})]})]}),e.jsxs(q,{children:[e.jsxs(J,{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(W,{children:[e.jsx(h,{className:"h-8 w-32 mb-1"}),e.jsx(h,{className:"h-4 w-24"})]})]}),e.jsxs(q,{className:"@xl:col-span-2 @2xl:col-span-1",children:[e.jsxs(J,{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(W,{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(q,{children:[e.jsxs(J,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ce,{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(W,{children:[e.jsx("div",{className:"text-2xl font-bold",children:e.jsx(us.FormattedNumber,{value:r,style:"currency",currency:"CAD",currencyDisplay:"symbol"})}),e.jsx("p",{className:"text-xs text-muted-foreground"})]})]}),e.jsxs(q,{children:[e.jsxs(J,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ce,{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(W,{children:[e.jsx("div",{className:"text-2xl font-bold",children:e.jsx(us.FormattedNumber,{value:n,style:"currency",currency:"CAD",currencyDisplay:"symbol"})}),e.jsx("p",{className:"text-xs text-muted-foreground"})]})]}),l&&e.jsxs(q,{className:"@xl:col-span-2 @2xl:col-span-1",children:[e.jsxs(J,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsxs(ce,{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(W,{children:[e.jsx("div",{className:"text-2xl font-bold",children:e.jsx(us.FormattedNumber,{value:i,style:"currency",currency:"CAD",currencyDisplay:"symbol"})}),e.jsx("p",{className:"text-xs text-muted-foreground"})]})]})]})}const q=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("rounded-md border bg-card text-card-foreground shadow-sm",s),...t}));q.displayName="Card";const J=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("flex flex-col space-y-1.5 p-6",s),...t}));J.displayName="CardHeader";const ce=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("font-semibold leading-none tracking-tight",s),...t}));ce.displayName="CardTitle";const it=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("text-sm text-muted-foreground",s),...t}));it.displayName="CardDescription";const W=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("p-6 pt-0",s),...t}));W.displayName="CardContent";const fs=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("flex items-center p-6 pt-0",s),...t}));fs.displayName="CardFooter";const lt=P.forwardRef(({className:s,value:t,...a},r)=>e.jsx(Ca.Root,{ref:r,className:v("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",s),...a,children:e.jsx(Ca.Indicator,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(t||0)}%)`}})}));lt.displayName=Ca.Root.displayName;function ic({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((d,c)=>d+(c.InventoryValue||0),0),u=i-l,x=i>0?Math.round(l/i*100):0;return t||r||n?e.jsxs(q,{children:[e.jsxs(J,{children:[e.jsx(h,{className:"h-7 w-3/4"}),e.jsx(h,{className:"h-5 w-1/2 mt-2"})]}),e.jsxs(W,{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(q,{children:[e.jsxs(J,{children:[e.jsxs(ce,{className:"flex items-center gap-2",children:[e.jsx(g.DollarSign,{className:"h-5 w-5 text-muted-foreground"}),"Inventory Finance"]}),e.jsx(it,{children:"Current inventory financial status"})]}),e.jsxs(W,{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:oe(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:oe(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 ${u>=0?"text-success":"text-destructive"}`,children:oe(u)})]})]}),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(g.AlertCircle,{className:"h-4 w-4 text-warning"})]})}),e.jsx(fe,{children:e.jsx("p",{children:x>80?"High usage alert":"Budget usage"})})]})})]}),e.jsx(lt,{value:x,className:"h-2"})]})]})]})}function lc({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(q,{children:[e.jsxs(J,{children:[e.jsx(h,{className:"h-7 w-3/4"}),e.jsx(h,{className:"h-5 w-1/2 mt-2"})]}),e.jsxs(W,{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(q,{children:[e.jsxs(J,{children:[e.jsxs(ce,{className:"flex items-center gap-2",children:[e.jsx(g.CreditCard,{className:"h-5 w-5 text-muted-foreground"}),"Credit Finance"]}),e.jsx(it,{children:"Current credit financial status"})]}),e.jsxs(W,{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:oe(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:oe(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:oe(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(fe,{children:e.jsx("p",{children:i>80?"High credit usage alert":"Credit usage"})})]})})]}),e.jsx(lt,{value:i,className:"h-2"})]})]})]})}function ar({statistics:s,loading:t=!1,mode:a="month",chartHeight:r=300,className:n,size:i="default"}){return t?e.jsxs(q,{className:v("w-full",n),children:[e.jsx(J,{children:e.jsx(h,{className:"h-7 w-48 rounded-md"})}),e.jsxs(W,{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(q,{className:v("w-full",n),children:[e.jsx(J,{children:e.jsx(ce,{children:a==="week"?"Weekly Sales Performance":"Monthly Sales Performance"})}),e.jsx(W,{children:e.jsx(zs,{statistics:s,mode:a,chartHeight:r,size:i})})]})}function Jn({applicationId:s,readonly:t,withReports:a,manufacturer:r,userEmail:n}){const{data:i,isLoading:l,isError:u}=_.useGetV4PartnerByApplicationIdAccountManufacturerQuery({applicationId:s,withSpecification:!0},{skip:!!r}),[x,d]=o.useState({publicInfo:{hasUnsavedChanges:!1},qualifications:{hasUnsavedChanges:!1},billingInfo:{hasUnsavedChanges:!1}}),c=o.useCallback(()=>t?!1:x.publicInfo.hasUnsavedChanges||x.qualifications.hasUnsavedChanges||x.billingInfo.hasUnsavedChanges,[t,x]),m=o.useCallback((N,w)=>{d(y=>y[N]?.hasUnsavedChanges!==w.hasUnsavedChanges?(console.log(`Updating form state for ${N}:`,w.hasUnsavedChanges),{...y,[N]:w}):y)},[]),{NavigationGuardDialog:f}=Kn(c),p=r??i;return e.jsxs("div",{className:"@container",children:[u?e.jsx(q,{className:"p-6",children:e.jsxs(vs,{variant:"destructive",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(ws,{children:"Error"}),e.jsx(Ss,{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(Yn,{fiscalYearMonthStart:p?.FiscalYearMonthStart,salesData:p?.SalesData,isLoading:l}),e.jsxs("div",{className:"grid @2xl:grid-cols-2 gap-6",children:[e.jsx(ar,{statistics:p?.SalesStatistics??[],loading:l}),e.jsx(rc,{manufacturerId:p?.ManufacturerId??"",activeOrders:p?.ActiveOrderDetails??void 0,isLoading:l}),a&&e.jsx(ic,{manufacturer:p,isLoading:l}),a&&e.jsx(lc,{manufacturer:p,isLoading:l}),a&&e.jsx(pi,{manufacturer:p??{},onSave:()=>{},loading:l,readonly:t}),a&&e.jsx(sc,{manufacturer:p,readonly:t,isLoading:l,onUnsavedChanges:N=>m("publicInfo",{hasUnsavedChanges:N})}),a&&e.jsx(Xo,{manufacturer:p,readonly:t,isLoading:l}),a&&e.jsx(Zo,{manufacturer:p,readonly:t,isLoading:l,onUnsavedChanges:N=>m("billingInfo",{hasUnsavedChanges:N})}),a&&e.jsx(tc,{manufacturer:p,readonly:t,isLoading:l,onUnsavedChanges:N=>m("qualifications",{hasUnsavedChanges:N})})]}),a&&e.jsx(ac,{manufacturerId:p?.ManufacturerId??"",userEmail:n,isLoading:l})]}),e.jsx(f,{})]})}function _r({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(E,{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 oc(s){const{data:t,isLoading:a,isFetching:r}=_.useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:s.appID,manufacturerId:s.manufID,categoryCode:s.categoryCode});return e.jsx(q,{className:"w-full",children:e.jsx(W,{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(zs,{statistics:t?.SalesStatistics??[],loading:a||r,chartHeight:300})]})})})}function cc(s){return(s.categories??[]).filter(a=>a.CategoryName).map(a=>e.jsx(oc,{appID:s.appID,manufID:s.manufID,categoryCode:a.CategoryCode,categoryName:a.CategoryName},`${s.manufID}-${a.CategoryCode}`))}const Zn=tt.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"}}),he=P.forwardRef(({className:s,variant:t,size:a,icon:r,children:n,...i},l)=>e.jsxs("div",{ref:l,className:v(Zn({variant:t,size:a}),s),...i,children:[r&&e.jsx("span",{className:"mr-1",children:r}),n]}));he.displayName="Badge";function dc({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(q,{children:[e.jsx(J,{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(W,{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(q,{children:e.jsxs(W,{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(he,{variant:r?"success":"warning",className:"text-xs",children:r?"Enabled":"Disabled"})]})]})]})]})})}const As=Be.Root,uc=Be.Group,Is=Be.Value,ys=P.forwardRef(({className:s,children:t,...a},r)=>e.jsxs(Be.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(Be.Icon,{asChild:!0,children:e.jsx(g.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));ys.displayName=Be.Trigger.displayName;const rr=P.forwardRef(({className:s,...t},a)=>e.jsx(Be.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"})}));rr.displayName=Be.ScrollUpButton.displayName;const nr=P.forwardRef(({className:s,...t},a)=>e.jsx(Be.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"})}));nr.displayName=Be.ScrollDownButton.displayName;const Ns=P.forwardRef(({className:s,children:t,position:a="popper",...r},n)=>e.jsx(Be.Portal,{children:e.jsxs(Be.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(rr,{}),e.jsx(Be.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(nr,{})]})}));Ns.displayName=Be.Content.displayName;const Xn=P.forwardRef(({className:s,...t},a)=>e.jsx(Be.Label,{ref:a,className:v("px-2 py-1.5 text-sm font-semibold",s),...t}));Xn.displayName=Be.Label.displayName;const as=P.forwardRef(({className:s,children:t,...a},r)=>e.jsxs(Be.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(Be.ItemIndicator,{children:e.jsx(g.Check,{className:"h-4 w-4"})})}),e.jsx(Be.ItemText,{children:t})]}));as.displayName=Be.Item.displayName;const mc=P.forwardRef(({className:s,...t},a)=>e.jsx(Be.Separator,{ref:a,className:v("-mx-1 my-1 h-px bg-muted",s),...t}));mc.displayName=Be.Separator.displayName;function xc({applicationId:s,manufacturer:t,shopifyHostName:a}){const[r]=_.usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeShopifyMutation(),[n,i]=o.useState(()=>{const k=t.Categories?.[0]?.CategoryCode??"";if(typeof window>"u")return k;const D=new URLSearchParams(window.location.search).get("category")?.trim();return D&&t.Categories?.some(M=>M.CategoryCode===D)?D:k}),[l,u]=o.useState(!1),[x,d]=o.useState(!1),[c,m]=o.useState("percentile"),[f,p]=o.useState(!1),{toast:N}=Pe(),{data:w,isLoading:y,isFetching:j}=_.useGetV4ResellerByRouteResellerIdManufacturerAndManufacturerIdCategoryCodeQuery({routeResellerId:s,manufacturerId:t.ManufacturerId,categoryCode:n??""},{skip:!t.ManufacturerId||!n}),b=async()=>{try{u(!0),d(!1),await r({routeResellerId:s,manufacturerId:t.ManufacturerId??"",categoryCode:n,shopifyHostName:a}).unwrap()&&N({title:"Success",description:"Category synced to Shopify successfully",variant:"success"})}catch(k){console.error("Error syncing to Shopify:",k),N({title:"Error",description:"Error syncing category to Shopify.",variant:"destructive"})}finally{u(!1)}},C=()=>t.Categories?.find(k=>k.CategoryCode===n)?.CategoryName||n,S=o.useMemo(()=>w?.Products?[...w.Products].sort((k,D)=>c==="price-asc"?(k.MAP??0)-(D.MAP??0):c==="price-desc"?(D.MAP??0)-(k.MAP??0):c==="name"?(k.Title??"").localeCompare(D.Title??""):c==="percentile"?(D.OverallPercentileRank??0)-(k.OverallPercentileRank??0):0):[],[w?.Products,c]),A=o.useMemo(()=>f?S.filter(k=>{const D=k.Distribution?.Inventory;return!Array.isArray(D)||D.length===0?!1:D.reduce((M,I)=>M+(I?.AvailableQuantity??0),0)>0}):S,[f,S]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx(_r,{categories:t.Categories||[],activeCategory:n,onSelectCategory:i}),e.jsx("div",{className:"mb-4 w-full",children:e.jsx(dc,{name:C(),niche:w?.Niche||"",productsNumber:w?.Products?.length||0,autoreorder:w?.AutoReorder||!1,starred:w?.Starred||!1,isLoading:y||j,children:a&&t.Categories?.findIndex(k=>k.AvailableToBuy)!==-1&&e.jsx(E,{className:"bg-success text-success-foreground hover:bg-success/90",disabled:l,onClick:()=>d(!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(cc,{categories:[t.Categories?.find(k=>k.CategoryCode===n)].filter(Boolean),manufID:t.ManufacturerId,appID:s}),e.jsx(oi,{orders:w?.ActiveOrderDetails??void 0,loading:y||j})]})]}),e.jsx(_r,{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(As,{value:c,onValueChange:m,children:[e.jsx(ys,{className:"w-[220px]",children:e.jsx(Is,{})}),e.jsxs(Ns,{children:[e.jsx(as,{value:"price-asc",children:"MAP: Low to High"}),e.jsx(as,{value:"price-desc",children:"MAP: High to Low"}),e.jsx(as,{value:"name",children:"Name"}),e.jsx(as,{value:"percentile",children:"Best Selling"})]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ds,{id:"in-stock-filter",checked:f,onCheckedChange:k=>p(k===!0)}),e.jsx(Z,{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:y||j?Array.from({length:4}).map((k,D)=>e.jsx(Ht,{},D)):A.length>0?A.map(k=>e.jsx(Ht,{applicationId:s,product:k,viewProductLink:`/${s}/Product/${k.RandmarSKU}`,shopifyHostname:a},k.RandmarSKU)):e.jsxs(vs,{variant:"warning",className:"col-span-1 @md:col-span-2",children:[e.jsx(g.AlertCircleIcon,{className:"h-4 w-4"}),e.jsx(ws,{children:"Warning"}),e.jsx(Ss,{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(De,{open:x,onOpenChange:d,children:e.jsxs(Me,{children:[e.jsxs($e,{children:[e.jsx(_e,{children:"Confirm Sync to Shopify"}),e.jsxs(ze,{children:['Are you sure you want to sync the category "',C(),'" to Shopify? This will add all products in this category to your Shopify store.']})]}),e.jsxs(qe,{children:[e.jsx(E,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(E,{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 hc({applicationId:s,partnerId:t,userEmail:a,shopifyHostName:r,isSuperAdmin:n}){const{data:i,isLoading:l,isFetching:u}=_.useGetV4PartnerByRouteApplicationIdPartnerAndPartnerIdQuery({routeApplicationId:s,partnerId:t,withSpecification:!0}),{toast:x}=Pe(),[d]=_.usePostV4ResellerByRouteResellerIdManufacturerAndManufacturerIdShopifyMutation(),[c,m]=o.useState(!1),[f,p]=o.useState(!1),N=async()=>{try{m(!0),p(!1),await d({routeResellerId:s??"",manufacturerId:t??"",shopifyHostName:r}).unwrap()&&x({title:"Success",description:"Manufacturer synced to Shopify successfully",variant:"success"})}catch(b){console.error("Error syncing to Shopify:",b),x({title:"Error",description:"Error syncing manufacturer to Shopify.",variant:"destructive"})}finally{m(!1)}},w=()=>i?.Manufacturer?"products":i?.Reseller?"reseller-overview":"",y=()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("tab"),j=()=>{const b=y();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(ai,{account:i,loading:l||u,withAbout:!0,action:" "}),e.jsxs("div",{className:"grid gap-4",children:[(i?.Manufacturer||l||u)&&e.jsx(et,{manufacturer:i?.Manufacturer,loading:l||u,mainAction:e.jsxs(e.Fragment,{children:[i?.Manufacturer&&e.jsx(mr,{applicationId:s,manufacturer:i?.Manufacturer}),r&&i?.Manufacturer?.Categories?.findIndex(b=>b.AvailableToBuy)!==-1&&e.jsxs(De,{open:f,onOpenChange:p,children:[e.jsx(Zs,{asChild:!0,children:e.jsx(E,{className:"ml-2 bg-success text-success-foreground hover:bg-success/90",disabled:c,children:c?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($e,{children:[e.jsx(_e,{children:"Confirm Sync to Shopify"}),e.jsxs(ze,{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(qe,{children:[e.jsx(E,{variant:"outline",onClick:()=>p(!1),children:"Cancel"}),e.jsx(E,{className:"bg-success text-success-foreground hover:bg-success/90",onClick:N,disabled:c,children:c?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(ri,{reseller:i?.Reseller,loading:l||u})]})]}),(i?.Reseller||i?.Manufacturer)&&!l&&!u&&e.jsx("div",{className:"w-full p-4 sm:p-6",children:e.jsxs(tr,{defaultValue:j(),className:"w-full",children:[e.jsxs(Kt,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[i?.Reseller&&e.jsx(Je,{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(Je,{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(Je,{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(Je,{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(ts,{value:"reseller-overview",children:e.jsx("div",{className:"mt-4",children:e.jsx(ti,{readonly:!0,appID:i.ApplicationId||"",reseller:i?.Reseller,userEmail:a,isSuperAdmin:n,withoutReports:!0})})}),i?.Manufacturer&&e.jsx(ts,{value:"manufacturer-overview",children:e.jsx("div",{className:"mt-4",children:e.jsx(Jn,{readonly:!0,manufacturer:i?.Manufacturer,applicationId:s,userEmail:a})})}),i?.Manufacturer&&e.jsx(ts,{value:"products",children:e.jsx("div",{className:"mt-4",children:e.jsx(xc,{applicationId:s,manufacturer:i.Manufacturer,shopifyHostName:r})})})]})}),(l||u)&&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 fc=({reseller:s,appID:t,isLoading:a,readonly:r,onUnsavedChanges:n})=>{const{toast:i}=Pe(),[l]=_.usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),[u,x]=o.useState({}),d=o.useMemo(()=>({publicEmail:s.PublicEmail??"",contactName:s.ContactName??"",phone:s.Phone??"",website:s.Website??""}),[s]),{register:c,handleSubmit:m,reset:f,watch:p,formState:{errors:N,isSubmitting:w}}=Nt.useForm({defaultValues:d}),y=p(),j=o.useCallback(()=>u?JSON.stringify(y)!==JSON.stringify(u):!1,[y,u]);o.useEffect(()=>{n&&n(j())},[j,n]),o.useEffect(()=>{s&&Object.keys(s).length>0&&(f(d),x(d))},[s,f,d]);const b=async S=>{let A=!0,k=!1;const D=Object.keys(S).map(O=>({key:O,keyApi:O.charAt(0).toUpperCase()+O.slice(1)}));for(const O of D){const M=S[O.key],I=s[O.keyApi];if(M!==I&&M!==void 0){k=!0;try{await l({applicationId:t,fieldName:O.keyApi,newValue:String(M)}).unwrap()||(A=!1)}catch(F){console.error(`Error updating ${O.keyApi}:`,F),A=!1}}}A&&k?(i({title:"Public info",description:"Information updated successfully",variant:"success"}),x({...S}),n&&n(!1)):A||i({title:"Updation error",description:"Failed to update",variant:"destructive"})},C=S=>!S||S.trim()==="";return a?e.jsxs(q,{children:[e.jsx(J,{children:e.jsx(ce,{children:"Public Information"})}),e.jsx(W,{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(q,{children:[e.jsx(J,{children:e.jsxs(ce,{className:"text-1xl font-bold",children:["Public Information ",r?"(read only)":""]})}),e.jsxs(W,{children:[(C(p("contactName"))||C(p("publicEmail"))||C(p("website"))||C(p("phone")))&&e.jsxs(vs,{variant:"destructive",className:"mb-6",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(ws,{children:"Missing information"}),e.jsx(Ss,{children:"All fields are required to get started at working with Manufacturers."})]}),e.jsxs("form",{onSubmit:m(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(ne,{id:"contactName",placeholder:"John Doe",readOnly:r,...c("contactName",{}),className:N.contactName||C(p("contactName"))?"input-error-indicator":""}),N.contactName&&e.jsx("p",{className:"text-destructive text-sm",children:N.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(ne,{id:"publicEmail",placeholder:"contact@company.com",readOnly:r,...c("publicEmail",{pattern:{value:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,message:"Invalid email address"}}),className:N.publicEmail||C(p("publicEmail"))?"input-error-indicator":""}),N.publicEmail&&e.jsx("p",{className:"text-destructive text-sm",children:N.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(ne,{id:"website",placeholder:"https://company.com",readOnly:r,...c("website",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:N.website||C(p("website"))?"input-error-indicator":""}),N.website&&e.jsx("p",{className:"text-destructive text-sm",children:N.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(ne,{id:"phone",placeholder:"+1 (555) 123-4567",readOnly:r,...c("phone",{pattern:{value:/^.{7,}$/,message:"Must be at least 7 characters"}}),className:N.phone||C(p("phone"))?"input-error-indicator":""}),N.phone&&e.jsx("p",{className:"text-destructive text-sm",children:N.phone.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(E,{type:"submit",disabled:w||r,className:r?"hidden":"",children:w?"Saving...":"Save"})})]})]})]})};function pc({appID:s,reseller:t,isLoading:a,withoutReports:r,userEmail:n,isSuperAdmin:i}){const{toast:l}=Pe(),{Statement:u,CreditLimit:x}=t,[d,c]=o.useState(!1),[m,f]=o.useState(!1),[p,N]=o.useState(!1),[w,y]=o.useState(!1),[j,b]=o.useState(n||""),[C,S]=o.useState(!1),[A,k]=o.useState(x?.toString()||""),[D,{isLoading:O}]=_.usePostV4PartnerByApplicationIdAccountResellerCreditLimitMutation(),M=[{label:"0 - 30 Days",value:e.jsx(us.FormattedNumber,{value:u?.Over0||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:g.Calendar},{label:"31 - 45 Days",value:e.jsx(us.FormattedNumber,{value:u?.Over30||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:g.CalendarDays},{label:"45+ Days",value:e.jsx(us.FormattedNumber,{value:u?.Over45||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:g.CalendarRange},{label:"Total",value:e.jsx(us.FormattedNumber,{value:u?.Total||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),icon:g.DollarSign},{label:"Credit Limit",value:e.jsxs(e.Fragment,{children:[e.jsx(us.FormattedNumber,{value:x||0,style:"currency",currency:"CAD",currencyDisplay:"symbol"}),i&&e.jsx(E,{size:"icon",variant:"outline",className:"ml-2",onClick:()=>{S(!0),k(x?.toString()||"")},children:e.jsx(g.EditIcon,{})})]}),icon:g.CreditCard}],[I]=_.useLazyGetV4ResellerByRouteResellerIdDocumentAndDocumentNumberPdfQuery(),F=async T=>{T?c(!0):f(!0);try{const ae=(await I({routeResellerId:s,documentNumber:`ST${s}`})).data;if(!ae)throw new Error("No data received for download.");if(T)window.open(ae);else{const de=document.createElement("a");de.href=ae,de.download=`ST${s}.pdf`,document.body.appendChild(de),de.click(),de.remove()}l({title:"Success",description:"Statement downloaded successfully.",variant:"success"})}catch(V){console.error("Download Error:",V),l({title:"Error",description:"An error occurred while downloading the statement. Please try again.",variant:"destructive"})}finally{T?c(!1):f(!1)}},[Q]=_.usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),$=async()=>{if(!j||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(j)){l({title:"Invalid Email",description:"Please enter a valid email address.",variant:"destructive"});return}N(!0);try{await Q({routeResellerId:s,emailAddress:j}).unwrap(),l({title:"Success",description:`Statement sent to ${j} successfully.`,variant:"success"}),y(!1)}catch(V){console.error("Send Email Error:",V),l({title:"Error",description:"An error occurred while sending the statement. Please try again.",variant:"destructive"})}finally{N(!1)}};if(a)return e.jsxs(q,{className:"w-full",children:[e.jsx(J,{className:"border-b p-6 md:p-5",children:e.jsx(h,{className:"h-6 w-36"})}),e.jsxs(W,{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(T=>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"})]},T))}),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(T=>e.jsx("div",{className:T===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"})]})},T))})]}),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(q,{className:"w-full",children:[e.jsx(J,{className:"border-b p-6 md:p-5",children:e.jsx(ce,{className:"text-1xl font-bold",children:"Billing Overview"})}),e.jsxs(W,{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:M.slice(0,3).map((T,V)=>e.jsx(Vr,{icon:T.icon,label:T.label,value:T.value},V))}),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:M.slice(3).map((T,V)=>e.jsx("div",{className:V===1?"pt-6 mt-6 border-t border-border":"",children:e.jsx(Vr,{icon:T.icon,label:T.label,value:T.value})},V))})]}),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(E,{variant:"outline",size:"icon",onClick:()=>F(!0),disabled:d,children:d?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.Printer,{className:"h-4 w-4"})})}),e.jsx(fe,{children:e.jsx("p",{children:"Print Statement"})})]})}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"icon",onClick:()=>F(!1),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(fe,{children:e.jsx("p",{children:"Download Statement"})})]})}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"icon",onClick:()=>y(!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(fe,{children:e.jsx("p",{children:"Email Statement"})})]})}),e.jsx(Ce.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(E,{children:[e.jsx(g.CreditCard,{className:"mr-2 h-4 w-4"}),"Pay Invoices"]})})]})]})]}),e.jsx(De,{open:w,onOpenChange:y,children:e.jsxs(Me,{className:"sm:max-w-[425px]",children:[e.jsxs($e,{children:[e.jsx(_e,{children:"Send Statement by Email"}),e.jsx(ze,{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(Z,{htmlFor:"email",className:"text-right",children:"Email"}),e.jsx(ne,{id:"email",type:"email",value:j,onChange:T=>b(T.target.value),className:"col-span-3",placeholder:"recipient@example.com"})]})}),e.jsx(qe,{children:e.jsx(E,{type:"submit",onClick:$,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:C,onOpenChange:S,children:e.jsxs(Me,{className:"sm:max-w-[425px]",children:[e.jsxs($e,{children:[e.jsx(_e,{children:"Edit Credit Limit"}),e.jsx(ze,{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(Z,{htmlFor:"creditLimit",className:"text-right",children:"Amount"}),e.jsx(ne,{id:"creditLimit",type:"number",value:A,onChange:T=>k(T.target.value),className:"col-span-3",placeholder:"0.00"})]})}),e.jsx(qe,{children:e.jsx(E,{type:"submit",onClick:async()=>{const T=Number(A);if(isNaN(T)){l({title:"Invalid Amount",description:"Please enter a valid number for credit limit.",variant:"destructive"});return}try{await D({applicationId:s,newValue:T}).unwrap(),S(!1),l({title:"Success",description:"Credit limit updated successfully.",variant:"success"})}catch(V){console.error("Update Credit Limit Error:",V),l({title:"Error",description:"Failed to update credit limit. Please try again.",variant:"destructive"})}},disabled:O,children:O?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})})]})})]})}function Vr({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 gc({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($e,{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(qe,{children:[e.jsx(E,{variant:"outline",onClick:i,disabled:n,children:"Cancel"}),e.jsx(E,{onClick:r,disabled:n,children:n?"Loading...":`Apply for ${a}`})]})]})})}const jc=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,bc=s=>s==="A"?"Free or Custom":s==="B"?"Fixed $10 anywhere":s==="C"?`Free shipping on $150+ orders to your location,
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,yc=s=>s==="STRIPE"?"Credit card payment":s==="NET30"?"Net 30 days":s,Nc=({isSuperAdmin:s,readonly:t,reseller:a,appID:r,isLoading:n})=>{const{toast:i}=Pe(),[l,u]=o.useState(!1),[x,d]=o.useState(""),[c,{isLoading:m}]=_.usePostV4PartnerByApplicationIdAccountResellerAndFieldNameMutation(),f=T=>T&&{Starter:"starter","E-Commerce":"ecommerce",Commercial:"commercial",Basics:"cws",Novexco:"novexco",COOPSCO:"coopsco","Jean Coutu":"jeancoutu",Exclusive:"exclusive"}[T]||"",p=T=>T&&{A:"free",B:"fixed",C:"dropshipped",D:"under1500",E:"fullcharges"}[T]||"",N=T=>T&&{1:"exclusive",2:"ecommerce",3:"commercial",4:"buyinggroup",5:"cost"}[T]||"",[w,y]=o.useState(f(a?.Priority??"")),[j,b]=o.useState(p(a?.ShippingProfile??"")),[C,S]=o.useState(N(a?.PriceProfile)),A=T=>({starter:"Starter",ecommerce:"E-Commerce",commercial:"Commercial",cws:"Basics",novexco:"Novexco",coopsco:"COOPSCO",jeancoutu:"Jean Coutu",exclusive:"Exclusive"})[T]||T,k=T=>({free:"A",fixed:"B",dropshipped:"C",under1500:"D",fullcharges:"E"})[T]||T,D=T=>({exclusive:"1",ecommerce:"2",commercial:"3",buyinggroup:"4",cost:"5"})[T]||T;o.useEffect(()=>{y(f(a?.Priority??"")),b(p(a?.ShippingProfile??"")),S(N(a?.PriceProfile))},[a]);const O=async(T,V,ae,de)=>{try{(await c({applicationId:r,fieldName:T,newValue:V})).error?i({title:"Error",description:de,variant:"destructive"}):i({title:"Success",description:ae,variant:"success"})}catch{i({title:"Error",description:"An unexpected error occurred",variant:"destructive"})}},M=async T=>{y(T);const V=A(T);O("Priority",V,`Priority updated to ${V}`,"Failed to update priority")},I=async T=>{b(T);const V=k(T);O("ShippingProfile",V,`Shipping profile updated to ${V}`,"Failed to update shipping profile")},F=async T=>{S(T);const V=D(T);O("PriceProfile",V,`Pricing profile updated to ${V}`,"Failed to update pricing profile")},Q=async()=>{try{const T=await c({applicationId:r,fieldName:"Tier",newValue:x});T.error?i({title:"Error",description:"Failed to update reseller",variant:"destructive"}):T.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{u(!1),d("")}},$=[{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=T=>{d(T),u(!0)};return n?e.jsxs(q,{className:"w-full",children:[e.jsx(J,{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(W,{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(T=>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"})]})]},T))}),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(q,{className:"w-full",children:[e.jsxs(J,{className:"pb-2 pt-4 px-4 flex flex-row items-center justify-between",children:[e.jsx(ce,{className:"text-base font-medium text-foreground",children:"Account Tier"}),e.jsx(he,{variant:"success",className:"text-xs",children:"Active"})]}),e.jsxs(W,{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:jc(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:bc(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:yc(a?.Terms||"")})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[!t&&e.jsx(E,{variant:"outline",className:"flex-1",asChild:!0,children:e.jsxs(Ce.Link,{to:"https://randmar.io/pricing",target:"_blank",children:[e.jsx(g.ExternalLink,{className:"h-4 w-4 mr-1"}),"Pricing Tiers"]})}),e.jsxs(Ct,{children:[e.jsx(kt,{asChild:!0,children:e.jsxs(E,{disabled:t,className:t?"hidden":"flex-1",children:["Upgrade Tier ",e.jsx(g.ChevronRight,{className:"h-3 w-3 ml-1"})]})}),e.jsx(ot,{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"}),$.map(T=>e.jsx(E,{variant:"ghost",size:"sm",className:"w-full justify-start h-8",disabled:!T.enabled,onClick:()=>z(T.name),children:T.name},T.name))]})})]})]})]})]}),e.jsx(gc,{isLoading:m,open:l,setOpen:u,tier:x,onTierChange:Q}),s&&!t&&e.jsxs(q,{className:"mt-4",children:[e.jsx(J,{className:"pb-2 pt-3 px-4",children:e.jsx(ce,{className:"text-1xl font-bold",children:"Admin Configuration"})}),e.jsx(W,{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(Z,{className:"block mb-1 text-xs font-medium",children:"Priority"}),e.jsx(Ws,{value:w,onValueChange:M,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(T=>e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(ps,{value:T.value,id:`priority-${T.value}`,className:"h-6 w-6 scale-50"}),e.jsx(Z,{htmlFor:`priority-${T.value}`,className:"cursor-pointer text-xs",children:T.label})]},T.value))})]}),e.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[e.jsx(Z,{className:"block mb-1 text-xs font-medium",children:"Shipping Profile"}),e.jsx(Ws,{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(T=>e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(ps,{value:T.value,id:`shipping-${T.value}`,className:"h-6 w-6 scale-50"}),e.jsx(Z,{htmlFor:`shipping-${T.value}`,className:"cursor-pointer text-xs",children:T.label})]},T.value))})]}),e.jsxs("div",{className:"bg-muted/30 p-2 rounded-lg",children:[e.jsx(Z,{className:"block mb-1 text-xs font-medium",children:"Pricing Profile"}),e.jsx(Ws,{value:C,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(T=>e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(ps,{value:T.value,id:`pricing-${T.value}`,className:"h-6 w-6 scale-50 antialiased"}),e.jsx(Z,{htmlFor:`pricing-${T.value}`,className:"cursor-pointer text-xs",children:T.label})]},T.value))})]})]})})]})]})};function vc({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,y)=>w+(y.Quantity??0),0),l=n.reduce((w,y)=>w+(y.ExtendedPrice??0),0),u=a.filter(w=>w.WarehouseCode==="3PLE"),x=u.reduce((w,y)=>w+(y.Quantity??0),0),d=u.reduce((w,y)=>w+(y.ExtendedPrice??0),0),c=r.reduce((w,y)=>w+(y.Quantity??0),0),m=r.reduce((w,y)=>w+(y.ExtendedPrice??0),0),f=i+x+c,p=l+d+m,N=[{name:"All",icon:g.Package,stripeClass:"bg-info/60",iconBgClass:"bg-info/90",iconTextClass:"text-info-foreground",orders:f,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:c,amount:m},{name:"Delayed",icon:g.AlertCircle,stripeClass:"bg-destructive/60",iconBgClass:"bg-destructive/90",iconTextClass:"text-destructive-foreground",orders:x,amount:d}];return t?e.jsxs(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(h,{className:"h-7 w-40"})}),e.jsx(W,{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(q,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:e.jsxs(W,{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(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-base font-medium text-foreground",children:"Order Categories"})}),e.jsx(W,{children:e.jsx("div",{className:"grid grid-cols-1 @sm:grid-cols-2 gap-3.5",children:N.map(w=>e.jsx(q,{className:"overflow-hidden rounded-md rounded-b-lg border-0 shadow-md",children:e.jsxs(W,{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(us.FormattedNumber,{value:w.amount,style:"currency",currency:"CAD",currencyDisplay:"symbol"})})]})]})]})]})},w.name))})})]})}function wc({isLoading:s,userEmail:t,appID:a}){const{toast:r}=Pe(),[n,{isLoading:i}]=_.usePostV4ResellerByRouteResellerIdReportWalmartTrackingFileEmailMutation(),[l,{isLoading:u}]=_.usePostV4ResellerByRouteResellerIdReportAmazonTrackingFileEmailMutation(),[x,{isLoading:d}]=_.usePostV4ResellerByRouteResellerIdReportOpenOrdersEmailMutation(),[c,{isLoading:m}]=_.usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[f,{isLoading:p}]=_.usePostV4ResellerByRouteResellerIdReportInvoicesEmailMutation(),[N,{isLoading:w}]=_.usePostV4ResellerByRouteResellerIdDocumentStatementEmailMutation(),[y,j]=o.useState(null),[b,C]=o.useState(t),[S,A]=o.useState(!1),[k,D]=o.useState("all"),{data:O,isLoading:M}=_.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}]}],F=async z=>{j(z),z.id==="Products"&&D("all"),A(!0)},Q=async()=>{if(!(!y||!a))try{switch(y.id){case"Products":{const z={routeResellerId:a,emailAddress:b};k&&k!=="all"&&(z.manufacturerId=k),await c(z).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 x({routeResellerId:a,emailAddress:b}).unwrap();break;case"Invoices":await f({routeResellerId:a,emailAddress:b}).unwrap();break;case"Statement":await N({routeResellerId:a,emailAddress:b}).unwrap();break;default:throw new Error("invalid report id")}r({title:"Report requested",description:`The ${y.title} will be sent to ${b} shortly.`,variant:"success"}),A(!1)}catch(z){console.error("Error requesting report:",z),r({title:"Error",description:"Failed to request report. Please try again.",variant:"destructive"})}},$=d||m||u||i||w||p;return e.jsxs(q,{children:[e.jsxs(J,{children:[e.jsx(ce,{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(W,{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(T=>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"})]},T))]},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(T=>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(T.icon,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-sm",children:T.title}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:T.description})]}),e.jsxs(E,{variant:"outline",size:"sm",className:"flex items-center gap-1",onClick:()=>F(T),children:[e.jsx(g.Download,{className:"h-4 w-4"}),"Request"]})]},T.id))]},z.name))})}),e.jsx(De,{open:S,onOpenChange:A,children:e.jsxs(Me,{children:[e.jsxs($e,{children:[e.jsxs(_e,{children:["Request ",y?.title]}),e.jsx(ze,{children:"Enter the email address where you would like to receive the report."})]}),e.jsxs("div",{className:"py-4",children:[e.jsx(Z,{htmlFor:"email",children:"Email"}),e.jsx(ne,{id:"email",value:b,onChange:z=>C(z.target.value),placeholder:"your@email.com",className:"mt-2"})]}),y?.id==="Products"&&e.jsxs("div",{className:"py-2",children:[e.jsx(Z,{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:k,onChange:z=>D(z.target.value),disabled:M,children:[e.jsx("option",{value:"all",children:"All manufacturers"}),!M&&Array.isArray(O)&&O.slice().sort((z,T)=>(z.PublicName||z.Name||"").localeCompare(T.PublicName||T.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(ze,{children:"The report will take around 5 minutes to generate."}),e.jsxs(qe,{children:[e.jsx(E,{variant:"outline",onClick:()=>A(!1),children:"Cancel"}),e.jsx(E,{onClick:Q,disabled:!b||$,children:$?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function ei({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(he,{variant:"destructive",children:[e.jsx(g.X,{className:"h-3 w-3 mr-1"}),"Do Not Sell"]})}),e.jsx(fe,{children:e.jsx("p",{children:"Qualification"})})]})}):e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsxs(he,{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(he,{variant:"secondary",size:"sm",className:"ml-1",children:s.DefaultOpportunityNumber})]})}),e.jsx(fe,{children:e.jsx("p",{children:"Qualification"})})]})})}function zs({statistics:s,mode:t="month",chartHeight:a,loading:r=!1,size:n="default"}){const[i,l]=o.useState([]),[u,x]=o.useState(!1),d=[{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 c=[];if(t==="week"){const m=new Map;s.forEach(f=>{const p=f.Day?.toString()||"";if(p.length===8){const N=parseInt(p.substring(0,4),10),w=parseInt(p.substring(4,6),10)-1,y=parseInt(p.substring(6,8),10),j=new Date(N,w,y),b=new Date(j);b.setDate(j.getDate()-j.getDay());const C=`${b.getFullYear()}-${String(b.getMonth()+1).padStart(2,"0")}-${String(b.getDate()).padStart(2,"0")}`,S=m.get(C)||{price:0,quantity:0};S.price+=f.ExtendedPrice||0,S.quantity+=f.Quantity||0,m.set(C,S)}}),c=Array.from(m).sort(([f],[p])=>f.localeCompare(p)).map(([f,p])=>({date:`${f.substring(5,7)}/${f.substring(8,10)}`,dollarVolume:p.price,unitsSold:p.quantity}))}else{const m=new Date,f=m.getFullYear(),p=m.getMonth(),N=m.getDate(),w=`${f}-${(p+1).toString().padStart(2,"0")}`,y=Array.from({length:12},(b,C)=>{const S=new Date(f,p-(11-C),1);return`${S.getFullYear()}-${(S.getMonth()+1).toString().padStart(2,"0")}`}),j=Object.fromEntries(y.map(b=>[b,{price:0,quantity:0}]));if(s.forEach(b=>{const C=String(b.Day??0);if(C.length!==8)return;const S=`${C.substring(0,4)}-${C.substring(4,6)}`;j[S]&&(j[S].price+=b.ExtendedPrice??0,j[S].quantity+=b.Quantity??0)}),c=y.map(b=>{const C=j[b],[S,A]=b.split("-").map(Number);return{date:new Date(S,A-1).toLocaleString("default",{month:"short",year:"numeric"}),dollarVolume:C.price,unitsSold:C.quantity}}),u){const b=j[w];if(b&&b.price>0&&N>0){const C=new Date(f,p+1,0).getDate();if(N<C){const S=b.price/N,A=b.quantity/N,k=S*C,D=A*C,O=c[c.length-1];O&&(O.dollarVolume=k,O.unitsSold=D)}}}}l(c)},[s,t,u,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(zn,{data:i,series:d,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(nt,{checked:u,onCheckedChange:x,id:"extrapolate-switch"}),e.jsx(Z,{htmlFor:"extrapolate-switch",children:"Extrapolate Current Month"})]}),u&&e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["* Values for ",new Date().toLocaleString("default",{month:"long"})," are projected estimates."]})]})]})}function ir({type:s,applicationId:t,publicName:a,name:r,location:n,link:i,linkNewTab:l=!0,children:u}){const[x,d]=o.useState(!1),c=f=>{f.preventDefault(),f.stopPropagation(),navigator.clipboard.writeText(t),d(!0),setTimeout(()=>d(!1),2e3)},m=e.jsxs(J,{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(hs,{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:c,children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t}),x?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(fe,{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})]})]}),u&&e.jsx("div",{className:"flex flex-col items-end gap-2",children:u})]});return i?e.jsx(Ce.Link,{to:i,target:l?"_blank":"_self",children:m}):m}function et({manufacturer:s,link:t,linkNewTab:a=!0,actions:r,mainAction:n,loading:i=!1,appID:l}){const{toast:u}=Pe(),[x,{isLoading:d}]=_.usePostV4ResellerByRouteResellerIdReportProductsEmailMutation(),[c,m]=o.useState(!1),[f,p]=o.useState(""),{data:N}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:l||""},{skip:!l}),w=N?.IsReseller;if(i||!s)return e.jsxs(q,{className:"flex flex-col h-full",children:[e.jsxs(J,{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(W,{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(fs,{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 y=[s.City,s.Province,s.Country].filter(Boolean),j=y.length>0?y.join(", "):"",b=s.Tags?.split(",").map(S=>S.trim()).filter(Boolean)||[],C=async()=>{if(!(!s?.ManufacturerId||!l||!f))try{await x({routeResellerId:l,emailAddress:f,manufacturerId:s.ManufacturerId}).unwrap(),u({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),u({title:"Error",description:"Failed to request product list. Please try again.",variant:"destructive"})}};return e.jsxs(q,{className:"flex flex-col h-full",children:[e.jsx(ir,{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(zs,{statistics:s.SalesStatistics,size:"mini"})})})}),e.jsx(W,{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(ei,{qualification:s.Qualification??{}}),!!s.OpenToWork&&e.jsxs(he,{variant:"success",children:[e.jsx(g.HardHat,{className:"h-3 w-3 mr-1"}),"Open To Work"]}),!!s.OnHold&&s.OnHold!==0&&e.jsx(he,{variant:"warning",children:"On Hold"}),b.map((S,A)=>e.jsx(he,{variant:"outline",children:S},A))]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[s.Phone&&e.jsxs(Ce.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(Ce.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(Ce.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?oe(s.SalesData.SalesYearToDay):"—"}),e.jsx("strong",{className:"mt-2",children:"3 mo."}),e.jsx("p",{children:s.SalesData.SalesLast3Months?oe(s.SalesData.SalesLast3Months):"—"}),e.jsx("strong",{className:"mt-2",children:"30 days"}),e.jsx("p",{children:s.SalesData.SalesLast30Days?oe(s.SalesData.SalesLast30Days):"—"})]})]})}),(r||n||s.PublicResourcesLink||w&&l&&s.ManufacturerId||t)&&e.jsxs(fs,{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(E,{size:"icon",onClick:()=>m(!0),disabled:d,children:d?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(g.Download,{className:"h-4 w-4"})})}),e.jsx(fe,{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(Ce.Link,{to:s.PublicResourcesLink,target:"_blank",children:e.jsx(E,{size:"icon",children:e.jsx(g.BookOpen,{className:"h-4 w-4"})})})}),e.jsx(fe,{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:c,onOpenChange:m,children:e.jsxs(Me,{children:[e.jsxs($e,{children:[e.jsx(_e,{children:"Request Universal Product List"}),e.jsx(ze,{children:"Enter the email address where you would like to receive the report."})]}),e.jsxs("div",{className:"py-4",children:[e.jsx(Z,{htmlFor:"email",children:"Email"}),e.jsx(ne,{id:"email",value:f,onChange:S=>p(S.target.value),placeholder:"your@email.com",className:"mt-2"})]}),e.jsx(ze,{children:"The report will take around 5 minutes to generate."}),e.jsxs(qe,{children:[e.jsx(E,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),e.jsx(E,{onClick:C,disabled:!f||d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Report"})]})]})})]})}function si({applicationId:s,randmarSku:t,inventory:a,buttonSize:r="default",buttonClassName:n}){const i=o.useRef(null),l=Gt({elementRef:i,threshold:.1,rootMargin:"100px",freezeOnceVisible:!0}),{toast:u}=Pe(),[x,d]=o.useState(!1),[c,m]=o.useState(!1),[f,p]=o.useState(!1),{data:N,isLoading:w,isFetching:y}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:s},{skip:!s||!l}),{data:j,isLoading:b,isFetching:C}=_.useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:s,randmarSku:t,withSpecification:!1},{skip:!!a||!l}),[S]=_.usePutV4ResellerByRouteResellerIdProductAndRandmarSkuRequisitionMutation(),A=a??j?.Distribution?.Inventory;o.useEffect(()=>{d(!1)},[t]);const{inventoryQuantity:k,totalIncomingQuantity:D}=o.useMemo(()=>{if(!A||A.length===0)return{inventoryQuantity:0,totalIncomingQuantity:0};const F=A.reduce(($,z)=>$+(z.AvailableQuantity||0),0),Q=A.reduce(($,z)=>$+(z.PurchaseOrderQuantity||0),0);return{inventoryQuantity:F,totalIncomingQuantity:Q}},[A]);if(w||y||b||C)return e.jsx("div",{ref:i,children:e.jsx(h,{className:v("h-10 w-36 rounded-md",n)})});const M=()=>{f||!N?.IsReseller||(p(!0),S({routeResellerId:s??"",randmarSku:t??""}).then(F=>{F.error||F.data===!1?u({title:"Warning",description:"Reorder is pending or requires manual approval. Contact the Randmar team for details.",variant:"warning"}):u({title:"Success",description:"Qualification successfully submitted.",variant:"success"}),m(!1)}).catch(F=>{console.error(F),u({title:"Error",description:"Error submitting your qualification.",variant:"destructive"})}).finally(()=>{p(!1)}))};if(!A)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(E,{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(fe,{children:e.jsx("p",{children:"No inventory data could be found for this product."})})]})})});if(N?.IsReseller&&k<=0&&D<=0)return e.jsx("div",{ref:i,children:e.jsxs(De,{open:c,onOpenChange:m,children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(E,{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($e,{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(E,{variant:"outline",onClick:()=>m(!1),disabled:f,children:"Cancel"}),e.jsx(E,{onClick:M,disabled:f,children:f?e.jsxs(e.Fragment,{children:[e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin mr-2"}),"Requesting..."]}):"Confirm"})]})]})]})});const I=k<=0&&D>0;return e.jsx("div",{ref:i,children:e.jsxs(De,{open:x,onOpenChange:d,children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:r,className:v("text-sm",I?"text-info":k>0?"text-success":"text-destructive",n),children:[e.jsx(g.LucideWarehouse,{size:"16",className:"mr-2"}),I?e.jsxs(e.Fragment,{children:[ds(D)," Incoming"]}):k>0?e.jsxs(e.Fragment,{children:[ds(k)," in stock"]}):e.jsx(e.Fragment,{children:"Out of stock"})]})}),e.jsxs(Me,{className:"max-w-4xl",children:[e.jsx($e,{children:e.jsxs(_e,{className:"flex items-center",children:[e.jsx(g.LucideWarehouse,{className:"mr-2",size:18}),"Inventory Information"]})}),e.jsx(La,{inventory:A})]})]})})}function yt({applicationId:s,orders:t=null,loading:a=!1,title:r="Order Details"}){const n=o.useMemo(()=>[{accessorKey:"OrderNumber",header:"Order Number",cell:({row:u})=>u.original.OrderNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(Ce.Link,{to:`/${s}/GeneralDocument/${u.original.OrderNumber}`,className:"font-medium text-primary hover:underline",children:u.original.OrderNumber})}),e.jsx(fe,{children:e.jsxs("p",{children:["View details for order ",u.original.OrderNumber]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentNumber",header:"Document Number",cell:({row:u})=>u.original.DocumentNumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"DocumentDate",header:"Document Date",cell:({row:u})=>Js(u.original.DocumentDate),enableSorting:!0,enableFiltering:!1},{accessorKey:"PONumber",header:"PO Number",cell:({row:u})=>u.original.PONumber??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseCode",header:"Warehouse",cell:({row:u})=>u.original.WarehouseCode??"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"MPN",header:"MPN",cell:({row:u})=>u.original.MPN?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(Ce.Link,{to:`/${s}/Product/${u.original.MPN}`,className:"font-medium text-primary hover:underline",children:u.original.MPN})}),e.jsx(fe,{children:e.jsxs("p",{children:["View details for MPN ",u.original.MPN]})})]})}):"N/A",enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:u})=>u.original.Quantity??"N/A",enableSorting:!0,enableFiltering:!1},{accessorKey:"ShipToName",header:"Name",cell:({row:u})=>e.jsx("div",{className:"min-w-[150px]",children:u.original.ShipToName??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:u})=>u.original.UnitPrice?oe(u.original.UnitPrice):"N/A",enableSorting:!0,enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:u})=>e.jsx("div",{className:"flex space-x-2",children:e.jsx(si,{applicationId:s,randmarSku:u.original.RandmarSKU??"",buttonSize:"sm"})})}],[s]),i=o.useMemo(()=>{const u={};if(t){const x=Array.from(new Set(t.map(N=>N.WarehouseCode).filter(N=>N!=null)));u.WarehouseCode=x;const d=Array.from(new Set(t.map(N=>N.ShipToName).filter(N=>N!=null)));u.ShipToName=d;const c=Array.from(new Set(t.map(N=>N.DocumentNumber).filter(N=>N!=null)));u.DocumentNumber=c;const m=Array.from(new Set(t.map(N=>N.OrderNumber).filter(N=>N!=null)));u.OrderNumber=m;const f=Array.from(new Set(t.map(N=>N.PONumber).filter(N=>N!=null)));u.PONumber=f;const p=Array.from(new Set(t.map(N=>N.MPN).filter(N=>N!=null)));u.MPN=p}return u},[t]),l=t||[];return a?e.jsxs(q,{className:"w-full",children:[e.jsxs(J,{children:[" ",e.jsx(h,{className:"h-7 w-48"})," "]}),e.jsxs(W,{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(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-1xl font-bold",children:r})}),e.jsx(W,{children:e.jsx(Ms,{columns:n,data:l,uniqueValues:i})})]})}function ti({appID:s,reseller:t,readonly:a,userEmail:r,isSuperAdmin:n,withoutReports:i=!1,loadFullAfterSummary:l=!1}){const u=`${s}|${l?1:0}`,x=o.useRef(u),[d,c]=o.useState(()=>l?!!t:!1);o.useEffect(()=>{x.current!==u&&(x.current=u,c(!1))},[u]),o.useEffect(()=>{l&&t&&c(!0)},[l,t]);const m=l?d:!t,{data:f,isLoading:p,isError:N}=_.useGetV4PartnerByApplicationIdAccountResellerQuery({applicationId:s??"",withSpecification:!0},{skip:!s||!m}),[w,y]=o.useState({publicInfo:{hasUnsavedChanges:!1}}),j=o.useCallback(()=>a?!1:w.publicInfo.hasUnsavedChanges,[a,w]),b=o.useCallback((I,F)=>{y(Q=>Q[I]?.hasUnsavedChanges!==F.hasUnsavedChanges?{...Q,[I]:F}:Q)},[]),{NavigationGuardDialog:C}=Kn(j),S=f??t,A=p&&!S,k=N&&!S,D=!a||!!S?.Statement&&(S.Statement.Total??0)!==0,O=S?.QualifiedManufacturers??[],M=S?.Qualifications??[];return e.jsxs("div",{className:"@container",children:[k?e.jsx(q,{className:"p-6",children:e.jsxs(vs,{variant:"destructive",children:[e.jsx(g.AlertCircle,{className:"h-4 w-4"}),e.jsx(ws,{children:"Error"}),e.jsx(Ss,{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(Yn,{fiscalYearMonthStart:S?.FiscalYearMonthStart||1,salesData:S?.SalesData,isLoading:A}),e.jsxs("div",{className:"grid @lg:grid-cols-2 gap-6",children:[e.jsx(ar,{statistics:S?.SalesStatistics??[],loading:A}),e.jsx(vc,{openOrders:S?.ActiveOrderDetails??[],isLoading:A}),D&&e.jsx(pc,{appID:s,reseller:S||{},withoutReports:i,isLoading:A,userEmail:r,isSuperAdmin:n}),e.jsx(fc,{reseller:S||{},appID:s??"",isLoading:A,readonly:a,onUnsavedChanges:I=>b("publicInfo",{hasUnsavedChanges:I})}),e.jsx(Nc,{isSuperAdmin:n,readonly:a,reseller:S||{},appID:s??"",isLoading:A}),A||O.length>0?e.jsxs(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(ce,{children:"Manufacturers you are qualified for"})}),e.jsx(W,{children:e.jsx("div",{className:"grid @lg:grid-cols-2 gap-4",children:A?Array.from({length:2}).map((I,F)=>e.jsx(et,{loading:!0},F)):O.map(I=>e.jsx(et,{manufacturer:I,link:`https://dashboard.randmar.io/${s}/Partner/${I.ManufacturerId}`},I.ManufacturerId))})})]}):M.length>0&&e.jsx(bi,{qualifications:M})]}),(S?.Opportunities?.length??0)>0&&e.jsx(gr,{applicationId:s,opportunities:S?.Opportunities,loading:A}),(S?.ActiveOrderDetails?.length??0)>0&&e.jsx(yt,{applicationId:s,title:"Active Orders",orders:S?.ActiveOrderDetails,loading:A}),(S?.CompletedOrderDetails?.length??0)>0&&e.jsx(yt,{applicationId:s,title:"Completed Orders",orders:S?.CompletedOrderDetails,loading:A}),(S?.Returns?.length??0)>0&&e.jsx(pr,{applicationId:s,returns:S?.Returns,loading:A}),!i&&e.jsx(wc,{appID:s,userEmail:r,isLoading:A})]}),e.jsx(C,{})]})}const Sc=tt.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"}}),vs=P.forwardRef(({className:s,variant:t,...a},r)=>e.jsx("div",{ref:r,role:"alert",className:v(Sc({variant:t}),s),...a}));vs.displayName="Alert";const ws=P.forwardRef(({className:s,...t},a)=>e.jsx("h5",{ref:a,className:v("mb-1 font-medium leading-none tracking-tight",s),...t}));ws.displayName="AlertTitle";const Ss=P.forwardRef(({className:s,...t},a)=>e.jsx("div",{ref:a,className:v("text-sm [&_p]:leading-relaxed",s),...t}));Ss.displayName="AlertDescription";function Ms({columns:s,data:t,uniqueValues:a,tableClass:r,loading:n,initialSort:i}){const[l,u]=o.useState(i??[]),[x,d]=o.useState([]),[c,m]=o.useState({pageIndex:0,pageSize:10}),[f,p]=o.useState(null),N=Ps.useReactTable({data:n?[]:t,columns:s,getCoreRowModel:Ps.getCoreRowModel(),onSortingChange:u,getSortedRowModel:Ps.getSortedRowModel(),onColumnFiltersChange:d,getFilteredRowModel:Ps.getFilteredRowModel(),getPaginationRowModel:Ps.getPaginationRowModel(),onPaginationChange:m,state:{sorting:l,columnFilters:x,pagination:c},manualPagination:n,manualSorting:n,manualFiltering:n}),w=(y,j)=>{y.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(Vt,{children:[e.jsx(zt,{children:e.jsx(Ls,{children:s.map((y,j)=>e.jsx(qt,{children:e.jsx(h,{className:"h-6 w-full"})},`skeleton-header-${j}`))})}),e.jsx(Ut,{children:Array.from({length:c.pageSize}).map((y,j)=>e.jsx(Ls,{children:s.map((b,C)=>e.jsx(jt,{children:e.jsx(h,{className:"h-6 w-full"})},`skeleton-cell-${j}-${C}`))},`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(gs,{className:`rounded-md border ${r??""}`,children:[e.jsxs(Vt,{children:[e.jsx(zt,{children:N.getHeaderGroups().map(y=>e.jsx(Ls,{children:y.headers.map(j=>e.jsx(qt,{children:j.isPlaceholder?null:j.column.getCanSort()||j.column.getCanFilter()?e.jsxs(Ct,{open:f===j.id,onOpenChange:b=>p(b?j.id:null),children:[e.jsx(kt,{asChild:!0,children:e.jsxs(E,{variant:"ghost",className:"pl-0",children:[Ps.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(ot,{className:"w-56",children:e.jsxs("div",{className:"space-y-2",children:[j.column.getCanSort()&&e.jsxs(e.Fragment,{children:[e.jsxs(E,{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(E,{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(As,{onValueChange:b=>j.column.setFilterValue(b==="all"?void 0:[b]),children:[e.jsx(ys,{children:e.jsx(Is,{placeholder:`Filter ${j.column.columnDef.header}...`})}),e.jsxs(Ns,{children:[e.jsx(as,{value:"all",children:"All"}),a[j.column.id]?.map(b=>e.jsx(as,{value:b||"empty",children:b||"(Empty)"},b))]})]}):e.jsx(ne,{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:Ps.flexRender(j.column.columnDef.header,j.getContext())})},j.id))},y.id))}),e.jsx(Ut,{children:N.getRowModel().rows?.length?N.getRowModel().rows.map(y=>e.jsx(Ls,{"data-state":y.getIsSelected()&&"selected",children:y.getVisibleCells().map(j=>e.jsx(jt,{children:Ps.flexRender(j.column.columnDef.cell,j.getContext())},j.id))},y.id)):e.jsx(Ls,{children:e.jsx(jt,{colSpan:s.length,className:"h-24 text-center",children:"No results."})})})]}),e.jsx(Wt,{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(As,{value:`${N.getState().pagination.pageSize}`,onValueChange:y=>{N.setPageSize(Number(y))},children:[e.jsx(ys,{className:"h-8 w-[70px]",children:e.jsx(Is,{asChild:!0,children:e.jsx("span",{children:N.getState().pagination.pageSize})})}),e.jsx(Ns,{side:"top",children:[10,20,30,40,50].map(y=>e.jsx(as,{value:`${y}`,children:e.jsx("span",{children:y})},y))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(E,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>N.setPageIndex(0),disabled:!N.getCanPreviousPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to first page"}),e.jsx(g.ChevronsLeft,{className:"h-4 w-4"})]}),e.jsxs(E,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>N.previousPage(),disabled:!N.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:N.getState().pagination.pageIndex+1}),e.jsx("p",{className:"text-sm font-medium",children:"of"}),e.jsx("span",{className:"text-sm font-medium",children:N.getPageCount()})]}),e.jsxs(E,{variant:"outline",className:"h-8 w-8 p-0",onClick:()=>N.nextPage(),disabled:!N.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to next page"}),e.jsx(g.ChevronRight,{className:"h-4 w-4"})]}),e.jsxs(E,{variant:"outline",className:"hidden h-8 w-8 p-0 lg:flex",onClick:()=>N.setPageIndex(N.getPageCount()-1),disabled:!N.getCanNextPage(),children:[e.jsx("span",{className:"sr-only",children:"Go to last page"}),e.jsx(g.ChevronsRight,{className:"h-4 w-4"})]})]})]})]})}function ai({account:s,action:t,loading:a=!1,className:r,withAbout:n=!1}){return a||!s?e.jsxs(q,{className:`flex flex-col h-full ${r}`,children:[e.jsx(J,{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(W,{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(fs,{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(q,{className:`flex flex-col h-full ${r}`,children:[e.jsx(ir,{type:"Partner",applicationId:s.ApplicationId,publicName:s.PublicName}),e.jsx(W,{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(he,{variant:"info",children:"Manufacturer"}),s.IsReseller&&e.jsx(he,{variant:"success",children:"Reseller"}),s.IsSalesAgency&&e.jsx(he,{variant:"outline",children:"Agency"}),s.HasShopifyStore&&e.jsx(he,{variant:"secondary",children:"Shopify"}),s.IsVendor&&e.jsx(he,{variant:"outline",children:"Vendor"})]}),n&&s.About&&e.jsx("div",{className:"prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:s.About??""}})]})}),e.jsx(fs,{className:"px-6 py-4 flex justify-end gap-2 mt-auto",children:t||e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(g.ExternalLink,{className:"h-4 w-4"}),"Go to Partner Dashboard"]})})]})}function ri({reseller:s,link:t,linkNewTab:a=!0,actions:r,mainAction:n,loading:i=!1}){if(i||!s)return e.jsxs(q,{className:"flex flex-col h-full",children:[e.jsx(J,{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(W,{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(fs,{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),u=l.length>0?l.join(", "):"Location not provided",x=s.Priority?.trim(),d=!!s.Qualification?.QualificationId&&s.Qualification?.QualificationId!=="Suspended",c=!!s.OnHold&&s.OnHold!==0,m=!!x,f=p=>{const N=p.toLowerCase();return N.includes("starter")||N.includes("basic")?"secondary":N.includes("exclusive")||N.includes("jean coutu")||N.includes("novexco")||N.includes("coopsco")?"success":"info"};return e.jsxs(q,{className:"flex flex-col h-full",children:[e.jsx(ir,{type:"Reseller",applicationId:s.ResellerId,publicName:s.PublicName,name:s.Name,location:u,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(zs,{statistics:s.SalesStatistics,size:"mini"})})})}),e.jsx(W,{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:[(d||c||m)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[d&&e.jsx(ei,{qualification:s.Qualification??{}}),c&&e.jsx(he,{variant:"warning",children:"On Hold"}),m&&e.jsx(he,{variant:f(x),children:x})]}),e.jsxs("div",{className:"space-y-1 pt-2",children:[s.Phone&&e.jsxs(Ce.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(Ce.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(Ce.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?oe(s?.SalesData.SalesYearToDay):"—"}),e.jsx("strong",{className:"mt-2",children:"3 mo."}),e.jsx("p",{children:s?.SalesData.SalesLast3Months?oe(s?.SalesData.SalesLast3Months):"—"}),e.jsx("strong",{className:"mt-2",children:"30 days"}),e.jsx("p",{children:s?.SalesData.SalesLast30Days?oe(s?.SalesData.SalesLast30Days):"—"})]})]})}),(r||n)&&e.jsxs(fs,{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 Vt=P.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})}));Vt.displayName="Table";const zt=P.forwardRef(({className:s,...t},a)=>e.jsx("thead",{ref:a,className:v("[&_tr]:border-b",s),...t}));zt.displayName="TableHeader";const Ut=P.forwardRef(({className:s,...t},a)=>e.jsx("tbody",{ref:a,className:v("[&_tr:last-child]:border-0",s),...t}));Ut.displayName="TableBody";const ni=P.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}));ni.displayName="TableFooter";const Ls=P.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}));Ls.displayName="TableRow";const qt=P.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:P.isValidElement(t.children)&&t.children.type==="span"?t.children:e.jsx("span",{children:t.children})}));qt.displayName="TableHead";const jt=P.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:P.isValidElement(t.children)&&t.children.type==="span"?t.children:e.jsx("span",{children:t.children})}));jt.displayName="TableCell";const ii=P.forwardRef(({className:s,...t},a)=>e.jsx("caption",{ref:a,className:v("mt-4 text-sm text-muted-foreground",s),...t}));ii.displayName="TableCaption";const li="[--rm-shell-header-height:3.5rem]",Cc="h-[var(--rm-shell-header-height)]",kc="pt-[var(--rm-shell-header-height)]",lr=o.forwardRef(({onSignOut:s,handleValidSearch:t,rightMenu:a,searchPlaceholder:r},n)=>{const[i,l]=o.useState(""),u=Ce.useLocation(),{toast:x}=Pe();o.useEffect(()=>{const f=new URLSearchParams(u.search).get("q");f&&l(f)},[u.search]);const d=()=>{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)},c=m=>{m.key==="Enter"&&d()};return e.jsxs("header",{className:`fixed top-0 right-0 left-0 z-50 flex ${li} ${Cc} 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(Va,{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:d,"aria-label":"Search",children:e.jsx(g.Search,{className:"h-4 w-4"})}),e.jsx(ne,{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:c,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(E,{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"})]})})]})]})});lr.displayName="Topbar";function oi({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(y=>y.DocumentType==="Order"),i=s.filter(y=>y.DocumentType==="Shipment"),l=n.filter(y=>y.WarehouseCode!=="3PLE"),u=l.reduce((y,j)=>y+(j.Quantity||0),0),x=l.reduce((y,j)=>y+(j.ExtendedPrice||0),0),d=n.filter(y=>y.WarehouseCode==="3PLE"),c=d.reduce((y,j)=>y+(j.Quantity||0),0),m=d.reduce((y,j)=>y+(j.ExtendedPrice||0),0),f=i.length,p=i.reduce((y,j)=>y+(j.ExtendedPrice||0),0),N=u+c+f,w=x+m+p;return{all:{orders:N,amount:w},processing:{orders:u,amount:x},shipped:{orders:f,amount:p},delayed:{orders:c,amount:m}}},[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(q,{className:"@container",children:[e.jsx(J,{className:"pb-0",children:e.jsx(ce,{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(q,{className:"@container",children:[e.jsx(J,{className:"pb-0",children:e.jsx(ce,{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:oe(n.amount)})]})]})]})]},n.name))})]})}const Ds=P.forwardRef(({className:s,...t},a)=>e.jsx(ka.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(ka.Indicator,{className:v("flex items-center justify-center text-current"),children:e.jsx(g.Check,{className:"h-4 w-4"})})}));Ds.displayName=ka.Root.displayName;function ci({items:s,selectedIds:t,onSelectedIdsChange:a,disabled:r=!1,loading:n=!1,selectionMode:i="multiple",layout:l="stack",gridColumns:u=2,emptyState:x,loadingState:d,getItemAriaLabel:c,renderItem:m,className:f,...p}){const N=P.useId(),w=P.useMemo(()=>new Set(t),[t]),y=l==="grid"?v("grid gap-3",u===2&&"grid-cols-1 sm:grid-cols-2"):"space-y-3",j=P.useCallback(b=>{if(r||n||b.disabled)return;const C=w.has(b.id);if(i==="single"){a(C?[]:[b.id]);return}if(C){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(y,f),role:"status","aria-live":"polite",...p,children:d??e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:"Loading options"}),Array.from({length:l==="grid"?4:3}).map((b,C)=>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-${C}`))]})}):s.length===0?e.jsx("div",{className:v(y,f),...p,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(y,f),role:"group","aria-disabled":r||void 0,...p,children:s.map((b,C)=>{const S=w.has(b.id),A=r||b.disabled===!0,k=`${N}-${C}-label`,D=`${N}-${C}-description`;return e.jsxs("button",{type:"button",role:"checkbox","aria-checked":S,"aria-disabled":A,"aria-label":c?.(b)??b.label,"aria-labelledby":m?void 0:k,"aria-describedby":!m&&b.description?D:void 0,disabled:A,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",A&&"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:m?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:b.label}),m(b,{checked:S,disabled:A,index:C})]}):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:k,className:v("block text-sm font-medium text-foreground",(b.prefix||b.emphasis)&&"mt-1"),children:b.label}),b.description&&e.jsx("span",{id:D,className:"mt-1 block text-sm text-muted-foreground",children:b.description})]})})]},b.id)})})}const Yt=P.forwardRef(({className:s,...t},a)=>e.jsx(rs.Command,{ref:a,className:v("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s),...t}));Yt.displayName=rs.Command.displayName;const Rc=({children:s,...t})=>e.jsx(De,{...t,children:e.jsx(Me,{className:"overflow-hidden p-0",children:e.jsx(Yt,{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})})}),or=P.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(rs.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})]}));or.displayName=rs.Command.Input.displayName;const cr=P.forwardRef(({className:s,...t},a)=>e.jsx(rs.Command.List,{ref:a,className:v("max-h-[300px] overflow-y-auto overflow-x-hidden",s),...t}));cr.displayName=rs.Command.List.displayName;const dr=P.forwardRef((s,t)=>e.jsx(rs.Command.Empty,{ref:t,className:"py-6 text-center text-sm",...s}));dr.displayName=rs.Command.Empty.displayName;const ur=P.forwardRef(({className:s,...t},a)=>e.jsx(rs.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}));ur.displayName=rs.Command.Group.displayName;const di=P.forwardRef(({className:s,...t},a)=>e.jsx(rs.Command.Separator,{ref:a,className:v("-mx-1 h-px bg-border",s),...t}));di.displayName=rs.Command.Separator.displayName;const Qt=P.forwardRef(({className:s,...t},a)=>e.jsx(rs.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}));Qt.displayName=rs.Command.Item.displayName;const ui=({className:s,...t})=>e.jsx("span",{className:v("ml-auto text-xs tracking-widest text-muted-foreground",s),...t});ui.displayName="CommandShortcut";const mi=({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 Pc({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 xi({path:s,origin:t,...a}){const r=St(),n=P.useMemo(()=>js(s,t??r),[r,t,s]);return e.jsx("img",{...a,src:n})}var Aa=(s=>(s.STRING="string",s.NUMBER="number",s.BOOLEAN="boolean",s.OBJECT="object",s))(Aa||{});const Ot="TheRequestBody",Ac="Request body content";function Ic(s){return pl.md5(s).substring(0,16)}function Dc(s){const t=new Map;return s.map(a=>{const r=a.declaration.name,n=t.get(r)||0;let i=r;return n>0&&(i=`${r}_${n}`),t.set(r,n+1),{...a,declaration:{...a.declaration,name:i}}})}function Mc(s){return!!s&&"$ref"in s}function Tc(s){return!!s&&!("$ref"in s)}function Ec(s){if(!s?.content)return;const t=["application/json","application/json-patch+json","multipart/form-data","text/plain"];for(const r of t){const n=s.content[r]?.schema;if(n)return n}return Object.values(s.content).find(r=>r?.schema)?.schema}async function Oc(s){const t=s?.swaggerJsonUrl??$t,a=_t(t)??_t($t),r=js(t,a);try{const n=await fetch(r);if(!n.ok)throw new Error("Failed to fetch Swagger spec");const i=await n.json(),l=[];for(const[u,x]of Object.entries(i.paths)){const d=["get","post","put","delete"];for(const c of d){const m=x[c];if(!m||m["x-allowed-for-chatbots"]!==!0)continue;const f=u.split("/").filter(Boolean);let p;f.length>0&&f[0].toLowerCase()==="v4"?p=f.length>1?f[1]:"api":p=f.length>0?f[0]:"api",p=p.replace(/[{}]/g,"");const N=Ic(u),w=`${c}-${p.toLowerCase()}-${N}`,y={},j=[];m.parameters?.forEach(M=>{const I=M.schema?.type,F=I==="integer"||I==="number"?"number":I==="boolean"?"boolean":"string";y[M.name]={type:F,description:M.description||`The ${M.name} parameter`},M.required&&j.push(M.name)});const b=m.parameters?.filter(M=>M.in==="path").map(M=>M.name)||[];if((c==="post"||c==="put")&&m.requestBody){const M=Ec(m.requestBody),I=m.requestBody.description||Ac;if(M&&Mc(M)&&M.$ref.startsWith("#/components/schemas/")){const F=M.$ref.substring(21),Q=i.components.schemas[F],$=Tc(Q)?Q.properties:void 0,z=$?JSON.stringify($):"Refer to API schema for details.";y[Ot]={type:"string",description:`${I}. Must be a JSON string with these properties: ${z}`}}else y[Ot]={type:"string",description:I};j.push(Ot)}const C={name:w,description:m.description?`${m.summary}
49
+
50
+ ${m.description}`:m.summary||`${c.toUpperCase()} ${f[f.length-1]}`,parameters:{type:"object",properties:y,required:j}},S=async M=>{let I=u;try{b.forEach(Ne=>{const Ve=`{${Ne}}`,Ue=M[Ne];Ue!=null&&(I=I.replace(Ve,encodeURIComponent(String(Ue))))});const F=js(I,a),Q=localStorage.getItem("access_token"),$={method:c.toUpperCase(),headers:{Authorization:Q?`Bearer ${Q}`:"","Content-Type":"application/json"}},z=new URLSearchParams;(m.parameters?.filter(Ne=>Ne.in==="query")||[]).forEach(Ne=>{const Ve=Ne.name,Le=M[Ve];Le!=null&&z.set(Ne.name,String(Le))});const V=z.toString(),ae=V?`${F}${F.includes("?")?"&":"?"}${V}`:F;if(c==="post"||c==="put"){const Ve=M[Ot];Ve&&($.body=Ve)}const de=await fetch(ae,$);if(!de.ok){const Ne=await de.text();throw console.error(`[API Function] Error response: ${Ne}`),new Error(`Error ${de.status}: ${Ne}`)}const Oe=await de.text();return Oe.length>3e6?"response body dropped - it was too big to fix in the context window. Try a different function.":Oe}catch(F){return console.error(`Error in ${w}:`,F),`I'm sorry, I couldn't retrieve the requested information. Error: ${F instanceof Error?F.message:"Unknown error"}`}},A=m.tags?.[0]??"Partner",D=`${{get:"Fetching",put:"Inserting",post:"Updating",delete:"Deleting"}[c]} - ${A}.`,O=`${c} ${u}`;l.push({declaration:C,handler:S,prettyName:D,details:O})}}return Dc(l)}catch(n){return console.error("Error fetching API functions:",n),[]}}function Lc({userId:s,apiConfig:t,onGeneratedImageUploaded:a}){const[r,n]=o.useState(""),[i,l]=o.useState([]),[u,x]=o.useState([]),[d,c]=o.useState([]),[m,f]=o.useState(!1),[p,N]=o.useState([]),[w,y]=o.useState([]),[j,b]=o.useState(0),C=o.useRef(!1),S=o.useRef(null),A=o.useRef(null),k=o.useRef([]),D=o.useRef([]),O=o.useRef(new Map),[M]=_.useLazyGetV4PartnerByApplicationIdAccountQuery(),[I]=_.usePostV4PartnerByApplicationIdGenerationRandmarAssistantMutation(),[F]=_.usePostV4PartnerByApplicationIdGenerationUploadMutation();o.useEffect(()=>{const H=async()=>{f(!0);try{const K=await Oc({swaggerJsonUrl:t?.swaggerJsonUrl}),Y={declaration:{name:"set_on_behalf_id",description:"Call this function when the user wants to act on behalf of another one. It will return to you important flags such as: is user specified by the user ID a reseller, manufacturer or an agency?",parameters:{type:Aa.OBJECT,properties:{user_id:{type:Aa.STRING,description:"The user ID to use going forward."}},required:["user_id"]}},prettyName:"Fetching account details",details:"GET Partner Account",handler:async ee=>{const Re=await M({applicationId:ee.user_id});return JSON.stringify(Re.data)}};N([...K,Y])}catch(K){console.error("Error loading API functions:",K)}f(!1)};p.length===0&&!m&&H()},[t?.swaggerJsonUrl,p,m]),o.useEffect(()=>{if(r||d.length===0)return;n("Handling message...");const{input:H,attachedFiles:K,uiMessageId:Y}=d[0];c(ee=>ee.slice(1)),Ne(H,K,Y)},[r,d]),o.useEffect(()=>{D.current=w},[w]);const Q=H=>{if(!H)return!1;const K=H,Y=typeof K.name=="string"?K.name:"",ee=typeof K.message=="string"?K.message:"",pe=typeof K.error=="string"?K.error:"";return Y==="AbortError"||pe==="AbortError"||ee.toLowerCase().includes("abort")||ee.toLowerCase().includes("canceled")},$=async H=>{const K=p.find(Y=>Y.declaration.name===H.name);if(!K){const Y=`Function ${H.name} not found`;return console.error(Y),JSON.stringify({error:Y})}try{return x(Y=>[...Y,[K.prettyName,`${K.details} where ${JSON.stringify(H.args,null,2)}`]]),await K.handler(H.args)}catch(Y){const ee=`${H.name} failed.`;return console.error(ee,Y),JSON.stringify({error:ee,details:Y instanceof Error?Y.message:String(Y)})}},z=H=>{if(typeof H!="string"||H.length===0||!H.includes("Base64Data")&&!H.includes("base64Data")&&!H.includes('"Images"')&&!H.includes('"images"'))return null;let K;try{K=JSON.parse(H)}catch{return null}const Y=K;if(!Y||typeof Y!="object")return null;const ee=Y.Images??Y.images;if(!Array.isArray(ee)||ee.length===0)return null;const pe=ee.map(Ee=>{const U=Ee,me=U?.MimeType??U?.mimeType,we=U?.Base64Data??U?.base64Data;if(typeof me!="string"||typeof we!="string")return null;const Se=me.trim(),Fe=we.replace(/\s+/g,"");return!Se.startsWith("image/")||Fe.length===0?null:{mimeType:Se,base64Data:Fe}}).filter(Ee=>Ee!=null);if(pe.length===0)return null;const Re=Y.Text??Y.text;return{text:typeof Re=="string"?Re:"",images:pe}},T=H=>{const K=(H??"").toLowerCase();return K==="image/png"?"png":K==="image/jpeg"?"jpg":K==="image/webp"?"webp":K==="image/gif"?"gif":K==="image/svg+xml"?"svg":"png"},V=H=>{const K=H.replace(/^data:[^,]+,/,"").replace(/\s+/g,""),Y=atob(K),ee=new Uint8Array(Y.length);for(let pe=0;pe<Y.length;pe++)ee[pe]=Y.charCodeAt(pe);return ee},ae=async(H,K)=>{if(C.current||!H||H.length===0)return;const Y=new Date,ee=`${Y.getFullYear()}${String(Y.getMonth()+1).padStart(2,"0")}${String(Y.getDate()).padStart(2,"0")}_${String(Y.getHours()).padStart(2,"0")}${String(Y.getMinutes()).padStart(2,"0")}${String(Y.getSeconds()).padStart(2,"0")}`,pe=await Promise.allSettled(H.map(async(ve,Ee)=>{const U=T(ve.mimeType),me=`generated_${ee}_${Ee+1}.${U}`,we=V(ve.base64Data),Se=new File([we],me,{type:ve.mimeType}),Fe=F({applicationId:s,body:{file:Se}});k.current.push(Fe);try{const Xe=await Fe.unwrap();if(typeof Xe!="string"||Xe.length===0)throw new Error("Upload did not return a file URI.");return Xe}finally{k.current=k.current.filter(Xe=>Xe!==Fe)}}));if(C.current)return;const Re=pe.map(ve=>ve.status==="fulfilled"?ve.value:null).filter(ve=>typeof ve=="string"&&ve.length>0);Re.length>0&&(x(ve=>[...ve,["Generated image uploaded",Re.join(`
51
+ `)]]),a?.({assistantMessageId:K,urls:Re}))},de=async(H,K)=>{if(C.current){n("");return}if(K===0){Le({content:"I've reached my action limit for this request. Please let me know if you'd like me to continue.",timestamp:new Date}),n("");return}try{n("Thinking...");const Y=I({applicationId:s,body:H});S.current=Y;const ee=await Y.unwrap();if(S.current=null,C.current){n("");return}const pe=ee.Content,Re=[...H,pe],ve=ee.ContextUtilization??0;y(Re),b(ve);const Ee=pe.Parts?.find(me=>me.Text)?.Text;Ee&&Le({content:Ee,timestamp:new Date});const U=pe.Parts?.map(me=>me.FunctionCall).filter(Boolean)??[];if(U.length>0){n("Using Randmar API...");const me=[];for(const we of U){if(C.current){n("");return}if(we?.Name){const Se=await $({name:we.Name,args:we.Args??{}});if(C.current){n("");return}const Fe=z(Se);if(Fe){const Us=Le({content:"",images:Fe.images,timestamp:new Date});Us&&ae(Fe.images,Us)}const Xe=Fe?"image generated ok":Se;me.push({FunctionResponse:{Name:we.Name,Content:Xe}})}}if(me.length>0){const we={Role:"user",Parts:me},Se=[...Re,we];y(Se),n("Composing response..."),await de(Se,K-1);return}}n("")}catch(Y){if(S.current=null,console.error("Error during AI interaction:",Y),C.current||Q(Y)){n("");return}Le({content:"I'm sorry, I encountered an error. Please write continue or try again.",timestamp:new Date}),n("")}},Oe=H=>H==="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"||H==="application/vnd.ms-excel"?"text/plain":H,Ne=async(H,K,Y)=>{try{const ee=[{Text:H.trim()}],pe=[];if(K&&K.length>0){n(K.length===1?"Receiving attached file...":"Receiving attached files...");for(const Ee of K){if(C.current){n("");return}const U=new File([await Ee.arrayBuffer()],Ee.name,{type:Ee.type}),me=F({applicationId:s,body:{file:U}});A.current=me;const we=await me.unwrap();if(A.current=null,C.current){n("");return}if(typeof we!="string"||we.length===0)throw new Error("Upload did not return a file URI.");const Se=we;pe.push({name:Ee.name,fileUri:Se,mimeType:Oe(Ee.type)}),ee.push({FileData:{FileUri:Se,MimeType:Oe(Ee.type)}})}pe.length>0&&ee.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(pe)}`})}const Re={Role:"user",Parts:ee},ve=[...D.current,Re];y(ve),D.current=ve,Y&&O.current.set(Y,ve.length-1),await de(ve,100)}catch(ee){if(A.current=null,console.error("Error processing user request:",ee),C.current||Q(ee)){n("");return}Le({content:"I'm sorry, there was an issue with your request, especially if a file was attached. Please try again.",timestamp:new Date}),n("")}},Ve=(H,K,Y)=>{p.length>0&&(C.current=!1,c(pe=>[...pe,{input:H,attachedFiles:K,uiMessageId:Y}]))},Le=H=>{if(C.current)return;const K=H.id??crypto.randomUUID();return l(Y=>[...Y,{...H,id:K}]),K},Ue=()=>l([]),Ke=()=>{C.current=!1,S.current?.abort?.(),S.current=null,A.current?.abort?.(),A.current=null;for(const H of k.current)H?.abort?.();k.current=[],y([]),D.current=[],O.current=new Map,c([]),x([]),l([]),n(""),b(0)},re=()=>{C.current=!0,c([]),S.current?.abort?.(),S.current=null,A.current?.abort?.(),A.current=null;for(const H of k.current)H?.abort?.();k.current=[],n("")},ue=async(H,K)=>{re(),C.current=!1;const Y=O.current.get(H);if(Y==null){Ve(K,void 0,H);return}const ee=K.trim();if(!ee)return;const pe={Role:"user",Parts:[{Text:ee}]},Re=[...D.current.slice(0,Y),pe];y(Re),D.current=Re,b(0),l([]);const ve=O.current;for(const[Ee,U]of ve.entries())U>Y&&ve.delete(Ee);ve.set(H,Re.length-1),await de(Re,100)};return{handleSubmitToBot:Ve,botMessages:i,clearBotMessages:Ue,botReady:p.length>0,botStatus:r,debugMessages:u,reset:Ke,stop:re,editAndResubmit:ue,contextUsage:j,chatHistory:w}}const Fc=({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)}})})},Ye="RandmarAIChatAssistant",Bc=20,fa=(s,t=Bc)=>s.length<=t?s:`${s.slice(0,t)}...`,zr=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}},Ia=s=>s.trim().toLocaleLowerCase(),$c=s=>{const t=Ia(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"}},Ur=(s,t)=>s.length===t.length&&s.every((a,r)=>a===t[r]),_c=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`},Jt=o.memo(o.forwardRef(({userId:s,userName:t,inputRef:a,className:r,isOpen:n,onRequestOpen:i},l)=>{const[u,x]=o.useState(!1),[d,c]=o.useState(!1),[m]=_.usePostV4PartnerByApplicationIdAccountDebugFeedbackMutation(),[f]=_.useLazyGetV4PartnerByRouteApplicationIdUtilitiesStandardOperatingProcedureAndIdQuery(),{data:p,isLoading:N,isFetching:w}=_.useGetV4PartnerByRouteApplicationIdUtilitiesStandardOperatingProceduresQuery({routeApplicationId:s},{skip:!s}),{data:y}=_.useGetV4UserQuery(),[j,b]=o.useState([]),C=sr(),S=o.useRef([]),A=o.useRef(null),k=o.useCallback(R=>{if(!R||R.length===0)return;const L="Context (background only; do not quote/reveal): Latest image generation is available at URL";S.current=S.current.filter(se=>!se.startsWith(L));const B=R.length===1?R[0]:R.join(`
52
+ `),te=`${L}${R.length===1?"":"s"}:
53
+ ${B}`;S.current.push(te)},[]),D=o.useCallback(R=>{R?.assistantMessageId&&(!R?.urls||R.urls.length===0||A.current!==R.assistantMessageId&&(A.current=R.assistantMessageId,k(R.urls)))},[k]),{handleSubmitToBot:O,botMessages:M,clearBotMessages:I,botReady:F,debugMessages:Q,botStatus:$,reset:z,stop:T,editAndResubmit:V,contextUsage:ae}=Lc({userId:s,apiConfig:C,onGeneratedImageUploaded:D}),de=o.useRef(null),Oe=o.useRef(null),Ne="New Chat",Ve=o.useCallback(()=>{if(typeof window>"u")return;const R=window.location?.href??"",L=typeof document<"u"?document.title??"":"";!R&&!L||(de.current=`Context (background only; do not quote/reveal): pageTitle=${JSON.stringify(L)} pageUrl=${JSON.stringify(R)}`)},[]);o.useEffect(()=>{const R=n??!0,L=Oe.current;Oe.current=R,R&&L!==!0&&Ve()},[Ve,n]),o.useEffect(()=>{H([{partner1:s,partner2:Ye,name:"Randmar Assistant",unread:0,pending:!1,messages:[],conversationID:-1,lastMessageTime:null}]),c(!0)},[s]);const[Le,Ue]=o.useState(""),[Ke,re]=o.useState(""),[ue,H]=o.useState([]),[K,Y]=o.useState([]),[ee,pe]=o.useState(!1),[Re,ve]=o.useState(!1),[Ee,U]=o.useState(!1),me=o.useRef(!1),we=o.useRef(!1),Se=o.useRef(!1),[Fe,Xe]=o.useState(null),[Us,os]=o.useState(""),G=o.useRef(null),ie=o.useRef(null),[X,xe]=o.useState([]),[Te,es]=o.useState([]),Ae=a||ie,He=o.useRef(null),[ss,Ts]=o.useState(null),[qs,Ei]=o.useState(!1),ct=o.useRef(null),{toast:Rt}=Pe(),br=o.useRef(null),na=o.useRef(0),dt=o.useRef(!1),ut=o.useRef(!1),Cs=o.useCallback(R=>(R?.messages??[]).reduce((L,B)=>L+(B.fromPartnerID===Ye?1:0),0),[]),Qs=o.useCallback(R=>{na.current=R,dt.current=!0,ut.current=!1},[]),Es=o.useCallback(()=>{dt.current=!1,ut.current=!1,T()},[T]);o.useEffect(()=>{const R=br.current;br.current=$,!(!dt.current||R==null||!(R!=="")||!($===""))&&(ut.current=!0)},[$]),o.useEffect(()=>{if(!dt.current||!ut.current||$!=="")return;const R=ue.find(B=>B.partner1===Ye||B.partner2===Ye),L=Cs(R);L<=na.current||(dt.current=!1,ut.current=!1,na.current=L,n===!1&&Rt({title:"Randmar Assistant",description:"Response ready. Open the Assistant to view.",variant:"info",duration:5e3,...i?{action:e.jsx(Ya,{altText:"Open Randmar Assistant",onClick:i,children:"Open"})}:{}}))},[$,ue,Cs,n,i,Rt]);const mt=o.useCallback(()=>ue.find(R=>!!R),[ue]),Ge=mt(),ms=o.useMemo(()=>(p??[]).map(R=>{const L=R.Name??"",{portalName:B,sopName:te}=zr(L);return{id:R.Id??"",label:L,portalName:B,sopName:te}}).filter(R=>!!R.id).sort((R,L)=>R.label.localeCompare(L.label)),[p]),xs=ee||Re,ia=N||w&&ms.length===0,yr=((Ge?.messages??[]).length??0)===0,Os=X.length,ks=Os>0,Oi=o.useCallback(R=>{Se.current=!0,Y(R)},[]);o.useEffect(()=>{Y(R=>{const L=R.filter(B=>ms.some(te=>te.id===B));return Ur(R,L)?R:L})},[ms]),o.useEffect(()=>{if(we.current)return;if(Se.current){we.current=!0;return}if(ia)return;const R=Ia(y?.Role??"");if(!R){we.current=!0;return}const L=ms.filter(B=>Ia(B.sopName)===R).map(B=>B.id);Y(B=>Ur(B,L)?B:L),we.current=!0},[y?.Role,ia,ms]);const Nr=o.useCallback(R=>!R||typeof R!="object"||!("status"in R)||R.status!=="PARSING_ERROR"||!("originalStatus"in R)||R.originalStatus!==200?null:R.data??null,[]),Pt=o.useCallback(async R=>{if(!s||!R)throw new Error("Missing user or SOP id.");try{return await f({routeApplicationId:s,id:R},!1).unwrap()}catch(L){const B=Nr(L);if(B!=null)return B;throw L}},[f,Nr,s]),Hs=o.useCallback(()=>{Ae.current?.focus()},[Ae]),vr=o.useRef(0);o.useEffect(()=>{const R=vr.current,L=X.length;vr.current=L,!(L===0||L<=R)&&Hs()},[Hs,X.length]),o.useEffect(()=>()=>{ct.current&&clearTimeout(ct.current)},[]);const Gs=o.useCallback((R,L=5e3)=>{ct.current&&clearTimeout(ct.current),Ts(R),L!=null&&(ct.current=setTimeout(()=>Ts(null),L))},[]);o.useEffect(()=>{const R=ue.find(B=>B.partner1===Ye||B.partner2===Ye),L=new Set((R?.messages??[]).map(B=>B.id));es(B=>B.filter(te=>L.has(te.messageId)))},[ue]),o.useEffect(()=>{if(M.length===0)return;const R=[];for(const L of M)!L||L.isComponent||typeof L.content=="string"&&R.push({id:L.id,fromPartnerID:Ye,toPartnerID:s,senderName:"Assistant",timestamp:L.timestamp.getTime(),content:L.content,images:L.images});R.length>0&&b(L=>[...L,...R]),I()},[M,I,s]);const wr=o.useCallback(R=>{b(L=>[...L,R])},[]);o.useEffect(()=>{j.length!=0&&(H(R=>R.map(L=>{const B=L.messages??[];if(B.length===0)return{...L,messages:[...j]};const te=new Set(B.map(le=>le.id)),se=j.filter(le=>!te.has(le.id));return se.length===0?L:{...L,messages:[...B,...se]}})),requestAnimationFrame(()=>G.current?.scrollIntoView({behavior:"smooth"})),b([]))},[j]);const Sr=o.useCallback(async()=>{if(K.length===0)return{sopFilesForMessage:[],sopHiddenNotes:[]};const R=K.map(L=>ms.find(B=>B.id===L)).filter(L=>L!=null);if(R.length===0)return{sopFilesForMessage:[],sopHiddenNotes:[]};pe(!0);try{const L=await Promise.allSettled(R.map(async se=>{const le=await Pt(se.id),be=typeof le=="string"?le:le==null?"":JSON.stringify(le,null,2);if(!be.trim())throw new Error("SOP_EMPTY");return{choice:se,sopText:be}})),B=[],te=[];for(const[se,le]of L.entries()){const be=R[se];if(le.status==="rejected"){const We=le.reason instanceof Error&&le.reason.message==="SOP_EMPTY";Rt({title:"Could not load SOP",description:`${be.label} was skipped${We?" because it is empty.":"."}`,variant:"warning"});continue}B.push(new File([le.value.sopText],_c(be.label),{type:"text/markdown"})),te.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
+
55
+ SOP markdown content:
56
+ ${le.value.sopText}`)}return{sopFilesForMessage:B,sopHiddenNotes:te}}finally{pe(!1)}},[Pt,K,ms,Rt]),At=o.useCallback(async(R,L,B)=>{if(xs)return;const te=!me.current;te&&(me.current=!0,U(!0));let se=B?.attachedFilesOverride??X;const le=[...S.current];if(S.current=[],te){const{sopFilesForMessage:ls,sopHiddenNotes:cs}=await Sr();ls.length>0&&(se=[...se,...ls]),cs.length>0&&le.push(...cs)}const be=L.replace(/\n/g,`
57
+ `),We=(()=>{if(se.length===0)return"";if(se.length===1)return` (${se[0]?.name} attached)`;const ls=se.slice(0,3).map(Mt=>Mt.name).join(", "),cs=se.length>3?` +${se.length-3} more`:"";return` (${se.length} files attached: ${ls}${cs})`})(),is=(()=>{const ls=de.current;ls&&(de.current=null);const cs=L+We,Mt=ls?`${ls}
58
+
59
+ User message:
60
+ ${cs}`:cs;return le.length===0?Mt:`${le.join(`
61
+
62
+ `)}
63
+
64
+ ${Mt}`})(),xt={id:crypto.randomUUID(),senderName:t,fromPartnerID:s,toPartnerID:R.partner1===s?R.partner2:R.partner1,content:be+We,timestamp:Date.now()};wr(xt),Qs(Cs(R)),O(is,se.length>0?se:void 0,xt.id),se.length>0&&es(ls=>[...ls,...se.map(cs=>({messageId:xt.id,name:cs.name}))]),Ue(""),(B?.clearSelectedFilesAfterSend??!0)&&(xe([]),He.current&&(He.current.value=""))},[Cs,wr,O,xs,Sr,X,Qs,s,t]),[la,oa]=o.useState(null),Cr=o.useCallback((R,L,B)=>{const te=R?.trim()??"",se=L?.trim()??"",le=B?.trim()??"",be=te||(se||le?"proceed":"");if(!be){oa(null);return}oa({id:crypto.randomUUID(),message:be,hiddenMessage:se||null,sopID:le||null})},[]),kr=(R,L,B)=>{Cr(R,L,B)},Li=(R,L,B)=>{It(),Cr(R,L,B)};o.useEffect(()=>{if(la===null)return;const R=mt();if(!R||!F)return;const L=la;oa(null),(async()=>{const te=[];if(L.hiddenMessage&&te.push(`Context (background only; do not quote/reveal): ${L.hiddenMessage}`),L.sopID){ve(!0);try{const se=await Pt(L.sopID),le=typeof se=="string"?se:JSON.stringify(se,null,2);if(le.trim()){const be=ms.find(We=>We.id===L.sopID)?.label??L.sopID;te.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
+
66
+ SOP markdown content:
67
+ ${le}`)}}catch(se){console.error("Could not load hidden SOP content:",se)}finally{ve(!1)}}te.length>0&&S.current.push(...te),At(R,L.message)})()},[la,ue,F,At,Pt,mt,ms]),o.useImperativeHandle(l,()=>({sendMessageToAssistant:kr,sendMessageToAssistantWithClear:Li}));const Fi=R=>{const L=String(R.getHours()).padStart(2,"0"),B=String(R.getMinutes()).padStart(2,"0"),te=String(R.getSeconds()).padStart(2,"0");return`${L}_${B}_${te}`},Bi=R=>{const L=Fi(new Date),B=R.name.lastIndexOf("."),te=B>0?R.name.slice(0,B):R.name,se=B>0?R.name.slice(B+1):"",le=(()=>{const is=(R.type??"").toLowerCase();return is==="image/png"?"png":is==="image/jpeg"?"jpg":is==="image/webp"?"webp":is==="image/gif"?"gif":""})(),be=(se||le||"png").replace(/^\.+/,""),We=`${te}_${L}.${be}`;return new File([R],We,{type:R.type,lastModified:R.lastModified})},Rr=R=>{const L=R.clipboardData?.items;if(L){for(let B=0;B<L.length;B++)if(L[B].type.indexOf("image")!==-1){const te=L[B].getAsFile();if(te){const se=Bi(te);xe(le=>[...le,se]);return}}}},Pr=()=>{if(xs)return;let R=Le.trim();!R&&X.length>0&&(R="consider this"),!(!Ge||!R)&&At(Ge,R)},Ar=()=>{if(!F||$||xs)return;let R=Ke.trim();!R&&X.length>0&&(R="consider this"),!(!R||!Ge)&&(At(Ge,R),re(""))},$i=R=>{R.key!=="Enter"||R.shiftKey||(R.preventDefault(),Ar())},_i=R=>{R.preventDefault(),Ar()},Vi=(R,L)=>{const B=$c(R);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",B.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",B.badgeClassName),title:R,children:e.jsx("span",{className:"truncate",children:R})}),e.jsx("span",{className:"block break-words text-sm leading-snug font-semibold text-foreground",title:L,children:L})]})]})},zi=()=>Ee?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(ci,{items:ms,selectedIds:K,onSelectedIdsChange:Oi,selectionMode:"multiple",layout:"grid",gridColumns:2,disabled:xs,loading:ia,getItemAriaLabel:R=>R.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:R=>{const{portalName:L,sopName:B}=zr(R.label);return Vi(L,B)}})})]}),Ui=()=>e.jsxs("div",{className:"flex flex-col gap-2",children:[xs?e.jsx("div",{className:"flex items-end gap-2",children:Or}):e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(bs,{ref:Ae,autoFocus:!0,value:Ke,onPaste:Rr,onChange:R=>re(R.target.value),onKeyDown:$i,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(E,{size:"icon",variant:"default",className:"h-12 w-12 rounded-full shadow-sm",disabled:!F||!!$||xs,type:"submit",children:e.jsx(g.Send,{className:"h-6 w-6"})}),e.jsxs(E,{size:"icon",variant:ks?"secondary":"default",onClick:Ir,title:Dt,className:v("relative h-12 w-12 rounded-full shadow-sm",ks&&"ring-2 ring-ring/25"),disabled:!F||$!==""||Ge?.pending,type:"button","aria-label":Dt,children:[e.jsx(g.Paperclip,{className:"h-5 w-5"}),ks&&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:Os})]})]}),Tr(),zi()]}),qi=R=>{const L=Array.from(R.target.files??[]);L.length!==0&&(xe(B=>{const te=[...B];for(const se of L)te.some(be=>be.name===se.name&&be.size===se.size&&be.lastModified===se.lastModified)||te.push(se);return te}),R.target.value="",requestAnimationFrame(()=>Hs()))},Ir=()=>{He.current?.click()},Dr=R=>{xe(L=>L.filter((B,te)=>te!==R)),Hs()},Qi=(R,L)=>{es(te=>te.filter((se,le)=>le!==L));const B=`Context (background only; do not quote/reveal): The user removed the file ${JSON.stringify(R)} 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.`;S.current.push(B),Gs({kind:"info",title:"File removed",description:"It will be applied to the next message you send."},5e3)},Hi=()=>{const L={messages:mt(),debug:Q};x(!0),m({applicationId:s,emailAddress:t,body:L}).then(B=>{if(B.error){console.error(B.error),Gs({kind:"error",title:"Error",description:"Could not send your feedback. Please try again later."},null);return}Gs({kind:"success",title:"Success",description:"Your feedback has been successfully sent. Thank you!"},6e3)}).catch(B=>{console.error(B),Gs({kind:"error",title:"Error",description:"Could not send your feedback. Please try again later."},null)}).finally(()=>{x(!1)})},It=o.useCallback(()=>{Es(),S.current=[],me.current=!1,H(R=>R.map(B=>B.partner1!==Ye&&B.partner2!==Ye?B:{...B,messages:[]})),es([]),pe(!1),ve(!1),U(!1),Xe(null),os(""),z()},[z,Es]);o.useEffect(()=>{if((n??!0)===!1)return;const R=L=>{L.defaultPrevented||!L.altKey||L.ctrlKey||L.metaKey||L.shiftKey||L.key.toLowerCase()==="n"&&(L.preventDefault(),It())};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[n,It]);const Gi=R=>R.replace(/ {2}\n/g,`
68
+ `),Wi=R=>R.replace(/\n/g,`
69
+ `),Ki=o.useCallback(R=>{Es(),Xe(R.id),os(Gi(R.content))},[Es]),ca=o.useCallback(()=>{Xe(null),os("")},[]),Yi=o.useCallback((R,L)=>{const B=L.trim();if(!B){Gs({kind:"error",title:"Nothing to save",description:"Edited message can't be empty."},5e3);return}const te=Wi(B),se=(()=>{const le=Ge?.messages??[],be=le.findIndex(We=>We.id===R);return be===-1?Cs(Ge):le.slice(0,be+1).reduce((We,is)=>We+(is.fromPartnerID===Ye?1:0),0)})();H(le=>le.map(be=>{if(be.partner1!==Ye&&be.partner2!==Ye)return be;const We=be.messages??[],is=We.findIndex(cs=>cs.id===R);if(is===-1)return be;const xt={...We[is],content:te},ls=[...We.slice(0,is),xt];return{...be,messages:ls}})),es(le=>le.filter(be=>be.messageId!==R)),ca(),Qs(se),V(R,te)},[Ge,ca,Cs,V,Gs,Qs]),Ji=o.useCallback(R=>{Es(),Xe(null),os("");const L=(()=>{const B=Ge?.messages??[],te=B.findIndex(se=>se.id===R.id);return te===-1?Cs(Ge):B.slice(0,te+1).reduce((se,le)=>se+(le.fromPartnerID===Ye?1:0),0)})();H(B=>B.map(te=>{if(te.partner1!==Ye&&te.partner2!==Ye)return te;const se=te.messages??[],le=se.findIndex(be=>be.id===R.id);return le===-1?te:{...te,messages:se.slice(0,le+1)}})),Qs(L),V(R.id,R.content)},[Ge,Cs,V,Qs,Es]);o.useEffect(()=>{!d||!F||setTimeout(()=>Hs(),50)},[F,Hs,yr,d]);const Mr=o.useRef(null);o.useEffect(()=>{Mr.current?.scrollIntoView({behavior:"smooth"})},[Q]);const Dt=(()=>{if(!ks)return"Attach files";const R=X.slice(0,5).map(B=>B.name).join(", "),L=Os>5?` +${Os-5} more`:"";return`Attached (${Os}): ${R}${L}`})(),Tr=R=>ks?e.jsxs("div",{className:v("flex flex-col gap-1 rounded-2xl bg-background/70 p-2 shadow-xs ring-1 ring-border/80",R),role:"group","aria-label":`Attached files (${Os})`,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"}),X.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(g.File,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"max-w-[16rem] truncate",title:L.name,children:fa(L.name)}),e.jsx(E,{size:"icon",variant:"ghost",className:"h-5 w-5 shrink-0 rounded-full hover:bg-muted/80",onClick:()=>Dr(B),"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}_${B}`))]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Will be included with your next message."})]}):null,Er=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..."})]})}),Or=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 d?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:mt()?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(wt,{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(E,{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:()=>Hi()},disabled:u,children:u?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(E,{className:"ml-1",onClick:()=>It(),title:Ne,"aria-label":Ne,children:[e.jsx(g.MessageCircleXIcon,{className:"h-5 w-5"})," ",Ne]}),$!==""&&e.jsxs(E,{className:"ml-1",variant:"destructive",onClick:()=>Es(),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(ne,{type:"file",onChange:qi,className:"hidden",ref:He,multiple:!0}),ss&&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",ss.kind==="error"&&"border-destructive/30 bg-destructive/10 text-foreground",ss.kind==="success"&&"border-success/30 bg-success/10 text-foreground",ss.kind==="info"&&"border-border bg-background text-foreground"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-semibold",children:ss.title}),ss.description&&e.jsx("div",{className:v("mt-0.5",ss.kind==="error"&&"text-destructive",ss.kind==="success"&&"text-success",ss.kind==="info"&&"text-muted-foreground"),children:ss.description})]}),e.jsx(E,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",onClick:()=>Ts(null),"aria-label":"Dismiss notice",type:"button",children:e.jsx(g.X,{className:"h-4 w-4"})})]})}),F?yr?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:Ui()})]})})}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs(gs,{className:"min-h-0 flex-1 bg-muted/30 pl-2 pr-2",children:[e.jsx(Wn,{messages:Ge?.messages??[],appID:s,isAssistantChat:!0,botStatus:$,hideSenderNames:!0,editableUserMessages:!0,editingMessageId:Fe,editingDraft:Us,onEditingDraftChange:os,onStartEditUserMessage:Ki,onCancelEditUserMessage:ca,onSaveEditUserMessage:Yi,onRetryUserMessage:Ji}),e.jsx("div",{ref:G})]}),e.jsxs("div",{className:"flex shrink-0 flex-col gap-2 border-r border-t p-4",children:[xs?Or:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(bs,{ref:Ae,placeholder:"Type a message...",value:Le,onPaste:Rr,onChange:R=>Ue(R.target.value),onKeyDown:R=>{R.key!=="Enter"||R.shiftKey||(R.preventDefault(),!(!F||$||xs)&&Pr())},className:"flex-1 resize-none field-sizing-content max-h-[30em]"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(E,{size:"icon",variant:"default",className:Ge?.pending?"collapse":"ml-2 h-8 w-8",disabled:!F||!!$||xs,onClick:Pr,children:e.jsx(g.Send,{className:"h-6 w-6"})}),e.jsxs(E,{size:"icon",variant:ks?"secondary":"default",onClick:Ir,title:Dt,"aria-label":Dt,className:v(Ge?.pending?"collapse":"relative ml-2 h-8 w-8",ks&&"ring-2 ring-ring/25"),disabled:!F||$!==""||Ge?.pending,children:[e.jsx(g.Paperclip,{className:"h-5 w-5"}),ks&&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:Os})]})]})]}),Tr()]})]}):e.jsx("div",{className:"flex-1 bg-muted/30",children:Er})]})]}):Er}),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(Z,{htmlFor:"show-dev-logs-checkbox",className:"text-xs font-semibold tracking-wider text-muted-foreground uppercase",children:"Show Dev Logs"}),e.jsx(Ds,{id:"show-dev-logs-checkbox",checked:qs,onCheckedChange:R=>Ei(R===!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(gs,{className:"flex-1 px-4",children:e.jsx("div",{className:"py-2 text-sm",children:X.length>0||Te.length>0?e.jsxs("div",{className:"space-y-2",children:[X.map((R,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:`${R.name} (pending)`,children:[fa(R.name)," (pending)"]})]}),e.jsx(E,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0",onClick:()=>Dr(L),"aria-label":`Remove pending file ${R.name}`,children:e.jsx(g.X,{className:"h-4 w-4"})})]},`${R.name}_${R.lastModified}_${R.size}_${L}`)),Te.slice().reverse().map((R,L)=>{const B=Te.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:R.name,children:fa(R.name)})]}),e.jsx(E,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0",onClick:()=>Qi(R.name,B),"aria-label":`Remove file ${R.name}`,children:e.jsx(g.X,{className:"h-4 w-4"})})]},R.messageId)})]}):e.jsx("p",{className:"text-muted-foreground text-xs italic",children:"No files attached yet."})})})]}),qs?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(gs,{className:"flex-1 px-4",children:e.jsxs("div",{className:"py-2 text-xs font-mono",children:[e.jsx(Fc,{debugMessages:Q}),e.jsx("div",{ref:Mr})]})})]}):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(gs,{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:"Massimo Fiore"}),e.jsx("div",{className:"text-muted-foreground",children:e.jsx("a",{className:"text-primary hover:underline",href:"mailto:massimo@randmar.io",children:"massimo@randmar.io"})}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Extension: 305"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Location: Ontario"})]}),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(E,{className:"w-full",variant:"secondary",onClick:()=>kr("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(Vc,{})]}),e.jsxs("div",{className:"flex-1 max-w-[160px]",children:[e.jsx(lt,{value:Math.round((ae||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((ae||0)*100),"%"]})]})]})]})})]})})]}):e.jsx(g.Loader2,{className:"h-12 w-12 animate-spin mx-auto mb-4"})}));Jt.displayName="AIChatLayout";const Vc=({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 zc(s){return s.split(/[?#]/u,1)[0]??""}function qr(s,t){const a=zc(s).split("/").filter(Boolean),r=a.indexOf(t);return r===-1?a:a.slice(r+1)}function Uc(s,t,a){const r=qr(s,a),n=qr(t,a);return n.length===0?r.length===0:r.length<n.length?!1:n.every((i,l)=>r[l]===i)}function qc(s,t){return(s.startsWith("/")?s:`/${s}`).replace(":appID",t)}const hi=o.forwardRef(({routes:s,footer:t,dashboardTitle:a,chatUserName:r,appID:n,chatRoutePath:i},l)=>{const u=s.filter(k=>k.showInNav),x=o.useRef(null),d=o.useRef(null),c=o.useRef(null),[m,f]=o.useState(!1),{isMobile:p,setOpenMobile:N}=rt(),w=Ce.useLocation(),{data:y}=_.useGetV4PartnerByRouteApplicationIdBusinessDevelopmentConversationsHasUnreadsQuery({routeApplicationId:n}),{hasUnreads:j}=Xs(),b=o.useCallback((k,D=null,O=null,M)=>{f(!0),setTimeout(()=>{x.current?.focus(),d.current&&(M?.clear?d.current.sendMessageToAssistantWithClear(k,D,O):d.current.sendMessageToAssistant(k,D,O))},100)},[]),C=o.useCallback(()=>{N(!1)},[N]);o.useImperativeHandle(l,()=>({sendMessageToAssistant:(k,D,O)=>{b(k,D,O)},sendMessageToAssistantWithClear(k,D,O){b(k,D,O,{clear:!0})}}));const S=u.map(k=>{const D=qc(k.path,n),O=Uc(w.pathname,D,n);return{route:k,linkPath:D,isActive:O}}),A=S.find(k=>k.isActive)?.route.label??"None";return e.jsxs(_a,{className:"border-r border-sidebar-border",children:[e.jsx(za,{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(xi,{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(qa,{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:A})]})]}),e.jsx("div",{className:"mt-4 grid grid-cols-3 gap-3",children:S.map(({route:k,linkPath:D,isActive:O})=>{const M=k.icon??g.AppWindow;return e.jsxs(Ce.Link,{to:D,"aria-current":O?"page":void 0,onClickCapture:C,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",O&&"border-sidebar-ring bg-sidebar-accent text-sidebar-accent-foreground"),children:[e.jsx(M,{className:"h-9 w-9 shrink-0"}),e.jsx("span",{className:"line-clamp-2",children:k.label??k.key})]},k.key)})})]}):e.jsx(Qa,{children:S.map(({route:k,linkPath:D,isActive:O})=>{const M=k.icon;return e.jsx(Ha,{children:e.jsx(Ga,{asChild:!0,isActive:O,children:e.jsxs(Ce.Link,{to:D,className:"transition-colors hover:bg-muted px-6",children:[M&&e.jsx(M,{className:"h-4 w-4"}),e.jsx("span",{children:k.label})]})})},k.key)})})}),e.jsxs(Ua,{className:"border-t border-sidebar-border p-4 bg-sidebar text-sidebar-foreground",children:[e.jsxs(De,{open:m,onOpenChange:f,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Zs,{asChild:!0,children:e.jsxs(E,{ref:c,size:"lg",className:"collapse md:visible flex-grow",onClick:()=>setTimeout(()=>x.current?.focus(),50),children:[e.jsx(g.Bot,{}),"Assistant"]})}),e.jsx(Ce.Link,{to:i,onClickCapture:C,children:e.jsx(E,{size:"icon",className:j||y?.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:m,children:e.jsx(Jt,{className:"h-[85vh]",ref:d,inputRef:x,userId:n,userName:r??"Unknown user",isOpen:m,onRequestOpen:()=>{f(!0),setTimeout(()=>x.current?.focus(),50)}})})]}),t]})]})}),fi=o.forwardRef(({children:s,appID:t,rightMenu:a,routes:r,footer:n,handleValidSearch:i,dashboardTitle:l,onSignOut:u,searchPlaceholder:x,chatUserName:d,chatRef:c,chatRoutePath:m},f)=>e.jsx(e.Fragment,{children:e.jsx($a,{children:e.jsxs("div",{className:`flex grow ${li}`,children:[e.jsx(hi,{appID:t,routes:r,footer:n,dashboardTitle:l,chatUserName:d,ref:c,chatRoutePath:m}),e.jsx(lr,{ref:f,onSignOut:u,rightMenu:a,handleValidSearch:i,searchPlaceholder:x}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("main",{className:`${kc} @container flex-1 overflow-x-clip bg-muted`,"data-rm-main-content-region":"true",children:s}),e.jsx(Fn,{})]})]})})}));fi.displayName="Layout";const Qr=[{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)"}],Hr=[{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 mr({applicationId:s,manufacturer:t}){const{toast:a}=Pe(),[r,n]=o.useState(!1),[i,l]=o.useState(!1),[u,x]=o.useState(!1),[d,c]=o.useState(""),[m,f]=o.useState(""),[p,N]=o.useState(!1),[w,y]=o.useState(""),[j,b]=o.useState(""),[C,S]=o.useState([]),[A,k]=o.useState(""),[D,O]=o.useState(""),[M,I]=o.useState([]),[F,Q]=o.useState(""),[$,z]=o.useState(""),[T]=_.usePostV4PartnerByRouteApplicationIdBusinessDevelopmentConversationPartnerAndPartnerIdMutation(),V=()=>{c(""),f("")},ae=()=>{y(""),b(""),S([]),k(""),O(""),I([]),Q(""),z("")},de=()=>{t.PartnerRegistrationLink?n(!0):t.OpenToWork&&l(!0)},Oe=re=>{if(re.preventDefault(),!u){if(!d.trim()){f("Qualification ID is required");return}x(!0),T({routeApplicationId:s,partnerId:t.ManufacturerId??"",message:`Hello! I'd like to get started with you. Here's my Qualification ID: ${d}`}).then(ue=>{if(ue.error){console.error(ue.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),V()}).catch(ue=>{console.error(ue),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"})}).finally(()=>{x(!1)})}},Ne=re=>{if(re.preventDefault(),p)return;b(""),k(""),Q("");let ue=!1;if(w.trim().length<10&&(b("Please provide a brief description of your business (minimum 10 characters)"),ue=!0),C.length===0&&(k("Please select at least one sales channel"),ue=!0),M.length===0&&(Q("Please select at least one market"),ue=!0),ue)return;const H=Qr.filter(ee=>C.includes(ee.id)).map(ee=>ee.label);D&&H.push(`Other: ${D}`);const K=Hr.filter(ee=>M.includes(ee.id)).map(ee=>ee.label);$&&K.push(`Other: ${$}`);const Y=["Hello! I'd like to introduce my business:",`**Business Description:** ${w}`,`**Sales Channels:** ${H.join(", ")}`,`**Markets:** ${K.join(", ")}`].join(`
70
+
71
+ `);N(!0),T({routeApplicationId:s,partnerId:t.ManufacturerId??"",message:Y}).then(ee=>{if(ee.error){console.error(ee.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),ae()}).catch(ee=>{console.error(ee),a({title:"Could not initiate chat",description:"Try again later.",variant:"destructive"})}).finally(()=>{N(!1)})},Ve=(re,ue)=>{S(H=>ue?[...H,re]:H.filter(K=>K!==re)),k("")},Le=(re,ue)=>{I(H=>ue?[...H,re]:H.filter(K=>K!==re)),Q("")},Ue=C.includes("other-channel"),Ke=M.includes("other-market");return e.jsxs(e.Fragment,{children:[!t.Qualification&&e.jsxs(E,{onClick:de,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:re=>{n(re)},children:e.jsxs(Me,{className:"sm:max-w-[400px]",children:[e.jsxs($e,{children:[e.jsx(_e,{children:t.PublicName}),e.jsxs(ze,{children:[e.jsx("span",{className:"font-bold",children:"Already qualified?"})," Provide your Qualification ID."]})]}),e.jsxs("form",{onSubmit:Oe,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{htmlFor:"qualificationId",children:"Qualification ID"}),e.jsx(ne,{id:"qualificationId",placeholder:"Enter your qualification ID",value:d,onChange:re=>{c(re.target.value),f("")}}),m&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:m})]}),e.jsx(qe,{children:e.jsx(E,{type:"submit",className:"w-full",disabled:u,children:u?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(vt,{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(Ce.Link,{to:t.PartnerRegistrationLink,target:"_blank",children:e.jsxs(E,{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:re=>{l(re)},children:e.jsxs(Me,{className:"sm:max-w-[768px]",children:[e.jsx($e,{children:e.jsx(_e,{children:"Introduce Yourself"})}),e.jsxs("form",{onSubmit:Ne,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Z,{htmlFor:"businessDescription",children:["Tell Us About Your Business ",e.jsx("span",{className:"text-sm text-muted-foreground",children:"(Briefly describe your business)"})]}),e.jsx(bs,{id:"businessDescription",placeholder:"We are an online retailer specializing in office supplies, serving businesses since 2018...",className:"min-h-[100px]",value:w,onChange:re=>{y(re.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(Z,{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:Qr.map(re=>e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx(Ds,{id:`channel-${re.id}`,checked:C.includes(re.id),onCheckedChange:ue=>Ve(re.id,ue===!0)}),e.jsx(Z,{htmlFor:`channel-${re.id}`,className:"text-sm font-normal",children:re.label})]},re.id))}),Ue&&e.jsx(ne,{placeholder:"Please specify",value:D,onChange:re=>O(re.target.value)}),A&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:A})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Z,{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:Hr.map(re=>e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx(Ds,{id:`market-${re.id}`,checked:M.includes(re.id),onCheckedChange:ue=>Le(re.id,ue===!0)}),e.jsx(Z,{htmlFor:`market-${re.id}`,className:"text-sm font-normal",children:re.label})]},re.id))}),Ke&&e.jsx(ne,{placeholder:"Please specify",value:$,onChange:re=>z(re.target.value)}),F&&e.jsx("p",{className:"text-sm font-medium text-destructive",children:F})]}),e.jsx(qe,{children:e.jsx(E,{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 pa=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function pi({manufacturer:s,onSave:t,loading:a=!1,saving:r=!1,readonly:n=!1}){const[i,l]=o.useState({...s}),[u,x]=o.useState({...s});o.useEffect(()=>{x({...s}),l({...s})},[s]);const d=(j,b)=>{n||l(C=>({...C,[j]:b}))},c=(j,b)=>{n||l(C=>({...C,[j]:b}))},m=(j,b)=>{n||l(C=>({...C,[j]:b}))},f=()=>{const j={};return Object.keys(i).forEach(b=>{const C=b;JSON.stringify(i[C])!==JSON.stringify(u[C])&&(j[C]=i[C])}),j},p=()=>{if(!r&&!n){const j=f();Object.keys(j).length>0&&t(j)}},N=j=>j===-1?"ASAP":j===void 0||j<0||j>6?"Sunday":pa[j],w=j=>j==="ASAP"?-1:pa.indexOf(j),y=Object.keys(f()).length>0;return e.jsxs(q,{children:[e.jsxs(J,{children:[a?e.jsx(h,{className:"h-8 w-32"}):e.jsx(ce,{className:"text-lg font-bold",children:"Reordering"}),a?e.jsx(h,{className:"h-4 w-full mt-2"}):e.jsx(it,{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(W,{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(nt,{id:"automatic-reordering",checked:i.AutoUpdate,onCheckedChange:j=>d("AutoUpdate",j),disabled:r||n}),e.jsx(Z,{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(Z,{htmlFor:"reorder-date",children:"Automatic Reorder Date"}),e.jsxs(As,{value:N(i.AutoReorderDate),onValueChange:j=>c("AutoReorderDate",w(j)),disabled:r||n,children:[e.jsx(ys,{id:"reorder-date",children:e.jsx(Is,{placeholder:"Select day"})}),e.jsxs(Ns,{children:[e.jsx(as,{value:"ASAP",children:"ASAP"}),pa.map(j=>e.jsx(as,{value:j,children:j},j))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{htmlFor:"weeks-stocking",children:"Default Weeks of Stocking"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(ne,{id:"weeks-stocking",type:"number",value:i.DefaultWeeksOfStocking||"",onChange:j=>c("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(Z,{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(ne,{id:"minimum-order",type:"number",className:"pl-6",value:i.DefaultMinimumOrder||"",onChange:j=>c("DefaultMinimumOrder",Number(j.target.value)),disabled:r||n})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{htmlFor:"lead-time",children:"Default Lead Time"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(ne,{id:"lead-time",type:"number",value:i.DefaultLeadTime||"",onChange:j=>c("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(Z,{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(ne,{id:"maximum-inventory-value",type:"number",className:"pl-6",value:i.DefaultMaxInventoryValue||"",onChange:j=>c("DefaultMaxInventoryValue",Number(j.target.value)),disabled:r||n})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{htmlFor:"order-confirmations",children:"Send Order Confirmations To"}),e.jsx(ne,{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(fs,{className:"flex justify-end",children:a?e.jsx(h,{className:"h-10 w-20"}):e.jsxs(E,{onClick:p,disabled:r||!y,children:[r&&e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Save"]})})]})}const Ct=Ys.Root,kt=Ys.Trigger,Qc=Ys.Anchor,ot=P.forwardRef(({className:s,align:t="center",sideOffset:a=4,...r},n)=>e.jsx(Ys.Portal,{children:e.jsx(Ys.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})}));ot.displayName=Ys.Content.displayName;function gi({options:s,selected:t,onChange:a,placeholder:r="Select items...",disabled:n=!1}){const[i,l]=P.useState(!1),[u,x]=P.useState(""),d=P.useRef(null),[c,m]=P.useState(void 0),f=P.useCallback(()=>{d.current&&m(d.current.offsetWidth)},[]);P.useLayoutEffect(()=>{f()},[f]),P.useEffect(()=>(window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)),[f]);const p=y=>{a(t.filter(j=>j!==y))},N=y=>{l(!1),t.includes(y)?a(t.filter(j=>j!==y)):a([...t,y])},w=y=>{y.key==="Enter"&&u&&!s.includes(u)&&!t.includes(u)&&(y.preventDefault(),N(u),x(""))};return e.jsxs(Ct,{open:i,onOpenChange:l,children:[e.jsx(kt,{asChild:!0,children:e.jsxs(E,{ref:d,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(y=>e.jsxs(he,{variant:"outline",className:"mr-1 mb-1",children:[y,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(y)},children:e.jsx(g.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},y)):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(ot,{className:"w-full p-0",style:{width:c},children:e.jsxs(Yt,{onKeyDown:w,children:[e.jsx(or,{placeholder:"Search or add custom item...",value:u,onValueChange:x}),e.jsxs(cr,{children:[e.jsx(dr,{children:"No item found."}),e.jsxs(ur,{children:[s.filter(y=>!t.includes(y)).map(y=>e.jsxs(Qt,{onSelect:()=>N(y),children:[e.jsx(g.Check,{className:v("mr-2 h-4 w-4",t.includes(y)?"opacity-100":"opacity-0")}),y]},y)),u&&!s.includes(u)&&!t.includes(u)&&e.jsxs(Qt,{onSelect:()=>N(u),children:['Add "',u,'"']})]})]})]})})]})}const Hc={sm:100,md:200,lg:300,xl:400};function Gc(s){return s==null?null:Array.isArray(s)?s:s&&typeof s=="object"&&"Images"in s&&Array.isArray(s.Images)?s.Images:[]}function Da(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 Gr({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(js(i,s)),d=x.pathname.split("/").filter(Boolean),c=t.trim().toLowerCase(),m=w=>{try{return decodeURIComponent(w).toLowerCase()===c}catch{return w.toLowerCase()===c}},f=d.slice(-3),p=d.slice(-4);return f.length===3&&f[0]?.toLowerCase()==="product"&&m(f[1]??"")&&f[2]?.toLowerCase()==="image"||p.length===4&&p[0]?.toLowerCase()==="product"&&m(p[1]??"")&&p[2]?.toLowerCase()==="image"?Da(x.toString(),r,n):x.toString()}catch{}}const u=a.ImageId!==void 0&&a.ImageId!==null&&String(a.ImageId).trim()!==""?`/Product/${encodeURIComponent(t)}/Image/${encodeURIComponent(String(a.ImageId))}`:`/Product/${encodeURIComponent(t)}/Image`;return Da(js(u,s),r,n)}function Wc({apiOrigin:s,randmarSKU:t,width:a,height:r}){return Da(js(`/Product/${encodeURIComponent(t)}/Image`,s),a,r)}const Wr=({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 Kc({randmarSKU:s,size:t="md",alt:a,className:r,fallback:n}){const i=Hc[t],l=P.useRef(null),u=Gt({elementRef:l,threshold:.1,rootMargin:"100px"}),x=St(),{data:d,isError:c,isFetching:m}=_.useGetProductByRandmarSkuImagesQuery({randmarSku:s},{skip:!s||!u,refetchOnMountOrArgChange:!0}),f=P.useMemo(()=>Gc(d),[d]),[p,N]=P.useState(0),[w,y]=P.useState(!1),j=P.useRef(!1),b=P.useRef(new Set);P.useEffect(()=>{N(0),y(!1),j.current=!1,b.current.clear()},[s]);const C=P.useMemo(()=>f?[...f].sort((T,V)=>{const ae=T.SortOrder??Number.POSITIVE_INFINITY,de=V.SortOrder??Number.POSITIVE_INFINITY;if(ae!==de)return ae-de;const Oe=T.IsPrimary===!0?0:1,Ne=V.IsPrimary===!0?0:1;return Oe-Ne}):null,[f]),S=P.useMemo(()=>{if(!C?.length)return 0;const T=C.findIndex(V=>V.IsPrimary===!0);return T>=0?T:0},[C]);P.useEffect(()=>{C?.length&&(j.current||(N(S),j.current=!0))},[S,C]);const A=C?.length??0,k=P.useMemo(()=>{const T=(a??"").trim();return T?`${T} (Product ${s})`:`Product ${s}`},[a,s]),D=P.useCallback(T=>A>1?`${k} image ${T+1}`:k,[k,A]),O=C?.[p],M=P.useMemo(()=>O?Gr({apiOrigin:x,randmarSKU:s,image:O,width:i*1.5,height:i*1.5}):null,[O,x,i,s]),I=P.useCallback(T=>{if(A<=0)return;const V=(T%A+A)%A;N(V)},[A]),F=P.useCallback(()=>I(p-1),[p,I]),Q=P.useCallback(()=>I(p+1),[p,I]),$=P.useCallback(T=>{if(!(A<=1))switch(T.key){case"ArrowLeft":T.preventDefault(),F();break;case"ArrowRight":T.preventDefault(),Q();break;case"Home":T.preventDefault(),I(0);break;case"End":T.preventDefault(),I(A-1);break}},[Q,F,I,A]);if(P.useEffect(()=>{if(!C?.length||A<=1)return;const T=(p-1+A)%A,V=(p+1)%A,ae=[T,V];for(const de of ae){const Oe=C[de];if(!Oe)continue;const Ne=Gr({apiOrigin:x,randmarSKU:s,image:Oe,width:i*1.5,height:i*1.5});if(b.current.has(Ne))continue;b.current.add(Ne);const Ve=new Image;Ve.src=Ne}},[p,x,i,s,A,C]),c)return e.jsx(e.Fragment,{children:n??null});if(f===null&&u&&m)return e.jsx("div",{className:r,ref:l,children:e.jsx(h,{className:"rounded-md",style:{width:i,height:i}})});if(C&&C.length===0){if(n!=null)return e.jsx(e.Fragment,{children:n});const T=Wc({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":k,children:w?e.jsx(Wr,{size:i,alt:k}):e.jsx("img",{alt:k,className:"w-full h-full object-contain",src:T,width:i,height:i,loading:"eager",onError:()=>y(!0)})})})}return M?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:$,children:[e.jsx("img",{alt:D(p),className:"w-full h-full object-contain",src:M,width:i,height:i,loading:"eager"}),A>1&&e.jsxs(e.Fragment,{children:[e.jsx(E,{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:F,"aria-label":"Previous image",children:e.jsx(g.ChevronLeft,{className:"h-4 w-4"})}),e.jsx(E,{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:Q,"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:A}).map((T,V)=>{const ae=V===p;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",ae?"bg-foreground":"bg-muted-foreground/40 hover:bg-muted-foreground/60"].join(" "),onClick:()=>I(V),"aria-label":`Go to image ${V+1} of ${A}`,"aria-current":ae?"true":void 0},V)})})]})]})}):e.jsx("div",{className:r,ref:l,children:e.jsx(Wr,{size:i,alt:k})})}const ji=()=>new Date().toISOString().split("T")[0],Yc=s=>s.StartDate?s.StartDate.split("T")[0]>ji():!1,Kr=s=>{if(s.Active!==!0)return!1;const t=ji();return!(s.EndDate&&s.EndDate.split("T")[0]<t||s.StartDate&&s.StartDate.split("T")[0]>t)};function Ht({applicationId:s,product:t,viewProductLink:a,defaultOpportunityNumber:r="",onAddToCart:n,addingToCart:i=!1,shopifyHostname:l,customAction:u=e.jsx(e.Fragment,{}),showUsdLabelOnCost:x=!1}){const d=Ce.useNavigate(),{toast:c}=Pe(),[m,f]=o.useState(1),[p,N]=o.useState(null),[w,y]=o.useState(0),[j,b]=o.useState(!1),[C]=_.usePostV4ResellerByRouteResellerIdProductAndRandmarSkuShopifyMutation(),[S,A]=o.useState(!1),[k,D]=o.useState(null),[O,M]=o.useState("idle"),[I,F]=o.useState(null),[Q]=_.useLazyGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery(),$=t?.Distribution?.Cost||0,z=t?.Distribution?.RegularPrice||0,T=t?.Distribution?.Price||0,V=!!(s&&t?.RandmarSKU);o.useEffect(()=>{f(1),N(null),y(0)},[t?.RandmarSKU]),o.useEffect(()=>{if(t&&r){const U=t.Opportunities?.find(me=>me.BidNumber==r);U&&Kr(U)&&N(U)}},[t,r]),o.useEffect(()=>{if(!t)return;const U=p?.Price?p.Price:T;y(z>0?Math.round((z-U)/z*100):0)},[t,p,T,z]),o.useEffect(()=>{i||f(1)},[i]),o.useEffect(()=>{if(!S){D(null),M("idle"),F(null);return}if(!s||!t?.RandmarSKU){M("error"),F("Missing identifiers to load performance data.");return}let U=!1;const me=t.RandmarSKU;return(async()=>{M("summary"),F(null);try{const Se=await Q({routeApplicationId:s,randmarSku:me,withSpecification:!1});if(U)return;if("error"in Se&&Se.error)throw Se.error;D(Se.data??null),M("detailed");const Fe=await Q({routeApplicationId:s,randmarSku:me,withSpecification:!0});if(U)return;if("error"in Fe&&Fe.error)throw Fe.error;D(Fe.data??Se.data??null),M("complete")}catch(Se){if(U)return;console.error("Failed to load performance data for product modal",Se),M("error"),F("We couldn't load the performance details. Please try again.")}})(),()=>{U=!0}},[s,Q,S,t?.RandmarSKU]);const ae=U=>U>=90?{label:"Top 10% Bestseller",color:"text-primary",bgColor:"bg-primary/10"}:U>=75?{label:"Bestseller",color:"text-info",bgColor:"bg-info/10"}:U>=33?{label:"Popular",color:"text-success",bgColor:"bg-success/10"}:{label:"Rising",color:"text-muted-foreground",bgColor:"bg-muted/30"},de=O!=="complete"&&O!=="error",Oe=O==="summary"?40:O==="detailed"?80:10,Ne=k?.SalesStatistics??[],Ve=de?[]:Ne,Le=k?.RandmarTitle??t?.RandmarTitle??t?.RandmarSKU??"this product",Ue=k?.RandmarSKU??t?.RandmarSKU,Ke=s&&t?.ManufacturerId?`/${encodeURIComponent(s)}/Partner/${encodeURIComponent(t.ManufacturerId)}?tab=manufacturer-overview`:null;if(!t)return e.jsx(q,{className:"flex h-full w-full flex-col",children:e.jsxs(W,{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 re=t?.Opportunities||[],ue=re.length>0,H=()=>{if(m==null){f(1);return}m>1&&f(m-1)},K=()=>{if(m==null){f(1);return}f(m+1)},Y=U=>{const me=Number.parseInt(U.target.value,10);if(!isNaN(me)&&me>0){f(me);return}f(void 0)},ee=()=>{(m==null||m<1)&&f(1)},pe=U=>{try{return new Date(U).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch(me){return console.error(me),U.split("T")[0]||"N/A"}},Re=U=>{const me=typeof t?.MSRP=="number"&&t.MSRP>0?t.MSRP:typeof t?.MAP=="number"&&t.MAP>0?t.MAP:null;if(me===null)return null;const we=U.Price??t?.Distribution?.Price;if(typeof we!="number")return null;const Se=U.Rebate??0,Fe=Math.max(we-Se,0);return me-Fe},ve=()=>{typeof n<"u"&&n({quantity:m??1,bidNumber:p?.BidNumber??null})},Ee=()=>{j||!l||(b(!0),C({routeResellerId:s??"",randmarSku:t.RandmarSKU??"",shopifyHostName:l}).then(U=>{if(U.error){console.error("Error syncing to Shopify:",U.error),c({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"});return}c({title:"Product synced",description:"Product synced to Shopify successfully",variant:"success"})}).catch(U=>{console.error("Error syncing to Shopify:",U),c({title:"Product synced failed.",description:"Error syncing to Shopify:",variant:"destructive"})}).finally(()=>{b(!1)}))};return e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"flex h-full w-full flex-col hover:shadow-lg transition-shadow @container",children:e.jsxs(W,{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:Ke?e.jsx(Ce.Link,{to:Ke,"aria-label":`Open manufacturer overview for ${t.ManufacturerName??"this manufacturer"}`,className:"block h-full w-full",children:e.jsx(hs,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40,className:"cursor-pointer"},`partner_logo_${t.ManufacturerId}`)}):e.jsx(hs,{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(he,{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(he,{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(he,{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(he,{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(he,{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(he,{variant:"info",className:"rounded-full px-3",children:[e.jsx(g.ShieldCheckIcon,{size:"12",className:"mr-1.5"})," ","Requires Opportunity"]}),t.ManufacturerId&&e.jsxs(he,{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(he,{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?`${ds(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?oe(t.MAP):"N/A",e.jsx("span",{className:"text-primary",children:" / "}),t.MSRP?oe(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(he,{variant:"outline",className:`rounded-full px-3 w-fit ${ae(t.OverallPercentileRank).bgColor} ${ae(t.OverallPercentileRank).color} hover:${ae(t.OverallPercentileRank).bgColor}`,children:ae(t.OverallPercentileRank).label})}),e.jsx(fe,{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(he,{variant:"outline",className:`rounded-full px-3 w-fit ${ae(t.ManufacturerPercentileRank).bgColor} ${ae(t.ManufacturerPercentileRank).color} hover:${ae(t.ManufacturerPercentileRank).bgColor}`,children:ae(t.ManufacturerPercentileRank).label})}),e.jsx(fe,{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(mi,{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(Kc,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||"",fallback:e.jsx(xr,{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:ue&&t.Distribution&&e.jsxs("div",{className:"w-full",children:[e.jsx("div",{className:"flex items-center",children:"You have "+re.length+(re.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:re.map((U,me)=>{const we=Re(U);return Kr(U)?e.jsxs("div",{className:`flex justify-between items-center rounded-lg transition-colors py-2 px-4 border cursor-pointer ${U.BidNumber==p?.BidNumber?"bg-primary/10 border-2 border-primary":"bg-background border-border hover:bg-muted/30"}`,onClick:()=>{N(U.BidNumber!==p?.BidNumber?U: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:U.Opportunity}),e.jsx("span",{className:"text-xs text-foreground",children:U.BidNumber})]})}),e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-semibold",children:oe(U.Price??0)}),U.Rebate&&U.Rebate>0&&e.jsxs("span",{className:"text-xs text-success",children:["Rebate: ",oe(U.Rebate)]}),we!==null&&e.jsxs("span",{className:"text-xs text-info",children:["Potential Revenue: ",oe(we)]}),U.EndDate&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Ends: ",pe(U.EndDate)]})]})]},me):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:()=>{U.BidNumber&&d(`/${s}/Opportunity/${U.ManufacturerId}/${U.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:U.Opportunity}),e.jsxs("span",{className:"text-xs text-foreground",children:[U.BidNumber," ",e.jsx(he,{variant:"secondary",className:"text-xs mx-1 h-5",children:Yc(U)&&U.StartDate?`Starts ${pe(U.StartDate)}`:"Currently unavailable"})]})]})}),e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-semibold",children:oe(U.Price??0)}),U.Rebate&&U.Rebate>0&&e.jsxs("span",{className:"text-xs text-success",children:["Rebate: ",oe(U.Rebate)]}),we!==null&&e.jsxs("span",{className:"text-xs text-info",children:["Potential Revenue: ",oe(we)]}),U.EndDate&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Ends: ",pe(U.EndDate)]})]})]})}),e.jsx(fe,{children:e.jsx("p",{children:"View Opportunity"})})]},me)})})})]})})})]}),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:$>0?e.jsx("div",{className:"flex items-center",children:e.jsxs("span",{className:"text-2xl font-bold whitespace-nowrap",children:["Cost: ",oe($),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:oe((p?t.Opportunities?.find(U=>U.BidNumber==p.BidNumber)?.Price:T)??0)})}),w>0&&e.jsx("span",{className:"text-muted-foreground line-through ml-2 whitespace-nowrap",children:oe(z)})]}),w>0&&e.jsx("div",{className:"flex items-center",children:e.jsxs(he,{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(E,{className:"gap-2 whitespace-nowrap",onClick:Ee,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"]})}),u,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(E,{variant:"ghost",size:"icon",className:"rounded-r-none",onClick:H,disabled:typeof m<"u"&&(m<=1||!t.AvailableToBuy||i),children:"-"}),e.jsx("input",{value:m,onChange:Y,onBlur:ee,onClick:U=>U.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(E,{variant:"ghost",size:"icon",className:"rounded-l-none",onClick:K,disabled:!t.AvailableToBuy||i,children:"+"})]}),e.jsx(E,{className:"gap-2 whitespace-nowrap",onClick:ve,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(E,{variant:"outline",type:"button",className:"h-11 px-4 text-sm font-medium justify-start w-full",onClick:()=>A(!0),disabled:!V,children:[e.jsx(g.LineChart,{className:"mr-2"}),"View statistics"]})}),e.jsx("div",{className:"flex-1 min-w-[10rem]",children:e.jsx(si,{applicationId:s??"",randmarSku:t.RandmarSKU??"",inventory:t.Distribution?.Inventory,buttonSize:"lg",buttonClassName:"w-full h-11 justify-start"})}),a&&e.jsx(Ce.Link,{to:a,className:"flex-1 min-w-[10rem]",children:e.jsxs(E,{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:A,children:e.jsxs(Me,{className:"w-[min(95vw,1100px)] max-w-5xl space-y-6",children:[e.jsxs($e,{children:[e.jsx(_e,{children:"Monthly Sales Performance"}),e.jsxs(ze,{children:["Expanded product insights for ",Le,Ue?` (SKU ${Ue})`:""]})]}),e.jsx("div",{className:"space-y-6",children:I?e.jsxs(vs,{variant:"destructive",children:[e.jsx(ws,{children:"Unable to load details"}),e.jsx(Ss,{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(lt,{value:Oe,className:"h-2 w-full animate-pulse","aria-label":"Loading performance data"})})]}),e.jsx(zs,{statistics:Ve,mode:"month",chartHeight:320}),de&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Gathering product summary and sales statistics..."})]})})]})})]})}const Jc={sm:100,md:200,lg:300,xl:400},Zc=({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"})}),Xc=()=>e.jsx(h,{className:"w-full",style:{aspectRatio:"16/9"}});function xr({randmarSKU:s,sceneName:t,size:a="md",alt:r,secondaryContent:n}){const[i,l]=P.useState(!1),[u,x]=P.useState(!1),{sendMessageWithClear:d}=Xs(),c=St(),m=Jc[a],f=o.useRef(null),p=Gt({elementRef:f,threshold:.1,rootMargin:"100px"}),{data:N,isFetching:w}=_.useGetProductByProductNumberImageExistsQuery({productNumber:s},{skip:!s||!p}),{data:y,isFetching:j}=_.useGetProductByRandmarSkuImageQuery({randmarSku:s,width:m*1.5,height:m*1.5},{skip:!N}),{data:b}=_.useGetProductByProductNumberVideoExistsQuery({productNumber:s},{skip:!s||!p}),{data:C,isFetching:S}=_.useGetProductByProductNumberVideoQuery({productNumber:s},{skip:!b||!i}),A=w||j;function k(){if(C)try{const I=document.createElement("a");I.href=C,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 D(){const I=`/Product/${encodeURIComponent(s)}/Video`;navigator.clipboard.writeText(js(I,c)),x(!0),setTimeout(()=>x(!1),2e3)}function O(){b&&l(!0)}const M=P.useCallback(()=>{if(!y)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.";d(`Help me generate product images for (Randmar SKU: ${s}).
72
+
73
+ ${F}
74
+
75
+ Repeat and ask me what to change or improve until we are done creating pictures.`)},[y,s,t,d]);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||!C?e.jsx(Xc,{}):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:C,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:C,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(E,{variant:"secondary",size:"icon",onClick:D,"aria-label":"Copy video link",children:u?e.jsx(g.Check,{className:"h-4 w-4"}):e.jsx(g.Copy,{className:"h-4 w-4"})})}),e.jsx(fe,{children:e.jsx("p",{children:"Copy video link"})})]})}),e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(E,{variant:"secondary",size:"icon",onClick:k,"aria-label":"Download video",children:e.jsx(g.Download,{className:"h-4 w-4"})})}),e.jsx(fe,{children:e.jsx("p",{children:"Download video"})})]})})]})]})})})}),e.jsxs("div",{className:"relative w-max h-max",ref:f,children:[A?e.jsx(h,{className:"rounded-md",style:{width:m,height:m}}):y?e.jsx("img",{alt:r||`Product ${s}`,className:`rounded-md ${b?"cursor-pointer":""}`,onClick:O,src:y,width:m,height:m}):e.jsx(Zc,{size:m}),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(E,{variant:"secondary",size:"icon",onClick:O,"aria-label":"Play product video",children:e.jsx(g.Play,{className:"h-4 w-4"})})}),e.jsx(fe,{children:e.jsx("p",{children:"Play video"})})]})}),y?e.jsx(ye,{children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(E,{variant:"secondary",size:"icon",onClick:M,"aria-label":"Ask AI to generate product images",children:e.jsx(g.Bot,{className:"h-4 w-4"})})}),e.jsx(fe,{children:e.jsx("p",{children:"Ask AI to generate product images"})})]})}):null]})]})]})}function ed({reseller:s,actions:t,loading:a=!1}){return a||!s?e.jsx(sd,{}):e.jsx(td,{reseller:s,actions:t})}function sd(){return e.jsxs(q,{children:[e.jsx(J,{children:e.jsx(ce,{children:e.jsx(h,{className:"h-6 w-40"})})}),e.jsxs(W,{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 td({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(q,{children:[e.jsx(J,{children:e.jsx(ce,{children:"Billing Overview"})}),e.jsxs(W,{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:oe(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:oe(i.amount)})})]},l))})]}),t&&e.jsx("div",{className:"flex justify-end mt-4",children:t})]})]})}function bi({qualifications:s=[],loading:t=!1}){return t?e.jsxs(q,{children:[e.jsx(J,{children:e.jsx(ce,{children:"Qualifications"})}),e.jsx(W,{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(q,{children:[e.jsx(J,{children:e.jsx(ce,{children:"Qualifications"})}),e.jsx(W,{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(ad,{manufacturerId:a.ManufacturerId,opportunityNumber:a.DefaultOpportunityNumber},`${a.ManufacturerId}-${r}`))})}):e.jsx("p",{children:"No qualification available."})})]})}function ad({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(hs,{id:s,width:96,height:48})}),t&&e.jsx(he,{variant:"outline",className:"text-xs",children:t})]})}function rd({salesData:s,salesStatistics:t=[],loading:a=!1}){return a||!s?e.jsx(nd,{}):e.jsx(id,{salesData:s,salesStatistics:t})}function nd(){return e.jsxs(q,{children:[e.jsx(J,{className:"pb-0",children:e.jsx(ce,{className:"text-lg @sm:text-xl",children:e.jsx(h,{className:"h-7 w-40"})})}),e.jsxs(W,{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 id({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(q,{children:[e.jsx(J,{className:"pb-0",children:e.jsx(ce,{className:"text-lg @sm:text-xl",children:"Sales Overview"})}),e.jsxs(W,{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:oe(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(zs,{statistics:t,chartHeight:300,mode:"week"})})]})})]})]})}function ld({icon:s,contentType:t,identifier:a,description:r,fields:n,actions:i,highlightedHeader:l=!1,className:u,...x}){const d=P.Children.toArray(i).filter(Boolean);return e.jsxs(q,{className:v("flex flex-col h-full overflow-hidden",u),...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((c,m)=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("dt",{className:"text-xs font-semibold text-muted-foreground",children:c.label}),e.jsx("dd",{className:"text-sm text-foreground",children:c.value??"-"})]},`${c.label}-${m}`))})}),d.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:d.map((c,m)=>e.jsx("div",{className:"flex items-center justify-center [&>*]:min-h-11 [&>*]:min-w-11",children:c},m))})})]})}const hr=Ze.Root,fr=Ze.Trigger,od=Ze.Portal,yi=P.forwardRef(({className:s,...t},a)=>e.jsx(Ze.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}));yi.displayName=Ze.Overlay.displayName;const Zt=P.forwardRef(({className:s,...t},a)=>e.jsxs(od,{children:[e.jsx(yi,{}),e.jsx(Ze.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})]}));Zt.displayName=Ze.Content.displayName;const Xt=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col space-y-2 text-center sm:text-left",s),...t});Xt.displayName="AlertDialogHeader";const ea=({className:s,...t})=>e.jsx("div",{className:v("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...t});ea.displayName="AlertDialogFooter";const sa=P.forwardRef(({className:s,...t},a)=>e.jsx(Ze.Title,{ref:a,className:v("text-lg font-semibold",s),...t}));sa.displayName=Ze.Title.displayName;const ta=P.forwardRef(({className:s,...t},a)=>e.jsx(Ze.Description,{ref:a,className:v("text-sm text-muted-foreground",s),...t}));ta.displayName=Ze.Description.displayName;const aa=P.forwardRef(({className:s,...t},a)=>e.jsx(Ze.Action,{ref:a,className:v(_s(),s),...t}));aa.displayName=Ze.Action.displayName;const ra=P.forwardRef(({className:s,...t},a)=>e.jsx(Ze.Cancel,{ref:a,className:v(_s({variant:"outline"}),"mt-2 sm:mt-0",s),...t}));ra.displayName=Ze.Cancel.displayName;const cd="https://assistant.randmar.io";function dd(s){if(s==null)return null;const t=s instanceof Date?s:new Date(s);return Number.isNaN(t.getTime())?null:t}function ud(s){const t=dd(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 Ni({lastRefreshAt:s,onRefresh:t,onProgressiveRefresh:a,onAssistantClick:r,isRefreshing:n=!1,refreshLabel:i="Refresh",assistantLabel:l="Assistant",className:u,disabled:x=!1}){const[d,c]=P.useState(!1),[m,f]=P.useState(s);P.useEffect(()=>{f(s)},[s]);const p=!!(t||a),N=n||d,w=s??m,y=P.useCallback(async()=>{if(!(!p||x||N)){c(!0);try{a?(await a(!1),await a(!0)):await t?.(),f(new Date)}finally{c(!1)}}},[p,x,N,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",u),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:ud(w)})]}),e.jsxs(E,{type:"button",variant:"outline",className:"min-h-11",disabled:x||N||!p,onClick:y,children:[N?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(E,{asChild:!0,variant:"default",className:v("min-h-11 lg:hidden",x&&"pointer-events-none opacity-50"),children:e.jsxs("a",{href:cd,target:"_blank",rel:"noopener noreferrer","aria-disabled":x||void 0,onClick:x?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(E,{type:"button",variant:"default",className:"hidden min-h-11 lg:inline-flex",disabled:x,onClick:r,children:[e.jsx(g.Bot,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{children:l})]})]})}function md({onAssistantClick:s,assistantPromptOptions:t,onAssistantUnavailable:a,...r}){const n=Bn(),i=P.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(Ni,{...r,onAssistantClick:i})}const Yr="w-full max-w-none w-[100cqw] ml-[calc(50%-50cqw)] mr-[calc(50%-50cqw)]",vi="px-4 lg:px-6",xd=`${vi} py-4`,hd=`${vi} py-3`;function fd({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 pd({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(fd,{item:t,isCurrent:!!t.current||r}),r?null:e.jsx("span",{"aria-hidden":"true",className:"text-xs text-muted-foreground",children:"/"})]},n)})})})}function wi({title:s,subtitle:t,breadcrumbs:a,rightTopActions:r,rightBottomActions:n,secondaryRow:i,sticky:l=!1,stickyClassName:u,className:x,cardClassName:d,contentClassName:c}){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(xd,d),children:e.jsxs("div",{className:v("flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",c),children:[e.jsxs("div",{className:"space-y-1",children:[a?.length?e.jsx(pd,{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:hd,children:i})}):null]});return l?e.jsx("div",{className:Yr,children:e.jsx("div",{className:v("sticky top-0 z-20",u),children:f})}):e.jsx("div",{className:Yr,children:f})}function gd({title:s,children:t,className:a}){return e.jsx(wi,{title:s,rightBottomActions:t?e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:t}):void 0,cardClassName:a})}const Si="space-y-8",Ci="px-4 py-4 sm:px-6 sm:py-6";function jd({header:s,children:t,className:a,contentClassName:r,contentProps:n,...i}){return e.jsxs("section",{className:v(Si,a),...i,children:[s,e.jsx("div",{className:v(Ci,r),...n,children:t})]})}function bd({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 yd=[{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"}],Nd=`
76
+ .ProseMirror {
77
+ min-height: 150px;
78
+ padding: 0.5rem;
79
+ }
80
+ .ProseMirror:focus {
81
+ outline: none;
82
+ }
83
+ .ProseMirror h1 {
84
+ font-size: 2em;
85
+ font-weight: bold;
86
+ margin-bottom: 0.5em;
87
+ }
88
+ .ProseMirror h2 {
89
+ font-size: 1.5em;
90
+ font-weight: bold;
91
+ margin-bottom: 0.5em;
92
+ }
93
+ .ProseMirror h3 {
94
+ font-size: 1.17em;
95
+ font-weight: bold;
96
+ margin-bottom: 0.5em;
97
+ }
98
+ .ProseMirror h4 {
99
+ font-size: 1em;
100
+ font-weight: bold;
101
+ margin-bottom: 0.5em;
102
+ }
103
+ .ProseMirror h5 {
104
+ font-size: 0.83em;
105
+ font-weight: bold;
106
+ margin-bottom: 0.5em;
107
+ }
108
+ .ProseMirror h6 {
109
+ font-size: 0.67em;
110
+ font-weight: bold;
111
+ margin-bottom: 0.5em;
112
+ }
113
+ .ProseMirror ul {
114
+ list-style-type: disc;
115
+ padding-left: 1.5em;
116
+ margin-bottom: 0.5em;
117
+ }
118
+ .ProseMirror ol {
119
+ list-style-type: decimal;
120
+ padding-left: 1.5em;
121
+ margin-bottom: 0.5em;
122
+ }
123
+ .ProseMirror li {
124
+ margin-bottom: 0.25em;
125
+ }
126
+ .ProseMirror p {
127
+ margin-bottom: 0.5em;
128
+ }
129
+ `;function vd({id:s,name:t,value:a,onChange:r,placeholder:n,className:i,...l}){const[u,x]=o.useState(!1),d=o.useRef(null),c=o.useRef(null),m=Fr.useEditor({extensions:[bl,yl],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(()=>{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 b=Number.parseInt(j.slice(1));m.chain().setHeading({level:b}).run()}},[m]),p=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]),N=o.useCallback(()=>{x(j=>!j)},[]),w=o.useCallback(j=>{const b=j.target.value;m&&m.commands.setContent(b),r({target:{id:s,name:t,value:b}})},[r,m,s,t]),y=o.useCallback(()=>{!u&&m&&m.commands.focus()},[u,m]);return m?e.jsxs("div",{ref:c,className:v("border border-input rounded-md overflow-hidden focus-within:outline-hidden focus-within:ring-1 focus-within:ring-ring",i),onClick:y,...l,children:[e.jsx("style",{children:Nd}),e.jsxs("div",{className:"flex flex-wrap items-center p-2 border-b border-input gap-2 bg-background",children:[e.jsxs(As,{onValueChange:f,disabled:u,children:[e.jsx(ys,{className:"w-[160px]",children:e.jsx(Is,{placeholder:"Format"})}),e.jsx(Ns,{children:yd.map(j=>e.jsx(as,{value:j.value,children:j.label},j.value))})]}),["bold","italic","underline","strike","bulletList","orderedList"].map(j=>e.jsxs(E,{type:"button",variant:"ghost",size:"sm",onClick:()=>p(j),className:m.isActive(j)?"bg-muted":"",disabled:u,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(E,{type:"button",variant:"ghost",size:"sm",onClick:N,className:u?"bg-muted":"",children:e.jsx(g.Code,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"p-3",children:u?e.jsx(bs,{ref:d,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(Fr.EditorContent,{editor:m})})]}):null}function wd({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})=>Js(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(Ce.Link,{to:`/${s}/Document/${l.original.ReceiptNumber}`,className:"font-medium text-primary hover:underline",children:l.original.ReceiptNumber})}),e.jsx(fe,{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?oe(l.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0}],[]),n=o.useMemo(()=>{const l={};if(t){const u=Array.from(new Set(t.map(d=>d.Location).filter(d=>d!=null)));l.Location=u;const x=Array.from(new Set(t.map(d=>Js(d.ReceiptDate)).filter(d=>d!=="—"&&d!=="Invalid Date"))).sort((d,c)=>new Date(c).getTime()-new Date(d).getTime());l.ReceiptDate=x}return l},[t]),i=t||[];return e.jsx(Ms,{columns:r,data:i,uniqueValues:n,loading:a,tableClass:"bg-card text-card-foreground",initialSort:[{id:"ReceiptDate",desc:!0}]})}const ga=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"}},Sd=s=>{const t=s?.toLowerCase()||"";return t.includes("accepted")?"success":t.includes("error")||t.includes("rejected")?"destructive":"neutral"};function pr({applicationId:s,returns:t=null,loading:a=!1}){const r=o.useMemo(()=>[{accessorKey:"ReturnNumber1",header:"RMA Number",cell:({row:l})=>{const u=l.original.ReturnNumber1||l.original.ReturnNumber;return u?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(Ce.Link,{to:`/${s}/Return/${u}`,className:"font-medium text-primary hover:underline",children:u})}),e.jsx(fe,{children:e.jsxs("p",{children:["View details for return ",u]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestDate",header:"Request Date",cell:({row:l})=>ga(l.original.RequestDate),enableSorting:!0},{accessorKey:"InvoiceNumber",header:"Invoice Number",cell:({row:l})=>{const u=l.original.InvoiceNumber;return u?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(Ce.Link,{to:`/${s}/Document/${u}`,className:"text-primary hover:underline",children:u})}),e.jsx(fe,{children:e.jsxs("p",{children:["View details for invoice ",u]})})]})}):"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 u=l.original.Status,x=Sd(u),d=x==="success"?"success":x==="destructive"?"destructive":"secondary";return u?e.jsx(he,{variant:d,className:"font-medium",children:u}):"—"},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})=>ga(l.original.LastUpdatedDate)!=="N/A"?ga(l.original.LastUpdatedDate):"—",enableSorting:!0}],[s]),n=o.useMemo(()=>{const l={};if(t){const u=Array.from(new Set(t.map(c=>c.Status).filter(Boolean)));l.Status=u;const x=Array.from(new Set(t.map(c=>c.ReasonForReturn).filter(Boolean)));l.ReasonForReturn=x;const d=Array.from(new Set(t.map(c=>c.WarehouseLocation).filter(Boolean)));l.WarehouseLocation=d}return l},[t]),i=o.useMemo(()=>t?[...t].sort((u,x)=>(x.ReturnNumber1||x.ReturnNumber||"").localeCompare(u.ReturnNumber1||u.ReturnNumber||"")):[],[t]);return a?e.jsxs(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(h,{className:"h-7 w-48"})}),e.jsxs(W,{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(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-xl font-semibold text-foreground",children:"Returns"})}),e.jsx(W,{children:e.jsx(Ms,{columns:r,data:i,uniqueValues:n})})]})}function Cd({applicationId:s,purchaseOrders:t=null,loading:a=!1}){const[r,n]=o.useState([]),[i]=_.usePostV4ManufacturerByRouteManufacturerIdPurchaseOrderAndPurchaseOrderNumberEditItemRandmarSkuMutation(),{toast:l}=Pe();o.useEffect(()=>{n(t||[])},[t]);const u=o.useMemo(()=>[{accessorKey:"PurchaseOrderNumber",header:"Number",cell:({row:d})=>d.original.PurchaseOrderNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(Ce.Link,{to:`/${s}/Document/${d.original.PurchaseOrderNumber}`,className:"font-medium text-primary hover:underline",children:d.original.PurchaseOrderNumber})}),e.jsx(fe,{children:e.jsxs("p",{children:["View details for Purchase Order ",d.original.PurchaseOrderNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PurchaseOrderDate",header:"Date",cell:({row:d})=>Js(d.original.PurchaseOrderDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:d})=>d.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PartNumber",header:"Part Number",cell:({row:d})=>d.original.MPN?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(Ce.Link,{to:`/${s}/Product/${d.original.RandmarSKU}`,className:"font-medium text-primary hover:underline",children:d.original.MPN})}),e.jsx(fe,{children:e.jsxs("p",{children:["View details for Product ",d.original.RandmarSKU]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:d})=>d.original.QuantityOrdered??0,enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:d})=>d.original.UnitPrice?oe(d.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:c}){const[m,f]=o.useState(!1),p=c.original,N=()=>{f(!0),i({routeManufacturerId:s,purchaseOrderNumber:p.PurchaseOrderNumber??"",randmarSku:p.RandmarSKU??"",quantity:0}).then(()=>{n(w=>w.filter(y=>!(y.PurchaseOrderNumber===y.PurchaseOrderNumber&&y.MPN===y.MPN))),l({variant:"success",title:"Success",description:`Part ${p.MPN} has been successfully deleted from Purchase Order ${p.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(hr,{children:[e.jsx(fr,{asChild:!0,children:e.jsx(E,{variant:"red",size:"sm",disabled:m,children:m?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(Zt,{children:[e.jsxs(Xt,{children:[e.jsx(sa,{children:"Confirmation"}),e.jsxs(ta,{children:["Are you sure you want to delete part ",e.jsx("strong",{children:p.MPN})," from Purchase Order ",e.jsx("strong",{children:p.PurchaseOrderNumber}),"?."]})]}),e.jsxs(ea,{children:[e.jsx(ra,{disabled:m,children:"Cancel"}),e.jsxs(aa,{onClick:N,disabled:m,children:[m&&e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}],[s]),x=o.useMemo(()=>{const d={};return r&&(d.PurchaseOrderNumber=Array.from(new Set(r.map(c=>c.PurchaseOrderNumber).filter(c=>c!=null))),d.PurchaseOrderDate=Array.from(new Set(r.map(c=>c.PurchaseOrderDate).filter(c=>c!=null).map(String))),d.Location=Array.from(new Set(r.map(c=>c.Location).filter(c=>c!=null))),d.PartNumber=Array.from(new Set(r.map(c=>c.MPN).filter(c=>c!=null))),d.QuantityOrdered=Array.from(new Set(r.map(c=>c.QuantityOrdered).filter(c=>c!=null).map(String))),d.UnitPrice=Array.from(new Set(r.map(c=>c.UnitPrice).filter(c=>c!=null).map(String)))),d},[r]);return e.jsx(Ms,{columns:u,data:r,uniqueValues:x,loading:a,tableClass:"bg-card text-card-foreground"})}function kd({applicationId:s,requisitions:t=null,loading:a=!1}){const[r,n]=o.useState([]),[i]=_.useDeleteV4ManufacturerByRouteManufacturerIdRequisitionAndRequisitionNumberMutation(),{toast:l}=Pe();o.useEffect(()=>{n(t||[])},[t]);const u=o.useMemo(()=>[{accessorKey:"RequisitionNumber",header:"Number",cell:({row:d})=>d.original.RequisitionNumber?e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(Ce.Link,{to:`/${s}/Document/${d.original.RequisitionNumber}`,className:"font-medium text-primary hover:underline",children:d.original.RequisitionNumber})}),e.jsx(fe,{children:e.jsxs("p",{children:["View details for Draft Purchase ",d.original.RequisitionNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequisitionDate",header:"Date",cell:({row:d})=>Js(d.original.RequisitionDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:d})=>d.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:d})=>d.original.QuantityOrdered??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOutstanding",header:"Quantity Outstanding",cell:({row:d})=>d.original.QuantityOutstanding??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityReceived",header:"Quantity Received",cell:({row:d})=>d.original.QuantityReceived??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"SubTotal",header:"Sub Total",cell:({row:d})=>d.original.SubTotal?oe(d.original.SubTotal):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestedBy",header:"Requestor",cell:({row:d})=>d.original.RequestedBy??"—",enableSorting:!0,enableFiltering:!0},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:c}){const[m,f]=o.useState(!1),p=c.original,N=()=>{f(!0),i({routeManufacturerId:s,requisitionNumber:p.RequisitionNumber??""}).then(()=>{n(w=>w.filter(y=>y.RequisitionNumber!==y.RequisitionNumber)),l({variant:"success",title:"Success",description:`Draft Purchase ${p.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(hr,{children:[e.jsx(fr,{asChild:!0,children:e.jsx(E,{variant:"red",size:"sm",disabled:m,children:m?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(Zt,{children:[e.jsxs(Xt,{children:[e.jsx(sa,{children:"Confirmation"}),e.jsxs(ta,{children:["Are you sure you want to cancel Draft Purchase ",e.jsx("strong",{children:p.RequisitionNumber}),"?."]})]}),e.jsxs(ea,{children:[e.jsx(ra,{disabled:m,children:"Cancel"}),e.jsxs(aa,{onClick:N,disabled:m,children:[m&&e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}],[s]),x=o.useMemo(()=>{const d={};return r&&(d.RequisitionNumber=Array.from(new Set(r.map(c=>c.RequisitionNumber).filter(c=>c!=null))),d.RequisitionDate=Array.from(new Set(r.map(c=>c.RequisitionDate).filter(c=>c!=null).map(String))),d.QuantityOrdered=Array.from(new Set(r.map(c=>c.QuantityOrdered).filter(c=>c!=null).map(String))),d.QuantityOutstanding=Array.from(new Set(r.map(c=>c.QuantityOutstanding).filter(c=>c!=null).map(String))),d.QuantityReceived=Array.from(new Set(r.map(c=>c.QuantityReceived).filter(c=>c!=null).map(String))),d.Location=Array.from(new Set(r.map(c=>c.Location).filter(c=>c!=null))),d.RequestedBy=Array.from(new Set(r.map(c=>c.RequestedBy).filter(c=>c!=null))),d.SubTotal=Array.from(new Set(r.map(c=>c.SubTotal).filter(c=>c!=null).map(String)))),d},[r]);return e.jsx(Ms,{columns:u,data:r,uniqueValues:x,loading:a,tableClass:"bg-card text-card-foreground"})}const Rd=new Intl.DateTimeFormat(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"});function Ma(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,u,x]=n.split("-"),d=Number.parseInt(l??"",10),c=Number.parseInt(u??"",10),m=Number.parseInt(x??"",10);if(!Number.isFinite(d)||!Number.isFinite(c)||!Number.isFinite(m))return null;let f=0,p=0,N=0,w=0;if(i){const j=i.trim(),[b,C,S]=j.split(":");if(f=Number.parseInt(b??"0",10),p=Number.parseInt(C??"0",10),S){const[A,k]=S.split(".");N=Number.parseInt(A??"0",10),k&&(w=Number.parseInt(k.slice(0,3).padEnd(3,"0"),10))}}if(!Number.isFinite(f)||!Number.isFinite(p)||!Number.isFinite(N)||!Number.isFinite(w))return null;const y=new Date(d,c-1,m,f,p,N,w);return Number.isNaN(y.getTime())||y.getFullYear()!==d||y.getMonth()!==c-1||y.getDate()!==m?null:y}function Pd(s){const t=Ma(s);return t?Rd.format(t):"—"}function Ad({logs:s=null,loading:t=!1}){const a=o.useMemo(()=>[{accessorKey:"DateTime",header:"Date & Time",cell:({row:r})=>Pd(r.original.DateTime),enableSorting:!0,enableFiltering:!1,sortingFn:(r,n,i)=>{const l=Ma(r.getValue(i)),u=Ma(n.getValue(i)),x=l?l.getTime():Number.NEGATIVE_INFINITY,d=u?u.getTime():Number.NEGATIVE_INFINITY;return x===d?0:x>d?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(Ms,{columns:a,data:s||[],uniqueValues:{},loading:t,tableClass:"bg-card text-card-foreground",initialSort:[{id:"DateTime",desc:!0}]})}function Id({applicationId:s,sku:t,product:a,productDefaultOpportunityNumber:r="",productOnAddToCart:n,productAddingToCart:i=!1,productShopifyHostname:l,productCustomAction:u=e.jsx(e.Fragment,{})}){const{data:x,isLoading:d}=_.useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:s,randmarSku:t??"",withSpecification:!1},{skip:!!a||!s||!t}),{data:c,isLoading:m}=_.useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:s,randmarSku:t??"",withSpecification:!0},{skip:!!a||!s||!t}),f=a??c??x,{data:p}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:s}),N=p?.IsManufacturer&&p?.BillingInformation?.CurrencyCode?.toUpperCase()==="USD",[w,y]=o.useState("stats-tab"),[j,b]=o.useState(!1);o.useEffect(()=>{if(!a&&m){b(!1);return}const $={"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":!p?.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($).some(T=>!T);if(b(z),z&&$[w]){const T=Object.keys($).find(V=>!$[V]);T&&y(T)}},[m,f,a,w,p?.IsManufacturer]);const C=!a&&(d||m),S=f?.Title||f?.RandmarTitle||f?.RandmarSKU||"Product",A=f?.VoiceoverCaption||"",k=typeof f?.MAP=="number"&&f.MAP>0?f.MAP:typeof f?.Distribution?.MAP=="number"&&f.Distribution.MAP>0?f.Distribution.MAP:null,D=typeof f?.MSRP=="number"&&f.MSRP>0?f.MSRP:typeof f?.Distribution?.MSRP=="number"&&f.Distribution.MSRP>0?f.Distribution.MSRP:null,O=r?f?.Opportunities?.find($=>$.BidNumber===r)?.Price:null,M=typeof O=="number"&&O>0?O:typeof f?.Distribution?.Price=="number"&&f.Distribution.Price>0?f.Distribution.Price:null,I=C||typeof M=="number",F=typeof k=="number"&&typeof M=="number"?k-M:null,Q=typeof F=="number"&&typeof k=="number"&&k>0?Math.round(F/k*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(q,{className:"@md:col-span-2",children:[e.jsxs(J,{className:"space-y-2",children:[e.jsx(ce,{className:"text-2xl font-semibold leading-tight",children:C&&!f?e.jsx(h,{className:"h-7 w-2/3"}):S}),A?e.jsx("div",{className:"text-sm text-muted-foreground",children:A}):C&&!f?e.jsx(h,{className:"h-4 w-4/5"}):null]}),e.jsxs(W,{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 M=="number"?oe(M):C?e.jsx(h,{className:"h-9 w-40"}):null})]}),typeof F=="number"&&typeof Q=="number"?e.jsxs("div",{className:"flex flex-col items-start @sm:items-end",children:[e.jsxs(he,{variant:F>=0?"success":"destructive",className:"rounded-full px-3 py-1.5 text-sm font-semibold",children:[F>=0?"Potential Profit":"Below MAP",": ",oe(Math.abs(F))]}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:F>=0?`${Q}% margin vs MAP`:`${Math.abs(Q)}% 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(fe,{children:"Minimum Advertised Price — the lowest price you can publicly advertise."})]})}),e.jsx("div",{className:"font-medium",children:typeof k=="number"?oe(k):"—"})]}),typeof F=="number"&&typeof M=="number"&&typeof k=="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:[oe(k)," - ",oe(M)," = ",oe(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(fe,{children:"Manufacturer's Suggested Retail Price — a reference retail list price."})]})}),e.jsx("div",{className:"font-medium",children:typeof D=="number"?oe(D):"—"})]})})]})})]}),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(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(Ht,{applicationId:s,product:f,defaultOpportunityNumber:r,onAddToCart:n,addingToCart:i,shopifyHostname:l,customAction:u,showUsdLabelOnCost:N})})]}),e.jsx("div",{className:"my-4",children:d||m?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"})}):j&&e.jsxs(tr,{value:w,onValueChange:y,children:[e.jsxs(Kt,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[e.jsx(Je,{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(Je,{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(Je,{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(Je,{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(Je,{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(Je,{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(Je,{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:!p?.IsManufacturer||(f?.PurchaseOrders?.length??0)<=0&&(f?.Requisitions?.length??0)<=0,children:"Purchase Orders"}),e.jsx(Je,{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(Je,{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(ts,{value:"stats-tab",children:e.jsx("div",{className:"mt-4",children:e.jsx(ar,{statistics:f?.SalesStatistics??[],loading:m})})}),e.jsx(ts,{value:"inventory-tab",children:e.jsx("div",{className:"mt-4",children:e.jsx(La,{inventory:f?.Distribution?.Inventory??[],className:"bg-card text-card-foreground"})})}),e.jsx(ts,{value:"opportunities-tab",children:e.jsx("div",{className:"mt-4",children:e.jsx(gr,{applicationId:s,opportunities:f?.Opportunities,loading:m})})}),e.jsx(ts,{value:"active-orders-tab",children:(f?.ActiveOrderDetails?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsx(yt,{applicationId:s,title:"Active Orders",orders:f?.ActiveOrderDetails,loading:m})})}),e.jsx(ts,{value:"completed-orders-tab",children:(f?.CompletedOrderDetails?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsx(yt,{applicationId:s,title:"Completed Orders",orders:f?.CompletedOrderDetails,loading:m})})}),e.jsx(ts,{value:"returns-tab",children:(f?.Returns?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsx(pr,{applicationId:s,returns:f?.Returns,loading:m})})}),e.jsxs(ts,{value:"purchase-orders-tab",children:[(f?.PurchaseOrders?.length??0)>0&&e.jsxs(q,{className:"mt-4 w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-1xl font-bold",children:"Purchase Orders"})}),e.jsx(W,{children:e.jsx(Cd,{applicationId:s,purchaseOrders:f?.PurchaseOrders,loading:m})})]}),(f?.Requisitions?.length??0)>0&&e.jsxs(q,{className:"mt-4 w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-1xl font-bold",children:"Draft Purchases"})}),e.jsx(W,{children:e.jsx(kd,{applicationId:s,requisitions:f?.Requisitions,loading:m})})]})]}),e.jsx(ts,{value:"warehouse-tab",children:(f?.Receipts?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsxs(q,{className:"mt-4 w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-1xl font-bold",children:"Receipts"})}),e.jsx(W,{children:e.jsx(wd,{applicationId:s,receipts:f?.Receipts,loading:m})})]})})}),e.jsx(ts,{value:"logs-tab",children:(f?.Logs?.length??0)>0&&e.jsx("div",{className:"mt-4",children:e.jsxs(q,{className:"w-full",children:[e.jsx(J,{children:e.jsx(ce,{className:"text-1xl font-bold",children:"Logs"})}),e.jsx(W,{children:e.jsx(Ad,{logs:f?.Logs,loading:m})})]})})})]})})]})}const ft={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"}},Dd=s=>{const t={base:1,md:2,...s};return["grid","gap-4",t.base?ft.base[t.base]:"",t.sm?ft.sm[t.sm]:"",t.md?ft.md[t.md]:"",t.lg?ft.lg[t.lg]:"",t.xl?ft.xl[t.xl]:""].filter(Boolean).join(" ")},Md=({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:u}=i;if(l.length===0)return null;const x=Dd(u);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((d,c)=>a(d,c))})]},n)})})},Td=["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=Td,onReloadSearch:r,onAssistantClick:n,reloadLabel:i="Reload Search",assistantLabel:l="Assistant",icon:u,className:x}){const c=`No Results "${s.trim()}"`,m=a.length>0;return e.jsxs(q,{className:v("w-full border-border bg-card",x),children:[e.jsxs(J,{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:u??e.jsx(g.SearchX,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ce,{className:"text-xl leading-tight",children:c}),e.jsx(it,{children:t})]})]}),e.jsx(W,{className:"border-t border-border pt-4",children:m?e.jsx("ul",{className:"space-y-2 text-sm text-foreground",children:a.map((f,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:f})]},`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(fs,{className:"border-t border-border pt-4",children:e.jsxs("div",{className:"flex w-full flex-wrap justify-end gap-3",children:[e.jsx(E,{type:"button",variant:"outline",onClick:r,disabled:!r,children:i}),e.jsx(E,{type:"button",variant:"default",onClick:n,disabled:!n,children:l})]})})]})}function Ed(s){const t=s?.trim();return t?`Search Results for "${t}"`:"Search Results"}function Od({query:s,title:t,subtitle:a,actions:r,children:n,className:i,contentClassName:l}){const u=r??n;return e.jsx("header",{className:v("w-full",i),children:e.jsx(q,{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??Ed(s)}),a?e.jsx("p",{className:"text-sm text-muted-foreground",children:a}):null]}),u?e.jsx("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-2",children:u}):null]})})})}function Ld(){return e.jsxs(q,{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 Jr({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(Ld,{},`search-cards-skeleton-${a}`))})]})}function Zr({tableRows:s}){return e.jsxs("section",{className:"space-y-4",children:[e.jsx(h,{className:"h-6 w-56 bg-muted"}),e.jsx(q,{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(Jr,{cardCount:t}):null,s==="table"?e.jsx(Zr,{tableRows:a}):null,s==="mixed"?e.jsxs(e.Fragment,{children:[e.jsx(Jr,{cardCount:Math.max(3,Math.min(t,6))}),e.jsx(Zr,{tableRows:a})]}):null,e.jsx("span",{className:"sr-only",children:"Loading search results"})]})}const Fd=({query:s,results:t,isLoading:a,header:r,loadingState:n,noResultsState:i,initialState:l,className:u,resultsContainerClassName:x,children:d})=>{const c=Array.isArray(t)?t:[],m=s.trim().length>0,f=c.length>0;let p=null;return f?p=e.jsx("div",{className:v("grid grid-cols-3 gap-8",x),children:e.jsx("div",{className:"col-span-3",children:d})}):a?p=n??e.jsx(Ri,{}):m?p=i??e.jsx(ki,{query:s}):p=l??null,!r&&!p?null:e.jsxs("div",{className:v("w-full space-y-6",u),children:[r,p]})},Bd=$s.Root,Pi=P.forwardRef(({className:s,...t},a)=>e.jsx($s.Item,{ref:a,className:v("border-b",s),...t}));Pi.displayName="AccordionItem";const Ai=P.forwardRef(({className:s,children:t,...a},r)=>e.jsx($s.Header,{className:"flex",children:e.jsxs($s.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=$s.Trigger.displayName;const Ii=P.forwardRef(({className:s,children:t,...a},r)=>e.jsx($s.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=$s.Content.displayName;function Di({className:s,classNames:t,showOutsideDays:a=!0,captionLayout:r="label",buttonVariant:n="ghost",formatters:i,components:l,...u}){const x=wa.getDefaultClassNames();return e.jsx(wa.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:d=>d.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(_s({variant:n}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",x.button_previous),button_next:v(_s({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:d,rootRef:c,...m})=>e.jsx("div",{"data-slot":"calendar",ref:c,className:v(d),...m}),Chevron:({className:d,orientation:c,...m})=>c==="left"?e.jsx(g.ChevronLeftIcon,{className:v("size-4",d),...m}):c==="right"?e.jsx(g.ChevronRightIcon,{className:v("size-4",d),...m}):e.jsx(g.ChevronDownIcon,{className:v("size-4",d),...m}),DayButton:$d,WeekNumber:({children:d,...c})=>e.jsx("td",{...c,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:d})}),...l},...u})}function $d({className:s,day:t,modifiers:a,...r}){const n=wa.getDefaultClassNames(),i=P.useRef(null);return P.useEffect(()=>{a.focused&&i.current?.focus()},[a.focused]),e.jsx(E,{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 _d(s){return e.jsx(q,{className:"max-w-6xl",children:e.jsx(Jt,{className:"h-[40em]",userId:s.userId,userName:s.userName,initialPrompt:s.initialPrompt})})}function ja(s){if(!s||!Ta(s))return"";const t=s.getTimezoneOffset()*6e4;return new Date(s.getTime()-t).toISOString().split("T")[0]}function Ta(s){return s instanceof Date&&!Number.isNaN(s.getTime())}function Bt({date:s,onDateChange:t,label:a,id:r,className:n}){const[i,l]=P.useState(!1),[u,x]=P.useState(s),[d,c]=P.useState(ja(s));P.useEffect(()=>{c(ja(s)),Ta(s)&&x(s)},[s]);const m=p=>{const w=p.target.value.replace(/\D/g,"").slice(0,8);let y=w;if(w.length>4&&(y=`${w.slice(0,4)}-${w.slice(4)}`),w.length>6&&(y=`${w.slice(0,4)}-${w.slice(4,6)}-${w.slice(6)}`),c(y),w.length===8){const j=new Date(y),b=new Date(j.getUTCFullYear(),j.getUTCMonth(),j.getUTCDate());Ta(b)?(t(b),x(b)):t(void 0)}else t(void 0)},f=p=>{p&&(t(p),c(ja(p))),l(!1)};return e.jsxs("div",{className:v("flex flex-col gap-2",n),children:[a&&e.jsx(Z,{htmlFor:r,children:a}),e.jsxs("div",{className:"relative",children:[e.jsx(ne,{id:r,value:d,placeholder:"YYYY-MM-DD",className:"bg-background pr-10",onChange:m,onKeyDown:p=>{p.key==="ArrowDown"&&(p.preventDefault(),l(!0))}}),e.jsxs(Ct,{open:i,onOpenChange:l,children:[e.jsx(kt,{asChild:!0,children:e.jsx(E,{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(ot,{className:"w-auto min-w-[280px] p-0",align:"end",sideOffset:8,children:e.jsx(Di,{mode:"single",selected:s,onSelect:f,month:u,onMonthChange:x,initialFocus:!0,className:"w-full"})})]})]})]})}function Vd({product:s,viewProductLink:t}){return s?e.jsx(q,{className:"@container border-dashed border-2 hover:shadow-md transition-shadow h-full",children:e.jsxs(W,{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(hs,{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(xr,{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(hs,{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(he,{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(he,{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(Ce.Link,{to:t,children:e.jsxs(E,{variant:"secondary",className:"w-full @[36rem]:w-auto",children:[e.jsx(g.LucideEye,{className:"mr-2 h-4 w-4"}),"View Product"]})})})]})]})]})}):e.jsx(q,{className:"@container border-dashed border-2 h-full",children:e.jsx(W,{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 zd(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 ba=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 gr({applicationId:s,opportunities:t=null,loading:a=!1}){const{toast:r}=Pe(),[n,i]=o.useState({}),[l,u]=o.useState(!1),[x,d]=o.useState(""),[c,m]=o.useState(null),{data:f}=_.useGetV4PartnerByApplicationIdAccountQuery({applicationId:s},{skip:!s}),p=o.useCallback((D,O,M)=>{i(I=>({...I,[D]:{...I[D],[O]:M}}))},[]),[N]=_.usePutV4ResellerByRouteResellerIdOpportunityAndManufacturerIdDefaultMutation(),w=o.useCallback(async D=>{if(!f?.IsReseller)return;if(!D.BidNumber){r({title:"Error",description:"Bid Number is missing, cannot set default.",variant:"destructive"});return}const O=D.BidNumber;p(O,"isSettingDefault",!0),N({routeResellerId:s,manufacturerId:D.ManufacturerId??"",opportunityNumber:O}).unwrap().then(()=>{r({title:"Success",description:`Opportunity "${D.OpportunityName||D.Opportunity||O}" was successfully set as default.`,variant:"success"})}).catch(M=>{console.error("Set as default error:",M),r({title:"Error",description:M.data?.message||M.message||"An error occurred while setting this opportunity as default.",variant:"destructive"})}).finally(()=>{p(O,"isSettingDefault",!1)})},[s,N,r,p,f?.IsReseller]),[y]=_.usePostV4ResellerByRouteResellerIdOpportunityAndManufacturerIdBidNumberEmailMutation(),j=o.useCallback(D=>{if(f?.IsReseller){if(!D.BidNumber){r({title:"Error",description:"Bid Number is missing, cannot prepare report.",variant:"destructive"});return}m(D),d(""),u(!0)}},[r,f?.IsReseller]),b=o.useCallback(async()=>{if(!f?.IsReseller)return;if(!c||!c.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 D=c.BidNumber;p(D,"isSendingReport",!0),y({routeResellerId:s,manufacturerId:c.ManufacturerId??"",bidNumber:D,emailAddress:x}).unwrap().then(()=>{r({title:"Success",description:`A report for "${c.OpportunityName||c.Opportunity||D}" was successfully sent to ${x}.`,variant:"success"}),u(!1)}).catch(O=>{console.error("Send report by email error:",O),r({title:"Error",description:O.data?.message||O.message||"An error occurred while sending the report by email.",variant:"destructive"})}).finally(()=>{p(D,"isSendingReport",!1),l||(m(null),d(""))})},[c,x,s,y,r,p,u]),C=o.useMemo(()=>[{accessorKey:"ManufacturerId",header:"Manuf.",cell:({row:D})=>e.jsx("div",{className:"w-20 h-8",children:e.jsx(hs,{id:D.original.ManufacturerId,width:80,height:32})}),enableSorting:!0,enableFiltering:!0},{id:"opportunityDisplay",accessorFn:D=>D.OpportunityName||D.Opportunity,header:"Opportunity",cell:({getValue:D})=>e.jsx("div",{className:"min-w-[150px]",children:D()??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"BidNumber",header:"Bid Number",cell:({row:D})=>D.original.BidNumber??"N/A",enableSorting:!0,enableFiltering:!0},{id:"statusInfo",header:"Status",cell:({row:D})=>{const O=D.original,M=O.Active===!0,I=zd(O.EndDate),F=M?"success":"secondary",Q=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(he,{variant:F,className:"font-medium",children:M?"Active":"Inactive"}),O.EndDate&&e.jsx(he,{variant:Q,className:"font-medium",children:I.text}),e.jsx(ye,{delayDuration:100,children:e.jsxs(ge,{children:[e.jsx(je,{asChild:!0,children:e.jsx(E,{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(fe,{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:"})," ",ba(O.StartDate)]}),e.jsxs("p",{children:[e.jsx("strong",{children:"End:"})," ",ba(O.EndDate)]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Updated:"})," ",ba(O.LastUpdate)]})]})})]})})]})},enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:D})=>{const O=D.original;if(!O.BidNumber)return e.jsx("span",{className:"text-xs text-muted-foreground",children:"Actions unavailable"});const M=O.BidNumber,I=n[M]?.isSettingDefault,F=c?.BidNumber===M&&n[M]?.isSendingReport,Q=I||F,$=O.CanBeSetAsDefault===!0,z=f?.IsManufacturer?`/${s}/Opportunity/${O.BidNumber}`:`/${s}/Opportunity/${O.ManufacturerId}/${O.BidNumber}`;return e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(Ce.Link,{to:z,children:e.jsxs(E,{variant:"outline",size:"sm",className:"flex items-center",children:[e.jsx(g.Star,{className:"mr-2 h-4 w-4"})," View"]})}),f?.IsReseller&&e.jsxs(e.Fragment,{children:[e.jsxs(E,{variant:"outline",size:"sm",onClick:()=>w(O),disabled:Q||!$,title:$?"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(E,{variant:"outline",size:"sm",onClick:()=>j(O),disabled:Q,title:"Send report by email",className:"flex items-center",children:[F?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,c,f?.IsReseller,s]),S=o.useMemo(()=>{const D={};if(t){const O=Array.from(new Set(t.map(I=>I.ManufacturerId).filter(I=>I!=null)));D.ManufacturerId=O;const M=Array.from(new Set(t.map(I=>I.OpportunityName||I.Opportunity).filter(I=>I!=null)));D.opportunityDisplay=M}return D},[t]),A=t||[],k=c?.BidNumber?n[c.BidNumber]?.isSendingReport:!1;return a?e.jsxs(q,{className:"w-full",children:[e.jsxs(J,{children:[" ",e.jsx(h,{className:"h-7 w-48"})," "]}),e.jsxs(W,{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(q,{className:"w-full",children:[e.jsxs(J,{children:[" ",e.jsx(ce,{className:"text-1xl font-bold",children:"Opportunities"})," "]}),e.jsx(W,{children:e.jsx(Ms,{columns:C,data:A,uniqueValues:S})})]}),e.jsx(De,{open:l,onOpenChange:D=>{u(D),D||(m(null),d(""))},children:e.jsxs(Me,{className:"@sm:max-w-[425px]",children:[e.jsxs($e,{children:[e.jsx(_e,{children:"Send Opportunity Report"}),e.jsxs(ze,{children:["Enter the email address to send the report for opportunity: ",e.jsx("br",{}),e.jsx("span",{className:"font-semibold",children:c?.OpportunityName||c?.Opportunity||"N/A"}),c?.BidNumber&&e.jsxs("span",{className:"block text-sm text-muted-foreground",children:["Bid Number: ",c.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(Z,{htmlFor:"email",className:"text-right",children:"Email"}),e.jsx(ne,{id:"email",type:"email",value:x,onChange:D=>d(D.target.value),placeholder:"recipient@example.com",className:"col-span-3",disabled:k})]})}),e.jsxs(qe,{children:[e.jsx(E,{variant:"outline",onClick:()=>u(!1),disabled:k,children:"Cancel"}),e.jsxs(E,{type:"submit",onClick:b,disabled:k,children:[k&&e.jsx(g.Loader2,{className:"mr-2 h-4 w-4 animate-spin"})," Send Report"]})]})]})})]})}function Ud(s){const t=s instanceof Date?new Date(s.getTime()):new Date(s);return Number.isNaN(t.getTime())?null:t}function qd(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=Ud(a.timestamp);if(!r)continue;const n=new Date(r.getFullYear(),r.getMonth(),r.getDate()),i=qd(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 Qd=new Intl.DateTimeFormat(void 0,{weekday:"long",month:"short",day:"numeric",year:"numeric"}),Hd=new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit",second:"2-digit"});function Gd({entries:s,emptyStateText:t="No system log entries available.",className:a,formatDayLabel:r=i=>Qd.format(i),formatTimeLabel:n=i=>Hd.format(i)}){const i=P.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((u,x)=>{const d=u.entry.id??`${l.dayKey}-${u.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(u.timestamp)}),e.jsx("pre",{className:"font-mono text-xs text-foreground whitespace-pre-wrap break-words",children:u.entry.payload})]},d)})})]},l.dayKey))})}function Wd(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 ya(s,t,a){a/=100;const r=t*Math.min(a,1-a)/100,n=i=>{const l=(i+s/30)%12,u=a-r*Math.max(Math.min(l-3,9-l,1),-1);return Math.round(255*u).toString(16).padStart(2,"0")};return`#${n(0)}${n(8)}${n(4)}`}const jr=P.forwardRef(({data:s,options:t,height:a="500px",className:r,loading:n,disableClick:i=!0,...l},u)=>{const x=P.useRef(null),[d,c]=P.useState(null);P.useEffect(()=>{if(!x.current)return;const p=x.current,N=()=>{const b=getComputedStyle(p).getPropertyValue("--primary").trim();if(b){const C=Wd(b);if(C){const{h:S,s:A,l:k}=C;c({minColor:ya(S,A,Math.min(100,k+50)),midColor:ya(S,A,Math.min(100,k+35)),maxColor:ya(S,A,Math.min(100,k+20))})}return!0}return!1};if(N())return;let w=0;const y=20,j=setInterval(()=>{(N()||w>=y)&&clearInterval(j),w++},100);return()=>{j&&clearInterval(j)}},[]);const m=P.useMemo(()=>{const p={headerHeight:0,fontSize:14,showScale:!1,isHtml:!0,backgroundColor:"transparent",generateTooltip:(N,w)=>{const y=s[N+1]?.[0];if(!y)return"";const j=oe(w);return`<div class="p-2 bg-background text-foreground border rounded-md shadow-lg">
130
+ <strong>${y}</strong><br>Value: ${j}
131
+ </div>`}};return d&&(!t||!t.colorAxis)&&(p.minColor=d.minColor,p.midColor=d.midColor,p.maxColor=d.maxColor),{...p,...t}},[s,t,d]),f=P.useMemo(()=>i?[{eventName:"select",callback:({chartWrapper:N})=>{N.getChart().setSelection(null)}}]:void 0,[i]);return P.useImperativeHandle(u,()=>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(vl.Chart,{chartType:"TreeMap",width:"100%",height:"100%",data:s,options:m,chartEvents:f,loader:e.jsx(h,{className:"h-full w-full"})})})});jr.displayName="Treemap";const Kd=({data:s,topPercent:t=80,title:a,loading:r,...n})=>{const i=P.useMemo(()=>{if(!s||s.length===0)return[["ID","Parent","Value"],["Root",null,0]];const u=[...s].sort((N,w)=>w.value-N.value),d=u.reduce((N,w)=>N+w.value,0)*(t/100),c=[["ID","Parent","Value"],["Root",null,0]],m=[],f=[];let p=0;for(const N of u)p<d?(m.push(N),p+=N.value):f.push(N);if(m.forEach(N=>{c.push([N.name,"Root",N.value])}),f.length>0){const N=`More... (${f.length} items)`;c.push([N,"Root",0]),f.forEach(w=>{c.push([w.name,N,w.value])})}return c},[s,t]),l=P.useMemo(()=>({title:a,maxDepth:1,backgroundColor:"transparent"}),[a]);return e.jsx(jr,{data:i,options:l,className:v("h-full",n.className),loading:r,disableClick:!1,...n})},Na=["central-theme","partner-theme","reseller-theme","manufacturer-theme","shopify-theme"],Yd={central:"central-theme",partner:"partner-theme",reseller:"reseller-theme",manufacturer:"manufacturer-theme",shopify:"shopify-theme"},Jd=10;function Ti(s,t,a=0){const r=s.trim();return!r||a>Jd||!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 Zd(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 va(s){const t=getComputedStyle(s),a=t.getPropertyValue("--primary").trim();if(!a)return null;const r=Ti(a,t)||a;return Zd(r)}function Xd(){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 eu(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 su({theme:s,applyTo:t="documentElement",children:a}){const r=o.useMemo(()=>eu(s),[s]),n=o.useRef(null),i=o.useRef(null),l=o.useRef(!1),u=o.useRef(null),x=o.useRef(!1);return o.useEffect(()=>{if(typeof document>"u")return;const d=t==="body"?document.body??document.documentElement:document.documentElement??document.body;if(d){n.current||(n.current=Na.filter(c=>d.classList.contains(c)));for(const c of Na)d.classList.remove(c);return r!=="default"&&d.classList.add(Yd[r]),()=>{for(const c of Na)d.classList.remove(c);for(const c of n.current??[])d.classList.add(c)}}},[t,r]),o.useEffect(()=>{if(typeof document>"u")return;const d=t==="body"?document.body??document.documentElement:document.documentElement??document.body;if(!d)return;const c=Xd();if(!c)return;const{metaTag:m,existedBeforeEnsure:f}=c;i.current?i.current!==m&&(i.current=m):(i.current=m,l.current=!f,x.current=m.hasAttribute("content"),u.current=m.getAttribute("content"));const p=va(d)??va(document.documentElement)??va(document.body??document.documentElement);p&&m.setAttribute("content",p)},[t,r]),o.useEffect(()=>()=>{if(typeof document>"u")return;const d=i.current;if(!(!d||!d.isConnected)){if(l.current){d.remove();return}x.current?d.setAttribute("content",u.current??""):d.removeAttribute("content")}},[]),a}exports.AIChatLayout=Jt;exports.Accordion=Bd;exports.AccordionContent=Ii;exports.AccordionItem=Pi;exports.AccordionTrigger=Ai;exports.ActiveOrdersCard=oi;exports.Alert=vs;exports.AlertDescription=Ss;exports.AlertDialog=hr;exports.AlertDialogAction=aa;exports.AlertDialogCancel=ra;exports.AlertDialogContent=Zt;exports.AlertDialogDescription=ta;exports.AlertDialogFooter=ea;exports.AlertDialogHeader=Xt;exports.AlertDialogTitle=sa;exports.AlertDialogTrigger=fr;exports.AlertTitle=ws;exports.ApiImage=xi;exports.AreaChart=zn;exports.AssistantChat=_d;exports.Avatar=wt;exports.AvatarFallback=qn;exports.AvatarFooter=Bl;exports.AvatarImage=Un;exports.Badge=he;exports.Button=E;exports.Calendar=Di;exports.Card=q;exports.CardContent=W;exports.CardDescription=it;exports.CardFooter=fs;exports.CardHeader=J;exports.CardTitle=ce;exports.ChatLayout=Yo;exports.ChatProvider=Yl;exports.Checkbox=Ds;exports.CheckboxCardList=ci;exports.Command=Yt;exports.CommandDialog=Rc;exports.CommandEmpty=dr;exports.CommandGroup=ur;exports.CommandInput=or;exports.CommandItem=Qt;exports.CommandList=cr;exports.CommandSeparator=di;exports.CommandShortcut=ui;exports.CountryFlag=mi;exports.DataRefreshAssistantCluster=md;exports.DataTable=Ms;exports.DatePicker=Bt;exports.Dialog=De;exports.DialogClose=Ra;exports.DialogContent=Me;exports.DialogDescription=ze;exports.DialogFooter=qe;exports.DialogHeader=$e;exports.DialogOverlay=Ea;exports.DialogPortal=sn;exports.DialogTitle=_e;exports.DialogTrigger=Zs;exports.DropdownMenu=tn;exports.DropdownMenuCheckboxItem=ln;exports.DropdownMenuContent=Oa;exports.DropdownMenuGroup=Pl;exports.DropdownMenuItem=pt;exports.DropdownMenuLabel=cn;exports.DropdownMenuPortal=Al;exports.DropdownMenuRadioGroup=Dl;exports.DropdownMenuRadioItem=on;exports.DropdownMenuSeparator=dn;exports.DropdownMenuShortcut=un;exports.DropdownMenuSub=Il;exports.DropdownMenuSubContent=nn;exports.DropdownMenuSubTrigger=rn;exports.DropdownMenuTrigger=an;exports.ExploreManufacturers=eo;exports.ExternalProductCard=Vd;exports.GeneralDocumentCard=Pc;exports.Input=ne;exports.InputOTP=Sl;exports.InputOTPGroup=Cl;exports.InputOTPSeparator=Rl;exports.InputOTPSlot=kl;exports.Label=Z;exports.Layout=fi;exports.ManufacturerCard=et;exports.ManufacturerGetStartedButton=mr;exports.ManufacturerOverviewPage=Jn;exports.ManufacturerReorderingCard=pi;exports.MultiSelect=gi;exports.Navbar=hi;exports.OpportunitiesTable=gr;exports.OrdersCard=yt;exports.PARTNER_PAGE_SHELL_CONTENT_CLASS_NAME=Ci;exports.PARTNER_PAGE_SHELL_STACK_CLASS_NAME=Si;exports.PageHeader=gd;exports.PartnerActions=mn;exports.PartnerCard=ai;exports.PartnerPageShell=jd;exports.PartnerRelationshipPage=hc;exports.Popover=Ct;exports.PopoverAnchor=Qc;exports.PopoverContent=ot;exports.PopoverTrigger=kt;exports.PortalThemeProvider=su;exports.Preloader=Do;exports.ProductCard=Ht;exports.ProductImage=xr;exports.ProductInventoryGrid=La;exports.ProductOverviewPage=Id;exports.Progress=lt;exports.RadioGroup=Ws;exports.RadioGroupItem=ps;exports.RandmarApiConfigProvider=to;exports.RefreshCluster=Ni;exports.ResellerBillingOverviewCard=ed;exports.ResellerCard=ri;exports.ResellerOverview=ti;exports.ResellerQualificationsCard=bi;exports.ReturnsTable=pr;exports.RichTextEditor=vd;exports.RmBodyZone=bd;exports.RmPageHeader=wi;exports.SalesChart=zs;exports.SalesOverviewCard=rd;exports.ScrollArea=gs;exports.ScrollBar=Wt;exports.SearchNoResultsCard=ki;exports.SearchPage=Fd;exports.SearchPageGrid=Md;exports.SearchResultsHeader=Od;exports.SearchResultsSkeleton=Ri;exports.Select=As;exports.SelectContent=Ns;exports.SelectGroup=uc;exports.SelectItem=as;exports.SelectLabel=Xn;exports.SelectScrollDownButton=nr;exports.SelectScrollUpButton=rr;exports.SelectTrigger=ys;exports.SelectValue=Is;exports.Separator=vt;exports.Sheet=xn;exports.SheetClose=Ll;exports.SheetContent=Ba;exports.SheetDescription=jn;exports.SheetFooter=pn;exports.SheetHeader=fn;exports.SheetOverlay=Fa;exports.SheetPortal=hn;exports.SheetTitle=gn;exports.SheetTrigger=Ol;exports.Sidebar=_a;exports.SidebarContent=qa;exports.SidebarFooter=Ua;exports.SidebarGroup=Cn;exports.SidebarGroupAction=Rn;exports.SidebarGroupContent=Pn;exports.SidebarGroupLabel=kn;exports.SidebarHeader=za;exports.SidebarInput=wn;exports.SidebarInset=vn;exports.SidebarMenu=Qa;exports.SidebarMenuAction=An;exports.SidebarMenuBadge=In;exports.SidebarMenuButton=Ga;exports.SidebarMenuItem=Ha;exports.SidebarMenuSkeleton=Dn;exports.SidebarMenuSub=Mn;exports.SidebarMenuSubButton=En;exports.SidebarMenuSubItem=Tn;exports.SidebarProvider=$a;exports.SidebarRail=Nn;exports.SidebarSeparator=Sn;exports.SidebarTrigger=Va;exports.Skeleton=h;exports.SummaryOverviewCard=ld;exports.Switch=nt;exports.SystemLogFeed=Gd;exports.Table=Vt;exports.TableBody=Ut;exports.TableCaption=ii;exports.TableCell=jt;exports.TableFooter=ni;exports.TableHead=qt;exports.TableHeader=zt;exports.TableRow=Ls;exports.Tabs=tr;exports.TabsContent=ts;exports.TabsList=Kt;exports.TabsTrigger=Je;exports.Textarea=bs;exports.Toast=Ka;exports.ToastAction=Ya;exports.ToastClose=Ja;exports.ToastDescription=Xa;exports.ToastProvider=On;exports.ToastTitle=Za;exports.ToastViewport=Wa;exports.Toaster=Fn;exports.Tooltip=ge;exports.TooltipContent=fe;exports.TooltipProvider=ye;exports.TooltipTrigger=je;exports.TopPercentTreemap=Kd;exports.Topbar=lr;exports.Treemap=jr;exports.badgeVariants=Zn;exports.buildApiUrl=js;exports.buttonVariants=_s;exports.formatMoney=oe;exports.formatNumber=ds;exports.formatYYYYMMDDIntToDateString=Js;exports.groupSystemLogEntries=Mi;exports.toast=Ln;exports.useApiOrigin=St;exports.useChat=Xs;exports.useIsMobile=bn;exports.useOptionalChat=Bn;exports.useRandmarApiConfig=sr;exports.useSidebar=rt;exports.useToast=Pe;