randmarcomps 1.393.0 → 1.394.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.
@@ -32,6 +32,7 @@ import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
32
32
  import * as React_2 from 'react';
33
33
  import { ReactNode } from 'react';
34
34
  import { RefAttributes } from 'react';
35
+ import { Requisition } from 'randmar-api-client';
35
36
  import { Reseller } from 'randmar-api-client';
36
37
  import { Return } from 'randmar-api-client';
37
38
  import { SalesData } from 'randmar-api-client';
@@ -340,6 +341,15 @@ export declare interface CountryFlagProps {
340
341
  className?: string;
341
342
  }
342
343
 
344
+ declare type CustomProduct = Product & {
345
+ Requisitions?: CustomRequisition[] | null;
346
+ };
347
+
348
+ declare type CustomRequisition = Requisition & {
349
+ QuantityOutstanding?: number;
350
+ QuantityReceived?: number;
351
+ };
352
+
343
353
  /**
344
354
  * Defines the structure for a single data point in the chart.
345
355
  * The first key is assumed to be the x-axis label.
@@ -548,7 +558,7 @@ export declare interface InputProps extends Omit<React_2.ComponentProps<"input">
548
558
  declare interface IProps {
549
559
  applicationId: string;
550
560
  sku?: string;
551
- product?: Product;
561
+ product?: CustomProduct;
552
562
  productDefaultOpportunityNumber?: string;
553
563
  productOnAddToCart?: (state: {
554
564
  quantity: number;
@@ -93750,6 +93750,20 @@ function RequisitionsTable({
93750
93750
  enableSorting: !0,
93751
93751
  enableFiltering: !0
93752
93752
  },
93753
+ {
93754
+ accessorKey: "QuantityOutstanding",
93755
+ header: "Quantity Outstanding",
93756
+ cell: ({ row: S }) => S.original.QuantityOutstanding ?? "—",
93757
+ enableSorting: !0,
93758
+ enableFiltering: !0
93759
+ },
93760
+ {
93761
+ accessorKey: "QuantityReceived",
93762
+ header: "Quantity Received",
93763
+ cell: ({ row: S }) => S.original.QuantityReceived ?? "—",
93764
+ enableSorting: !0,
93765
+ enableFiltering: !0
93766
+ },
93753
93767
  {
93754
93768
  accessorKey: "SubTotal",
93755
93769
  header: "Sub Total",
@@ -93840,6 +93854,14 @@ function RequisitionsTable({
93840
93854
  new Set(
93841
93855
  o.map((_) => _.QuantityOrdered).filter((_) => _ != null).map(String)
93842
93856
  )
93857
+ ), S.QuantityOutstanding = Array.from(
93858
+ new Set(
93859
+ o.map((_) => _.QuantityOutstanding).filter((_) => _ != null).map(String)
93860
+ )
93861
+ ), S.QuantityReceived = Array.from(
93862
+ new Set(
93863
+ o.map((_) => _.QuantityReceived).filter((_) => _ != null).map(String)
93864
+ )
93843
93865
  ), S.Location = Array.from(
93844
93866
  new Set(o.map((_) => _.Location).filter((_) => _ != null))
93845
93867
  ), S.RequestedBy = Array.from(
@@ -94473,13 +94495,13 @@ function OpportunitiesTable({
94473
94495
  id: "actions",
94474
94496
  header: "Actions",
94475
94497
  cell: ({ row: ne }) => {
94476
- var Ve, Fe;
94498
+ var Fe, je;
94477
94499
  const ae = ne.original;
94478
94500
  if (!ae.BidNumber)
94479
94501
  return /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "Actions unavailable" });
94480
- const $e = ae.BidNumber, Ne = (Ve = l[$e]) == null ? void 0 : Ve.isSettingDefault, oe = (_ == null ? void 0 : _.BidNumber) === $e && ((Fe = l[$e]) == null ? void 0 : Fe.isSendingReport), Ae = Ne || oe, ge = ae.CanBeSetAsDefault === !0;
94502
+ const $e = ae.BidNumber, Ne = (Fe = l[$e]) == null ? void 0 : Fe.isSettingDefault, oe = (_ == null ? void 0 : _.BidNumber) === $e && ((je = l[$e]) == null ? void 0 : je.isSendingReport), Ae = Ne || oe, ge = ae.CanBeSetAsDefault === !0, Ve = E != null && E.IsManufacturer ? `/${t}/Opportunity/${ae.BidNumber}` : `/${t}/Opportunity/${ae.ManufacturerId}/${ae.BidNumber}`;
94481
94503
  return /* @__PURE__ */ jsxs("div", { className: "flex space-x-2", children: [
94482
- /* @__PURE__ */ jsx(Link, { to: `/${t}/Opportunity/${ae.ManufacturerId}/${ae.BidNumber}`, children: /* @__PURE__ */ jsxs(Button$1, { variant: "outline", size: "sm", className: "flex items-center", children: [
94504
+ /* @__PURE__ */ jsx(Link, { to: Ve, children: /* @__PURE__ */ jsxs(Button$1, { variant: "outline", size: "sm", className: "flex items-center", children: [
94483
94505
  /* @__PURE__ */ jsx(Star, { className: "mr-2 h-4 w-4" }),
94484
94506
  " View"
94485
94507
  ] }) }),
@@ -1425,7 +1425,7 @@ img.ProseMirror-separator {
1425
1425
  .ProseMirror p {
1426
1426
  margin-bottom: 0.5em;
1427
1427
  }
1428
- `;function RichTextEditor({id:t,name:e,value:n,onChange:o,placeholder:l,className:d,...f}){const[g,b]=React.useState(!1),S=React.useRef(null),_=React.useRef(null),R=useEditor({extensions:[StarterKit,Underline],content:n,editorProps:{attributes:{class:"prose prose-sm sm:prose dark:prose-invert focus:outline-none",id:t??"",name:e??""}},onUpdate:({editor:j})=>{const q=j.getHTML();o({target:{id:t,name:e,value:q}})}});React.useEffect(()=>{R&&n!==R.getHTML()&&R.commands.setContent(n)},[n,R]);const C=React.useCallback(j=>{if(R)if(R.chain().focus(),j==="paragraph")R.chain().setParagraph().run();else{const q=Number.parseInt(j.slice(1));R.chain().setHeading({level:q}).run()}},[R]),E=React.useCallback(j=>{if(R)switch(R.chain().focus(),j){case"bold":R.chain().toggleBold().run();break;case"italic":R.chain().toggleItalic().run();break;case"underline":R.chain().toggleUnderline().run();break;case"strike":R.chain().toggleStrike().run();break;case"bulletList":R.chain().toggleBulletList().run();break;case"orderedList":R.chain().toggleOrderedList().run();break}},[R]),A=React.useCallback(()=>{b(j=>!j)},[]),I=React.useCallback(j=>{const q=j.target.value;R&&R.commands.setContent(q),o({target:{id:t,name:e,value:q}})},[o,R,t,e]),M=React.useCallback(()=>{!g&&R&&R.commands.focus()},[g,R]);return R?jsxRuntime.jsxs("div",{ref:_,className:cn("border border-input rounded-md overflow-hidden focus-within:outline-hidden focus-within:ring-1 focus-within:ring-ring",d),onClick:M,...f,children:[jsxRuntime.jsx("style",{children:editorStyles}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center p-2 border-b border-input gap-2 bg-background",children:[jsxRuntime.jsxs(Select$1,{onValueChange:C,disabled:g,children:[jsxRuntime.jsx(SelectTrigger,{className:"w-[160px]",children:jsxRuntime.jsx(SelectValue,{placeholder:"Format"})}),jsxRuntime.jsx(SelectContent,{children:formatOptions.map(j=>jsxRuntime.jsx(SelectItem,{value:j.value,children:j.label},j.value))})]}),["bold","italic","underline","strike","bulletList","orderedList"].map(j=>jsxRuntime.jsxs(Button$1,{type:"button",variant:"ghost",size:"sm",onClick:()=>E(j),className:R.isActive(j)?"bg-muted":"",disabled:g,children:[j==="bold"&&jsxRuntime.jsx(Bold$1,{className:"h-4 w-4"}),j==="italic"&&jsxRuntime.jsx(Italic$1,{className:"h-4 w-4"}),j==="underline"&&jsxRuntime.jsx(Underline$1,{className:"h-4 w-4"}),j==="strike"&&jsxRuntime.jsx(Strikethrough,{className:"h-4 w-4"}),j==="bulletList"&&jsxRuntime.jsx(List$1,{className:"h-4 w-4"}),j==="orderedList"&&jsxRuntime.jsx(ListOrdered,{className:"h-4 w-4"})]},j)),jsxRuntime.jsx(Button$1,{type:"button",variant:"ghost",size:"sm",onClick:A,className:g?"bg-muted":"",children:jsxRuntime.jsx(Code$1,{className:"h-4 w-4"})})]}),jsxRuntime.jsx("div",{className:"p-3",children:g?jsxRuntime.jsx(Textarea,{ref:S,id:t,name:e,value:R.getHTML(),onChange:I,className:cn("min-h-[150px] font-mono text-sm resize-none border-0 focus-visible:ring-0 focus-visible:ring-offset-0",d),placeholder:l}):jsxRuntime.jsx(EditorContent,{editor:R})})]}):null}function ReceiptsTable({applicationId:t,receipts:e=null,loading:n=!1}){const o=React.useMemo(()=>[{accessorKey:"Location",header:"Location",cell:({row:f})=>f.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptDate",header:"Date",cell:({row:f})=>formatYYYYMMDDIntToDateString(f.original.ReceiptDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptNumber",header:"Number",cell:({row:f})=>f.original.ReceiptNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${f.original.ReceiptNumber}`,className:"font-medium text-primary hover:underline",children:f.original.ReceiptNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for Receipt ",f.original.ReceiptNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:f})=>f.original.Quantity??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:f})=>f.original.UnitPrice?formatMoney(f.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0}],[]),l=React.useMemo(()=>{const f={};if(e){const g=Array.from(new Set(e.map(S=>S.Location).filter(S=>S!=null)));f.Location=g;const b=Array.from(new Set(e.map(S=>formatYYYYMMDDIntToDateString(S.ReceiptDate)).filter(S=>S!=="—"&&S!=="Invalid Date"))).sort((S,_)=>new Date(_).getTime()-new Date(S).getTime());f.ReceiptDate=b}return f},[e]),d=e||[];return jsxRuntime.jsx(DataTable,{columns:o,data:d,uniqueValues:l,loading:n,tableClass:"bg-card text-card-foreground",initialSort:[{id:"ReceiptDate",desc:!0}]})}const formatDate$1=t=>{if(!t)return"N/A";try{const e=new Date(t);return isNaN(e.getTime())?"Invalid Date":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}},getStatusVariant=t=>{const e=(t==null?void 0:t.toLowerCase())||"";return e.includes("accepted")?"success":e.includes("error")||e.includes("rejected")?"destructive":"neutral"};function ReturnsTable({applicationId:t,returns:e=null,loading:n=!1}){const o=React.useMemo(()=>[{accessorKey:"ReturnNumber1",header:"RMA Number",cell:({row:f})=>{const g=f.original.ReturnNumber1||f.original.ReturnNumber;return g?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Return/${g}`,className:"font-medium text-primary hover:underline",children:g})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for return ",g]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestDate",header:"Request Date",cell:({row:f})=>formatDate$1(f.original.RequestDate),enableSorting:!0},{accessorKey:"InvoiceNumber",header:"Invoice Number",cell:({row:f})=>{const g=f.original.InvoiceNumber;return g?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${g}`,className:"text-blue-600 hover:underline dark:text-blue-400",children:g})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for invoice ",g]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:f})=>f.original.Quantity??"0",enableSorting:!0},{accessorKey:"ReasonForReturn",header:"Return Reason",cell:({row:f})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:f.original.ReasonForReturn??"—"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"Status",header:"Status",cell:({row:f})=>{const g=f.original.Status,b=getStatusVariant(g);let S="border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400";return b==="success"?S="border-green-500 bg-green-100 text-green-700 dark:border-green-600 dark:bg-green-900/50 dark:text-green-400":b==="destructive"&&(S="border-red-500 bg-red-100 text-red-700 dark:border-red-600 dark:bg-red-900/50 dark:text-red-400"),g?jsxRuntime.jsx(Badge,{variant:"outline",className:`${S} font-medium`,children:g}):"—"},enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseLocation",header:"Warehouse",cell:({row:f})=>f.original.WarehouseLocation??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"LastUpdatedDate",header:"Last Update",cell:({row:f})=>formatDate$1(f.original.LastUpdatedDate)!=="N/A"?formatDate$1(f.original.LastUpdatedDate):"—",enableSorting:!0}],[t]),l=React.useMemo(()=>{const f={};if(e){const g=Array.from(new Set(e.map(_=>_.Status).filter(Boolean)));f.Status=g;const b=Array.from(new Set(e.map(_=>_.ReasonForReturn).filter(Boolean)));f.ReasonForReturn=b;const S=Array.from(new Set(e.map(_=>_.WarehouseLocation).filter(Boolean)));f.WarehouseLocation=S}return f},[e]),d=React.useMemo(()=>e?[...e].sort((g,b)=>(b.ReturnNumber1||b.ReturnNumber||"").localeCompare(g.ReturnNumber1||g.ReturnNumber||"")):[],[e]);return n?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(Skeleton,{className:"h-7 w-48"})}),jsxRuntime.jsxs(CardContent,{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-48 w-full rounded-md border"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between pt-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-[130px]"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-20"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})]})]})]})]}):jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Returns"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:o,data:d,uniqueValues:l})})]})}function PurchaseOrdersTable({applicationId:t,purchaseOrders:e=null,loading:n=!1}){const[o,l]=React.useState([]),[d]=usePostV4ManufacturerByRouteManufacturerIdPurchaseOrderAndPurchaseOrderNumberEditItemRandmarSkuMutation(),{toast:f}=useToast();React.useEffect(()=>{l(e||[])},[e]);const g=React.useMemo(()=>[{accessorKey:"PurchaseOrderNumber",header:"Number",cell:({row:S})=>S.original.PurchaseOrderNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${S.original.PurchaseOrderNumber}`,className:"font-medium text-primary hover:underline",children:S.original.PurchaseOrderNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for Purchase Order ",S.original.PurchaseOrderNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PurchaseOrderDate",header:"Date",cell:({row:S})=>formatYYYYMMDDIntToDateString(S.original.PurchaseOrderDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:S})=>S.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PartNumber",header:"Part Number",cell:({row:S})=>S.original.MPN?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Product/${S.original.RandmarSKU}`,className:"font-medium text-primary hover:underline",children:S.original.MPN})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for Product ",S.original.RandmarSKU]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:S})=>S.original.QuantityOrdered??0,enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:S})=>S.original.UnitPrice?formatMoney(S.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0},{id:"actions",header:()=>jsxRuntime.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:_}){const[R,C]=React.useState(!1),E=_.original,A=()=>{C(!0),d({routeManufacturerId:t,purchaseOrderNumber:E.PurchaseOrderNumber??"",randmarSku:E.RandmarSKU??"",quantity:0}).then(()=>{l(I=>I.filter(M=>!(M.PurchaseOrderNumber===M.PurchaseOrderNumber&&M.MPN===M.MPN))),f({variant:"success",title:"Success",description:`Part ${E.MPN} has been successfully deleted from Purchase Order ${E.PurchaseOrderNumber}.`})}).catch(I=>{console.error(I),C(!0),f({variant:"destructive",title:"Error",description:"Something went wrong!"})})};return jsxRuntime.jsx("div",{className:"text-right",children:jsxRuntime.jsxs(AlertDialog,{children:[jsxRuntime.jsx(AlertDialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{variant:"red",size:"sm",disabled:R,children:R?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting"]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})}),jsxRuntime.jsxs(AlertDialogContent,{children:[jsxRuntime.jsxs(AlertDialogHeader,{children:[jsxRuntime.jsx(AlertDialogTitle,{children:"Confirmation"}),jsxRuntime.jsxs(AlertDialogDescription,{children:["Are you sure you want to delete part ",jsxRuntime.jsx("strong",{children:E.MPN})," from Purchase Order ",jsxRuntime.jsx("strong",{children:E.PurchaseOrderNumber}),"?."]})]}),jsxRuntime.jsxs(AlertDialogFooter,{children:[jsxRuntime.jsx(AlertDialogCancel,{disabled:R,children:"Cancel"}),jsxRuntime.jsxs(AlertDialogAction,{onClick:A,disabled:R,children:[R&&jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}],[t]),b=React.useMemo(()=>{const S={};return o&&(S.PurchaseOrderNumber=Array.from(new Set(o.map(_=>_.PurchaseOrderNumber).filter(_=>_!=null))),S.PurchaseOrderDate=Array.from(new Set(o.map(_=>_.PurchaseOrderDate).filter(_=>_!=null).map(String))),S.Location=Array.from(new Set(o.map(_=>_.Location).filter(_=>_!=null))),S.PartNumber=Array.from(new Set(o.map(_=>_.MPN).filter(_=>_!=null))),S.QuantityOrdered=Array.from(new Set(o.map(_=>_.QuantityOrdered).filter(_=>_!=null).map(String))),S.UnitPrice=Array.from(new Set(o.map(_=>_.UnitPrice).filter(_=>_!=null).map(String)))),S},[o]);return jsxRuntime.jsx(DataTable,{columns:g,data:o,uniqueValues:b,loading:n,tableClass:"bg-card text-card-foreground"})}function RequisitionsTable({applicationId:t,requisitions:e=null,loading:n=!1}){const[o,l]=React.useState([]),[d]=useDeleteV4ManufacturerByRouteManufacturerIdRequisitionAndRequisitionNumberMutation(),{toast:f}=useToast();React.useEffect(()=>{l(e||[])},[e]);const g=React.useMemo(()=>[{accessorKey:"RequisitionNumber",header:"Number",cell:({row:S})=>S.original.RequisitionNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${S.original.RequisitionNumber}`,className:"font-medium text-primary hover:underline",children:S.original.RequisitionNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for Draft Purchase ",S.original.RequisitionNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequisitionDate",header:"Date",cell:({row:S})=>formatYYYYMMDDIntToDateString(S.original.RequisitionDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:S})=>S.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:S})=>S.original.QuantityOrdered??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"SubTotal",header:"Sub Total",cell:({row:S})=>S.original.SubTotal?formatMoney(S.original.SubTotal):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestedBy",header:"Requestor",cell:({row:S})=>S.original.RequestedBy??"—",enableSorting:!0,enableFiltering:!0},{id:"actions",header:()=>jsxRuntime.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:_}){const[R,C]=React.useState(!1),E=_.original,A=()=>{C(!0),d({routeManufacturerId:t,requisitionNumber:E.RequisitionNumber??""}).then(()=>{l(I=>I.filter(M=>M.RequisitionNumber!==M.RequisitionNumber)),f({variant:"success",title:"Success",description:`Draft Purchase ${E.RequisitionNumber} has been successfully cancelled.`})}).catch(I=>{console.error(I),C(!0),f({variant:"destructive",title:"Error",description:"Something went wrong!"})})};return jsxRuntime.jsx("div",{className:"text-right",children:jsxRuntime.jsxs(AlertDialog,{children:[jsxRuntime.jsx(AlertDialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{variant:"red",size:"sm",disabled:R,children:R?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancelling"]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Trash2,{className:"mr-2 h-4 w-4"}),"Cancel"]})})}),jsxRuntime.jsxs(AlertDialogContent,{children:[jsxRuntime.jsxs(AlertDialogHeader,{children:[jsxRuntime.jsx(AlertDialogTitle,{children:"Confirmation"}),jsxRuntime.jsxs(AlertDialogDescription,{children:["Are you sure you want to cancel Draft Purchase ",jsxRuntime.jsx("strong",{children:E.RequisitionNumber}),"?."]})]}),jsxRuntime.jsxs(AlertDialogFooter,{children:[jsxRuntime.jsx(AlertDialogCancel,{disabled:R,children:"Cancel"}),jsxRuntime.jsxs(AlertDialogAction,{onClick:A,disabled:R,children:[R&&jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}],[t]),b=React.useMemo(()=>{const S={};return o&&(S.RequisitionNumber=Array.from(new Set(o.map(_=>_.RequisitionNumber).filter(_=>_!=null))),S.RequisitionDate=Array.from(new Set(o.map(_=>_.RequisitionDate).filter(_=>_!=null).map(String))),S.QuantityOrdered=Array.from(new Set(o.map(_=>_.QuantityOrdered).filter(_=>_!=null).map(String))),S.Location=Array.from(new Set(o.map(_=>_.Location).filter(_=>_!=null))),S.RequestedBy=Array.from(new Set(o.map(_=>_.RequestedBy).filter(_=>_!=null))),S.SubTotal=Array.from(new Set(o.map(_=>_.SubTotal).filter(_=>_!=null).map(String)))),S},[o]);return jsxRuntime.jsx(DataTable,{columns:g,data:o,uniqueValues:b,loading:n,tableClass:"bg-card text-card-foreground"})}function ProductOverviewPage({applicationId:t,sku:e,product:n,productDefaultOpportunityNumber:o="",productOnAddToCart:l,productAddingToCart:d=!1,productShopifyHostname:f,productCustomAction:g=jsxRuntime.jsx(jsxRuntime.Fragment,{})}){var z,Q,V,O,te,ne,ae,Ve,Ne,se,Ae,ge,je,Le,Fe,$e;const{data:b,isLoading:S}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:t,randmarSku:e??"",withSpecification:!1},{skip:!!n||!t||!e}),{data:_,isLoading:R}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:t,randmarSku:e??"",withSpecification:!0},{skip:!!n||!t||!e}),C=n??_??b,{data:E}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:t}),[A,I]=React.useState("stats-tab"),[M,j]=React.useState(!1);React.useEffect(()=>{var We,ze,Ke,et,Ue,Qe,Xe,it;if(!n&&R){j(!1);return}const Oe={stats:(((We=C==null?void 0:C.SalesStatistics)==null?void 0:We.length)??0)<=0,inventory:(((Ke=(ze=C==null?void 0:C.Distribution)==null?void 0:ze.Inventory)==null?void 0:Ke.length)??0)<=0,opportunities:(((et=C==null?void 0:C.Opportunities)==null?void 0:et.length)??0)<=0,orders:(((Ue=C==null?void 0:C.ActiveOrderDetails)==null?void 0:Ue.length)??0)<=0&&(((Qe=C==null?void 0:C.Returns)==null?void 0:Qe.length)??0)<=0,invoices:(((Xe=C==null?void 0:C.CompletedOrderDetails)==null?void 0:Xe.length)??0)<=0,warehouse:(((it=C==null?void 0:C.Receipts)==null?void 0:it.length)??0)<=0},He=Object.values(Oe).some(tt=>!tt);if(j(He),He&&Oe[A]){const tt=Object.keys(Oe).find(at=>!Oe[at]);tt&&I(tt)}},[R,C,n,A]);const q=(C==null?void 0:C.ManufacturerId)!==t;return console.log("readonly",q),jsxRuntime.jsxs("div",{className:"@container",children:[jsxRuntime.jsxs("div",{className:"grid gap-4 grid-cols-1 @sm:grid-cols-2 @md:grid-cols-3",children:[jsxRuntime.jsx("div",{className:"@md:col-span-2",children:jsxRuntime.jsx(ProductCard,{applicationId:t,product:C??C,defaultOpportunityNumber:o,onAddToCart:l,addingToCart:d,shopifyHostname:f,customAction:g})}),jsxRuntime.jsxs(Card,{className:"flex flex-col",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsxs(CardTitle,{children:[jsxRuntime.jsx(Info,{className:"h-5 w-5 inline mr-2"})," Additionnal information"]})}),jsxRuntime.jsx(CardContent,{className:"basis-0 mb-6 grow overflow-y-auto",children:S?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-1 w-full my-6"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full mt-2"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full mt-1"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Category Name"}),jsxRuntime.jsx("span",{className:"font-medium",children:(C==null?void 0:C.ProductType)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Master Carton"}),jsxRuntime.jsx("span",{className:"font-medium",children:(C==null?void 0:C.MasterCarton)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Skid Quantity"}),jsxRuntime.jsx("span",{className:"font-medium",children:(C==null?void 0:C.SkidQuantity)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Automatic Reorder"}),jsxRuntime.jsx("span",{className:"font-medium",children:C!=null&&C.AutoUpdate?"Yes":"No"})]}),((C==null?void 0:C.VoiceoverCaption)||(C==null?void 0:C.BodyHTML))&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("hr",{className:"my-6"}),jsxRuntime.jsx("div",{className:"text-muted-foreground mb-2",children:"Description"}),(C==null?void 0:C.VoiceoverCaption)&&jsxRuntime.jsx("div",{children:C==null?void 0:C.VoiceoverCaption}),(C==null?void 0:C.BodyHTML)&&jsxRuntime.jsx("div",{className:"prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:(C==null?void 0:C.BodyHTML)??""}})]})]})})]})]}),jsxRuntime.jsx("div",{className:"my-4",children:S||R?jsxRuntime.jsx("div",{className:"mx-auto flex justify-center items-center h-32",children:jsxRuntime.jsx(LoaderCircle,{className:"h-8 w-8 animate-spin text-primary"})}):M&&jsxRuntime.jsxs(Tabs,{value:A,onValueChange:I,children:[jsxRuntime.jsxs(TabsList,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[jsxRuntime.jsx(TabsTrigger,{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:(((z=C==null?void 0:C.SalesStatistics)==null?void 0:z.length)??0)<=0,children:"Statistics"}),jsxRuntime.jsx(TabsTrigger,{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:(((V=(Q=C==null?void 0:C.Distribution)==null?void 0:Q.Inventory)==null?void 0:V.length)??0)<=0,children:"Inventory"}),jsxRuntime.jsx(TabsTrigger,{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:(((O=C==null?void 0:C.Opportunities)==null?void 0:O.length)??0)<=0,children:"Opportunities"}),jsxRuntime.jsx(TabsTrigger,{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:(((te=C==null?void 0:C.ActiveOrderDetails)==null?void 0:te.length)??0)<=0,children:"Active Orders"}),jsxRuntime.jsx(TabsTrigger,{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:(((ne=C==null?void 0:C.CompletedOrderDetails)==null?void 0:ne.length)??0)<=0,children:"Completed Orders"}),jsxRuntime.jsx(TabsTrigger,{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:(((ae=C==null?void 0:C.Returns)==null?void 0:ae.length)??0)<=0,children:"Returns"}),jsxRuntime.jsx(TabsTrigger,{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:!(E!=null&&E.IsManufacturer)||(((Ve=C==null?void 0:C.PurchaseOrders)==null?void 0:Ve.length)??0)<=0&&(((Ne=C==null?void 0:C.Requisitions)==null?void 0:Ne.length)??0)<=0,children:"Purchase Orders"}),jsxRuntime.jsx(TabsTrigger,{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:(((se=C==null?void 0:C.Receipts)==null?void 0:se.length)??0)<=0,children:"Latest Warehouse Receiving"})]}),jsxRuntime.jsx(TabsContent,{value:"stats-tab",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(SalesChartCard,{statistics:(C==null?void 0:C.SalesStatistics)??[],loading:R})})}),jsxRuntime.jsx(TabsContent,{value:"inventory-tab",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ProductInventoryGrid,{inventory:((Ae=C==null?void 0:C.Distribution)==null?void 0:Ae.Inventory)??[],className:"bg-card text-card-foreground"})})}),jsxRuntime.jsx(TabsContent,{value:"opportunities-tab",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OpportunitiesTable,{applicationId:t,opportunities:C==null?void 0:C.Opportunities,loading:R})})}),jsxRuntime.jsx(TabsContent,{value:"active-orders-tab",children:(((ge=C==null?void 0:C.ActiveOrderDetails)==null?void 0:ge.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OrdersCard,{applicationId:t,title:"Active Orders",orders:C==null?void 0:C.ActiveOrderDetails,loading:R})})}),jsxRuntime.jsx(TabsContent,{value:"completed-orders-tab",children:(((je=C==null?void 0:C.CompletedOrderDetails)==null?void 0:je.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OrdersCard,{applicationId:t,title:"Completed Orders",orders:C==null?void 0:C.CompletedOrderDetails,loading:R})})}),jsxRuntime.jsx(TabsContent,{value:"returns-tab",children:(((Le=C==null?void 0:C.Returns)==null?void 0:Le.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ReturnsTable,{applicationId:t,returns:C==null?void 0:C.Returns,loading:R})})}),jsxRuntime.jsxs(TabsContent,{value:"purchase-orders-tab",children:[(((Fe=C==null?void 0:C.PurchaseOrders)==null?void 0:Fe.length)??0)>0&&jsxRuntime.jsxs(Card,{className:"mt-4 w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Purchase Orders"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(PurchaseOrdersTable,{applicationId:t,purchaseOrders:C==null?void 0:C.PurchaseOrders,loading:R})})]}),((($e=C==null?void 0:C.Requisitions)==null?void 0:$e.length)??0)>0&&jsxRuntime.jsxs(Card,{className:"mt-4 w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Draft Purchases"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(RequisitionsTable,{applicationId:t,requisitions:C==null?void 0:C.Requisitions,loading:R})})]})]}),jsxRuntime.jsx(TabsContent,{value:"warehouse-tab",children:jsxRuntime.jsxs(Card,{className:"mt-4 w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Receipts"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(ReceiptsTable,{applicationId:t,receipts:C==null?void 0:C.Receipts,loading:R})})]})})]})})]})}function AssistantInsight({prompt:t,smartAndSlow:e=!1,thinkingPlaceholderText:n="Thinking...",withCard:o=!0}){const{response:l,isLoading:d,error:f,sendPrompt:g}=useGemini({useProModel:e,outputFormat:"html"});React.useEffect(()=>{t&&g(t)},[t,g]);const b=`flex items-start gap-4 ${o?"p-4 border rounded-lg bg-background":""}`;return jsxRuntime.jsxs("div",{className:b,children:[jsxRuntime.jsx(Bot,{className:`mt-1 h-6 w-6 flex-shrink-0 ${d?"animate-pulse text-primary":"text-primary"}`}),jsxRuntime.jsxs("div",{className:"w-full min-h-[4rem]",children:[d&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("p",{className:"font-medium text-muted-foreground",children:n}),jsxRuntime.jsxs("div",{className:"space-y-2 mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-5/6"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-3/4"})]})]}),f&&jsxRuntime.jsx("p",{className:"text-sm text-red-600",children:f}),!d&&!f&&l&&jsxRuntime.jsx("div",{className:"chat-bubble-in-animation text-sm text-foreground space-y-4",dangerouslySetInnerHTML:{__html:l}})]})]})}function AssistantChat(t){return jsxRuntime.jsx(Card,{className:"max-w-6xl",children:jsxRuntime.jsx(ChatLayout,{className:"h-[40em]",userId:t.userId,userName:t.userName,assistantOnly:!0,initialPrompt:t.initialPrompt})})}function ExternalProductCard({product:t,viewProductLink:e}){return t?jsxRuntime.jsx(Card,{className:"@container border-dashed border-2 hover:shadow-md transition-shadow h-full",children:jsxRuntime.jsxs(CardContent,{className:"p-6 flex flex-col h-full",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start mb-4 @[36rem]:hidden",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-lg pr-4 text-center w-full",children:t.Title||t.RandmarTitle}),jsxRuntime.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:jsxRuntime.jsx(PartnerLogo,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40})})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-x-6 gap-y-4 flex-grow @[36rem]:flex-row",children:[jsxRuntime.jsx("div",{className:"mx-auto flex-shrink-0 @[36rem]:mx-0 @[36rem]:w-48",children:jsxRuntime.jsx(ProductImage,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||""})}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col text-center @[36rem]:text-left",children:[jsxRuntime.jsxs("div",{className:"hidden @[36rem]:flex justify-between items-start mb-4",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-lg pr-4",children:t.Title||t.RandmarTitle}),jsxRuntime.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:jsxRuntime.jsx(PartnerLogo,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40})})]}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @[36rem]:hidden",children:[jsxRuntime.jsxs(Badge,{variant:"outline",className:"border-orange-300 bg-orange-50 text-orange-800",children:[jsxRuntime.jsx(Telescope,{className:"mr-2 h-3 w-3"}),jsxRuntime.jsx("span",{children:"External Product"})]}),jsxRuntime.jsxs(Badge,{variant:"outline",className:"border-randmar-red bg-red-50 text-randmar-red",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2 h-3 w-3"}),jsxRuntime.jsxs("span",{children:["Held by ",jsxRuntime.jsx("b",{children:"Randmar"})]})]})]}),jsxRuntime.jsxs("div",{className:"hidden @[36rem]:grid grid-cols-2 gap-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center rounded-md bg-orange-50 px-4 py-2 text-orange-800 border-1 border-orange-800 text-sm",children:[jsxRuntime.jsx(Telescope,{className:"mr-2 h-5 w-5 flex-shrink-0"}),jsxRuntime.jsx("span",{children:"External Product"})]}),jsxRuntime.jsxs("div",{className:"flex items-center rounded-md bg-red-50 px-4 py-2 text-randmar-red border-1 border-randmar-red text-sm",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2 h-5 w-5 flex-shrink-0"}),jsxRuntime.jsxs("span",{children:["Held by ",jsxRuntime.jsx("b",{children:"Randmar"})]})]})]}),e&&jsxRuntime.jsx("div",{className:"mt-auto pt-4 flex justify-center @[36rem]:justify-end",children:jsxRuntime.jsx(reactRouterDom.Link,{to:e,children:jsxRuntime.jsxs(Button$1,{variant:"secondary",className:"w-full @[36rem]:w-auto",children:[jsxRuntime.jsx(Eye,{className:"mr-2 h-4 w-4"}),"View Product"]})})})]})]})]})}):jsxRuntime.jsx(Card,{className:"@container border-dashed border-2 h-full",children:jsxRuntime.jsx(CardContent,{className:"p-6 flex flex-col h-full",children:jsxRuntime.jsxs("div",{className:"flex flex-col gap-6 flex-grow @[36rem]:flex-row",children:[jsxRuntime.jsx("div",{className:"flex-shrink-0 @[36rem]:w-48",children:jsxRuntime.jsx(Skeleton,{className:"aspect-square w-full h-auto"})}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-4",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-1/2"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-24 rounded"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @[36rem]:hidden",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-36 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-36 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"hidden @[36rem]:grid grid-cols-2 gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md"})]})]}),jsxRuntime.jsx("div",{className:"mt-auto pt-4 flex justify-center @[36rem]:justify-end",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-full @[36rem]:w-40"})})]})]})})})}function getEndDateStatus(t){if(!t)return{text:"No End Date",variant:"neutral",daysRemaining:null};const e=new Date(t);if(isNaN(e.getTime()))return{text:"Invalid Date",variant:"neutral",daysRemaining:null};const n=new Date,o=new Date(e.getFullYear(),e.getMonth(),e.getDate()),l=new Date(n.getFullYear(),n.getMonth(),n.getDate()),d=o.getTime()-l.getTime(),f=Math.ceil(d/(1e3*60*60*24));return f<0?{text:`Ended ${Math.abs(f)}d ago`,variant:"destructive",daysRemaining:f}:f===0?{text:"Ends today",variant:"destructive",daysRemaining:f}:f<=7?{text:`Ends in ${f}d`,variant:"destructive",daysRemaining:f}:f<=30?{text:`Ends in ${f}d`,variant:"warning",daysRemaining:f}:{text:`Ends in ${f}d`,variant:"neutral",daysRemaining:f}}const formatDate=t=>{if(!t)return"N/A";try{const e=new Date(t);return isNaN(e.getTime())?"Invalid Date":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}};function OpportunitiesTable({applicationId:t,opportunities:e=null,loading:n=!1}){var te;const{toast:o}=useToast(),[l,d]=React.useState({}),[f,g]=React.useState(!1),[b,S]=React.useState(""),[_,R]=React.useState(null),{data:C}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:t},{skip:!t}),E=React.useCallback((ne,ae,Ve)=>{d(Ne=>({...Ne,[ne]:{...Ne[ne],[ae]:Ve}}))},[]),[A]=usePutV4ResellerByRouteResellerIdOpportunityAndManufacturerIdDefaultMutation(),I=React.useCallback(async ne=>{if(!(C!=null&&C.IsReseller))return;if(!ne.BidNumber){o({title:"Error",description:"Bid Number is missing, cannot set default.",variant:"destructive"});return}const ae=ne.BidNumber;E(ae,"isSettingDefault",!0),A({routeResellerId:t,manufacturerId:ne.ManufacturerId??"",opportunityNumber:ae}).unwrap().then(()=>{o({title:"Success",description:`Opportunity "${ne.OpportunityName||ne.Opportunity||ae}" was successfully set as default.`,variant:"success"})}).catch(Ve=>{var Ne;console.error("Set as default error:",Ve),o({title:"Error",description:((Ne=Ve.data)==null?void 0:Ne.message)||Ve.message||"An error occurred while setting this opportunity as default.",variant:"destructive"})}).finally(()=>{E(ae,"isSettingDefault",!1)})},[t,A,o,E,C==null?void 0:C.IsReseller]),[M]=usePostV4ResellerByRouteResellerIdOpportunityAndManufacturerIdBidNumberEmailMutation(),j=React.useCallback(ne=>{if(C!=null&&C.IsReseller){if(!ne.BidNumber){o({title:"Error",description:"Bid Number is missing, cannot prepare report.",variant:"destructive"});return}R(ne),S(""),g(!0)}},[o,C==null?void 0:C.IsReseller]),q=React.useCallback(async()=>{if(!(C!=null&&C.IsReseller))return;if(!_||!_.BidNumber){o({title:"Error",description:"No opportunity selected or Bid Number is missing.",variant:"destructive"});return}if(!b.trim()||!/\S+@\S+\.\S+/.test(b)){o({title:"Validation Error",description:"Please enter a valid email address.",variant:"destructive"});return}const ne=_.BidNumber;E(ne,"isSendingReport",!0),M({routeResellerId:t,manufacturerId:_.ManufacturerId??"",bidNumber:ne,emailAddress:b}).unwrap().then(()=>{o({title:"Success",description:`A report for "${_.OpportunityName||_.Opportunity||ne}" was successfully sent to ${b}.`,variant:"success"}),g(!1)}).catch(ae=>{var Ve;console.error("Send report by email error:",ae),o({title:"Error",description:((Ve=ae.data)==null?void 0:Ve.message)||ae.message||"An error occurred while sending the report by email.",variant:"destructive"})}).finally(()=>{E(ne,"isSendingReport",!1),f||(R(null),S(""))})},[_,b,t,M,o,E,g]),z=React.useMemo(()=>[{accessorKey:"ManufacturerId",header:"Manuf.",cell:({row:ne})=>jsxRuntime.jsx("div",{className:"w-20 h-8",children:jsxRuntime.jsx(PartnerLogo,{id:ne.original.ManufacturerId,width:80,height:32})}),enableSorting:!0,enableFiltering:!0},{id:"opportunityDisplay",accessorFn:ne=>ne.OpportunityName||ne.Opportunity,header:"Opportunity",cell:({getValue:ne})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:ne()??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"BidNumber",header:"Bid Number",cell:({row:ne})=>ne.original.BidNumber??"N/A",enableSorting:!0,enableFiltering:!0},{id:"statusInfo",header:"Status",cell:({row:ne})=>{const ae=ne.original,Ve=ae.Active===!0,Ne=getEndDateStatus(ae.EndDate);let se="border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400";return Ne.variant==="destructive"?se="border-red-500 bg-red-100 text-red-700 dark:border-red-600 dark:bg-red-900/50 dark:text-red-400":Ne.variant==="warning"&&(se="border-yellow-500 bg-yellow-100 text-yellow-700 dark:border-yellow-600 dark:bg-yellow-900/50 dark:text-yellow-400"),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 min-w-[200px]",children:[jsxRuntime.jsx(Badge,{variant:"outline",className:Ve?"border-green-500 bg-green-100 text-green-700 dark:border-green-600 dark:bg-green-900/50 dark:text-green-400 font-medium":"border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400 font-medium",children:Ve?"Active":"Inactive"}),ae.EndDate&&jsxRuntime.jsx(Badge,{variant:"outline",className:`${se} font-medium`,children:Ne.text}),jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0 data-[state=delayed-open]:bg-accent data-[state=instant-open]:bg-accent",children:jsxRuntime.jsx(Info,{className:"h-4 w-4 text-muted-foreground"})})}),jsxRuntime.jsx(TooltipContent,{side:"top",align:"center",className:"bg-popover text-popover-foreground p-2 rounded shadow-lg",children:jsxRuntime.jsxs("div",{className:"text-sm space-y-1",children:[jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"Start:"})," ",formatDate(ae.StartDate)]}),jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"End:"})," ",formatDate(ae.EndDate)]}),jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"Updated:"})," ",formatDate(ae.LastUpdate)]})]})})]})})]})},enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:ne})=>{var je,Le;const ae=ne.original;if(!ae.BidNumber)return jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"Actions unavailable"});const Ve=ae.BidNumber,Ne=(je=l[Ve])==null?void 0:je.isSettingDefault,se=(_==null?void 0:_.BidNumber)===Ve&&((Le=l[Ve])==null?void 0:Le.isSendingReport),Ae=Ne||se,ge=ae.CanBeSetAsDefault===!0;return jsxRuntime.jsxs("div",{className:"flex space-x-2",children:[jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Opportunity/${ae.ManufacturerId}/${ae.BidNumber}`,children:jsxRuntime.jsxs(Button$1,{variant:"outline",size:"sm",className:"flex items-center",children:[jsxRuntime.jsx(Star,{className:"mr-2 h-4 w-4"})," View"]})}),(C==null?void 0:C.IsReseller)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Button$1,{variant:"outline",size:"sm",onClick:()=>I(ae),disabled:Ae||!ge,title:ge?"Set as default":"This opportunity cannot be set as default",className:"flex items-center",children:[Ne?jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):jsxRuntime.jsx(Star,{className:"mr-2 h-4 w-4"})," Set Default"]}),jsxRuntime.jsxs(Button$1,{variant:"outline",size:"sm",onClick:()=>j(ae),disabled:Ae,title:"Send report by email",className:"flex items-center",children:[se?jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):jsxRuntime.jsx(Send,{className:"mr-2 h-4 w-4"})," Send Report"]})]})]})}}],[l,I,j,_,C==null?void 0:C.IsReseller,t]),Q=React.useMemo(()=>{const ne={};if(e){const ae=Array.from(new Set(e.map(Ne=>Ne.ManufacturerId).filter(Ne=>Ne!=null)));ne.ManufacturerId=ae;const Ve=Array.from(new Set(e.map(Ne=>Ne.OpportunityName||Ne.Opportunity).filter(Ne=>Ne!=null)));ne.opportunityDisplay=Ve}return ne},[e]),V=e||[],O=_!=null&&_.BidNumber?(te=l[_.BidNumber])==null?void 0:te.isSendingReport:!1;return n?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{children:[" ",jsxRuntime.jsx(Skeleton,{className:"h-7 w-48"})," "]}),jsxRuntime.jsxs(CardContent,{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-48 w-full rounded-md border"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between pt-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-[130px]"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-20"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})]})]})]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{children:[" ",jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Opportunities"})," "]}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:z,data:V,uniqueValues:Q})})]}),jsxRuntime.jsx(Dialog,{open:f,onOpenChange:ne=>{g(ne),ne||(R(null),S(""))},children:jsxRuntime.jsxs(DialogContent,{className:"@sm:max-w-[425px]",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Send Opportunity Report"}),jsxRuntime.jsxs(DialogDescription,{children:["Enter the email address to send the report for opportunity: ",jsxRuntime.jsx("br",{}),jsxRuntime.jsx("span",{className:"font-semibold",children:(_==null?void 0:_.OpportunityName)||(_==null?void 0:_.Opportunity)||"N/A"}),(_==null?void 0:_.BidNumber)&&jsxRuntime.jsxs("span",{className:"block text-sm text-muted-foreground",children:["Bid Number: ",_.BidNumber]})]})]}),jsxRuntime.jsx("div",{className:"grid gap-4 py-4",children:jsxRuntime.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[jsxRuntime.jsx(Label$2,{htmlFor:"email",className:"text-right",children:"Email"}),jsxRuntime.jsx(Input,{id:"email",type:"email",value:b,onChange:ne=>S(ne.target.value),placeholder:"recipient@example.com",className:"col-span-3",disabled:O})]})}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>g(!1),disabled:O,children:"Cancel"}),jsxRuntime.jsxs(Button$1,{type:"submit",onClick:q,disabled:O,children:[O&&jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"})," Send Report"]})]})]})})]})}function useLoadScript(t){const[e,n]=React.useState(!0),[o,l]=React.useState(null),[d,f]=React.useState(!1),g=()=>{n(!1),f(!0)};return React.useEffect(()=>{if(!document){const R=new Error(`[ScriptLoadingError] document not defined when attempting to load ${t}`);l(R);return}const b=document.querySelector(`script[src="${t}"]`);if(b!=null&&b.dataset.loaded){g();return}const S=b||document.createElement("script");b||(S.src=t);const _=()=>{S.dataset.loaded="1",g()};S.addEventListener("load",_),S.addEventListener("error",R=>{console.error("Failed to load script:",t,R);const C=new Error(`[ScriptLoadingError] Failed to load script: ${t}`);l(C)}),b||document.head.append(S)},[]),{isLoading:e,error:o,isSuccess:d}}const isGoogleReady=t=>t&&t.charts,isGoogleChartsReady=(t,e)=>{const{controls:n,toolbarItems:o,getChartEditor:l}=t;return e&&e.charts&&e.visualization&&e.visualization.ChartWrapper&&e.visualization.Dashboard&&(!n||e.visualization.ChartWrapper)&&(!l||e.visualization.ChartEditor)&&(!o||e.visualization.drawToolbar)},getGoogleInstanceFromWindow=t=>window.google;function useLoadGoogleCharts(t){const{chartVersion:e="current",chartPackages:n=["corechart","controls"],chartLanguage:o="en",mapsApiKey:l}=t,[d,f]=React.useState(null),[g,b]=React.useState(null),[S,_]=React.useState(null),{isLoading:R,error:C,isSuccess:E}=useLoadScript(t.chartLoaderScriptUrl||"https://www.gstatic.com/charts/loader.js");return React.useEffect(()=>{if(!E)return;const A=getGoogleInstanceFromWindow();if(!isGoogleReady(A)){const I=new Error("[ScriptInitializationError] Script loaded but Google not attached to window.");b(I);return}if(isGoogleChartsReady(t,A)){f(A);return}A.charts.load(e,{packages:n,language:o,mapsApiKey:l}),A.charts.setOnLoadCallback(()=>{if(!isGoogleChartsReady(t,A)){const I=new Error("[GoogleChartsInitializationError] Google Charts not ready after load callback.");console.error(I),_(I);return}f(A)})},[E]),{error:C||g||S,isLoading:R,google:d}}const chartDefaultProps={legend_toggle:!1,options:{},legendToggle:!1,getChartWrapper:()=>{},spreadSheetQueryParameters:{headers:1,gid:1},rootProps:{},chartWrapperParams:{},chartLoaderScriptUrl:"https://www.gstatic.com/charts/loader.js"},GoogleChartControls=t=>{const{isReady:e,chartControls:n,filter:o}=t;return!e||!n||!(n!=null&&n.length)?null:React.createElement(React.Fragment,null,n.filter(l=>{let{controlProp:d,control:f}=l;return o?o({control:f,controlProp:d}):!0}).map(l=>{let{control:d}=l;return React.createElement("div",{key:d.getContainerId(),id:d.getContainerId()})}))};let uniqueID=0;const generateUniqueID=()=>(uniqueID+=1,`reactgooglegraph-${uniqueID}`),Ln=class Ln{};rn(Ln,"initializeControls",e=>{for(let n=0;n<e.length;n+=1){const{controlType:o,options:l,controlWrapperParams:d}=e[n].controlProp;d&&"state"in d&&e[n].control.setState(d.state),e[n].control.setOptions(l),e[n].control.setControlType(o)}}),rn(Ln,"listenToControlEvents",(e,n)=>{const{google:o}=n;return e.flatMap(l=>{const{control:d,controlProp:f}=l,{controlEvents:g=[]}=f;return g.map(b=>{const{callback:S,eventName:_}=b;return o.visualization.events.addListener(d,_,function(){for(var R=arguments.length,C=new Array(R),E=0;E<R;E++)C[E]=arguments[E];S({chartWrapper:null,controlWrapper:d,props:n,google:o,eventArgs:C})})})})}),rn(Ln,"createControlId",e=>{let n;return typeof e>"u"?n=`googlechart-control-${generateUniqueID()}`:n=e,n}),rn(Ln,"createChartControls",e=>{const{controls:n,google:o}=e;return n?n.map((l,d)=>{const{controlID:f,controlType:g,options:b,controlWrapperParams:S}=l,_=Ln.createControlId(f);return{controlProp:l,control:new o.visualization.ControlWrapper({containerId:_,controlType:g,options:b,...S})}}):null}),rn(Ln,"addControls",e=>{const{chartWrapper:n,chartDashboard:o}=e,l=Ln.createChartControls(e);return!l||!o||!n?null:(o.bind(l.map(d=>{let{control:f}=d;return f}),n),Ln.initializeControls(l),l)});let GoogleChartControlsInternal=Ln;const useCreateChartControls=t=>{const[e,n]=React__namespace.useState(null);return[React__namespace.useMemo(()=>!e||!t?null:t.map((l,d)=>{const f=e[d];return f?{controlProp:l,control:f}:void 0}).flatMap(l=>l?[l]:[]),[e,t]),n]},useListenToControlEvents=(t,e)=>{React__namespace.useEffect(()=>{const n=GoogleChartControlsInternal.listenToControlEvents(t??[],e);return()=>{n.forEach(o=>{e.google.visualization.events.removeListener(o)})}},[t,e])},useChartControls=t=>{const[e,n]=useCreateChartControls(t.controls);return useListenToControlEvents(e??[],t),{addControls:l=>{const d=GoogleChartControlsInternal.addControls(l);n((d==null?void 0:d.map(f=>f.control))??null)},renderControl:l=>{const{chartWrapper:d,chartDashboard:f}=t;return React__namespace.createElement(GoogleChartControls,{...t,isReady:!!(d&&f),chartControls:e,filter:l})}}},useChartId=t=>{const e=React__namespace.useRef(null);return{chartId:(()=>{const{graphID:l,graph_id:d}=t,f=l||d;let g;return f?g=f:g=e.current||generateUniqueID(),e.current=g,e.current})()}},DEFAULT_CHART_COLORS=["#3366CC","#DC3912","#FF9900","#109618","#990099","#3B3EAC","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#329262","#5574A6","#3B3EAC"],loadDataTableFromSpreadSheet=async function(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((o,l)=>{const d=`${n.headers?`headers=${n.headers}`:"headers=0"}`,f=`${n.query?`&tq=${encodeURIComponent(n.query)}`:""}`,g=`${n.gid?`&gid=${n.gid}`:""}`,b=`${n.sheet?`&sheet=${n.sheet}`:""}`,S=`${n.access_token?`&access_token=${n.access_token}`:""}`,_=`${d}${g}${b}${f}${S}`,R=`${e}/gviz/tq?${_}`;new t.visualization.Query(R).send(E=>{E.isError()?l(`Error in query: ${E.getMessage()} ${E.getDetailedMessage()}`):o(E.getDataTable())})})},GRAY_COLOR="#CCCCCC",$n=class $n{};rn($n,"grayOutHiddenColumnsLabel",(e,n)=>{const{googleChartWrapper:o,options:l}=e;if(!o){console.error("googleChartWrapper is not defined");return}const d=o.getDataTable();if(!d)return;const f=d.getNumberOfColumns();if(n.length>0===!1)return;const b=Array.from({length:f-1}).map((S,_)=>{const R=$n.getColumnId(d,_+1);return n.includes(R)?GRAY_COLOR:l&&l.colors?l.colors[_]:DEFAULT_CHART_COLORS[_]});o.setOptions({...l,colors:b}),o.draw()}),rn($n,"listenToLegendToggle",(e,n)=>{const[o,l]=n,{google:d,googleChartWrapper:f}=e;if(!f){console.error("googleChartWrapper is not defined");return}return d.visualization.events.addListener(f,"select",()=>{const b=f.getChart().getSelection(),S=f.getDataTable();if(b.length===0||b[0].row!==null||!S)return;const _=b[0].column,R=$n.getColumnId(S,_);o!=null&&o.includes(R)?l(C=>[...C.filter(E=>E!==R)]):l(C=>[...C,R])})}),rn($n,"draw",async e=>{const{data:n,diffdata:o,rows:l,columns:d,options:f,chartType:g,formatters:b,spreadSheetUrl:S,spreadSheetQueryParameters:_,googleChartDashboard:R,googleChartWrapper:C,google:E,hiddenColumns:A,legendToggle:I,legend_toggle:M}=e;if(!C){console.error("draw was called with googleChartWrapper = null");return}let j,q=null;if(o){const te=E.visualization.arrayToDataTable(o.old),ne=E.visualization.arrayToDataTable(o.new);q=E.visualization[g].prototype.computeDiff(te,ne)}n?n instanceof E.visualization.DataTable?j=n:Array.isArray(n)?j=E.visualization.arrayToDataTable(n):j=new E.visualization.DataTable(n):l&&d?j=E.visualization.arrayToDataTable([d,...l]):S?j=await loadDataTableFromSpreadSheet(E,S,_):j=E.visualization.arrayToDataTable([]);const z=j.getNumberOfColumns(),Q=Array(z).fill(0).map((te,ne)=>{const ae=$n.getColumnId(j,ne);return A.includes(ae)?{label:j.getColumnLabel(ne),type:j.getColumnType(ne),calc:()=>null}:ne}),V=C.getChart();C.getChartType()==="Timeline"&&V&&V.clearChart(),C.setChartType(g),C.setOptions(f||{});const O=new E.visualization.DataView(j);O.setColumns(Q),C.setDataTable(O),C.draw(),R&&R.draw(j),q&&(C.setDataTable(q),C.draw()),b&&($n.applyFormatters({dataTable:j,formatters:b,google:E}),C.setDataTable(j),C.draw()),(I===!0||M===!0)&&$n.grayOutHiddenColumnsLabel(e,A)}),rn($n,"getColumnId",(e,n)=>e.getColumnId(n)||e.getColumnLabel(n)),rn($n,"applyFormatters",e=>{let{dataTable:n,formatters:o,google:l}=e;for(let d of o)switch(d.type){case"ArrowFormat":{new l.visualization.ArrowFormat(d.options).format(n,d.column);return}case"BarFormat":{new l.visualization.BarFormat(d.options).format(n,d.column);return}case"ColorFormat":{const f=new l.visualization.ColorFormat(d.options),{ranges:g}=d;if(g)for(let b of g)f.addRange(...b);f.format(n,d.column);return}case"DateFormat":{new l.visualization.DateFormat(d.options).format(n,d.column);return}case"NumberFormat":{new l.visualization.NumberFormat(d.options).format(n,d.column);return}case"PatternFormat":{new l.visualization.PatternFormat(d.options).format(n,d.column);return}default:{console.warn(`Unknown formatter type: ${d.type}`);return}}});let GoogleChartInternal=$n;const useGoogleChartDataTable=t=>{const{google:e,googleChartWrapper:n,googleChartDashboard:o}=t,[l,d]=React__namespace.useState([]);React__namespace.useEffect(()=>{n&&GoogleChartInternal.draw({...t,hiddenColumns:l,googleChartWrapper:n,googleChartDashboard:o,google:e})},[l,t.data,t.rows,t.columns,t.options,t.chartLoaderScriptUrl,t.chartType,t.formatters,t.spreadSheetUrl,t.spreadSheetQueryParameters,t.legendToggle,t.legend_toggle]);const f=()=>{const{googleChartWrapper:S}=t;S&&S.draw()},g=S=>{const _=[],{legendToggle:R,legend_toggle:C}=t;if(GoogleChartInternal.draw({...t,hiddenColumns:l,googleChartWrapper:S,googleChartDashboard:o,google:e}),window.addEventListener("resize",f),C||R){const E=GoogleChartInternal.listenToLegendToggle(t,[l,d]);E&&_.push(E)}return _},b=(S,_)=>{window.removeEventListener("resize",f),_.forEach(R=>{e.visualization.events.removeListener(R)}),S.getChartType()==="Timeline"&&S.getChart()&&S.getChart().clearChart()};React__namespace.useEffect(()=>{if(!n)return;const S=g(n);return()=>{b(n,S)}},[n,g,b])},listenToEvents=t=>{const{chartEvents:e,google:n,googleChartWrapper:o}=t;if(e){if(!o){console.warn("listenToEvents was called before chart wrapper ready.");return}return e.map(l=>{let{eventName:d,callback:f}=l;return n.visualization.events.addListener(o,d,function(){for(var g=arguments.length,b=new Array(g),S=0;S<g;S++)b[S]=arguments[S];f({chartWrapper:o,props:t,google:n,eventArgs:b})})})}},useGoogleChartEvents=t=>{React.useEffect(()=>{if(!t.googleChartWrapper)return;const e=listenToEvents(t);return()=>{e==null||e.forEach(n=>{t.google.visualization.events.removeListener(n)})}},[t])},GoogleChart=t=>{const[e,n]=React__namespace.useState(null),[o,l]=React__namespace.useState(null),{addControls:d,renderControl:f}=useChartControls({...t,chartDashboard:o,chartWrapper:e});useGoogleChartEvents({...t,googleChartWrapper:e});const{chartId:g}=useChartId(t),b=React__namespace.useRef(null),S=React__namespace.useRef(null);React__namespace.useEffect(()=>{const{options:j,google:q,chartType:z,chartWrapperParams:Q,toolbarItems:V,getChartEditor:O,getChartWrapper:te,onLoad:ne}=t,ae={chartType:z,options:j,containerId:g,...Q},Ve=new q.visualization.ChartWrapper(ae);Ve.setOptions(j||{}),te==null||te(Ve,q);const Ne=new q.visualization.Dashboard(b.current);V&&q.visualization.drawToolbar(S.current,V);let se=null;O&&(se=new q.visualization.ChartEditor,O({chartEditor:se,chartWrapper:Ve,google:q})),d({...t,chartDashboard:Ne,chartWrapper:Ve}),n(Ve),l(Ne),ne==null||ne(q,{google:q,chartWrapper:Ve,chartEditor:se,chartDashboard:Ne})},[]),useGoogleChartDataTable({...t,googleChartWrapper:e,googleChartDashboard:o});const _=()=>{const{width:j,height:q,options:z,style:Q,className:V,rootProps:O,google:te}=t,ne={height:q||z&&z.height,width:j||z&&z.width,...Q};return React__namespace.createElement("div",{id:g,style:ne,className:V,...O})},R=()=>t.toolbarItems?React__namespace.createElement("div",{ref:S}):null,{width:C,height:E,options:A,style:I}=t,M={height:E||A&&A.height,width:C||A&&A.width,...I};return t.render?React__namespace.createElement("div",{ref:b,style:M},React__namespace.createElement("div",{ref:S,id:"toolbar"}),t.render({renderChart:_,renderControl:f,renderToolbar:R})):React__namespace.createElement("div",{ref:b,style:M},f(j=>{let{controlProp:q}=j;return q.controlPosition!=="bottom"}),_(),f(j=>{let{controlProp:q}=j;return q.controlPosition==="bottom"}),R())},ChartContext=React__namespace.createContext(chartDefaultProps),ContextProvider=t=>{let{children:e,value:n}=t;return React__namespace.createElement(ChartContext.Provider,{value:n},e)},ChartView=t=>{const{google:e,isLoading:n,error:o}=useLoadGoogleCharts(t);return n?t.loader??null:o?t.errorElement??null:e?React.createElement(GoogleChart,{google:e,...t}):null},Chart=t=>{const e={...chartDefaultProps,...t};return React.createElement(ContextProvider,{value:e},React.createElement(ChartView,e))};var GoogleDataTableColumnRoleType;(function(t){t.annotation="annotation",t.annotationText="annotationText",t.certainty="certainty",t.emphasis="emphasis",t.interval="interval",t.scope="scope",t.style="style",t.tooltip="tooltip",t.domain="domain"})(GoogleDataTableColumnRoleType||(GoogleDataTableColumnRoleType={}));function parseHsl(t){const e=t.match(/(\d+\.?\d*)\s*(\d+\.?\d*)%\s*(\d+\.?\d*)%/);return e?{h:parseFloat(e[1]),s:parseFloat(e[2]),l:parseFloat(e[3])}:null}function hslToHex(t,e,n){n/=100;const o=e*Math.min(n,1-n)/100,l=d=>{const f=(d+t/30)%12,g=n-o*Math.max(Math.min(f-3,9-f,1),-1);return Math.round(255*g).toString(16).padStart(2,"0")};return`#${l(0)}${l(8)}${l(4)}`}const Treemap=React__namespace.forwardRef(({data:t,options:e,height:n="500px",className:o,loading:l,disableClick:d=!0,...f},g)=>{const b=React__namespace.useRef(null),[S,_]=React__namespace.useState(null);React__namespace.useEffect(()=>{if(!b.current)return;const E=b.current,A=()=>{const q=getComputedStyle(E).getPropertyValue("--primary").trim();if(q){const z=parseHsl(q);if(z){const{h:Q,s:V,l:O}=z;_({minColor:hslToHex(Q,V,Math.min(100,O+50)),midColor:hslToHex(Q,V,Math.min(100,O+35)),maxColor:hslToHex(Q,V,Math.min(100,O+20))})}return!0}return!1};if(A())return;let I=0;const M=20,j=setInterval(()=>{(A()||I>=M)&&clearInterval(j),I++},100);return()=>{j&&clearInterval(j)}},[]);const R=React__namespace.useMemo(()=>{const E={headerHeight:0,fontSize:14,showScale:!1,isHtml:!0,backgroundColor:"hsl(var(--background))",generateTooltip:(A,I)=>{var q;const M=(q=t[A+1])==null?void 0:q[0];if(!M)return"";const j=formatMoney(I);return`<div class="p-2 bg-background text-foreground border rounded-md shadow-lg">
1428
+ `;function RichTextEditor({id:t,name:e,value:n,onChange:o,placeholder:l,className:d,...f}){const[g,b]=React.useState(!1),S=React.useRef(null),_=React.useRef(null),R=useEditor({extensions:[StarterKit,Underline],content:n,editorProps:{attributes:{class:"prose prose-sm sm:prose dark:prose-invert focus:outline-none",id:t??"",name:e??""}},onUpdate:({editor:j})=>{const q=j.getHTML();o({target:{id:t,name:e,value:q}})}});React.useEffect(()=>{R&&n!==R.getHTML()&&R.commands.setContent(n)},[n,R]);const C=React.useCallback(j=>{if(R)if(R.chain().focus(),j==="paragraph")R.chain().setParagraph().run();else{const q=Number.parseInt(j.slice(1));R.chain().setHeading({level:q}).run()}},[R]),E=React.useCallback(j=>{if(R)switch(R.chain().focus(),j){case"bold":R.chain().toggleBold().run();break;case"italic":R.chain().toggleItalic().run();break;case"underline":R.chain().toggleUnderline().run();break;case"strike":R.chain().toggleStrike().run();break;case"bulletList":R.chain().toggleBulletList().run();break;case"orderedList":R.chain().toggleOrderedList().run();break}},[R]),A=React.useCallback(()=>{b(j=>!j)},[]),I=React.useCallback(j=>{const q=j.target.value;R&&R.commands.setContent(q),o({target:{id:t,name:e,value:q}})},[o,R,t,e]),M=React.useCallback(()=>{!g&&R&&R.commands.focus()},[g,R]);return R?jsxRuntime.jsxs("div",{ref:_,className:cn("border border-input rounded-md overflow-hidden focus-within:outline-hidden focus-within:ring-1 focus-within:ring-ring",d),onClick:M,...f,children:[jsxRuntime.jsx("style",{children:editorStyles}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center p-2 border-b border-input gap-2 bg-background",children:[jsxRuntime.jsxs(Select$1,{onValueChange:C,disabled:g,children:[jsxRuntime.jsx(SelectTrigger,{className:"w-[160px]",children:jsxRuntime.jsx(SelectValue,{placeholder:"Format"})}),jsxRuntime.jsx(SelectContent,{children:formatOptions.map(j=>jsxRuntime.jsx(SelectItem,{value:j.value,children:j.label},j.value))})]}),["bold","italic","underline","strike","bulletList","orderedList"].map(j=>jsxRuntime.jsxs(Button$1,{type:"button",variant:"ghost",size:"sm",onClick:()=>E(j),className:R.isActive(j)?"bg-muted":"",disabled:g,children:[j==="bold"&&jsxRuntime.jsx(Bold$1,{className:"h-4 w-4"}),j==="italic"&&jsxRuntime.jsx(Italic$1,{className:"h-4 w-4"}),j==="underline"&&jsxRuntime.jsx(Underline$1,{className:"h-4 w-4"}),j==="strike"&&jsxRuntime.jsx(Strikethrough,{className:"h-4 w-4"}),j==="bulletList"&&jsxRuntime.jsx(List$1,{className:"h-4 w-4"}),j==="orderedList"&&jsxRuntime.jsx(ListOrdered,{className:"h-4 w-4"})]},j)),jsxRuntime.jsx(Button$1,{type:"button",variant:"ghost",size:"sm",onClick:A,className:g?"bg-muted":"",children:jsxRuntime.jsx(Code$1,{className:"h-4 w-4"})})]}),jsxRuntime.jsx("div",{className:"p-3",children:g?jsxRuntime.jsx(Textarea,{ref:S,id:t,name:e,value:R.getHTML(),onChange:I,className:cn("min-h-[150px] font-mono text-sm resize-none border-0 focus-visible:ring-0 focus-visible:ring-offset-0",d),placeholder:l}):jsxRuntime.jsx(EditorContent,{editor:R})})]}):null}function ReceiptsTable({applicationId:t,receipts:e=null,loading:n=!1}){const o=React.useMemo(()=>[{accessorKey:"Location",header:"Location",cell:({row:f})=>f.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptDate",header:"Date",cell:({row:f})=>formatYYYYMMDDIntToDateString(f.original.ReceiptDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"ReceiptNumber",header:"Number",cell:({row:f})=>f.original.ReceiptNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${f.original.ReceiptNumber}`,className:"font-medium text-primary hover:underline",children:f.original.ReceiptNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for Receipt ",f.original.ReceiptNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:f})=>f.original.Quantity??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:f})=>f.original.UnitPrice?formatMoney(f.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0}],[]),l=React.useMemo(()=>{const f={};if(e){const g=Array.from(new Set(e.map(S=>S.Location).filter(S=>S!=null)));f.Location=g;const b=Array.from(new Set(e.map(S=>formatYYYYMMDDIntToDateString(S.ReceiptDate)).filter(S=>S!=="—"&&S!=="Invalid Date"))).sort((S,_)=>new Date(_).getTime()-new Date(S).getTime());f.ReceiptDate=b}return f},[e]),d=e||[];return jsxRuntime.jsx(DataTable,{columns:o,data:d,uniqueValues:l,loading:n,tableClass:"bg-card text-card-foreground",initialSort:[{id:"ReceiptDate",desc:!0}]})}const formatDate$1=t=>{if(!t)return"N/A";try{const e=new Date(t);return isNaN(e.getTime())?"Invalid Date":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}},getStatusVariant=t=>{const e=(t==null?void 0:t.toLowerCase())||"";return e.includes("accepted")?"success":e.includes("error")||e.includes("rejected")?"destructive":"neutral"};function ReturnsTable({applicationId:t,returns:e=null,loading:n=!1}){const o=React.useMemo(()=>[{accessorKey:"ReturnNumber1",header:"RMA Number",cell:({row:f})=>{const g=f.original.ReturnNumber1||f.original.ReturnNumber;return g?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Return/${g}`,className:"font-medium text-primary hover:underline",children:g})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for return ",g]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestDate",header:"Request Date",cell:({row:f})=>formatDate$1(f.original.RequestDate),enableSorting:!0},{accessorKey:"InvoiceNumber",header:"Invoice Number",cell:({row:f})=>{const g=f.original.InvoiceNumber;return g?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${g}`,className:"text-blue-600 hover:underline dark:text-blue-400",children:g})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for invoice ",g]})})]})}):"N/A"},enableSorting:!0,enableFiltering:!0},{accessorKey:"Quantity",header:"Quantity",cell:({row:f})=>f.original.Quantity??"0",enableSorting:!0},{accessorKey:"ReasonForReturn",header:"Return Reason",cell:({row:f})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:f.original.ReasonForReturn??"—"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"Status",header:"Status",cell:({row:f})=>{const g=f.original.Status,b=getStatusVariant(g);let S="border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400";return b==="success"?S="border-green-500 bg-green-100 text-green-700 dark:border-green-600 dark:bg-green-900/50 dark:text-green-400":b==="destructive"&&(S="border-red-500 bg-red-100 text-red-700 dark:border-red-600 dark:bg-red-900/50 dark:text-red-400"),g?jsxRuntime.jsx(Badge,{variant:"outline",className:`${S} font-medium`,children:g}):"—"},enableSorting:!0,enableFiltering:!0},{accessorKey:"WarehouseLocation",header:"Warehouse",cell:({row:f})=>f.original.WarehouseLocation??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"LastUpdatedDate",header:"Last Update",cell:({row:f})=>formatDate$1(f.original.LastUpdatedDate)!=="N/A"?formatDate$1(f.original.LastUpdatedDate):"—",enableSorting:!0}],[t]),l=React.useMemo(()=>{const f={};if(e){const g=Array.from(new Set(e.map(_=>_.Status).filter(Boolean)));f.Status=g;const b=Array.from(new Set(e.map(_=>_.ReasonForReturn).filter(Boolean)));f.ReasonForReturn=b;const S=Array.from(new Set(e.map(_=>_.WarehouseLocation).filter(Boolean)));f.WarehouseLocation=S}return f},[e]),d=React.useMemo(()=>e?[...e].sort((g,b)=>(b.ReturnNumber1||b.ReturnNumber||"").localeCompare(g.ReturnNumber1||g.ReturnNumber||"")):[],[e]);return n?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(Skeleton,{className:"h-7 w-48"})}),jsxRuntime.jsxs(CardContent,{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-48 w-full rounded-md border"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between pt-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-[130px]"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-20"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"}),jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})]})]})]})]}):jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Returns"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:o,data:d,uniqueValues:l})})]})}function PurchaseOrdersTable({applicationId:t,purchaseOrders:e=null,loading:n=!1}){const[o,l]=React.useState([]),[d]=usePostV4ManufacturerByRouteManufacturerIdPurchaseOrderAndPurchaseOrderNumberEditItemRandmarSkuMutation(),{toast:f}=useToast();React.useEffect(()=>{l(e||[])},[e]);const g=React.useMemo(()=>[{accessorKey:"PurchaseOrderNumber",header:"Number",cell:({row:S})=>S.original.PurchaseOrderNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${S.original.PurchaseOrderNumber}`,className:"font-medium text-primary hover:underline",children:S.original.PurchaseOrderNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for Purchase Order ",S.original.PurchaseOrderNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PurchaseOrderDate",header:"Date",cell:({row:S})=>formatYYYYMMDDIntToDateString(S.original.PurchaseOrderDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:S})=>S.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"PartNumber",header:"Part Number",cell:({row:S})=>S.original.MPN?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Product/${S.original.RandmarSKU}`,className:"font-medium text-primary hover:underline",children:S.original.MPN})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for Product ",S.original.RandmarSKU]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:S})=>S.original.QuantityOrdered??0,enableSorting:!0,enableFiltering:!0},{accessorKey:"UnitPrice",header:"Unit Price",cell:({row:S})=>S.original.UnitPrice?formatMoney(S.original.UnitPrice):"—",enableSorting:!0,enableFiltering:!0},{id:"actions",header:()=>jsxRuntime.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:_}){const[R,C]=React.useState(!1),E=_.original,A=()=>{C(!0),d({routeManufacturerId:t,purchaseOrderNumber:E.PurchaseOrderNumber??"",randmarSku:E.RandmarSKU??"",quantity:0}).then(()=>{l(I=>I.filter(M=>!(M.PurchaseOrderNumber===M.PurchaseOrderNumber&&M.MPN===M.MPN))),f({variant:"success",title:"Success",description:`Part ${E.MPN} has been successfully deleted from Purchase Order ${E.PurchaseOrderNumber}.`})}).catch(I=>{console.error(I),C(!0),f({variant:"destructive",title:"Error",description:"Something went wrong!"})})};return jsxRuntime.jsx("div",{className:"text-right",children:jsxRuntime.jsxs(AlertDialog,{children:[jsxRuntime.jsx(AlertDialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{variant:"red",size:"sm",disabled:R,children:R?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting"]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})}),jsxRuntime.jsxs(AlertDialogContent,{children:[jsxRuntime.jsxs(AlertDialogHeader,{children:[jsxRuntime.jsx(AlertDialogTitle,{children:"Confirmation"}),jsxRuntime.jsxs(AlertDialogDescription,{children:["Are you sure you want to delete part ",jsxRuntime.jsx("strong",{children:E.MPN})," from Purchase Order ",jsxRuntime.jsx("strong",{children:E.PurchaseOrderNumber}),"?."]})]}),jsxRuntime.jsxs(AlertDialogFooter,{children:[jsxRuntime.jsx(AlertDialogCancel,{disabled:R,children:"Cancel"}),jsxRuntime.jsxs(AlertDialogAction,{onClick:A,disabled:R,children:[R&&jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}],[t]),b=React.useMemo(()=>{const S={};return o&&(S.PurchaseOrderNumber=Array.from(new Set(o.map(_=>_.PurchaseOrderNumber).filter(_=>_!=null))),S.PurchaseOrderDate=Array.from(new Set(o.map(_=>_.PurchaseOrderDate).filter(_=>_!=null).map(String))),S.Location=Array.from(new Set(o.map(_=>_.Location).filter(_=>_!=null))),S.PartNumber=Array.from(new Set(o.map(_=>_.MPN).filter(_=>_!=null))),S.QuantityOrdered=Array.from(new Set(o.map(_=>_.QuantityOrdered).filter(_=>_!=null).map(String))),S.UnitPrice=Array.from(new Set(o.map(_=>_.UnitPrice).filter(_=>_!=null).map(String)))),S},[o]);return jsxRuntime.jsx(DataTable,{columns:g,data:o,uniqueValues:b,loading:n,tableClass:"bg-card text-card-foreground"})}function RequisitionsTable({applicationId:t,requisitions:e=null,loading:n=!1}){const[o,l]=React.useState([]),[d]=useDeleteV4ManufacturerByRouteManufacturerIdRequisitionAndRequisitionNumberMutation(),{toast:f}=useToast();React.useEffect(()=>{l(e||[])},[e]);const g=React.useMemo(()=>[{accessorKey:"RequisitionNumber",header:"Number",cell:({row:S})=>S.original.RequisitionNumber?jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactRouterDom.Link,{to:`/${t}/Document/${S.original.RequisitionNumber}`,className:"font-medium text-primary hover:underline",children:S.original.RequisitionNumber})}),jsxRuntime.jsx(TooltipContent,{children:jsxRuntime.jsxs("p",{children:["View details for Draft Purchase ",S.original.RequisitionNumber]})})]})}):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequisitionDate",header:"Date",cell:({row:S})=>formatYYYYMMDDIntToDateString(S.original.RequisitionDate),enableSorting:!0,enableFiltering:!0},{accessorKey:"Location",header:"Location",cell:({row:S})=>S.original.Location??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOrdered",header:"Quantity Ordered",cell:({row:S})=>S.original.QuantityOrdered??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityOutstanding",header:"Quantity Outstanding",cell:({row:S})=>S.original.QuantityOutstanding??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"QuantityReceived",header:"Quantity Received",cell:({row:S})=>S.original.QuantityReceived??"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"SubTotal",header:"Sub Total",cell:({row:S})=>S.original.SubTotal?formatMoney(S.original.SubTotal):"—",enableSorting:!0,enableFiltering:!0},{accessorKey:"RequestedBy",header:"Requestor",cell:({row:S})=>S.original.RequestedBy??"—",enableSorting:!0,enableFiltering:!0},{id:"actions",header:()=>jsxRuntime.jsx("div",{className:"text-right",children:"Action"}),cell:function({row:_}){const[R,C]=React.useState(!1),E=_.original,A=()=>{C(!0),d({routeManufacturerId:t,requisitionNumber:E.RequisitionNumber??""}).then(()=>{l(I=>I.filter(M=>M.RequisitionNumber!==M.RequisitionNumber)),f({variant:"success",title:"Success",description:`Draft Purchase ${E.RequisitionNumber} has been successfully cancelled.`})}).catch(I=>{console.error(I),C(!0),f({variant:"destructive",title:"Error",description:"Something went wrong!"})})};return jsxRuntime.jsx("div",{className:"text-right",children:jsxRuntime.jsxs(AlertDialog,{children:[jsxRuntime.jsx(AlertDialogTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{variant:"red",size:"sm",disabled:R,children:R?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancelling"]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Trash2,{className:"mr-2 h-4 w-4"}),"Cancel"]})})}),jsxRuntime.jsxs(AlertDialogContent,{children:[jsxRuntime.jsxs(AlertDialogHeader,{children:[jsxRuntime.jsx(AlertDialogTitle,{children:"Confirmation"}),jsxRuntime.jsxs(AlertDialogDescription,{children:["Are you sure you want to cancel Draft Purchase ",jsxRuntime.jsx("strong",{children:E.RequisitionNumber}),"?."]})]}),jsxRuntime.jsxs(AlertDialogFooter,{children:[jsxRuntime.jsx(AlertDialogCancel,{disabled:R,children:"Cancel"}),jsxRuntime.jsxs(AlertDialogAction,{onClick:A,disabled:R,children:[R&&jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirm"]})]})]})]})})}}],[t]),b=React.useMemo(()=>{const S={};return o&&(S.RequisitionNumber=Array.from(new Set(o.map(_=>_.RequisitionNumber).filter(_=>_!=null))),S.RequisitionDate=Array.from(new Set(o.map(_=>_.RequisitionDate).filter(_=>_!=null).map(String))),S.QuantityOrdered=Array.from(new Set(o.map(_=>_.QuantityOrdered).filter(_=>_!=null).map(String))),S.QuantityOutstanding=Array.from(new Set(o.map(_=>_.QuantityOutstanding).filter(_=>_!=null).map(String))),S.QuantityReceived=Array.from(new Set(o.map(_=>_.QuantityReceived).filter(_=>_!=null).map(String))),S.Location=Array.from(new Set(o.map(_=>_.Location).filter(_=>_!=null))),S.RequestedBy=Array.from(new Set(o.map(_=>_.RequestedBy).filter(_=>_!=null))),S.SubTotal=Array.from(new Set(o.map(_=>_.SubTotal).filter(_=>_!=null).map(String)))),S},[o]);return jsxRuntime.jsx(DataTable,{columns:g,data:o,uniqueValues:b,loading:n,tableClass:"bg-card text-card-foreground"})}function ProductOverviewPage({applicationId:t,sku:e,product:n,productDefaultOpportunityNumber:o="",productOnAddToCart:l,productAddingToCart:d=!1,productShopifyHostname:f,productCustomAction:g=jsxRuntime.jsx(jsxRuntime.Fragment,{})}){var z,Q,V,O,te,ne,ae,Ve,Ne,se,Ae,ge,je,Le,Fe,$e;const{data:b,isLoading:S}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:t,randmarSku:e??"",withSpecification:!1},{skip:!!n||!t||!e}),{data:_,isLoading:R}=useGetV4PartnerByRouteApplicationIdProductAndRandmarSkuQuery({routeApplicationId:t,randmarSku:e??"",withSpecification:!0},{skip:!!n||!t||!e}),C=n??_??b,{data:E}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:t}),[A,I]=React.useState("stats-tab"),[M,j]=React.useState(!1);React.useEffect(()=>{var We,ze,Ke,et,Ue,Qe,Xe,it;if(!n&&R){j(!1);return}const Oe={stats:(((We=C==null?void 0:C.SalesStatistics)==null?void 0:We.length)??0)<=0,inventory:(((Ke=(ze=C==null?void 0:C.Distribution)==null?void 0:ze.Inventory)==null?void 0:Ke.length)??0)<=0,opportunities:(((et=C==null?void 0:C.Opportunities)==null?void 0:et.length)??0)<=0,orders:(((Ue=C==null?void 0:C.ActiveOrderDetails)==null?void 0:Ue.length)??0)<=0&&(((Qe=C==null?void 0:C.Returns)==null?void 0:Qe.length)??0)<=0,invoices:(((Xe=C==null?void 0:C.CompletedOrderDetails)==null?void 0:Xe.length)??0)<=0,warehouse:(((it=C==null?void 0:C.Receipts)==null?void 0:it.length)??0)<=0},He=Object.values(Oe).some(tt=>!tt);if(j(He),He&&Oe[A]){const tt=Object.keys(Oe).find(at=>!Oe[at]);tt&&I(tt)}},[R,C,n,A]);const q=(C==null?void 0:C.ManufacturerId)!==t;return console.log("readonly",q),jsxRuntime.jsxs("div",{className:"@container",children:[jsxRuntime.jsxs("div",{className:"grid gap-4 grid-cols-1 @sm:grid-cols-2 @md:grid-cols-3",children:[jsxRuntime.jsx("div",{className:"@md:col-span-2",children:jsxRuntime.jsx(ProductCard,{applicationId:t,product:C??C,defaultOpportunityNumber:o,onAddToCart:l,addingToCart:d,shopifyHostname:f,customAction:g})}),jsxRuntime.jsxs(Card,{className:"flex flex-col",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsxs(CardTitle,{children:[jsxRuntime.jsx(Info,{className:"h-5 w-5 inline mr-2"})," Additionnal information"]})}),jsxRuntime.jsx(CardContent,{className:"basis-0 mb-6 grow overflow-y-auto",children:S?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-5 w-32"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"})]}),jsxRuntime.jsx(Skeleton,{className:"h-1 w-full my-6"}),jsxRuntime.jsx(Skeleton,{className:"h-5 w-24"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full mt-2"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-full mt-1"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex justify-between",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Category Name"}),jsxRuntime.jsx("span",{className:"font-medium",children:(C==null?void 0:C.ProductType)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Master Carton"}),jsxRuntime.jsx("span",{className:"font-medium",children:(C==null?void 0:C.MasterCarton)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Skid Quantity"}),jsxRuntime.jsx("span",{className:"font-medium",children:(C==null?void 0:C.SkidQuantity)||"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-2",children:[jsxRuntime.jsx("span",{className:"text-muted-foreground",children:"Automatic Reorder"}),jsxRuntime.jsx("span",{className:"font-medium",children:C!=null&&C.AutoUpdate?"Yes":"No"})]}),((C==null?void 0:C.VoiceoverCaption)||(C==null?void 0:C.BodyHTML))&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("hr",{className:"my-6"}),jsxRuntime.jsx("div",{className:"text-muted-foreground mb-2",children:"Description"}),(C==null?void 0:C.VoiceoverCaption)&&jsxRuntime.jsx("div",{children:C==null?void 0:C.VoiceoverCaption}),(C==null?void 0:C.BodyHTML)&&jsxRuntime.jsx("div",{className:"prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:(C==null?void 0:C.BodyHTML)??""}})]})]})})]})]}),jsxRuntime.jsx("div",{className:"my-4",children:S||R?jsxRuntime.jsx("div",{className:"mx-auto flex justify-center items-center h-32",children:jsxRuntime.jsx(LoaderCircle,{className:"h-8 w-8 animate-spin text-primary"})}):M&&jsxRuntime.jsxs(Tabs,{value:A,onValueChange:I,children:[jsxRuntime.jsxs(TabsList,{className:"inline-flex h-auto items-center justify-center rounded-none border-b bg-transparent p-0",children:[jsxRuntime.jsx(TabsTrigger,{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:(((z=C==null?void 0:C.SalesStatistics)==null?void 0:z.length)??0)<=0,children:"Statistics"}),jsxRuntime.jsx(TabsTrigger,{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:(((V=(Q=C==null?void 0:C.Distribution)==null?void 0:Q.Inventory)==null?void 0:V.length)??0)<=0,children:"Inventory"}),jsxRuntime.jsx(TabsTrigger,{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:(((O=C==null?void 0:C.Opportunities)==null?void 0:O.length)??0)<=0,children:"Opportunities"}),jsxRuntime.jsx(TabsTrigger,{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:(((te=C==null?void 0:C.ActiveOrderDetails)==null?void 0:te.length)??0)<=0,children:"Active Orders"}),jsxRuntime.jsx(TabsTrigger,{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:(((ne=C==null?void 0:C.CompletedOrderDetails)==null?void 0:ne.length)??0)<=0,children:"Completed Orders"}),jsxRuntime.jsx(TabsTrigger,{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:(((ae=C==null?void 0:C.Returns)==null?void 0:ae.length)??0)<=0,children:"Returns"}),jsxRuntime.jsx(TabsTrigger,{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:!(E!=null&&E.IsManufacturer)||(((Ve=C==null?void 0:C.PurchaseOrders)==null?void 0:Ve.length)??0)<=0&&(((Ne=C==null?void 0:C.Requisitions)==null?void 0:Ne.length)??0)<=0,children:"Purchase Orders"}),jsxRuntime.jsx(TabsTrigger,{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:(((se=C==null?void 0:C.Receipts)==null?void 0:se.length)??0)<=0,children:"Latest Warehouse Receiving"})]}),jsxRuntime.jsx(TabsContent,{value:"stats-tab",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(SalesChartCard,{statistics:(C==null?void 0:C.SalesStatistics)??[],loading:R})})}),jsxRuntime.jsx(TabsContent,{value:"inventory-tab",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ProductInventoryGrid,{inventory:((Ae=C==null?void 0:C.Distribution)==null?void 0:Ae.Inventory)??[],className:"bg-card text-card-foreground"})})}),jsxRuntime.jsx(TabsContent,{value:"opportunities-tab",children:jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OpportunitiesTable,{applicationId:t,opportunities:C==null?void 0:C.Opportunities,loading:R})})}),jsxRuntime.jsx(TabsContent,{value:"active-orders-tab",children:(((ge=C==null?void 0:C.ActiveOrderDetails)==null?void 0:ge.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OrdersCard,{applicationId:t,title:"Active Orders",orders:C==null?void 0:C.ActiveOrderDetails,loading:R})})}),jsxRuntime.jsx(TabsContent,{value:"completed-orders-tab",children:(((je=C==null?void 0:C.CompletedOrderDetails)==null?void 0:je.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(OrdersCard,{applicationId:t,title:"Completed Orders",orders:C==null?void 0:C.CompletedOrderDetails,loading:R})})}),jsxRuntime.jsx(TabsContent,{value:"returns-tab",children:(((Le=C==null?void 0:C.Returns)==null?void 0:Le.length)??0)>0&&jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(ReturnsTable,{applicationId:t,returns:C==null?void 0:C.Returns,loading:R})})}),jsxRuntime.jsxs(TabsContent,{value:"purchase-orders-tab",children:[(((Fe=C==null?void 0:C.PurchaseOrders)==null?void 0:Fe.length)??0)>0&&jsxRuntime.jsxs(Card,{className:"mt-4 w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Purchase Orders"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(PurchaseOrdersTable,{applicationId:t,purchaseOrders:C==null?void 0:C.PurchaseOrders,loading:R})})]}),((($e=C==null?void 0:C.Requisitions)==null?void 0:$e.length)??0)>0&&jsxRuntime.jsxs(Card,{className:"mt-4 w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Draft Purchases"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(RequisitionsTable,{applicationId:t,requisitions:C==null?void 0:C.Requisitions,loading:R})})]})]}),jsxRuntime.jsx(TabsContent,{value:"warehouse-tab",children:jsxRuntime.jsxs(Card,{className:"mt-4 w-full",children:[jsxRuntime.jsx(CardHeader,{children:jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Receipts"})}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(ReceiptsTable,{applicationId:t,receipts:C==null?void 0:C.Receipts,loading:R})})]})})]})})]})}function AssistantInsight({prompt:t,smartAndSlow:e=!1,thinkingPlaceholderText:n="Thinking...",withCard:o=!0}){const{response:l,isLoading:d,error:f,sendPrompt:g}=useGemini({useProModel:e,outputFormat:"html"});React.useEffect(()=>{t&&g(t)},[t,g]);const b=`flex items-start gap-4 ${o?"p-4 border rounded-lg bg-background":""}`;return jsxRuntime.jsxs("div",{className:b,children:[jsxRuntime.jsx(Bot,{className:`mt-1 h-6 w-6 flex-shrink-0 ${d?"animate-pulse text-primary":"text-primary"}`}),jsxRuntime.jsxs("div",{className:"w-full min-h-[4rem]",children:[d&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("p",{className:"font-medium text-muted-foreground",children:n}),jsxRuntime.jsxs("div",{className:"space-y-2 mt-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-4 w-5/6"}),jsxRuntime.jsx(Skeleton,{className:"h-4 w-3/4"})]})]}),f&&jsxRuntime.jsx("p",{className:"text-sm text-red-600",children:f}),!d&&!f&&l&&jsxRuntime.jsx("div",{className:"chat-bubble-in-animation text-sm text-foreground space-y-4",dangerouslySetInnerHTML:{__html:l}})]})]})}function AssistantChat(t){return jsxRuntime.jsx(Card,{className:"max-w-6xl",children:jsxRuntime.jsx(ChatLayout,{className:"h-[40em]",userId:t.userId,userName:t.userName,assistantOnly:!0,initialPrompt:t.initialPrompt})})}function ExternalProductCard({product:t,viewProductLink:e}){return t?jsxRuntime.jsx(Card,{className:"@container border-dashed border-2 hover:shadow-md transition-shadow h-full",children:jsxRuntime.jsxs(CardContent,{className:"p-6 flex flex-col h-full",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start mb-4 @[36rem]:hidden",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-lg pr-4 text-center w-full",children:t.Title||t.RandmarTitle}),jsxRuntime.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:jsxRuntime.jsx(PartnerLogo,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40})})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-x-6 gap-y-4 flex-grow @[36rem]:flex-row",children:[jsxRuntime.jsx("div",{className:"mx-auto flex-shrink-0 @[36rem]:mx-0 @[36rem]:w-48",children:jsxRuntime.jsx(ProductImage,{randmarSKU:t.RandmarSKU||"",alt:t.RandmarTitle||""})}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col text-center @[36rem]:text-left",children:[jsxRuntime.jsxs("div",{className:"hidden @[36rem]:flex justify-between items-start mb-4",children:[jsxRuntime.jsx("h3",{className:"font-semibold text-lg pr-4",children:t.Title||t.RandmarTitle}),jsxRuntime.jsx("div",{className:"w-24 h-10 flex-shrink-0",children:jsxRuntime.jsx(PartnerLogo,{id:t.ManufacturerId,name:t.ManufacturerName,width:96,height:40})})]}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @[36rem]:hidden",children:[jsxRuntime.jsxs(Badge,{variant:"outline",className:"border-orange-300 bg-orange-50 text-orange-800",children:[jsxRuntime.jsx(Telescope,{className:"mr-2 h-3 w-3"}),jsxRuntime.jsx("span",{children:"External Product"})]}),jsxRuntime.jsxs(Badge,{variant:"outline",className:"border-randmar-red bg-red-50 text-randmar-red",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2 h-3 w-3"}),jsxRuntime.jsxs("span",{children:["Held by ",jsxRuntime.jsx("b",{children:"Randmar"})]})]})]}),jsxRuntime.jsxs("div",{className:"hidden @[36rem]:grid grid-cols-2 gap-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center rounded-md bg-orange-50 px-4 py-2 text-orange-800 border-1 border-orange-800 text-sm",children:[jsxRuntime.jsx(Telescope,{className:"mr-2 h-5 w-5 flex-shrink-0"}),jsxRuntime.jsx("span",{children:"External Product"})]}),jsxRuntime.jsxs("div",{className:"flex items-center rounded-md bg-red-50 px-4 py-2 text-randmar-red border-1 border-randmar-red text-sm",children:[jsxRuntime.jsx(Warehouse,{className:"mr-2 h-5 w-5 flex-shrink-0"}),jsxRuntime.jsxs("span",{children:["Held by ",jsxRuntime.jsx("b",{children:"Randmar"})]})]})]}),e&&jsxRuntime.jsx("div",{className:"mt-auto pt-4 flex justify-center @[36rem]:justify-end",children:jsxRuntime.jsx(reactRouterDom.Link,{to:e,children:jsxRuntime.jsxs(Button$1,{variant:"secondary",className:"w-full @[36rem]:w-auto",children:[jsxRuntime.jsx(Eye,{className:"mr-2 h-4 w-4"}),"View Product"]})})})]})]})]})}):jsxRuntime.jsx(Card,{className:"@container border-dashed border-2 h-full",children:jsxRuntime.jsx(CardContent,{className:"p-6 flex flex-col h-full",children:jsxRuntime.jsxs("div",{className:"flex flex-col gap-6 flex-grow @[36rem]:flex-row",children:[jsxRuntime.jsx("div",{className:"flex-shrink-0 @[36rem]:w-48",children:jsxRuntime.jsx(Skeleton,{className:"aspect-square w-full h-auto"})}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-4",children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-start",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-1/2"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-24 rounded"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 justify-center @[36rem]:hidden",children:[jsxRuntime.jsx(Skeleton,{className:"h-6 w-36 rounded-full"}),jsxRuntime.jsx(Skeleton,{className:"h-6 w-36 rounded-full"})]}),jsxRuntime.jsxs("div",{className:"hidden @[36rem]:grid grid-cols-2 gap-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md"}),jsxRuntime.jsx(Skeleton,{className:"h-10 w-full rounded-md"})]})]}),jsxRuntime.jsx("div",{className:"mt-auto pt-4 flex justify-center @[36rem]:justify-end",children:jsxRuntime.jsx(Skeleton,{className:"h-10 w-full @[36rem]:w-40"})})]})]})})})}function getEndDateStatus(t){if(!t)return{text:"No End Date",variant:"neutral",daysRemaining:null};const e=new Date(t);if(isNaN(e.getTime()))return{text:"Invalid Date",variant:"neutral",daysRemaining:null};const n=new Date,o=new Date(e.getFullYear(),e.getMonth(),e.getDate()),l=new Date(n.getFullYear(),n.getMonth(),n.getDate()),d=o.getTime()-l.getTime(),f=Math.ceil(d/(1e3*60*60*24));return f<0?{text:`Ended ${Math.abs(f)}d ago`,variant:"destructive",daysRemaining:f}:f===0?{text:"Ends today",variant:"destructive",daysRemaining:f}:f<=7?{text:`Ends in ${f}d`,variant:"destructive",daysRemaining:f}:f<=30?{text:`Ends in ${f}d`,variant:"warning",daysRemaining:f}:{text:`Ends in ${f}d`,variant:"neutral",daysRemaining:f}}const formatDate=t=>{if(!t)return"N/A";try{const e=new Date(t);return isNaN(e.getTime())?"Invalid Date":e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"Invalid Date"}};function OpportunitiesTable({applicationId:t,opportunities:e=null,loading:n=!1}){var te;const{toast:o}=useToast(),[l,d]=React.useState({}),[f,g]=React.useState(!1),[b,S]=React.useState(""),[_,R]=React.useState(null),{data:C}=useGetV4PartnerByApplicationIdAccountQuery({applicationId:t},{skip:!t}),E=React.useCallback((ne,ae,Ve)=>{d(Ne=>({...Ne,[ne]:{...Ne[ne],[ae]:Ve}}))},[]),[A]=usePutV4ResellerByRouteResellerIdOpportunityAndManufacturerIdDefaultMutation(),I=React.useCallback(async ne=>{if(!(C!=null&&C.IsReseller))return;if(!ne.BidNumber){o({title:"Error",description:"Bid Number is missing, cannot set default.",variant:"destructive"});return}const ae=ne.BidNumber;E(ae,"isSettingDefault",!0),A({routeResellerId:t,manufacturerId:ne.ManufacturerId??"",opportunityNumber:ae}).unwrap().then(()=>{o({title:"Success",description:`Opportunity "${ne.OpportunityName||ne.Opportunity||ae}" was successfully set as default.`,variant:"success"})}).catch(Ve=>{var Ne;console.error("Set as default error:",Ve),o({title:"Error",description:((Ne=Ve.data)==null?void 0:Ne.message)||Ve.message||"An error occurred while setting this opportunity as default.",variant:"destructive"})}).finally(()=>{E(ae,"isSettingDefault",!1)})},[t,A,o,E,C==null?void 0:C.IsReseller]),[M]=usePostV4ResellerByRouteResellerIdOpportunityAndManufacturerIdBidNumberEmailMutation(),j=React.useCallback(ne=>{if(C!=null&&C.IsReseller){if(!ne.BidNumber){o({title:"Error",description:"Bid Number is missing, cannot prepare report.",variant:"destructive"});return}R(ne),S(""),g(!0)}},[o,C==null?void 0:C.IsReseller]),q=React.useCallback(async()=>{if(!(C!=null&&C.IsReseller))return;if(!_||!_.BidNumber){o({title:"Error",description:"No opportunity selected or Bid Number is missing.",variant:"destructive"});return}if(!b.trim()||!/\S+@\S+\.\S+/.test(b)){o({title:"Validation Error",description:"Please enter a valid email address.",variant:"destructive"});return}const ne=_.BidNumber;E(ne,"isSendingReport",!0),M({routeResellerId:t,manufacturerId:_.ManufacturerId??"",bidNumber:ne,emailAddress:b}).unwrap().then(()=>{o({title:"Success",description:`A report for "${_.OpportunityName||_.Opportunity||ne}" was successfully sent to ${b}.`,variant:"success"}),g(!1)}).catch(ae=>{var Ve;console.error("Send report by email error:",ae),o({title:"Error",description:((Ve=ae.data)==null?void 0:Ve.message)||ae.message||"An error occurred while sending the report by email.",variant:"destructive"})}).finally(()=>{E(ne,"isSendingReport",!1),f||(R(null),S(""))})},[_,b,t,M,o,E,g]),z=React.useMemo(()=>[{accessorKey:"ManufacturerId",header:"Manuf.",cell:({row:ne})=>jsxRuntime.jsx("div",{className:"w-20 h-8",children:jsxRuntime.jsx(PartnerLogo,{id:ne.original.ManufacturerId,width:80,height:32})}),enableSorting:!0,enableFiltering:!0},{id:"opportunityDisplay",accessorFn:ne=>ne.OpportunityName||ne.Opportunity,header:"Opportunity",cell:({getValue:ne})=>jsxRuntime.jsx("div",{className:"min-w-[150px]",children:ne()??"N/A"}),enableSorting:!0,enableFiltering:!0},{accessorKey:"BidNumber",header:"Bid Number",cell:({row:ne})=>ne.original.BidNumber??"N/A",enableSorting:!0,enableFiltering:!0},{id:"statusInfo",header:"Status",cell:({row:ne})=>{const ae=ne.original,Ve=ae.Active===!0,Ne=getEndDateStatus(ae.EndDate);let se="border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400";return Ne.variant==="destructive"?se="border-red-500 bg-red-100 text-red-700 dark:border-red-600 dark:bg-red-900/50 dark:text-red-400":Ne.variant==="warning"&&(se="border-yellow-500 bg-yellow-100 text-yellow-700 dark:border-yellow-600 dark:bg-yellow-900/50 dark:text-yellow-400"),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 min-w-[200px]",children:[jsxRuntime.jsx(Badge,{variant:"outline",className:Ve?"border-green-500 bg-green-100 text-green-700 dark:border-green-600 dark:bg-green-900/50 dark:text-green-400 font-medium":"border-gray-400 bg-gray-100 text-gray-600 dark:border-gray-600 dark:bg-gray-800/50 dark:text-gray-400 font-medium",children:Ve?"Active":"Inactive"}),ae.EndDate&&jsxRuntime.jsx(Badge,{variant:"outline",className:`${se} font-medium`,children:Ne.text}),jsxRuntime.jsx(TooltipProvider,{delayDuration:100,children:jsxRuntime.jsxs(Tooltip$1,{children:[jsxRuntime.jsx(TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(Button$1,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0 data-[state=delayed-open]:bg-accent data-[state=instant-open]:bg-accent",children:jsxRuntime.jsx(Info,{className:"h-4 w-4 text-muted-foreground"})})}),jsxRuntime.jsx(TooltipContent,{side:"top",align:"center",className:"bg-popover text-popover-foreground p-2 rounded shadow-lg",children:jsxRuntime.jsxs("div",{className:"text-sm space-y-1",children:[jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"Start:"})," ",formatDate(ae.StartDate)]}),jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"End:"})," ",formatDate(ae.EndDate)]}),jsxRuntime.jsxs("p",{children:[jsxRuntime.jsx("strong",{children:"Updated:"})," ",formatDate(ae.LastUpdate)]})]})})]})})]})},enableFiltering:!1},{id:"actions",header:"Actions",cell:({row:ne})=>{var Le,Fe;const ae=ne.original;if(!ae.BidNumber)return jsxRuntime.jsx("span",{className:"text-xs text-muted-foreground",children:"Actions unavailable"});const Ve=ae.BidNumber,Ne=(Le=l[Ve])==null?void 0:Le.isSettingDefault,se=(_==null?void 0:_.BidNumber)===Ve&&((Fe=l[Ve])==null?void 0:Fe.isSendingReport),Ae=Ne||se,ge=ae.CanBeSetAsDefault===!0,je=C!=null&&C.IsManufacturer?`/${t}/Opportunity/${ae.BidNumber}`:`/${t}/Opportunity/${ae.ManufacturerId}/${ae.BidNumber}`;return jsxRuntime.jsxs("div",{className:"flex space-x-2",children:[jsxRuntime.jsx(reactRouterDom.Link,{to:je,children:jsxRuntime.jsxs(Button$1,{variant:"outline",size:"sm",className:"flex items-center",children:[jsxRuntime.jsx(Star,{className:"mr-2 h-4 w-4"})," View"]})}),(C==null?void 0:C.IsReseller)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Button$1,{variant:"outline",size:"sm",onClick:()=>I(ae),disabled:Ae||!ge,title:ge?"Set as default":"This opportunity cannot be set as default",className:"flex items-center",children:[Ne?jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):jsxRuntime.jsx(Star,{className:"mr-2 h-4 w-4"})," Set Default"]}),jsxRuntime.jsxs(Button$1,{variant:"outline",size:"sm",onClick:()=>j(ae),disabled:Ae,title:"Send report by email",className:"flex items-center",children:[se?jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):jsxRuntime.jsx(Send,{className:"mr-2 h-4 w-4"})," Send Report"]})]})]})}}],[l,I,j,_,C==null?void 0:C.IsReseller,t]),Q=React.useMemo(()=>{const ne={};if(e){const ae=Array.from(new Set(e.map(Ne=>Ne.ManufacturerId).filter(Ne=>Ne!=null)));ne.ManufacturerId=ae;const Ve=Array.from(new Set(e.map(Ne=>Ne.OpportunityName||Ne.Opportunity).filter(Ne=>Ne!=null)));ne.opportunityDisplay=Ve}return ne},[e]),V=e||[],O=_!=null&&_.BidNumber?(te=l[_.BidNumber])==null?void 0:te.isSendingReport:!1;return n?jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{children:[" ",jsxRuntime.jsx(Skeleton,{className:"h-7 w-48"})," "]}),jsxRuntime.jsxs(CardContent,{className:"space-y-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-12 w-full rounded-md border"}),jsxRuntime.jsx(Skeleton,{className:"h-48 w-full rounded-md border"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between pt-4",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-[130px]"}),jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsx(Skeleton,{className:"h-9 w-20"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-24"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})," ",jsxRuntime.jsx(Skeleton,{className:"h-9 w-9"})]})]})]})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(Card,{className:"w-full",children:[jsxRuntime.jsxs(CardHeader,{children:[" ",jsxRuntime.jsx(CardTitle,{className:"text-1xl font-bold",children:"Opportunities"})," "]}),jsxRuntime.jsx(CardContent,{children:jsxRuntime.jsx(DataTable,{columns:z,data:V,uniqueValues:Q})})]}),jsxRuntime.jsx(Dialog,{open:f,onOpenChange:ne=>{g(ne),ne||(R(null),S(""))},children:jsxRuntime.jsxs(DialogContent,{className:"@sm:max-w-[425px]",children:[jsxRuntime.jsxs(DialogHeader,{children:[jsxRuntime.jsx(DialogTitle,{children:"Send Opportunity Report"}),jsxRuntime.jsxs(DialogDescription,{children:["Enter the email address to send the report for opportunity: ",jsxRuntime.jsx("br",{}),jsxRuntime.jsx("span",{className:"font-semibold",children:(_==null?void 0:_.OpportunityName)||(_==null?void 0:_.Opportunity)||"N/A"}),(_==null?void 0:_.BidNumber)&&jsxRuntime.jsxs("span",{className:"block text-sm text-muted-foreground",children:["Bid Number: ",_.BidNumber]})]})]}),jsxRuntime.jsx("div",{className:"grid gap-4 py-4",children:jsxRuntime.jsxs("div",{className:"grid grid-cols-4 items-center gap-4",children:[jsxRuntime.jsx(Label$2,{htmlFor:"email",className:"text-right",children:"Email"}),jsxRuntime.jsx(Input,{id:"email",type:"email",value:b,onChange:ne=>S(ne.target.value),placeholder:"recipient@example.com",className:"col-span-3",disabled:O})]})}),jsxRuntime.jsxs(DialogFooter,{children:[jsxRuntime.jsx(Button$1,{variant:"outline",onClick:()=>g(!1),disabled:O,children:"Cancel"}),jsxRuntime.jsxs(Button$1,{type:"submit",onClick:q,disabled:O,children:[O&&jsxRuntime.jsx(LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"})," Send Report"]})]})]})})]})}function useLoadScript(t){const[e,n]=React.useState(!0),[o,l]=React.useState(null),[d,f]=React.useState(!1),g=()=>{n(!1),f(!0)};return React.useEffect(()=>{if(!document){const R=new Error(`[ScriptLoadingError] document not defined when attempting to load ${t}`);l(R);return}const b=document.querySelector(`script[src="${t}"]`);if(b!=null&&b.dataset.loaded){g();return}const S=b||document.createElement("script");b||(S.src=t);const _=()=>{S.dataset.loaded="1",g()};S.addEventListener("load",_),S.addEventListener("error",R=>{console.error("Failed to load script:",t,R);const C=new Error(`[ScriptLoadingError] Failed to load script: ${t}`);l(C)}),b||document.head.append(S)},[]),{isLoading:e,error:o,isSuccess:d}}const isGoogleReady=t=>t&&t.charts,isGoogleChartsReady=(t,e)=>{const{controls:n,toolbarItems:o,getChartEditor:l}=t;return e&&e.charts&&e.visualization&&e.visualization.ChartWrapper&&e.visualization.Dashboard&&(!n||e.visualization.ChartWrapper)&&(!l||e.visualization.ChartEditor)&&(!o||e.visualization.drawToolbar)},getGoogleInstanceFromWindow=t=>window.google;function useLoadGoogleCharts(t){const{chartVersion:e="current",chartPackages:n=["corechart","controls"],chartLanguage:o="en",mapsApiKey:l}=t,[d,f]=React.useState(null),[g,b]=React.useState(null),[S,_]=React.useState(null),{isLoading:R,error:C,isSuccess:E}=useLoadScript(t.chartLoaderScriptUrl||"https://www.gstatic.com/charts/loader.js");return React.useEffect(()=>{if(!E)return;const A=getGoogleInstanceFromWindow();if(!isGoogleReady(A)){const I=new Error("[ScriptInitializationError] Script loaded but Google not attached to window.");b(I);return}if(isGoogleChartsReady(t,A)){f(A);return}A.charts.load(e,{packages:n,language:o,mapsApiKey:l}),A.charts.setOnLoadCallback(()=>{if(!isGoogleChartsReady(t,A)){const I=new Error("[GoogleChartsInitializationError] Google Charts not ready after load callback.");console.error(I),_(I);return}f(A)})},[E]),{error:C||g||S,isLoading:R,google:d}}const chartDefaultProps={legend_toggle:!1,options:{},legendToggle:!1,getChartWrapper:()=>{},spreadSheetQueryParameters:{headers:1,gid:1},rootProps:{},chartWrapperParams:{},chartLoaderScriptUrl:"https://www.gstatic.com/charts/loader.js"},GoogleChartControls=t=>{const{isReady:e,chartControls:n,filter:o}=t;return!e||!n||!(n!=null&&n.length)?null:React.createElement(React.Fragment,null,n.filter(l=>{let{controlProp:d,control:f}=l;return o?o({control:f,controlProp:d}):!0}).map(l=>{let{control:d}=l;return React.createElement("div",{key:d.getContainerId(),id:d.getContainerId()})}))};let uniqueID=0;const generateUniqueID=()=>(uniqueID+=1,`reactgooglegraph-${uniqueID}`),Ln=class Ln{};rn(Ln,"initializeControls",e=>{for(let n=0;n<e.length;n+=1){const{controlType:o,options:l,controlWrapperParams:d}=e[n].controlProp;d&&"state"in d&&e[n].control.setState(d.state),e[n].control.setOptions(l),e[n].control.setControlType(o)}}),rn(Ln,"listenToControlEvents",(e,n)=>{const{google:o}=n;return e.flatMap(l=>{const{control:d,controlProp:f}=l,{controlEvents:g=[]}=f;return g.map(b=>{const{callback:S,eventName:_}=b;return o.visualization.events.addListener(d,_,function(){for(var R=arguments.length,C=new Array(R),E=0;E<R;E++)C[E]=arguments[E];S({chartWrapper:null,controlWrapper:d,props:n,google:o,eventArgs:C})})})})}),rn(Ln,"createControlId",e=>{let n;return typeof e>"u"?n=`googlechart-control-${generateUniqueID()}`:n=e,n}),rn(Ln,"createChartControls",e=>{const{controls:n,google:o}=e;return n?n.map((l,d)=>{const{controlID:f,controlType:g,options:b,controlWrapperParams:S}=l,_=Ln.createControlId(f);return{controlProp:l,control:new o.visualization.ControlWrapper({containerId:_,controlType:g,options:b,...S})}}):null}),rn(Ln,"addControls",e=>{const{chartWrapper:n,chartDashboard:o}=e,l=Ln.createChartControls(e);return!l||!o||!n?null:(o.bind(l.map(d=>{let{control:f}=d;return f}),n),Ln.initializeControls(l),l)});let GoogleChartControlsInternal=Ln;const useCreateChartControls=t=>{const[e,n]=React__namespace.useState(null);return[React__namespace.useMemo(()=>!e||!t?null:t.map((l,d)=>{const f=e[d];return f?{controlProp:l,control:f}:void 0}).flatMap(l=>l?[l]:[]),[e,t]),n]},useListenToControlEvents=(t,e)=>{React__namespace.useEffect(()=>{const n=GoogleChartControlsInternal.listenToControlEvents(t??[],e);return()=>{n.forEach(o=>{e.google.visualization.events.removeListener(o)})}},[t,e])},useChartControls=t=>{const[e,n]=useCreateChartControls(t.controls);return useListenToControlEvents(e??[],t),{addControls:l=>{const d=GoogleChartControlsInternal.addControls(l);n((d==null?void 0:d.map(f=>f.control))??null)},renderControl:l=>{const{chartWrapper:d,chartDashboard:f}=t;return React__namespace.createElement(GoogleChartControls,{...t,isReady:!!(d&&f),chartControls:e,filter:l})}}},useChartId=t=>{const e=React__namespace.useRef(null);return{chartId:(()=>{const{graphID:l,graph_id:d}=t,f=l||d;let g;return f?g=f:g=e.current||generateUniqueID(),e.current=g,e.current})()}},DEFAULT_CHART_COLORS=["#3366CC","#DC3912","#FF9900","#109618","#990099","#3B3EAC","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#329262","#5574A6","#3B3EAC"],loadDataTableFromSpreadSheet=async function(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((o,l)=>{const d=`${n.headers?`headers=${n.headers}`:"headers=0"}`,f=`${n.query?`&tq=${encodeURIComponent(n.query)}`:""}`,g=`${n.gid?`&gid=${n.gid}`:""}`,b=`${n.sheet?`&sheet=${n.sheet}`:""}`,S=`${n.access_token?`&access_token=${n.access_token}`:""}`,_=`${d}${g}${b}${f}${S}`,R=`${e}/gviz/tq?${_}`;new t.visualization.Query(R).send(E=>{E.isError()?l(`Error in query: ${E.getMessage()} ${E.getDetailedMessage()}`):o(E.getDataTable())})})},GRAY_COLOR="#CCCCCC",$n=class $n{};rn($n,"grayOutHiddenColumnsLabel",(e,n)=>{const{googleChartWrapper:o,options:l}=e;if(!o){console.error("googleChartWrapper is not defined");return}const d=o.getDataTable();if(!d)return;const f=d.getNumberOfColumns();if(n.length>0===!1)return;const b=Array.from({length:f-1}).map((S,_)=>{const R=$n.getColumnId(d,_+1);return n.includes(R)?GRAY_COLOR:l&&l.colors?l.colors[_]:DEFAULT_CHART_COLORS[_]});o.setOptions({...l,colors:b}),o.draw()}),rn($n,"listenToLegendToggle",(e,n)=>{const[o,l]=n,{google:d,googleChartWrapper:f}=e;if(!f){console.error("googleChartWrapper is not defined");return}return d.visualization.events.addListener(f,"select",()=>{const b=f.getChart().getSelection(),S=f.getDataTable();if(b.length===0||b[0].row!==null||!S)return;const _=b[0].column,R=$n.getColumnId(S,_);o!=null&&o.includes(R)?l(C=>[...C.filter(E=>E!==R)]):l(C=>[...C,R])})}),rn($n,"draw",async e=>{const{data:n,diffdata:o,rows:l,columns:d,options:f,chartType:g,formatters:b,spreadSheetUrl:S,spreadSheetQueryParameters:_,googleChartDashboard:R,googleChartWrapper:C,google:E,hiddenColumns:A,legendToggle:I,legend_toggle:M}=e;if(!C){console.error("draw was called with googleChartWrapper = null");return}let j,q=null;if(o){const te=E.visualization.arrayToDataTable(o.old),ne=E.visualization.arrayToDataTable(o.new);q=E.visualization[g].prototype.computeDiff(te,ne)}n?n instanceof E.visualization.DataTable?j=n:Array.isArray(n)?j=E.visualization.arrayToDataTable(n):j=new E.visualization.DataTable(n):l&&d?j=E.visualization.arrayToDataTable([d,...l]):S?j=await loadDataTableFromSpreadSheet(E,S,_):j=E.visualization.arrayToDataTable([]);const z=j.getNumberOfColumns(),Q=Array(z).fill(0).map((te,ne)=>{const ae=$n.getColumnId(j,ne);return A.includes(ae)?{label:j.getColumnLabel(ne),type:j.getColumnType(ne),calc:()=>null}:ne}),V=C.getChart();C.getChartType()==="Timeline"&&V&&V.clearChart(),C.setChartType(g),C.setOptions(f||{});const O=new E.visualization.DataView(j);O.setColumns(Q),C.setDataTable(O),C.draw(),R&&R.draw(j),q&&(C.setDataTable(q),C.draw()),b&&($n.applyFormatters({dataTable:j,formatters:b,google:E}),C.setDataTable(j),C.draw()),(I===!0||M===!0)&&$n.grayOutHiddenColumnsLabel(e,A)}),rn($n,"getColumnId",(e,n)=>e.getColumnId(n)||e.getColumnLabel(n)),rn($n,"applyFormatters",e=>{let{dataTable:n,formatters:o,google:l}=e;for(let d of o)switch(d.type){case"ArrowFormat":{new l.visualization.ArrowFormat(d.options).format(n,d.column);return}case"BarFormat":{new l.visualization.BarFormat(d.options).format(n,d.column);return}case"ColorFormat":{const f=new l.visualization.ColorFormat(d.options),{ranges:g}=d;if(g)for(let b of g)f.addRange(...b);f.format(n,d.column);return}case"DateFormat":{new l.visualization.DateFormat(d.options).format(n,d.column);return}case"NumberFormat":{new l.visualization.NumberFormat(d.options).format(n,d.column);return}case"PatternFormat":{new l.visualization.PatternFormat(d.options).format(n,d.column);return}default:{console.warn(`Unknown formatter type: ${d.type}`);return}}});let GoogleChartInternal=$n;const useGoogleChartDataTable=t=>{const{google:e,googleChartWrapper:n,googleChartDashboard:o}=t,[l,d]=React__namespace.useState([]);React__namespace.useEffect(()=>{n&&GoogleChartInternal.draw({...t,hiddenColumns:l,googleChartWrapper:n,googleChartDashboard:o,google:e})},[l,t.data,t.rows,t.columns,t.options,t.chartLoaderScriptUrl,t.chartType,t.formatters,t.spreadSheetUrl,t.spreadSheetQueryParameters,t.legendToggle,t.legend_toggle]);const f=()=>{const{googleChartWrapper:S}=t;S&&S.draw()},g=S=>{const _=[],{legendToggle:R,legend_toggle:C}=t;if(GoogleChartInternal.draw({...t,hiddenColumns:l,googleChartWrapper:S,googleChartDashboard:o,google:e}),window.addEventListener("resize",f),C||R){const E=GoogleChartInternal.listenToLegendToggle(t,[l,d]);E&&_.push(E)}return _},b=(S,_)=>{window.removeEventListener("resize",f),_.forEach(R=>{e.visualization.events.removeListener(R)}),S.getChartType()==="Timeline"&&S.getChart()&&S.getChart().clearChart()};React__namespace.useEffect(()=>{if(!n)return;const S=g(n);return()=>{b(n,S)}},[n,g,b])},listenToEvents=t=>{const{chartEvents:e,google:n,googleChartWrapper:o}=t;if(e){if(!o){console.warn("listenToEvents was called before chart wrapper ready.");return}return e.map(l=>{let{eventName:d,callback:f}=l;return n.visualization.events.addListener(o,d,function(){for(var g=arguments.length,b=new Array(g),S=0;S<g;S++)b[S]=arguments[S];f({chartWrapper:o,props:t,google:n,eventArgs:b})})})}},useGoogleChartEvents=t=>{React.useEffect(()=>{if(!t.googleChartWrapper)return;const e=listenToEvents(t);return()=>{e==null||e.forEach(n=>{t.google.visualization.events.removeListener(n)})}},[t])},GoogleChart=t=>{const[e,n]=React__namespace.useState(null),[o,l]=React__namespace.useState(null),{addControls:d,renderControl:f}=useChartControls({...t,chartDashboard:o,chartWrapper:e});useGoogleChartEvents({...t,googleChartWrapper:e});const{chartId:g}=useChartId(t),b=React__namespace.useRef(null),S=React__namespace.useRef(null);React__namespace.useEffect(()=>{const{options:j,google:q,chartType:z,chartWrapperParams:Q,toolbarItems:V,getChartEditor:O,getChartWrapper:te,onLoad:ne}=t,ae={chartType:z,options:j,containerId:g,...Q},Ve=new q.visualization.ChartWrapper(ae);Ve.setOptions(j||{}),te==null||te(Ve,q);const Ne=new q.visualization.Dashboard(b.current);V&&q.visualization.drawToolbar(S.current,V);let se=null;O&&(se=new q.visualization.ChartEditor,O({chartEditor:se,chartWrapper:Ve,google:q})),d({...t,chartDashboard:Ne,chartWrapper:Ve}),n(Ve),l(Ne),ne==null||ne(q,{google:q,chartWrapper:Ve,chartEditor:se,chartDashboard:Ne})},[]),useGoogleChartDataTable({...t,googleChartWrapper:e,googleChartDashboard:o});const _=()=>{const{width:j,height:q,options:z,style:Q,className:V,rootProps:O,google:te}=t,ne={height:q||z&&z.height,width:j||z&&z.width,...Q};return React__namespace.createElement("div",{id:g,style:ne,className:V,...O})},R=()=>t.toolbarItems?React__namespace.createElement("div",{ref:S}):null,{width:C,height:E,options:A,style:I}=t,M={height:E||A&&A.height,width:C||A&&A.width,...I};return t.render?React__namespace.createElement("div",{ref:b,style:M},React__namespace.createElement("div",{ref:S,id:"toolbar"}),t.render({renderChart:_,renderControl:f,renderToolbar:R})):React__namespace.createElement("div",{ref:b,style:M},f(j=>{let{controlProp:q}=j;return q.controlPosition!=="bottom"}),_(),f(j=>{let{controlProp:q}=j;return q.controlPosition==="bottom"}),R())},ChartContext=React__namespace.createContext(chartDefaultProps),ContextProvider=t=>{let{children:e,value:n}=t;return React__namespace.createElement(ChartContext.Provider,{value:n},e)},ChartView=t=>{const{google:e,isLoading:n,error:o}=useLoadGoogleCharts(t);return n?t.loader??null:o?t.errorElement??null:e?React.createElement(GoogleChart,{google:e,...t}):null},Chart=t=>{const e={...chartDefaultProps,...t};return React.createElement(ContextProvider,{value:e},React.createElement(ChartView,e))};var GoogleDataTableColumnRoleType;(function(t){t.annotation="annotation",t.annotationText="annotationText",t.certainty="certainty",t.emphasis="emphasis",t.interval="interval",t.scope="scope",t.style="style",t.tooltip="tooltip",t.domain="domain"})(GoogleDataTableColumnRoleType||(GoogleDataTableColumnRoleType={}));function parseHsl(t){const e=t.match(/(\d+\.?\d*)\s*(\d+\.?\d*)%\s*(\d+\.?\d*)%/);return e?{h:parseFloat(e[1]),s:parseFloat(e[2]),l:parseFloat(e[3])}:null}function hslToHex(t,e,n){n/=100;const o=e*Math.min(n,1-n)/100,l=d=>{const f=(d+t/30)%12,g=n-o*Math.max(Math.min(f-3,9-f,1),-1);return Math.round(255*g).toString(16).padStart(2,"0")};return`#${l(0)}${l(8)}${l(4)}`}const Treemap=React__namespace.forwardRef(({data:t,options:e,height:n="500px",className:o,loading:l,disableClick:d=!0,...f},g)=>{const b=React__namespace.useRef(null),[S,_]=React__namespace.useState(null);React__namespace.useEffect(()=>{if(!b.current)return;const E=b.current,A=()=>{const q=getComputedStyle(E).getPropertyValue("--primary").trim();if(q){const z=parseHsl(q);if(z){const{h:Q,s:V,l:O}=z;_({minColor:hslToHex(Q,V,Math.min(100,O+50)),midColor:hslToHex(Q,V,Math.min(100,O+35)),maxColor:hslToHex(Q,V,Math.min(100,O+20))})}return!0}return!1};if(A())return;let I=0;const M=20,j=setInterval(()=>{(A()||I>=M)&&clearInterval(j),I++},100);return()=>{j&&clearInterval(j)}},[]);const R=React__namespace.useMemo(()=>{const E={headerHeight:0,fontSize:14,showScale:!1,isHtml:!0,backgroundColor:"hsl(var(--background))",generateTooltip:(A,I)=>{var q;const M=(q=t[A+1])==null?void 0:q[0];if(!M)return"";const j=formatMoney(I);return`<div class="p-2 bg-background text-foreground border rounded-md shadow-lg">
1429
1429
  <strong>${M}</strong><br>Value: ${j}
1430
1430
  </div>`}};return S&&(!e||!e.colorAxis)&&(E.minColor=S.minColor,E.midColor=S.midColor,E.maxColor=S.maxColor),{...E,...e}},[t,e,S]),C=React__namespace.useMemo(()=>d?[{eventName:"select",callback:({chartWrapper:A})=>{A.getChart().setSelection(null)}}]:void 0,[d]);return React__namespace.useImperativeHandle(g,()=>b.current,[]),l?jsxRuntime.jsx("div",{ref:b,className:cn("w-full",o),style:{height:n},...f,children:jsxRuntime.jsx(Skeleton,{className:"h-full w-full"})}):!t||t.length<=2?jsxRuntime.jsx("div",{ref:b,className:cn("w-full flex items-center justify-center text-muted-foreground",o),style:{height:n},...f,children:"No data available"}):jsxRuntime.jsx("div",{ref:b,className:cn("w-full",o),style:{height:n},...f,children:jsxRuntime.jsx(Chart,{chartType:"TreeMap",width:"100%",height:"100%",data:t,options:R,chartEvents:C,loader:jsxRuntime.jsx(Skeleton,{className:"h-full w-full"})})})});Treemap.displayName="Treemap";const TopPercentTreemap=({data:t,topPercent:e=80,title:n,loading:o,...l})=>{const d=React__namespace.useMemo(()=>{if(!t||t.length===0)return[["ID","Parent","Value"],["Root",null,0]];const g=[...t].sort((A,I)=>I.value-A.value),S=g.reduce((A,I)=>A+I.value,0)*(e/100),_=[["ID","Parent","Value"],["Root",null,0]],R=[],C=[];let E=0;for(const A of g)E<S?(R.push(A),E+=A.value):C.push(A);if(R.forEach(A=>{_.push([A.name,"Root",A.value])}),C.length>0){const A=`More... (${C.length} items)`;_.push([A,"Root",0]),C.forEach(I=>{_.push([I.name,A,I.value])})}return _},[t,e]),f=React__namespace.useMemo(()=>({title:n,maxDepth:1,backgroundColor:"hsl(var(--background))"}),[n]);return jsxRuntime.jsx(Treemap,{data:d,options:f,className:cn("h-full",l.className),loading:o,disableClick:!1,...l})},SearchPage=({query:t,results:e,isLoading:n,children:o})=>{const l=React.useMemo(()=>e!=null&&e.length?`
1431
1431
  Act as a helpful search analyst. Your task is to provide a concise, high-level summary
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "randmarcomps",
3
3
  "private": false,
4
- "version": "1.393.0",
4
+ "version": "1.394.0",
5
5
  "description": "The UI library enabling speed and consistency in Randmar frontends.",
6
6
  "type": "module",
7
7
  "files": [